]> git.ipfire.org Git - thirdparty/grsecurity-scrape.git/blob - test/grsecurity-3.0-3.13.10-201404182111.patch
Auto commit, 1 new patch{es}.
[thirdparty/grsecurity-scrape.git] / test / grsecurity-3.0-3.13.10-201404182111.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 982ade0..f9cdd67 100644
291 --- a/Makefile
292 +++ b/Makefile
293 @@ -244,8 +244,9 @@ CONFIG_SHELL := $(shell if [ -x "$$BASH" ]; then echo $$BASH; \
294
295 HOSTCC = gcc
296 HOSTCXX = g++
297 -HOSTCFLAGS = -Wall -Wmissing-prototypes -Wstrict-prototypes -O2 -fomit-frame-pointer
298 -HOSTCXXFLAGS = -O2
299 +HOSTCFLAGS = -Wall -W -Wmissing-prototypes -Wstrict-prototypes -Wno-unused-parameter -Wno-missing-field-initializers -O2 -fomit-frame-pointer -fno-delete-null-pointer-checks
300 +HOSTCFLAGS += $(call cc-option, -Wno-empty-body)
301 +HOSTCXXFLAGS = -O2 -Wall -W -fno-delete-null-pointer-checks
302
303 # Decide whether to build built-in, modular, or both.
304 # Normally, just do built-in.
305 @@ -311,9 +312,15 @@ endif
306 # If the user is running make -s (silent mode), suppress echoing of
307 # commands
308
309 +ifneq ($(filter 4.%,$(MAKE_VERSION)),) # make-4
310 +ifneq ($(filter %s ,$(firstword x$(MAKEFLAGS))),)
311 + quiet=silent_
312 +endif
313 +else # make-3.8x
314 ifneq ($(filter s% -s%,$(MAKEFLAGS)),)
315 quiet=silent_
316 endif
317 +endif
318
319 export quiet Q KBUILD_VERBOSE
320
321 @@ -417,8 +424,8 @@ export RCS_TAR_IGNORE := --exclude SCCS --exclude BitKeeper --exclude .svn \
322 # Rules shared between *config targets and build targets
323
324 # Basic helpers built in scripts/
325 -PHONY += scripts_basic
326 -scripts_basic:
327 +PHONY += scripts_basic gcc-plugins
328 +scripts_basic: gcc-plugins
329 $(Q)$(MAKE) $(build)=scripts/basic
330 $(Q)rm -f .tmp_quiet_recordmcount
331
332 @@ -579,6 +586,72 @@ else
333 KBUILD_CFLAGS += -O2
334 endif
335
336 +ifndef DISABLE_PAX_PLUGINS
337 +ifeq ($(call cc-ifversion, -ge, 0408, y), y)
338 +PLUGINCC := $(shell $(CONFIG_SHELL) $(srctree)/scripts/gcc-plugin.sh "$(HOSTCXX)" "$(HOSTCXX)" "$(CC)")
339 +else
340 +PLUGINCC := $(shell $(CONFIG_SHELL) $(srctree)/scripts/gcc-plugin.sh "$(HOSTCC)" "$(HOSTCXX)" "$(CC)")
341 +endif
342 +ifneq ($(PLUGINCC),)
343 +ifdef CONFIG_PAX_CONSTIFY_PLUGIN
344 +CONSTIFY_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/constify_plugin.so -DCONSTIFY_PLUGIN
345 +endif
346 +ifdef CONFIG_PAX_MEMORY_STACKLEAK
347 +STACKLEAK_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/stackleak_plugin.so -DSTACKLEAK_PLUGIN
348 +STACKLEAK_PLUGIN_CFLAGS += -fplugin-arg-stackleak_plugin-track-lowest-sp=100
349 +endif
350 +ifdef CONFIG_KALLOCSTAT_PLUGIN
351 +KALLOCSTAT_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/kallocstat_plugin.so
352 +endif
353 +ifdef CONFIG_PAX_KERNEXEC_PLUGIN
354 +KERNEXEC_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/kernexec_plugin.so
355 +KERNEXEC_PLUGIN_CFLAGS += -fplugin-arg-kernexec_plugin-method=$(CONFIG_PAX_KERNEXEC_PLUGIN_METHOD) -DKERNEXEC_PLUGIN
356 +KERNEXEC_PLUGIN_AFLAGS := -DKERNEXEC_PLUGIN
357 +endif
358 +ifdef CONFIG_GRKERNSEC_RANDSTRUCT
359 +RANDSTRUCT_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/randomize_layout_plugin.so -DRANDSTRUCT_PLUGIN
360 +ifdef CONFIG_GRKERNSEC_RANDSTRUCT_PERFORMANCE
361 +RANDSTRUCT_PLUGIN_CFLAGS += -fplugin-arg-randomize_layout_plugin-performance-mode
362 +endif
363 +endif
364 +ifdef CONFIG_CHECKER_PLUGIN
365 +ifeq ($(call cc-ifversion, -ge, 0406, y), y)
366 +CHECKER_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/checker_plugin.so -DCHECKER_PLUGIN
367 +endif
368 +endif
369 +COLORIZE_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/colorize_plugin.so
370 +ifdef CONFIG_PAX_SIZE_OVERFLOW
371 +SIZE_OVERFLOW_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/size_overflow_plugin.so -DSIZE_OVERFLOW_PLUGIN
372 +endif
373 +ifdef CONFIG_PAX_LATENT_ENTROPY
374 +LATENT_ENTROPY_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/latent_entropy_plugin.so -DLATENT_ENTROPY_PLUGIN
375 +endif
376 +ifdef CONFIG_PAX_MEMORY_STRUCTLEAK
377 +STRUCTLEAK_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/structleak_plugin.so -DSTRUCTLEAK_PLUGIN
378 +endif
379 +GCC_PLUGINS_CFLAGS := $(CONSTIFY_PLUGIN_CFLAGS) $(STACKLEAK_PLUGIN_CFLAGS) $(KALLOCSTAT_PLUGIN_CFLAGS)
380 +GCC_PLUGINS_CFLAGS += $(KERNEXEC_PLUGIN_CFLAGS) $(CHECKER_PLUGIN_CFLAGS) $(COLORIZE_PLUGIN_CFLAGS)
381 +GCC_PLUGINS_CFLAGS += $(SIZE_OVERFLOW_PLUGIN_CFLAGS) $(LATENT_ENTROPY_PLUGIN_CFLAGS) $(STRUCTLEAK_PLUGIN_CFLAGS)
382 +GCC_PLUGINS_CFLAGS += $(RANDSTRUCT_PLUGIN_CFLAGS)
383 +GCC_PLUGINS_AFLAGS := $(KERNEXEC_PLUGIN_AFLAGS)
384 +export PLUGINCC GCC_PLUGINS_CFLAGS GCC_PLUGINS_AFLAGS CONSTIFY_PLUGIN LATENT_ENTROPY_PLUGIN_CFLAGS
385 +ifeq ($(KBUILD_EXTMOD),)
386 +gcc-plugins:
387 + $(Q)$(MAKE) $(build)=tools/gcc
388 +else
389 +gcc-plugins: ;
390 +endif
391 +else
392 +gcc-plugins:
393 +ifeq ($(call cc-ifversion, -ge, 0405, y), y)
394 + $(error Your gcc installation does not support plugins. If the necessary headers for plugin support are missing, they should be installed. On Debian, apt-get install gcc-<ver>-plugin-dev. If you choose to ignore this error and lessen the improvements provided by this patch, re-run make with the DISABLE_PAX_PLUGINS=y argument.))
395 +else
396 + $(Q)echo "warning, your gcc version does not support plugins, you should upgrade it to gcc 4.5 at least"
397 +endif
398 + $(Q)echo "PAX_MEMORY_STACKLEAK, constification, PAX_LATENT_ENTROPY and other features will be less secure. PAX_SIZE_OVERFLOW will not be active."
399 +endif
400 +endif
401 +
402 include $(srctree)/arch/$(SRCARCH)/Makefile
403
404 ifdef CONFIG_READABLE_ASM
405 @@ -619,7 +692,7 @@ endif
406
407 ifdef CONFIG_DEBUG_INFO
408 KBUILD_CFLAGS += -g
409 -KBUILD_AFLAGS += -gdwarf-2
410 +KBUILD_AFLAGS += -Wa,--gdwarf-2
411 endif
412
413 ifdef CONFIG_DEBUG_INFO_REDUCED
414 @@ -754,7 +827,7 @@ export mod_sign_cmd
415
416
417 ifeq ($(KBUILD_EXTMOD),)
418 -core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/
419 +core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/ grsecurity/
420
421 vmlinux-dirs := $(patsubst %/,%,$(filter %/, $(init-y) $(init-m) \
422 $(core-y) $(core-m) $(drivers-y) $(drivers-m) \
423 @@ -803,6 +876,8 @@ endif
424
425 # The actual objects are generated when descending,
426 # make sure no implicit rule kicks in
427 +$(filter-out $(init-y),$(vmlinux-deps)): KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
428 +$(filter-out $(init-y),$(vmlinux-deps)): KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
429 $(sort $(vmlinux-deps)): $(vmlinux-dirs) ;
430
431 # Handle descending into subdirectories listed in $(vmlinux-dirs)
432 @@ -812,7 +887,7 @@ $(sort $(vmlinux-deps)): $(vmlinux-dirs) ;
433 # Error messages still appears in the original language
434
435 PHONY += $(vmlinux-dirs)
436 -$(vmlinux-dirs): prepare scripts
437 +$(vmlinux-dirs): gcc-plugins prepare scripts
438 $(Q)$(MAKE) $(build)=$@
439
440 define filechk_kernel.release
441 @@ -855,10 +930,13 @@ prepare1: prepare2 $(version_h) include/generated/utsrelease.h \
442
443 archprepare: archheaders archscripts prepare1 scripts_basic
444
445 +prepare0: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
446 +prepare0: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
447 prepare0: archprepare FORCE
448 $(Q)$(MAKE) $(build)=.
449
450 # All the preparing..
451 +prepare: KBUILD_CFLAGS := $(filter-out $(GCC_PLUGINS_CFLAGS),$(KBUILD_CFLAGS))
452 prepare: prepare0
453
454 # Generate some files
455 @@ -966,6 +1044,8 @@ all: modules
456 # using awk while concatenating to the final file.
457
458 PHONY += modules
459 +modules: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
460 +modules: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
461 modules: $(vmlinux-dirs) $(if $(KBUILD_BUILTIN),vmlinux) modules.builtin
462 $(Q)$(AWK) '!x[$$0]++' $(vmlinux-dirs:%=$(objtree)/%/modules.order) > $(objtree)/modules.order
463 @$(kecho) ' Building modules, stage 2.';
464 @@ -981,7 +1061,7 @@ modules.builtin: $(vmlinux-dirs:%=%/modules.builtin)
465
466 # Target to prepare building external modules
467 PHONY += modules_prepare
468 -modules_prepare: prepare scripts
469 +modules_prepare: gcc-plugins prepare scripts
470
471 # Target to install modules
472 PHONY += modules_install
473 @@ -1047,7 +1127,8 @@ MRPROPER_FILES += .config .config.old .version .old_version $(version_h) \
474 Module.symvers tags TAGS cscope* GPATH GTAGS GRTAGS GSYMS \
475 signing_key.priv signing_key.x509 x509.genkey \
476 extra_certificates signing_key.x509.keyid \
477 - signing_key.x509.signer
478 + signing_key.x509.signer tools/gcc/size_overflow_hash.h \
479 + tools/gcc/randomize_layout_seed.h
480
481 # clean - Delete most, but leave enough to build external modules
482 #
483 @@ -1087,6 +1168,7 @@ distclean: mrproper
484 \( -name '*.orig' -o -name '*.rej' -o -name '*~' \
485 -o -name '*.bak' -o -name '#*#' -o -name '.*.orig' \
486 -o -name '.*.rej' \
487 + -o -name '.*.rej' -o -name '*.so' \
488 -o -name '*%' -o -name '.*.cmd' -o -name 'core' \) \
489 -type f -print | xargs rm -f
490
491 @@ -1248,6 +1330,8 @@ PHONY += $(module-dirs) modules
492 $(module-dirs): crmodverdir $(objtree)/Module.symvers
493 $(Q)$(MAKE) $(build)=$(patsubst _module_%,%,$@)
494
495 +modules: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
496 +modules: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
497 modules: $(module-dirs)
498 @$(kecho) ' Building modules, stage 2.';
499 $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modpost
500 @@ -1387,17 +1471,21 @@ else
501 target-dir = $(if $(KBUILD_EXTMOD),$(dir $<),$(dir $@))
502 endif
503
504 -%.s: %.c prepare scripts FORCE
505 +%.s: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
506 +%.s: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
507 +%.s: %.c gcc-plugins prepare scripts FORCE
508 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
509 %.i: %.c prepare scripts FORCE
510 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
511 -%.o: %.c prepare scripts FORCE
512 +%.o: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
513 +%.o: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
514 +%.o: %.c gcc-plugins prepare scripts FORCE
515 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
516 %.lst: %.c prepare scripts FORCE
517 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
518 -%.s: %.S prepare scripts FORCE
519 +%.s: %.S gcc-plugins prepare scripts FORCE
520 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
521 -%.o: %.S prepare scripts FORCE
522 +%.o: %.S gcc-plugins prepare scripts FORCE
523 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
524 %.symtypes: %.c prepare scripts FORCE
525 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
526 @@ -1407,11 +1495,15 @@ endif
527 $(cmd_crmodverdir)
528 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
529 $(build)=$(build-dir)
530 -%/: prepare scripts FORCE
531 +%/: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
532 +%/: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
533 +%/: gcc-plugins prepare scripts FORCE
534 $(cmd_crmodverdir)
535 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
536 $(build)=$(build-dir)
537 -%.ko: prepare scripts FORCE
538 +%.ko: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
539 +%.ko: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
540 +%.ko: gcc-plugins prepare scripts FORCE
541 $(cmd_crmodverdir)
542 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
543 $(build)=$(build-dir) $(@:.ko=.o)
544 diff --git a/arch/alpha/include/asm/atomic.h b/arch/alpha/include/asm/atomic.h
545 index 78b03ef..da28a51 100644
546 --- a/arch/alpha/include/asm/atomic.h
547 +++ b/arch/alpha/include/asm/atomic.h
548 @@ -292,6 +292,16 @@ static inline long atomic64_dec_if_positive(atomic64_t *v)
549 #define atomic_dec(v) atomic_sub(1,(v))
550 #define atomic64_dec(v) atomic64_sub(1,(v))
551
552 +#define atomic64_read_unchecked(v) atomic64_read(v)
553 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
554 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
555 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
556 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
557 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
558 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
559 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
560 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
561 +
562 #define smp_mb__before_atomic_dec() smp_mb()
563 #define smp_mb__after_atomic_dec() smp_mb()
564 #define smp_mb__before_atomic_inc() smp_mb()
565 diff --git a/arch/alpha/include/asm/cache.h b/arch/alpha/include/asm/cache.h
566 index ad368a9..fbe0f25 100644
567 --- a/arch/alpha/include/asm/cache.h
568 +++ b/arch/alpha/include/asm/cache.h
569 @@ -4,19 +4,19 @@
570 #ifndef __ARCH_ALPHA_CACHE_H
571 #define __ARCH_ALPHA_CACHE_H
572
573 +#include <linux/const.h>
574
575 /* Bytes per L1 (data) cache line. */
576 #if defined(CONFIG_ALPHA_GENERIC) || defined(CONFIG_ALPHA_EV6)
577 -# define L1_CACHE_BYTES 64
578 # define L1_CACHE_SHIFT 6
579 #else
580 /* Both EV4 and EV5 are write-through, read-allocate,
581 direct-mapped, physical.
582 */
583 -# define L1_CACHE_BYTES 32
584 # define L1_CACHE_SHIFT 5
585 #endif
586
587 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
588 #define SMP_CACHE_BYTES L1_CACHE_BYTES
589
590 #endif
591 diff --git a/arch/alpha/include/asm/elf.h b/arch/alpha/include/asm/elf.h
592 index 968d999..d36b2df 100644
593 --- a/arch/alpha/include/asm/elf.h
594 +++ b/arch/alpha/include/asm/elf.h
595 @@ -91,6 +91,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
596
597 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x1000000)
598
599 +#ifdef CONFIG_PAX_ASLR
600 +#define PAX_ELF_ET_DYN_BASE (current->personality & ADDR_LIMIT_32BIT ? 0x10000 : 0x120000000UL)
601 +
602 +#define PAX_DELTA_MMAP_LEN (current->personality & ADDR_LIMIT_32BIT ? 14 : 28)
603 +#define PAX_DELTA_STACK_LEN (current->personality & ADDR_LIMIT_32BIT ? 14 : 19)
604 +#endif
605 +
606 /* $0 is set by ld.so to a pointer to a function which might be
607 registered using atexit. This provides a mean for the dynamic
608 linker to call DT_FINI functions for shared libraries that have
609 diff --git a/arch/alpha/include/asm/pgalloc.h b/arch/alpha/include/asm/pgalloc.h
610 index aab14a0..b4fa3e7 100644
611 --- a/arch/alpha/include/asm/pgalloc.h
612 +++ b/arch/alpha/include/asm/pgalloc.h
613 @@ -29,6 +29,12 @@ pgd_populate(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
614 pgd_set(pgd, pmd);
615 }
616
617 +static inline void
618 +pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
619 +{
620 + pgd_populate(mm, pgd, pmd);
621 +}
622 +
623 extern pgd_t *pgd_alloc(struct mm_struct *mm);
624
625 static inline void
626 diff --git a/arch/alpha/include/asm/pgtable.h b/arch/alpha/include/asm/pgtable.h
627 index d8f9b7e..f6222fa 100644
628 --- a/arch/alpha/include/asm/pgtable.h
629 +++ b/arch/alpha/include/asm/pgtable.h
630 @@ -102,6 +102,17 @@ struct vm_area_struct;
631 #define PAGE_SHARED __pgprot(_PAGE_VALID | __ACCESS_BITS)
632 #define PAGE_COPY __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW)
633 #define PAGE_READONLY __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW)
634 +
635 +#ifdef CONFIG_PAX_PAGEEXEC
636 +# define PAGE_SHARED_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOE)
637 +# define PAGE_COPY_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW | _PAGE_FOE)
638 +# define PAGE_READONLY_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW | _PAGE_FOE)
639 +#else
640 +# define PAGE_SHARED_NOEXEC PAGE_SHARED
641 +# define PAGE_COPY_NOEXEC PAGE_COPY
642 +# define PAGE_READONLY_NOEXEC PAGE_READONLY
643 +#endif
644 +
645 #define PAGE_KERNEL __pgprot(_PAGE_VALID | _PAGE_ASM | _PAGE_KRE | _PAGE_KWE)
646
647 #define _PAGE_NORMAL(x) __pgprot(_PAGE_VALID | __ACCESS_BITS | (x))
648 diff --git a/arch/alpha/kernel/module.c b/arch/alpha/kernel/module.c
649 index 2fd00b7..cfd5069 100644
650 --- a/arch/alpha/kernel/module.c
651 +++ b/arch/alpha/kernel/module.c
652 @@ -160,7 +160,7 @@ apply_relocate_add(Elf64_Shdr *sechdrs, const char *strtab,
653
654 /* The small sections were sorted to the end of the segment.
655 The following should definitely cover them. */
656 - gp = (u64)me->module_core + me->core_size - 0x8000;
657 + gp = (u64)me->module_core_rw + me->core_size_rw - 0x8000;
658 got = sechdrs[me->arch.gotsecindex].sh_addr;
659
660 for (i = 0; i < n; i++) {
661 diff --git a/arch/alpha/kernel/osf_sys.c b/arch/alpha/kernel/osf_sys.c
662 index 1402fcc..0b1abd2 100644
663 --- a/arch/alpha/kernel/osf_sys.c
664 +++ b/arch/alpha/kernel/osf_sys.c
665 @@ -1298,10 +1298,11 @@ SYSCALL_DEFINE1(old_adjtimex, struct timex32 __user *, txc_p)
666 generic version except that we know how to honor ADDR_LIMIT_32BIT. */
667
668 static unsigned long
669 -arch_get_unmapped_area_1(unsigned long addr, unsigned long len,
670 - unsigned long limit)
671 +arch_get_unmapped_area_1(struct file *filp, unsigned long addr, unsigned long len,
672 + unsigned long limit, unsigned long flags)
673 {
674 struct vm_unmapped_area_info info;
675 + unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
676
677 info.flags = 0;
678 info.length = len;
679 @@ -1309,6 +1310,7 @@ arch_get_unmapped_area_1(unsigned long addr, unsigned long len,
680 info.high_limit = limit;
681 info.align_mask = 0;
682 info.align_offset = 0;
683 + info.threadstack_offset = offset;
684 return vm_unmapped_area(&info);
685 }
686
687 @@ -1341,20 +1343,24 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
688 merely specific addresses, but regions of memory -- perhaps
689 this feature should be incorporated into all ports? */
690
691 +#ifdef CONFIG_PAX_RANDMMAP
692 + if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
693 +#endif
694 +
695 if (addr) {
696 - addr = arch_get_unmapped_area_1 (PAGE_ALIGN(addr), len, limit);
697 + addr = arch_get_unmapped_area_1 (filp, PAGE_ALIGN(addr), len, limit, flags);
698 if (addr != (unsigned long) -ENOMEM)
699 return addr;
700 }
701
702 /* Next, try allocating at TASK_UNMAPPED_BASE. */
703 - addr = arch_get_unmapped_area_1 (PAGE_ALIGN(TASK_UNMAPPED_BASE),
704 - len, limit);
705 + addr = arch_get_unmapped_area_1 (filp, PAGE_ALIGN(current->mm->mmap_base), len, limit, flags);
706 +
707 if (addr != (unsigned long) -ENOMEM)
708 return addr;
709
710 /* Finally, try allocating in low memory. */
711 - addr = arch_get_unmapped_area_1 (PAGE_SIZE, len, limit);
712 + addr = arch_get_unmapped_area_1 (filp, PAGE_SIZE, len, limit, flags);
713
714 return addr;
715 }
716 diff --git a/arch/alpha/mm/fault.c b/arch/alpha/mm/fault.c
717 index 98838a0..b304fb4 100644
718 --- a/arch/alpha/mm/fault.c
719 +++ b/arch/alpha/mm/fault.c
720 @@ -53,6 +53,124 @@ __load_new_mm_context(struct mm_struct *next_mm)
721 __reload_thread(pcb);
722 }
723
724 +#ifdef CONFIG_PAX_PAGEEXEC
725 +/*
726 + * PaX: decide what to do with offenders (regs->pc = fault address)
727 + *
728 + * returns 1 when task should be killed
729 + * 2 when patched PLT trampoline was detected
730 + * 3 when unpatched PLT trampoline was detected
731 + */
732 +static int pax_handle_fetch_fault(struct pt_regs *regs)
733 +{
734 +
735 +#ifdef CONFIG_PAX_EMUPLT
736 + int err;
737 +
738 + do { /* PaX: patched PLT emulation #1 */
739 + unsigned int ldah, ldq, jmp;
740 +
741 + err = get_user(ldah, (unsigned int *)regs->pc);
742 + err |= get_user(ldq, (unsigned int *)(regs->pc+4));
743 + err |= get_user(jmp, (unsigned int *)(regs->pc+8));
744 +
745 + if (err)
746 + break;
747 +
748 + if ((ldah & 0xFFFF0000U) == 0x277B0000U &&
749 + (ldq & 0xFFFF0000U) == 0xA77B0000U &&
750 + jmp == 0x6BFB0000U)
751 + {
752 + unsigned long r27, addr;
753 + unsigned long addrh = (ldah | 0xFFFFFFFFFFFF0000UL) << 16;
754 + unsigned long addrl = ldq | 0xFFFFFFFFFFFF0000UL;
755 +
756 + addr = regs->r27 + ((addrh ^ 0x80000000UL) + 0x80000000UL) + ((addrl ^ 0x8000UL) + 0x8000UL);
757 + err = get_user(r27, (unsigned long *)addr);
758 + if (err)
759 + break;
760 +
761 + regs->r27 = r27;
762 + regs->pc = r27;
763 + return 2;
764 + }
765 + } while (0);
766 +
767 + do { /* PaX: patched PLT emulation #2 */
768 + unsigned int ldah, lda, br;
769 +
770 + err = get_user(ldah, (unsigned int *)regs->pc);
771 + err |= get_user(lda, (unsigned int *)(regs->pc+4));
772 + err |= get_user(br, (unsigned int *)(regs->pc+8));
773 +
774 + if (err)
775 + break;
776 +
777 + if ((ldah & 0xFFFF0000U) == 0x277B0000U &&
778 + (lda & 0xFFFF0000U) == 0xA77B0000U &&
779 + (br & 0xFFE00000U) == 0xC3E00000U)
780 + {
781 + unsigned long addr = br | 0xFFFFFFFFFFE00000UL;
782 + unsigned long addrh = (ldah | 0xFFFFFFFFFFFF0000UL) << 16;
783 + unsigned long addrl = lda | 0xFFFFFFFFFFFF0000UL;
784 +
785 + regs->r27 += ((addrh ^ 0x80000000UL) + 0x80000000UL) + ((addrl ^ 0x8000UL) + 0x8000UL);
786 + regs->pc += 12 + (((addr ^ 0x00100000UL) + 0x00100000UL) << 2);
787 + return 2;
788 + }
789 + } while (0);
790 +
791 + do { /* PaX: unpatched PLT emulation */
792 + unsigned int br;
793 +
794 + err = get_user(br, (unsigned int *)regs->pc);
795 +
796 + if (!err && (br & 0xFFE00000U) == 0xC3800000U) {
797 + unsigned int br2, ldq, nop, jmp;
798 + unsigned long addr = br | 0xFFFFFFFFFFE00000UL, resolver;
799 +
800 + addr = regs->pc + 4 + (((addr ^ 0x00100000UL) + 0x00100000UL) << 2);
801 + err = get_user(br2, (unsigned int *)addr);
802 + err |= get_user(ldq, (unsigned int *)(addr+4));
803 + err |= get_user(nop, (unsigned int *)(addr+8));
804 + err |= get_user(jmp, (unsigned int *)(addr+12));
805 + err |= get_user(resolver, (unsigned long *)(addr+16));
806 +
807 + if (err)
808 + break;
809 +
810 + if (br2 == 0xC3600000U &&
811 + ldq == 0xA77B000CU &&
812 + nop == 0x47FF041FU &&
813 + jmp == 0x6B7B0000U)
814 + {
815 + regs->r28 = regs->pc+4;
816 + regs->r27 = addr+16;
817 + regs->pc = resolver;
818 + return 3;
819 + }
820 + }
821 + } while (0);
822 +#endif
823 +
824 + return 1;
825 +}
826 +
827 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
828 +{
829 + unsigned long i;
830 +
831 + printk(KERN_ERR "PAX: bytes at PC: ");
832 + for (i = 0; i < 5; i++) {
833 + unsigned int c;
834 + if (get_user(c, (unsigned int *)pc+i))
835 + printk(KERN_CONT "???????? ");
836 + else
837 + printk(KERN_CONT "%08x ", c);
838 + }
839 + printk("\n");
840 +}
841 +#endif
842
843 /*
844 * This routine handles page faults. It determines the address,
845 @@ -133,8 +251,29 @@ retry:
846 good_area:
847 si_code = SEGV_ACCERR;
848 if (cause < 0) {
849 - if (!(vma->vm_flags & VM_EXEC))
850 + if (!(vma->vm_flags & VM_EXEC)) {
851 +
852 +#ifdef CONFIG_PAX_PAGEEXEC
853 + if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || address != regs->pc)
854 + goto bad_area;
855 +
856 + up_read(&mm->mmap_sem);
857 + switch (pax_handle_fetch_fault(regs)) {
858 +
859 +#ifdef CONFIG_PAX_EMUPLT
860 + case 2:
861 + case 3:
862 + return;
863 +#endif
864 +
865 + }
866 + pax_report_fault(regs, (void *)regs->pc, (void *)rdusp());
867 + do_group_exit(SIGKILL);
868 +#else
869 goto bad_area;
870 +#endif
871 +
872 + }
873 } else if (!cause) {
874 /* Allow reads even for write-only mappings */
875 if (!(vma->vm_flags & (VM_READ | VM_WRITE)))
876 diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig
877 index 47085a0..f975a53 100644
878 --- a/arch/arm/Kconfig
879 +++ b/arch/arm/Kconfig
880 @@ -1830,7 +1830,7 @@ config ALIGNMENT_TRAP
881
882 config UACCESS_WITH_MEMCPY
883 bool "Use kernel mem{cpy,set}() for {copy_to,clear}_user()"
884 - depends on MMU
885 + depends on MMU && !PAX_MEMORY_UDEREF
886 default y if CPU_FEROCEON
887 help
888 Implement faster copy_to_user and clear_user methods for CPU
889 @@ -2102,6 +2102,7 @@ config XIP_PHYS_ADDR
890 config KEXEC
891 bool "Kexec system call (EXPERIMENTAL)"
892 depends on (!SMP || PM_SLEEP_SMP)
893 + depends on !GRKERNSEC_KMEM
894 help
895 kexec is a system call that implements the ability to shutdown your
896 current kernel, and to start another kernel. It is like a reboot
897 diff --git a/arch/arm/include/asm/atomic.h b/arch/arm/include/asm/atomic.h
898 index 62d2cb5..09d45e3 100644
899 --- a/arch/arm/include/asm/atomic.h
900 +++ b/arch/arm/include/asm/atomic.h
901 @@ -18,17 +18,35 @@
902 #include <asm/barrier.h>
903 #include <asm/cmpxchg.h>
904
905 +#ifdef CONFIG_GENERIC_ATOMIC64
906 +#include <asm-generic/atomic64.h>
907 +#endif
908 +
909 #define ATOMIC_INIT(i) { (i) }
910
911 #ifdef __KERNEL__
912
913 +#define _ASM_EXTABLE(from, to) \
914 +" .pushsection __ex_table,\"a\"\n"\
915 +" .align 3\n" \
916 +" .long " #from ", " #to"\n" \
917 +" .popsection"
918 +
919 /*
920 * On ARM, ordinary assignment (str instruction) doesn't clear the local
921 * strex/ldrex monitor on some implementations. The reason we can use it for
922 * atomic_set() is the clrex or dummy strex done on every exception return.
923 */
924 #define atomic_read(v) (*(volatile int *)&(v)->counter)
925 +static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
926 +{
927 + return v->counter;
928 +}
929 #define atomic_set(v,i) (((v)->counter) = (i))
930 +static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
931 +{
932 + v->counter = i;
933 +}
934
935 #if __LINUX_ARM_ARCH__ >= 6
936
937 @@ -44,6 +62,36 @@ static inline void atomic_add(int i, atomic_t *v)
938
939 prefetchw(&v->counter);
940 __asm__ __volatile__("@ atomic_add\n"
941 +"1: ldrex %1, [%3]\n"
942 +" adds %0, %1, %4\n"
943 +
944 +#ifdef CONFIG_PAX_REFCOUNT
945 +" bvc 3f\n"
946 +"2: bkpt 0xf103\n"
947 +"3:\n"
948 +#endif
949 +
950 +" strex %1, %0, [%3]\n"
951 +" teq %1, #0\n"
952 +" bne 1b"
953 +
954 +#ifdef CONFIG_PAX_REFCOUNT
955 +"\n4:\n"
956 + _ASM_EXTABLE(2b, 4b)
957 +#endif
958 +
959 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
960 + : "r" (&v->counter), "Ir" (i)
961 + : "cc");
962 +}
963 +
964 +static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
965 +{
966 + unsigned long tmp;
967 + int result;
968 +
969 + prefetchw(&v->counter);
970 + __asm__ __volatile__("@ atomic_add_unchecked\n"
971 "1: ldrex %0, [%3]\n"
972 " add %0, %0, %4\n"
973 " strex %1, %0, [%3]\n"
974 @@ -62,6 +110,42 @@ static inline int atomic_add_return(int i, atomic_t *v)
975 smp_mb();
976
977 __asm__ __volatile__("@ atomic_add_return\n"
978 +"1: ldrex %1, [%3]\n"
979 +" adds %0, %1, %4\n"
980 +
981 +#ifdef CONFIG_PAX_REFCOUNT
982 +" bvc 3f\n"
983 +" mov %0, %1\n"
984 +"2: bkpt 0xf103\n"
985 +"3:\n"
986 +#endif
987 +
988 +" strex %1, %0, [%3]\n"
989 +" teq %1, #0\n"
990 +" bne 1b"
991 +
992 +#ifdef CONFIG_PAX_REFCOUNT
993 +"\n4:\n"
994 + _ASM_EXTABLE(2b, 4b)
995 +#endif
996 +
997 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
998 + : "r" (&v->counter), "Ir" (i)
999 + : "cc");
1000 +
1001 + smp_mb();
1002 +
1003 + return result;
1004 +}
1005 +
1006 +static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
1007 +{
1008 + unsigned long tmp;
1009 + int result;
1010 +
1011 + smp_mb();
1012 +
1013 + __asm__ __volatile__("@ atomic_add_return_unchecked\n"
1014 "1: ldrex %0, [%3]\n"
1015 " add %0, %0, %4\n"
1016 " strex %1, %0, [%3]\n"
1017 @@ -83,6 +167,36 @@ static inline void atomic_sub(int i, atomic_t *v)
1018
1019 prefetchw(&v->counter);
1020 __asm__ __volatile__("@ atomic_sub\n"
1021 +"1: ldrex %1, [%3]\n"
1022 +" subs %0, %1, %4\n"
1023 +
1024 +#ifdef CONFIG_PAX_REFCOUNT
1025 +" bvc 3f\n"
1026 +"2: bkpt 0xf103\n"
1027 +"3:\n"
1028 +#endif
1029 +
1030 +" strex %1, %0, [%3]\n"
1031 +" teq %1, #0\n"
1032 +" bne 1b"
1033 +
1034 +#ifdef CONFIG_PAX_REFCOUNT
1035 +"\n4:\n"
1036 + _ASM_EXTABLE(2b, 4b)
1037 +#endif
1038 +
1039 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1040 + : "r" (&v->counter), "Ir" (i)
1041 + : "cc");
1042 +}
1043 +
1044 +static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
1045 +{
1046 + unsigned long tmp;
1047 + int result;
1048 +
1049 + prefetchw(&v->counter);
1050 + __asm__ __volatile__("@ atomic_sub_unchecked\n"
1051 "1: ldrex %0, [%3]\n"
1052 " sub %0, %0, %4\n"
1053 " strex %1, %0, [%3]\n"
1054 @@ -101,11 +215,25 @@ static inline int atomic_sub_return(int i, atomic_t *v)
1055 smp_mb();
1056
1057 __asm__ __volatile__("@ atomic_sub_return\n"
1058 -"1: ldrex %0, [%3]\n"
1059 -" sub %0, %0, %4\n"
1060 +"1: ldrex %1, [%3]\n"
1061 +" subs %0, %1, %4\n"
1062 +
1063 +#ifdef CONFIG_PAX_REFCOUNT
1064 +" bvc 3f\n"
1065 +" mov %0, %1\n"
1066 +"2: bkpt 0xf103\n"
1067 +"3:\n"
1068 +#endif
1069 +
1070 " strex %1, %0, [%3]\n"
1071 " teq %1, #0\n"
1072 " bne 1b"
1073 +
1074 +#ifdef CONFIG_PAX_REFCOUNT
1075 +"\n4:\n"
1076 + _ASM_EXTABLE(2b, 4b)
1077 +#endif
1078 +
1079 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1080 : "r" (&v->counter), "Ir" (i)
1081 : "cc");
1082 @@ -138,6 +266,28 @@ static inline int atomic_cmpxchg(atomic_t *ptr, int old, int new)
1083 return oldval;
1084 }
1085
1086 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *ptr, int old, int new)
1087 +{
1088 + unsigned long oldval, res;
1089 +
1090 + smp_mb();
1091 +
1092 + do {
1093 + __asm__ __volatile__("@ atomic_cmpxchg_unchecked\n"
1094 + "ldrex %1, [%3]\n"
1095 + "mov %0, #0\n"
1096 + "teq %1, %4\n"
1097 + "strexeq %0, %5, [%3]\n"
1098 + : "=&r" (res), "=&r" (oldval), "+Qo" (ptr->counter)
1099 + : "r" (&ptr->counter), "Ir" (old), "r" (new)
1100 + : "cc");
1101 + } while (res);
1102 +
1103 + smp_mb();
1104 +
1105 + return oldval;
1106 +}
1107 +
1108 #else /* ARM_ARCH_6 */
1109
1110 #ifdef CONFIG_SMP
1111 @@ -156,7 +306,17 @@ static inline int atomic_add_return(int i, atomic_t *v)
1112
1113 return val;
1114 }
1115 +
1116 +static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
1117 +{
1118 + return atomic_add_return(i, v);
1119 +}
1120 +
1121 #define atomic_add(i, v) (void) atomic_add_return(i, v)
1122 +static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
1123 +{
1124 + (void) atomic_add_return(i, v);
1125 +}
1126
1127 static inline int atomic_sub_return(int i, atomic_t *v)
1128 {
1129 @@ -171,6 +331,10 @@ static inline int atomic_sub_return(int i, atomic_t *v)
1130 return val;
1131 }
1132 #define atomic_sub(i, v) (void) atomic_sub_return(i, v)
1133 +static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
1134 +{
1135 + (void) atomic_sub_return(i, v);
1136 +}
1137
1138 static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
1139 {
1140 @@ -186,9 +350,18 @@ static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
1141 return ret;
1142 }
1143
1144 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
1145 +{
1146 + return atomic_cmpxchg(v, old, new);
1147 +}
1148 +
1149 #endif /* __LINUX_ARM_ARCH__ */
1150
1151 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
1152 +static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
1153 +{
1154 + return xchg(&v->counter, new);
1155 +}
1156
1157 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
1158 {
1159 @@ -201,11 +374,27 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
1160 }
1161
1162 #define atomic_inc(v) atomic_add(1, v)
1163 +static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
1164 +{
1165 + atomic_add_unchecked(1, v);
1166 +}
1167 #define atomic_dec(v) atomic_sub(1, v)
1168 +static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
1169 +{
1170 + atomic_sub_unchecked(1, v);
1171 +}
1172
1173 #define atomic_inc_and_test(v) (atomic_add_return(1, v) == 0)
1174 +static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
1175 +{
1176 + return atomic_add_return_unchecked(1, v) == 0;
1177 +}
1178 #define atomic_dec_and_test(v) (atomic_sub_return(1, v) == 0)
1179 #define atomic_inc_return(v) (atomic_add_return(1, v))
1180 +static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
1181 +{
1182 + return atomic_add_return_unchecked(1, v);
1183 +}
1184 #define atomic_dec_return(v) (atomic_sub_return(1, v))
1185 #define atomic_sub_and_test(i, v) (atomic_sub_return(i, v) == 0)
1186
1187 @@ -221,6 +410,14 @@ typedef struct {
1188 long long counter;
1189 } atomic64_t;
1190
1191 +#ifdef CONFIG_PAX_REFCOUNT
1192 +typedef struct {
1193 + long long counter;
1194 +} atomic64_unchecked_t;
1195 +#else
1196 +typedef atomic64_t atomic64_unchecked_t;
1197 +#endif
1198 +
1199 #define ATOMIC64_INIT(i) { (i) }
1200
1201 #ifdef CONFIG_ARM_LPAE
1202 @@ -237,6 +434,19 @@ static inline long long atomic64_read(const atomic64_t *v)
1203 return result;
1204 }
1205
1206 +static inline long long atomic64_read_unchecked(const atomic64_unchecked_t *v)
1207 +{
1208 + long long result;
1209 +
1210 + __asm__ __volatile__("@ atomic64_read_unchecked\n"
1211 +" ldrd %0, %H0, [%1]"
1212 + : "=&r" (result)
1213 + : "r" (&v->counter), "Qo" (v->counter)
1214 + );
1215 +
1216 + return result;
1217 +}
1218 +
1219 static inline void atomic64_set(atomic64_t *v, long long i)
1220 {
1221 __asm__ __volatile__("@ atomic64_set\n"
1222 @@ -245,6 +455,15 @@ static inline void atomic64_set(atomic64_t *v, long long i)
1223 : "r" (&v->counter), "r" (i)
1224 );
1225 }
1226 +
1227 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long long i)
1228 +{
1229 + __asm__ __volatile__("@ atomic64_set_unchecked\n"
1230 +" strd %2, %H2, [%1]"
1231 + : "=Qo" (v->counter)
1232 + : "r" (&v->counter), "r" (i)
1233 + );
1234 +}
1235 #else
1236 static inline long long atomic64_read(const atomic64_t *v)
1237 {
1238 @@ -259,6 +478,19 @@ static inline long long atomic64_read(const atomic64_t *v)
1239 return result;
1240 }
1241
1242 +static inline long long atomic64_read_unchecked(const atomic64_unchecked_t *v)
1243 +{
1244 + long long result;
1245 +
1246 + __asm__ __volatile__("@ atomic64_read_unchecked\n"
1247 +" ldrexd %0, %H0, [%1]"
1248 + : "=&r" (result)
1249 + : "r" (&v->counter), "Qo" (v->counter)
1250 + );
1251 +
1252 + return result;
1253 +}
1254 +
1255 static inline void atomic64_set(atomic64_t *v, long long i)
1256 {
1257 long long tmp;
1258 @@ -273,6 +505,21 @@ static inline void atomic64_set(atomic64_t *v, long long i)
1259 : "r" (&v->counter), "r" (i)
1260 : "cc");
1261 }
1262 +
1263 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long long i)
1264 +{
1265 + long long tmp;
1266 +
1267 + prefetchw(&v->counter);
1268 + __asm__ __volatile__("@ atomic64_set_unchecked\n"
1269 +"1: ldrexd %0, %H0, [%2]\n"
1270 +" strexd %0, %3, %H3, [%2]\n"
1271 +" teq %0, #0\n"
1272 +" bne 1b"
1273 + : "=&r" (tmp), "=Qo" (v->counter)
1274 + : "r" (&v->counter), "r" (i)
1275 + : "cc");
1276 +}
1277 #endif
1278
1279 static inline void atomic64_add(long long i, atomic64_t *v)
1280 @@ -284,6 +531,37 @@ static inline void atomic64_add(long long i, atomic64_t *v)
1281 __asm__ __volatile__("@ atomic64_add\n"
1282 "1: ldrexd %0, %H0, [%3]\n"
1283 " adds %Q0, %Q0, %Q4\n"
1284 +" adcs %R0, %R0, %R4\n"
1285 +
1286 +#ifdef CONFIG_PAX_REFCOUNT
1287 +" bvc 3f\n"
1288 +"2: bkpt 0xf103\n"
1289 +"3:\n"
1290 +#endif
1291 +
1292 +" strexd %1, %0, %H0, [%3]\n"
1293 +" teq %1, #0\n"
1294 +" bne 1b"
1295 +
1296 +#ifdef CONFIG_PAX_REFCOUNT
1297 +"\n4:\n"
1298 + _ASM_EXTABLE(2b, 4b)
1299 +#endif
1300 +
1301 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1302 + : "r" (&v->counter), "r" (i)
1303 + : "cc");
1304 +}
1305 +
1306 +static inline void atomic64_add_unchecked(long long i, atomic64_unchecked_t *v)
1307 +{
1308 + long long result;
1309 + unsigned long tmp;
1310 +
1311 + prefetchw(&v->counter);
1312 + __asm__ __volatile__("@ atomic64_add_unchecked\n"
1313 +"1: ldrexd %0, %H0, [%3]\n"
1314 +" adds %Q0, %Q0, %Q4\n"
1315 " adc %R0, %R0, %R4\n"
1316 " strexd %1, %0, %H0, [%3]\n"
1317 " teq %1, #0\n"
1318 @@ -303,6 +581,44 @@ static inline long long atomic64_add_return(long long i, atomic64_t *v)
1319 __asm__ __volatile__("@ atomic64_add_return\n"
1320 "1: ldrexd %0, %H0, [%3]\n"
1321 " adds %Q0, %Q0, %Q4\n"
1322 +" adcs %R0, %R0, %R4\n"
1323 +
1324 +#ifdef CONFIG_PAX_REFCOUNT
1325 +" bvc 3f\n"
1326 +" mov %0, %1\n"
1327 +" mov %H0, %H1\n"
1328 +"2: bkpt 0xf103\n"
1329 +"3:\n"
1330 +#endif
1331 +
1332 +" strexd %1, %0, %H0, [%3]\n"
1333 +" teq %1, #0\n"
1334 +" bne 1b"
1335 +
1336 +#ifdef CONFIG_PAX_REFCOUNT
1337 +"\n4:\n"
1338 + _ASM_EXTABLE(2b, 4b)
1339 +#endif
1340 +
1341 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1342 + : "r" (&v->counter), "r" (i)
1343 + : "cc");
1344 +
1345 + smp_mb();
1346 +
1347 + return result;
1348 +}
1349 +
1350 +static inline long long atomic64_add_return_unchecked(long long i, atomic64_unchecked_t *v)
1351 +{
1352 + long long result;
1353 + unsigned long tmp;
1354 +
1355 + smp_mb();
1356 +
1357 + __asm__ __volatile__("@ atomic64_add_return_unchecked\n"
1358 +"1: ldrexd %0, %H0, [%3]\n"
1359 +" adds %Q0, %Q0, %Q4\n"
1360 " adc %R0, %R0, %R4\n"
1361 " strexd %1, %0, %H0, [%3]\n"
1362 " teq %1, #0\n"
1363 @@ -325,6 +641,37 @@ static inline void atomic64_sub(long long i, atomic64_t *v)
1364 __asm__ __volatile__("@ atomic64_sub\n"
1365 "1: ldrexd %0, %H0, [%3]\n"
1366 " subs %Q0, %Q0, %Q4\n"
1367 +" sbcs %R0, %R0, %R4\n"
1368 +
1369 +#ifdef CONFIG_PAX_REFCOUNT
1370 +" bvc 3f\n"
1371 +"2: bkpt 0xf103\n"
1372 +"3:\n"
1373 +#endif
1374 +
1375 +" strexd %1, %0, %H0, [%3]\n"
1376 +" teq %1, #0\n"
1377 +" bne 1b"
1378 +
1379 +#ifdef CONFIG_PAX_REFCOUNT
1380 +"\n4:\n"
1381 + _ASM_EXTABLE(2b, 4b)
1382 +#endif
1383 +
1384 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1385 + : "r" (&v->counter), "r" (i)
1386 + : "cc");
1387 +}
1388 +
1389 +static inline void atomic64_sub_unchecked(long long i, atomic64_unchecked_t *v)
1390 +{
1391 + long long result;
1392 + unsigned long tmp;
1393 +
1394 + prefetchw(&v->counter);
1395 + __asm__ __volatile__("@ atomic64_sub_unchecked\n"
1396 +"1: ldrexd %0, %H0, [%3]\n"
1397 +" subs %Q0, %Q0, %Q4\n"
1398 " sbc %R0, %R0, %R4\n"
1399 " strexd %1, %0, %H0, [%3]\n"
1400 " teq %1, #0\n"
1401 @@ -344,16 +691,29 @@ static inline long long atomic64_sub_return(long long i, atomic64_t *v)
1402 __asm__ __volatile__("@ atomic64_sub_return\n"
1403 "1: ldrexd %0, %H0, [%3]\n"
1404 " subs %Q0, %Q0, %Q4\n"
1405 -" sbc %R0, %R0, %R4\n"
1406 +" sbcs %R0, %R0, %R4\n"
1407 +
1408 +#ifdef CONFIG_PAX_REFCOUNT
1409 +" bvc 3f\n"
1410 +" mov %0, %1\n"
1411 +" mov %H0, %H1\n"
1412 +"2: bkpt 0xf103\n"
1413 +"3:\n"
1414 +#endif
1415 +
1416 " strexd %1, %0, %H0, [%3]\n"
1417 " teq %1, #0\n"
1418 " bne 1b"
1419 +
1420 +#ifdef CONFIG_PAX_REFCOUNT
1421 +"\n4:\n"
1422 + _ASM_EXTABLE(2b, 4b)
1423 +#endif
1424 +
1425 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1426 : "r" (&v->counter), "r" (i)
1427 : "cc");
1428
1429 - smp_mb();
1430 -
1431 return result;
1432 }
1433
1434 @@ -382,6 +742,31 @@ static inline long long atomic64_cmpxchg(atomic64_t *ptr, long long old,
1435 return oldval;
1436 }
1437
1438 +static inline long long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *ptr, long long old,
1439 + long long new)
1440 +{
1441 + long long oldval;
1442 + unsigned long res;
1443 +
1444 + smp_mb();
1445 +
1446 + do {
1447 + __asm__ __volatile__("@ atomic64_cmpxchg_unchecked\n"
1448 + "ldrexd %1, %H1, [%3]\n"
1449 + "mov %0, #0\n"
1450 + "teq %1, %4\n"
1451 + "teqeq %H1, %H4\n"
1452 + "strexdeq %0, %5, %H5, [%3]"
1453 + : "=&r" (res), "=&r" (oldval), "+Qo" (ptr->counter)
1454 + : "r" (&ptr->counter), "r" (old), "r" (new)
1455 + : "cc");
1456 + } while (res);
1457 +
1458 + smp_mb();
1459 +
1460 + return oldval;
1461 +}
1462 +
1463 static inline long long atomic64_xchg(atomic64_t *ptr, long long new)
1464 {
1465 long long result;
1466 @@ -406,20 +791,34 @@ static inline long long atomic64_xchg(atomic64_t *ptr, long long new)
1467 static inline long long atomic64_dec_if_positive(atomic64_t *v)
1468 {
1469 long long result;
1470 - unsigned long tmp;
1471 + u64 tmp;
1472
1473 smp_mb();
1474
1475 __asm__ __volatile__("@ atomic64_dec_if_positive\n"
1476 -"1: ldrexd %0, %H0, [%3]\n"
1477 -" subs %Q0, %Q0, #1\n"
1478 -" sbc %R0, %R0, #0\n"
1479 +"1: ldrexd %1, %H1, [%3]\n"
1480 +" subs %Q0, %Q1, #1\n"
1481 +" sbcs %R0, %R1, #0\n"
1482 +
1483 +#ifdef CONFIG_PAX_REFCOUNT
1484 +" bvc 3f\n"
1485 +" mov %Q0, %Q1\n"
1486 +" mov %R0, %R1\n"
1487 +"2: bkpt 0xf103\n"
1488 +"3:\n"
1489 +#endif
1490 +
1491 " teq %R0, #0\n"
1492 -" bmi 2f\n"
1493 +" bmi 4f\n"
1494 " strexd %1, %0, %H0, [%3]\n"
1495 " teq %1, #0\n"
1496 " bne 1b\n"
1497 -"2:"
1498 +"4:\n"
1499 +
1500 +#ifdef CONFIG_PAX_REFCOUNT
1501 + _ASM_EXTABLE(2b, 4b)
1502 +#endif
1503 +
1504 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1505 : "r" (&v->counter)
1506 : "cc");
1507 @@ -442,13 +841,25 @@ static inline int atomic64_add_unless(atomic64_t *v, long long a, long long u)
1508 " teq %0, %5\n"
1509 " teqeq %H0, %H5\n"
1510 " moveq %1, #0\n"
1511 -" beq 2f\n"
1512 +" beq 4f\n"
1513 " adds %Q0, %Q0, %Q6\n"
1514 -" adc %R0, %R0, %R6\n"
1515 +" adcs %R0, %R0, %R6\n"
1516 +
1517 +#ifdef CONFIG_PAX_REFCOUNT
1518 +" bvc 3f\n"
1519 +"2: bkpt 0xf103\n"
1520 +"3:\n"
1521 +#endif
1522 +
1523 " strexd %2, %0, %H0, [%4]\n"
1524 " teq %2, #0\n"
1525 " bne 1b\n"
1526 -"2:"
1527 +"4:\n"
1528 +
1529 +#ifdef CONFIG_PAX_REFCOUNT
1530 + _ASM_EXTABLE(2b, 4b)
1531 +#endif
1532 +
1533 : "=&r" (val), "+r" (ret), "=&r" (tmp), "+Qo" (v->counter)
1534 : "r" (&v->counter), "r" (u), "r" (a)
1535 : "cc");
1536 @@ -461,10 +872,13 @@ static inline int atomic64_add_unless(atomic64_t *v, long long a, long long u)
1537
1538 #define atomic64_add_negative(a, v) (atomic64_add_return((a), (v)) < 0)
1539 #define atomic64_inc(v) atomic64_add(1LL, (v))
1540 +#define atomic64_inc_unchecked(v) atomic64_add_unchecked(1LL, (v))
1541 #define atomic64_inc_return(v) atomic64_add_return(1LL, (v))
1542 +#define atomic64_inc_return_unchecked(v) atomic64_add_return_unchecked(1LL, (v))
1543 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
1544 #define atomic64_sub_and_test(a, v) (atomic64_sub_return((a), (v)) == 0)
1545 #define atomic64_dec(v) atomic64_sub(1LL, (v))
1546 +#define atomic64_dec_unchecked(v) atomic64_sub_unchecked(1LL, (v))
1547 #define atomic64_dec_return(v) atomic64_sub_return(1LL, (v))
1548 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
1549 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
1550 diff --git a/arch/arm/include/asm/cache.h b/arch/arm/include/asm/cache.h
1551 index 75fe66b..ba3dee4 100644
1552 --- a/arch/arm/include/asm/cache.h
1553 +++ b/arch/arm/include/asm/cache.h
1554 @@ -4,8 +4,10 @@
1555 #ifndef __ASMARM_CACHE_H
1556 #define __ASMARM_CACHE_H
1557
1558 +#include <linux/const.h>
1559 +
1560 #define L1_CACHE_SHIFT CONFIG_ARM_L1_CACHE_SHIFT
1561 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
1562 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
1563
1564 /*
1565 * Memory returned by kmalloc() may be used for DMA, so we must make
1566 @@ -24,5 +26,6 @@
1567 #endif
1568
1569 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
1570 +#define __read_only __attribute__ ((__section__(".data..read_only")))
1571
1572 #endif
1573 diff --git a/arch/arm/include/asm/cacheflush.h b/arch/arm/include/asm/cacheflush.h
1574 index ab91ebb..2c2afeb 100644
1575 --- a/arch/arm/include/asm/cacheflush.h
1576 +++ b/arch/arm/include/asm/cacheflush.h
1577 @@ -116,7 +116,7 @@ struct cpu_cache_fns {
1578 void (*dma_unmap_area)(const void *, size_t, int);
1579
1580 void (*dma_flush_range)(const void *, const void *);
1581 -};
1582 +} __no_const;
1583
1584 /*
1585 * Select the calling method
1586 diff --git a/arch/arm/include/asm/checksum.h b/arch/arm/include/asm/checksum.h
1587 index 6dcc164..b14d917 100644
1588 --- a/arch/arm/include/asm/checksum.h
1589 +++ b/arch/arm/include/asm/checksum.h
1590 @@ -37,7 +37,19 @@ __wsum
1591 csum_partial_copy_nocheck(const void *src, void *dst, int len, __wsum sum);
1592
1593 __wsum
1594 -csum_partial_copy_from_user(const void __user *src, void *dst, int len, __wsum sum, int *err_ptr);
1595 +__csum_partial_copy_from_user(const void __user *src, void *dst, int len, __wsum sum, int *err_ptr);
1596 +
1597 +static inline __wsum
1598 +csum_partial_copy_from_user(const void __user *src, void *dst, int len, __wsum sum, int *err_ptr)
1599 +{
1600 + __wsum ret;
1601 + pax_open_userland();
1602 + ret = __csum_partial_copy_from_user(src, dst, len, sum, err_ptr);
1603 + pax_close_userland();
1604 + return ret;
1605 +}
1606 +
1607 +
1608
1609 /*
1610 * Fold a partial checksum without adding pseudo headers
1611 diff --git a/arch/arm/include/asm/cmpxchg.h b/arch/arm/include/asm/cmpxchg.h
1612 index df2fbba..63fe3e1 100644
1613 --- a/arch/arm/include/asm/cmpxchg.h
1614 +++ b/arch/arm/include/asm/cmpxchg.h
1615 @@ -102,6 +102,8 @@ static inline unsigned long __xchg(unsigned long x, volatile void *ptr, int size
1616
1617 #define xchg(ptr,x) \
1618 ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
1619 +#define xchg_unchecked(ptr,x) \
1620 + ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
1621
1622 #include <asm-generic/cmpxchg-local.h>
1623
1624 diff --git a/arch/arm/include/asm/domain.h b/arch/arm/include/asm/domain.h
1625 index 6ddbe44..b5e38b1 100644
1626 --- a/arch/arm/include/asm/domain.h
1627 +++ b/arch/arm/include/asm/domain.h
1628 @@ -48,18 +48,37 @@
1629 * Domain types
1630 */
1631 #define DOMAIN_NOACCESS 0
1632 -#define DOMAIN_CLIENT 1
1633 #ifdef CONFIG_CPU_USE_DOMAINS
1634 +#define DOMAIN_USERCLIENT 1
1635 +#define DOMAIN_KERNELCLIENT 1
1636 #define DOMAIN_MANAGER 3
1637 +#define DOMAIN_VECTORS DOMAIN_USER
1638 #else
1639 +
1640 +#ifdef CONFIG_PAX_KERNEXEC
1641 #define DOMAIN_MANAGER 1
1642 +#define DOMAIN_KERNEXEC 3
1643 +#else
1644 +#define DOMAIN_MANAGER 1
1645 +#endif
1646 +
1647 +#ifdef CONFIG_PAX_MEMORY_UDEREF
1648 +#define DOMAIN_USERCLIENT 0
1649 +#define DOMAIN_UDEREF 1
1650 +#define DOMAIN_VECTORS DOMAIN_KERNEL
1651 +#else
1652 +#define DOMAIN_USERCLIENT 1
1653 +#define DOMAIN_VECTORS DOMAIN_USER
1654 +#endif
1655 +#define DOMAIN_KERNELCLIENT 1
1656 +
1657 #endif
1658
1659 #define domain_val(dom,type) ((type) << (2*(dom)))
1660
1661 #ifndef __ASSEMBLY__
1662
1663 -#ifdef CONFIG_CPU_USE_DOMAINS
1664 +#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
1665 static inline void set_domain(unsigned val)
1666 {
1667 asm volatile(
1668 @@ -68,15 +87,7 @@ static inline void set_domain(unsigned val)
1669 isb();
1670 }
1671
1672 -#define modify_domain(dom,type) \
1673 - do { \
1674 - struct thread_info *thread = current_thread_info(); \
1675 - unsigned int domain = thread->cpu_domain; \
1676 - domain &= ~domain_val(dom, DOMAIN_MANAGER); \
1677 - thread->cpu_domain = domain | domain_val(dom, type); \
1678 - set_domain(thread->cpu_domain); \
1679 - } while (0)
1680 -
1681 +extern void modify_domain(unsigned int dom, unsigned int type);
1682 #else
1683 static inline void set_domain(unsigned val) { }
1684 static inline void modify_domain(unsigned dom, unsigned type) { }
1685 diff --git a/arch/arm/include/asm/elf.h b/arch/arm/include/asm/elf.h
1686 index f4b46d3..abc9b2b 100644
1687 --- a/arch/arm/include/asm/elf.h
1688 +++ b/arch/arm/include/asm/elf.h
1689 @@ -114,7 +114,14 @@ int dump_task_regs(struct task_struct *t, elf_gregset_t *elfregs);
1690 the loader. We need to make sure that it is out of the way of the program
1691 that it will "exec", and that there is sufficient room for the brk. */
1692
1693 -#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
1694 +#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
1695 +
1696 +#ifdef CONFIG_PAX_ASLR
1697 +#define PAX_ELF_ET_DYN_BASE 0x00008000UL
1698 +
1699 +#define PAX_DELTA_MMAP_LEN ((current->personality == PER_LINUX_32BIT) ? 16 : 10)
1700 +#define PAX_DELTA_STACK_LEN ((current->personality == PER_LINUX_32BIT) ? 16 : 10)
1701 +#endif
1702
1703 /* When the program starts, a1 contains a pointer to a function to be
1704 registered with atexit, as per the SVR4 ABI. A value of 0 means we
1705 @@ -124,10 +131,6 @@ int dump_task_regs(struct task_struct *t, elf_gregset_t *elfregs);
1706 extern void elf_set_personality(const struct elf32_hdr *);
1707 #define SET_PERSONALITY(ex) elf_set_personality(&(ex))
1708
1709 -struct mm_struct;
1710 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
1711 -#define arch_randomize_brk arch_randomize_brk
1712 -
1713 #ifdef CONFIG_MMU
1714 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
1715 struct linux_binprm;
1716 diff --git a/arch/arm/include/asm/fncpy.h b/arch/arm/include/asm/fncpy.h
1717 index de53547..52b9a28 100644
1718 --- a/arch/arm/include/asm/fncpy.h
1719 +++ b/arch/arm/include/asm/fncpy.h
1720 @@ -81,7 +81,9 @@
1721 BUG_ON((uintptr_t)(dest_buf) & (FNCPY_ALIGN - 1) || \
1722 (__funcp_address & ~(uintptr_t)1 & (FNCPY_ALIGN - 1))); \
1723 \
1724 + pax_open_kernel(); \
1725 memcpy(dest_buf, (void const *)(__funcp_address & ~1), size); \
1726 + pax_close_kernel(); \
1727 flush_icache_range((unsigned long)(dest_buf), \
1728 (unsigned long)(dest_buf) + (size)); \
1729 \
1730 diff --git a/arch/arm/include/asm/futex.h b/arch/arm/include/asm/futex.h
1731 index e42cf59..7b94b8f 100644
1732 --- a/arch/arm/include/asm/futex.h
1733 +++ b/arch/arm/include/asm/futex.h
1734 @@ -50,6 +50,8 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
1735 if (!access_ok(VERIFY_WRITE, uaddr, sizeof(u32)))
1736 return -EFAULT;
1737
1738 + pax_open_userland();
1739 +
1740 smp_mb();
1741 __asm__ __volatile__("@futex_atomic_cmpxchg_inatomic\n"
1742 "1: ldrex %1, [%4]\n"
1743 @@ -65,6 +67,8 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
1744 : "cc", "memory");
1745 smp_mb();
1746
1747 + pax_close_userland();
1748 +
1749 *uval = val;
1750 return ret;
1751 }
1752 @@ -95,6 +99,8 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
1753 if (!access_ok(VERIFY_WRITE, uaddr, sizeof(u32)))
1754 return -EFAULT;
1755
1756 + pax_open_userland();
1757 +
1758 __asm__ __volatile__("@futex_atomic_cmpxchg_inatomic\n"
1759 "1: " TUSER(ldr) " %1, [%4]\n"
1760 " teq %1, %2\n"
1761 @@ -105,6 +111,8 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
1762 : "r" (oldval), "r" (newval), "r" (uaddr), "Ir" (-EFAULT)
1763 : "cc", "memory");
1764
1765 + pax_close_userland();
1766 +
1767 *uval = val;
1768 return ret;
1769 }
1770 @@ -127,6 +135,7 @@ futex_atomic_op_inuser (int encoded_op, u32 __user *uaddr)
1771 return -EFAULT;
1772
1773 pagefault_disable(); /* implies preempt_disable() */
1774 + pax_open_userland();
1775
1776 switch (op) {
1777 case FUTEX_OP_SET:
1778 @@ -148,6 +157,7 @@ futex_atomic_op_inuser (int encoded_op, u32 __user *uaddr)
1779 ret = -ENOSYS;
1780 }
1781
1782 + pax_close_userland();
1783 pagefault_enable(); /* subsumes preempt_enable() */
1784
1785 if (!ret) {
1786 diff --git a/arch/arm/include/asm/kmap_types.h b/arch/arm/include/asm/kmap_types.h
1787 index 83eb2f7..ed77159 100644
1788 --- a/arch/arm/include/asm/kmap_types.h
1789 +++ b/arch/arm/include/asm/kmap_types.h
1790 @@ -4,6 +4,6 @@
1791 /*
1792 * This is the "bare minimum". AIO seems to require this.
1793 */
1794 -#define KM_TYPE_NR 16
1795 +#define KM_TYPE_NR 17
1796
1797 #endif
1798 diff --git a/arch/arm/include/asm/mach/dma.h b/arch/arm/include/asm/mach/dma.h
1799 index 9e614a1..3302cca 100644
1800 --- a/arch/arm/include/asm/mach/dma.h
1801 +++ b/arch/arm/include/asm/mach/dma.h
1802 @@ -22,7 +22,7 @@ struct dma_ops {
1803 int (*residue)(unsigned int, dma_t *); /* optional */
1804 int (*setspeed)(unsigned int, dma_t *, int); /* optional */
1805 const char *type;
1806 -};
1807 +} __do_const;
1808
1809 struct dma_struct {
1810 void *addr; /* single DMA address */
1811 diff --git a/arch/arm/include/asm/mach/map.h b/arch/arm/include/asm/mach/map.h
1812 index 2fe141f..192dc01 100644
1813 --- a/arch/arm/include/asm/mach/map.h
1814 +++ b/arch/arm/include/asm/mach/map.h
1815 @@ -27,13 +27,16 @@ struct map_desc {
1816 #define MT_MINICLEAN 6
1817 #define MT_LOW_VECTORS 7
1818 #define MT_HIGH_VECTORS 8
1819 -#define MT_MEMORY 9
1820 +#define MT_MEMORY_RWX 9
1821 #define MT_ROM 10
1822 -#define MT_MEMORY_NONCACHED 11
1823 +#define MT_MEMORY_NONCACHED_RX 11
1824 #define MT_MEMORY_DTCM 12
1825 #define MT_MEMORY_ITCM 13
1826 #define MT_MEMORY_SO 14
1827 #define MT_MEMORY_DMA_READY 15
1828 +#define MT_MEMORY_RW 16
1829 +#define MT_MEMORY_RX 17
1830 +#define MT_MEMORY_NONCACHED_RW 18
1831
1832 #ifdef CONFIG_MMU
1833 extern void iotable_init(struct map_desc *, int);
1834 diff --git a/arch/arm/include/asm/outercache.h b/arch/arm/include/asm/outercache.h
1835 index f94784f..9a09a4a 100644
1836 --- a/arch/arm/include/asm/outercache.h
1837 +++ b/arch/arm/include/asm/outercache.h
1838 @@ -35,7 +35,7 @@ struct outer_cache_fns {
1839 #endif
1840 void (*set_debug)(unsigned long);
1841 void (*resume)(void);
1842 -};
1843 +} __no_const;
1844
1845 extern struct outer_cache_fns outer_cache;
1846
1847 diff --git a/arch/arm/include/asm/page.h b/arch/arm/include/asm/page.h
1848 index 4355f0e..cd9168e 100644
1849 --- a/arch/arm/include/asm/page.h
1850 +++ b/arch/arm/include/asm/page.h
1851 @@ -23,6 +23,7 @@
1852
1853 #else
1854
1855 +#include <linux/compiler.h>
1856 #include <asm/glue.h>
1857
1858 /*
1859 @@ -114,7 +115,7 @@ struct cpu_user_fns {
1860 void (*cpu_clear_user_highpage)(struct page *page, unsigned long vaddr);
1861 void (*cpu_copy_user_highpage)(struct page *to, struct page *from,
1862 unsigned long vaddr, struct vm_area_struct *vma);
1863 -};
1864 +} __no_const;
1865
1866 #ifdef MULTI_USER
1867 extern struct cpu_user_fns cpu_user;
1868 diff --git a/arch/arm/include/asm/pgalloc.h b/arch/arm/include/asm/pgalloc.h
1869 index 78a7793..e3dc06c 100644
1870 --- a/arch/arm/include/asm/pgalloc.h
1871 +++ b/arch/arm/include/asm/pgalloc.h
1872 @@ -17,6 +17,7 @@
1873 #include <asm/processor.h>
1874 #include <asm/cacheflush.h>
1875 #include <asm/tlbflush.h>
1876 +#include <asm/system_info.h>
1877
1878 #define check_pgt_cache() do { } while (0)
1879
1880 @@ -43,6 +44,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1881 set_pud(pud, __pud(__pa(pmd) | PMD_TYPE_TABLE));
1882 }
1883
1884 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1885 +{
1886 + pud_populate(mm, pud, pmd);
1887 +}
1888 +
1889 #else /* !CONFIG_ARM_LPAE */
1890
1891 /*
1892 @@ -51,6 +57,7 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1893 #define pmd_alloc_one(mm,addr) ({ BUG(); ((pmd_t *)2); })
1894 #define pmd_free(mm, pmd) do { } while (0)
1895 #define pud_populate(mm,pmd,pte) BUG()
1896 +#define pud_populate_kernel(mm,pmd,pte) BUG()
1897
1898 #endif /* CONFIG_ARM_LPAE */
1899
1900 @@ -128,6 +135,19 @@ static inline void pte_free(struct mm_struct *mm, pgtable_t pte)
1901 __free_page(pte);
1902 }
1903
1904 +static inline void __section_update(pmd_t *pmdp, unsigned long addr, pmdval_t prot)
1905 +{
1906 +#ifdef CONFIG_ARM_LPAE
1907 + pmdp[0] = __pmd(pmd_val(pmdp[0]) | prot);
1908 +#else
1909 + if (addr & SECTION_SIZE)
1910 + pmdp[1] = __pmd(pmd_val(pmdp[1]) | prot);
1911 + else
1912 + pmdp[0] = __pmd(pmd_val(pmdp[0]) | prot);
1913 +#endif
1914 + flush_pmd_entry(pmdp);
1915 +}
1916 +
1917 static inline void __pmd_populate(pmd_t *pmdp, phys_addr_t pte,
1918 pmdval_t prot)
1919 {
1920 @@ -157,7 +177,7 @@ pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmdp, pte_t *ptep)
1921 static inline void
1922 pmd_populate(struct mm_struct *mm, pmd_t *pmdp, pgtable_t ptep)
1923 {
1924 - __pmd_populate(pmdp, page_to_phys(ptep), _PAGE_USER_TABLE);
1925 + __pmd_populate(pmdp, page_to_phys(ptep), _PAGE_USER_TABLE | __supported_pmd_mask);
1926 }
1927 #define pmd_pgtable(pmd) pmd_page(pmd)
1928
1929 diff --git a/arch/arm/include/asm/pgtable-2level-hwdef.h b/arch/arm/include/asm/pgtable-2level-hwdef.h
1930 index 5cfba15..f415e1a 100644
1931 --- a/arch/arm/include/asm/pgtable-2level-hwdef.h
1932 +++ b/arch/arm/include/asm/pgtable-2level-hwdef.h
1933 @@ -20,12 +20,15 @@
1934 #define PMD_TYPE_FAULT (_AT(pmdval_t, 0) << 0)
1935 #define PMD_TYPE_TABLE (_AT(pmdval_t, 1) << 0)
1936 #define PMD_TYPE_SECT (_AT(pmdval_t, 2) << 0)
1937 +#define PMD_PXNTABLE (_AT(pmdval_t, 1) << 2) /* v7 */
1938 #define PMD_BIT4 (_AT(pmdval_t, 1) << 4)
1939 #define PMD_DOMAIN(x) (_AT(pmdval_t, (x)) << 5)
1940 #define PMD_PROTECTION (_AT(pmdval_t, 1) << 9) /* v5 */
1941 +
1942 /*
1943 * - section
1944 */
1945 +#define PMD_SECT_PXN (_AT(pmdval_t, 1) << 0) /* v7 */
1946 #define PMD_SECT_BUFFERABLE (_AT(pmdval_t, 1) << 2)
1947 #define PMD_SECT_CACHEABLE (_AT(pmdval_t, 1) << 3)
1948 #define PMD_SECT_XN (_AT(pmdval_t, 1) << 4) /* v6 */
1949 @@ -37,6 +40,7 @@
1950 #define PMD_SECT_nG (_AT(pmdval_t, 1) << 17) /* v6 */
1951 #define PMD_SECT_SUPER (_AT(pmdval_t, 1) << 18) /* v6 */
1952 #define PMD_SECT_AF (_AT(pmdval_t, 0))
1953 +#define PMD_SECT_RDONLY (_AT(pmdval_t, 0))
1954
1955 #define PMD_SECT_UNCACHED (_AT(pmdval_t, 0))
1956 #define PMD_SECT_BUFFERED (PMD_SECT_BUFFERABLE)
1957 @@ -66,6 +70,7 @@
1958 * - extended small page/tiny page
1959 */
1960 #define PTE_EXT_XN (_AT(pteval_t, 1) << 0) /* v6 */
1961 +#define PTE_EXT_PXN (_AT(pteval_t, 1) << 2) /* v7 */
1962 #define PTE_EXT_AP_MASK (_AT(pteval_t, 3) << 4)
1963 #define PTE_EXT_AP0 (_AT(pteval_t, 1) << 4)
1964 #define PTE_EXT_AP1 (_AT(pteval_t, 2) << 4)
1965 diff --git a/arch/arm/include/asm/pgtable-2level.h b/arch/arm/include/asm/pgtable-2level.h
1966 index 86a659a..70e0120 100644
1967 --- a/arch/arm/include/asm/pgtable-2level.h
1968 +++ b/arch/arm/include/asm/pgtable-2level.h
1969 @@ -126,6 +126,9 @@
1970 #define L_PTE_SHARED (_AT(pteval_t, 1) << 10) /* shared(v6), coherent(xsc3) */
1971 #define L_PTE_NONE (_AT(pteval_t, 1) << 11)
1972
1973 +/* Two-level page tables only have PXN in the PGD, not in the PTE. */
1974 +#define L_PTE_PXN (_AT(pteval_t, 0))
1975 +
1976 /*
1977 * These are the memory types, defined to be compatible with
1978 * pre-ARMv6 CPUs cacheable and bufferable bits: XXCB
1979 diff --git a/arch/arm/include/asm/pgtable-3level-hwdef.h b/arch/arm/include/asm/pgtable-3level-hwdef.h
1980 index 626989f..9d67a33 100644
1981 --- a/arch/arm/include/asm/pgtable-3level-hwdef.h
1982 +++ b/arch/arm/include/asm/pgtable-3level-hwdef.h
1983 @@ -75,6 +75,7 @@
1984 #define PTE_EXT_SHARED (_AT(pteval_t, 3) << 8) /* SH[1:0], inner shareable */
1985 #define PTE_EXT_AF (_AT(pteval_t, 1) << 10) /* Access Flag */
1986 #define PTE_EXT_NG (_AT(pteval_t, 1) << 11) /* nG */
1987 +#define PTE_EXT_PXN (_AT(pteval_t, 1) << 53) /* PXN */
1988 #define PTE_EXT_XN (_AT(pteval_t, 1) << 54) /* XN */
1989
1990 /*
1991 diff --git a/arch/arm/include/asm/pgtable-3level.h b/arch/arm/include/asm/pgtable-3level.h
1992 index 1d15673..04d626a 100644
1993 --- a/arch/arm/include/asm/pgtable-3level.h
1994 +++ b/arch/arm/include/asm/pgtable-3level.h
1995 @@ -82,6 +82,7 @@
1996 #define L_PTE_RDONLY (_AT(pteval_t, 1) << 7) /* AP[2] */
1997 #define L_PTE_SHARED (_AT(pteval_t, 3) << 8) /* SH[1:0], inner shareable */
1998 #define L_PTE_YOUNG (_AT(pteval_t, 1) << 10) /* AF */
1999 +#define L_PTE_PXN (_AT(pteval_t, 1) << 53) /* PXN */
2000 #define L_PTE_XN (_AT(pteval_t, 1) << 54) /* XN */
2001 #define L_PTE_DIRTY (_AT(pteval_t, 1) << 55) /* unused */
2002 #define L_PTE_SPECIAL (_AT(pteval_t, 1) << 56) /* unused */
2003 @@ -95,6 +96,7 @@
2004 /*
2005 * To be used in assembly code with the upper page attributes.
2006 */
2007 +#define L_PTE_PXN_HIGH (1 << (53 - 32))
2008 #define L_PTE_XN_HIGH (1 << (54 - 32))
2009 #define L_PTE_DIRTY_HIGH (1 << (55 - 32))
2010
2011 diff --git a/arch/arm/include/asm/pgtable.h b/arch/arm/include/asm/pgtable.h
2012 index 1571d12..b8a9b43 100644
2013 --- a/arch/arm/include/asm/pgtable.h
2014 +++ b/arch/arm/include/asm/pgtable.h
2015 @@ -33,6 +33,9 @@
2016 #include <asm/pgtable-2level.h>
2017 #endif
2018
2019 +#define ktla_ktva(addr) (addr)
2020 +#define ktva_ktla(addr) (addr)
2021 +
2022 /*
2023 * Just any arbitrary offset to the start of the vmalloc VM area: the
2024 * current 8MB value just means that there will be a 8MB "hole" after the
2025 @@ -48,6 +51,9 @@
2026 #define LIBRARY_TEXT_START 0x0c000000
2027
2028 #ifndef __ASSEMBLY__
2029 +extern pteval_t __supported_pte_mask;
2030 +extern pmdval_t __supported_pmd_mask;
2031 +
2032 extern void __pte_error(const char *file, int line, pte_t);
2033 extern void __pmd_error(const char *file, int line, pmd_t);
2034 extern void __pgd_error(const char *file, int line, pgd_t);
2035 @@ -56,6 +62,48 @@ extern void __pgd_error(const char *file, int line, pgd_t);
2036 #define pmd_ERROR(pmd) __pmd_error(__FILE__, __LINE__, pmd)
2037 #define pgd_ERROR(pgd) __pgd_error(__FILE__, __LINE__, pgd)
2038
2039 +#define __HAVE_ARCH_PAX_OPEN_KERNEL
2040 +#define __HAVE_ARCH_PAX_CLOSE_KERNEL
2041 +
2042 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2043 +#include <asm/domain.h>
2044 +#include <linux/thread_info.h>
2045 +#include <linux/preempt.h>
2046 +
2047 +static inline int test_domain(int domain, int domaintype)
2048 +{
2049 + return ((current_thread_info()->cpu_domain) & domain_val(domain, 3)) == domain_val(domain, domaintype);
2050 +}
2051 +#endif
2052 +
2053 +#ifdef CONFIG_PAX_KERNEXEC
2054 +static inline unsigned long pax_open_kernel(void) {
2055 +#ifdef CONFIG_ARM_LPAE
2056 + /* TODO */
2057 +#else
2058 + preempt_disable();
2059 + BUG_ON(test_domain(DOMAIN_KERNEL, DOMAIN_KERNEXEC));
2060 + modify_domain(DOMAIN_KERNEL, DOMAIN_KERNEXEC);
2061 +#endif
2062 + return 0;
2063 +}
2064 +
2065 +static inline unsigned long pax_close_kernel(void) {
2066 +#ifdef CONFIG_ARM_LPAE
2067 + /* TODO */
2068 +#else
2069 + BUG_ON(test_domain(DOMAIN_KERNEL, DOMAIN_MANAGER));
2070 + /* DOMAIN_MANAGER = "client" under KERNEXEC */
2071 + modify_domain(DOMAIN_KERNEL, DOMAIN_MANAGER);
2072 + preempt_enable_no_resched();
2073 +#endif
2074 + return 0;
2075 +}
2076 +#else
2077 +static inline unsigned long pax_open_kernel(void) { return 0; }
2078 +static inline unsigned long pax_close_kernel(void) { return 0; }
2079 +#endif
2080 +
2081 /*
2082 * This is the lowest virtual address we can permit any user space
2083 * mapping to be mapped at. This is particularly important for
2084 @@ -75,8 +123,8 @@ extern void __pgd_error(const char *file, int line, pgd_t);
2085 /*
2086 * The pgprot_* and protection_map entries will be fixed up in runtime
2087 * to include the cachable and bufferable bits based on memory policy,
2088 - * as well as any architecture dependent bits like global/ASID and SMP
2089 - * shared mapping bits.
2090 + * as well as any architecture dependent bits like global/ASID, PXN,
2091 + * and SMP shared mapping bits.
2092 */
2093 #define _L_PTE_DEFAULT L_PTE_PRESENT | L_PTE_YOUNG
2094
2095 @@ -260,7 +308,7 @@ static inline pte_t pte_mkspecial(pte_t pte) { return pte; }
2096 static inline pte_t pte_modify(pte_t pte, pgprot_t newprot)
2097 {
2098 const pteval_t mask = L_PTE_XN | L_PTE_RDONLY | L_PTE_USER |
2099 - L_PTE_NONE | L_PTE_VALID;
2100 + L_PTE_NONE | L_PTE_VALID | __supported_pte_mask;
2101 pte_val(pte) = (pte_val(pte) & ~mask) | (pgprot_val(newprot) & mask);
2102 return pte;
2103 }
2104 diff --git a/arch/arm/include/asm/psci.h b/arch/arm/include/asm/psci.h
2105 index c4ae171..ea0c0c2 100644
2106 --- a/arch/arm/include/asm/psci.h
2107 +++ b/arch/arm/include/asm/psci.h
2108 @@ -29,7 +29,7 @@ struct psci_operations {
2109 int (*cpu_off)(struct psci_power_state state);
2110 int (*cpu_on)(unsigned long cpuid, unsigned long entry_point);
2111 int (*migrate)(unsigned long cpuid);
2112 -};
2113 +} __no_const;
2114
2115 extern struct psci_operations psci_ops;
2116 extern struct smp_operations psci_smp_ops;
2117 diff --git a/arch/arm/include/asm/smp.h b/arch/arm/include/asm/smp.h
2118 index 22a3b9b..7f214ee 100644
2119 --- a/arch/arm/include/asm/smp.h
2120 +++ b/arch/arm/include/asm/smp.h
2121 @@ -112,7 +112,7 @@ struct smp_operations {
2122 int (*cpu_disable)(unsigned int cpu);
2123 #endif
2124 #endif
2125 -};
2126 +} __no_const;
2127
2128 /*
2129 * set platform specific SMP operations
2130 diff --git a/arch/arm/include/asm/thread_info.h b/arch/arm/include/asm/thread_info.h
2131 index 71a06b2..8bb9ae1 100644
2132 --- a/arch/arm/include/asm/thread_info.h
2133 +++ b/arch/arm/include/asm/thread_info.h
2134 @@ -88,9 +88,9 @@ struct thread_info {
2135 .flags = 0, \
2136 .preempt_count = INIT_PREEMPT_COUNT, \
2137 .addr_limit = KERNEL_DS, \
2138 - .cpu_domain = domain_val(DOMAIN_USER, DOMAIN_MANAGER) | \
2139 - domain_val(DOMAIN_KERNEL, DOMAIN_MANAGER) | \
2140 - domain_val(DOMAIN_IO, DOMAIN_CLIENT), \
2141 + .cpu_domain = domain_val(DOMAIN_USER, DOMAIN_USERCLIENT) | \
2142 + domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT) | \
2143 + domain_val(DOMAIN_IO, DOMAIN_KERNELCLIENT), \
2144 .restart_block = { \
2145 .fn = do_no_restart_syscall, \
2146 }, \
2147 @@ -157,7 +157,11 @@ extern int vfp_restore_user_hwstate(struct user_vfp __user *,
2148 #define TIF_SYSCALL_AUDIT 9
2149 #define TIF_SYSCALL_TRACEPOINT 10
2150 #define TIF_SECCOMP 11 /* seccomp syscall filtering active */
2151 -#define TIF_NOHZ 12 /* in adaptive nohz mode */
2152 +/* within 8 bits of TIF_SYSCALL_TRACE
2153 + * to meet flexible second operand requirements
2154 + */
2155 +#define TIF_GRSEC_SETXID 12
2156 +#define TIF_NOHZ 13 /* in adaptive nohz mode */
2157 #define TIF_USING_IWMMXT 17
2158 #define TIF_MEMDIE 18 /* is terminating due to OOM killer */
2159 #define TIF_RESTORE_SIGMASK 20
2160 @@ -170,10 +174,11 @@ extern int vfp_restore_user_hwstate(struct user_vfp __user *,
2161 #define _TIF_SYSCALL_TRACEPOINT (1 << TIF_SYSCALL_TRACEPOINT)
2162 #define _TIF_SECCOMP (1 << TIF_SECCOMP)
2163 #define _TIF_USING_IWMMXT (1 << TIF_USING_IWMMXT)
2164 +#define _TIF_GRSEC_SETXID (1 << TIF_GRSEC_SETXID)
2165
2166 /* Checks for any syscall work in entry-common.S */
2167 #define _TIF_SYSCALL_WORK (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | \
2168 - _TIF_SYSCALL_TRACEPOINT | _TIF_SECCOMP)
2169 + _TIF_SYSCALL_TRACEPOINT | _TIF_SECCOMP | _TIF_GRSEC_SETXID)
2170
2171 /*
2172 * Change these and you break ASM code in entry-common.S
2173 diff --git a/arch/arm/include/asm/uaccess.h b/arch/arm/include/asm/uaccess.h
2174 index 72abdc5..35acac1 100644
2175 --- a/arch/arm/include/asm/uaccess.h
2176 +++ b/arch/arm/include/asm/uaccess.h
2177 @@ -18,6 +18,7 @@
2178 #include <asm/domain.h>
2179 #include <asm/unified.h>
2180 #include <asm/compiler.h>
2181 +#include <asm/pgtable.h>
2182
2183 #if __LINUX_ARM_ARCH__ < 6
2184 #include <asm-generic/uaccess-unaligned.h>
2185 @@ -70,11 +71,38 @@ extern int __put_user_bad(void);
2186 static inline void set_fs(mm_segment_t fs)
2187 {
2188 current_thread_info()->addr_limit = fs;
2189 - modify_domain(DOMAIN_KERNEL, fs ? DOMAIN_CLIENT : DOMAIN_MANAGER);
2190 + modify_domain(DOMAIN_KERNEL, fs ? DOMAIN_KERNELCLIENT : DOMAIN_MANAGER);
2191 }
2192
2193 #define segment_eq(a,b) ((a) == (b))
2194
2195 +#define __HAVE_ARCH_PAX_OPEN_USERLAND
2196 +#define __HAVE_ARCH_PAX_CLOSE_USERLAND
2197 +
2198 +static inline void pax_open_userland(void)
2199 +{
2200 +
2201 +#ifdef CONFIG_PAX_MEMORY_UDEREF
2202 + if (segment_eq(get_fs(), USER_DS)) {
2203 + BUG_ON(test_domain(DOMAIN_USER, DOMAIN_UDEREF));
2204 + modify_domain(DOMAIN_USER, DOMAIN_UDEREF);
2205 + }
2206 +#endif
2207 +
2208 +}
2209 +
2210 +static inline void pax_close_userland(void)
2211 +{
2212 +
2213 +#ifdef CONFIG_PAX_MEMORY_UDEREF
2214 + if (segment_eq(get_fs(), USER_DS)) {
2215 + BUG_ON(test_domain(DOMAIN_USER, DOMAIN_NOACCESS));
2216 + modify_domain(DOMAIN_USER, DOMAIN_NOACCESS);
2217 + }
2218 +#endif
2219 +
2220 +}
2221 +
2222 #define __addr_ok(addr) ({ \
2223 unsigned long flag; \
2224 __asm__("cmp %2, %0; movlo %0, #0" \
2225 @@ -150,8 +178,12 @@ extern int __get_user_4(void *);
2226
2227 #define get_user(x,p) \
2228 ({ \
2229 + int __e; \
2230 might_fault(); \
2231 - __get_user_check(x,p); \
2232 + pax_open_userland(); \
2233 + __e = __get_user_check(x,p); \
2234 + pax_close_userland(); \
2235 + __e; \
2236 })
2237
2238 extern int __put_user_1(void *, unsigned int);
2239 @@ -195,8 +227,12 @@ extern int __put_user_8(void *, unsigned long long);
2240
2241 #define put_user(x,p) \
2242 ({ \
2243 + int __e; \
2244 might_fault(); \
2245 - __put_user_check(x,p); \
2246 + pax_open_userland(); \
2247 + __e = __put_user_check(x,p); \
2248 + pax_close_userland(); \
2249 + __e; \
2250 })
2251
2252 #else /* CONFIG_MMU */
2253 @@ -220,6 +256,7 @@ static inline void set_fs(mm_segment_t fs)
2254
2255 #endif /* CONFIG_MMU */
2256
2257 +#define access_ok_noprefault(type,addr,size) access_ok((type),(addr),(size))
2258 #define access_ok(type,addr,size) (__range_ok(addr,size) == 0)
2259
2260 #define user_addr_max() \
2261 @@ -237,13 +274,17 @@ static inline void set_fs(mm_segment_t fs)
2262 #define __get_user(x,ptr) \
2263 ({ \
2264 long __gu_err = 0; \
2265 + pax_open_userland(); \
2266 __get_user_err((x),(ptr),__gu_err); \
2267 + pax_close_userland(); \
2268 __gu_err; \
2269 })
2270
2271 #define __get_user_error(x,ptr,err) \
2272 ({ \
2273 + pax_open_userland(); \
2274 __get_user_err((x),(ptr),err); \
2275 + pax_close_userland(); \
2276 (void) 0; \
2277 })
2278
2279 @@ -319,13 +360,17 @@ do { \
2280 #define __put_user(x,ptr) \
2281 ({ \
2282 long __pu_err = 0; \
2283 + pax_open_userland(); \
2284 __put_user_err((x),(ptr),__pu_err); \
2285 + pax_close_userland(); \
2286 __pu_err; \
2287 })
2288
2289 #define __put_user_error(x,ptr,err) \
2290 ({ \
2291 + pax_open_userland(); \
2292 __put_user_err((x),(ptr),err); \
2293 + pax_close_userland(); \
2294 (void) 0; \
2295 })
2296
2297 @@ -425,11 +470,44 @@ do { \
2298
2299
2300 #ifdef CONFIG_MMU
2301 -extern unsigned long __must_check __copy_from_user(void *to, const void __user *from, unsigned long n);
2302 -extern unsigned long __must_check __copy_to_user(void __user *to, const void *from, unsigned long n);
2303 +extern unsigned long __must_check ___copy_from_user(void *to, const void __user *from, unsigned long n);
2304 +extern unsigned long __must_check ___copy_to_user(void __user *to, const void *from, unsigned long n);
2305 +
2306 +static inline unsigned long __must_check __copy_from_user(void *to, const void __user *from, unsigned long n)
2307 +{
2308 + unsigned long ret;
2309 +
2310 + check_object_size(to, n, false);
2311 + pax_open_userland();
2312 + ret = ___copy_from_user(to, from, n);
2313 + pax_close_userland();
2314 + return ret;
2315 +}
2316 +
2317 +static inline unsigned long __must_check __copy_to_user(void __user *to, const void *from, unsigned long n)
2318 +{
2319 + unsigned long ret;
2320 +
2321 + check_object_size(from, n, true);
2322 + pax_open_userland();
2323 + ret = ___copy_to_user(to, from, n);
2324 + pax_close_userland();
2325 + return ret;
2326 +}
2327 +
2328 extern unsigned long __must_check __copy_to_user_std(void __user *to, const void *from, unsigned long n);
2329 -extern unsigned long __must_check __clear_user(void __user *addr, unsigned long n);
2330 +extern unsigned long __must_check ___clear_user(void __user *addr, unsigned long n);
2331 extern unsigned long __must_check __clear_user_std(void __user *addr, unsigned long n);
2332 +
2333 +static inline unsigned long __must_check __clear_user(void __user *addr, unsigned long n)
2334 +{
2335 + unsigned long ret;
2336 + pax_open_userland();
2337 + ret = ___clear_user(addr, n);
2338 + pax_close_userland();
2339 + return ret;
2340 +}
2341 +
2342 #else
2343 #define __copy_from_user(to,from,n) (memcpy(to, (void __force *)from, n), 0)
2344 #define __copy_to_user(to,from,n) (memcpy((void __force *)to, from, n), 0)
2345 @@ -438,6 +516,9 @@ extern unsigned long __must_check __clear_user_std(void __user *addr, unsigned l
2346
2347 static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
2348 {
2349 + if ((long)n < 0)
2350 + return n;
2351 +
2352 if (access_ok(VERIFY_READ, from, n))
2353 n = __copy_from_user(to, from, n);
2354 else /* security hole - plug it */
2355 @@ -447,6 +528,9 @@ static inline unsigned long __must_check copy_from_user(void *to, const void __u
2356
2357 static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
2358 {
2359 + if ((long)n < 0)
2360 + return n;
2361 +
2362 if (access_ok(VERIFY_WRITE, to, n))
2363 n = __copy_to_user(to, from, n);
2364 return n;
2365 diff --git a/arch/arm/include/uapi/asm/ptrace.h b/arch/arm/include/uapi/asm/ptrace.h
2366 index 5af0ed1..cea83883 100644
2367 --- a/arch/arm/include/uapi/asm/ptrace.h
2368 +++ b/arch/arm/include/uapi/asm/ptrace.h
2369 @@ -92,7 +92,7 @@
2370 * ARMv7 groups of PSR bits
2371 */
2372 #define APSR_MASK 0xf80f0000 /* N, Z, C, V, Q and GE flags */
2373 -#define PSR_ISET_MASK 0x01000010 /* ISA state (J, T) mask */
2374 +#define PSR_ISET_MASK 0x01000020 /* ISA state (J, T) mask */
2375 #define PSR_IT_MASK 0x0600fc00 /* If-Then execution state mask */
2376 #define PSR_ENDIAN_MASK 0x00000200 /* Endianness state mask */
2377
2378 diff --git a/arch/arm/kernel/armksyms.c b/arch/arm/kernel/armksyms.c
2379 index 1f031dd..d9b5e4a 100644
2380 --- a/arch/arm/kernel/armksyms.c
2381 +++ b/arch/arm/kernel/armksyms.c
2382 @@ -53,7 +53,7 @@ EXPORT_SYMBOL(arm_delay_ops);
2383
2384 /* networking */
2385 EXPORT_SYMBOL(csum_partial);
2386 -EXPORT_SYMBOL(csum_partial_copy_from_user);
2387 +EXPORT_SYMBOL(__csum_partial_copy_from_user);
2388 EXPORT_SYMBOL(csum_partial_copy_nocheck);
2389 EXPORT_SYMBOL(__csum_ipv6_magic);
2390
2391 @@ -89,9 +89,9 @@ EXPORT_SYMBOL(__memzero);
2392 #ifdef CONFIG_MMU
2393 EXPORT_SYMBOL(copy_page);
2394
2395 -EXPORT_SYMBOL(__copy_from_user);
2396 -EXPORT_SYMBOL(__copy_to_user);
2397 -EXPORT_SYMBOL(__clear_user);
2398 +EXPORT_SYMBOL(___copy_from_user);
2399 +EXPORT_SYMBOL(___copy_to_user);
2400 +EXPORT_SYMBOL(___clear_user);
2401
2402 EXPORT_SYMBOL(__get_user_1);
2403 EXPORT_SYMBOL(__get_user_2);
2404 diff --git a/arch/arm/kernel/entry-armv.S b/arch/arm/kernel/entry-armv.S
2405 index b3fb8c9..59cfab2 100644
2406 --- a/arch/arm/kernel/entry-armv.S
2407 +++ b/arch/arm/kernel/entry-armv.S
2408 @@ -47,6 +47,87 @@
2409 9997:
2410 .endm
2411
2412 + .macro pax_enter_kernel
2413 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2414 + @ make aligned space for saved DACR
2415 + sub sp, sp, #8
2416 + @ save regs
2417 + stmdb sp!, {r1, r2}
2418 + @ read DACR from cpu_domain into r1
2419 + mov r2, sp
2420 + @ assume 8K pages, since we have to split the immediate in two
2421 + bic r2, r2, #(0x1fc0)
2422 + bic r2, r2, #(0x3f)
2423 + ldr r1, [r2, #TI_CPU_DOMAIN]
2424 + @ store old DACR on stack
2425 + str r1, [sp, #8]
2426 +#ifdef CONFIG_PAX_KERNEXEC
2427 + @ set type of DOMAIN_KERNEL to DOMAIN_KERNELCLIENT
2428 + bic r1, r1, #(domain_val(DOMAIN_KERNEL, 3))
2429 + orr r1, r1, #(domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT))
2430 +#endif
2431 +#ifdef CONFIG_PAX_MEMORY_UDEREF
2432 + @ set current DOMAIN_USER to DOMAIN_NOACCESS
2433 + bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2434 +#endif
2435 + @ write r1 to current_thread_info()->cpu_domain
2436 + str r1, [r2, #TI_CPU_DOMAIN]
2437 + @ write r1 to DACR
2438 + mcr p15, 0, r1, c3, c0, 0
2439 + @ instruction sync
2440 + instr_sync
2441 + @ restore regs
2442 + ldmia sp!, {r1, r2}
2443 +#endif
2444 + .endm
2445 +
2446 + .macro pax_open_userland
2447 +#ifdef CONFIG_PAX_MEMORY_UDEREF
2448 + @ save regs
2449 + stmdb sp!, {r0, r1}
2450 + @ read DACR from cpu_domain into r1
2451 + mov r0, sp
2452 + @ assume 8K pages, since we have to split the immediate in two
2453 + bic r0, r0, #(0x1fc0)
2454 + bic r0, r0, #(0x3f)
2455 + ldr r1, [r0, #TI_CPU_DOMAIN]
2456 + @ set current DOMAIN_USER to DOMAIN_CLIENT
2457 + bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2458 + orr r1, r1, #(domain_val(DOMAIN_USER, DOMAIN_UDEREF))
2459 + @ write r1 to current_thread_info()->cpu_domain
2460 + str r1, [r0, #TI_CPU_DOMAIN]
2461 + @ write r1 to DACR
2462 + mcr p15, 0, r1, c3, c0, 0
2463 + @ instruction sync
2464 + instr_sync
2465 + @ restore regs
2466 + ldmia sp!, {r0, r1}
2467 +#endif
2468 + .endm
2469 +
2470 + .macro pax_close_userland
2471 +#ifdef CONFIG_PAX_MEMORY_UDEREF
2472 + @ save regs
2473 + stmdb sp!, {r0, r1}
2474 + @ read DACR from cpu_domain into r1
2475 + mov r0, sp
2476 + @ assume 8K pages, since we have to split the immediate in two
2477 + bic r0, r0, #(0x1fc0)
2478 + bic r0, r0, #(0x3f)
2479 + ldr r1, [r0, #TI_CPU_DOMAIN]
2480 + @ set current DOMAIN_USER to DOMAIN_NOACCESS
2481 + bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2482 + @ write r1 to current_thread_info()->cpu_domain
2483 + str r1, [r0, #TI_CPU_DOMAIN]
2484 + @ write r1 to DACR
2485 + mcr p15, 0, r1, c3, c0, 0
2486 + @ instruction sync
2487 + instr_sync
2488 + @ restore regs
2489 + ldmia sp!, {r0, r1}
2490 +#endif
2491 + .endm
2492 +
2493 .macro pabt_helper
2494 @ PABORT handler takes pt_regs in r2, fault address in r4 and psr in r5
2495 #ifdef MULTI_PABORT
2496 @@ -89,11 +170,15 @@
2497 * Invalid mode handlers
2498 */
2499 .macro inv_entry, reason
2500 +
2501 + pax_enter_kernel
2502 +
2503 sub sp, sp, #S_FRAME_SIZE
2504 ARM( stmib sp, {r1 - lr} )
2505 THUMB( stmia sp, {r0 - r12} )
2506 THUMB( str sp, [sp, #S_SP] )
2507 THUMB( str lr, [sp, #S_LR] )
2508 +
2509 mov r1, #\reason
2510 .endm
2511
2512 @@ -149,7 +234,11 @@ ENDPROC(__und_invalid)
2513 .macro svc_entry, stack_hole=0
2514 UNWIND(.fnstart )
2515 UNWIND(.save {r0 - pc} )
2516 +
2517 + pax_enter_kernel
2518 +
2519 sub sp, sp, #(S_FRAME_SIZE + \stack_hole - 4)
2520 +
2521 #ifdef CONFIG_THUMB2_KERNEL
2522 SPFIX( str r0, [sp] ) @ temporarily saved
2523 SPFIX( mov r0, sp )
2524 @@ -164,7 +253,12 @@ ENDPROC(__und_invalid)
2525 ldmia r0, {r3 - r5}
2526 add r7, sp, #S_SP - 4 @ here for interlock avoidance
2527 mov r6, #-1 @ "" "" "" ""
2528 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2529 + @ offset sp by 8 as done in pax_enter_kernel
2530 + add r2, sp, #(S_FRAME_SIZE + \stack_hole + 4)
2531 +#else
2532 add r2, sp, #(S_FRAME_SIZE + \stack_hole - 4)
2533 +#endif
2534 SPFIX( addeq r2, r2, #4 )
2535 str r3, [sp, #-4]! @ save the "real" r0 copied
2536 @ from the exception stack
2537 @@ -317,6 +411,9 @@ ENDPROC(__pabt_svc)
2538 .macro usr_entry
2539 UNWIND(.fnstart )
2540 UNWIND(.cantunwind ) @ don't unwind the user space
2541 +
2542 + pax_enter_kernel_user
2543 +
2544 sub sp, sp, #S_FRAME_SIZE
2545 ARM( stmib sp, {r1 - r12} )
2546 THUMB( stmia sp, {r0 - r12} )
2547 @@ -416,7 +513,9 @@ __und_usr:
2548 tst r3, #PSR_T_BIT @ Thumb mode?
2549 bne __und_usr_thumb
2550 sub r4, r2, #4 @ ARM instr at LR - 4
2551 + pax_open_userland
2552 1: ldrt r0, [r4]
2553 + pax_close_userland
2554 ARM_BE8(rev r0, r0) @ little endian instruction
2555
2556 @ r0 = 32-bit ARM instruction which caused the exception
2557 @@ -450,10 +549,14 @@ __und_usr_thumb:
2558 */
2559 .arch armv6t2
2560 #endif
2561 + pax_open_userland
2562 2: ldrht r5, [r4]
2563 + pax_close_userland
2564 cmp r5, #0xe800 @ 32bit instruction if xx != 0
2565 blo __und_usr_fault_16 @ 16bit undefined instruction
2566 + pax_open_userland
2567 3: ldrht r0, [r2]
2568 + pax_close_userland
2569 add r2, r2, #2 @ r2 is PC + 2, make it PC + 4
2570 str r2, [sp, #S_PC] @ it's a 2x16bit instr, update
2571 orr r0, r0, r5, lsl #16
2572 @@ -482,7 +585,8 @@ ENDPROC(__und_usr)
2573 */
2574 .pushsection .fixup, "ax"
2575 .align 2
2576 -4: mov pc, r9
2577 +4: pax_close_userland
2578 + mov pc, r9
2579 .popsection
2580 .pushsection __ex_table,"a"
2581 .long 1b, 4b
2582 @@ -692,7 +796,7 @@ ENTRY(__switch_to)
2583 THUMB( str lr, [ip], #4 )
2584 ldr r4, [r2, #TI_TP_VALUE]
2585 ldr r5, [r2, #TI_TP_VALUE + 4]
2586 -#ifdef CONFIG_CPU_USE_DOMAINS
2587 +#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2588 ldr r6, [r2, #TI_CPU_DOMAIN]
2589 #endif
2590 switch_tls r1, r4, r5, r3, r7
2591 @@ -701,7 +805,7 @@ ENTRY(__switch_to)
2592 ldr r8, =__stack_chk_guard
2593 ldr r7, [r7, #TSK_STACK_CANARY]
2594 #endif
2595 -#ifdef CONFIG_CPU_USE_DOMAINS
2596 +#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2597 mcr p15, 0, r6, c3, c0, 0 @ Set domain register
2598 #endif
2599 mov r5, r0
2600 diff --git a/arch/arm/kernel/entry-common.S b/arch/arm/kernel/entry-common.S
2601 index a2dcafd..1048b5a 100644
2602 --- a/arch/arm/kernel/entry-common.S
2603 +++ b/arch/arm/kernel/entry-common.S
2604 @@ -10,18 +10,46 @@
2605
2606 #include <asm/unistd.h>
2607 #include <asm/ftrace.h>
2608 +#include <asm/domain.h>
2609 #include <asm/unwind.h>
2610
2611 +#include "entry-header.S"
2612 +
2613 #ifdef CONFIG_NEED_RET_TO_USER
2614 #include <mach/entry-macro.S>
2615 #else
2616 .macro arch_ret_to_user, tmp1, tmp2
2617 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2618 + @ save regs
2619 + stmdb sp!, {r1, r2}
2620 + @ read DACR from cpu_domain into r1
2621 + mov r2, sp
2622 + @ assume 8K pages, since we have to split the immediate in two
2623 + bic r2, r2, #(0x1fc0)
2624 + bic r2, r2, #(0x3f)
2625 + ldr r1, [r2, #TI_CPU_DOMAIN]
2626 +#ifdef CONFIG_PAX_KERNEXEC
2627 + @ set type of DOMAIN_KERNEL to DOMAIN_KERNELCLIENT
2628 + bic r1, r1, #(domain_val(DOMAIN_KERNEL, 3))
2629 + orr r1, r1, #(domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT))
2630 +#endif
2631 +#ifdef CONFIG_PAX_MEMORY_UDEREF
2632 + @ set current DOMAIN_USER to DOMAIN_UDEREF
2633 + bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2634 + orr r1, r1, #(domain_val(DOMAIN_USER, DOMAIN_UDEREF))
2635 +#endif
2636 + @ write r1 to current_thread_info()->cpu_domain
2637 + str r1, [r2, #TI_CPU_DOMAIN]
2638 + @ write r1 to DACR
2639 + mcr p15, 0, r1, c3, c0, 0
2640 + @ instruction sync
2641 + instr_sync
2642 + @ restore regs
2643 + ldmia sp!, {r1, r2}
2644 +#endif
2645 .endm
2646 #endif
2647
2648 -#include "entry-header.S"
2649 -
2650 -
2651 .align 5
2652 /*
2653 * This is the fast syscall return path. We do as little as
2654 @@ -411,6 +439,12 @@ ENTRY(vector_swi)
2655 USER( ldr scno, [lr, #-4] ) @ get SWI instruction
2656 #endif
2657
2658 + /*
2659 + * do this here to avoid a performance hit of wrapping the code above
2660 + * that directly dereferences userland to parse the SWI instruction
2661 + */
2662 + pax_enter_kernel_user
2663 +
2664 adr tbl, sys_call_table @ load syscall table pointer
2665
2666 #if defined(CONFIG_OABI_COMPAT)
2667 diff --git a/arch/arm/kernel/entry-header.S b/arch/arm/kernel/entry-header.S
2668 index 39f89fb..d612bd9 100644
2669 --- a/arch/arm/kernel/entry-header.S
2670 +++ b/arch/arm/kernel/entry-header.S
2671 @@ -184,6 +184,60 @@
2672 msr cpsr_c, \rtemp @ switch back to the SVC mode
2673 .endm
2674
2675 + .macro pax_enter_kernel_user
2676 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2677 + @ save regs
2678 + stmdb sp!, {r0, r1}
2679 + @ read DACR from cpu_domain into r1
2680 + mov r0, sp
2681 + @ assume 8K pages, since we have to split the immediate in two
2682 + bic r0, r0, #(0x1fc0)
2683 + bic r0, r0, #(0x3f)
2684 + ldr r1, [r0, #TI_CPU_DOMAIN]
2685 +#ifdef CONFIG_PAX_MEMORY_UDEREF
2686 + @ set current DOMAIN_USER to DOMAIN_NOACCESS
2687 + bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2688 +#endif
2689 +#ifdef CONFIG_PAX_KERNEXEC
2690 + @ set current DOMAIN_KERNEL to DOMAIN_KERNELCLIENT
2691 + bic r1, r1, #(domain_val(DOMAIN_KERNEL, 3))
2692 + orr r1, r1, #(domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT))
2693 +#endif
2694 + @ write r1 to current_thread_info()->cpu_domain
2695 + str r1, [r0, #TI_CPU_DOMAIN]
2696 + @ write r1 to DACR
2697 + mcr p15, 0, r1, c3, c0, 0
2698 + @ instruction sync
2699 + instr_sync
2700 + @ restore regs
2701 + ldmia sp!, {r0, r1}
2702 +#endif
2703 + .endm
2704 +
2705 + .macro pax_exit_kernel
2706 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2707 + @ save regs
2708 + stmdb sp!, {r0, r1}
2709 + @ read old DACR from stack into r1
2710 + ldr r1, [sp, #(8 + S_SP)]
2711 + sub r1, r1, #8
2712 + ldr r1, [r1]
2713 +
2714 + @ write r1 to current_thread_info()->cpu_domain
2715 + mov r0, sp
2716 + @ assume 8K pages, since we have to split the immediate in two
2717 + bic r0, r0, #(0x1fc0)
2718 + bic r0, r0, #(0x3f)
2719 + str r1, [r0, #TI_CPU_DOMAIN]
2720 + @ write r1 to DACR
2721 + mcr p15, 0, r1, c3, c0, 0
2722 + @ instruction sync
2723 + instr_sync
2724 + @ restore regs
2725 + ldmia sp!, {r0, r1}
2726 +#endif
2727 + .endm
2728 +
2729 #ifndef CONFIG_THUMB2_KERNEL
2730 .macro svc_exit, rpsr, irq = 0
2731 .if \irq != 0
2732 @@ -203,6 +257,9 @@
2733 blne trace_hardirqs_off
2734 #endif
2735 .endif
2736 +
2737 + pax_exit_kernel
2738 +
2739 msr spsr_cxsf, \rpsr
2740 #if defined(CONFIG_CPU_V6)
2741 ldr r0, [sp]
2742 @@ -266,6 +323,9 @@
2743 blne trace_hardirqs_off
2744 #endif
2745 .endif
2746 +
2747 + pax_exit_kernel
2748 +
2749 ldr lr, [sp, #S_SP] @ top of the stack
2750 ldrd r0, r1, [sp, #S_LR] @ calling lr and pc
2751 clrex @ clear the exclusive monitor
2752 diff --git a/arch/arm/kernel/fiq.c b/arch/arm/kernel/fiq.c
2753 index 918875d..cd5fa27 100644
2754 --- a/arch/arm/kernel/fiq.c
2755 +++ b/arch/arm/kernel/fiq.c
2756 @@ -87,7 +87,10 @@ void set_fiq_handler(void *start, unsigned int length)
2757 void *base = vectors_page;
2758 unsigned offset = FIQ_OFFSET;
2759
2760 + pax_open_kernel();
2761 memcpy(base + offset, start, length);
2762 + pax_close_kernel();
2763 +
2764 if (!cache_is_vipt_nonaliasing())
2765 flush_icache_range((unsigned long)base + offset, offset +
2766 length);
2767 diff --git a/arch/arm/kernel/head.S b/arch/arm/kernel/head.S
2768 index 32f317e..710ae07 100644
2769 --- a/arch/arm/kernel/head.S
2770 +++ b/arch/arm/kernel/head.S
2771 @@ -52,7 +52,9 @@
2772 .equ swapper_pg_dir, KERNEL_RAM_VADDR - PG_DIR_SIZE
2773
2774 .macro pgtbl, rd, phys
2775 - add \rd, \phys, #TEXT_OFFSET - PG_DIR_SIZE
2776 + mov \rd, #TEXT_OFFSET
2777 + sub \rd, #PG_DIR_SIZE
2778 + add \rd, \rd, \phys
2779 .endm
2780
2781 /*
2782 @@ -436,7 +438,7 @@ __enable_mmu:
2783 mov r5, #(domain_val(DOMAIN_USER, DOMAIN_MANAGER) | \
2784 domain_val(DOMAIN_KERNEL, DOMAIN_MANAGER) | \
2785 domain_val(DOMAIN_TABLE, DOMAIN_MANAGER) | \
2786 - domain_val(DOMAIN_IO, DOMAIN_CLIENT))
2787 + domain_val(DOMAIN_IO, DOMAIN_KERNELCLIENT))
2788 mcr p15, 0, r5, c3, c0, 0 @ load domain access register
2789 mcr p15, 0, r4, c2, c0, 0 @ load page table pointer
2790 #endif
2791 diff --git a/arch/arm/kernel/module.c b/arch/arm/kernel/module.c
2792 index 45e4781..8eac93d 100644
2793 --- a/arch/arm/kernel/module.c
2794 +++ b/arch/arm/kernel/module.c
2795 @@ -38,12 +38,39 @@
2796 #endif
2797
2798 #ifdef CONFIG_MMU
2799 -void *module_alloc(unsigned long size)
2800 +static inline void *__module_alloc(unsigned long size, pgprot_t prot)
2801 {
2802 + if (!size || PAGE_ALIGN(size) > MODULES_END - MODULES_VADDR)
2803 + return NULL;
2804 return __vmalloc_node_range(size, 1, MODULES_VADDR, MODULES_END,
2805 - GFP_KERNEL, PAGE_KERNEL_EXEC, NUMA_NO_NODE,
2806 + GFP_KERNEL, prot, NUMA_NO_NODE,
2807 __builtin_return_address(0));
2808 }
2809 +
2810 +void *module_alloc(unsigned long size)
2811 +{
2812 +
2813 +#ifdef CONFIG_PAX_KERNEXEC
2814 + return __module_alloc(size, PAGE_KERNEL);
2815 +#else
2816 + return __module_alloc(size, PAGE_KERNEL_EXEC);
2817 +#endif
2818 +
2819 +}
2820 +
2821 +#ifdef CONFIG_PAX_KERNEXEC
2822 +void module_free_exec(struct module *mod, void *module_region)
2823 +{
2824 + module_free(mod, module_region);
2825 +}
2826 +EXPORT_SYMBOL(module_free_exec);
2827 +
2828 +void *module_alloc_exec(unsigned long size)
2829 +{
2830 + return __module_alloc(size, PAGE_KERNEL_EXEC);
2831 +}
2832 +EXPORT_SYMBOL(module_alloc_exec);
2833 +#endif
2834 #endif
2835
2836 int
2837 diff --git a/arch/arm/kernel/patch.c b/arch/arm/kernel/patch.c
2838 index 07314af..c46655c 100644
2839 --- a/arch/arm/kernel/patch.c
2840 +++ b/arch/arm/kernel/patch.c
2841 @@ -18,6 +18,7 @@ void __kprobes __patch_text(void *addr, unsigned int insn)
2842 bool thumb2 = IS_ENABLED(CONFIG_THUMB2_KERNEL);
2843 int size;
2844
2845 + pax_open_kernel();
2846 if (thumb2 && __opcode_is_thumb16(insn)) {
2847 *(u16 *)addr = __opcode_to_mem_thumb16(insn);
2848 size = sizeof(u16);
2849 @@ -39,6 +40,7 @@ void __kprobes __patch_text(void *addr, unsigned int insn)
2850 *(u32 *)addr = insn;
2851 size = sizeof(u32);
2852 }
2853 + pax_close_kernel();
2854
2855 flush_icache_range((uintptr_t)(addr),
2856 (uintptr_t)(addr) + size);
2857 diff --git a/arch/arm/kernel/process.c b/arch/arm/kernel/process.c
2858 index 92f7b15..7048500 100644
2859 --- a/arch/arm/kernel/process.c
2860 +++ b/arch/arm/kernel/process.c
2861 @@ -217,6 +217,7 @@ void machine_power_off(void)
2862
2863 if (pm_power_off)
2864 pm_power_off();
2865 + BUG();
2866 }
2867
2868 /*
2869 @@ -230,7 +231,7 @@ void machine_power_off(void)
2870 * executing pre-reset code, and using RAM that the primary CPU's code wishes
2871 * to use. Implementing such co-ordination would be essentially impossible.
2872 */
2873 -void machine_restart(char *cmd)
2874 +__noreturn void machine_restart(char *cmd)
2875 {
2876 local_irq_disable();
2877 smp_send_stop();
2878 @@ -253,8 +254,8 @@ void __show_regs(struct pt_regs *regs)
2879
2880 show_regs_print_info(KERN_DEFAULT);
2881
2882 - print_symbol("PC is at %s\n", instruction_pointer(regs));
2883 - print_symbol("LR is at %s\n", regs->ARM_lr);
2884 + printk("PC is at %pA\n", (void *)instruction_pointer(regs));
2885 + printk("LR is at %pA\n", (void *)regs->ARM_lr);
2886 printk("pc : [<%08lx>] lr : [<%08lx>] psr: %08lx\n"
2887 "sp : %08lx ip : %08lx fp : %08lx\n",
2888 regs->ARM_pc, regs->ARM_lr, regs->ARM_cpsr,
2889 @@ -425,12 +426,6 @@ unsigned long get_wchan(struct task_struct *p)
2890 return 0;
2891 }
2892
2893 -unsigned long arch_randomize_brk(struct mm_struct *mm)
2894 -{
2895 - unsigned long range_end = mm->brk + 0x02000000;
2896 - return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
2897 -}
2898 -
2899 #ifdef CONFIG_MMU
2900 #ifdef CONFIG_KUSER_HELPERS
2901 /*
2902 @@ -446,7 +441,7 @@ static struct vm_area_struct gate_vma = {
2903
2904 static int __init gate_vma_init(void)
2905 {
2906 - gate_vma.vm_page_prot = PAGE_READONLY_EXEC;
2907 + gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
2908 return 0;
2909 }
2910 arch_initcall(gate_vma_init);
2911 @@ -472,41 +467,16 @@ int in_gate_area_no_mm(unsigned long addr)
2912
2913 const char *arch_vma_name(struct vm_area_struct *vma)
2914 {
2915 - return is_gate_vma(vma) ? "[vectors]" :
2916 - (vma->vm_mm && vma->vm_start == vma->vm_mm->context.sigpage) ?
2917 - "[sigpage]" : NULL;
2918 + return is_gate_vma(vma) ? "[vectors]" : NULL;
2919 }
2920
2921 -static struct page *signal_page;
2922 -extern struct page *get_signal_page(void);
2923 -
2924 int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
2925 {
2926 struct mm_struct *mm = current->mm;
2927 - unsigned long addr;
2928 - int ret;
2929 -
2930 - if (!signal_page)
2931 - signal_page = get_signal_page();
2932 - if (!signal_page)
2933 - return -ENOMEM;
2934
2935 down_write(&mm->mmap_sem);
2936 - addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, 0);
2937 - if (IS_ERR_VALUE(addr)) {
2938 - ret = addr;
2939 - goto up_fail;
2940 - }
2941 -
2942 - ret = install_special_mapping(mm, addr, PAGE_SIZE,
2943 - VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC,
2944 - &signal_page);
2945 -
2946 - if (ret == 0)
2947 - mm->context.sigpage = addr;
2948 -
2949 - up_fail:
2950 + mm->context.sigpage = (PAGE_OFFSET + (get_random_int() % 0x3FFEFFE0)) & 0xFFFFFFFC;
2951 up_write(&mm->mmap_sem);
2952 - return ret;
2953 + return 0;
2954 }
2955 #endif
2956 diff --git a/arch/arm/kernel/psci.c b/arch/arm/kernel/psci.c
2957 index 4693188..4596c5e 100644
2958 --- a/arch/arm/kernel/psci.c
2959 +++ b/arch/arm/kernel/psci.c
2960 @@ -24,7 +24,7 @@
2961 #include <asm/opcodes-virt.h>
2962 #include <asm/psci.h>
2963
2964 -struct psci_operations psci_ops;
2965 +struct psci_operations psci_ops __read_only;
2966
2967 static int (*invoke_psci_fn)(u32, u32, u32, u32);
2968
2969 diff --git a/arch/arm/kernel/ptrace.c b/arch/arm/kernel/ptrace.c
2970 index 0dd3b79..e018f64 100644
2971 --- a/arch/arm/kernel/ptrace.c
2972 +++ b/arch/arm/kernel/ptrace.c
2973 @@ -929,10 +929,19 @@ static int tracehook_report_syscall(struct pt_regs *regs,
2974 return current_thread_info()->syscall;
2975 }
2976
2977 +#ifdef CONFIG_GRKERNSEC_SETXID
2978 +extern void gr_delayed_cred_worker(void);
2979 +#endif
2980 +
2981 asmlinkage int syscall_trace_enter(struct pt_regs *regs, int scno)
2982 {
2983 current_thread_info()->syscall = scno;
2984
2985 +#ifdef CONFIG_GRKERNSEC_SETXID
2986 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
2987 + gr_delayed_cred_worker();
2988 +#endif
2989 +
2990 /* Do the secure computing check first; failures should be fast. */
2991 if (secure_computing(scno) == -1)
2992 return -1;
2993 diff --git a/arch/arm/kernel/setup.c b/arch/arm/kernel/setup.c
2994 index 987a7f5..ab0c397 100644
2995 --- a/arch/arm/kernel/setup.c
2996 +++ b/arch/arm/kernel/setup.c
2997 @@ -100,21 +100,23 @@ EXPORT_SYMBOL(system_serial_high);
2998 unsigned int elf_hwcap __read_mostly;
2999 EXPORT_SYMBOL(elf_hwcap);
3000
3001 +pteval_t __supported_pte_mask __read_only;
3002 +pmdval_t __supported_pmd_mask __read_only;
3003
3004 #ifdef MULTI_CPU
3005 -struct processor processor __read_mostly;
3006 +struct processor processor __read_only;
3007 #endif
3008 #ifdef MULTI_TLB
3009 -struct cpu_tlb_fns cpu_tlb __read_mostly;
3010 +struct cpu_tlb_fns cpu_tlb __read_only;
3011 #endif
3012 #ifdef MULTI_USER
3013 -struct cpu_user_fns cpu_user __read_mostly;
3014 +struct cpu_user_fns cpu_user __read_only;
3015 #endif
3016 #ifdef MULTI_CACHE
3017 -struct cpu_cache_fns cpu_cache __read_mostly;
3018 +struct cpu_cache_fns cpu_cache __read_only;
3019 #endif
3020 #ifdef CONFIG_OUTER_CACHE
3021 -struct outer_cache_fns outer_cache __read_mostly;
3022 +struct outer_cache_fns outer_cache __read_only;
3023 EXPORT_SYMBOL(outer_cache);
3024 #endif
3025
3026 @@ -247,9 +249,13 @@ static int __get_cpu_architecture(void)
3027 asm("mrc p15, 0, %0, c0, c1, 4"
3028 : "=r" (mmfr0));
3029 if ((mmfr0 & 0x0000000f) >= 0x00000003 ||
3030 - (mmfr0 & 0x000000f0) >= 0x00000030)
3031 + (mmfr0 & 0x000000f0) >= 0x00000030) {
3032 cpu_arch = CPU_ARCH_ARMv7;
3033 - else if ((mmfr0 & 0x0000000f) == 0x00000002 ||
3034 + if ((mmfr0 & 0x0000000f) == 0x00000005 || (mmfr0 & 0x0000000f) == 0x00000004) {
3035 + __supported_pte_mask |= L_PTE_PXN;
3036 + __supported_pmd_mask |= PMD_PXNTABLE;
3037 + }
3038 + } else if ((mmfr0 & 0x0000000f) == 0x00000002 ||
3039 (mmfr0 & 0x000000f0) == 0x00000020)
3040 cpu_arch = CPU_ARCH_ARMv6;
3041 else
3042 diff --git a/arch/arm/kernel/signal.c b/arch/arm/kernel/signal.c
3043 index 04d6388..5115238 100644
3044 --- a/arch/arm/kernel/signal.c
3045 +++ b/arch/arm/kernel/signal.c
3046 @@ -23,8 +23,6 @@
3047
3048 extern const unsigned long sigreturn_codes[7];
3049
3050 -static unsigned long signal_return_offset;
3051 -
3052 #ifdef CONFIG_CRUNCH
3053 static int preserve_crunch_context(struct crunch_sigframe __user *frame)
3054 {
3055 @@ -395,8 +393,7 @@ setup_return(struct pt_regs *regs, struct ksignal *ksig,
3056 * except when the MPU has protected the vectors
3057 * page from PL0
3058 */
3059 - retcode = mm->context.sigpage + signal_return_offset +
3060 - (idx << 2) + thumb;
3061 + retcode = mm->context.sigpage + (idx << 2) + thumb;
3062 } else
3063 #endif
3064 {
3065 @@ -600,33 +597,3 @@ do_work_pending(struct pt_regs *regs, unsigned int thread_flags, int syscall)
3066 } while (thread_flags & _TIF_WORK_MASK);
3067 return 0;
3068 }
3069 -
3070 -struct page *get_signal_page(void)
3071 -{
3072 - unsigned long ptr;
3073 - unsigned offset;
3074 - struct page *page;
3075 - void *addr;
3076 -
3077 - page = alloc_pages(GFP_KERNEL, 0);
3078 -
3079 - if (!page)
3080 - return NULL;
3081 -
3082 - addr = page_address(page);
3083 -
3084 - /* Give the signal return code some randomness */
3085 - offset = 0x200 + (get_random_int() & 0x7fc);
3086 - signal_return_offset = offset;
3087 -
3088 - /*
3089 - * Copy signal return handlers into the vector page, and
3090 - * set sigreturn to be a pointer to these.
3091 - */
3092 - memcpy(addr + offset, sigreturn_codes, sizeof(sigreturn_codes));
3093 -
3094 - ptr = (unsigned long)addr + offset;
3095 - flush_icache_range(ptr, ptr + sizeof(sigreturn_codes));
3096 -
3097 - return page;
3098 -}
3099 diff --git a/arch/arm/kernel/smp.c b/arch/arm/kernel/smp.c
3100 index dc894ab..f929a0d 100644
3101 --- a/arch/arm/kernel/smp.c
3102 +++ b/arch/arm/kernel/smp.c
3103 @@ -73,7 +73,7 @@ enum ipi_msg_type {
3104
3105 static DECLARE_COMPLETION(cpu_running);
3106
3107 -static struct smp_operations smp_ops;
3108 +static struct smp_operations smp_ops __read_only;
3109
3110 void __init smp_set_ops(struct smp_operations *ops)
3111 {
3112 diff --git a/arch/arm/kernel/traps.c b/arch/arm/kernel/traps.c
3113 index 4636d56..ce4ec3d 100644
3114 --- a/arch/arm/kernel/traps.c
3115 +++ b/arch/arm/kernel/traps.c
3116 @@ -62,7 +62,7 @@ static void dump_mem(const char *, const char *, unsigned long, unsigned long);
3117 void dump_backtrace_entry(unsigned long where, unsigned long from, unsigned long frame)
3118 {
3119 #ifdef CONFIG_KALLSYMS
3120 - printk("[<%08lx>] (%pS) from [<%08lx>] (%pS)\n", where, (void *)where, from, (void *)from);
3121 + printk("[<%08lx>] (%pA) from [<%08lx>] (%pA)\n", where, (void *)where, from, (void *)from);
3122 #else
3123 printk("Function entered at [<%08lx>] from [<%08lx>]\n", where, from);
3124 #endif
3125 @@ -264,6 +264,8 @@ static arch_spinlock_t die_lock = __ARCH_SPIN_LOCK_UNLOCKED;
3126 static int die_owner = -1;
3127 static unsigned int die_nest_count;
3128
3129 +extern void gr_handle_kernel_exploit(void);
3130 +
3131 static unsigned long oops_begin(void)
3132 {
3133 int cpu;
3134 @@ -306,6 +308,9 @@ static void oops_end(unsigned long flags, struct pt_regs *regs, int signr)
3135 panic("Fatal exception in interrupt");
3136 if (panic_on_oops)
3137 panic("Fatal exception");
3138 +
3139 + gr_handle_kernel_exploit();
3140 +
3141 if (signr)
3142 do_exit(signr);
3143 }
3144 @@ -642,7 +647,9 @@ asmlinkage int arm_syscall(int no, struct pt_regs *regs)
3145 * The user helper at 0xffff0fe0 must be used instead.
3146 * (see entry-armv.S for details)
3147 */
3148 + pax_open_kernel();
3149 *((unsigned int *)0xffff0ff0) = regs->ARM_r0;
3150 + pax_close_kernel();
3151 }
3152 return 0;
3153
3154 @@ -899,7 +906,11 @@ void __init early_trap_init(void *vectors_base)
3155 kuser_init(vectors_base);
3156
3157 flush_icache_range(vectors, vectors + PAGE_SIZE * 2);
3158 - modify_domain(DOMAIN_USER, DOMAIN_CLIENT);
3159 +
3160 +#ifndef CONFIG_PAX_MEMORY_UDEREF
3161 + modify_domain(DOMAIN_USER, DOMAIN_USERCLIENT);
3162 +#endif
3163 +
3164 #else /* ifndef CONFIG_CPU_V7M */
3165 /*
3166 * on V7-M there is no need to copy the vector table to a dedicated
3167 diff --git a/arch/arm/kernel/vmlinux.lds.S b/arch/arm/kernel/vmlinux.lds.S
3168 index 7bcee5c..e2f3249 100644
3169 --- a/arch/arm/kernel/vmlinux.lds.S
3170 +++ b/arch/arm/kernel/vmlinux.lds.S
3171 @@ -8,7 +8,11 @@
3172 #include <asm/thread_info.h>
3173 #include <asm/memory.h>
3174 #include <asm/page.h>
3175 -
3176 +
3177 +#ifdef CONFIG_PAX_KERNEXEC
3178 +#include <asm/pgtable.h>
3179 +#endif
3180 +
3181 #define PROC_INFO \
3182 . = ALIGN(4); \
3183 VMLINUX_SYMBOL(__proc_info_begin) = .; \
3184 @@ -34,7 +38,7 @@
3185 #endif
3186
3187 #if (defined(CONFIG_SMP_ON_UP) && !defined(CONFIG_DEBUG_SPINLOCK)) || \
3188 - defined(CONFIG_GENERIC_BUG)
3189 + defined(CONFIG_GENERIC_BUG) || defined(CONFIG_PAX_REFCOUNT)
3190 #define ARM_EXIT_KEEP(x) x
3191 #define ARM_EXIT_DISCARD(x)
3192 #else
3193 @@ -90,6 +94,11 @@ SECTIONS
3194 _text = .;
3195 HEAD_TEXT
3196 }
3197 +
3198 +#ifdef CONFIG_PAX_KERNEXEC
3199 + . = ALIGN(1<<SECTION_SHIFT);
3200 +#endif
3201 +
3202 .text : { /* Real text segment */
3203 _stext = .; /* Text and read-only data */
3204 __exception_text_start = .;
3205 @@ -112,6 +121,8 @@ SECTIONS
3206 ARM_CPU_KEEP(PROC_INFO)
3207 }
3208
3209 + _etext = .; /* End of text section */
3210 +
3211 RO_DATA(PAGE_SIZE)
3212
3213 . = ALIGN(4);
3214 @@ -142,7 +153,9 @@ SECTIONS
3215
3216 NOTES
3217
3218 - _etext = .; /* End of text and rodata section */
3219 +#ifdef CONFIG_PAX_KERNEXEC
3220 + . = ALIGN(1<<SECTION_SHIFT);
3221 +#endif
3222
3223 #ifndef CONFIG_XIP_KERNEL
3224 . = ALIGN(PAGE_SIZE);
3225 @@ -220,6 +233,11 @@ SECTIONS
3226 . = PAGE_OFFSET + TEXT_OFFSET;
3227 #else
3228 __init_end = .;
3229 +
3230 +#ifdef CONFIG_PAX_KERNEXEC
3231 + . = ALIGN(1<<SECTION_SHIFT);
3232 +#endif
3233 +
3234 . = ALIGN(THREAD_SIZE);
3235 __data_loc = .;
3236 #endif
3237 diff --git a/arch/arm/kvm/arm.c b/arch/arm/kvm/arm.c
3238 index 2a700e0..745b980 100644
3239 --- a/arch/arm/kvm/arm.c
3240 +++ b/arch/arm/kvm/arm.c
3241 @@ -56,7 +56,7 @@ static unsigned long hyp_default_vectors;
3242 static DEFINE_PER_CPU(struct kvm_vcpu *, kvm_arm_running_vcpu);
3243
3244 /* The VMID used in the VTTBR */
3245 -static atomic64_t kvm_vmid_gen = ATOMIC64_INIT(1);
3246 +static atomic64_unchecked_t kvm_vmid_gen = ATOMIC64_INIT(1);
3247 static u8 kvm_next_vmid;
3248 static DEFINE_SPINLOCK(kvm_vmid_lock);
3249
3250 @@ -397,7 +397,7 @@ void force_vm_exit(const cpumask_t *mask)
3251 */
3252 static bool need_new_vmid_gen(struct kvm *kvm)
3253 {
3254 - return unlikely(kvm->arch.vmid_gen != atomic64_read(&kvm_vmid_gen));
3255 + return unlikely(kvm->arch.vmid_gen != atomic64_read_unchecked(&kvm_vmid_gen));
3256 }
3257
3258 /**
3259 @@ -430,7 +430,7 @@ static void update_vttbr(struct kvm *kvm)
3260
3261 /* First user of a new VMID generation? */
3262 if (unlikely(kvm_next_vmid == 0)) {
3263 - atomic64_inc(&kvm_vmid_gen);
3264 + atomic64_inc_unchecked(&kvm_vmid_gen);
3265 kvm_next_vmid = 1;
3266
3267 /*
3268 @@ -447,7 +447,7 @@ static void update_vttbr(struct kvm *kvm)
3269 kvm_call_hyp(__kvm_flush_vm_context);
3270 }
3271
3272 - kvm->arch.vmid_gen = atomic64_read(&kvm_vmid_gen);
3273 + kvm->arch.vmid_gen = atomic64_read_unchecked(&kvm_vmid_gen);
3274 kvm->arch.vmid = kvm_next_vmid;
3275 kvm_next_vmid++;
3276
3277 diff --git a/arch/arm/lib/clear_user.S b/arch/arm/lib/clear_user.S
3278 index 14a0d98..7771a7d 100644
3279 --- a/arch/arm/lib/clear_user.S
3280 +++ b/arch/arm/lib/clear_user.S
3281 @@ -12,14 +12,14 @@
3282
3283 .text
3284
3285 -/* Prototype: int __clear_user(void *addr, size_t sz)
3286 +/* Prototype: int ___clear_user(void *addr, size_t sz)
3287 * Purpose : clear some user memory
3288 * Params : addr - user memory address to clear
3289 * : sz - number of bytes to clear
3290 * Returns : number of bytes NOT cleared
3291 */
3292 ENTRY(__clear_user_std)
3293 -WEAK(__clear_user)
3294 +WEAK(___clear_user)
3295 stmfd sp!, {r1, lr}
3296 mov r2, #0
3297 cmp r1, #4
3298 @@ -44,7 +44,7 @@ WEAK(__clear_user)
3299 USER( strnebt r2, [r0])
3300 mov r0, #0
3301 ldmfd sp!, {r1, pc}
3302 -ENDPROC(__clear_user)
3303 +ENDPROC(___clear_user)
3304 ENDPROC(__clear_user_std)
3305
3306 .pushsection .fixup,"ax"
3307 diff --git a/arch/arm/lib/copy_from_user.S b/arch/arm/lib/copy_from_user.S
3308 index 66a477a..bee61d3 100644
3309 --- a/arch/arm/lib/copy_from_user.S
3310 +++ b/arch/arm/lib/copy_from_user.S
3311 @@ -16,7 +16,7 @@
3312 /*
3313 * Prototype:
3314 *
3315 - * size_t __copy_from_user(void *to, const void *from, size_t n)
3316 + * size_t ___copy_from_user(void *to, const void *from, size_t n)
3317 *
3318 * Purpose:
3319 *
3320 @@ -84,11 +84,11 @@
3321
3322 .text
3323
3324 -ENTRY(__copy_from_user)
3325 +ENTRY(___copy_from_user)
3326
3327 #include "copy_template.S"
3328
3329 -ENDPROC(__copy_from_user)
3330 +ENDPROC(___copy_from_user)
3331
3332 .pushsection .fixup,"ax"
3333 .align 0
3334 diff --git a/arch/arm/lib/copy_page.S b/arch/arm/lib/copy_page.S
3335 index 6ee2f67..d1cce76 100644
3336 --- a/arch/arm/lib/copy_page.S
3337 +++ b/arch/arm/lib/copy_page.S
3338 @@ -10,6 +10,7 @@
3339 * ASM optimised string functions
3340 */
3341 #include <linux/linkage.h>
3342 +#include <linux/const.h>
3343 #include <asm/assembler.h>
3344 #include <asm/asm-offsets.h>
3345 #include <asm/cache.h>
3346 diff --git a/arch/arm/lib/copy_to_user.S b/arch/arm/lib/copy_to_user.S
3347 index d066df6..df28194 100644
3348 --- a/arch/arm/lib/copy_to_user.S
3349 +++ b/arch/arm/lib/copy_to_user.S
3350 @@ -16,7 +16,7 @@
3351 /*
3352 * Prototype:
3353 *
3354 - * size_t __copy_to_user(void *to, const void *from, size_t n)
3355 + * size_t ___copy_to_user(void *to, const void *from, size_t n)
3356 *
3357 * Purpose:
3358 *
3359 @@ -88,11 +88,11 @@
3360 .text
3361
3362 ENTRY(__copy_to_user_std)
3363 -WEAK(__copy_to_user)
3364 +WEAK(___copy_to_user)
3365
3366 #include "copy_template.S"
3367
3368 -ENDPROC(__copy_to_user)
3369 +ENDPROC(___copy_to_user)
3370 ENDPROC(__copy_to_user_std)
3371
3372 .pushsection .fixup,"ax"
3373 diff --git a/arch/arm/lib/csumpartialcopyuser.S b/arch/arm/lib/csumpartialcopyuser.S
3374 index 7d08b43..f7ca7ea 100644
3375 --- a/arch/arm/lib/csumpartialcopyuser.S
3376 +++ b/arch/arm/lib/csumpartialcopyuser.S
3377 @@ -57,8 +57,8 @@
3378 * Returns : r0 = checksum, [[sp, #0], #0] = 0 or -EFAULT
3379 */
3380
3381 -#define FN_ENTRY ENTRY(csum_partial_copy_from_user)
3382 -#define FN_EXIT ENDPROC(csum_partial_copy_from_user)
3383 +#define FN_ENTRY ENTRY(__csum_partial_copy_from_user)
3384 +#define FN_EXIT ENDPROC(__csum_partial_copy_from_user)
3385
3386 #include "csumpartialcopygeneric.S"
3387
3388 diff --git a/arch/arm/lib/delay.c b/arch/arm/lib/delay.c
3389 index 5306de3..aed6d03 100644
3390 --- a/arch/arm/lib/delay.c
3391 +++ b/arch/arm/lib/delay.c
3392 @@ -28,7 +28,7 @@
3393 /*
3394 * Default to the loop-based delay implementation.
3395 */
3396 -struct arm_delay_ops arm_delay_ops = {
3397 +struct arm_delay_ops arm_delay_ops __read_only = {
3398 .delay = __loop_delay,
3399 .const_udelay = __loop_const_udelay,
3400 .udelay = __loop_udelay,
3401 diff --git a/arch/arm/lib/uaccess_with_memcpy.c b/arch/arm/lib/uaccess_with_memcpy.c
3402 index 3e58d71..029817c 100644
3403 --- a/arch/arm/lib/uaccess_with_memcpy.c
3404 +++ b/arch/arm/lib/uaccess_with_memcpy.c
3405 @@ -136,7 +136,7 @@ out:
3406 }
3407
3408 unsigned long
3409 -__copy_to_user(void __user *to, const void *from, unsigned long n)
3410 +___copy_to_user(void __user *to, const void *from, unsigned long n)
3411 {
3412 /*
3413 * This test is stubbed out of the main function above to keep
3414 @@ -190,7 +190,7 @@ out:
3415 return n;
3416 }
3417
3418 -unsigned long __clear_user(void __user *addr, unsigned long n)
3419 +unsigned long ___clear_user(void __user *addr, unsigned long n)
3420 {
3421 /* See rational for this in __copy_to_user() above. */
3422 if (n < 64)
3423 diff --git a/arch/arm/mach-kirkwood/common.c b/arch/arm/mach-kirkwood/common.c
3424 index f3407a5..bd4256f 100644
3425 --- a/arch/arm/mach-kirkwood/common.c
3426 +++ b/arch/arm/mach-kirkwood/common.c
3427 @@ -156,7 +156,16 @@ static void clk_gate_fn_disable(struct clk_hw *hw)
3428 clk_gate_ops.disable(hw);
3429 }
3430
3431 -static struct clk_ops clk_gate_fn_ops;
3432 +static int clk_gate_fn_is_enabled(struct clk_hw *hw)
3433 +{
3434 + return clk_gate_ops.is_enabled(hw);
3435 +}
3436 +
3437 +static struct clk_ops clk_gate_fn_ops = {
3438 + .enable = clk_gate_fn_enable,
3439 + .disable = clk_gate_fn_disable,
3440 + .is_enabled = clk_gate_fn_is_enabled,
3441 +};
3442
3443 static struct clk __init *clk_register_gate_fn(struct device *dev,
3444 const char *name,
3445 @@ -190,14 +199,6 @@ static struct clk __init *clk_register_gate_fn(struct device *dev,
3446 gate_fn->fn_en = fn_en;
3447 gate_fn->fn_dis = fn_dis;
3448
3449 - /* ops is the gate ops, but with our enable/disable functions */
3450 - if (clk_gate_fn_ops.enable != clk_gate_fn_enable ||
3451 - clk_gate_fn_ops.disable != clk_gate_fn_disable) {
3452 - clk_gate_fn_ops = clk_gate_ops;
3453 - clk_gate_fn_ops.enable = clk_gate_fn_enable;
3454 - clk_gate_fn_ops.disable = clk_gate_fn_disable;
3455 - }
3456 -
3457 clk = clk_register(dev, &gate_fn->gate.hw);
3458
3459 if (IS_ERR(clk))
3460 diff --git a/arch/arm/mach-omap2/board-n8x0.c b/arch/arm/mach-omap2/board-n8x0.c
3461 index 827d1500..2885dc6 100644
3462 --- a/arch/arm/mach-omap2/board-n8x0.c
3463 +++ b/arch/arm/mach-omap2/board-n8x0.c
3464 @@ -627,7 +627,7 @@ static int n8x0_menelaus_late_init(struct device *dev)
3465 }
3466 #endif
3467
3468 -static struct menelaus_platform_data n8x0_menelaus_platform_data __initdata = {
3469 +static struct menelaus_platform_data n8x0_menelaus_platform_data __initconst = {
3470 .late_init = n8x0_menelaus_late_init,
3471 };
3472
3473 diff --git a/arch/arm/mach-omap2/gpmc.c b/arch/arm/mach-omap2/gpmc.c
3474 index ab43755..ccfa231 100644
3475 --- a/arch/arm/mach-omap2/gpmc.c
3476 +++ b/arch/arm/mach-omap2/gpmc.c
3477 @@ -148,7 +148,6 @@ struct omap3_gpmc_regs {
3478 };
3479
3480 static struct gpmc_client_irq gpmc_client_irq[GPMC_NR_IRQ];
3481 -static struct irq_chip gpmc_irq_chip;
3482 static int gpmc_irq_start;
3483
3484 static struct resource gpmc_mem_root;
3485 @@ -716,6 +715,18 @@ static void gpmc_irq_noop(struct irq_data *data) { }
3486
3487 static unsigned int gpmc_irq_noop_ret(struct irq_data *data) { return 0; }
3488
3489 +static struct irq_chip gpmc_irq_chip = {
3490 + .name = "gpmc",
3491 + .irq_startup = gpmc_irq_noop_ret,
3492 + .irq_enable = gpmc_irq_enable,
3493 + .irq_disable = gpmc_irq_disable,
3494 + .irq_shutdown = gpmc_irq_noop,
3495 + .irq_ack = gpmc_irq_noop,
3496 + .irq_mask = gpmc_irq_noop,
3497 + .irq_unmask = gpmc_irq_noop,
3498 +
3499 +};
3500 +
3501 static int gpmc_setup_irq(void)
3502 {
3503 int i;
3504 @@ -730,15 +741,6 @@ static int gpmc_setup_irq(void)
3505 return gpmc_irq_start;
3506 }
3507
3508 - gpmc_irq_chip.name = "gpmc";
3509 - gpmc_irq_chip.irq_startup = gpmc_irq_noop_ret;
3510 - gpmc_irq_chip.irq_enable = gpmc_irq_enable;
3511 - gpmc_irq_chip.irq_disable = gpmc_irq_disable;
3512 - gpmc_irq_chip.irq_shutdown = gpmc_irq_noop;
3513 - gpmc_irq_chip.irq_ack = gpmc_irq_noop;
3514 - gpmc_irq_chip.irq_mask = gpmc_irq_noop;
3515 - gpmc_irq_chip.irq_unmask = gpmc_irq_noop;
3516 -
3517 gpmc_client_irq[0].bitmask = GPMC_IRQ_FIFOEVENTENABLE;
3518 gpmc_client_irq[1].bitmask = GPMC_IRQ_COUNT_EVENT;
3519
3520 diff --git a/arch/arm/mach-omap2/omap-mpuss-lowpower.c b/arch/arm/mach-omap2/omap-mpuss-lowpower.c
3521 index f991016..145ebeb 100644
3522 --- a/arch/arm/mach-omap2/omap-mpuss-lowpower.c
3523 +++ b/arch/arm/mach-omap2/omap-mpuss-lowpower.c
3524 @@ -84,7 +84,7 @@ struct cpu_pm_ops {
3525 int (*finish_suspend)(unsigned long cpu_state);
3526 void (*resume)(void);
3527 void (*scu_prepare)(unsigned int cpu_id, unsigned int cpu_state);
3528 -};
3529 +} __no_const;
3530
3531 static DEFINE_PER_CPU(struct omap4_cpu_pm_info, omap4_pm_info);
3532 static struct powerdomain *mpuss_pd;
3533 @@ -102,7 +102,7 @@ static void dummy_cpu_resume(void)
3534 static void dummy_scu_prepare(unsigned int cpu_id, unsigned int cpu_state)
3535 {}
3536
3537 -struct cpu_pm_ops omap_pm_ops = {
3538 +static struct cpu_pm_ops omap_pm_ops __read_only = {
3539 .finish_suspend = default_finish_suspend,
3540 .resume = dummy_cpu_resume,
3541 .scu_prepare = dummy_scu_prepare,
3542 diff --git a/arch/arm/mach-omap2/omap-wakeupgen.c b/arch/arm/mach-omap2/omap-wakeupgen.c
3543 index 3664562..72f85c6 100644
3544 --- a/arch/arm/mach-omap2/omap-wakeupgen.c
3545 +++ b/arch/arm/mach-omap2/omap-wakeupgen.c
3546 @@ -343,7 +343,7 @@ static int irq_cpu_hotplug_notify(struct notifier_block *self,
3547 return NOTIFY_OK;
3548 }
3549
3550 -static struct notifier_block __refdata irq_hotplug_notifier = {
3551 +static struct notifier_block irq_hotplug_notifier = {
3552 .notifier_call = irq_cpu_hotplug_notify,
3553 };
3554
3555 diff --git a/arch/arm/mach-omap2/omap_device.c b/arch/arm/mach-omap2/omap_device.c
3556 index e0a398c..a470fa5 100644
3557 --- a/arch/arm/mach-omap2/omap_device.c
3558 +++ b/arch/arm/mach-omap2/omap_device.c
3559 @@ -508,7 +508,7 @@ void omap_device_delete(struct omap_device *od)
3560 struct platform_device __init *omap_device_build(const char *pdev_name,
3561 int pdev_id,
3562 struct omap_hwmod *oh,
3563 - void *pdata, int pdata_len)
3564 + const void *pdata, int pdata_len)
3565 {
3566 struct omap_hwmod *ohs[] = { oh };
3567
3568 @@ -536,7 +536,7 @@ struct platform_device __init *omap_device_build(const char *pdev_name,
3569 struct platform_device __init *omap_device_build_ss(const char *pdev_name,
3570 int pdev_id,
3571 struct omap_hwmod **ohs,
3572 - int oh_cnt, void *pdata,
3573 + int oh_cnt, const void *pdata,
3574 int pdata_len)
3575 {
3576 int ret = -ENOMEM;
3577 diff --git a/arch/arm/mach-omap2/omap_device.h b/arch/arm/mach-omap2/omap_device.h
3578 index 78c02b3..c94109a 100644
3579 --- a/arch/arm/mach-omap2/omap_device.h
3580 +++ b/arch/arm/mach-omap2/omap_device.h
3581 @@ -72,12 +72,12 @@ int omap_device_idle(struct platform_device *pdev);
3582 /* Core code interface */
3583
3584 struct platform_device *omap_device_build(const char *pdev_name, int pdev_id,
3585 - struct omap_hwmod *oh, void *pdata,
3586 + struct omap_hwmod *oh, const void *pdata,
3587 int pdata_len);
3588
3589 struct platform_device *omap_device_build_ss(const char *pdev_name, int pdev_id,
3590 struct omap_hwmod **oh, int oh_cnt,
3591 - void *pdata, int pdata_len);
3592 + const void *pdata, int pdata_len);
3593
3594 struct omap_device *omap_device_alloc(struct platform_device *pdev,
3595 struct omap_hwmod **ohs, int oh_cnt);
3596 diff --git a/arch/arm/mach-omap2/omap_hwmod.c b/arch/arm/mach-omap2/omap_hwmod.c
3597 index 8a1b5e0..5f30074 100644
3598 --- a/arch/arm/mach-omap2/omap_hwmod.c
3599 +++ b/arch/arm/mach-omap2/omap_hwmod.c
3600 @@ -194,10 +194,10 @@ struct omap_hwmod_soc_ops {
3601 int (*init_clkdm)(struct omap_hwmod *oh);
3602 void (*update_context_lost)(struct omap_hwmod *oh);
3603 int (*get_context_lost)(struct omap_hwmod *oh);
3604 -};
3605 +} __no_const;
3606
3607 /* soc_ops: adapts the omap_hwmod code to the currently-booted SoC */
3608 -static struct omap_hwmod_soc_ops soc_ops;
3609 +static struct omap_hwmod_soc_ops soc_ops __read_only;
3610
3611 /* omap_hwmod_list contains all registered struct omap_hwmods */
3612 static LIST_HEAD(omap_hwmod_list);
3613 diff --git a/arch/arm/mach-omap2/powerdomains43xx_data.c b/arch/arm/mach-omap2/powerdomains43xx_data.c
3614 index 95fee54..cfa9cf1 100644
3615 --- a/arch/arm/mach-omap2/powerdomains43xx_data.c
3616 +++ b/arch/arm/mach-omap2/powerdomains43xx_data.c
3617 @@ -10,6 +10,7 @@
3618
3619 #include <linux/kernel.h>
3620 #include <linux/init.h>
3621 +#include <asm/pgtable.h>
3622
3623 #include "powerdomain.h"
3624
3625 @@ -129,7 +130,9 @@ static int am43xx_check_vcvp(void)
3626
3627 void __init am43xx_powerdomains_init(void)
3628 {
3629 - omap4_pwrdm_operations.pwrdm_has_voltdm = am43xx_check_vcvp;
3630 + pax_open_kernel();
3631 + *(void **)&omap4_pwrdm_operations.pwrdm_has_voltdm = am43xx_check_vcvp;
3632 + pax_close_kernel();
3633 pwrdm_register_platform_funcs(&omap4_pwrdm_operations);
3634 pwrdm_register_pwrdms(powerdomains_am43xx);
3635 pwrdm_complete_init();
3636 diff --git a/arch/arm/mach-omap2/wd_timer.c b/arch/arm/mach-omap2/wd_timer.c
3637 index d15c7bb..b2d1f0c 100644
3638 --- a/arch/arm/mach-omap2/wd_timer.c
3639 +++ b/arch/arm/mach-omap2/wd_timer.c
3640 @@ -110,7 +110,9 @@ static int __init omap_init_wdt(void)
3641 struct omap_hwmod *oh;
3642 char *oh_name = "wd_timer2";
3643 char *dev_name = "omap_wdt";
3644 - struct omap_wd_timer_platform_data pdata;
3645 + static struct omap_wd_timer_platform_data pdata = {
3646 + .read_reset_sources = prm_read_reset_sources
3647 + };
3648
3649 if (!cpu_class_is_omap2() || of_have_populated_dt())
3650 return 0;
3651 @@ -121,8 +123,6 @@ static int __init omap_init_wdt(void)
3652 return -EINVAL;
3653 }
3654
3655 - pdata.read_reset_sources = prm_read_reset_sources;
3656 -
3657 pdev = omap_device_build(dev_name, id, oh, &pdata,
3658 sizeof(struct omap_wd_timer_platform_data));
3659 WARN(IS_ERR(pdev), "Can't build omap_device for %s:%s.\n",
3660 diff --git a/arch/arm/mach-tegra/cpuidle-tegra20.c b/arch/arm/mach-tegra/cpuidle-tegra20.c
3661 index b82dcae..44ee5b6 100644
3662 --- a/arch/arm/mach-tegra/cpuidle-tegra20.c
3663 +++ b/arch/arm/mach-tegra/cpuidle-tegra20.c
3664 @@ -180,7 +180,7 @@ static int tegra20_idle_lp2_coupled(struct cpuidle_device *dev,
3665 bool entered_lp2 = false;
3666
3667 if (tegra_pending_sgi())
3668 - ACCESS_ONCE(abort_flag) = true;
3669 + ACCESS_ONCE_RW(abort_flag) = true;
3670
3671 cpuidle_coupled_parallel_barrier(dev, &abort_barrier);
3672
3673 diff --git a/arch/arm/mach-ux500/setup.h b/arch/arm/mach-ux500/setup.h
3674 index bdb3564..cebb96f 100644
3675 --- a/arch/arm/mach-ux500/setup.h
3676 +++ b/arch/arm/mach-ux500/setup.h
3677 @@ -39,13 +39,6 @@ extern void ux500_timer_init(void);
3678 .type = MT_DEVICE, \
3679 }
3680
3681 -#define __MEM_DEV_DESC(x, sz) { \
3682 - .virtual = IO_ADDRESS(x), \
3683 - .pfn = __phys_to_pfn(x), \
3684 - .length = sz, \
3685 - .type = MT_MEMORY, \
3686 -}
3687 -
3688 extern struct smp_operations ux500_smp_ops;
3689 extern void ux500_cpu_die(unsigned int cpu);
3690
3691 diff --git a/arch/arm/mm/Kconfig b/arch/arm/mm/Kconfig
3692 index 1f8fed9..14d7823 100644
3693 --- a/arch/arm/mm/Kconfig
3694 +++ b/arch/arm/mm/Kconfig
3695 @@ -446,7 +446,7 @@ config CPU_32v5
3696
3697 config CPU_32v6
3698 bool
3699 - select CPU_USE_DOMAINS if CPU_V6 && MMU
3700 + select CPU_USE_DOMAINS if CPU_V6 && MMU && !PAX_KERNEXEC && !PAX_MEMORY_UDEREF
3701 select TLS_REG_EMUL if !CPU_32v6K && !MMU
3702
3703 config CPU_32v6K
3704 @@ -601,6 +601,7 @@ config CPU_CP15_MPU
3705
3706 config CPU_USE_DOMAINS
3707 bool
3708 + depends on !ARM_LPAE && !PAX_KERNEXEC && !PAX_MEMORY_UDEREF
3709 help
3710 This option enables or disables the use of domain switching
3711 via the set_fs() function.
3712 @@ -800,6 +801,7 @@ config NEED_KUSER_HELPERS
3713 config KUSER_HELPERS
3714 bool "Enable kuser helpers in vector page" if !NEED_KUSER_HELPERS
3715 default y
3716 + depends on !(CPU_V6 || CPU_V6K || CPU_V7) || GRKERNSEC_OLD_ARM_USERLAND
3717 help
3718 Warning: disabling this option may break user programs.
3719
3720 @@ -812,7 +814,7 @@ config KUSER_HELPERS
3721 See Documentation/arm/kernel_user_helpers.txt for details.
3722
3723 However, the fixed address nature of these helpers can be used
3724 - by ROP (return orientated programming) authors when creating
3725 + by ROP (Return Oriented Programming) authors when creating
3726 exploits.
3727
3728 If all of the binaries and libraries which run on your platform
3729 diff --git a/arch/arm/mm/alignment.c b/arch/arm/mm/alignment.c
3730 index 9240364..a2b8cf3 100644
3731 --- a/arch/arm/mm/alignment.c
3732 +++ b/arch/arm/mm/alignment.c
3733 @@ -212,10 +212,12 @@ union offset_union {
3734 #define __get16_unaligned_check(ins,val,addr) \
3735 do { \
3736 unsigned int err = 0, v, a = addr; \
3737 + pax_open_userland(); \
3738 __get8_unaligned_check(ins,v,a,err); \
3739 val = v << ((BE) ? 8 : 0); \
3740 __get8_unaligned_check(ins,v,a,err); \
3741 val |= v << ((BE) ? 0 : 8); \
3742 + pax_close_userland(); \
3743 if (err) \
3744 goto fault; \
3745 } while (0)
3746 @@ -229,6 +231,7 @@ union offset_union {
3747 #define __get32_unaligned_check(ins,val,addr) \
3748 do { \
3749 unsigned int err = 0, v, a = addr; \
3750 + pax_open_userland(); \
3751 __get8_unaligned_check(ins,v,a,err); \
3752 val = v << ((BE) ? 24 : 0); \
3753 __get8_unaligned_check(ins,v,a,err); \
3754 @@ -237,6 +240,7 @@ union offset_union {
3755 val |= v << ((BE) ? 8 : 16); \
3756 __get8_unaligned_check(ins,v,a,err); \
3757 val |= v << ((BE) ? 0 : 24); \
3758 + pax_close_userland(); \
3759 if (err) \
3760 goto fault; \
3761 } while (0)
3762 @@ -250,6 +254,7 @@ union offset_union {
3763 #define __put16_unaligned_check(ins,val,addr) \
3764 do { \
3765 unsigned int err = 0, v = val, a = addr; \
3766 + pax_open_userland(); \
3767 __asm__( FIRST_BYTE_16 \
3768 ARM( "1: "ins" %1, [%2], #1\n" ) \
3769 THUMB( "1: "ins" %1, [%2]\n" ) \
3770 @@ -269,6 +274,7 @@ union offset_union {
3771 " .popsection\n" \
3772 : "=r" (err), "=&r" (v), "=&r" (a) \
3773 : "0" (err), "1" (v), "2" (a)); \
3774 + pax_close_userland(); \
3775 if (err) \
3776 goto fault; \
3777 } while (0)
3778 @@ -282,6 +288,7 @@ union offset_union {
3779 #define __put32_unaligned_check(ins,val,addr) \
3780 do { \
3781 unsigned int err = 0, v = val, a = addr; \
3782 + pax_open_userland(); \
3783 __asm__( FIRST_BYTE_32 \
3784 ARM( "1: "ins" %1, [%2], #1\n" ) \
3785 THUMB( "1: "ins" %1, [%2]\n" ) \
3786 @@ -311,6 +318,7 @@ union offset_union {
3787 " .popsection\n" \
3788 : "=r" (err), "=&r" (v), "=&r" (a) \
3789 : "0" (err), "1" (v), "2" (a)); \
3790 + pax_close_userland(); \
3791 if (err) \
3792 goto fault; \
3793 } while (0)
3794 diff --git a/arch/arm/mm/cache-l2x0.c b/arch/arm/mm/cache-l2x0.c
3795 index 447da6f..77a5057 100644
3796 --- a/arch/arm/mm/cache-l2x0.c
3797 +++ b/arch/arm/mm/cache-l2x0.c
3798 @@ -45,7 +45,7 @@ struct l2x0_of_data {
3799 void (*setup)(const struct device_node *, u32 *, u32 *);
3800 void (*save)(void);
3801 struct outer_cache_fns outer_cache;
3802 -};
3803 +} __do_const;
3804
3805 static bool of_init = false;
3806
3807 diff --git a/arch/arm/mm/context.c b/arch/arm/mm/context.c
3808 index 84e6f77..0b52f31 100644
3809 --- a/arch/arm/mm/context.c
3810 +++ b/arch/arm/mm/context.c
3811 @@ -43,7 +43,7 @@
3812 #define NUM_USER_ASIDS ASID_FIRST_VERSION
3813
3814 static DEFINE_RAW_SPINLOCK(cpu_asid_lock);
3815 -static atomic64_t asid_generation = ATOMIC64_INIT(ASID_FIRST_VERSION);
3816 +static atomic64_unchecked_t asid_generation = ATOMIC64_INIT(ASID_FIRST_VERSION);
3817 static DECLARE_BITMAP(asid_map, NUM_USER_ASIDS);
3818
3819 static DEFINE_PER_CPU(atomic64_t, active_asids);
3820 @@ -180,7 +180,7 @@ static int is_reserved_asid(u64 asid)
3821 static u64 new_context(struct mm_struct *mm, unsigned int cpu)
3822 {
3823 u64 asid = atomic64_read(&mm->context.id);
3824 - u64 generation = atomic64_read(&asid_generation);
3825 + u64 generation = atomic64_read_unchecked(&asid_generation);
3826
3827 if (asid != 0 && is_reserved_asid(asid)) {
3828 /*
3829 @@ -198,7 +198,7 @@ static u64 new_context(struct mm_struct *mm, unsigned int cpu)
3830 */
3831 asid = find_next_zero_bit(asid_map, NUM_USER_ASIDS, 1);
3832 if (asid == NUM_USER_ASIDS) {
3833 - generation = atomic64_add_return(ASID_FIRST_VERSION,
3834 + generation = atomic64_add_return_unchecked(ASID_FIRST_VERSION,
3835 &asid_generation);
3836 flush_context(cpu);
3837 asid = find_next_zero_bit(asid_map, NUM_USER_ASIDS, 1);
3838 @@ -227,14 +227,14 @@ void check_and_switch_context(struct mm_struct *mm, struct task_struct *tsk)
3839 cpu_set_reserved_ttbr0();
3840
3841 asid = atomic64_read(&mm->context.id);
3842 - if (!((asid ^ atomic64_read(&asid_generation)) >> ASID_BITS)
3843 + if (!((asid ^ atomic64_read_unchecked(&asid_generation)) >> ASID_BITS)
3844 && atomic64_xchg(&per_cpu(active_asids, cpu), asid))
3845 goto switch_mm_fastpath;
3846
3847 raw_spin_lock_irqsave(&cpu_asid_lock, flags);
3848 /* Check that our ASID belongs to the current generation. */
3849 asid = atomic64_read(&mm->context.id);
3850 - if ((asid ^ atomic64_read(&asid_generation)) >> ASID_BITS) {
3851 + if ((asid ^ atomic64_read_unchecked(&asid_generation)) >> ASID_BITS) {
3852 asid = new_context(mm, cpu);
3853 atomic64_set(&mm->context.id, asid);
3854 }
3855 diff --git a/arch/arm/mm/fault.c b/arch/arm/mm/fault.c
3856 index eb8830a..5360ce7 100644
3857 --- a/arch/arm/mm/fault.c
3858 +++ b/arch/arm/mm/fault.c
3859 @@ -25,6 +25,7 @@
3860 #include <asm/system_misc.h>
3861 #include <asm/system_info.h>
3862 #include <asm/tlbflush.h>
3863 +#include <asm/sections.h>
3864
3865 #include "fault.h"
3866
3867 @@ -138,6 +139,31 @@ __do_kernel_fault(struct mm_struct *mm, unsigned long addr, unsigned int fsr,
3868 if (fixup_exception(regs))
3869 return;
3870
3871 +#ifdef CONFIG_PAX_MEMORY_UDEREF
3872 + if (addr < TASK_SIZE) {
3873 + if (current->signal->curr_ip)
3874 + printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to access userland memory at %08lx\n", &current->signal->curr_ip, current->comm, task_pid_nr(current),
3875 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()), addr);
3876 + else
3877 + printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to access userland memory at %08lx\n", current->comm, task_pid_nr(current),
3878 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()), addr);
3879 + }
3880 +#endif
3881 +
3882 +#ifdef CONFIG_PAX_KERNEXEC
3883 + if ((fsr & FSR_WRITE) &&
3884 + (((unsigned long)_stext <= addr && addr < init_mm.end_code) ||
3885 + (MODULES_VADDR <= addr && addr < MODULES_END)))
3886 + {
3887 + if (current->signal->curr_ip)
3888 + printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n", &current->signal->curr_ip, current->comm, task_pid_nr(current),
3889 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
3890 + else
3891 + printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n", current->comm, task_pid_nr(current),
3892 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
3893 + }
3894 +#endif
3895 +
3896 /*
3897 * No handler, we'll have to terminate things with extreme prejudice.
3898 */
3899 @@ -174,6 +200,13 @@ __do_user_fault(struct task_struct *tsk, unsigned long addr,
3900 }
3901 #endif
3902
3903 +#ifdef CONFIG_PAX_PAGEEXEC
3904 + if (fsr & FSR_LNX_PF) {
3905 + pax_report_fault(regs, (void *)regs->ARM_pc, (void *)regs->ARM_sp);
3906 + do_group_exit(SIGKILL);
3907 + }
3908 +#endif
3909 +
3910 tsk->thread.address = addr;
3911 tsk->thread.error_code = fsr;
3912 tsk->thread.trap_no = 14;
3913 @@ -401,6 +434,33 @@ do_page_fault(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
3914 }
3915 #endif /* CONFIG_MMU */
3916
3917 +#ifdef CONFIG_PAX_PAGEEXEC
3918 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
3919 +{
3920 + long i;
3921 +
3922 + printk(KERN_ERR "PAX: bytes at PC: ");
3923 + for (i = 0; i < 20; i++) {
3924 + unsigned char c;
3925 + if (get_user(c, (__force unsigned char __user *)pc+i))
3926 + printk(KERN_CONT "?? ");
3927 + else
3928 + printk(KERN_CONT "%02x ", c);
3929 + }
3930 + printk("\n");
3931 +
3932 + printk(KERN_ERR "PAX: bytes at SP-4: ");
3933 + for (i = -1; i < 20; i++) {
3934 + unsigned long c;
3935 + if (get_user(c, (__force unsigned long __user *)sp+i))
3936 + printk(KERN_CONT "???????? ");
3937 + else
3938 + printk(KERN_CONT "%08lx ", c);
3939 + }
3940 + printk("\n");
3941 +}
3942 +#endif
3943 +
3944 /*
3945 * First Level Translation Fault Handler
3946 *
3947 @@ -548,9 +608,22 @@ do_DataAbort(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
3948 const struct fsr_info *inf = fsr_info + fsr_fs(fsr);
3949 struct siginfo info;
3950
3951 +#ifdef CONFIG_PAX_MEMORY_UDEREF
3952 + if (addr < TASK_SIZE && is_domain_fault(fsr)) {
3953 + if (current->signal->curr_ip)
3954 + printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to access userland memory at %08lx\n", &current->signal->curr_ip, current->comm, task_pid_nr(current),
3955 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()), addr);
3956 + else
3957 + printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to access userland memory at %08lx\n", current->comm, task_pid_nr(current),
3958 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()), addr);
3959 + goto die;
3960 + }
3961 +#endif
3962 +
3963 if (!inf->fn(addr, fsr & ~FSR_LNX_PF, regs))
3964 return;
3965
3966 +die:
3967 printk(KERN_ALERT "Unhandled fault: %s (0x%03x) at 0x%08lx\n",
3968 inf->name, fsr, addr);
3969
3970 @@ -574,15 +647,98 @@ hook_ifault_code(int nr, int (*fn)(unsigned long, unsigned int, struct pt_regs *
3971 ifsr_info[nr].name = name;
3972 }
3973
3974 +asmlinkage int sys_sigreturn(struct pt_regs *regs);
3975 +asmlinkage int sys_rt_sigreturn(struct pt_regs *regs);
3976 +
3977 asmlinkage void __exception
3978 do_PrefetchAbort(unsigned long addr, unsigned int ifsr, struct pt_regs *regs)
3979 {
3980 const struct fsr_info *inf = ifsr_info + fsr_fs(ifsr);
3981 struct siginfo info;
3982 + unsigned long pc = instruction_pointer(regs);
3983 +
3984 + if (user_mode(regs)) {
3985 + unsigned long sigpage = current->mm->context.sigpage;
3986 +
3987 + if (sigpage <= pc && pc < sigpage + 7*4) {
3988 + if (pc < sigpage + 3*4)
3989 + sys_sigreturn(regs);
3990 + else
3991 + sys_rt_sigreturn(regs);
3992 + return;
3993 + }
3994 + if (pc == 0xffff0f60UL) {
3995 + /*
3996 + * PaX: __kuser_cmpxchg64 emulation
3997 + */
3998 + // TODO
3999 + //regs->ARM_pc = regs->ARM_lr;
4000 + //return;
4001 + }
4002 + if (pc == 0xffff0fa0UL) {
4003 + /*
4004 + * PaX: __kuser_memory_barrier emulation
4005 + */
4006 + // dmb(); implied by the exception
4007 + regs->ARM_pc = regs->ARM_lr;
4008 + return;
4009 + }
4010 + if (pc == 0xffff0fc0UL) {
4011 + /*
4012 + * PaX: __kuser_cmpxchg emulation
4013 + */
4014 + // TODO
4015 + //long new;
4016 + //int op;
4017 +
4018 + //op = FUTEX_OP_SET << 28;
4019 + //new = futex_atomic_op_inuser(op, regs->ARM_r2);
4020 + //regs->ARM_r0 = old != new;
4021 + //regs->ARM_pc = regs->ARM_lr;
4022 + //return;
4023 + }
4024 + if (pc == 0xffff0fe0UL) {
4025 + /*
4026 + * PaX: __kuser_get_tls emulation
4027 + */
4028 + regs->ARM_r0 = current_thread_info()->tp_value[0];
4029 + regs->ARM_pc = regs->ARM_lr;
4030 + return;
4031 + }
4032 + }
4033 +
4034 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
4035 + else if (is_domain_fault(ifsr) || is_xn_fault(ifsr)) {
4036 + if (current->signal->curr_ip)
4037 + printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to execute %s memory at %08lx\n", &current->signal->curr_ip, current->comm, task_pid_nr(current),
4038 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()),
4039 + pc >= TASK_SIZE ? "non-executable kernel" : "userland", pc);
4040 + else
4041 + printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to execute %s memory at %08lx\n", current->comm, task_pid_nr(current),
4042 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()),
4043 + pc >= TASK_SIZE ? "non-executable kernel" : "userland", pc);
4044 + goto die;
4045 + }
4046 +#endif
4047 +
4048 +#ifdef CONFIG_PAX_REFCOUNT
4049 + if (fsr_fs(ifsr) == FAULT_CODE_DEBUG) {
4050 + unsigned int bkpt;
4051 +
4052 + if (!probe_kernel_address(pc, bkpt) && cpu_to_le32(bkpt) == 0xe12f1073) {
4053 + current->thread.error_code = ifsr;
4054 + current->thread.trap_no = 0;
4055 + pax_report_refcount_overflow(regs);
4056 + fixup_exception(regs);
4057 + return;
4058 + }
4059 + }
4060 +#endif
4061
4062 if (!inf->fn(addr, ifsr | FSR_LNX_PF, regs))
4063 return;
4064
4065 +die:
4066 printk(KERN_ALERT "Unhandled prefetch abort: %s (0x%03x) at 0x%08lx\n",
4067 inf->name, ifsr, addr);
4068
4069 diff --git a/arch/arm/mm/fault.h b/arch/arm/mm/fault.h
4070 index cf08bdf..772656c 100644
4071 --- a/arch/arm/mm/fault.h
4072 +++ b/arch/arm/mm/fault.h
4073 @@ -3,6 +3,7 @@
4074
4075 /*
4076 * Fault status register encodings. We steal bit 31 for our own purposes.
4077 + * Set when the FSR value is from an instruction fault.
4078 */
4079 #define FSR_LNX_PF (1 << 31)
4080 #define FSR_WRITE (1 << 11)
4081 @@ -22,6 +23,17 @@ static inline int fsr_fs(unsigned int fsr)
4082 }
4083 #endif
4084
4085 +/* valid for LPAE and !LPAE */
4086 +static inline int is_xn_fault(unsigned int fsr)
4087 +{
4088 + return ((fsr_fs(fsr) & 0x3c) == 0xc);
4089 +}
4090 +
4091 +static inline int is_domain_fault(unsigned int fsr)
4092 +{
4093 + return ((fsr_fs(fsr) & 0xD) == 0x9);
4094 +}
4095 +
4096 void do_bad_area(unsigned long addr, unsigned int fsr, struct pt_regs *regs);
4097 unsigned long search_exception_table(unsigned long addr);
4098
4099 diff --git a/arch/arm/mm/init.c b/arch/arm/mm/init.c
4100 index ac1d883..5a7bb91 100644
4101 --- a/arch/arm/mm/init.c
4102 +++ b/arch/arm/mm/init.c
4103 @@ -30,6 +30,8 @@
4104 #include <asm/setup.h>
4105 #include <asm/tlb.h>
4106 #include <asm/fixmap.h>
4107 +#include <asm/system_info.h>
4108 +#include <asm/cp15.h>
4109
4110 #include <asm/mach/arch.h>
4111 #include <asm/mach/map.h>
4112 @@ -682,7 +684,46 @@ void free_initmem(void)
4113 {
4114 #ifdef CONFIG_HAVE_TCM
4115 extern char __tcm_start, __tcm_end;
4116 +#endif
4117
4118 +#ifdef CONFIG_PAX_KERNEXEC
4119 + unsigned long addr;
4120 + pgd_t *pgd;
4121 + pud_t *pud;
4122 + pmd_t *pmd;
4123 + int cpu_arch = cpu_architecture();
4124 + unsigned int cr = get_cr();
4125 +
4126 + if (cpu_arch >= CPU_ARCH_ARMv6 && (cr & CR_XP)) {
4127 + /* make pages tables, etc before .text NX */
4128 + for (addr = PAGE_OFFSET; addr < (unsigned long)_stext; addr += SECTION_SIZE) {
4129 + pgd = pgd_offset_k(addr);
4130 + pud = pud_offset(pgd, addr);
4131 + pmd = pmd_offset(pud, addr);
4132 + __section_update(pmd, addr, PMD_SECT_XN);
4133 + }
4134 + /* make init NX */
4135 + for (addr = (unsigned long)__init_begin; addr < (unsigned long)_sdata; addr += SECTION_SIZE) {
4136 + pgd = pgd_offset_k(addr);
4137 + pud = pud_offset(pgd, addr);
4138 + pmd = pmd_offset(pud, addr);
4139 + __section_update(pmd, addr, PMD_SECT_XN);
4140 + }
4141 + /* make kernel code/rodata RX */
4142 + for (addr = (unsigned long)_stext; addr < (unsigned long)__init_begin; addr += SECTION_SIZE) {
4143 + pgd = pgd_offset_k(addr);
4144 + pud = pud_offset(pgd, addr);
4145 + pmd = pmd_offset(pud, addr);
4146 +#ifdef CONFIG_ARM_LPAE
4147 + __section_update(pmd, addr, PMD_SECT_RDONLY);
4148 +#else
4149 + __section_update(pmd, addr, PMD_SECT_APX|PMD_SECT_AP_WRITE);
4150 +#endif
4151 + }
4152 + }
4153 +#endif
4154 +
4155 +#ifdef CONFIG_HAVE_TCM
4156 poison_init_mem(&__tcm_start, &__tcm_end - &__tcm_start);
4157 free_reserved_area(&__tcm_start, &__tcm_end, -1, "TCM link");
4158 #endif
4159 diff --git a/arch/arm/mm/ioremap.c b/arch/arm/mm/ioremap.c
4160 index f123d6e..04bf569 100644
4161 --- a/arch/arm/mm/ioremap.c
4162 +++ b/arch/arm/mm/ioremap.c
4163 @@ -392,9 +392,9 @@ __arm_ioremap_exec(phys_addr_t phys_addr, size_t size, bool cached)
4164 unsigned int mtype;
4165
4166 if (cached)
4167 - mtype = MT_MEMORY;
4168 + mtype = MT_MEMORY_RX;
4169 else
4170 - mtype = MT_MEMORY_NONCACHED;
4171 + mtype = MT_MEMORY_NONCACHED_RX;
4172
4173 return __arm_ioremap_caller(phys_addr, size, mtype,
4174 __builtin_return_address(0));
4175 diff --git a/arch/arm/mm/mmap.c b/arch/arm/mm/mmap.c
4176 index 5e85ed3..b10a7ed 100644
4177 --- a/arch/arm/mm/mmap.c
4178 +++ b/arch/arm/mm/mmap.c
4179 @@ -59,6 +59,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
4180 struct vm_area_struct *vma;
4181 int do_align = 0;
4182 int aliasing = cache_is_vipt_aliasing();
4183 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
4184 struct vm_unmapped_area_info info;
4185
4186 /*
4187 @@ -81,6 +82,10 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
4188 if (len > TASK_SIZE)
4189 return -ENOMEM;
4190
4191 +#ifdef CONFIG_PAX_RANDMMAP
4192 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
4193 +#endif
4194 +
4195 if (addr) {
4196 if (do_align)
4197 addr = COLOUR_ALIGN(addr, pgoff);
4198 @@ -88,8 +93,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
4199 addr = PAGE_ALIGN(addr);
4200
4201 vma = find_vma(mm, addr);
4202 - if (TASK_SIZE - len >= addr &&
4203 - (!vma || addr + len <= vma->vm_start))
4204 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
4205 return addr;
4206 }
4207
4208 @@ -99,6 +103,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
4209 info.high_limit = TASK_SIZE;
4210 info.align_mask = do_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
4211 info.align_offset = pgoff << PAGE_SHIFT;
4212 + info.threadstack_offset = offset;
4213 return vm_unmapped_area(&info);
4214 }
4215
4216 @@ -112,6 +117,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4217 unsigned long addr = addr0;
4218 int do_align = 0;
4219 int aliasing = cache_is_vipt_aliasing();
4220 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
4221 struct vm_unmapped_area_info info;
4222
4223 /*
4224 @@ -132,6 +138,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4225 return addr;
4226 }
4227
4228 +#ifdef CONFIG_PAX_RANDMMAP
4229 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
4230 +#endif
4231 +
4232 /* requesting a specific address */
4233 if (addr) {
4234 if (do_align)
4235 @@ -139,8 +149,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4236 else
4237 addr = PAGE_ALIGN(addr);
4238 vma = find_vma(mm, addr);
4239 - if (TASK_SIZE - len >= addr &&
4240 - (!vma || addr + len <= vma->vm_start))
4241 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
4242 return addr;
4243 }
4244
4245 @@ -150,6 +159,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4246 info.high_limit = mm->mmap_base;
4247 info.align_mask = do_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
4248 info.align_offset = pgoff << PAGE_SHIFT;
4249 + info.threadstack_offset = offset;
4250 addr = vm_unmapped_area(&info);
4251
4252 /*
4253 @@ -173,6 +183,10 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
4254 {
4255 unsigned long random_factor = 0UL;
4256
4257 +#ifdef CONFIG_PAX_RANDMMAP
4258 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
4259 +#endif
4260 +
4261 /* 8 bits of randomness in 20 address space bits */
4262 if ((current->flags & PF_RANDOMIZE) &&
4263 !(current->personality & ADDR_NO_RANDOMIZE))
4264 @@ -180,9 +194,21 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
4265
4266 if (mmap_is_legacy()) {
4267 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
4268 +
4269 +#ifdef CONFIG_PAX_RANDMMAP
4270 + if (mm->pax_flags & MF_PAX_RANDMMAP)
4271 + mm->mmap_base += mm->delta_mmap;
4272 +#endif
4273 +
4274 mm->get_unmapped_area = arch_get_unmapped_area;
4275 } else {
4276 mm->mmap_base = mmap_base(random_factor);
4277 +
4278 +#ifdef CONFIG_PAX_RANDMMAP
4279 + if (mm->pax_flags & MF_PAX_RANDMMAP)
4280 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
4281 +#endif
4282 +
4283 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
4284 }
4285 }
4286 diff --git a/arch/arm/mm/mmu.c b/arch/arm/mm/mmu.c
4287 index 911d433..8580952 100644
4288 --- a/arch/arm/mm/mmu.c
4289 +++ b/arch/arm/mm/mmu.c
4290 @@ -38,6 +38,22 @@
4291 #include "mm.h"
4292 #include "tcm.h"
4293
4294 +#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
4295 +void modify_domain(unsigned int dom, unsigned int type)
4296 +{
4297 + struct thread_info *thread = current_thread_info();
4298 + unsigned int domain = thread->cpu_domain;
4299 + /*
4300 + * DOMAIN_MANAGER might be defined to some other value,
4301 + * use the arch-defined constant
4302 + */
4303 + domain &= ~domain_val(dom, 3);
4304 + thread->cpu_domain = domain | domain_val(dom, type);
4305 + set_domain(thread->cpu_domain);
4306 +}
4307 +EXPORT_SYMBOL(modify_domain);
4308 +#endif
4309 +
4310 /*
4311 * empty_zero_page is a special page that is used for
4312 * zero-initialized data and COW.
4313 @@ -230,11 +246,19 @@ __setup("noalign", noalign_setup);
4314
4315 #endif /* ifdef CONFIG_CPU_CP15 / else */
4316
4317 -#define PROT_PTE_DEVICE L_PTE_PRESENT|L_PTE_YOUNG|L_PTE_DIRTY|L_PTE_XN
4318 +#define PROT_PTE_DEVICE L_PTE_PRESENT|L_PTE_YOUNG|L_PTE_DIRTY
4319 #define PROT_PTE_S2_DEVICE PROT_PTE_DEVICE
4320 #define PROT_SECT_DEVICE PMD_TYPE_SECT|PMD_SECT_AP_WRITE
4321
4322 -static struct mem_type mem_types[] = {
4323 +#ifdef CONFIG_PAX_KERNEXEC
4324 +#define L_PTE_KERNEXEC L_PTE_RDONLY
4325 +#define PMD_SECT_KERNEXEC PMD_SECT_RDONLY
4326 +#else
4327 +#define L_PTE_KERNEXEC L_PTE_DIRTY
4328 +#define PMD_SECT_KERNEXEC PMD_SECT_AP_WRITE
4329 +#endif
4330 +
4331 +static struct mem_type mem_types[] __read_only = {
4332 [MT_DEVICE] = { /* Strongly ordered / ARMv6 shared device */
4333 .prot_pte = PROT_PTE_DEVICE | L_PTE_MT_DEV_SHARED |
4334 L_PTE_SHARED,
4335 @@ -266,16 +290,16 @@ static struct mem_type mem_types[] = {
4336 [MT_UNCACHED] = {
4337 .prot_pte = PROT_PTE_DEVICE,
4338 .prot_l1 = PMD_TYPE_TABLE,
4339 - .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
4340 + .prot_sect = PROT_SECT_DEVICE,
4341 .domain = DOMAIN_IO,
4342 },
4343 [MT_CACHECLEAN] = {
4344 - .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
4345 + .prot_sect = PMD_TYPE_SECT | PMD_SECT_RDONLY,
4346 .domain = DOMAIN_KERNEL,
4347 },
4348 #ifndef CONFIG_ARM_LPAE
4349 [MT_MINICLEAN] = {
4350 - .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN | PMD_SECT_MINICACHE,
4351 + .prot_sect = PMD_TYPE_SECT | PMD_SECT_MINICACHE | PMD_SECT_RDONLY,
4352 .domain = DOMAIN_KERNEL,
4353 },
4354 #endif
4355 @@ -283,36 +307,54 @@ static struct mem_type mem_types[] = {
4356 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4357 L_PTE_RDONLY,
4358 .prot_l1 = PMD_TYPE_TABLE,
4359 - .domain = DOMAIN_USER,
4360 + .domain = DOMAIN_VECTORS,
4361 },
4362 [MT_HIGH_VECTORS] = {
4363 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4364 L_PTE_USER | L_PTE_RDONLY,
4365 .prot_l1 = PMD_TYPE_TABLE,
4366 - .domain = DOMAIN_USER,
4367 + .domain = DOMAIN_VECTORS,
4368 },
4369 - [MT_MEMORY] = {
4370 + [MT_MEMORY_RWX] = {
4371 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY,
4372 .prot_l1 = PMD_TYPE_TABLE,
4373 .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE,
4374 .domain = DOMAIN_KERNEL,
4375 },
4376 + [MT_MEMORY_RW] = {
4377 + .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY,
4378 + .prot_l1 = PMD_TYPE_TABLE,
4379 + .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE,
4380 + .domain = DOMAIN_KERNEL,
4381 + },
4382 + [MT_MEMORY_RX] = {
4383 + .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_KERNEXEC,
4384 + .prot_l1 = PMD_TYPE_TABLE,
4385 + .prot_sect = PMD_TYPE_SECT | PMD_SECT_KERNEXEC,
4386 + .domain = DOMAIN_KERNEL,
4387 + },
4388 [MT_ROM] = {
4389 - .prot_sect = PMD_TYPE_SECT,
4390 + .prot_sect = PMD_TYPE_SECT | PMD_SECT_RDONLY,
4391 .domain = DOMAIN_KERNEL,
4392 },
4393 - [MT_MEMORY_NONCACHED] = {
4394 + [MT_MEMORY_NONCACHED_RW] = {
4395 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4396 L_PTE_MT_BUFFERABLE,
4397 .prot_l1 = PMD_TYPE_TABLE,
4398 .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE,
4399 .domain = DOMAIN_KERNEL,
4400 },
4401 + [MT_MEMORY_NONCACHED_RX] = {
4402 + .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_KERNEXEC |
4403 + L_PTE_MT_BUFFERABLE,
4404 + .prot_l1 = PMD_TYPE_TABLE,
4405 + .prot_sect = PMD_TYPE_SECT | PMD_SECT_KERNEXEC,
4406 + .domain = DOMAIN_KERNEL,
4407 + },
4408 [MT_MEMORY_DTCM] = {
4409 - .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4410 - L_PTE_XN,
4411 + .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY,
4412 .prot_l1 = PMD_TYPE_TABLE,
4413 - .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
4414 + .prot_sect = PMD_TYPE_SECT | PMD_SECT_RDONLY,
4415 .domain = DOMAIN_KERNEL,
4416 },
4417 [MT_MEMORY_ITCM] = {
4418 @@ -322,10 +364,10 @@ static struct mem_type mem_types[] = {
4419 },
4420 [MT_MEMORY_SO] = {
4421 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4422 - L_PTE_MT_UNCACHED | L_PTE_XN,
4423 + L_PTE_MT_UNCACHED,
4424 .prot_l1 = PMD_TYPE_TABLE,
4425 .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE | PMD_SECT_S |
4426 - PMD_SECT_UNCACHED | PMD_SECT_XN,
4427 + PMD_SECT_UNCACHED,
4428 .domain = DOMAIN_KERNEL,
4429 },
4430 [MT_MEMORY_DMA_READY] = {
4431 @@ -411,9 +453,35 @@ static void __init build_mem_type_table(void)
4432 * to prevent speculative instruction fetches.
4433 */
4434 mem_types[MT_DEVICE].prot_sect |= PMD_SECT_XN;
4435 + mem_types[MT_DEVICE].prot_pte |= L_PTE_XN;
4436 mem_types[MT_DEVICE_NONSHARED].prot_sect |= PMD_SECT_XN;
4437 + mem_types[MT_DEVICE_NONSHARED].prot_pte |= L_PTE_XN;
4438 mem_types[MT_DEVICE_CACHED].prot_sect |= PMD_SECT_XN;
4439 + mem_types[MT_DEVICE_CACHED].prot_pte |= L_PTE_XN;
4440 mem_types[MT_DEVICE_WC].prot_sect |= PMD_SECT_XN;
4441 + mem_types[MT_DEVICE_WC].prot_pte |= L_PTE_XN;
4442 +
4443 + /* Mark other regions on ARMv6+ as execute-never */
4444 +
4445 +#ifdef CONFIG_PAX_KERNEXEC
4446 + mem_types[MT_UNCACHED].prot_sect |= PMD_SECT_XN;
4447 + mem_types[MT_UNCACHED].prot_pte |= L_PTE_XN;
4448 + mem_types[MT_CACHECLEAN].prot_sect |= PMD_SECT_XN;
4449 + mem_types[MT_CACHECLEAN].prot_pte |= L_PTE_XN;
4450 +#ifndef CONFIG_ARM_LPAE
4451 + mem_types[MT_MINICLEAN].prot_sect |= PMD_SECT_XN;
4452 + mem_types[MT_MINICLEAN].prot_pte |= L_PTE_XN;
4453 +#endif
4454 + mem_types[MT_MEMORY_RW].prot_sect |= PMD_SECT_XN;
4455 + mem_types[MT_MEMORY_RW].prot_pte |= L_PTE_XN;
4456 + mem_types[MT_MEMORY_NONCACHED_RW].prot_sect |= PMD_SECT_XN;
4457 + mem_types[MT_MEMORY_NONCACHED_RW].prot_pte |= PMD_SECT_XN;
4458 + mem_types[MT_MEMORY_DTCM].prot_sect |= PMD_SECT_XN;
4459 + mem_types[MT_MEMORY_DTCM].prot_pte |= L_PTE_XN;
4460 +#endif
4461 +
4462 + mem_types[MT_MEMORY_SO].prot_sect |= PMD_SECT_XN;
4463 + mem_types[MT_MEMORY_SO].prot_pte |= L_PTE_XN;
4464 }
4465 if (cpu_arch >= CPU_ARCH_ARMv7 && (cr & CR_TRE)) {
4466 /*
4467 @@ -475,6 +543,9 @@ static void __init build_mem_type_table(void)
4468 * from SVC mode and no access from userspace.
4469 */
4470 mem_types[MT_ROM].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4471 +#ifdef CONFIG_PAX_KERNEXEC
4472 + mem_types[MT_MEMORY_RX].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4473 +#endif
4474 mem_types[MT_MINICLEAN].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4475 mem_types[MT_CACHECLEAN].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4476 #endif
4477 @@ -492,11 +563,17 @@ static void __init build_mem_type_table(void)
4478 mem_types[MT_DEVICE_WC].prot_pte |= L_PTE_SHARED;
4479 mem_types[MT_DEVICE_CACHED].prot_sect |= PMD_SECT_S;
4480 mem_types[MT_DEVICE_CACHED].prot_pte |= L_PTE_SHARED;
4481 - mem_types[MT_MEMORY].prot_sect |= PMD_SECT_S;
4482 - mem_types[MT_MEMORY].prot_pte |= L_PTE_SHARED;
4483 + mem_types[MT_MEMORY_RWX].prot_sect |= PMD_SECT_S;
4484 + mem_types[MT_MEMORY_RWX].prot_pte |= L_PTE_SHARED;
4485 + mem_types[MT_MEMORY_RW].prot_sect |= PMD_SECT_S;
4486 + mem_types[MT_MEMORY_RW].prot_pte |= L_PTE_SHARED;
4487 + mem_types[MT_MEMORY_RX].prot_sect |= PMD_SECT_S;
4488 + mem_types[MT_MEMORY_RX].prot_pte |= L_PTE_SHARED;
4489 mem_types[MT_MEMORY_DMA_READY].prot_pte |= L_PTE_SHARED;
4490 - mem_types[MT_MEMORY_NONCACHED].prot_sect |= PMD_SECT_S;
4491 - mem_types[MT_MEMORY_NONCACHED].prot_pte |= L_PTE_SHARED;
4492 + mem_types[MT_MEMORY_NONCACHED_RW].prot_sect |= PMD_SECT_S;
4493 + mem_types[MT_MEMORY_NONCACHED_RW].prot_pte |= L_PTE_SHARED;
4494 + mem_types[MT_MEMORY_NONCACHED_RX].prot_sect |= PMD_SECT_S;
4495 + mem_types[MT_MEMORY_NONCACHED_RX].prot_pte |= L_PTE_SHARED;
4496 }
4497 }
4498
4499 @@ -507,15 +584,20 @@ static void __init build_mem_type_table(void)
4500 if (cpu_arch >= CPU_ARCH_ARMv6) {
4501 if (cpu_arch >= CPU_ARCH_ARMv7 && (cr & CR_TRE)) {
4502 /* Non-cacheable Normal is XCB = 001 */
4503 - mem_types[MT_MEMORY_NONCACHED].prot_sect |=
4504 + mem_types[MT_MEMORY_NONCACHED_RW].prot_sect |=
4505 + PMD_SECT_BUFFERED;
4506 + mem_types[MT_MEMORY_NONCACHED_RX].prot_sect |=
4507 PMD_SECT_BUFFERED;
4508 } else {
4509 /* For both ARMv6 and non-TEX-remapping ARMv7 */
4510 - mem_types[MT_MEMORY_NONCACHED].prot_sect |=
4511 + mem_types[MT_MEMORY_NONCACHED_RW].prot_sect |=
4512 + PMD_SECT_TEX(1);
4513 + mem_types[MT_MEMORY_NONCACHED_RX].prot_sect |=
4514 PMD_SECT_TEX(1);
4515 }
4516 } else {
4517 - mem_types[MT_MEMORY_NONCACHED].prot_sect |= PMD_SECT_BUFFERABLE;
4518 + mem_types[MT_MEMORY_NONCACHED_RW].prot_sect |= PMD_SECT_BUFFERABLE;
4519 + mem_types[MT_MEMORY_NONCACHED_RX].prot_sect |= PMD_SECT_BUFFERABLE;
4520 }
4521
4522 #ifdef CONFIG_ARM_LPAE
4523 @@ -531,6 +613,8 @@ static void __init build_mem_type_table(void)
4524 vecs_pgprot |= PTE_EXT_AF;
4525 #endif
4526
4527 + user_pgprot |= __supported_pte_mask;
4528 +
4529 for (i = 0; i < 16; i++) {
4530 pteval_t v = pgprot_val(protection_map[i]);
4531 protection_map[i] = __pgprot(v | user_pgprot);
4532 @@ -548,10 +632,15 @@ static void __init build_mem_type_table(void)
4533
4534 mem_types[MT_LOW_VECTORS].prot_l1 |= ecc_mask;
4535 mem_types[MT_HIGH_VECTORS].prot_l1 |= ecc_mask;
4536 - mem_types[MT_MEMORY].prot_sect |= ecc_mask | cp->pmd;
4537 - mem_types[MT_MEMORY].prot_pte |= kern_pgprot;
4538 + mem_types[MT_MEMORY_RWX].prot_sect |= ecc_mask | cp->pmd;
4539 + mem_types[MT_MEMORY_RWX].prot_pte |= kern_pgprot;
4540 + mem_types[MT_MEMORY_RW].prot_sect |= ecc_mask | cp->pmd;
4541 + mem_types[MT_MEMORY_RW].prot_pte |= kern_pgprot;
4542 + mem_types[MT_MEMORY_RX].prot_sect |= ecc_mask | cp->pmd;
4543 + mem_types[MT_MEMORY_RX].prot_pte |= kern_pgprot;
4544 mem_types[MT_MEMORY_DMA_READY].prot_pte |= kern_pgprot;
4545 - mem_types[MT_MEMORY_NONCACHED].prot_sect |= ecc_mask;
4546 + mem_types[MT_MEMORY_NONCACHED_RW].prot_sect |= ecc_mask;
4547 + mem_types[MT_MEMORY_NONCACHED_RX].prot_sect |= ecc_mask;
4548 mem_types[MT_ROM].prot_sect |= cp->pmd;
4549
4550 switch (cp->pmd) {
4551 @@ -1193,18 +1282,15 @@ void __init arm_mm_memblock_reserve(void)
4552 * called function. This means you can't use any function or debugging
4553 * method which may touch any device, otherwise the kernel _will_ crash.
4554 */
4555 +
4556 +static char vectors[PAGE_SIZE * 2] __read_only __aligned(PAGE_SIZE);
4557 +
4558 static void __init devicemaps_init(const struct machine_desc *mdesc)
4559 {
4560 struct map_desc map;
4561 unsigned long addr;
4562 - void *vectors;
4563
4564 - /*
4565 - * Allocate the vector page early.
4566 - */
4567 - vectors = early_alloc(PAGE_SIZE * 2);
4568 -
4569 - early_trap_init(vectors);
4570 + early_trap_init(&vectors);
4571
4572 for (addr = VMALLOC_START; addr; addr += PMD_SIZE)
4573 pmd_clear(pmd_off_k(addr));
4574 @@ -1244,7 +1330,7 @@ static void __init devicemaps_init(const struct machine_desc *mdesc)
4575 * location (0xffff0000). If we aren't using high-vectors, also
4576 * create a mapping at the low-vectors virtual address.
4577 */
4578 - map.pfn = __phys_to_pfn(virt_to_phys(vectors));
4579 + map.pfn = __phys_to_pfn(virt_to_phys(&vectors));
4580 map.virtual = 0xffff0000;
4581 map.length = PAGE_SIZE;
4582 #ifdef CONFIG_KUSER_HELPERS
4583 @@ -1316,8 +1402,39 @@ static void __init map_lowmem(void)
4584 map.pfn = __phys_to_pfn(start);
4585 map.virtual = __phys_to_virt(start);
4586 map.length = end - start;
4587 - map.type = MT_MEMORY;
4588
4589 +#ifdef CONFIG_PAX_KERNEXEC
4590 + if (map.virtual <= (unsigned long)_stext && ((unsigned long)_end < (map.virtual + map.length))) {
4591 + struct map_desc kernel;
4592 + struct map_desc initmap;
4593 +
4594 + /* when freeing initmem we will make this RW */
4595 + initmap.pfn = __phys_to_pfn(__pa(__init_begin));
4596 + initmap.virtual = (unsigned long)__init_begin;
4597 + initmap.length = _sdata - __init_begin;
4598 + initmap.type = MT_MEMORY_RWX;
4599 + create_mapping(&initmap);
4600 +
4601 + /* when freeing initmem we will make this RX */
4602 + kernel.pfn = __phys_to_pfn(__pa(_stext));
4603 + kernel.virtual = (unsigned long)_stext;
4604 + kernel.length = __init_begin - _stext;
4605 + kernel.type = MT_MEMORY_RWX;
4606 + create_mapping(&kernel);
4607 +
4608 + if (map.virtual < (unsigned long)_stext) {
4609 + map.length = (unsigned long)_stext - map.virtual;
4610 + map.type = MT_MEMORY_RWX;
4611 + create_mapping(&map);
4612 + }
4613 +
4614 + map.pfn = __phys_to_pfn(__pa(_sdata));
4615 + map.virtual = (unsigned long)_sdata;
4616 + map.length = end - __pa(_sdata);
4617 + }
4618 +#endif
4619 +
4620 + map.type = MT_MEMORY_RW;
4621 create_mapping(&map);
4622 }
4623 }
4624 diff --git a/arch/arm/plat-omap/sram.c b/arch/arm/plat-omap/sram.c
4625 index a5bc92d..0bb4730 100644
4626 --- a/arch/arm/plat-omap/sram.c
4627 +++ b/arch/arm/plat-omap/sram.c
4628 @@ -93,6 +93,8 @@ void __init omap_map_sram(unsigned long start, unsigned long size,
4629 * Looks like we need to preserve some bootloader code at the
4630 * beginning of SRAM for jumping to flash for reboot to work...
4631 */
4632 + pax_open_kernel();
4633 memset_io(omap_sram_base + omap_sram_skip, 0,
4634 omap_sram_size - omap_sram_skip);
4635 + pax_close_kernel();
4636 }
4637 diff --git a/arch/arm/plat-samsung/include/plat/dma-ops.h b/arch/arm/plat-samsung/include/plat/dma-ops.h
4638 index ce6d763..cfea917 100644
4639 --- a/arch/arm/plat-samsung/include/plat/dma-ops.h
4640 +++ b/arch/arm/plat-samsung/include/plat/dma-ops.h
4641 @@ -47,7 +47,7 @@ struct samsung_dma_ops {
4642 int (*started)(unsigned ch);
4643 int (*flush)(unsigned ch);
4644 int (*stop)(unsigned ch);
4645 -};
4646 +} __no_const;
4647
4648 extern void *samsung_dmadev_get_ops(void);
4649 extern void *s3c_dma_get_ops(void);
4650 diff --git a/arch/arm64/include/asm/uaccess.h b/arch/arm64/include/asm/uaccess.h
4651 index 7ecc2b2..5e56c66 100644
4652 --- a/arch/arm64/include/asm/uaccess.h
4653 +++ b/arch/arm64/include/asm/uaccess.h
4654 @@ -99,6 +99,7 @@ static inline void set_fs(mm_segment_t fs)
4655 flag; \
4656 })
4657
4658 +#define access_ok_noprefault(type, addr, size) access_ok((type), (addr), (size))
4659 #define access_ok(type, addr, size) __range_ok(addr, size)
4660
4661 /*
4662 diff --git a/arch/avr32/include/asm/cache.h b/arch/avr32/include/asm/cache.h
4663 index c3a58a1..78fbf54 100644
4664 --- a/arch/avr32/include/asm/cache.h
4665 +++ b/arch/avr32/include/asm/cache.h
4666 @@ -1,8 +1,10 @@
4667 #ifndef __ASM_AVR32_CACHE_H
4668 #define __ASM_AVR32_CACHE_H
4669
4670 +#include <linux/const.h>
4671 +
4672 #define L1_CACHE_SHIFT 5
4673 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4674 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4675
4676 /*
4677 * Memory returned by kmalloc() may be used for DMA, so we must make
4678 diff --git a/arch/avr32/include/asm/elf.h b/arch/avr32/include/asm/elf.h
4679 index d232888..87c8df1 100644
4680 --- a/arch/avr32/include/asm/elf.h
4681 +++ b/arch/avr32/include/asm/elf.h
4682 @@ -84,8 +84,14 @@ typedef struct user_fpu_struct elf_fpregset_t;
4683 the loader. We need to make sure that it is out of the way of the program
4684 that it will "exec", and that there is sufficient room for the brk. */
4685
4686 -#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
4687 +#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
4688
4689 +#ifdef CONFIG_PAX_ASLR
4690 +#define PAX_ELF_ET_DYN_BASE 0x00001000UL
4691 +
4692 +#define PAX_DELTA_MMAP_LEN 15
4693 +#define PAX_DELTA_STACK_LEN 15
4694 +#endif
4695
4696 /* This yields a mask that user programs can use to figure out what
4697 instruction set this CPU supports. This could be done in user space,
4698 diff --git a/arch/avr32/include/asm/kmap_types.h b/arch/avr32/include/asm/kmap_types.h
4699 index 479330b..53717a8 100644
4700 --- a/arch/avr32/include/asm/kmap_types.h
4701 +++ b/arch/avr32/include/asm/kmap_types.h
4702 @@ -2,9 +2,9 @@
4703 #define __ASM_AVR32_KMAP_TYPES_H
4704
4705 #ifdef CONFIG_DEBUG_HIGHMEM
4706 -# define KM_TYPE_NR 29
4707 +# define KM_TYPE_NR 30
4708 #else
4709 -# define KM_TYPE_NR 14
4710 +# define KM_TYPE_NR 15
4711 #endif
4712
4713 #endif /* __ASM_AVR32_KMAP_TYPES_H */
4714 diff --git a/arch/avr32/mm/fault.c b/arch/avr32/mm/fault.c
4715 index 0eca933..eb78c7b 100644
4716 --- a/arch/avr32/mm/fault.c
4717 +++ b/arch/avr32/mm/fault.c
4718 @@ -41,6 +41,23 @@ static inline int notify_page_fault(struct pt_regs *regs, int trap)
4719
4720 int exception_trace = 1;
4721
4722 +#ifdef CONFIG_PAX_PAGEEXEC
4723 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
4724 +{
4725 + unsigned long i;
4726 +
4727 + printk(KERN_ERR "PAX: bytes at PC: ");
4728 + for (i = 0; i < 20; i++) {
4729 + unsigned char c;
4730 + if (get_user(c, (unsigned char *)pc+i))
4731 + printk(KERN_CONT "???????? ");
4732 + else
4733 + printk(KERN_CONT "%02x ", c);
4734 + }
4735 + printk("\n");
4736 +}
4737 +#endif
4738 +
4739 /*
4740 * This routine handles page faults. It determines the address and the
4741 * problem, and then passes it off to one of the appropriate routines.
4742 @@ -176,6 +193,16 @@ bad_area:
4743 up_read(&mm->mmap_sem);
4744
4745 if (user_mode(regs)) {
4746 +
4747 +#ifdef CONFIG_PAX_PAGEEXEC
4748 + if (mm->pax_flags & MF_PAX_PAGEEXEC) {
4749 + if (ecr == ECR_PROTECTION_X || ecr == ECR_TLB_MISS_X) {
4750 + pax_report_fault(regs, (void *)regs->pc, (void *)regs->sp);
4751 + do_group_exit(SIGKILL);
4752 + }
4753 + }
4754 +#endif
4755 +
4756 if (exception_trace && printk_ratelimit())
4757 printk("%s%s[%d]: segfault at %08lx pc %08lx "
4758 "sp %08lx ecr %lu\n",
4759 diff --git a/arch/blackfin/include/asm/cache.h b/arch/blackfin/include/asm/cache.h
4760 index 568885a..f8008df 100644
4761 --- a/arch/blackfin/include/asm/cache.h
4762 +++ b/arch/blackfin/include/asm/cache.h
4763 @@ -7,6 +7,7 @@
4764 #ifndef __ARCH_BLACKFIN_CACHE_H
4765 #define __ARCH_BLACKFIN_CACHE_H
4766
4767 +#include <linux/const.h>
4768 #include <linux/linkage.h> /* for asmlinkage */
4769
4770 /*
4771 @@ -14,7 +15,7 @@
4772 * Blackfin loads 32 bytes for cache
4773 */
4774 #define L1_CACHE_SHIFT 5
4775 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4776 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4777 #define SMP_CACHE_BYTES L1_CACHE_BYTES
4778
4779 #define ARCH_DMA_MINALIGN L1_CACHE_BYTES
4780 diff --git a/arch/cris/include/arch-v10/arch/cache.h b/arch/cris/include/arch-v10/arch/cache.h
4781 index aea2718..3639a60 100644
4782 --- a/arch/cris/include/arch-v10/arch/cache.h
4783 +++ b/arch/cris/include/arch-v10/arch/cache.h
4784 @@ -1,8 +1,9 @@
4785 #ifndef _ASM_ARCH_CACHE_H
4786 #define _ASM_ARCH_CACHE_H
4787
4788 +#include <linux/const.h>
4789 /* Etrax 100LX have 32-byte cache-lines. */
4790 -#define L1_CACHE_BYTES 32
4791 #define L1_CACHE_SHIFT 5
4792 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4793
4794 #endif /* _ASM_ARCH_CACHE_H */
4795 diff --git a/arch/cris/include/arch-v32/arch/cache.h b/arch/cris/include/arch-v32/arch/cache.h
4796 index 7caf25d..ee65ac5 100644
4797 --- a/arch/cris/include/arch-v32/arch/cache.h
4798 +++ b/arch/cris/include/arch-v32/arch/cache.h
4799 @@ -1,11 +1,12 @@
4800 #ifndef _ASM_CRIS_ARCH_CACHE_H
4801 #define _ASM_CRIS_ARCH_CACHE_H
4802
4803 +#include <linux/const.h>
4804 #include <arch/hwregs/dma.h>
4805
4806 /* A cache-line is 32 bytes. */
4807 -#define L1_CACHE_BYTES 32
4808 #define L1_CACHE_SHIFT 5
4809 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4810
4811 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
4812
4813 diff --git a/arch/frv/include/asm/atomic.h b/arch/frv/include/asm/atomic.h
4814 index b86329d..6709906 100644
4815 --- a/arch/frv/include/asm/atomic.h
4816 +++ b/arch/frv/include/asm/atomic.h
4817 @@ -186,6 +186,16 @@ static inline void atomic64_dec(atomic64_t *v)
4818 #define atomic64_cmpxchg(v, old, new) (__cmpxchg_64(old, new, &(v)->counter))
4819 #define atomic64_xchg(v, new) (__xchg_64(new, &(v)->counter))
4820
4821 +#define atomic64_read_unchecked(v) atomic64_read(v)
4822 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
4823 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
4824 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
4825 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
4826 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
4827 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
4828 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
4829 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
4830 +
4831 static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
4832 {
4833 int c, old;
4834 diff --git a/arch/frv/include/asm/cache.h b/arch/frv/include/asm/cache.h
4835 index 2797163..c2a401d 100644
4836 --- a/arch/frv/include/asm/cache.h
4837 +++ b/arch/frv/include/asm/cache.h
4838 @@ -12,10 +12,11 @@
4839 #ifndef __ASM_CACHE_H
4840 #define __ASM_CACHE_H
4841
4842 +#include <linux/const.h>
4843
4844 /* bytes per L1 cache line */
4845 #define L1_CACHE_SHIFT (CONFIG_FRV_L1_CACHE_SHIFT)
4846 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4847 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4848
4849 #define __cacheline_aligned __attribute__((aligned(L1_CACHE_BYTES)))
4850 #define ____cacheline_aligned __attribute__((aligned(L1_CACHE_BYTES)))
4851 diff --git a/arch/frv/include/asm/kmap_types.h b/arch/frv/include/asm/kmap_types.h
4852 index 43901f2..0d8b865 100644
4853 --- a/arch/frv/include/asm/kmap_types.h
4854 +++ b/arch/frv/include/asm/kmap_types.h
4855 @@ -2,6 +2,6 @@
4856 #ifndef _ASM_KMAP_TYPES_H
4857 #define _ASM_KMAP_TYPES_H
4858
4859 -#define KM_TYPE_NR 17
4860 +#define KM_TYPE_NR 18
4861
4862 #endif
4863 diff --git a/arch/frv/mm/elf-fdpic.c b/arch/frv/mm/elf-fdpic.c
4864 index 836f147..4cf23f5 100644
4865 --- a/arch/frv/mm/elf-fdpic.c
4866 +++ b/arch/frv/mm/elf-fdpic.c
4867 @@ -61,6 +61,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
4868 {
4869 struct vm_area_struct *vma;
4870 struct vm_unmapped_area_info info;
4871 + unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
4872
4873 if (len > TASK_SIZE)
4874 return -ENOMEM;
4875 @@ -73,8 +74,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
4876 if (addr) {
4877 addr = PAGE_ALIGN(addr);
4878 vma = find_vma(current->mm, addr);
4879 - if (TASK_SIZE - len >= addr &&
4880 - (!vma || addr + len <= vma->vm_start))
4881 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
4882 goto success;
4883 }
4884
4885 @@ -85,6 +85,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
4886 info.high_limit = (current->mm->start_stack - 0x00200000);
4887 info.align_mask = 0;
4888 info.align_offset = 0;
4889 + info.threadstack_offset = offset;
4890 addr = vm_unmapped_area(&info);
4891 if (!(addr & ~PAGE_MASK))
4892 goto success;
4893 diff --git a/arch/hexagon/include/asm/cache.h b/arch/hexagon/include/asm/cache.h
4894 index f4ca594..adc72fd6 100644
4895 --- a/arch/hexagon/include/asm/cache.h
4896 +++ b/arch/hexagon/include/asm/cache.h
4897 @@ -21,9 +21,11 @@
4898 #ifndef __ASM_CACHE_H
4899 #define __ASM_CACHE_H
4900
4901 +#include <linux/const.h>
4902 +
4903 /* Bytes per L1 cache line */
4904 -#define L1_CACHE_SHIFT (5)
4905 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4906 +#define L1_CACHE_SHIFT 5
4907 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4908
4909 #define __cacheline_aligned __aligned(L1_CACHE_BYTES)
4910 #define ____cacheline_aligned __aligned(L1_CACHE_BYTES)
4911 diff --git a/arch/ia64/Kconfig b/arch/ia64/Kconfig
4912 index 4e4119b..dd7de0a 100644
4913 --- a/arch/ia64/Kconfig
4914 +++ b/arch/ia64/Kconfig
4915 @@ -554,6 +554,7 @@ source "drivers/sn/Kconfig"
4916 config KEXEC
4917 bool "kexec system call"
4918 depends on !IA64_HP_SIM && (!SMP || HOTPLUG_CPU)
4919 + depends on !GRKERNSEC_KMEM
4920 help
4921 kexec is a system call that implements the ability to shutdown your
4922 current kernel, and to start another kernel. It is like a reboot
4923 diff --git a/arch/ia64/include/asm/atomic.h b/arch/ia64/include/asm/atomic.h
4924 index 6e6fe18..a6ae668 100644
4925 --- a/arch/ia64/include/asm/atomic.h
4926 +++ b/arch/ia64/include/asm/atomic.h
4927 @@ -208,6 +208,16 @@ atomic64_add_negative (__s64 i, atomic64_t *v)
4928 #define atomic64_inc(v) atomic64_add(1, (v))
4929 #define atomic64_dec(v) atomic64_sub(1, (v))
4930
4931 +#define atomic64_read_unchecked(v) atomic64_read(v)
4932 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
4933 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
4934 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
4935 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
4936 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
4937 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
4938 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
4939 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
4940 +
4941 /* Atomic operations are already serializing */
4942 #define smp_mb__before_atomic_dec() barrier()
4943 #define smp_mb__after_atomic_dec() barrier()
4944 diff --git a/arch/ia64/include/asm/cache.h b/arch/ia64/include/asm/cache.h
4945 index 988254a..e1ee885 100644
4946 --- a/arch/ia64/include/asm/cache.h
4947 +++ b/arch/ia64/include/asm/cache.h
4948 @@ -1,6 +1,7 @@
4949 #ifndef _ASM_IA64_CACHE_H
4950 #define _ASM_IA64_CACHE_H
4951
4952 +#include <linux/const.h>
4953
4954 /*
4955 * Copyright (C) 1998-2000 Hewlett-Packard Co
4956 @@ -9,7 +10,7 @@
4957
4958 /* Bytes per L1 (data) cache line. */
4959 #define L1_CACHE_SHIFT CONFIG_IA64_L1_CACHE_SHIFT
4960 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4961 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4962
4963 #ifdef CONFIG_SMP
4964 # define SMP_CACHE_SHIFT L1_CACHE_SHIFT
4965 diff --git a/arch/ia64/include/asm/elf.h b/arch/ia64/include/asm/elf.h
4966 index 5a83c5c..4d7f553 100644
4967 --- a/arch/ia64/include/asm/elf.h
4968 +++ b/arch/ia64/include/asm/elf.h
4969 @@ -42,6 +42,13 @@
4970 */
4971 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x800000000UL)
4972
4973 +#ifdef CONFIG_PAX_ASLR
4974 +#define PAX_ELF_ET_DYN_BASE (current->personality == PER_LINUX32 ? 0x08048000UL : 0x4000000000000000UL)
4975 +
4976 +#define PAX_DELTA_MMAP_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
4977 +#define PAX_DELTA_STACK_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
4978 +#endif
4979 +
4980 #define PT_IA_64_UNWIND 0x70000001
4981
4982 /* IA-64 relocations: */
4983 diff --git a/arch/ia64/include/asm/pgalloc.h b/arch/ia64/include/asm/pgalloc.h
4984 index 5767cdf..7462574 100644
4985 --- a/arch/ia64/include/asm/pgalloc.h
4986 +++ b/arch/ia64/include/asm/pgalloc.h
4987 @@ -39,6 +39,12 @@ pgd_populate(struct mm_struct *mm, pgd_t * pgd_entry, pud_t * pud)
4988 pgd_val(*pgd_entry) = __pa(pud);
4989 }
4990
4991 +static inline void
4992 +pgd_populate_kernel(struct mm_struct *mm, pgd_t * pgd_entry, pud_t * pud)
4993 +{
4994 + pgd_populate(mm, pgd_entry, pud);
4995 +}
4996 +
4997 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
4998 {
4999 return quicklist_alloc(0, GFP_KERNEL, NULL);
5000 @@ -57,6 +63,12 @@ pud_populate(struct mm_struct *mm, pud_t * pud_entry, pmd_t * pmd)
5001 pud_val(*pud_entry) = __pa(pmd);
5002 }
5003
5004 +static inline void
5005 +pud_populate_kernel(struct mm_struct *mm, pud_t * pud_entry, pmd_t * pmd)
5006 +{
5007 + pud_populate(mm, pud_entry, pmd);
5008 +}
5009 +
5010 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr)
5011 {
5012 return quicklist_alloc(0, GFP_KERNEL, NULL);
5013 diff --git a/arch/ia64/include/asm/pgtable.h b/arch/ia64/include/asm/pgtable.h
5014 index 7935115..c0eca6a 100644
5015 --- a/arch/ia64/include/asm/pgtable.h
5016 +++ b/arch/ia64/include/asm/pgtable.h
5017 @@ -12,7 +12,7 @@
5018 * David Mosberger-Tang <davidm@hpl.hp.com>
5019 */
5020
5021 -
5022 +#include <linux/const.h>
5023 #include <asm/mman.h>
5024 #include <asm/page.h>
5025 #include <asm/processor.h>
5026 @@ -142,6 +142,17 @@
5027 #define PAGE_READONLY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
5028 #define PAGE_COPY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
5029 #define PAGE_COPY_EXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RX)
5030 +
5031 +#ifdef CONFIG_PAX_PAGEEXEC
5032 +# define PAGE_SHARED_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RW)
5033 +# define PAGE_READONLY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
5034 +# define PAGE_COPY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
5035 +#else
5036 +# define PAGE_SHARED_NOEXEC PAGE_SHARED
5037 +# define PAGE_READONLY_NOEXEC PAGE_READONLY
5038 +# define PAGE_COPY_NOEXEC PAGE_COPY
5039 +#endif
5040 +
5041 #define PAGE_GATE __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_X_RX)
5042 #define PAGE_KERNEL __pgprot(__DIRTY_BITS | _PAGE_PL_0 | _PAGE_AR_RWX)
5043 #define PAGE_KERNELRX __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_RX)
5044 diff --git a/arch/ia64/include/asm/spinlock.h b/arch/ia64/include/asm/spinlock.h
5045 index 45698cd..e8e2dbc 100644
5046 --- a/arch/ia64/include/asm/spinlock.h
5047 +++ b/arch/ia64/include/asm/spinlock.h
5048 @@ -71,7 +71,7 @@ static __always_inline void __ticket_spin_unlock(arch_spinlock_t *lock)
5049 unsigned short *p = (unsigned short *)&lock->lock + 1, tmp;
5050
5051 asm volatile ("ld2.bias %0=[%1]" : "=r"(tmp) : "r"(p));
5052 - ACCESS_ONCE(*p) = (tmp + 2) & ~1;
5053 + ACCESS_ONCE_RW(*p) = (tmp + 2) & ~1;
5054 }
5055
5056 static __always_inline void __ticket_spin_unlock_wait(arch_spinlock_t *lock)
5057 diff --git a/arch/ia64/include/asm/uaccess.h b/arch/ia64/include/asm/uaccess.h
5058 index 449c8c0..3d4b1e9 100644
5059 --- a/arch/ia64/include/asm/uaccess.h
5060 +++ b/arch/ia64/include/asm/uaccess.h
5061 @@ -70,6 +70,7 @@
5062 && ((segment).seg == KERNEL_DS.seg \
5063 || likely(REGION_OFFSET((unsigned long) (addr)) < RGN_MAP_LIMIT))); \
5064 })
5065 +#define access_ok_noprefault(type, addr, size) access_ok((type), (addr), (size))
5066 #define access_ok(type, addr, size) __access_ok((addr), (size), get_fs())
5067
5068 /*
5069 @@ -240,12 +241,24 @@ extern unsigned long __must_check __copy_user (void __user *to, const void __use
5070 static inline unsigned long
5071 __copy_to_user (void __user *to, const void *from, unsigned long count)
5072 {
5073 + if (count > INT_MAX)
5074 + return count;
5075 +
5076 + if (!__builtin_constant_p(count))
5077 + check_object_size(from, count, true);
5078 +
5079 return __copy_user(to, (__force void __user *) from, count);
5080 }
5081
5082 static inline unsigned long
5083 __copy_from_user (void *to, const void __user *from, unsigned long count)
5084 {
5085 + if (count > INT_MAX)
5086 + return count;
5087 +
5088 + if (!__builtin_constant_p(count))
5089 + check_object_size(to, count, false);
5090 +
5091 return __copy_user((__force void __user *) to, from, count);
5092 }
5093
5094 @@ -255,10 +268,13 @@ __copy_from_user (void *to, const void __user *from, unsigned long count)
5095 ({ \
5096 void __user *__cu_to = (to); \
5097 const void *__cu_from = (from); \
5098 - long __cu_len = (n); \
5099 + unsigned long __cu_len = (n); \
5100 \
5101 - if (__access_ok(__cu_to, __cu_len, get_fs())) \
5102 + if (__cu_len <= INT_MAX && __access_ok(__cu_to, __cu_len, get_fs())) { \
5103 + if (!__builtin_constant_p(n)) \
5104 + check_object_size(__cu_from, __cu_len, true); \
5105 __cu_len = __copy_user(__cu_to, (__force void __user *) __cu_from, __cu_len); \
5106 + } \
5107 __cu_len; \
5108 })
5109
5110 @@ -266,11 +282,14 @@ __copy_from_user (void *to, const void __user *from, unsigned long count)
5111 ({ \
5112 void *__cu_to = (to); \
5113 const void __user *__cu_from = (from); \
5114 - long __cu_len = (n); \
5115 + unsigned long __cu_len = (n); \
5116 \
5117 __chk_user_ptr(__cu_from); \
5118 - if (__access_ok(__cu_from, __cu_len, get_fs())) \
5119 + if (__cu_len <= INT_MAX && __access_ok(__cu_from, __cu_len, get_fs())) { \
5120 + if (!__builtin_constant_p(n)) \
5121 + check_object_size(__cu_to, __cu_len, false); \
5122 __cu_len = __copy_user((__force void __user *) __cu_to, __cu_from, __cu_len); \
5123 + } \
5124 __cu_len; \
5125 })
5126
5127 diff --git a/arch/ia64/kernel/module.c b/arch/ia64/kernel/module.c
5128 index 24603be..948052d 100644
5129 --- a/arch/ia64/kernel/module.c
5130 +++ b/arch/ia64/kernel/module.c
5131 @@ -307,8 +307,7 @@ plt_target (struct plt_entry *plt)
5132 void
5133 module_free (struct module *mod, void *module_region)
5134 {
5135 - if (mod && mod->arch.init_unw_table &&
5136 - module_region == mod->module_init) {
5137 + if (mod && mod->arch.init_unw_table && module_region == mod->module_init_rx) {
5138 unw_remove_unwind_table(mod->arch.init_unw_table);
5139 mod->arch.init_unw_table = NULL;
5140 }
5141 @@ -494,15 +493,39 @@ module_frob_arch_sections (Elf_Ehdr *ehdr, Elf_Shdr *sechdrs, char *secstrings,
5142 }
5143
5144 static inline int
5145 +in_init_rx (const struct module *mod, uint64_t addr)
5146 +{
5147 + return addr - (uint64_t) mod->module_init_rx < mod->init_size_rx;
5148 +}
5149 +
5150 +static inline int
5151 +in_init_rw (const struct module *mod, uint64_t addr)
5152 +{
5153 + return addr - (uint64_t) mod->module_init_rw < mod->init_size_rw;
5154 +}
5155 +
5156 +static inline int
5157 in_init (const struct module *mod, uint64_t addr)
5158 {
5159 - return addr - (uint64_t) mod->module_init < mod->init_size;
5160 + return in_init_rx(mod, addr) || in_init_rw(mod, addr);
5161 +}
5162 +
5163 +static inline int
5164 +in_core_rx (const struct module *mod, uint64_t addr)
5165 +{
5166 + return addr - (uint64_t) mod->module_core_rx < mod->core_size_rx;
5167 +}
5168 +
5169 +static inline int
5170 +in_core_rw (const struct module *mod, uint64_t addr)
5171 +{
5172 + return addr - (uint64_t) mod->module_core_rw < mod->core_size_rw;
5173 }
5174
5175 static inline int
5176 in_core (const struct module *mod, uint64_t addr)
5177 {
5178 - return addr - (uint64_t) mod->module_core < mod->core_size;
5179 + return in_core_rx(mod, addr) || in_core_rw(mod, addr);
5180 }
5181
5182 static inline int
5183 @@ -685,7 +708,14 @@ do_reloc (struct module *mod, uint8_t r_type, Elf64_Sym *sym, uint64_t addend,
5184 break;
5185
5186 case RV_BDREL:
5187 - val -= (uint64_t) (in_init(mod, val) ? mod->module_init : mod->module_core);
5188 + if (in_init_rx(mod, val))
5189 + val -= (uint64_t) mod->module_init_rx;
5190 + else if (in_init_rw(mod, val))
5191 + val -= (uint64_t) mod->module_init_rw;
5192 + else if (in_core_rx(mod, val))
5193 + val -= (uint64_t) mod->module_core_rx;
5194 + else if (in_core_rw(mod, val))
5195 + val -= (uint64_t) mod->module_core_rw;
5196 break;
5197
5198 case RV_LTV:
5199 @@ -820,15 +850,15 @@ apply_relocate_add (Elf64_Shdr *sechdrs, const char *strtab, unsigned int symind
5200 * addresses have been selected...
5201 */
5202 uint64_t gp;
5203 - if (mod->core_size > MAX_LTOFF)
5204 + if (mod->core_size_rx + mod->core_size_rw > MAX_LTOFF)
5205 /*
5206 * This takes advantage of fact that SHF_ARCH_SMALL gets allocated
5207 * at the end of the module.
5208 */
5209 - gp = mod->core_size - MAX_LTOFF / 2;
5210 + gp = mod->core_size_rx + mod->core_size_rw - MAX_LTOFF / 2;
5211 else
5212 - gp = mod->core_size / 2;
5213 - gp = (uint64_t) mod->module_core + ((gp + 7) & -8);
5214 + gp = (mod->core_size_rx + mod->core_size_rw) / 2;
5215 + gp = (uint64_t) mod->module_core_rx + ((gp + 7) & -8);
5216 mod->arch.gp = gp;
5217 DEBUGP("%s: placing gp at 0x%lx\n", __func__, gp);
5218 }
5219 diff --git a/arch/ia64/kernel/palinfo.c b/arch/ia64/kernel/palinfo.c
5220 index ab33328..f39506c 100644
5221 --- a/arch/ia64/kernel/palinfo.c
5222 +++ b/arch/ia64/kernel/palinfo.c
5223 @@ -980,7 +980,7 @@ static int palinfo_cpu_callback(struct notifier_block *nfb,
5224 return NOTIFY_OK;
5225 }
5226
5227 -static struct notifier_block __refdata palinfo_cpu_notifier =
5228 +static struct notifier_block palinfo_cpu_notifier =
5229 {
5230 .notifier_call = palinfo_cpu_callback,
5231 .priority = 0,
5232 diff --git a/arch/ia64/kernel/sys_ia64.c b/arch/ia64/kernel/sys_ia64.c
5233 index 41e33f8..65180b2a 100644
5234 --- a/arch/ia64/kernel/sys_ia64.c
5235 +++ b/arch/ia64/kernel/sys_ia64.c
5236 @@ -28,6 +28,7 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
5237 unsigned long align_mask = 0;
5238 struct mm_struct *mm = current->mm;
5239 struct vm_unmapped_area_info info;
5240 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
5241
5242 if (len > RGN_MAP_LIMIT)
5243 return -ENOMEM;
5244 @@ -43,6 +44,13 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
5245 if (REGION_NUMBER(addr) == RGN_HPAGE)
5246 addr = 0;
5247 #endif
5248 +
5249 +#ifdef CONFIG_PAX_RANDMMAP
5250 + if (mm->pax_flags & MF_PAX_RANDMMAP)
5251 + addr = mm->free_area_cache;
5252 + else
5253 +#endif
5254 +
5255 if (!addr)
5256 addr = TASK_UNMAPPED_BASE;
5257
5258 @@ -61,6 +69,7 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
5259 info.high_limit = TASK_SIZE;
5260 info.align_mask = align_mask;
5261 info.align_offset = 0;
5262 + info.threadstack_offset = offset;
5263 return vm_unmapped_area(&info);
5264 }
5265
5266 diff --git a/arch/ia64/kernel/vmlinux.lds.S b/arch/ia64/kernel/vmlinux.lds.S
5267 index 0ccb28f..8992469 100644
5268 --- a/arch/ia64/kernel/vmlinux.lds.S
5269 +++ b/arch/ia64/kernel/vmlinux.lds.S
5270 @@ -198,7 +198,7 @@ SECTIONS {
5271 /* Per-cpu data: */
5272 . = ALIGN(PERCPU_PAGE_SIZE);
5273 PERCPU_VADDR(SMP_CACHE_BYTES, PERCPU_ADDR, :percpu)
5274 - __phys_per_cpu_start = __per_cpu_load;
5275 + __phys_per_cpu_start = per_cpu_load;
5276 /*
5277 * ensure percpu data fits
5278 * into percpu page size
5279 diff --git a/arch/ia64/mm/fault.c b/arch/ia64/mm/fault.c
5280 index 7225dad..2a7c8256 100644
5281 --- a/arch/ia64/mm/fault.c
5282 +++ b/arch/ia64/mm/fault.c
5283 @@ -72,6 +72,23 @@ mapped_kernel_page_is_present (unsigned long address)
5284 return pte_present(pte);
5285 }
5286
5287 +#ifdef CONFIG_PAX_PAGEEXEC
5288 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
5289 +{
5290 + unsigned long i;
5291 +
5292 + printk(KERN_ERR "PAX: bytes at PC: ");
5293 + for (i = 0; i < 8; i++) {
5294 + unsigned int c;
5295 + if (get_user(c, (unsigned int *)pc+i))
5296 + printk(KERN_CONT "???????? ");
5297 + else
5298 + printk(KERN_CONT "%08x ", c);
5299 + }
5300 + printk("\n");
5301 +}
5302 +#endif
5303 +
5304 # define VM_READ_BIT 0
5305 # define VM_WRITE_BIT 1
5306 # define VM_EXEC_BIT 2
5307 @@ -151,8 +168,21 @@ retry:
5308 if (((isr >> IA64_ISR_R_BIT) & 1UL) && (!(vma->vm_flags & (VM_READ | VM_WRITE))))
5309 goto bad_area;
5310
5311 - if ((vma->vm_flags & mask) != mask)
5312 + if ((vma->vm_flags & mask) != mask) {
5313 +
5314 +#ifdef CONFIG_PAX_PAGEEXEC
5315 + if (!(vma->vm_flags & VM_EXEC) && (mask & VM_EXEC)) {
5316 + if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || address != regs->cr_iip)
5317 + goto bad_area;
5318 +
5319 + up_read(&mm->mmap_sem);
5320 + pax_report_fault(regs, (void *)regs->cr_iip, (void *)regs->r12);
5321 + do_group_exit(SIGKILL);
5322 + }
5323 +#endif
5324 +
5325 goto bad_area;
5326 + }
5327
5328 /*
5329 * If for any reason at all we couldn't handle the fault, make
5330 diff --git a/arch/ia64/mm/hugetlbpage.c b/arch/ia64/mm/hugetlbpage.c
5331 index 68232db..6ca80af 100644
5332 --- a/arch/ia64/mm/hugetlbpage.c
5333 +++ b/arch/ia64/mm/hugetlbpage.c
5334 @@ -154,6 +154,7 @@ unsigned long hugetlb_get_unmapped_area(struct file *file, unsigned long addr, u
5335 unsigned long pgoff, unsigned long flags)
5336 {
5337 struct vm_unmapped_area_info info;
5338 + unsigned long offset = gr_rand_threadstack_offset(current->mm, file, flags);
5339
5340 if (len > RGN_MAP_LIMIT)
5341 return -ENOMEM;
5342 @@ -177,6 +178,7 @@ unsigned long hugetlb_get_unmapped_area(struct file *file, unsigned long addr, u
5343 info.high_limit = HPAGE_REGION_BASE + RGN_MAP_LIMIT;
5344 info.align_mask = PAGE_MASK & (HPAGE_SIZE - 1);
5345 info.align_offset = 0;
5346 + info.threadstack_offset = offset;
5347 return vm_unmapped_area(&info);
5348 }
5349
5350 diff --git a/arch/ia64/mm/init.c b/arch/ia64/mm/init.c
5351 index 88504ab..cbb6c9f 100644
5352 --- a/arch/ia64/mm/init.c
5353 +++ b/arch/ia64/mm/init.c
5354 @@ -120,6 +120,19 @@ ia64_init_addr_space (void)
5355 vma->vm_start = current->thread.rbs_bot & PAGE_MASK;
5356 vma->vm_end = vma->vm_start + PAGE_SIZE;
5357 vma->vm_flags = VM_DATA_DEFAULT_FLAGS|VM_GROWSUP|VM_ACCOUNT;
5358 +
5359 +#ifdef CONFIG_PAX_PAGEEXEC
5360 + if (current->mm->pax_flags & MF_PAX_PAGEEXEC) {
5361 + vma->vm_flags &= ~VM_EXEC;
5362 +
5363 +#ifdef CONFIG_PAX_MPROTECT
5364 + if (current->mm->pax_flags & MF_PAX_MPROTECT)
5365 + vma->vm_flags &= ~VM_MAYEXEC;
5366 +#endif
5367 +
5368 + }
5369 +#endif
5370 +
5371 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
5372 down_write(&current->mm->mmap_sem);
5373 if (insert_vm_struct(current->mm, vma)) {
5374 diff --git a/arch/m32r/include/asm/cache.h b/arch/m32r/include/asm/cache.h
5375 index 40b3ee9..8c2c112 100644
5376 --- a/arch/m32r/include/asm/cache.h
5377 +++ b/arch/m32r/include/asm/cache.h
5378 @@ -1,8 +1,10 @@
5379 #ifndef _ASM_M32R_CACHE_H
5380 #define _ASM_M32R_CACHE_H
5381
5382 +#include <linux/const.h>
5383 +
5384 /* L1 cache line size */
5385 #define L1_CACHE_SHIFT 4
5386 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
5387 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5388
5389 #endif /* _ASM_M32R_CACHE_H */
5390 diff --git a/arch/m32r/lib/usercopy.c b/arch/m32r/lib/usercopy.c
5391 index 82abd15..d95ae5d 100644
5392 --- a/arch/m32r/lib/usercopy.c
5393 +++ b/arch/m32r/lib/usercopy.c
5394 @@ -14,6 +14,9 @@
5395 unsigned long
5396 __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
5397 {
5398 + if ((long)n < 0)
5399 + return n;
5400 +
5401 prefetch(from);
5402 if (access_ok(VERIFY_WRITE, to, n))
5403 __copy_user(to,from,n);
5404 @@ -23,6 +26,9 @@ __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
5405 unsigned long
5406 __generic_copy_from_user(void *to, const void __user *from, unsigned long n)
5407 {
5408 + if ((long)n < 0)
5409 + return n;
5410 +
5411 prefetchw(to);
5412 if (access_ok(VERIFY_READ, from, n))
5413 __copy_user_zeroing(to,from,n);
5414 diff --git a/arch/m68k/include/asm/cache.h b/arch/m68k/include/asm/cache.h
5415 index 0395c51..5f26031 100644
5416 --- a/arch/m68k/include/asm/cache.h
5417 +++ b/arch/m68k/include/asm/cache.h
5418 @@ -4,9 +4,11 @@
5419 #ifndef __ARCH_M68K_CACHE_H
5420 #define __ARCH_M68K_CACHE_H
5421
5422 +#include <linux/const.h>
5423 +
5424 /* bytes per L1 cache line */
5425 #define L1_CACHE_SHIFT 4
5426 -#define L1_CACHE_BYTES (1<< L1_CACHE_SHIFT)
5427 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5428
5429 #define ARCH_DMA_MINALIGN L1_CACHE_BYTES
5430
5431 diff --git a/arch/metag/mm/hugetlbpage.c b/arch/metag/mm/hugetlbpage.c
5432 index 0424315..defcca9 100644
5433 --- a/arch/metag/mm/hugetlbpage.c
5434 +++ b/arch/metag/mm/hugetlbpage.c
5435 @@ -205,6 +205,7 @@ hugetlb_get_unmapped_area_new_pmd(unsigned long len)
5436 info.high_limit = TASK_SIZE;
5437 info.align_mask = PAGE_MASK & HUGEPT_MASK;
5438 info.align_offset = 0;
5439 + info.threadstack_offset = 0;
5440 return vm_unmapped_area(&info);
5441 }
5442
5443 diff --git a/arch/microblaze/include/asm/cache.h b/arch/microblaze/include/asm/cache.h
5444 index 4efe96a..60e8699 100644
5445 --- a/arch/microblaze/include/asm/cache.h
5446 +++ b/arch/microblaze/include/asm/cache.h
5447 @@ -13,11 +13,12 @@
5448 #ifndef _ASM_MICROBLAZE_CACHE_H
5449 #define _ASM_MICROBLAZE_CACHE_H
5450
5451 +#include <linux/const.h>
5452 #include <asm/registers.h>
5453
5454 #define L1_CACHE_SHIFT 5
5455 /* word-granular cache in microblaze */
5456 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
5457 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5458
5459 #define SMP_CACHE_BYTES L1_CACHE_BYTES
5460
5461 diff --git a/arch/mips/Kconfig b/arch/mips/Kconfig
5462 index 650de39..6982b02 100644
5463 --- a/arch/mips/Kconfig
5464 +++ b/arch/mips/Kconfig
5465 @@ -2268,6 +2268,7 @@ source "kernel/Kconfig.preempt"
5466
5467 config KEXEC
5468 bool "Kexec system call"
5469 + depends on !GRKERNSEC_KMEM
5470 help
5471 kexec is a system call that implements the ability to shutdown your
5472 current kernel, and to start another kernel. It is like a reboot
5473 diff --git a/arch/mips/cavium-octeon/dma-octeon.c b/arch/mips/cavium-octeon/dma-octeon.c
5474 index 02f2444..506969c 100644
5475 --- a/arch/mips/cavium-octeon/dma-octeon.c
5476 +++ b/arch/mips/cavium-octeon/dma-octeon.c
5477 @@ -199,7 +199,7 @@ static void octeon_dma_free_coherent(struct device *dev, size_t size,
5478 if (dma_release_from_coherent(dev, order, vaddr))
5479 return;
5480
5481 - swiotlb_free_coherent(dev, size, vaddr, dma_handle);
5482 + swiotlb_free_coherent(dev, size, vaddr, dma_handle, attrs);
5483 }
5484
5485 static dma_addr_t octeon_unity_phys_to_dma(struct device *dev, phys_addr_t paddr)
5486 diff --git a/arch/mips/include/asm/atomic.h b/arch/mips/include/asm/atomic.h
5487 index 7eed2f2..c4e385d 100644
5488 --- a/arch/mips/include/asm/atomic.h
5489 +++ b/arch/mips/include/asm/atomic.h
5490 @@ -21,15 +21,39 @@
5491 #include <asm/cmpxchg.h>
5492 #include <asm/war.h>
5493
5494 +#ifdef CONFIG_GENERIC_ATOMIC64
5495 +#include <asm-generic/atomic64.h>
5496 +#endif
5497 +
5498 #define ATOMIC_INIT(i) { (i) }
5499
5500 +#ifdef CONFIG_64BIT
5501 +#define _ASM_EXTABLE(from, to) \
5502 +" .section __ex_table,\"a\"\n" \
5503 +" .dword " #from ", " #to"\n" \
5504 +" .previous\n"
5505 +#else
5506 +#define _ASM_EXTABLE(from, to) \
5507 +" .section __ex_table,\"a\"\n" \
5508 +" .word " #from ", " #to"\n" \
5509 +" .previous\n"
5510 +#endif
5511 +
5512 /*
5513 * atomic_read - read atomic variable
5514 * @v: pointer of type atomic_t
5515 *
5516 * Atomically reads the value of @v.
5517 */
5518 -#define atomic_read(v) (*(volatile int *)&(v)->counter)
5519 +static inline int atomic_read(const atomic_t *v)
5520 +{
5521 + return (*(volatile const int *) &v->counter);
5522 +}
5523 +
5524 +static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
5525 +{
5526 + return (*(volatile const int *) &v->counter);
5527 +}
5528
5529 /*
5530 * atomic_set - set atomic variable
5531 @@ -38,7 +62,15 @@
5532 *
5533 * Atomically sets the value of @v to @i.
5534 */
5535 -#define atomic_set(v, i) ((v)->counter = (i))
5536 +static inline void atomic_set(atomic_t *v, int i)
5537 +{
5538 + v->counter = i;
5539 +}
5540 +
5541 +static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
5542 +{
5543 + v->counter = i;
5544 +}
5545
5546 /*
5547 * atomic_add - add integer to atomic variable
5548 @@ -47,7 +79,67 @@
5549 *
5550 * Atomically adds @i to @v.
5551 */
5552 -static __inline__ void atomic_add(int i, atomic_t * v)
5553 +static __inline__ void atomic_add(int i, atomic_t *v)
5554 +{
5555 + int temp;
5556 +
5557 + if (kernel_uses_llsc && R10000_LLSC_WAR) {
5558 + __asm__ __volatile__(
5559 + " .set mips3 \n"
5560 + "1: ll %0, %1 # atomic_add \n"
5561 +#ifdef CONFIG_PAX_REFCOUNT
5562 + /* Exception on overflow. */
5563 + "2: add %0, %2 \n"
5564 +#else
5565 + " addu %0, %2 \n"
5566 +#endif
5567 + " sc %0, %1 \n"
5568 + " beqzl %0, 1b \n"
5569 +#ifdef CONFIG_PAX_REFCOUNT
5570 + "3: \n"
5571 + _ASM_EXTABLE(2b, 3b)
5572 +#endif
5573 + " .set mips0 \n"
5574 + : "=&r" (temp), "+m" (v->counter)
5575 + : "Ir" (i));
5576 + } else if (kernel_uses_llsc) {
5577 + __asm__ __volatile__(
5578 + " .set mips3 \n"
5579 + "1: ll %0, %1 # atomic_add \n"
5580 +#ifdef CONFIG_PAX_REFCOUNT
5581 + /* Exception on overflow. */
5582 + "2: add %0, %2 \n"
5583 +#else
5584 + " addu %0, %2 \n"
5585 +#endif
5586 + " sc %0, %1 \n"
5587 + " beqz %0, 1b \n"
5588 +#ifdef CONFIG_PAX_REFCOUNT
5589 + "3: \n"
5590 + _ASM_EXTABLE(2b, 3b)
5591 +#endif
5592 + " .set mips0 \n"
5593 + : "=&r" (temp), "+m" (v->counter)
5594 + : "Ir" (i));
5595 + } else {
5596 + unsigned long flags;
5597 +
5598 + raw_local_irq_save(flags);
5599 + __asm__ __volatile__(
5600 +#ifdef CONFIG_PAX_REFCOUNT
5601 + /* Exception on overflow. */
5602 + "1: add %0, %1 \n"
5603 + "2: \n"
5604 + _ASM_EXTABLE(1b, 2b)
5605 +#else
5606 + " addu %0, %1 \n"
5607 +#endif
5608 + : "+r" (v->counter) : "Ir" (i));
5609 + raw_local_irq_restore(flags);
5610 + }
5611 +}
5612 +
5613 +static __inline__ void atomic_add_unchecked(int i, atomic_unchecked_t *v)
5614 {
5615 if (kernel_uses_llsc && R10000_LLSC_WAR) {
5616 int temp;
5617 @@ -90,7 +182,67 @@ static __inline__ void atomic_add(int i, atomic_t * v)
5618 *
5619 * Atomically subtracts @i from @v.
5620 */
5621 -static __inline__ void atomic_sub(int i, atomic_t * v)
5622 +static __inline__ void atomic_sub(int i, atomic_t *v)
5623 +{
5624 + int temp;
5625 +
5626 + if (kernel_uses_llsc && R10000_LLSC_WAR) {
5627 + __asm__ __volatile__(
5628 + " .set mips3 \n"
5629 + "1: ll %0, %1 # atomic64_sub \n"
5630 +#ifdef CONFIG_PAX_REFCOUNT
5631 + /* Exception on overflow. */
5632 + "2: sub %0, %2 \n"
5633 +#else
5634 + " subu %0, %2 \n"
5635 +#endif
5636 + " sc %0, %1 \n"
5637 + " beqzl %0, 1b \n"
5638 +#ifdef CONFIG_PAX_REFCOUNT
5639 + "3: \n"
5640 + _ASM_EXTABLE(2b, 3b)
5641 +#endif
5642 + " .set mips0 \n"
5643 + : "=&r" (temp), "+m" (v->counter)
5644 + : "Ir" (i));
5645 + } else if (kernel_uses_llsc) {
5646 + __asm__ __volatile__(
5647 + " .set mips3 \n"
5648 + "1: ll %0, %1 # atomic64_sub \n"
5649 +#ifdef CONFIG_PAX_REFCOUNT
5650 + /* Exception on overflow. */
5651 + "2: sub %0, %2 \n"
5652 +#else
5653 + " subu %0, %2 \n"
5654 +#endif
5655 + " sc %0, %1 \n"
5656 + " beqz %0, 1b \n"
5657 +#ifdef CONFIG_PAX_REFCOUNT
5658 + "3: \n"
5659 + _ASM_EXTABLE(2b, 3b)
5660 +#endif
5661 + " .set mips0 \n"
5662 + : "=&r" (temp), "+m" (v->counter)
5663 + : "Ir" (i));
5664 + } else {
5665 + unsigned long flags;
5666 +
5667 + raw_local_irq_save(flags);
5668 + __asm__ __volatile__(
5669 +#ifdef CONFIG_PAX_REFCOUNT
5670 + /* Exception on overflow. */
5671 + "1: sub %0, %1 \n"
5672 + "2: \n"
5673 + _ASM_EXTABLE(1b, 2b)
5674 +#else
5675 + " subu %0, %1 \n"
5676 +#endif
5677 + : "+r" (v->counter) : "Ir" (i));
5678 + raw_local_irq_restore(flags);
5679 + }
5680 +}
5681 +
5682 +static __inline__ void atomic_sub_unchecked(long i, atomic_unchecked_t *v)
5683 {
5684 if (kernel_uses_llsc && R10000_LLSC_WAR) {
5685 int temp;
5686 @@ -129,7 +281,93 @@ static __inline__ void atomic_sub(int i, atomic_t * v)
5687 /*
5688 * Same as above, but return the result value
5689 */
5690 -static __inline__ int atomic_add_return(int i, atomic_t * v)
5691 +static __inline__ int atomic_add_return(int i, atomic_t *v)
5692 +{
5693 + int result;
5694 + int temp;
5695 +
5696 + smp_mb__before_llsc();
5697 +
5698 + if (kernel_uses_llsc && R10000_LLSC_WAR) {
5699 + __asm__ __volatile__(
5700 + " .set mips3 \n"
5701 + "1: ll %1, %2 # atomic_add_return \n"
5702 +#ifdef CONFIG_PAX_REFCOUNT
5703 + "2: add %0, %1, %3 \n"
5704 +#else
5705 + " addu %0, %1, %3 \n"
5706 +#endif
5707 + " sc %0, %2 \n"
5708 + " beqzl %0, 1b \n"
5709 +#ifdef CONFIG_PAX_REFCOUNT
5710 + " b 4f \n"
5711 + " .set noreorder \n"
5712 + "3: b 5f \n"
5713 + " move %0, %1 \n"
5714 + " .set reorder \n"
5715 + _ASM_EXTABLE(2b, 3b)
5716 +#endif
5717 + "4: addu %0, %1, %3 \n"
5718 +#ifdef CONFIG_PAX_REFCOUNT
5719 + "5: \n"
5720 +#endif
5721 + " .set mips0 \n"
5722 + : "=&r" (result), "=&r" (temp), "+m" (v->counter)
5723 + : "Ir" (i));
5724 + } else if (kernel_uses_llsc) {
5725 + __asm__ __volatile__(
5726 + " .set mips3 \n"
5727 + "1: ll %1, %2 # atomic_add_return \n"
5728 +#ifdef CONFIG_PAX_REFCOUNT
5729 + "2: add %0, %1, %3 \n"
5730 +#else
5731 + " addu %0, %1, %3 \n"
5732 +#endif
5733 + " sc %0, %2 \n"
5734 + " bnez %0, 4f \n"
5735 + " b 1b \n"
5736 +#ifdef CONFIG_PAX_REFCOUNT
5737 + " .set noreorder \n"
5738 + "3: b 5f \n"
5739 + " move %0, %1 \n"
5740 + " .set reorder \n"
5741 + _ASM_EXTABLE(2b, 3b)
5742 +#endif
5743 + "4: addu %0, %1, %3 \n"
5744 +#ifdef CONFIG_PAX_REFCOUNT
5745 + "5: \n"
5746 +#endif
5747 + " .set mips0 \n"
5748 + : "=&r" (result), "=&r" (temp), "+m" (v->counter)
5749 + : "Ir" (i));
5750 + } else {
5751 + unsigned long flags;
5752 +
5753 + raw_local_irq_save(flags);
5754 + __asm__ __volatile__(
5755 + " lw %0, %1 \n"
5756 +#ifdef CONFIG_PAX_REFCOUNT
5757 + /* Exception on overflow. */
5758 + "1: add %0, %2 \n"
5759 +#else
5760 + " addu %0, %2 \n"
5761 +#endif
5762 + " sw %0, %1 \n"
5763 +#ifdef CONFIG_PAX_REFCOUNT
5764 + /* Note: Dest reg is not modified on overflow */
5765 + "2: \n"
5766 + _ASM_EXTABLE(1b, 2b)
5767 +#endif
5768 + : "=&r" (result), "+m" (v->counter) : "Ir" (i));
5769 + raw_local_irq_restore(flags);
5770 + }
5771 +
5772 + smp_llsc_mb();
5773 +
5774 + return result;
5775 +}
5776 +
5777 +static __inline__ int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
5778 {
5779 int result;
5780
5781 @@ -178,7 +416,93 @@ static __inline__ int atomic_add_return(int i, atomic_t * v)
5782 return result;
5783 }
5784
5785 -static __inline__ int atomic_sub_return(int i, atomic_t * v)
5786 +static __inline__ int atomic_sub_return(int i, atomic_t *v)
5787 +{
5788 + int result;
5789 + int temp;
5790 +
5791 + smp_mb__before_llsc();
5792 +
5793 + if (kernel_uses_llsc && R10000_LLSC_WAR) {
5794 + __asm__ __volatile__(
5795 + " .set mips3 \n"
5796 + "1: ll %1, %2 # atomic_sub_return \n"
5797 +#ifdef CONFIG_PAX_REFCOUNT
5798 + "2: sub %0, %1, %3 \n"
5799 +#else
5800 + " subu %0, %1, %3 \n"
5801 +#endif
5802 + " sc %0, %2 \n"
5803 + " beqzl %0, 1b \n"
5804 +#ifdef CONFIG_PAX_REFCOUNT
5805 + " b 4f \n"
5806 + " .set noreorder \n"
5807 + "3: b 5f \n"
5808 + " move %0, %1 \n"
5809 + " .set reorder \n"
5810 + _ASM_EXTABLE(2b, 3b)
5811 +#endif
5812 + "4: subu %0, %1, %3 \n"
5813 +#ifdef CONFIG_PAX_REFCOUNT
5814 + "5: \n"
5815 +#endif
5816 + " .set mips0 \n"
5817 + : "=&r" (result), "=&r" (temp), "=m" (v->counter)
5818 + : "Ir" (i), "m" (v->counter)
5819 + : "memory");
5820 + } else if (kernel_uses_llsc) {
5821 + __asm__ __volatile__(
5822 + " .set mips3 \n"
5823 + "1: ll %1, %2 # atomic_sub_return \n"
5824 +#ifdef CONFIG_PAX_REFCOUNT
5825 + "2: sub %0, %1, %3 \n"
5826 +#else
5827 + " subu %0, %1, %3 \n"
5828 +#endif
5829 + " sc %0, %2 \n"
5830 + " bnez %0, 4f \n"
5831 + " b 1b \n"
5832 +#ifdef CONFIG_PAX_REFCOUNT
5833 + " .set noreorder \n"
5834 + "3: b 5f \n"
5835 + " move %0, %1 \n"
5836 + " .set reorder \n"
5837 + _ASM_EXTABLE(2b, 3b)
5838 +#endif
5839 + "4: subu %0, %1, %3 \n"
5840 +#ifdef CONFIG_PAX_REFCOUNT
5841 + "5: \n"
5842 +#endif
5843 + " .set mips0 \n"
5844 + : "=&r" (result), "=&r" (temp), "+m" (v->counter)
5845 + : "Ir" (i));
5846 + } else {
5847 + unsigned long flags;
5848 +
5849 + raw_local_irq_save(flags);
5850 + __asm__ __volatile__(
5851 + " lw %0, %1 \n"
5852 +#ifdef CONFIG_PAX_REFCOUNT
5853 + /* Exception on overflow. */
5854 + "1: sub %0, %2 \n"
5855 +#else
5856 + " subu %0, %2 \n"
5857 +#endif
5858 + " sw %0, %1 \n"
5859 +#ifdef CONFIG_PAX_REFCOUNT
5860 + /* Note: Dest reg is not modified on overflow */
5861 + "2: \n"
5862 + _ASM_EXTABLE(1b, 2b)
5863 +#endif
5864 + : "=&r" (result), "+m" (v->counter) : "Ir" (i));
5865 + raw_local_irq_restore(flags);
5866 + }
5867 +
5868 + smp_llsc_mb();
5869 +
5870 + return result;
5871 +}
5872 +static __inline__ int atomic_sub_return_unchecked(int i, atomic_unchecked_t *v)
5873 {
5874 int result;
5875
5876 @@ -238,7 +562,7 @@ static __inline__ int atomic_sub_return(int i, atomic_t * v)
5877 * Atomically test @v and subtract @i if @v is greater or equal than @i.
5878 * The function returns the old value of @v minus @i.
5879 */
5880 -static __inline__ int atomic_sub_if_positive(int i, atomic_t * v)
5881 +static __inline__ int atomic_sub_if_positive(int i, atomic_t *v)
5882 {
5883 int result;
5884
5885 @@ -295,8 +619,26 @@ static __inline__ int atomic_sub_if_positive(int i, atomic_t * v)
5886 return result;
5887 }
5888
5889 -#define atomic_cmpxchg(v, o, n) (cmpxchg(&((v)->counter), (o), (n)))
5890 -#define atomic_xchg(v, new) (xchg(&((v)->counter), (new)))
5891 +static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
5892 +{
5893 + return cmpxchg(&v->counter, old, new);
5894 +}
5895 +
5896 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old,
5897 + int new)
5898 +{
5899 + return cmpxchg(&(v->counter), old, new);
5900 +}
5901 +
5902 +static inline int atomic_xchg(atomic_t *v, int new)
5903 +{
5904 + return xchg(&v->counter, new);
5905 +}
5906 +
5907 +static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
5908 +{
5909 + return xchg(&(v->counter), new);
5910 +}
5911
5912 /**
5913 * __atomic_add_unless - add unless the number is a given value
5914 @@ -324,6 +666,10 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
5915
5916 #define atomic_dec_return(v) atomic_sub_return(1, (v))
5917 #define atomic_inc_return(v) atomic_add_return(1, (v))
5918 +static __inline__ int atomic_inc_return_unchecked(atomic_unchecked_t *v)
5919 +{
5920 + return atomic_add_return_unchecked(1, v);
5921 +}
5922
5923 /*
5924 * atomic_sub_and_test - subtract value from variable and test result
5925 @@ -345,6 +691,10 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
5926 * other cases.
5927 */
5928 #define atomic_inc_and_test(v) (atomic_inc_return(v) == 0)
5929 +static __inline__ int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
5930 +{
5931 + return atomic_add_return_unchecked(1, v) == 0;
5932 +}
5933
5934 /*
5935 * atomic_dec_and_test - decrement by 1 and test
5936 @@ -369,6 +719,10 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
5937 * Atomically increments @v by 1.
5938 */
5939 #define atomic_inc(v) atomic_add(1, (v))
5940 +static __inline__ void atomic_inc_unchecked(atomic_unchecked_t *v)
5941 +{
5942 + atomic_add_unchecked(1, v);
5943 +}
5944
5945 /*
5946 * atomic_dec - decrement and test
5947 @@ -377,6 +731,10 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
5948 * Atomically decrements @v by 1.
5949 */
5950 #define atomic_dec(v) atomic_sub(1, (v))
5951 +static __inline__ void atomic_dec_unchecked(atomic_unchecked_t *v)
5952 +{
5953 + atomic_sub_unchecked(1, v);
5954 +}
5955
5956 /*
5957 * atomic_add_negative - add and test if negative
5958 @@ -398,14 +756,30 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
5959 * @v: pointer of type atomic64_t
5960 *
5961 */
5962 -#define atomic64_read(v) (*(volatile long *)&(v)->counter)
5963 +static inline long atomic64_read(const atomic64_t *v)
5964 +{
5965 + return (*(volatile const long *) &v->counter);
5966 +}
5967 +
5968 +static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
5969 +{
5970 + return (*(volatile const long *) &v->counter);
5971 +}
5972
5973 /*
5974 * atomic64_set - set atomic variable
5975 * @v: pointer of type atomic64_t
5976 * @i: required value
5977 */
5978 -#define atomic64_set(v, i) ((v)->counter = (i))
5979 +static inline void atomic64_set(atomic64_t *v, long i)
5980 +{
5981 + v->counter = i;
5982 +}
5983 +
5984 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
5985 +{
5986 + v->counter = i;
5987 +}
5988
5989 /*
5990 * atomic64_add - add integer to atomic variable
5991 @@ -414,7 +788,66 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
5992 *
5993 * Atomically adds @i to @v.
5994 */
5995 -static __inline__ void atomic64_add(long i, atomic64_t * v)
5996 +static __inline__ void atomic64_add(long i, atomic64_t *v)
5997 +{
5998 + long temp;
5999 +
6000 + if (kernel_uses_llsc && R10000_LLSC_WAR) {
6001 + __asm__ __volatile__(
6002 + " .set mips3 \n"
6003 + "1: lld %0, %1 # atomic64_add \n"
6004 +#ifdef CONFIG_PAX_REFCOUNT
6005 + /* Exception on overflow. */
6006 + "2: dadd %0, %2 \n"
6007 +#else
6008 + " daddu %0, %2 \n"
6009 +#endif
6010 + " scd %0, %1 \n"
6011 + " beqzl %0, 1b \n"
6012 +#ifdef CONFIG_PAX_REFCOUNT
6013 + "3: \n"
6014 + _ASM_EXTABLE(2b, 3b)
6015 +#endif
6016 + " .set mips0 \n"
6017 + : "=&r" (temp), "+m" (v->counter)
6018 + : "Ir" (i));
6019 + } else if (kernel_uses_llsc) {
6020 + __asm__ __volatile__(
6021 + " .set mips3 \n"
6022 + "1: lld %0, %1 # atomic64_add \n"
6023 +#ifdef CONFIG_PAX_REFCOUNT
6024 + /* Exception on overflow. */
6025 + "2: dadd %0, %2 \n"
6026 +#else
6027 + " daddu %0, %2 \n"
6028 +#endif
6029 + " scd %0, %1 \n"
6030 + " beqz %0, 1b \n"
6031 +#ifdef CONFIG_PAX_REFCOUNT
6032 + "3: \n"
6033 + _ASM_EXTABLE(2b, 3b)
6034 +#endif
6035 + " .set mips0 \n"
6036 + : "=&r" (temp), "+m" (v->counter)
6037 + : "Ir" (i));
6038 + } else {
6039 + unsigned long flags;
6040 +
6041 + raw_local_irq_save(flags);
6042 + __asm__ __volatile__(
6043 +#ifdef CONFIG_PAX_REFCOUNT
6044 + /* Exception on overflow. */
6045 + "1: dadd %0, %1 \n"
6046 + "2: \n"
6047 + _ASM_EXTABLE(1b, 2b)
6048 +#else
6049 + " daddu %0, %1 \n"
6050 +#endif
6051 + : "+r" (v->counter) : "Ir" (i));
6052 + raw_local_irq_restore(flags);
6053 + }
6054 +}
6055 +static __inline__ void atomic64_add_unchecked(long i, atomic64_unchecked_t *v)
6056 {
6057 if (kernel_uses_llsc && R10000_LLSC_WAR) {
6058 long temp;
6059 @@ -457,7 +890,67 @@ static __inline__ void atomic64_add(long i, atomic64_t * v)
6060 *
6061 * Atomically subtracts @i from @v.
6062 */
6063 -static __inline__ void atomic64_sub(long i, atomic64_t * v)
6064 +static __inline__ void atomic64_sub(long i, atomic64_t *v)
6065 +{
6066 + long temp;
6067 +
6068 + if (kernel_uses_llsc && R10000_LLSC_WAR) {
6069 + __asm__ __volatile__(
6070 + " .set mips3 \n"
6071 + "1: lld %0, %1 # atomic64_sub \n"
6072 +#ifdef CONFIG_PAX_REFCOUNT
6073 + /* Exception on overflow. */
6074 + "2: dsub %0, %2 \n"
6075 +#else
6076 + " dsubu %0, %2 \n"
6077 +#endif
6078 + " scd %0, %1 \n"
6079 + " beqzl %0, 1b \n"
6080 +#ifdef CONFIG_PAX_REFCOUNT
6081 + "3: \n"
6082 + _ASM_EXTABLE(2b, 3b)
6083 +#endif
6084 + " .set mips0 \n"
6085 + : "=&r" (temp), "+m" (v->counter)
6086 + : "Ir" (i));
6087 + } else if (kernel_uses_llsc) {
6088 + __asm__ __volatile__(
6089 + " .set mips3 \n"
6090 + "1: lld %0, %1 # atomic64_sub \n"
6091 +#ifdef CONFIG_PAX_REFCOUNT
6092 + /* Exception on overflow. */
6093 + "2: dsub %0, %2 \n"
6094 +#else
6095 + " dsubu %0, %2 \n"
6096 +#endif
6097 + " scd %0, %1 \n"
6098 + " beqz %0, 1b \n"
6099 +#ifdef CONFIG_PAX_REFCOUNT
6100 + "3: \n"
6101 + _ASM_EXTABLE(2b, 3b)
6102 +#endif
6103 + " .set mips0 \n"
6104 + : "=&r" (temp), "+m" (v->counter)
6105 + : "Ir" (i));
6106 + } else {
6107 + unsigned long flags;
6108 +
6109 + raw_local_irq_save(flags);
6110 + __asm__ __volatile__(
6111 +#ifdef CONFIG_PAX_REFCOUNT
6112 + /* Exception on overflow. */
6113 + "1: dsub %0, %1 \n"
6114 + "2: \n"
6115 + _ASM_EXTABLE(1b, 2b)
6116 +#else
6117 + " dsubu %0, %1 \n"
6118 +#endif
6119 + : "+r" (v->counter) : "Ir" (i));
6120 + raw_local_irq_restore(flags);
6121 + }
6122 +}
6123 +
6124 +static __inline__ void atomic64_sub_unchecked(long i, atomic64_unchecked_t *v)
6125 {
6126 if (kernel_uses_llsc && R10000_LLSC_WAR) {
6127 long temp;
6128 @@ -496,7 +989,93 @@ static __inline__ void atomic64_sub(long i, atomic64_t * v)
6129 /*
6130 * Same as above, but return the result value
6131 */
6132 -static __inline__ long atomic64_add_return(long i, atomic64_t * v)
6133 +static __inline__ long atomic64_add_return(long i, atomic64_t *v)
6134 +{
6135 + long result;
6136 + long temp;
6137 +
6138 + smp_mb__before_llsc();
6139 +
6140 + if (kernel_uses_llsc && R10000_LLSC_WAR) {
6141 + __asm__ __volatile__(
6142 + " .set mips3 \n"
6143 + "1: lld %1, %2 # atomic64_add_return \n"
6144 +#ifdef CONFIG_PAX_REFCOUNT
6145 + "2: dadd %0, %1, %3 \n"
6146 +#else
6147 + " daddu %0, %1, %3 \n"
6148 +#endif
6149 + " scd %0, %2 \n"
6150 + " beqzl %0, 1b \n"
6151 +#ifdef CONFIG_PAX_REFCOUNT
6152 + " b 4f \n"
6153 + " .set noreorder \n"
6154 + "3: b 5f \n"
6155 + " move %0, %1 \n"
6156 + " .set reorder \n"
6157 + _ASM_EXTABLE(2b, 3b)
6158 +#endif
6159 + "4: daddu %0, %1, %3 \n"
6160 +#ifdef CONFIG_PAX_REFCOUNT
6161 + "5: \n"
6162 +#endif
6163 + " .set mips0 \n"
6164 + : "=&r" (result), "=&r" (temp), "+m" (v->counter)
6165 + : "Ir" (i));
6166 + } else if (kernel_uses_llsc) {
6167 + __asm__ __volatile__(
6168 + " .set mips3 \n"
6169 + "1: lld %1, %2 # atomic64_add_return \n"
6170 +#ifdef CONFIG_PAX_REFCOUNT
6171 + "2: dadd %0, %1, %3 \n"
6172 +#else
6173 + " daddu %0, %1, %3 \n"
6174 +#endif
6175 + " scd %0, %2 \n"
6176 + " bnez %0, 4f \n"
6177 + " b 1b \n"
6178 +#ifdef CONFIG_PAX_REFCOUNT
6179 + " .set noreorder \n"
6180 + "3: b 5f \n"
6181 + " move %0, %1 \n"
6182 + " .set reorder \n"
6183 + _ASM_EXTABLE(2b, 3b)
6184 +#endif
6185 + "4: daddu %0, %1, %3 \n"
6186 +#ifdef CONFIG_PAX_REFCOUNT
6187 + "5: \n"
6188 +#endif
6189 + " .set mips0 \n"
6190 + : "=&r" (result), "=&r" (temp), "=m" (v->counter)
6191 + : "Ir" (i), "m" (v->counter)
6192 + : "memory");
6193 + } else {
6194 + unsigned long flags;
6195 +
6196 + raw_local_irq_save(flags);
6197 + __asm__ __volatile__(
6198 + " ld %0, %1 \n"
6199 +#ifdef CONFIG_PAX_REFCOUNT
6200 + /* Exception on overflow. */
6201 + "1: dadd %0, %2 \n"
6202 +#else
6203 + " daddu %0, %2 \n"
6204 +#endif
6205 + " sd %0, %1 \n"
6206 +#ifdef CONFIG_PAX_REFCOUNT
6207 + /* Note: Dest reg is not modified on overflow */
6208 + "2: \n"
6209 + _ASM_EXTABLE(1b, 2b)
6210 +#endif
6211 + : "=&r" (result), "+m" (v->counter) : "Ir" (i));
6212 + raw_local_irq_restore(flags);
6213 + }
6214 +
6215 + smp_llsc_mb();
6216 +
6217 + return result;
6218 +}
6219 +static __inline__ long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
6220 {
6221 long result;
6222
6223 @@ -546,7 +1125,97 @@ static __inline__ long atomic64_add_return(long i, atomic64_t * v)
6224 return result;
6225 }
6226
6227 -static __inline__ long atomic64_sub_return(long i, atomic64_t * v)
6228 +static __inline__ long atomic64_sub_return(long i, atomic64_t *v)
6229 +{
6230 + long result;
6231 + long temp;
6232 +
6233 + smp_mb__before_llsc();
6234 +
6235 + if (kernel_uses_llsc && R10000_LLSC_WAR) {
6236 + long temp;
6237 +
6238 + __asm__ __volatile__(
6239 + " .set mips3 \n"
6240 + "1: lld %1, %2 # atomic64_sub_return \n"
6241 +#ifdef CONFIG_PAX_REFCOUNT
6242 + "2: dsub %0, %1, %3 \n"
6243 +#else
6244 + " dsubu %0, %1, %3 \n"
6245 +#endif
6246 + " scd %0, %2 \n"
6247 + " beqzl %0, 1b \n"
6248 +#ifdef CONFIG_PAX_REFCOUNT
6249 + " b 4f \n"
6250 + " .set noreorder \n"
6251 + "3: b 5f \n"
6252 + " move %0, %1 \n"
6253 + " .set reorder \n"
6254 + _ASM_EXTABLE(2b, 3b)
6255 +#endif
6256 + "4: dsubu %0, %1, %3 \n"
6257 +#ifdef CONFIG_PAX_REFCOUNT
6258 + "5: \n"
6259 +#endif
6260 + " .set mips0 \n"
6261 + : "=&r" (result), "=&r" (temp), "=m" (v->counter)
6262 + : "Ir" (i), "m" (v->counter)
6263 + : "memory");
6264 + } else if (kernel_uses_llsc) {
6265 + __asm__ __volatile__(
6266 + " .set mips3 \n"
6267 + "1: lld %1, %2 # atomic64_sub_return \n"
6268 +#ifdef CONFIG_PAX_REFCOUNT
6269 + "2: dsub %0, %1, %3 \n"
6270 +#else
6271 + " dsubu %0, %1, %3 \n"
6272 +#endif
6273 + " scd %0, %2 \n"
6274 + " bnez %0, 4f \n"
6275 + " b 1b \n"
6276 +#ifdef CONFIG_PAX_REFCOUNT
6277 + " .set noreorder \n"
6278 + "3: b 5f \n"
6279 + " move %0, %1 \n"
6280 + " .set reorder \n"
6281 + _ASM_EXTABLE(2b, 3b)
6282 +#endif
6283 + "4: dsubu %0, %1, %3 \n"
6284 +#ifdef CONFIG_PAX_REFCOUNT
6285 + "5: \n"
6286 +#endif
6287 + " .set mips0 \n"
6288 + : "=&r" (result), "=&r" (temp), "=m" (v->counter)
6289 + : "Ir" (i), "m" (v->counter)
6290 + : "memory");
6291 + } else {
6292 + unsigned long flags;
6293 +
6294 + raw_local_irq_save(flags);
6295 + __asm__ __volatile__(
6296 + " ld %0, %1 \n"
6297 +#ifdef CONFIG_PAX_REFCOUNT
6298 + /* Exception on overflow. */
6299 + "1: dsub %0, %2 \n"
6300 +#else
6301 + " dsubu %0, %2 \n"
6302 +#endif
6303 + " sd %0, %1 \n"
6304 +#ifdef CONFIG_PAX_REFCOUNT
6305 + /* Note: Dest reg is not modified on overflow */
6306 + "2: \n"
6307 + _ASM_EXTABLE(1b, 2b)
6308 +#endif
6309 + : "=&r" (result), "+m" (v->counter) : "Ir" (i));
6310 + raw_local_irq_restore(flags);
6311 + }
6312 +
6313 + smp_llsc_mb();
6314 +
6315 + return result;
6316 +}
6317 +
6318 +static __inline__ long atomic64_sub_return_unchecked(long i, atomic64_unchecked_t *v)
6319 {
6320 long result;
6321
6322 @@ -605,7 +1274,7 @@ static __inline__ long atomic64_sub_return(long i, atomic64_t * v)
6323 * Atomically test @v and subtract @i if @v is greater or equal than @i.
6324 * The function returns the old value of @v minus @i.
6325 */
6326 -static __inline__ long atomic64_sub_if_positive(long i, atomic64_t * v)
6327 +static __inline__ long atomic64_sub_if_positive(long i, atomic64_t *v)
6328 {
6329 long result;
6330
6331 @@ -662,9 +1331,26 @@ static __inline__ long atomic64_sub_if_positive(long i, atomic64_t * v)
6332 return result;
6333 }
6334
6335 -#define atomic64_cmpxchg(v, o, n) \
6336 - ((__typeof__((v)->counter))cmpxchg(&((v)->counter), (o), (n)))
6337 -#define atomic64_xchg(v, new) (xchg(&((v)->counter), (new)))
6338 +static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
6339 +{
6340 + return cmpxchg(&v->counter, old, new);
6341 +}
6342 +
6343 +static inline long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long old,
6344 + long new)
6345 +{
6346 + return cmpxchg(&(v->counter), old, new);
6347 +}
6348 +
6349 +static inline long atomic64_xchg(atomic64_t *v, long new)
6350 +{
6351 + return xchg(&v->counter, new);
6352 +}
6353 +
6354 +static inline long atomic64_xchg_unchecked(atomic64_unchecked_t *v, long new)
6355 +{
6356 + return xchg(&(v->counter), new);
6357 +}
6358
6359 /**
6360 * atomic64_add_unless - add unless the number is a given value
6361 @@ -694,6 +1380,7 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
6362
6363 #define atomic64_dec_return(v) atomic64_sub_return(1, (v))
6364 #define atomic64_inc_return(v) atomic64_add_return(1, (v))
6365 +#define atomic64_inc_return_unchecked(v) atomic64_add_return_unchecked(1, (v))
6366
6367 /*
6368 * atomic64_sub_and_test - subtract value from variable and test result
6369 @@ -715,6 +1402,7 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
6370 * other cases.
6371 */
6372 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
6373 +#define atomic64_inc_and_test_unchecked(v) atomic64_add_return_unchecked(1, (v)) == 0)
6374
6375 /*
6376 * atomic64_dec_and_test - decrement by 1 and test
6377 @@ -739,6 +1427,7 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
6378 * Atomically increments @v by 1.
6379 */
6380 #define atomic64_inc(v) atomic64_add(1, (v))
6381 +#define atomic64_inc_unchecked(v) atomic64_add_unchecked(1, (v))
6382
6383 /*
6384 * atomic64_dec - decrement and test
6385 @@ -747,6 +1436,7 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
6386 * Atomically decrements @v by 1.
6387 */
6388 #define atomic64_dec(v) atomic64_sub(1, (v))
6389 +#define atomic64_dec_unchecked(v) atomic64_sub_unchecked(1, (v))
6390
6391 /*
6392 * atomic64_add_negative - add and test if negative
6393 diff --git a/arch/mips/include/asm/cache.h b/arch/mips/include/asm/cache.h
6394 index b4db69f..8f3b093 100644
6395 --- a/arch/mips/include/asm/cache.h
6396 +++ b/arch/mips/include/asm/cache.h
6397 @@ -9,10 +9,11 @@
6398 #ifndef _ASM_CACHE_H
6399 #define _ASM_CACHE_H
6400
6401 +#include <linux/const.h>
6402 #include <kmalloc.h>
6403
6404 #define L1_CACHE_SHIFT CONFIG_MIPS_L1_CACHE_SHIFT
6405 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
6406 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
6407
6408 #define SMP_CACHE_SHIFT L1_CACHE_SHIFT
6409 #define SMP_CACHE_BYTES L1_CACHE_BYTES
6410 diff --git a/arch/mips/include/asm/elf.h b/arch/mips/include/asm/elf.h
6411 index a66359e..d3d474a 100644
6412 --- a/arch/mips/include/asm/elf.h
6413 +++ b/arch/mips/include/asm/elf.h
6414 @@ -373,13 +373,16 @@ extern const char *__elf_platform;
6415 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
6416 #endif
6417
6418 +#ifdef CONFIG_PAX_ASLR
6419 +#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
6420 +
6421 +#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6422 +#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6423 +#endif
6424 +
6425 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
6426 struct linux_binprm;
6427 extern int arch_setup_additional_pages(struct linux_binprm *bprm,
6428 int uses_interp);
6429
6430 -struct mm_struct;
6431 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
6432 -#define arch_randomize_brk arch_randomize_brk
6433 -
6434 #endif /* _ASM_ELF_H */
6435 diff --git a/arch/mips/include/asm/exec.h b/arch/mips/include/asm/exec.h
6436 index c1f6afa..38cc6e9 100644
6437 --- a/arch/mips/include/asm/exec.h
6438 +++ b/arch/mips/include/asm/exec.h
6439 @@ -12,6 +12,6 @@
6440 #ifndef _ASM_EXEC_H
6441 #define _ASM_EXEC_H
6442
6443 -extern unsigned long arch_align_stack(unsigned long sp);
6444 +#define arch_align_stack(x) ((x) & ~0xfUL)
6445
6446 #endif /* _ASM_EXEC_H */
6447 diff --git a/arch/mips/include/asm/ftrace.h b/arch/mips/include/asm/ftrace.h
6448 index ce35c9a..434321c 100644
6449 --- a/arch/mips/include/asm/ftrace.h
6450 +++ b/arch/mips/include/asm/ftrace.h
6451 @@ -22,12 +22,12 @@ extern void _mcount(void);
6452 #define safe_load(load, src, dst, error) \
6453 do { \
6454 asm volatile ( \
6455 - "1: " load " %[" STR(dst) "], 0(%[" STR(src) "])\n"\
6456 - " li %[" STR(error) "], 0\n" \
6457 + "1: " load " %[dest], 0(%[source])\n" \
6458 + " li %[err], 0\n" \
6459 "2:\n" \
6460 \
6461 ".section .fixup, \"ax\"\n" \
6462 - "3: li %[" STR(error) "], 1\n" \
6463 + "3: li %[err], 1\n" \
6464 " j 2b\n" \
6465 ".previous\n" \
6466 \
6467 @@ -35,8 +35,8 @@ do { \
6468 STR(PTR) "\t1b, 3b\n\t" \
6469 ".previous\n" \
6470 \
6471 - : [dst] "=&r" (dst), [error] "=r" (error)\
6472 - : [src] "r" (src) \
6473 + : [dest] "=&r" (dst), [err] "=r" (error)\
6474 + : [source] "r" (src) \
6475 : "memory" \
6476 ); \
6477 } while (0)
6478 @@ -44,12 +44,12 @@ do { \
6479 #define safe_store(store, src, dst, error) \
6480 do { \
6481 asm volatile ( \
6482 - "1: " store " %[" STR(src) "], 0(%[" STR(dst) "])\n"\
6483 - " li %[" STR(error) "], 0\n" \
6484 + "1: " store " %[source], 0(%[dest])\n"\
6485 + " li %[err], 0\n" \
6486 "2:\n" \
6487 \
6488 ".section .fixup, \"ax\"\n" \
6489 - "3: li %[" STR(error) "], 1\n" \
6490 + "3: li %[err], 1\n" \
6491 " j 2b\n" \
6492 ".previous\n" \
6493 \
6494 @@ -57,8 +57,8 @@ do { \
6495 STR(PTR) "\t1b, 3b\n\t" \
6496 ".previous\n" \
6497 \
6498 - : [error] "=r" (error) \
6499 - : [dst] "r" (dst), [src] "r" (src)\
6500 + : [err] "=r" (error) \
6501 + : [dest] "r" (dst), [source] "r" (src)\
6502 : "memory" \
6503 ); \
6504 } while (0)
6505 diff --git a/arch/mips/include/asm/hw_irq.h b/arch/mips/include/asm/hw_irq.h
6506 index 9e8ef59..1139d6b 100644
6507 --- a/arch/mips/include/asm/hw_irq.h
6508 +++ b/arch/mips/include/asm/hw_irq.h
6509 @@ -10,7 +10,7 @@
6510
6511 #include <linux/atomic.h>
6512
6513 -extern atomic_t irq_err_count;
6514 +extern atomic_unchecked_t irq_err_count;
6515
6516 /*
6517 * interrupt-retrigger: NOP for now. This may not be appropriate for all
6518 diff --git a/arch/mips/include/asm/local.h b/arch/mips/include/asm/local.h
6519 index d44622c..64990d2 100644
6520 --- a/arch/mips/include/asm/local.h
6521 +++ b/arch/mips/include/asm/local.h
6522 @@ -12,15 +12,25 @@ typedef struct
6523 atomic_long_t a;
6524 } local_t;
6525
6526 +typedef struct {
6527 + atomic_long_unchecked_t a;
6528 +} local_unchecked_t;
6529 +
6530 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
6531
6532 #define local_read(l) atomic_long_read(&(l)->a)
6533 +#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
6534 #define local_set(l, i) atomic_long_set(&(l)->a, (i))
6535 +#define local_set_unchecked(l, i) atomic_long_set_unchecked(&(l)->a, (i))
6536
6537 #define local_add(i, l) atomic_long_add((i), (&(l)->a))
6538 +#define local_add_unchecked(i, l) atomic_long_add_unchecked((i), (&(l)->a))
6539 #define local_sub(i, l) atomic_long_sub((i), (&(l)->a))
6540 +#define local_sub_unchecked(i, l) atomic_long_sub_unchecked((i), (&(l)->a))
6541 #define local_inc(l) atomic_long_inc(&(l)->a)
6542 +#define local_inc_unchecked(l) atomic_long_inc_unchecked(&(l)->a)
6543 #define local_dec(l) atomic_long_dec(&(l)->a)
6544 +#define local_dec_unchecked(l) atomic_long_dec_unchecked(&(l)->a)
6545
6546 /*
6547 * Same as above, but return the result value
6548 @@ -70,6 +80,51 @@ static __inline__ long local_add_return(long i, local_t * l)
6549 return result;
6550 }
6551
6552 +static __inline__ long local_add_return_unchecked(long i, local_unchecked_t * l)
6553 +{
6554 + unsigned long result;
6555 +
6556 + if (kernel_uses_llsc && R10000_LLSC_WAR) {
6557 + unsigned long temp;
6558 +
6559 + __asm__ __volatile__(
6560 + " .set mips3 \n"
6561 + "1:" __LL "%1, %2 # local_add_return \n"
6562 + " addu %0, %1, %3 \n"
6563 + __SC "%0, %2 \n"
6564 + " beqzl %0, 1b \n"
6565 + " addu %0, %1, %3 \n"
6566 + " .set mips0 \n"
6567 + : "=&r" (result), "=&r" (temp), "=m" (l->a.counter)
6568 + : "Ir" (i), "m" (l->a.counter)
6569 + : "memory");
6570 + } else if (kernel_uses_llsc) {
6571 + unsigned long temp;
6572 +
6573 + __asm__ __volatile__(
6574 + " .set mips3 \n"
6575 + "1:" __LL "%1, %2 # local_add_return \n"
6576 + " addu %0, %1, %3 \n"
6577 + __SC "%0, %2 \n"
6578 + " beqz %0, 1b \n"
6579 + " addu %0, %1, %3 \n"
6580 + " .set mips0 \n"
6581 + : "=&r" (result), "=&r" (temp), "=m" (l->a.counter)
6582 + : "Ir" (i), "m" (l->a.counter)
6583 + : "memory");
6584 + } else {
6585 + unsigned long flags;
6586 +
6587 + local_irq_save(flags);
6588 + result = l->a.counter;
6589 + result += i;
6590 + l->a.counter = result;
6591 + local_irq_restore(flags);
6592 + }
6593 +
6594 + return result;
6595 +}
6596 +
6597 static __inline__ long local_sub_return(long i, local_t * l)
6598 {
6599 unsigned long result;
6600 @@ -117,6 +172,8 @@ static __inline__ long local_sub_return(long i, local_t * l)
6601
6602 #define local_cmpxchg(l, o, n) \
6603 ((long)cmpxchg_local(&((l)->a.counter), (o), (n)))
6604 +#define local_cmpxchg_unchecked(l, o, n) \
6605 + ((long)cmpxchg_local(&((l)->a.counter), (o), (n)))
6606 #define local_xchg(l, n) (atomic_long_xchg((&(l)->a), (n)))
6607
6608 /**
6609 diff --git a/arch/mips/include/asm/page.h b/arch/mips/include/asm/page.h
6610 index f6be474..12ad554 100644
6611 --- a/arch/mips/include/asm/page.h
6612 +++ b/arch/mips/include/asm/page.h
6613 @@ -95,7 +95,7 @@ extern void copy_user_highpage(struct page *to, struct page *from,
6614 #ifdef CONFIG_CPU_MIPS32
6615 typedef struct { unsigned long pte_low, pte_high; } pte_t;
6616 #define pte_val(x) ((x).pte_low | ((unsigned long long)(x).pte_high << 32))
6617 - #define __pte(x) ({ pte_t __pte = {(x), ((unsigned long long)(x)) >> 32}; __pte; })
6618 + #define __pte(x) ({ pte_t __pte = {(x), (x) >> 32}; __pte; })
6619 #else
6620 typedef struct { unsigned long long pte; } pte_t;
6621 #define pte_val(x) ((x).pte)
6622 diff --git a/arch/mips/include/asm/pgalloc.h b/arch/mips/include/asm/pgalloc.h
6623 index b336037..5b874cc 100644
6624 --- a/arch/mips/include/asm/pgalloc.h
6625 +++ b/arch/mips/include/asm/pgalloc.h
6626 @@ -37,6 +37,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
6627 {
6628 set_pud(pud, __pud((unsigned long)pmd));
6629 }
6630 +
6631 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
6632 +{
6633 + pud_populate(mm, pud, pmd);
6634 +}
6635 #endif
6636
6637 /*
6638 diff --git a/arch/mips/include/asm/pgtable.h b/arch/mips/include/asm/pgtable.h
6639 index 008324d..f67c239 100644
6640 --- a/arch/mips/include/asm/pgtable.h
6641 +++ b/arch/mips/include/asm/pgtable.h
6642 @@ -20,6 +20,9 @@
6643 #include <asm/io.h>
6644 #include <asm/pgtable-bits.h>
6645
6646 +#define ktla_ktva(addr) (addr)
6647 +#define ktva_ktla(addr) (addr)
6648 +
6649 struct mm_struct;
6650 struct vm_area_struct;
6651
6652 diff --git a/arch/mips/include/asm/smtc_proc.h b/arch/mips/include/asm/smtc_proc.h
6653 index 25da651..ae2a259 100644
6654 --- a/arch/mips/include/asm/smtc_proc.h
6655 +++ b/arch/mips/include/asm/smtc_proc.h
6656 @@ -18,6 +18,6 @@ extern struct smtc_cpu_proc smtc_cpu_stats[NR_CPUS];
6657
6658 /* Count of number of recoveries of "stolen" FPU access rights on 34K */
6659
6660 -extern atomic_t smtc_fpu_recoveries;
6661 +extern atomic_unchecked_t smtc_fpu_recoveries;
6662
6663 #endif /* __ASM_SMTC_PROC_H */
6664 diff --git a/arch/mips/include/asm/syscall.h b/arch/mips/include/asm/syscall.h
6665 index 33e8dbf..81d8432 100644
6666 --- a/arch/mips/include/asm/syscall.h
6667 +++ b/arch/mips/include/asm/syscall.h
6668 @@ -39,14 +39,14 @@ static inline unsigned long mips_get_syscall_arg(unsigned long *arg,
6669
6670 #ifdef CONFIG_32BIT
6671 case 4: case 5: case 6: case 7:
6672 - return get_user(*arg, (int *)usp + 4 * n);
6673 + return get_user(*arg, (int *)usp + n);
6674 #endif
6675
6676 #ifdef CONFIG_64BIT
6677 case 4: case 5: case 6: case 7:
6678 #ifdef CONFIG_MIPS32_O32
6679 if (test_thread_flag(TIF_32BIT_REGS))
6680 - return get_user(*arg, (int *)usp + 4 * n);
6681 + return get_user(*arg, (int *)usp + n);
6682 else
6683 #endif
6684 *arg = regs->regs[4 + n];
6685 @@ -83,11 +83,10 @@ static inline void syscall_get_arguments(struct task_struct *task,
6686 unsigned int i, unsigned int n,
6687 unsigned long *args)
6688 {
6689 - unsigned long arg;
6690 int ret;
6691
6692 while (n--)
6693 - ret |= mips_get_syscall_arg(&arg, task, regs, i++);
6694 + ret |= mips_get_syscall_arg(args++, task, regs, i++);
6695
6696 /*
6697 * No way to communicate an error because this is a void function.
6698 diff --git a/arch/mips/include/asm/thread_info.h b/arch/mips/include/asm/thread_info.h
6699 index 4f58ef6..5e7081b 100644
6700 --- a/arch/mips/include/asm/thread_info.h
6701 +++ b/arch/mips/include/asm/thread_info.h
6702 @@ -115,6 +115,8 @@ static inline struct thread_info *current_thread_info(void)
6703 #define TIF_FPUBOUND 24 /* thread bound to FPU-full CPU set */
6704 #define TIF_LOAD_WATCH 25 /* If set, load watch registers */
6705 #define TIF_SYSCALL_TRACEPOINT 26 /* syscall tracepoint instrumentation */
6706 +/* li takes a 32bit immediate */
6707 +#define TIF_GRSEC_SETXID 29 /* update credentials on syscall entry/exit */
6708 #define TIF_SYSCALL_TRACE 31 /* syscall trace active */
6709
6710 #define _TIF_SYSCALL_TRACE (1<<TIF_SYSCALL_TRACE)
6711 @@ -132,13 +134,14 @@ static inline struct thread_info *current_thread_info(void)
6712 #define _TIF_FPUBOUND (1<<TIF_FPUBOUND)
6713 #define _TIF_LOAD_WATCH (1<<TIF_LOAD_WATCH)
6714 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
6715 +#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
6716
6717 #define _TIF_WORK_SYSCALL_ENTRY (_TIF_NOHZ | _TIF_SYSCALL_TRACE | \
6718 - _TIF_SYSCALL_AUDIT | _TIF_SYSCALL_TRACEPOINT)
6719 + _TIF_SYSCALL_AUDIT | _TIF_SYSCALL_TRACEPOINT | _TIF_GRSEC_SETXID)
6720
6721 /* work to do in syscall_trace_leave() */
6722 #define _TIF_WORK_SYSCALL_EXIT (_TIF_NOHZ | _TIF_SYSCALL_TRACE | \
6723 - _TIF_SYSCALL_AUDIT | _TIF_SYSCALL_TRACEPOINT)
6724 + _TIF_SYSCALL_AUDIT | _TIF_SYSCALL_TRACEPOINT | _TIF_GRSEC_SETXID)
6725
6726 /* work to do on interrupt/exception return */
6727 #define _TIF_WORK_MASK \
6728 @@ -146,7 +149,7 @@ static inline struct thread_info *current_thread_info(void)
6729 /* work to do on any return to u-space */
6730 #define _TIF_ALLWORK_MASK (_TIF_NOHZ | _TIF_WORK_MASK | \
6731 _TIF_WORK_SYSCALL_EXIT | \
6732 - _TIF_SYSCALL_TRACEPOINT)
6733 + _TIF_SYSCALL_TRACEPOINT | _TIF_GRSEC_SETXID)
6734
6735 /*
6736 * We stash processor id into a COP0 register to retrieve it fast
6737 diff --git a/arch/mips/include/asm/uaccess.h b/arch/mips/include/asm/uaccess.h
6738 index f3fa375..3af6637 100644
6739 --- a/arch/mips/include/asm/uaccess.h
6740 +++ b/arch/mips/include/asm/uaccess.h
6741 @@ -128,6 +128,7 @@ extern u64 __ua_limit;
6742 __ok == 0; \
6743 })
6744
6745 +#define access_ok_noprefault(type, addr, size) access_ok((type), (addr), (size))
6746 #define access_ok(type, addr, size) \
6747 likely(__access_ok((addr), (size), __access_mask))
6748
6749 diff --git a/arch/mips/kernel/binfmt_elfn32.c b/arch/mips/kernel/binfmt_elfn32.c
6750 index 1188e00..41cf144 100644
6751 --- a/arch/mips/kernel/binfmt_elfn32.c
6752 +++ b/arch/mips/kernel/binfmt_elfn32.c
6753 @@ -50,6 +50,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
6754 #undef ELF_ET_DYN_BASE
6755 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
6756
6757 +#ifdef CONFIG_PAX_ASLR
6758 +#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
6759 +
6760 +#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6761 +#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6762 +#endif
6763 +
6764 #include <asm/processor.h>
6765 #include <linux/module.h>
6766 #include <linux/elfcore.h>
6767 diff --git a/arch/mips/kernel/binfmt_elfo32.c b/arch/mips/kernel/binfmt_elfo32.c
6768 index 202e581..689ca79 100644
6769 --- a/arch/mips/kernel/binfmt_elfo32.c
6770 +++ b/arch/mips/kernel/binfmt_elfo32.c
6771 @@ -56,6 +56,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
6772 #undef ELF_ET_DYN_BASE
6773 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
6774
6775 +#ifdef CONFIG_PAX_ASLR
6776 +#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
6777 +
6778 +#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6779 +#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6780 +#endif
6781 +
6782 #include <asm/processor.h>
6783
6784 /*
6785 diff --git a/arch/mips/kernel/ftrace.c b/arch/mips/kernel/ftrace.c
6786 index 185ba25..374ed74 100644
6787 --- a/arch/mips/kernel/ftrace.c
6788 +++ b/arch/mips/kernel/ftrace.c
6789 @@ -111,11 +111,10 @@ static int ftrace_modify_code_2(unsigned long ip, unsigned int new_code1,
6790 safe_store_code(new_code1, ip, faulted);
6791 if (unlikely(faulted))
6792 return -EFAULT;
6793 - ip += 4;
6794 - safe_store_code(new_code2, ip, faulted);
6795 + safe_store_code(new_code2, ip + 4, faulted);
6796 if (unlikely(faulted))
6797 return -EFAULT;
6798 - flush_icache_range(ip, ip + 8); /* original ip + 12 */
6799 + flush_icache_range(ip, ip + 8);
6800 return 0;
6801 }
6802 #endif
6803 diff --git a/arch/mips/kernel/i8259.c b/arch/mips/kernel/i8259.c
6804 index 2b91fe8..fe4f6b4 100644
6805 --- a/arch/mips/kernel/i8259.c
6806 +++ b/arch/mips/kernel/i8259.c
6807 @@ -205,7 +205,7 @@ spurious_8259A_irq:
6808 printk(KERN_DEBUG "spurious 8259A interrupt: IRQ%d.\n", irq);
6809 spurious_irq_mask |= irqmask;
6810 }
6811 - atomic_inc(&irq_err_count);
6812 + atomic_inc_unchecked(&irq_err_count);
6813 /*
6814 * Theoretically we do not have to handle this IRQ,
6815 * but in Linux this does not cause problems and is
6816 diff --git a/arch/mips/kernel/irq-gt641xx.c b/arch/mips/kernel/irq-gt641xx.c
6817 index 44a1f79..2bd6aa3 100644
6818 --- a/arch/mips/kernel/irq-gt641xx.c
6819 +++ b/arch/mips/kernel/irq-gt641xx.c
6820 @@ -110,7 +110,7 @@ void gt641xx_irq_dispatch(void)
6821 }
6822 }
6823
6824 - atomic_inc(&irq_err_count);
6825 + atomic_inc_unchecked(&irq_err_count);
6826 }
6827
6828 void __init gt641xx_irq_init(void)
6829 diff --git a/arch/mips/kernel/irq.c b/arch/mips/kernel/irq.c
6830 index d1fea7a..45602ea 100644
6831 --- a/arch/mips/kernel/irq.c
6832 +++ b/arch/mips/kernel/irq.c
6833 @@ -77,17 +77,17 @@ void ack_bad_irq(unsigned int irq)
6834 printk("unexpected IRQ # %d\n", irq);
6835 }
6836
6837 -atomic_t irq_err_count;
6838 +atomic_unchecked_t irq_err_count;
6839
6840 int arch_show_interrupts(struct seq_file *p, int prec)
6841 {
6842 - seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read(&irq_err_count));
6843 + seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read_unchecked(&irq_err_count));
6844 return 0;
6845 }
6846
6847 asmlinkage void spurious_interrupt(void)
6848 {
6849 - atomic_inc(&irq_err_count);
6850 + atomic_inc_unchecked(&irq_err_count);
6851 }
6852
6853 void __init init_IRQ(void)
6854 diff --git a/arch/mips/kernel/process.c b/arch/mips/kernel/process.c
6855 index ddc7610..8c58f17 100644
6856 --- a/arch/mips/kernel/process.c
6857 +++ b/arch/mips/kernel/process.c
6858 @@ -566,15 +566,3 @@ unsigned long get_wchan(struct task_struct *task)
6859 out:
6860 return pc;
6861 }
6862 -
6863 -/*
6864 - * Don't forget that the stack pointer must be aligned on a 8 bytes
6865 - * boundary for 32-bits ABI and 16 bytes for 64-bits ABI.
6866 - */
6867 -unsigned long arch_align_stack(unsigned long sp)
6868 -{
6869 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
6870 - sp -= get_random_int() & ~PAGE_MASK;
6871 -
6872 - return sp & ALMASK;
6873 -}
6874 diff --git a/arch/mips/kernel/ptrace.c b/arch/mips/kernel/ptrace.c
6875 index b52e1d2..1a3ca09 100644
6876 --- a/arch/mips/kernel/ptrace.c
6877 +++ b/arch/mips/kernel/ptrace.c
6878 @@ -652,6 +652,10 @@ long arch_ptrace(struct task_struct *child, long request,
6879 return ret;
6880 }
6881
6882 +#ifdef CONFIG_GRKERNSEC_SETXID
6883 +extern void gr_delayed_cred_worker(void);
6884 +#endif
6885 +
6886 /*
6887 * Notification of system call entry/exit
6888 * - triggered by current->work.syscall_trace
6889 @@ -668,6 +672,11 @@ asmlinkage void syscall_trace_enter(struct pt_regs *regs)
6890 tracehook_report_syscall_entry(regs))
6891 ret = -1;
6892
6893 +#ifdef CONFIG_GRKERNSEC_SETXID
6894 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
6895 + gr_delayed_cred_worker();
6896 +#endif
6897 +
6898 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
6899 trace_sys_enter(regs, regs->regs[2]);
6900
6901 diff --git a/arch/mips/kernel/reset.c b/arch/mips/kernel/reset.c
6902 index 07fc524..b9d7f28 100644
6903 --- a/arch/mips/kernel/reset.c
6904 +++ b/arch/mips/kernel/reset.c
6905 @@ -13,6 +13,7 @@
6906 #include <linux/reboot.h>
6907
6908 #include <asm/reboot.h>
6909 +#include <asm/bug.h>
6910
6911 /*
6912 * Urgs ... Too many MIPS machines to handle this in a generic way.
6913 @@ -29,16 +30,19 @@ void machine_restart(char *command)
6914 {
6915 if (_machine_restart)
6916 _machine_restart(command);
6917 + BUG();
6918 }
6919
6920 void machine_halt(void)
6921 {
6922 if (_machine_halt)
6923 _machine_halt();
6924 + BUG();
6925 }
6926
6927 void machine_power_off(void)
6928 {
6929 if (pm_power_off)
6930 pm_power_off();
6931 + BUG();
6932 }
6933 diff --git a/arch/mips/kernel/smtc-proc.c b/arch/mips/kernel/smtc-proc.c
6934 index c10aa84..9ec2e60 100644
6935 --- a/arch/mips/kernel/smtc-proc.c
6936 +++ b/arch/mips/kernel/smtc-proc.c
6937 @@ -31,7 +31,7 @@ unsigned long selfipis[NR_CPUS];
6938
6939 struct smtc_cpu_proc smtc_cpu_stats[NR_CPUS];
6940
6941 -atomic_t smtc_fpu_recoveries;
6942 +atomic_unchecked_t smtc_fpu_recoveries;
6943
6944 static int smtc_proc_show(struct seq_file *m, void *v)
6945 {
6946 @@ -48,7 +48,7 @@ static int smtc_proc_show(struct seq_file *m, void *v)
6947 for(i = 0; i < NR_CPUS; i++)
6948 seq_printf(m, "%d: %ld\n", i, smtc_cpu_stats[i].selfipis);
6949 seq_printf(m, "%d Recoveries of \"stolen\" FPU\n",
6950 - atomic_read(&smtc_fpu_recoveries));
6951 + atomic_read_unchecked(&smtc_fpu_recoveries));
6952 return 0;
6953 }
6954
6955 @@ -73,7 +73,7 @@ void init_smtc_stats(void)
6956 smtc_cpu_stats[i].selfipis = 0;
6957 }
6958
6959 - atomic_set(&smtc_fpu_recoveries, 0);
6960 + atomic_set_unchecked(&smtc_fpu_recoveries, 0);
6961
6962 proc_create("smtc", 0444, NULL, &smtc_proc_fops);
6963 }
6964 diff --git a/arch/mips/kernel/smtc.c b/arch/mips/kernel/smtc.c
6965 index dfc1b91..11a2c07 100644
6966 --- a/arch/mips/kernel/smtc.c
6967 +++ b/arch/mips/kernel/smtc.c
6968 @@ -1359,7 +1359,7 @@ void smtc_soft_dump(void)
6969 }
6970 smtc_ipi_qdump();
6971 printk("%d Recoveries of \"stolen\" FPU\n",
6972 - atomic_read(&smtc_fpu_recoveries));
6973 + atomic_read_unchecked(&smtc_fpu_recoveries));
6974 }
6975
6976
6977 diff --git a/arch/mips/kernel/sync-r4k.c b/arch/mips/kernel/sync-r4k.c
6978 index 84536bf..79caa4d 100644
6979 --- a/arch/mips/kernel/sync-r4k.c
6980 +++ b/arch/mips/kernel/sync-r4k.c
6981 @@ -21,8 +21,8 @@
6982 #include <asm/mipsregs.h>
6983
6984 static atomic_t count_start_flag = ATOMIC_INIT(0);
6985 -static atomic_t count_count_start = ATOMIC_INIT(0);
6986 -static atomic_t count_count_stop = ATOMIC_INIT(0);
6987 +static atomic_unchecked_t count_count_start = ATOMIC_INIT(0);
6988 +static atomic_unchecked_t count_count_stop = ATOMIC_INIT(0);
6989 static atomic_t count_reference = ATOMIC_INIT(0);
6990
6991 #define COUNTON 100
6992 @@ -69,13 +69,13 @@ void synchronise_count_master(int cpu)
6993
6994 for (i = 0; i < NR_LOOPS; i++) {
6995 /* slaves loop on '!= 2' */
6996 - while (atomic_read(&count_count_start) != 1)
6997 + while (atomic_read_unchecked(&count_count_start) != 1)
6998 mb();
6999 - atomic_set(&count_count_stop, 0);
7000 + atomic_set_unchecked(&count_count_stop, 0);
7001 smp_wmb();
7002
7003 /* this lets the slaves write their count register */
7004 - atomic_inc(&count_count_start);
7005 + atomic_inc_unchecked(&count_count_start);
7006
7007 /*
7008 * Everyone initialises count in the last loop:
7009 @@ -86,11 +86,11 @@ void synchronise_count_master(int cpu)
7010 /*
7011 * Wait for all slaves to leave the synchronization point:
7012 */
7013 - while (atomic_read(&count_count_stop) != 1)
7014 + while (atomic_read_unchecked(&count_count_stop) != 1)
7015 mb();
7016 - atomic_set(&count_count_start, 0);
7017 + atomic_set_unchecked(&count_count_start, 0);
7018 smp_wmb();
7019 - atomic_inc(&count_count_stop);
7020 + atomic_inc_unchecked(&count_count_stop);
7021 }
7022 /* Arrange for an interrupt in a short while */
7023 write_c0_compare(read_c0_count() + COUNTON);
7024 @@ -131,8 +131,8 @@ void synchronise_count_slave(int cpu)
7025 initcount = atomic_read(&count_reference);
7026
7027 for (i = 0; i < NR_LOOPS; i++) {
7028 - atomic_inc(&count_count_start);
7029 - while (atomic_read(&count_count_start) != 2)
7030 + atomic_inc_unchecked(&count_count_start);
7031 + while (atomic_read_unchecked(&count_count_start) != 2)
7032 mb();
7033
7034 /*
7035 @@ -141,8 +141,8 @@ void synchronise_count_slave(int cpu)
7036 if (i == NR_LOOPS-1)
7037 write_c0_count(initcount);
7038
7039 - atomic_inc(&count_count_stop);
7040 - while (atomic_read(&count_count_stop) != 2)
7041 + atomic_inc_unchecked(&count_count_stop);
7042 + while (atomic_read_unchecked(&count_count_stop) != 2)
7043 mb();
7044 }
7045 /* Arrange for an interrupt in a short while */
7046 diff --git a/arch/mips/kernel/traps.c b/arch/mips/kernel/traps.c
7047 index f9c8746..78b64e3 100644
7048 --- a/arch/mips/kernel/traps.c
7049 +++ b/arch/mips/kernel/traps.c
7050 @@ -690,7 +690,18 @@ asmlinkage void do_ov(struct pt_regs *regs)
7051 siginfo_t info;
7052
7053 prev_state = exception_enter();
7054 - die_if_kernel("Integer overflow", regs);
7055 + if (unlikely(!user_mode(regs))) {
7056 +
7057 +#ifdef CONFIG_PAX_REFCOUNT
7058 + if (fixup_exception(regs)) {
7059 + pax_report_refcount_overflow(regs);
7060 + exception_exit(prev_state);
7061 + return;
7062 + }
7063 +#endif
7064 +
7065 + die("Integer overflow", regs);
7066 + }
7067
7068 info.si_code = FPE_INTOVF;
7069 info.si_signo = SIGFPE;
7070 diff --git a/arch/mips/mm/fault.c b/arch/mips/mm/fault.c
7071 index becc42b..9e43d4b 100644
7072 --- a/arch/mips/mm/fault.c
7073 +++ b/arch/mips/mm/fault.c
7074 @@ -28,6 +28,23 @@
7075 #include <asm/highmem.h> /* For VMALLOC_END */
7076 #include <linux/kdebug.h>
7077
7078 +#ifdef CONFIG_PAX_PAGEEXEC
7079 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
7080 +{
7081 + unsigned long i;
7082 +
7083 + printk(KERN_ERR "PAX: bytes at PC: ");
7084 + for (i = 0; i < 5; i++) {
7085 + unsigned int c;
7086 + if (get_user(c, (unsigned int *)pc+i))
7087 + printk(KERN_CONT "???????? ");
7088 + else
7089 + printk(KERN_CONT "%08x ", c);
7090 + }
7091 + printk("\n");
7092 +}
7093 +#endif
7094 +
7095 /*
7096 * This routine handles page faults. It determines the address,
7097 * and the problem, and then passes it off to one of the appropriate
7098 @@ -199,6 +216,14 @@ bad_area:
7099 bad_area_nosemaphore:
7100 /* User mode accesses just cause a SIGSEGV */
7101 if (user_mode(regs)) {
7102 +
7103 +#ifdef CONFIG_PAX_PAGEEXEC
7104 + if (cpu_has_rixi && (mm->pax_flags & MF_PAX_PAGEEXEC) && !write && address == instruction_pointer(regs)) {
7105 + pax_report_fault(regs, (void *)address, (void *)user_stack_pointer(regs));
7106 + do_group_exit(SIGKILL);
7107 + }
7108 +#endif
7109 +
7110 tsk->thread.cp0_badvaddr = address;
7111 tsk->thread.error_code = write;
7112 #if 0
7113 diff --git a/arch/mips/mm/mmap.c b/arch/mips/mm/mmap.c
7114 index f1baadd..5472dca 100644
7115 --- a/arch/mips/mm/mmap.c
7116 +++ b/arch/mips/mm/mmap.c
7117 @@ -59,6 +59,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
7118 struct vm_area_struct *vma;
7119 unsigned long addr = addr0;
7120 int do_color_align;
7121 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
7122 struct vm_unmapped_area_info info;
7123
7124 if (unlikely(len > TASK_SIZE))
7125 @@ -84,6 +85,11 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
7126 do_color_align = 1;
7127
7128 /* requesting a specific address */
7129 +
7130 +#ifdef CONFIG_PAX_RANDMMAP
7131 + if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
7132 +#endif
7133 +
7134 if (addr) {
7135 if (do_color_align)
7136 addr = COLOUR_ALIGN(addr, pgoff);
7137 @@ -91,14 +97,14 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
7138 addr = PAGE_ALIGN(addr);
7139
7140 vma = find_vma(mm, addr);
7141 - if (TASK_SIZE - len >= addr &&
7142 - (!vma || addr + len <= vma->vm_start))
7143 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
7144 return addr;
7145 }
7146
7147 info.length = len;
7148 info.align_mask = do_color_align ? (PAGE_MASK & shm_align_mask) : 0;
7149 info.align_offset = pgoff << PAGE_SHIFT;
7150 + info.threadstack_offset = offset;
7151
7152 if (dir == DOWN) {
7153 info.flags = VM_UNMAPPED_AREA_TOPDOWN;
7154 @@ -146,6 +152,10 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
7155 {
7156 unsigned long random_factor = 0UL;
7157
7158 +#ifdef CONFIG_PAX_RANDMMAP
7159 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
7160 +#endif
7161 +
7162 if (current->flags & PF_RANDOMIZE) {
7163 random_factor = get_random_int();
7164 random_factor = random_factor << PAGE_SHIFT;
7165 @@ -157,40 +167,25 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
7166
7167 if (mmap_is_legacy()) {
7168 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
7169 +
7170 +#ifdef CONFIG_PAX_RANDMMAP
7171 + if (mm->pax_flags & MF_PAX_RANDMMAP)
7172 + mm->mmap_base += mm->delta_mmap;
7173 +#endif
7174 +
7175 mm->get_unmapped_area = arch_get_unmapped_area;
7176 } else {
7177 mm->mmap_base = mmap_base(random_factor);
7178 +
7179 +#ifdef CONFIG_PAX_RANDMMAP
7180 + if (mm->pax_flags & MF_PAX_RANDMMAP)
7181 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
7182 +#endif
7183 +
7184 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
7185 }
7186 }
7187
7188 -static inline unsigned long brk_rnd(void)
7189 -{
7190 - unsigned long rnd = get_random_int();
7191 -
7192 - rnd = rnd << PAGE_SHIFT;
7193 - /* 8MB for 32bit, 256MB for 64bit */
7194 - if (TASK_IS_32BIT_ADDR)
7195 - rnd = rnd & 0x7ffffful;
7196 - else
7197 - rnd = rnd & 0xffffffful;
7198 -
7199 - return rnd;
7200 -}
7201 -
7202 -unsigned long arch_randomize_brk(struct mm_struct *mm)
7203 -{
7204 - unsigned long base = mm->brk;
7205 - unsigned long ret;
7206 -
7207 - ret = PAGE_ALIGN(base + brk_rnd());
7208 -
7209 - if (ret < mm->brk)
7210 - return mm->brk;
7211 -
7212 - return ret;
7213 -}
7214 -
7215 int __virt_addr_valid(const volatile void *kaddr)
7216 {
7217 return pfn_valid(PFN_DOWN(virt_to_phys(kaddr)));
7218 diff --git a/arch/mips/pci/pci-octeon.c b/arch/mips/pci/pci-octeon.c
7219 index 59cccd9..f39ac2f 100644
7220 --- a/arch/mips/pci/pci-octeon.c
7221 +++ b/arch/mips/pci/pci-octeon.c
7222 @@ -327,8 +327,8 @@ static int octeon_write_config(struct pci_bus *bus, unsigned int devfn,
7223
7224
7225 static struct pci_ops octeon_pci_ops = {
7226 - octeon_read_config,
7227 - octeon_write_config,
7228 + .read = octeon_read_config,
7229 + .write = octeon_write_config,
7230 };
7231
7232 static struct resource octeon_pci_mem_resource = {
7233 diff --git a/arch/mips/pci/pcie-octeon.c b/arch/mips/pci/pcie-octeon.c
7234 index 5e36c33..eb4a17b 100644
7235 --- a/arch/mips/pci/pcie-octeon.c
7236 +++ b/arch/mips/pci/pcie-octeon.c
7237 @@ -1792,8 +1792,8 @@ static int octeon_dummy_write_config(struct pci_bus *bus, unsigned int devfn,
7238 }
7239
7240 static struct pci_ops octeon_pcie0_ops = {
7241 - octeon_pcie0_read_config,
7242 - octeon_pcie0_write_config,
7243 + .read = octeon_pcie0_read_config,
7244 + .write = octeon_pcie0_write_config,
7245 };
7246
7247 static struct resource octeon_pcie0_mem_resource = {
7248 @@ -1813,8 +1813,8 @@ static struct pci_controller octeon_pcie0_controller = {
7249 };
7250
7251 static struct pci_ops octeon_pcie1_ops = {
7252 - octeon_pcie1_read_config,
7253 - octeon_pcie1_write_config,
7254 + .read = octeon_pcie1_read_config,
7255 + .write = octeon_pcie1_write_config,
7256 };
7257
7258 static struct resource octeon_pcie1_mem_resource = {
7259 @@ -1834,8 +1834,8 @@ static struct pci_controller octeon_pcie1_controller = {
7260 };
7261
7262 static struct pci_ops octeon_dummy_ops = {
7263 - octeon_dummy_read_config,
7264 - octeon_dummy_write_config,
7265 + .read = octeon_dummy_read_config,
7266 + .write = octeon_dummy_write_config,
7267 };
7268
7269 static struct resource octeon_dummy_mem_resource = {
7270 diff --git a/arch/mips/sgi-ip27/ip27-nmi.c b/arch/mips/sgi-ip27/ip27-nmi.c
7271 index a2358b4..7cead4f 100644
7272 --- a/arch/mips/sgi-ip27/ip27-nmi.c
7273 +++ b/arch/mips/sgi-ip27/ip27-nmi.c
7274 @@ -187,9 +187,9 @@ void
7275 cont_nmi_dump(void)
7276 {
7277 #ifndef REAL_NMI_SIGNAL
7278 - static atomic_t nmied_cpus = ATOMIC_INIT(0);
7279 + static atomic_unchecked_t nmied_cpus = ATOMIC_INIT(0);
7280
7281 - atomic_inc(&nmied_cpus);
7282 + atomic_inc_unchecked(&nmied_cpus);
7283 #endif
7284 /*
7285 * Only allow 1 cpu to proceed
7286 @@ -233,7 +233,7 @@ cont_nmi_dump(void)
7287 udelay(10000);
7288 }
7289 #else
7290 - while (atomic_read(&nmied_cpus) != num_online_cpus());
7291 + while (atomic_read_unchecked(&nmied_cpus) != num_online_cpus());
7292 #endif
7293
7294 /*
7295 diff --git a/arch/mips/sni/rm200.c b/arch/mips/sni/rm200.c
7296 index a046b30..6799527 100644
7297 --- a/arch/mips/sni/rm200.c
7298 +++ b/arch/mips/sni/rm200.c
7299 @@ -270,7 +270,7 @@ spurious_8259A_irq:
7300 "spurious RM200 8259A interrupt: IRQ%d.\n", irq);
7301 spurious_irq_mask |= irqmask;
7302 }
7303 - atomic_inc(&irq_err_count);
7304 + atomic_inc_unchecked(&irq_err_count);
7305 /*
7306 * Theoretically we do not have to handle this IRQ,
7307 * but in Linux this does not cause problems and is
7308 diff --git a/arch/mips/vr41xx/common/icu.c b/arch/mips/vr41xx/common/icu.c
7309 index 41e873b..34d33a7 100644
7310 --- a/arch/mips/vr41xx/common/icu.c
7311 +++ b/arch/mips/vr41xx/common/icu.c
7312 @@ -653,7 +653,7 @@ static int icu_get_irq(unsigned int irq)
7313
7314 printk(KERN_ERR "spurious ICU interrupt: %04x,%04x\n", pend1, pend2);
7315
7316 - atomic_inc(&irq_err_count);
7317 + atomic_inc_unchecked(&irq_err_count);
7318
7319 return -1;
7320 }
7321 diff --git a/arch/mips/vr41xx/common/irq.c b/arch/mips/vr41xx/common/irq.c
7322 index ae0e4ee..e8f0692 100644
7323 --- a/arch/mips/vr41xx/common/irq.c
7324 +++ b/arch/mips/vr41xx/common/irq.c
7325 @@ -64,7 +64,7 @@ static void irq_dispatch(unsigned int irq)
7326 irq_cascade_t *cascade;
7327
7328 if (irq >= NR_IRQS) {
7329 - atomic_inc(&irq_err_count);
7330 + atomic_inc_unchecked(&irq_err_count);
7331 return;
7332 }
7333
7334 @@ -84,7 +84,7 @@ static void irq_dispatch(unsigned int irq)
7335 ret = cascade->get_irq(irq);
7336 irq = ret;
7337 if (ret < 0)
7338 - atomic_inc(&irq_err_count);
7339 + atomic_inc_unchecked(&irq_err_count);
7340 else
7341 irq_dispatch(irq);
7342 if (!irqd_irq_disabled(idata) && chip->irq_unmask)
7343 diff --git a/arch/mn10300/proc-mn103e010/include/proc/cache.h b/arch/mn10300/proc-mn103e010/include/proc/cache.h
7344 index 967d144..db12197 100644
7345 --- a/arch/mn10300/proc-mn103e010/include/proc/cache.h
7346 +++ b/arch/mn10300/proc-mn103e010/include/proc/cache.h
7347 @@ -11,12 +11,14 @@
7348 #ifndef _ASM_PROC_CACHE_H
7349 #define _ASM_PROC_CACHE_H
7350
7351 +#include <linux/const.h>
7352 +
7353 /* L1 cache */
7354
7355 #define L1_CACHE_NWAYS 4 /* number of ways in caches */
7356 #define L1_CACHE_NENTRIES 256 /* number of entries in each way */
7357 -#define L1_CACHE_BYTES 16 /* bytes per entry */
7358 #define L1_CACHE_SHIFT 4 /* shift for bytes per entry */
7359 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT) /* bytes per entry */
7360 #define L1_CACHE_WAYDISP 0x1000 /* displacement of one way from the next */
7361
7362 #define L1_CACHE_TAG_VALID 0x00000001 /* cache tag valid bit */
7363 diff --git a/arch/mn10300/proc-mn2ws0050/include/proc/cache.h b/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
7364 index bcb5df2..84fabd2 100644
7365 --- a/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
7366 +++ b/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
7367 @@ -16,13 +16,15 @@
7368 #ifndef _ASM_PROC_CACHE_H
7369 #define _ASM_PROC_CACHE_H
7370
7371 +#include <linux/const.h>
7372 +
7373 /*
7374 * L1 cache
7375 */
7376 #define L1_CACHE_NWAYS 4 /* number of ways in caches */
7377 #define L1_CACHE_NENTRIES 128 /* number of entries in each way */
7378 -#define L1_CACHE_BYTES 32 /* bytes per entry */
7379 #define L1_CACHE_SHIFT 5 /* shift for bytes per entry */
7380 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT) /* bytes per entry */
7381 #define L1_CACHE_WAYDISP 0x1000 /* distance from one way to the next */
7382
7383 #define L1_CACHE_TAG_VALID 0x00000001 /* cache tag valid bit */
7384 diff --git a/arch/openrisc/include/asm/cache.h b/arch/openrisc/include/asm/cache.h
7385 index 4ce7a01..449202a 100644
7386 --- a/arch/openrisc/include/asm/cache.h
7387 +++ b/arch/openrisc/include/asm/cache.h
7388 @@ -19,11 +19,13 @@
7389 #ifndef __ASM_OPENRISC_CACHE_H
7390 #define __ASM_OPENRISC_CACHE_H
7391
7392 +#include <linux/const.h>
7393 +
7394 /* FIXME: How can we replace these with values from the CPU...
7395 * they shouldn't be hard-coded!
7396 */
7397
7398 -#define L1_CACHE_BYTES 16
7399 #define L1_CACHE_SHIFT 4
7400 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7401
7402 #endif /* __ASM_OPENRISC_CACHE_H */
7403 diff --git a/arch/parisc/include/asm/atomic.h b/arch/parisc/include/asm/atomic.h
7404 index 472886c..00e7df9 100644
7405 --- a/arch/parisc/include/asm/atomic.h
7406 +++ b/arch/parisc/include/asm/atomic.h
7407 @@ -252,6 +252,16 @@ static inline long atomic64_dec_if_positive(atomic64_t *v)
7408 return dec;
7409 }
7410
7411 +#define atomic64_read_unchecked(v) atomic64_read(v)
7412 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
7413 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
7414 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
7415 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
7416 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
7417 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
7418 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
7419 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
7420 +
7421 #endif /* !CONFIG_64BIT */
7422
7423
7424 diff --git a/arch/parisc/include/asm/cache.h b/arch/parisc/include/asm/cache.h
7425 index 47f11c7..3420df2 100644
7426 --- a/arch/parisc/include/asm/cache.h
7427 +++ b/arch/parisc/include/asm/cache.h
7428 @@ -5,6 +5,7 @@
7429 #ifndef __ARCH_PARISC_CACHE_H
7430 #define __ARCH_PARISC_CACHE_H
7431
7432 +#include <linux/const.h>
7433
7434 /*
7435 * PA 2.0 processors have 64-byte cachelines; PA 1.1 processors have
7436 @@ -15,13 +16,13 @@
7437 * just ruin performance.
7438 */
7439 #ifdef CONFIG_PA20
7440 -#define L1_CACHE_BYTES 64
7441 #define L1_CACHE_SHIFT 6
7442 #else
7443 -#define L1_CACHE_BYTES 32
7444 #define L1_CACHE_SHIFT 5
7445 #endif
7446
7447 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7448 +
7449 #ifndef __ASSEMBLY__
7450
7451 #define SMP_CACHE_BYTES L1_CACHE_BYTES
7452 diff --git a/arch/parisc/include/asm/elf.h b/arch/parisc/include/asm/elf.h
7453 index ad2b503..bdf1651 100644
7454 --- a/arch/parisc/include/asm/elf.h
7455 +++ b/arch/parisc/include/asm/elf.h
7456 @@ -342,6 +342,13 @@ struct pt_regs; /* forward declaration... */
7457
7458 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x01000000)
7459
7460 +#ifdef CONFIG_PAX_ASLR
7461 +#define PAX_ELF_ET_DYN_BASE 0x10000UL
7462 +
7463 +#define PAX_DELTA_MMAP_LEN 16
7464 +#define PAX_DELTA_STACK_LEN 16
7465 +#endif
7466 +
7467 /* This yields a mask that user programs can use to figure out what
7468 instruction set this CPU supports. This could be done in user space,
7469 but it's not easy, and we've already done it here. */
7470 diff --git a/arch/parisc/include/asm/pgalloc.h b/arch/parisc/include/asm/pgalloc.h
7471 index f213f5b..0af3e8e 100644
7472 --- a/arch/parisc/include/asm/pgalloc.h
7473 +++ b/arch/parisc/include/asm/pgalloc.h
7474 @@ -61,6 +61,11 @@ static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
7475 (__u32)(__pa((unsigned long)pmd) >> PxD_VALUE_SHIFT));
7476 }
7477
7478 +static inline void pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
7479 +{
7480 + pgd_populate(mm, pgd, pmd);
7481 +}
7482 +
7483 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long address)
7484 {
7485 pmd_t *pmd = (pmd_t *)__get_free_pages(GFP_KERNEL|__GFP_REPEAT,
7486 @@ -93,6 +98,7 @@ static inline void pmd_free(struct mm_struct *mm, pmd_t *pmd)
7487 #define pmd_alloc_one(mm, addr) ({ BUG(); ((pmd_t *)2); })
7488 #define pmd_free(mm, x) do { } while (0)
7489 #define pgd_populate(mm, pmd, pte) BUG()
7490 +#define pgd_populate_kernel(mm, pmd, pte) BUG()
7491
7492 #endif
7493
7494 diff --git a/arch/parisc/include/asm/pgtable.h b/arch/parisc/include/asm/pgtable.h
7495 index 34899b5..02dd060 100644
7496 --- a/arch/parisc/include/asm/pgtable.h
7497 +++ b/arch/parisc/include/asm/pgtable.h
7498 @@ -223,6 +223,17 @@ extern void purge_tlb_entries(struct mm_struct *, unsigned long);
7499 #define PAGE_EXECREAD __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_EXEC |_PAGE_ACCESSED)
7500 #define PAGE_COPY PAGE_EXECREAD
7501 #define PAGE_RWX __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_EXEC |_PAGE_ACCESSED)
7502 +
7503 +#ifdef CONFIG_PAX_PAGEEXEC
7504 +# define PAGE_SHARED_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_ACCESSED)
7505 +# define PAGE_COPY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
7506 +# define PAGE_READONLY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
7507 +#else
7508 +# define PAGE_SHARED_NOEXEC PAGE_SHARED
7509 +# define PAGE_COPY_NOEXEC PAGE_COPY
7510 +# define PAGE_READONLY_NOEXEC PAGE_READONLY
7511 +#endif
7512 +
7513 #define PAGE_KERNEL __pgprot(_PAGE_KERNEL)
7514 #define PAGE_KERNEL_EXEC __pgprot(_PAGE_KERNEL_EXEC)
7515 #define PAGE_KERNEL_RWX __pgprot(_PAGE_KERNEL_RWX)
7516 diff --git a/arch/parisc/include/asm/uaccess.h b/arch/parisc/include/asm/uaccess.h
7517 index 4006964..fcb3cc2 100644
7518 --- a/arch/parisc/include/asm/uaccess.h
7519 +++ b/arch/parisc/include/asm/uaccess.h
7520 @@ -246,10 +246,10 @@ static inline unsigned long __must_check copy_from_user(void *to,
7521 const void __user *from,
7522 unsigned long n)
7523 {
7524 - int sz = __compiletime_object_size(to);
7525 + size_t sz = __compiletime_object_size(to);
7526 int ret = -EFAULT;
7527
7528 - if (likely(sz == -1 || !__builtin_constant_p(n) || sz >= n))
7529 + if (likely(sz == (size_t)-1 || !__builtin_constant_p(n) || sz >= n))
7530 ret = __copy_from_user(to, from, n);
7531 else
7532 copy_from_user_overflow();
7533 diff --git a/arch/parisc/kernel/module.c b/arch/parisc/kernel/module.c
7534 index 50dfafc..b9fc230 100644
7535 --- a/arch/parisc/kernel/module.c
7536 +++ b/arch/parisc/kernel/module.c
7537 @@ -98,16 +98,38 @@
7538
7539 /* three functions to determine where in the module core
7540 * or init pieces the location is */
7541 +static inline int in_init_rx(struct module *me, void *loc)
7542 +{
7543 + return (loc >= me->module_init_rx &&
7544 + loc < (me->module_init_rx + me->init_size_rx));
7545 +}
7546 +
7547 +static inline int in_init_rw(struct module *me, void *loc)
7548 +{
7549 + return (loc >= me->module_init_rw &&
7550 + loc < (me->module_init_rw + me->init_size_rw));
7551 +}
7552 +
7553 static inline int in_init(struct module *me, void *loc)
7554 {
7555 - return (loc >= me->module_init &&
7556 - loc <= (me->module_init + me->init_size));
7557 + return in_init_rx(me, loc) || in_init_rw(me, loc);
7558 +}
7559 +
7560 +static inline int in_core_rx(struct module *me, void *loc)
7561 +{
7562 + return (loc >= me->module_core_rx &&
7563 + loc < (me->module_core_rx + me->core_size_rx));
7564 +}
7565 +
7566 +static inline int in_core_rw(struct module *me, void *loc)
7567 +{
7568 + return (loc >= me->module_core_rw &&
7569 + loc < (me->module_core_rw + me->core_size_rw));
7570 }
7571
7572 static inline int in_core(struct module *me, void *loc)
7573 {
7574 - return (loc >= me->module_core &&
7575 - loc <= (me->module_core + me->core_size));
7576 + return in_core_rx(me, loc) || in_core_rw(me, loc);
7577 }
7578
7579 static inline int in_local(struct module *me, void *loc)
7580 @@ -371,13 +393,13 @@ int module_frob_arch_sections(CONST Elf_Ehdr *hdr,
7581 }
7582
7583 /* align things a bit */
7584 - me->core_size = ALIGN(me->core_size, 16);
7585 - me->arch.got_offset = me->core_size;
7586 - me->core_size += gots * sizeof(struct got_entry);
7587 + me->core_size_rw = ALIGN(me->core_size_rw, 16);
7588 + me->arch.got_offset = me->core_size_rw;
7589 + me->core_size_rw += gots * sizeof(struct got_entry);
7590
7591 - me->core_size = ALIGN(me->core_size, 16);
7592 - me->arch.fdesc_offset = me->core_size;
7593 - me->core_size += fdescs * sizeof(Elf_Fdesc);
7594 + me->core_size_rw = ALIGN(me->core_size_rw, 16);
7595 + me->arch.fdesc_offset = me->core_size_rw;
7596 + me->core_size_rw += fdescs * sizeof(Elf_Fdesc);
7597
7598 me->arch.got_max = gots;
7599 me->arch.fdesc_max = fdescs;
7600 @@ -395,7 +417,7 @@ static Elf64_Word get_got(struct module *me, unsigned long value, long addend)
7601
7602 BUG_ON(value == 0);
7603
7604 - got = me->module_core + me->arch.got_offset;
7605 + got = me->module_core_rw + me->arch.got_offset;
7606 for (i = 0; got[i].addr; i++)
7607 if (got[i].addr == value)
7608 goto out;
7609 @@ -413,7 +435,7 @@ static Elf64_Word get_got(struct module *me, unsigned long value, long addend)
7610 #ifdef CONFIG_64BIT
7611 static Elf_Addr get_fdesc(struct module *me, unsigned long value)
7612 {
7613 - Elf_Fdesc *fdesc = me->module_core + me->arch.fdesc_offset;
7614 + Elf_Fdesc *fdesc = me->module_core_rw + me->arch.fdesc_offset;
7615
7616 if (!value) {
7617 printk(KERN_ERR "%s: zero OPD requested!\n", me->name);
7618 @@ -431,7 +453,7 @@ static Elf_Addr get_fdesc(struct module *me, unsigned long value)
7619
7620 /* Create new one */
7621 fdesc->addr = value;
7622 - fdesc->gp = (Elf_Addr)me->module_core + me->arch.got_offset;
7623 + fdesc->gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
7624 return (Elf_Addr)fdesc;
7625 }
7626 #endif /* CONFIG_64BIT */
7627 @@ -843,7 +865,7 @@ register_unwind_table(struct module *me,
7628
7629 table = (unsigned char *)sechdrs[me->arch.unwind_section].sh_addr;
7630 end = table + sechdrs[me->arch.unwind_section].sh_size;
7631 - gp = (Elf_Addr)me->module_core + me->arch.got_offset;
7632 + gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
7633
7634 DEBUGP("register_unwind_table(), sect = %d at 0x%p - 0x%p (gp=0x%lx)\n",
7635 me->arch.unwind_section, table, end, gp);
7636 diff --git a/arch/parisc/kernel/sys_parisc.c b/arch/parisc/kernel/sys_parisc.c
7637 index 0d3a9d4..20a99b0 100644
7638 --- a/arch/parisc/kernel/sys_parisc.c
7639 +++ b/arch/parisc/kernel/sys_parisc.c
7640 @@ -33,9 +33,11 @@
7641 #include <linux/utsname.h>
7642 #include <linux/personality.h>
7643
7644 -static unsigned long get_unshared_area(unsigned long addr, unsigned long len)
7645 +static unsigned long get_unshared_area(unsigned long addr, unsigned long len,
7646 + unsigned long flags)
7647 {
7648 struct vm_unmapped_area_info info;
7649 + unsigned long offset = gr_rand_threadstack_offset(current->mm, NULL, flags);
7650
7651 info.flags = 0;
7652 info.length = len;
7653 @@ -43,6 +45,7 @@ static unsigned long get_unshared_area(unsigned long addr, unsigned long len)
7654 info.high_limit = TASK_SIZE;
7655 info.align_mask = 0;
7656 info.align_offset = 0;
7657 + info.threadstack_offset = offset;
7658 return vm_unmapped_area(&info);
7659 }
7660
7661 @@ -69,9 +72,10 @@ static unsigned long shared_align_offset(struct file *filp, unsigned long pgoff)
7662 }
7663
7664 static unsigned long get_shared_area(struct file *filp, unsigned long addr,
7665 - unsigned long len, unsigned long pgoff)
7666 + unsigned long len, unsigned long pgoff, unsigned long flags)
7667 {
7668 struct vm_unmapped_area_info info;
7669 + unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
7670
7671 info.flags = 0;
7672 info.length = len;
7673 @@ -79,6 +83,7 @@ static unsigned long get_shared_area(struct file *filp, unsigned long addr,
7674 info.high_limit = TASK_SIZE;
7675 info.align_mask = PAGE_MASK & (SHMLBA - 1);
7676 info.align_offset = shared_align_offset(filp, pgoff);
7677 + info.threadstack_offset = offset;
7678 return vm_unmapped_area(&info);
7679 }
7680
7681 @@ -93,13 +98,20 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
7682 return -EINVAL;
7683 return addr;
7684 }
7685 - if (!addr)
7686 + if (!addr) {
7687 addr = TASK_UNMAPPED_BASE;
7688
7689 +#ifdef CONFIG_PAX_RANDMMAP
7690 + if (current->mm->pax_flags & MF_PAX_RANDMMAP)
7691 + addr += current->mm->delta_mmap;
7692 +#endif
7693 +
7694 + }
7695 +
7696 if (filp || (flags & MAP_SHARED))
7697 - addr = get_shared_area(filp, addr, len, pgoff);
7698 + addr = get_shared_area(filp, addr, len, pgoff, flags);
7699 else
7700 - addr = get_unshared_area(addr, len);
7701 + addr = get_unshared_area(addr, len, flags);
7702
7703 return addr;
7704 }
7705 diff --git a/arch/parisc/kernel/traps.c b/arch/parisc/kernel/traps.c
7706 index 1cd1d0c..44ec918 100644
7707 --- a/arch/parisc/kernel/traps.c
7708 +++ b/arch/parisc/kernel/traps.c
7709 @@ -722,9 +722,7 @@ void notrace handle_interruption(int code, struct pt_regs *regs)
7710
7711 down_read(&current->mm->mmap_sem);
7712 vma = find_vma(current->mm,regs->iaoq[0]);
7713 - if (vma && (regs->iaoq[0] >= vma->vm_start)
7714 - && (vma->vm_flags & VM_EXEC)) {
7715 -
7716 + if (vma && (regs->iaoq[0] >= vma->vm_start)) {
7717 fault_address = regs->iaoq[0];
7718 fault_space = regs->iasq[0];
7719
7720 diff --git a/arch/parisc/mm/fault.c b/arch/parisc/mm/fault.c
7721 index 9d08c71..e2b4d20 100644
7722 --- a/arch/parisc/mm/fault.c
7723 +++ b/arch/parisc/mm/fault.c
7724 @@ -15,6 +15,7 @@
7725 #include <linux/sched.h>
7726 #include <linux/interrupt.h>
7727 #include <linux/module.h>
7728 +#include <linux/unistd.h>
7729
7730 #include <asm/uaccess.h>
7731 #include <asm/traps.h>
7732 @@ -52,7 +53,7 @@ DEFINE_PER_CPU(struct exception_data, exception_data);
7733 static unsigned long
7734 parisc_acctyp(unsigned long code, unsigned int inst)
7735 {
7736 - if (code == 6 || code == 16)
7737 + if (code == 6 || code == 7 || code == 16)
7738 return VM_EXEC;
7739
7740 switch (inst & 0xf0000000) {
7741 @@ -138,6 +139,116 @@ parisc_acctyp(unsigned long code, unsigned int inst)
7742 }
7743 #endif
7744
7745 +#ifdef CONFIG_PAX_PAGEEXEC
7746 +/*
7747 + * PaX: decide what to do with offenders (instruction_pointer(regs) = fault address)
7748 + *
7749 + * returns 1 when task should be killed
7750 + * 2 when rt_sigreturn trampoline was detected
7751 + * 3 when unpatched PLT trampoline was detected
7752 + */
7753 +static int pax_handle_fetch_fault(struct pt_regs *regs)
7754 +{
7755 +
7756 +#ifdef CONFIG_PAX_EMUPLT
7757 + int err;
7758 +
7759 + do { /* PaX: unpatched PLT emulation */
7760 + unsigned int bl, depwi;
7761 +
7762 + err = get_user(bl, (unsigned int *)instruction_pointer(regs));
7763 + err |= get_user(depwi, (unsigned int *)(instruction_pointer(regs)+4));
7764 +
7765 + if (err)
7766 + break;
7767 +
7768 + if (bl == 0xEA9F1FDDU && depwi == 0xD6801C1EU) {
7769 + unsigned int ldw, bv, ldw2, addr = instruction_pointer(regs)-12;
7770 +
7771 + err = get_user(ldw, (unsigned int *)addr);
7772 + err |= get_user(bv, (unsigned int *)(addr+4));
7773 + err |= get_user(ldw2, (unsigned int *)(addr+8));
7774 +
7775 + if (err)
7776 + break;
7777 +
7778 + if (ldw == 0x0E801096U &&
7779 + bv == 0xEAC0C000U &&
7780 + ldw2 == 0x0E881095U)
7781 + {
7782 + unsigned int resolver, map;
7783 +
7784 + err = get_user(resolver, (unsigned int *)(instruction_pointer(regs)+8));
7785 + err |= get_user(map, (unsigned int *)(instruction_pointer(regs)+12));
7786 + if (err)
7787 + break;
7788 +
7789 + regs->gr[20] = instruction_pointer(regs)+8;
7790 + regs->gr[21] = map;
7791 + regs->gr[22] = resolver;
7792 + regs->iaoq[0] = resolver | 3UL;
7793 + regs->iaoq[1] = regs->iaoq[0] + 4;
7794 + return 3;
7795 + }
7796 + }
7797 + } while (0);
7798 +#endif
7799 +
7800 +#ifdef CONFIG_PAX_EMUTRAMP
7801 +
7802 +#ifndef CONFIG_PAX_EMUSIGRT
7803 + if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
7804 + return 1;
7805 +#endif
7806 +
7807 + do { /* PaX: rt_sigreturn emulation */
7808 + unsigned int ldi1, ldi2, bel, nop;
7809 +
7810 + err = get_user(ldi1, (unsigned int *)instruction_pointer(regs));
7811 + err |= get_user(ldi2, (unsigned int *)(instruction_pointer(regs)+4));
7812 + err |= get_user(bel, (unsigned int *)(instruction_pointer(regs)+8));
7813 + err |= get_user(nop, (unsigned int *)(instruction_pointer(regs)+12));
7814 +
7815 + if (err)
7816 + break;
7817 +
7818 + if ((ldi1 == 0x34190000U || ldi1 == 0x34190002U) &&
7819 + ldi2 == 0x3414015AU &&
7820 + bel == 0xE4008200U &&
7821 + nop == 0x08000240U)
7822 + {
7823 + regs->gr[25] = (ldi1 & 2) >> 1;
7824 + regs->gr[20] = __NR_rt_sigreturn;
7825 + regs->gr[31] = regs->iaoq[1] + 16;
7826 + regs->sr[0] = regs->iasq[1];
7827 + regs->iaoq[0] = 0x100UL;
7828 + regs->iaoq[1] = regs->iaoq[0] + 4;
7829 + regs->iasq[0] = regs->sr[2];
7830 + regs->iasq[1] = regs->sr[2];
7831 + return 2;
7832 + }
7833 + } while (0);
7834 +#endif
7835 +
7836 + return 1;
7837 +}
7838 +
7839 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
7840 +{
7841 + unsigned long i;
7842 +
7843 + printk(KERN_ERR "PAX: bytes at PC: ");
7844 + for (i = 0; i < 5; i++) {
7845 + unsigned int c;
7846 + if (get_user(c, (unsigned int *)pc+i))
7847 + printk(KERN_CONT "???????? ");
7848 + else
7849 + printk(KERN_CONT "%08x ", c);
7850 + }
7851 + printk("\n");
7852 +}
7853 +#endif
7854 +
7855 int fixup_exception(struct pt_regs *regs)
7856 {
7857 const struct exception_table_entry *fix;
7858 @@ -210,8 +321,33 @@ retry:
7859
7860 good_area:
7861
7862 - if ((vma->vm_flags & acc_type) != acc_type)
7863 + if ((vma->vm_flags & acc_type) != acc_type) {
7864 +
7865 +#ifdef CONFIG_PAX_PAGEEXEC
7866 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && (acc_type & VM_EXEC) &&
7867 + (address & ~3UL) == instruction_pointer(regs))
7868 + {
7869 + up_read(&mm->mmap_sem);
7870 + switch (pax_handle_fetch_fault(regs)) {
7871 +
7872 +#ifdef CONFIG_PAX_EMUPLT
7873 + case 3:
7874 + return;
7875 +#endif
7876 +
7877 +#ifdef CONFIG_PAX_EMUTRAMP
7878 + case 2:
7879 + return;
7880 +#endif
7881 +
7882 + }
7883 + pax_report_fault(regs, (void *)instruction_pointer(regs), (void *)regs->gr[30]);
7884 + do_group_exit(SIGKILL);
7885 + }
7886 +#endif
7887 +
7888 goto bad_area;
7889 + }
7890
7891 /*
7892 * If for any reason at all we couldn't handle the fault, make
7893 diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig
7894 index b44b52c..4cd253c 100644
7895 --- a/arch/powerpc/Kconfig
7896 +++ b/arch/powerpc/Kconfig
7897 @@ -382,6 +382,7 @@ config ARCH_ENABLE_MEMORY_HOTREMOVE
7898 config KEXEC
7899 bool "kexec system call"
7900 depends on (PPC_BOOK3S || FSL_BOOKE || (44x && !SMP))
7901 + depends on !GRKERNSEC_KMEM
7902 help
7903 kexec is a system call that implements the ability to shutdown your
7904 current kernel, and to start another kernel. It is like a reboot
7905 diff --git a/arch/powerpc/include/asm/atomic.h b/arch/powerpc/include/asm/atomic.h
7906 index e3b1d41..8e81edf 100644
7907 --- a/arch/powerpc/include/asm/atomic.h
7908 +++ b/arch/powerpc/include/asm/atomic.h
7909 @@ -523,6 +523,16 @@ static __inline__ long atomic64_inc_not_zero(atomic64_t *v)
7910 return t1;
7911 }
7912
7913 +#define atomic64_read_unchecked(v) atomic64_read(v)
7914 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
7915 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
7916 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
7917 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
7918 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
7919 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
7920 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
7921 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
7922 +
7923 #endif /* __powerpc64__ */
7924
7925 #endif /* __KERNEL__ */
7926 diff --git a/arch/powerpc/include/asm/cache.h b/arch/powerpc/include/asm/cache.h
7927 index 9e495c9..b6878e5 100644
7928 --- a/arch/powerpc/include/asm/cache.h
7929 +++ b/arch/powerpc/include/asm/cache.h
7930 @@ -3,6 +3,7 @@
7931
7932 #ifdef __KERNEL__
7933
7934 +#include <linux/const.h>
7935
7936 /* bytes per L1 cache line */
7937 #if defined(CONFIG_8xx) || defined(CONFIG_403GCX)
7938 @@ -22,7 +23,7 @@
7939 #define L1_CACHE_SHIFT 7
7940 #endif
7941
7942 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
7943 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7944
7945 #define SMP_CACHE_BYTES L1_CACHE_BYTES
7946
7947 diff --git a/arch/powerpc/include/asm/elf.h b/arch/powerpc/include/asm/elf.h
7948 index 935b5e7..7001d2d 100644
7949 --- a/arch/powerpc/include/asm/elf.h
7950 +++ b/arch/powerpc/include/asm/elf.h
7951 @@ -28,8 +28,19 @@
7952 the loader. We need to make sure that it is out of the way of the program
7953 that it will "exec", and that there is sufficient room for the brk. */
7954
7955 -extern unsigned long randomize_et_dyn(unsigned long base);
7956 -#define ELF_ET_DYN_BASE (randomize_et_dyn(0x20000000))
7957 +#define ELF_ET_DYN_BASE (0x20000000)
7958 +
7959 +#ifdef CONFIG_PAX_ASLR
7960 +#define PAX_ELF_ET_DYN_BASE (0x10000000UL)
7961 +
7962 +#ifdef __powerpc64__
7963 +#define PAX_DELTA_MMAP_LEN (is_32bit_task() ? 16 : 28)
7964 +#define PAX_DELTA_STACK_LEN (is_32bit_task() ? 16 : 28)
7965 +#else
7966 +#define PAX_DELTA_MMAP_LEN 15
7967 +#define PAX_DELTA_STACK_LEN 15
7968 +#endif
7969 +#endif
7970
7971 #define ELF_CORE_EFLAGS (is_elf2_task() ? 2 : 0)
7972
7973 @@ -127,10 +138,6 @@ extern int arch_setup_additional_pages(struct linux_binprm *bprm,
7974 (0x7ff >> (PAGE_SHIFT - 12)) : \
7975 (0x3ffff >> (PAGE_SHIFT - 12)))
7976
7977 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
7978 -#define arch_randomize_brk arch_randomize_brk
7979 -
7980 -
7981 #ifdef CONFIG_SPU_BASE
7982 /* Notes used in ET_CORE. Note name is "SPU/<fd>/<filename>". */
7983 #define NT_SPU 1
7984 diff --git a/arch/powerpc/include/asm/exec.h b/arch/powerpc/include/asm/exec.h
7985 index 8196e9c..d83a9f3 100644
7986 --- a/arch/powerpc/include/asm/exec.h
7987 +++ b/arch/powerpc/include/asm/exec.h
7988 @@ -4,6 +4,6 @@
7989 #ifndef _ASM_POWERPC_EXEC_H
7990 #define _ASM_POWERPC_EXEC_H
7991
7992 -extern unsigned long arch_align_stack(unsigned long sp);
7993 +#define arch_align_stack(x) ((x) & ~0xfUL)
7994
7995 #endif /* _ASM_POWERPC_EXEC_H */
7996 diff --git a/arch/powerpc/include/asm/kmap_types.h b/arch/powerpc/include/asm/kmap_types.h
7997 index 5acabbd..7ea14fa 100644
7998 --- a/arch/powerpc/include/asm/kmap_types.h
7999 +++ b/arch/powerpc/include/asm/kmap_types.h
8000 @@ -10,7 +10,7 @@
8001 * 2 of the License, or (at your option) any later version.
8002 */
8003
8004 -#define KM_TYPE_NR 16
8005 +#define KM_TYPE_NR 17
8006
8007 #endif /* __KERNEL__ */
8008 #endif /* _ASM_POWERPC_KMAP_TYPES_H */
8009 diff --git a/arch/powerpc/include/asm/local.h b/arch/powerpc/include/asm/local.h
8010 index b8da913..60b608a 100644
8011 --- a/arch/powerpc/include/asm/local.h
8012 +++ b/arch/powerpc/include/asm/local.h
8013 @@ -9,15 +9,26 @@ typedef struct
8014 atomic_long_t a;
8015 } local_t;
8016
8017 +typedef struct
8018 +{
8019 + atomic_long_unchecked_t a;
8020 +} local_unchecked_t;
8021 +
8022 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
8023
8024 #define local_read(l) atomic_long_read(&(l)->a)
8025 +#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
8026 #define local_set(l,i) atomic_long_set(&(l)->a, (i))
8027 +#define local_set_unchecked(l,i) atomic_long_set_unchecked(&(l)->a, (i))
8028
8029 #define local_add(i,l) atomic_long_add((i),(&(l)->a))
8030 +#define local_add_unchecked(i,l) atomic_long_add_unchecked((i),(&(l)->a))
8031 #define local_sub(i,l) atomic_long_sub((i),(&(l)->a))
8032 +#define local_sub_unchecked(i,l) atomic_long_sub_unchecked((i),(&(l)->a))
8033 #define local_inc(l) atomic_long_inc(&(l)->a)
8034 +#define local_inc_unchecked(l) atomic_long_inc_unchecked(&(l)->a)
8035 #define local_dec(l) atomic_long_dec(&(l)->a)
8036 +#define local_dec_unchecked(l) atomic_long_dec_unchecked(&(l)->a)
8037
8038 static __inline__ long local_add_return(long a, local_t *l)
8039 {
8040 @@ -35,6 +46,7 @@ static __inline__ long local_add_return(long a, local_t *l)
8041
8042 return t;
8043 }
8044 +#define local_add_return_unchecked(i, l) atomic_long_add_return_unchecked((i), (&(l)->a))
8045
8046 #define local_add_negative(a, l) (local_add_return((a), (l)) < 0)
8047
8048 @@ -54,6 +66,7 @@ static __inline__ long local_sub_return(long a, local_t *l)
8049
8050 return t;
8051 }
8052 +#define local_sub_return_unchecked(i, l) atomic_long_sub_return_unchecked((i), (&(l)->a))
8053
8054 static __inline__ long local_inc_return(local_t *l)
8055 {
8056 @@ -101,6 +114,8 @@ static __inline__ long local_dec_return(local_t *l)
8057
8058 #define local_cmpxchg(l, o, n) \
8059 (cmpxchg_local(&((l)->a.counter), (o), (n)))
8060 +#define local_cmpxchg_unchecked(l, o, n) \
8061 + (cmpxchg_local(&((l)->a.counter), (o), (n)))
8062 #define local_xchg(l, n) (xchg_local(&((l)->a.counter), (n)))
8063
8064 /**
8065 diff --git a/arch/powerpc/include/asm/mman.h b/arch/powerpc/include/asm/mman.h
8066 index 8565c25..2865190 100644
8067 --- a/arch/powerpc/include/asm/mman.h
8068 +++ b/arch/powerpc/include/asm/mman.h
8069 @@ -24,7 +24,7 @@ static inline unsigned long arch_calc_vm_prot_bits(unsigned long prot)
8070 }
8071 #define arch_calc_vm_prot_bits(prot) arch_calc_vm_prot_bits(prot)
8072
8073 -static inline pgprot_t arch_vm_get_page_prot(unsigned long vm_flags)
8074 +static inline pgprot_t arch_vm_get_page_prot(vm_flags_t vm_flags)
8075 {
8076 return (vm_flags & VM_SAO) ? __pgprot(_PAGE_SAO) : __pgprot(0);
8077 }
8078 diff --git a/arch/powerpc/include/asm/page.h b/arch/powerpc/include/asm/page.h
8079 index 32e4e21..62afb12 100644
8080 --- a/arch/powerpc/include/asm/page.h
8081 +++ b/arch/powerpc/include/asm/page.h
8082 @@ -230,8 +230,9 @@ extern long long virt_phys_offset;
8083 * and needs to be executable. This means the whole heap ends
8084 * up being executable.
8085 */
8086 -#define VM_DATA_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
8087 - VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
8088 +#define VM_DATA_DEFAULT_FLAGS32 \
8089 + (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
8090 + VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
8091
8092 #define VM_DATA_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
8093 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
8094 @@ -259,6 +260,9 @@ extern long long virt_phys_offset;
8095 #define is_kernel_addr(x) ((x) >= PAGE_OFFSET)
8096 #endif
8097
8098 +#define ktla_ktva(addr) (addr)
8099 +#define ktva_ktla(addr) (addr)
8100 +
8101 #ifndef CONFIG_PPC_BOOK3S_64
8102 /*
8103 * Use the top bit of the higher-level page table entries to indicate whether
8104 diff --git a/arch/powerpc/include/asm/page_64.h b/arch/powerpc/include/asm/page_64.h
8105 index 88693ce..ac6f9ab 100644
8106 --- a/arch/powerpc/include/asm/page_64.h
8107 +++ b/arch/powerpc/include/asm/page_64.h
8108 @@ -153,15 +153,18 @@ do { \
8109 * stack by default, so in the absence of a PT_GNU_STACK program header
8110 * we turn execute permission off.
8111 */
8112 -#define VM_STACK_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
8113 - VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
8114 +#define VM_STACK_DEFAULT_FLAGS32 \
8115 + (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
8116 + VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
8117
8118 #define VM_STACK_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
8119 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
8120
8121 +#ifndef CONFIG_PAX_PAGEEXEC
8122 #define VM_STACK_DEFAULT_FLAGS \
8123 (is_32bit_task() ? \
8124 VM_STACK_DEFAULT_FLAGS32 : VM_STACK_DEFAULT_FLAGS64)
8125 +#endif
8126
8127 #include <asm-generic/getorder.h>
8128
8129 diff --git a/arch/powerpc/include/asm/pgalloc-64.h b/arch/powerpc/include/asm/pgalloc-64.h
8130 index 4b0be20..c15a27d 100644
8131 --- a/arch/powerpc/include/asm/pgalloc-64.h
8132 +++ b/arch/powerpc/include/asm/pgalloc-64.h
8133 @@ -54,6 +54,7 @@ static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
8134 #ifndef CONFIG_PPC_64K_PAGES
8135
8136 #define pgd_populate(MM, PGD, PUD) pgd_set(PGD, PUD)
8137 +#define pgd_populate_kernel(MM, PGD, PUD) pgd_populate((MM), (PGD), (PUD))
8138
8139 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
8140 {
8141 @@ -71,6 +72,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
8142 pud_set(pud, (unsigned long)pmd);
8143 }
8144
8145 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
8146 +{
8147 + pud_populate(mm, pud, pmd);
8148 +}
8149 +
8150 #define pmd_populate(mm, pmd, pte_page) \
8151 pmd_populate_kernel(mm, pmd, page_address(pte_page))
8152 #define pmd_populate_kernel(mm, pmd, pte) pmd_set(pmd, (unsigned long)(pte))
8153 @@ -173,6 +179,7 @@ extern void __tlb_remove_table(void *_table);
8154 #endif
8155
8156 #define pud_populate(mm, pud, pmd) pud_set(pud, (unsigned long)pmd)
8157 +#define pud_populate_kernel(mm, pud, pmd) pud_populate((mm), (pud), (pmd))
8158
8159 static inline void pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmd,
8160 pte_t *pte)
8161 diff --git a/arch/powerpc/include/asm/pgtable.h b/arch/powerpc/include/asm/pgtable.h
8162 index 7d6eacf..14c0240 100644
8163 --- a/arch/powerpc/include/asm/pgtable.h
8164 +++ b/arch/powerpc/include/asm/pgtable.h
8165 @@ -2,6 +2,7 @@
8166 #define _ASM_POWERPC_PGTABLE_H
8167 #ifdef __KERNEL__
8168
8169 +#include <linux/const.h>
8170 #ifndef __ASSEMBLY__
8171 #include <asm/processor.h> /* For TASK_SIZE */
8172 #include <asm/mmu.h>
8173 diff --git a/arch/powerpc/include/asm/pte-hash32.h b/arch/powerpc/include/asm/pte-hash32.h
8174 index 4aad413..85d86bf 100644
8175 --- a/arch/powerpc/include/asm/pte-hash32.h
8176 +++ b/arch/powerpc/include/asm/pte-hash32.h
8177 @@ -21,6 +21,7 @@
8178 #define _PAGE_FILE 0x004 /* when !present: nonlinear file mapping */
8179 #define _PAGE_USER 0x004 /* usermode access allowed */
8180 #define _PAGE_GUARDED 0x008 /* G: prohibit speculative access */
8181 +#define _PAGE_EXEC _PAGE_GUARDED
8182 #define _PAGE_COHERENT 0x010 /* M: enforce memory coherence (SMP systems) */
8183 #define _PAGE_NO_CACHE 0x020 /* I: cache inhibit */
8184 #define _PAGE_WRITETHRU 0x040 /* W: cache write-through */
8185 diff --git a/arch/powerpc/include/asm/reg.h b/arch/powerpc/include/asm/reg.h
8186 index fa8388e..f985549 100644
8187 --- a/arch/powerpc/include/asm/reg.h
8188 +++ b/arch/powerpc/include/asm/reg.h
8189 @@ -239,6 +239,7 @@
8190 #define SPRN_DBCR 0x136 /* e300 Data Breakpoint Control Reg */
8191 #define SPRN_DSISR 0x012 /* Data Storage Interrupt Status Register */
8192 #define DSISR_NOHPTE 0x40000000 /* no translation found */
8193 +#define DSISR_GUARDED 0x10000000 /* fetch from guarded storage */
8194 #define DSISR_PROTFAULT 0x08000000 /* protection fault */
8195 #define DSISR_ISSTORE 0x02000000 /* access was a store */
8196 #define DSISR_DABRMATCH 0x00400000 /* hit data breakpoint */
8197 diff --git a/arch/powerpc/include/asm/smp.h b/arch/powerpc/include/asm/smp.h
8198 index 084e080..9415a3d 100644
8199 --- a/arch/powerpc/include/asm/smp.h
8200 +++ b/arch/powerpc/include/asm/smp.h
8201 @@ -51,7 +51,7 @@ struct smp_ops_t {
8202 int (*cpu_disable)(void);
8203 void (*cpu_die)(unsigned int nr);
8204 int (*cpu_bootable)(unsigned int nr);
8205 -};
8206 +} __no_const;
8207
8208 extern void smp_send_debugger_break(void);
8209 extern void start_secondary_resume(void);
8210 diff --git a/arch/powerpc/include/asm/thread_info.h b/arch/powerpc/include/asm/thread_info.h
8211 index 9854c56..7517190 100644
8212 --- a/arch/powerpc/include/asm/thread_info.h
8213 +++ b/arch/powerpc/include/asm/thread_info.h
8214 @@ -91,7 +91,6 @@ static inline struct thread_info *current_thread_info(void)
8215 #define TIF_POLLING_NRFLAG 3 /* true if poll_idle() is polling
8216 TIF_NEED_RESCHED */
8217 #define TIF_32BIT 4 /* 32 bit binary */
8218 -#define TIF_PERFMON_WORK 5 /* work for pfm_handle_work() */
8219 #define TIF_PERFMON_CTXSW 6 /* perfmon needs ctxsw calls */
8220 #define TIF_SYSCALL_AUDIT 7 /* syscall auditing active */
8221 #define TIF_SINGLESTEP 8 /* singlestepping active */
8222 @@ -108,6 +107,9 @@ static inline struct thread_info *current_thread_info(void)
8223 #if defined(CONFIG_PPC64)
8224 #define TIF_ELF2ABI 18 /* function descriptors must die! */
8225 #endif
8226 +#define TIF_PERFMON_WORK 19 /* work for pfm_handle_work() */
8227 +/* mask must be expressable within 16 bits to satisfy 'andi' instruction reqs */
8228 +#define TIF_GRSEC_SETXID 5 /* update credentials on syscall entry/exit */
8229
8230 /* as above, but as bit values */
8231 #define _TIF_SYSCALL_TRACE (1<<TIF_SYSCALL_TRACE)
8232 @@ -127,9 +129,10 @@ static inline struct thread_info *current_thread_info(void)
8233 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
8234 #define _TIF_EMULATE_STACK_STORE (1<<TIF_EMULATE_STACK_STORE)
8235 #define _TIF_NOHZ (1<<TIF_NOHZ)
8236 +#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
8237 #define _TIF_SYSCALL_T_OR_A (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | \
8238 _TIF_SECCOMP | _TIF_SYSCALL_TRACEPOINT | \
8239 - _TIF_NOHZ)
8240 + _TIF_NOHZ | _TIF_GRSEC_SETXID)
8241
8242 #define _TIF_USER_WORK_MASK (_TIF_SIGPENDING | _TIF_NEED_RESCHED | \
8243 _TIF_NOTIFY_RESUME | _TIF_UPROBE)
8244 diff --git a/arch/powerpc/include/asm/uaccess.h b/arch/powerpc/include/asm/uaccess.h
8245 index 9485b43..3bd3c16 100644
8246 --- a/arch/powerpc/include/asm/uaccess.h
8247 +++ b/arch/powerpc/include/asm/uaccess.h
8248 @@ -58,6 +58,7 @@
8249
8250 #endif
8251
8252 +#define access_ok_noprefault(type, addr, size) access_ok((type), (addr), (size))
8253 #define access_ok(type, addr, size) \
8254 (__chk_user_ptr(addr), \
8255 __access_ok((__force unsigned long)(addr), (size), get_fs()))
8256 @@ -318,52 +319,6 @@ do { \
8257 extern unsigned long __copy_tofrom_user(void __user *to,
8258 const void __user *from, unsigned long size);
8259
8260 -#ifndef __powerpc64__
8261 -
8262 -static inline unsigned long copy_from_user(void *to,
8263 - const void __user *from, unsigned long n)
8264 -{
8265 - unsigned long over;
8266 -
8267 - if (access_ok(VERIFY_READ, from, n))
8268 - return __copy_tofrom_user((__force void __user *)to, from, n);
8269 - if ((unsigned long)from < TASK_SIZE) {
8270 - over = (unsigned long)from + n - TASK_SIZE;
8271 - return __copy_tofrom_user((__force void __user *)to, from,
8272 - n - over) + over;
8273 - }
8274 - return n;
8275 -}
8276 -
8277 -static inline unsigned long copy_to_user(void __user *to,
8278 - const void *from, unsigned long n)
8279 -{
8280 - unsigned long over;
8281 -
8282 - if (access_ok(VERIFY_WRITE, to, n))
8283 - return __copy_tofrom_user(to, (__force void __user *)from, n);
8284 - if ((unsigned long)to < TASK_SIZE) {
8285 - over = (unsigned long)to + n - TASK_SIZE;
8286 - return __copy_tofrom_user(to, (__force void __user *)from,
8287 - n - over) + over;
8288 - }
8289 - return n;
8290 -}
8291 -
8292 -#else /* __powerpc64__ */
8293 -
8294 -#define __copy_in_user(to, from, size) \
8295 - __copy_tofrom_user((to), (from), (size))
8296 -
8297 -extern unsigned long copy_from_user(void *to, const void __user *from,
8298 - unsigned long n);
8299 -extern unsigned long copy_to_user(void __user *to, const void *from,
8300 - unsigned long n);
8301 -extern unsigned long copy_in_user(void __user *to, const void __user *from,
8302 - unsigned long n);
8303 -
8304 -#endif /* __powerpc64__ */
8305 -
8306 static inline unsigned long __copy_from_user_inatomic(void *to,
8307 const void __user *from, unsigned long n)
8308 {
8309 @@ -387,6 +342,10 @@ static inline unsigned long __copy_from_user_inatomic(void *to,
8310 if (ret == 0)
8311 return 0;
8312 }
8313 +
8314 + if (!__builtin_constant_p(n))
8315 + check_object_size(to, n, false);
8316 +
8317 return __copy_tofrom_user((__force void __user *)to, from, n);
8318 }
8319
8320 @@ -413,6 +372,10 @@ static inline unsigned long __copy_to_user_inatomic(void __user *to,
8321 if (ret == 0)
8322 return 0;
8323 }
8324 +
8325 + if (!__builtin_constant_p(n))
8326 + check_object_size(from, n, true);
8327 +
8328 return __copy_tofrom_user(to, (__force const void __user *)from, n);
8329 }
8330
8331 @@ -430,6 +393,92 @@ static inline unsigned long __copy_to_user(void __user *to,
8332 return __copy_to_user_inatomic(to, from, size);
8333 }
8334
8335 +#ifndef __powerpc64__
8336 +
8337 +static inline unsigned long __must_check copy_from_user(void *to,
8338 + const void __user *from, unsigned long n)
8339 +{
8340 + unsigned long over;
8341 +
8342 + if ((long)n < 0)
8343 + return n;
8344 +
8345 + if (access_ok(VERIFY_READ, from, n)) {
8346 + if (!__builtin_constant_p(n))
8347 + check_object_size(to, n, false);
8348 + return __copy_tofrom_user((__force void __user *)to, from, n);
8349 + }
8350 + if ((unsigned long)from < TASK_SIZE) {
8351 + over = (unsigned long)from + n - TASK_SIZE;
8352 + if (!__builtin_constant_p(n - over))
8353 + check_object_size(to, n - over, false);
8354 + return __copy_tofrom_user((__force void __user *)to, from,
8355 + n - over) + over;
8356 + }
8357 + return n;
8358 +}
8359 +
8360 +static inline unsigned long __must_check copy_to_user(void __user *to,
8361 + const void *from, unsigned long n)
8362 +{
8363 + unsigned long over;
8364 +
8365 + if ((long)n < 0)
8366 + return n;
8367 +
8368 + if (access_ok(VERIFY_WRITE, to, n)) {
8369 + if (!__builtin_constant_p(n))
8370 + check_object_size(from, n, true);
8371 + return __copy_tofrom_user(to, (__force void __user *)from, n);
8372 + }
8373 + if ((unsigned long)to < TASK_SIZE) {
8374 + over = (unsigned long)to + n - TASK_SIZE;
8375 + if (!__builtin_constant_p(n))
8376 + check_object_size(from, n - over, true);
8377 + return __copy_tofrom_user(to, (__force void __user *)from,
8378 + n - over) + over;
8379 + }
8380 + return n;
8381 +}
8382 +
8383 +#else /* __powerpc64__ */
8384 +
8385 +#define __copy_in_user(to, from, size) \
8386 + __copy_tofrom_user((to), (from), (size))
8387 +
8388 +static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
8389 +{
8390 + if ((long)n < 0 || n > INT_MAX)
8391 + return n;
8392 +
8393 + if (!__builtin_constant_p(n))
8394 + check_object_size(to, n, false);
8395 +
8396 + if (likely(access_ok(VERIFY_READ, from, n)))
8397 + n = __copy_from_user(to, from, n);
8398 + else
8399 + memset(to, 0, n);
8400 + return n;
8401 +}
8402 +
8403 +static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
8404 +{
8405 + if ((long)n < 0 || n > INT_MAX)
8406 + return n;
8407 +
8408 + if (likely(access_ok(VERIFY_WRITE, to, n))) {
8409 + if (!__builtin_constant_p(n))
8410 + check_object_size(from, n, true);
8411 + n = __copy_to_user(to, from, n);
8412 + }
8413 + return n;
8414 +}
8415 +
8416 +extern unsigned long copy_in_user(void __user *to, const void __user *from,
8417 + unsigned long n);
8418 +
8419 +#endif /* __powerpc64__ */
8420 +
8421 extern unsigned long __clear_user(void __user *addr, unsigned long size);
8422
8423 static inline unsigned long clear_user(void __user *addr, unsigned long size)
8424 diff --git a/arch/powerpc/kernel/Makefile b/arch/powerpc/kernel/Makefile
8425 index 445cb6e..4f80c5d 100644
8426 --- a/arch/powerpc/kernel/Makefile
8427 +++ b/arch/powerpc/kernel/Makefile
8428 @@ -26,6 +26,8 @@ CFLAGS_REMOVE_ftrace.o = -pg -mno-sched-epilog
8429 CFLAGS_REMOVE_time.o = -pg -mno-sched-epilog
8430 endif
8431
8432 +CFLAGS_REMOVE_prom_init.o += $(LATENT_ENTROPY_PLUGIN_CFLAGS)
8433 +
8434 obj-y := cputable.o ptrace.o syscalls.o \
8435 irq.o align.o signal_32.o pmc.o vdso.o \
8436 process.o systbl.o idle.o \
8437 diff --git a/arch/powerpc/kernel/exceptions-64e.S b/arch/powerpc/kernel/exceptions-64e.S
8438 index e775156..af2d1c0 100644
8439 --- a/arch/powerpc/kernel/exceptions-64e.S
8440 +++ b/arch/powerpc/kernel/exceptions-64e.S
8441 @@ -759,6 +759,7 @@ storage_fault_common:
8442 std r14,_DAR(r1)
8443 std r15,_DSISR(r1)
8444 addi r3,r1,STACK_FRAME_OVERHEAD
8445 + bl .save_nvgprs
8446 mr r4,r14
8447 mr r5,r15
8448 ld r14,PACA_EXGEN+EX_R14(r13)
8449 @@ -767,8 +768,7 @@ storage_fault_common:
8450 cmpdi r3,0
8451 bne- 1f
8452 b .ret_from_except_lite
8453 -1: bl .save_nvgprs
8454 - mr r5,r3
8455 +1: mr r5,r3
8456 addi r3,r1,STACK_FRAME_OVERHEAD
8457 ld r4,_DAR(r1)
8458 bl .bad_page_fault
8459 diff --git a/arch/powerpc/kernel/exceptions-64s.S b/arch/powerpc/kernel/exceptions-64s.S
8460 index 9f905e4..1d6b3d2 100644
8461 --- a/arch/powerpc/kernel/exceptions-64s.S
8462 +++ b/arch/powerpc/kernel/exceptions-64s.S
8463 @@ -1390,10 +1390,10 @@ handle_page_fault:
8464 11: ld r4,_DAR(r1)
8465 ld r5,_DSISR(r1)
8466 addi r3,r1,STACK_FRAME_OVERHEAD
8467 + bl .save_nvgprs
8468 bl .do_page_fault
8469 cmpdi r3,0
8470 beq+ 12f
8471 - bl .save_nvgprs
8472 mr r5,r3
8473 addi r3,r1,STACK_FRAME_OVERHEAD
8474 lwz r4,_DAR(r1)
8475 diff --git a/arch/powerpc/kernel/module_32.c b/arch/powerpc/kernel/module_32.c
8476 index 6cff040..74ac5d1 100644
8477 --- a/arch/powerpc/kernel/module_32.c
8478 +++ b/arch/powerpc/kernel/module_32.c
8479 @@ -161,7 +161,7 @@ int module_frob_arch_sections(Elf32_Ehdr *hdr,
8480 me->arch.core_plt_section = i;
8481 }
8482 if (!me->arch.core_plt_section || !me->arch.init_plt_section) {
8483 - printk("Module doesn't contain .plt or .init.plt sections.\n");
8484 + printk("Module %s doesn't contain .plt or .init.plt sections.\n", me->name);
8485 return -ENOEXEC;
8486 }
8487
8488 @@ -191,11 +191,16 @@ static uint32_t do_plt_call(void *location,
8489
8490 DEBUGP("Doing plt for call to 0x%x at 0x%x\n", val, (unsigned int)location);
8491 /* Init, or core PLT? */
8492 - if (location >= mod->module_core
8493 - && location < mod->module_core + mod->core_size)
8494 + if ((location >= mod->module_core_rx && location < mod->module_core_rx + mod->core_size_rx) ||
8495 + (location >= mod->module_core_rw && location < mod->module_core_rw + mod->core_size_rw))
8496 entry = (void *)sechdrs[mod->arch.core_plt_section].sh_addr;
8497 - else
8498 + else if ((location >= mod->module_init_rx && location < mod->module_init_rx + mod->init_size_rx) ||
8499 + (location >= mod->module_init_rw && location < mod->module_init_rw + mod->init_size_rw))
8500 entry = (void *)sechdrs[mod->arch.init_plt_section].sh_addr;
8501 + else {
8502 + printk(KERN_ERR "%s: invalid R_PPC_REL24 entry found\n", mod->name);
8503 + return ~0UL;
8504 + }
8505
8506 /* Find this entry, or if that fails, the next avail. entry */
8507 while (entry->jump[0]) {
8508 @@ -299,7 +304,7 @@ int apply_relocate_add(Elf32_Shdr *sechdrs,
8509 }
8510 #ifdef CONFIG_DYNAMIC_FTRACE
8511 module->arch.tramp =
8512 - do_plt_call(module->module_core,
8513 + do_plt_call(module->module_core_rx,
8514 (unsigned long)ftrace_caller,
8515 sechdrs, module);
8516 #endif
8517 diff --git a/arch/powerpc/kernel/process.c b/arch/powerpc/kernel/process.c
8518 index ea2f6a3..dbb2be3 100644
8519 --- a/arch/powerpc/kernel/process.c
8520 +++ b/arch/powerpc/kernel/process.c
8521 @@ -888,8 +888,8 @@ void show_regs(struct pt_regs * regs)
8522 * Lookup NIP late so we have the best change of getting the
8523 * above info out without failing
8524 */
8525 - printk("NIP ["REG"] %pS\n", regs->nip, (void *)regs->nip);
8526 - printk("LR ["REG"] %pS\n", regs->link, (void *)regs->link);
8527 + printk("NIP ["REG"] %pA\n", regs->nip, (void *)regs->nip);
8528 + printk("LR ["REG"] %pA\n", regs->link, (void *)regs->link);
8529 #endif
8530 show_stack(current, (unsigned long *) regs->gpr[1]);
8531 if (!user_mode(regs))
8532 @@ -1385,10 +1385,10 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
8533 newsp = stack[0];
8534 ip = stack[STACK_FRAME_LR_SAVE];
8535 if (!firstframe || ip != lr) {
8536 - printk("["REG"] ["REG"] %pS", sp, ip, (void *)ip);
8537 + printk("["REG"] ["REG"] %pA", sp, ip, (void *)ip);
8538 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
8539 if ((ip == rth || ip == mrth) && curr_frame >= 0) {
8540 - printk(" (%pS)",
8541 + printk(" (%pA)",
8542 (void *)current->ret_stack[curr_frame].ret);
8543 curr_frame--;
8544 }
8545 @@ -1408,7 +1408,7 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
8546 struct pt_regs *regs = (struct pt_regs *)
8547 (sp + STACK_FRAME_OVERHEAD);
8548 lr = regs->link;
8549 - printk("--- Exception: %lx at %pS\n LR = %pS\n",
8550 + printk("--- Exception: %lx at %pA\n LR = %pA\n",
8551 regs->trap, (void *)regs->nip, (void *)lr);
8552 firstframe = 1;
8553 }
8554 @@ -1444,58 +1444,3 @@ void notrace __ppc64_runlatch_off(void)
8555 mtspr(SPRN_CTRLT, ctrl);
8556 }
8557 #endif /* CONFIG_PPC64 */
8558 -
8559 -unsigned long arch_align_stack(unsigned long sp)
8560 -{
8561 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
8562 - sp -= get_random_int() & ~PAGE_MASK;
8563 - return sp & ~0xf;
8564 -}
8565 -
8566 -static inline unsigned long brk_rnd(void)
8567 -{
8568 - unsigned long rnd = 0;
8569 -
8570 - /* 8MB for 32bit, 1GB for 64bit */
8571 - if (is_32bit_task())
8572 - rnd = (long)(get_random_int() % (1<<(23-PAGE_SHIFT)));
8573 - else
8574 - rnd = (long)(get_random_int() % (1<<(30-PAGE_SHIFT)));
8575 -
8576 - return rnd << PAGE_SHIFT;
8577 -}
8578 -
8579 -unsigned long arch_randomize_brk(struct mm_struct *mm)
8580 -{
8581 - unsigned long base = mm->brk;
8582 - unsigned long ret;
8583 -
8584 -#ifdef CONFIG_PPC_STD_MMU_64
8585 - /*
8586 - * If we are using 1TB segments and we are allowed to randomise
8587 - * the heap, we can put it above 1TB so it is backed by a 1TB
8588 - * segment. Otherwise the heap will be in the bottom 1TB
8589 - * which always uses 256MB segments and this may result in a
8590 - * performance penalty.
8591 - */
8592 - if (!is_32bit_task() && (mmu_highuser_ssize == MMU_SEGSIZE_1T))
8593 - base = max_t(unsigned long, mm->brk, 1UL << SID_SHIFT_1T);
8594 -#endif
8595 -
8596 - ret = PAGE_ALIGN(base + brk_rnd());
8597 -
8598 - if (ret < mm->brk)
8599 - return mm->brk;
8600 -
8601 - return ret;
8602 -}
8603 -
8604 -unsigned long randomize_et_dyn(unsigned long base)
8605 -{
8606 - unsigned long ret = PAGE_ALIGN(base + brk_rnd());
8607 -
8608 - if (ret < base)
8609 - return base;
8610 -
8611 - return ret;
8612 -}
8613 diff --git a/arch/powerpc/kernel/ptrace.c b/arch/powerpc/kernel/ptrace.c
8614 index 2e3d2bf..35df241 100644
8615 --- a/arch/powerpc/kernel/ptrace.c
8616 +++ b/arch/powerpc/kernel/ptrace.c
8617 @@ -1762,6 +1762,10 @@ long arch_ptrace(struct task_struct *child, long request,
8618 return ret;
8619 }
8620
8621 +#ifdef CONFIG_GRKERNSEC_SETXID
8622 +extern void gr_delayed_cred_worker(void);
8623 +#endif
8624 +
8625 /*
8626 * We must return the syscall number to actually look up in the table.
8627 * This can be -1L to skip running any syscall at all.
8628 @@ -1774,6 +1778,11 @@ long do_syscall_trace_enter(struct pt_regs *regs)
8629
8630 secure_computing_strict(regs->gpr[0]);
8631
8632 +#ifdef CONFIG_GRKERNSEC_SETXID
8633 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
8634 + gr_delayed_cred_worker();
8635 +#endif
8636 +
8637 if (test_thread_flag(TIF_SYSCALL_TRACE) &&
8638 tracehook_report_syscall_entry(regs))
8639 /*
8640 @@ -1808,6 +1817,11 @@ void do_syscall_trace_leave(struct pt_regs *regs)
8641 {
8642 int step;
8643
8644 +#ifdef CONFIG_GRKERNSEC_SETXID
8645 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
8646 + gr_delayed_cred_worker();
8647 +#endif
8648 +
8649 audit_syscall_exit(regs);
8650
8651 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
8652 diff --git a/arch/powerpc/kernel/signal_32.c b/arch/powerpc/kernel/signal_32.c
8653 index 68027bf..b26fd31 100644
8654 --- a/arch/powerpc/kernel/signal_32.c
8655 +++ b/arch/powerpc/kernel/signal_32.c
8656 @@ -1004,7 +1004,7 @@ int handle_rt_signal32(unsigned long sig, struct k_sigaction *ka,
8657 /* Save user registers on the stack */
8658 frame = &rt_sf->uc.uc_mcontext;
8659 addr = frame;
8660 - if (vdso32_rt_sigtramp && current->mm->context.vdso_base) {
8661 + if (vdso32_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
8662 sigret = 0;
8663 tramp = current->mm->context.vdso_base + vdso32_rt_sigtramp;
8664 } else {
8665 diff --git a/arch/powerpc/kernel/signal_64.c b/arch/powerpc/kernel/signal_64.c
8666 index 448245f..b9bae83 100644
8667 --- a/arch/powerpc/kernel/signal_64.c
8668 +++ b/arch/powerpc/kernel/signal_64.c
8669 @@ -758,7 +758,7 @@ int handle_rt_signal64(int signr, struct k_sigaction *ka, siginfo_t *info,
8670 #endif
8671
8672 /* Set up to return from userspace. */
8673 - if (vdso64_rt_sigtramp && current->mm->context.vdso_base) {
8674 + if (vdso64_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
8675 regs->link = current->mm->context.vdso_base + vdso64_rt_sigtramp;
8676 } else {
8677 err |= setup_trampoline(__NR_rt_sigreturn, &frame->tramp[0]);
8678 diff --git a/arch/powerpc/kernel/traps.c b/arch/powerpc/kernel/traps.c
8679 index 907a472..4ba206f 100644
8680 --- a/arch/powerpc/kernel/traps.c
8681 +++ b/arch/powerpc/kernel/traps.c
8682 @@ -142,6 +142,8 @@ static unsigned __kprobes long oops_begin(struct pt_regs *regs)
8683 return flags;
8684 }
8685
8686 +extern void gr_handle_kernel_exploit(void);
8687 +
8688 static void __kprobes oops_end(unsigned long flags, struct pt_regs *regs,
8689 int signr)
8690 {
8691 @@ -191,6 +193,9 @@ static void __kprobes oops_end(unsigned long flags, struct pt_regs *regs,
8692 panic("Fatal exception in interrupt");
8693 if (panic_on_oops)
8694 panic("Fatal exception");
8695 +
8696 + gr_handle_kernel_exploit();
8697 +
8698 do_exit(signr);
8699 }
8700
8701 diff --git a/arch/powerpc/kernel/vdso.c b/arch/powerpc/kernel/vdso.c
8702 index 094e45c..d82b848 100644
8703 --- a/arch/powerpc/kernel/vdso.c
8704 +++ b/arch/powerpc/kernel/vdso.c
8705 @@ -35,6 +35,7 @@
8706 #include <asm/vdso.h>
8707 #include <asm/vdso_datapage.h>
8708 #include <asm/setup.h>
8709 +#include <asm/mman.h>
8710
8711 #undef DEBUG
8712
8713 @@ -221,7 +222,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
8714 vdso_base = VDSO32_MBASE;
8715 #endif
8716
8717 - current->mm->context.vdso_base = 0;
8718 + current->mm->context.vdso_base = ~0UL;
8719
8720 /* vDSO has a problem and was disabled, just don't "enable" it for the
8721 * process
8722 @@ -241,7 +242,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
8723 vdso_base = get_unmapped_area(NULL, vdso_base,
8724 (vdso_pages << PAGE_SHIFT) +
8725 ((VDSO_ALIGNMENT - 1) & PAGE_MASK),
8726 - 0, 0);
8727 + 0, MAP_PRIVATE | MAP_EXECUTABLE);
8728 if (IS_ERR_VALUE(vdso_base)) {
8729 rc = vdso_base;
8730 goto fail_mmapsem;
8731 diff --git a/arch/powerpc/kvm/powerpc.c b/arch/powerpc/kvm/powerpc.c
8732 index 9ae9768..87c3448 100644
8733 --- a/arch/powerpc/kvm/powerpc.c
8734 +++ b/arch/powerpc/kvm/powerpc.c
8735 @@ -1141,7 +1141,7 @@ void kvmppc_init_lpid(unsigned long nr_lpids_param)
8736 }
8737 EXPORT_SYMBOL_GPL(kvmppc_init_lpid);
8738
8739 -int kvm_arch_init(void *opaque)
8740 +int kvm_arch_init(const void *opaque)
8741 {
8742 return 0;
8743 }
8744 diff --git a/arch/powerpc/lib/usercopy_64.c b/arch/powerpc/lib/usercopy_64.c
8745 index 5eea6f3..5d10396 100644
8746 --- a/arch/powerpc/lib/usercopy_64.c
8747 +++ b/arch/powerpc/lib/usercopy_64.c
8748 @@ -9,22 +9,6 @@
8749 #include <linux/module.h>
8750 #include <asm/uaccess.h>
8751
8752 -unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
8753 -{
8754 - if (likely(access_ok(VERIFY_READ, from, n)))
8755 - n = __copy_from_user(to, from, n);
8756 - else
8757 - memset(to, 0, n);
8758 - return n;
8759 -}
8760 -
8761 -unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
8762 -{
8763 - if (likely(access_ok(VERIFY_WRITE, to, n)))
8764 - n = __copy_to_user(to, from, n);
8765 - return n;
8766 -}
8767 -
8768 unsigned long copy_in_user(void __user *to, const void __user *from,
8769 unsigned long n)
8770 {
8771 @@ -35,7 +19,5 @@ unsigned long copy_in_user(void __user *to, const void __user *from,
8772 return n;
8773 }
8774
8775 -EXPORT_SYMBOL(copy_from_user);
8776 -EXPORT_SYMBOL(copy_to_user);
8777 EXPORT_SYMBOL(copy_in_user);
8778
8779 diff --git a/arch/powerpc/mm/fault.c b/arch/powerpc/mm/fault.c
8780 index 51ab9e7..7d3c78b 100644
8781 --- a/arch/powerpc/mm/fault.c
8782 +++ b/arch/powerpc/mm/fault.c
8783 @@ -33,6 +33,10 @@
8784 #include <linux/magic.h>
8785 #include <linux/ratelimit.h>
8786 #include <linux/context_tracking.h>
8787 +#include <linux/slab.h>
8788 +#include <linux/pagemap.h>
8789 +#include <linux/compiler.h>
8790 +#include <linux/unistd.h>
8791
8792 #include <asm/firmware.h>
8793 #include <asm/page.h>
8794 @@ -69,6 +73,33 @@ static inline int notify_page_fault(struct pt_regs *regs)
8795 }
8796 #endif
8797
8798 +#ifdef CONFIG_PAX_PAGEEXEC
8799 +/*
8800 + * PaX: decide what to do with offenders (regs->nip = fault address)
8801 + *
8802 + * returns 1 when task should be killed
8803 + */
8804 +static int pax_handle_fetch_fault(struct pt_regs *regs)
8805 +{
8806 + return 1;
8807 +}
8808 +
8809 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
8810 +{
8811 + unsigned long i;
8812 +
8813 + printk(KERN_ERR "PAX: bytes at PC: ");
8814 + for (i = 0; i < 5; i++) {
8815 + unsigned int c;
8816 + if (get_user(c, (unsigned int __user *)pc+i))
8817 + printk(KERN_CONT "???????? ");
8818 + else
8819 + printk(KERN_CONT "%08x ", c);
8820 + }
8821 + printk("\n");
8822 +}
8823 +#endif
8824 +
8825 /*
8826 * Check whether the instruction at regs->nip is a store using
8827 * an update addressing form which will update r1.
8828 @@ -216,7 +247,7 @@ int __kprobes do_page_fault(struct pt_regs *regs, unsigned long address,
8829 * indicate errors in DSISR but can validly be set in SRR1.
8830 */
8831 if (trap == 0x400)
8832 - error_code &= 0x48200000;
8833 + error_code &= 0x58200000;
8834 else
8835 is_write = error_code & DSISR_ISSTORE;
8836 #else
8837 @@ -378,7 +409,7 @@ good_area:
8838 * "undefined". Of those that can be set, this is the only
8839 * one which seems bad.
8840 */
8841 - if (error_code & 0x10000000)
8842 + if (error_code & DSISR_GUARDED)
8843 /* Guarded storage error. */
8844 goto bad_area;
8845 #endif /* CONFIG_8xx */
8846 @@ -393,7 +424,7 @@ good_area:
8847 * processors use the same I/D cache coherency mechanism
8848 * as embedded.
8849 */
8850 - if (error_code & DSISR_PROTFAULT)
8851 + if (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))
8852 goto bad_area;
8853 #endif /* CONFIG_PPC_STD_MMU */
8854
8855 @@ -483,6 +514,23 @@ bad_area:
8856 bad_area_nosemaphore:
8857 /* User mode accesses cause a SIGSEGV */
8858 if (user_mode(regs)) {
8859 +
8860 +#ifdef CONFIG_PAX_PAGEEXEC
8861 + if (mm->pax_flags & MF_PAX_PAGEEXEC) {
8862 +#ifdef CONFIG_PPC_STD_MMU
8863 + if (is_exec && (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))) {
8864 +#else
8865 + if (is_exec && regs->nip == address) {
8866 +#endif
8867 + switch (pax_handle_fetch_fault(regs)) {
8868 + }
8869 +
8870 + pax_report_fault(regs, (void *)regs->nip, (void *)regs->gpr[PT_R1]);
8871 + do_group_exit(SIGKILL);
8872 + }
8873 + }
8874 +#endif
8875 +
8876 _exception(SIGSEGV, regs, code, address);
8877 goto bail;
8878 }
8879 diff --git a/arch/powerpc/mm/mmap.c b/arch/powerpc/mm/mmap.c
8880 index cb8bdbe..cde4bc7 100644
8881 --- a/arch/powerpc/mm/mmap.c
8882 +++ b/arch/powerpc/mm/mmap.c
8883 @@ -53,10 +53,14 @@ static inline int mmap_is_legacy(void)
8884 return sysctl_legacy_va_layout;
8885 }
8886
8887 -static unsigned long mmap_rnd(void)
8888 +static unsigned long mmap_rnd(struct mm_struct *mm)
8889 {
8890 unsigned long rnd = 0;
8891
8892 +#ifdef CONFIG_PAX_RANDMMAP
8893 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
8894 +#endif
8895 +
8896 if (current->flags & PF_RANDOMIZE) {
8897 /* 8MB for 32bit, 1GB for 64bit */
8898 if (is_32bit_task())
8899 @@ -67,7 +71,7 @@ static unsigned long mmap_rnd(void)
8900 return rnd << PAGE_SHIFT;
8901 }
8902
8903 -static inline unsigned long mmap_base(void)
8904 +static inline unsigned long mmap_base(struct mm_struct *mm)
8905 {
8906 unsigned long gap = rlimit(RLIMIT_STACK);
8907
8908 @@ -76,7 +80,7 @@ static inline unsigned long mmap_base(void)
8909 else if (gap > MAX_GAP)
8910 gap = MAX_GAP;
8911
8912 - return PAGE_ALIGN(TASK_SIZE - gap - mmap_rnd());
8913 + return PAGE_ALIGN(TASK_SIZE - gap - mmap_rnd(mm));
8914 }
8915
8916 /*
8917 @@ -91,9 +95,21 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
8918 */
8919 if (mmap_is_legacy()) {
8920 mm->mmap_base = TASK_UNMAPPED_BASE;
8921 +
8922 +#ifdef CONFIG_PAX_RANDMMAP
8923 + if (mm->pax_flags & MF_PAX_RANDMMAP)
8924 + mm->mmap_base += mm->delta_mmap;
8925 +#endif
8926 +
8927 mm->get_unmapped_area = arch_get_unmapped_area;
8928 } else {
8929 - mm->mmap_base = mmap_base();
8930 + mm->mmap_base = mmap_base(mm);
8931 +
8932 +#ifdef CONFIG_PAX_RANDMMAP
8933 + if (mm->pax_flags & MF_PAX_RANDMMAP)
8934 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
8935 +#endif
8936 +
8937 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
8938 }
8939 }
8940 diff --git a/arch/powerpc/mm/slice.c b/arch/powerpc/mm/slice.c
8941 index 7ce9cf3..a964087 100644
8942 --- a/arch/powerpc/mm/slice.c
8943 +++ b/arch/powerpc/mm/slice.c
8944 @@ -103,7 +103,7 @@ static int slice_area_is_free(struct mm_struct *mm, unsigned long addr,
8945 if ((mm->task_size - len) < addr)
8946 return 0;
8947 vma = find_vma(mm, addr);
8948 - return (!vma || (addr + len) <= vma->vm_start);
8949 + return check_heap_stack_gap(vma, addr, len, 0);
8950 }
8951
8952 static int slice_low_has_vma(struct mm_struct *mm, unsigned long slice)
8953 @@ -277,6 +277,12 @@ static unsigned long slice_find_area_bottomup(struct mm_struct *mm,
8954 info.align_offset = 0;
8955
8956 addr = TASK_UNMAPPED_BASE;
8957 +
8958 +#ifdef CONFIG_PAX_RANDMMAP
8959 + if (mm->pax_flags & MF_PAX_RANDMMAP)
8960 + addr += mm->delta_mmap;
8961 +#endif
8962 +
8963 while (addr < TASK_SIZE) {
8964 info.low_limit = addr;
8965 if (!slice_scan_available(addr, available, 1, &addr))
8966 @@ -410,6 +416,11 @@ unsigned long slice_get_unmapped_area(unsigned long addr, unsigned long len,
8967 if (fixed && addr > (mm->task_size - len))
8968 return -EINVAL;
8969
8970 +#ifdef CONFIG_PAX_RANDMMAP
8971 + if (!fixed && (mm->pax_flags & MF_PAX_RANDMMAP))
8972 + addr = 0;
8973 +#endif
8974 +
8975 /* If hint, make sure it matches our alignment restrictions */
8976 if (!fixed && addr) {
8977 addr = _ALIGN_UP(addr, 1ul << pshift);
8978 diff --git a/arch/powerpc/platforms/cell/celleb_scc_pciex.c b/arch/powerpc/platforms/cell/celleb_scc_pciex.c
8979 index 4278acf..67fd0e6 100644
8980 --- a/arch/powerpc/platforms/cell/celleb_scc_pciex.c
8981 +++ b/arch/powerpc/platforms/cell/celleb_scc_pciex.c
8982 @@ -400,8 +400,8 @@ static int scc_pciex_write_config(struct pci_bus *bus, unsigned int devfn,
8983 }
8984
8985 static struct pci_ops scc_pciex_pci_ops = {
8986 - scc_pciex_read_config,
8987 - scc_pciex_write_config,
8988 + .read = scc_pciex_read_config,
8989 + .write = scc_pciex_write_config,
8990 };
8991
8992 static void pciex_clear_intr_all(unsigned int __iomem *base)
8993 diff --git a/arch/powerpc/platforms/cell/spufs/file.c b/arch/powerpc/platforms/cell/spufs/file.c
8994 index 9098692..3d54cd1 100644
8995 --- a/arch/powerpc/platforms/cell/spufs/file.c
8996 +++ b/arch/powerpc/platforms/cell/spufs/file.c
8997 @@ -280,9 +280,9 @@ spufs_mem_mmap_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
8998 return VM_FAULT_NOPAGE;
8999 }
9000
9001 -static int spufs_mem_mmap_access(struct vm_area_struct *vma,
9002 +static ssize_t spufs_mem_mmap_access(struct vm_area_struct *vma,
9003 unsigned long address,
9004 - void *buf, int len, int write)
9005 + void *buf, size_t len, int write)
9006 {
9007 struct spu_context *ctx = vma->vm_file->private_data;
9008 unsigned long offset = address - vma->vm_start;
9009 diff --git a/arch/s390/include/asm/atomic.h b/arch/s390/include/asm/atomic.h
9010 index fa9aaf7..3f5d836 100644
9011 --- a/arch/s390/include/asm/atomic.h
9012 +++ b/arch/s390/include/asm/atomic.h
9013 @@ -398,6 +398,16 @@ static inline long long atomic64_dec_if_positive(atomic64_t *v)
9014 #define atomic64_dec_and_test(_v) (atomic64_sub_return(1, _v) == 0)
9015 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
9016
9017 +#define atomic64_read_unchecked(v) atomic64_read(v)
9018 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
9019 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
9020 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
9021 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
9022 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
9023 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
9024 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
9025 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
9026 +
9027 #define smp_mb__before_atomic_dec() smp_mb()
9028 #define smp_mb__after_atomic_dec() smp_mb()
9029 #define smp_mb__before_atomic_inc() smp_mb()
9030 diff --git a/arch/s390/include/asm/cache.h b/arch/s390/include/asm/cache.h
9031 index 4d7ccac..d03d0ad 100644
9032 --- a/arch/s390/include/asm/cache.h
9033 +++ b/arch/s390/include/asm/cache.h
9034 @@ -9,8 +9,10 @@
9035 #ifndef __ARCH_S390_CACHE_H
9036 #define __ARCH_S390_CACHE_H
9037
9038 -#define L1_CACHE_BYTES 256
9039 +#include <linux/const.h>
9040 +
9041 #define L1_CACHE_SHIFT 8
9042 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
9043 #define NET_SKB_PAD 32
9044
9045 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
9046 diff --git a/arch/s390/include/asm/elf.h b/arch/s390/include/asm/elf.h
9047 index 78f4f87..598ce39 100644
9048 --- a/arch/s390/include/asm/elf.h
9049 +++ b/arch/s390/include/asm/elf.h
9050 @@ -162,8 +162,14 @@ extern unsigned int vdso_enabled;
9051 the loader. We need to make sure that it is out of the way of the program
9052 that it will "exec", and that there is sufficient room for the brk. */
9053
9054 -extern unsigned long randomize_et_dyn(unsigned long base);
9055 -#define ELF_ET_DYN_BASE (randomize_et_dyn(STACK_TOP / 3 * 2))
9056 +#define ELF_ET_DYN_BASE (STACK_TOP / 3 * 2)
9057 +
9058 +#ifdef CONFIG_PAX_ASLR
9059 +#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_31BIT) ? 0x10000UL : 0x80000000UL)
9060 +
9061 +#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26)
9062 +#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26)
9063 +#endif
9064
9065 /* This yields a mask that user programs can use to figure out what
9066 instruction set this CPU supports. */
9067 @@ -222,9 +228,6 @@ struct linux_binprm;
9068 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
9069 int arch_setup_additional_pages(struct linux_binprm *, int);
9070
9071 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
9072 -#define arch_randomize_brk arch_randomize_brk
9073 -
9074 void *fill_cpu_elf_notes(void *ptr, struct save_area *sa);
9075
9076 #endif
9077 diff --git a/arch/s390/include/asm/exec.h b/arch/s390/include/asm/exec.h
9078 index c4a93d6..4d2a9b4 100644
9079 --- a/arch/s390/include/asm/exec.h
9080 +++ b/arch/s390/include/asm/exec.h
9081 @@ -7,6 +7,6 @@
9082 #ifndef __ASM_EXEC_H
9083 #define __ASM_EXEC_H
9084
9085 -extern unsigned long arch_align_stack(unsigned long sp);
9086 +#define arch_align_stack(x) ((x) & ~0xfUL)
9087
9088 #endif /* __ASM_EXEC_H */
9089 diff --git a/arch/s390/include/asm/uaccess.h b/arch/s390/include/asm/uaccess.h
9090 index 79330af..254cf37 100644
9091 --- a/arch/s390/include/asm/uaccess.h
9092 +++ b/arch/s390/include/asm/uaccess.h
9093 @@ -59,6 +59,7 @@ static inline int __range_ok(unsigned long addr, unsigned long size)
9094 __range_ok((unsigned long)(addr), (size)); \
9095 })
9096
9097 +#define access_ok_noprefault(type, addr, size) access_ok((type), (addr), (size))
9098 #define access_ok(type, addr, size) __access_ok(addr, size)
9099
9100 /*
9101 @@ -245,6 +246,10 @@ static inline unsigned long __must_check
9102 copy_to_user(void __user *to, const void *from, unsigned long n)
9103 {
9104 might_fault();
9105 +
9106 + if ((long)n < 0)
9107 + return n;
9108 +
9109 return __copy_to_user(to, from, n);
9110 }
9111
9112 @@ -268,6 +273,9 @@ copy_to_user(void __user *to, const void *from, unsigned long n)
9113 static inline unsigned long __must_check
9114 __copy_from_user(void *to, const void __user *from, unsigned long n)
9115 {
9116 + if ((long)n < 0)
9117 + return n;
9118 +
9119 return uaccess.copy_from_user(n, from, to);
9120 }
9121
9122 @@ -296,10 +304,14 @@ __compiletime_warning("copy_from_user() buffer size is not provably correct")
9123 static inline unsigned long __must_check
9124 copy_from_user(void *to, const void __user *from, unsigned long n)
9125 {
9126 - unsigned int sz = __compiletime_object_size(to);
9127 + size_t sz = __compiletime_object_size(to);
9128
9129 might_fault();
9130 - if (unlikely(sz != -1 && sz < n)) {
9131 +
9132 + if ((long)n < 0)
9133 + return n;
9134 +
9135 + if (unlikely(sz != (size_t)-1 && sz < n)) {
9136 copy_from_user_overflow();
9137 return n;
9138 }
9139 diff --git a/arch/s390/kernel/module.c b/arch/s390/kernel/module.c
9140 index b89b591..fd9609d 100644
9141 --- a/arch/s390/kernel/module.c
9142 +++ b/arch/s390/kernel/module.c
9143 @@ -169,11 +169,11 @@ int module_frob_arch_sections(Elf_Ehdr *hdr, Elf_Shdr *sechdrs,
9144
9145 /* Increase core size by size of got & plt and set start
9146 offsets for got and plt. */
9147 - me->core_size = ALIGN(me->core_size, 4);
9148 - me->arch.got_offset = me->core_size;
9149 - me->core_size += me->arch.got_size;
9150 - me->arch.plt_offset = me->core_size;
9151 - me->core_size += me->arch.plt_size;
9152 + me->core_size_rw = ALIGN(me->core_size_rw, 4);
9153 + me->arch.got_offset = me->core_size_rw;
9154 + me->core_size_rw += me->arch.got_size;
9155 + me->arch.plt_offset = me->core_size_rx;
9156 + me->core_size_rx += me->arch.plt_size;
9157 return 0;
9158 }
9159
9160 @@ -289,7 +289,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
9161 if (info->got_initialized == 0) {
9162 Elf_Addr *gotent;
9163
9164 - gotent = me->module_core + me->arch.got_offset +
9165 + gotent = me->module_core_rw + me->arch.got_offset +
9166 info->got_offset;
9167 *gotent = val;
9168 info->got_initialized = 1;
9169 @@ -312,7 +312,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
9170 rc = apply_rela_bits(loc, val, 0, 64, 0);
9171 else if (r_type == R_390_GOTENT ||
9172 r_type == R_390_GOTPLTENT) {
9173 - val += (Elf_Addr) me->module_core - loc;
9174 + val += (Elf_Addr) me->module_core_rw - loc;
9175 rc = apply_rela_bits(loc, val, 1, 32, 1);
9176 }
9177 break;
9178 @@ -325,7 +325,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
9179 case R_390_PLTOFF64: /* 16 bit offset from GOT to PLT. */
9180 if (info->plt_initialized == 0) {
9181 unsigned int *ip;
9182 - ip = me->module_core + me->arch.plt_offset +
9183 + ip = me->module_core_rx + me->arch.plt_offset +
9184 info->plt_offset;
9185 #ifndef CONFIG_64BIT
9186 ip[0] = 0x0d105810; /* basr 1,0; l 1,6(1); br 1 */
9187 @@ -350,7 +350,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
9188 val - loc + 0xffffUL < 0x1ffffeUL) ||
9189 (r_type == R_390_PLT32DBL &&
9190 val - loc + 0xffffffffULL < 0x1fffffffeULL)))
9191 - val = (Elf_Addr) me->module_core +
9192 + val = (Elf_Addr) me->module_core_rx +
9193 me->arch.plt_offset +
9194 info->plt_offset;
9195 val += rela->r_addend - loc;
9196 @@ -372,7 +372,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
9197 case R_390_GOTOFF32: /* 32 bit offset to GOT. */
9198 case R_390_GOTOFF64: /* 64 bit offset to GOT. */
9199 val = val + rela->r_addend -
9200 - ((Elf_Addr) me->module_core + me->arch.got_offset);
9201 + ((Elf_Addr) me->module_core_rw + me->arch.got_offset);
9202 if (r_type == R_390_GOTOFF16)
9203 rc = apply_rela_bits(loc, val, 0, 16, 0);
9204 else if (r_type == R_390_GOTOFF32)
9205 @@ -382,7 +382,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
9206 break;
9207 case R_390_GOTPC: /* 32 bit PC relative offset to GOT. */
9208 case R_390_GOTPCDBL: /* 32 bit PC rel. off. to GOT shifted by 1. */
9209 - val = (Elf_Addr) me->module_core + me->arch.got_offset +
9210 + val = (Elf_Addr) me->module_core_rw + me->arch.got_offset +
9211 rela->r_addend - loc;
9212 if (r_type == R_390_GOTPC)
9213 rc = apply_rela_bits(loc, val, 1, 32, 0);
9214 diff --git a/arch/s390/kernel/process.c b/arch/s390/kernel/process.c
9215 index 7ed0d4e..1dfc145 100644
9216 --- a/arch/s390/kernel/process.c
9217 +++ b/arch/s390/kernel/process.c
9218 @@ -242,39 +242,3 @@ unsigned long get_wchan(struct task_struct *p)
9219 }
9220 return 0;
9221 }
9222 -
9223 -unsigned long arch_align_stack(unsigned long sp)
9224 -{
9225 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
9226 - sp -= get_random_int() & ~PAGE_MASK;
9227 - return sp & ~0xf;
9228 -}
9229 -
9230 -static inline unsigned long brk_rnd(void)
9231 -{
9232 - /* 8MB for 32bit, 1GB for 64bit */
9233 - if (is_32bit_task())
9234 - return (get_random_int() & 0x7ffUL) << PAGE_SHIFT;
9235 - else
9236 - return (get_random_int() & 0x3ffffUL) << PAGE_SHIFT;
9237 -}
9238 -
9239 -unsigned long arch_randomize_brk(struct mm_struct *mm)
9240 -{
9241 - unsigned long ret = PAGE_ALIGN(mm->brk + brk_rnd());
9242 -
9243 - if (ret < mm->brk)
9244 - return mm->brk;
9245 - return ret;
9246 -}
9247 -
9248 -unsigned long randomize_et_dyn(unsigned long base)
9249 -{
9250 - unsigned long ret = PAGE_ALIGN(base + brk_rnd());
9251 -
9252 - if (!(current->flags & PF_RANDOMIZE))
9253 - return base;
9254 - if (ret < base)
9255 - return base;
9256 - return ret;
9257 -}
9258 diff --git a/arch/s390/mm/mmap.c b/arch/s390/mm/mmap.c
9259 index 9b436c2..54fbf0a 100644
9260 --- a/arch/s390/mm/mmap.c
9261 +++ b/arch/s390/mm/mmap.c
9262 @@ -95,9 +95,21 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
9263 */
9264 if (mmap_is_legacy()) {
9265 mm->mmap_base = mmap_base_legacy();
9266 +
9267 +#ifdef CONFIG_PAX_RANDMMAP
9268 + if (mm->pax_flags & MF_PAX_RANDMMAP)
9269 + mm->mmap_base += mm->delta_mmap;
9270 +#endif
9271 +
9272 mm->get_unmapped_area = arch_get_unmapped_area;
9273 } else {
9274 mm->mmap_base = mmap_base();
9275 +
9276 +#ifdef CONFIG_PAX_RANDMMAP
9277 + if (mm->pax_flags & MF_PAX_RANDMMAP)
9278 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
9279 +#endif
9280 +
9281 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
9282 }
9283 }
9284 @@ -170,9 +182,21 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
9285 */
9286 if (mmap_is_legacy()) {
9287 mm->mmap_base = mmap_base_legacy();
9288 +
9289 +#ifdef CONFIG_PAX_RANDMMAP
9290 + if (mm->pax_flags & MF_PAX_RANDMMAP)
9291 + mm->mmap_base += mm->delta_mmap;
9292 +#endif
9293 +
9294 mm->get_unmapped_area = s390_get_unmapped_area;
9295 } else {
9296 mm->mmap_base = mmap_base();
9297 +
9298 +#ifdef CONFIG_PAX_RANDMMAP
9299 + if (mm->pax_flags & MF_PAX_RANDMMAP)
9300 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
9301 +#endif
9302 +
9303 mm->get_unmapped_area = s390_get_unmapped_area_topdown;
9304 }
9305 }
9306 diff --git a/arch/score/include/asm/cache.h b/arch/score/include/asm/cache.h
9307 index ae3d59f..f65f075 100644
9308 --- a/arch/score/include/asm/cache.h
9309 +++ b/arch/score/include/asm/cache.h
9310 @@ -1,7 +1,9 @@
9311 #ifndef _ASM_SCORE_CACHE_H
9312 #define _ASM_SCORE_CACHE_H
9313
9314 +#include <linux/const.h>
9315 +
9316 #define L1_CACHE_SHIFT 4
9317 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
9318 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
9319
9320 #endif /* _ASM_SCORE_CACHE_H */
9321 diff --git a/arch/score/include/asm/exec.h b/arch/score/include/asm/exec.h
9322 index f9f3cd5..58ff438 100644
9323 --- a/arch/score/include/asm/exec.h
9324 +++ b/arch/score/include/asm/exec.h
9325 @@ -1,6 +1,6 @@
9326 #ifndef _ASM_SCORE_EXEC_H
9327 #define _ASM_SCORE_EXEC_H
9328
9329 -extern unsigned long arch_align_stack(unsigned long sp);
9330 +#define arch_align_stack(x) (x)
9331
9332 #endif /* _ASM_SCORE_EXEC_H */
9333 diff --git a/arch/score/kernel/process.c b/arch/score/kernel/process.c
9334 index a1519ad3..e8ac1ff 100644
9335 --- a/arch/score/kernel/process.c
9336 +++ b/arch/score/kernel/process.c
9337 @@ -116,8 +116,3 @@ unsigned long get_wchan(struct task_struct *task)
9338
9339 return task_pt_regs(task)->cp0_epc;
9340 }
9341 -
9342 -unsigned long arch_align_stack(unsigned long sp)
9343 -{
9344 - return sp;
9345 -}
9346 diff --git a/arch/sh/include/asm/cache.h b/arch/sh/include/asm/cache.h
9347 index ef9e555..331bd29 100644
9348 --- a/arch/sh/include/asm/cache.h
9349 +++ b/arch/sh/include/asm/cache.h
9350 @@ -9,10 +9,11 @@
9351 #define __ASM_SH_CACHE_H
9352 #ifdef __KERNEL__
9353
9354 +#include <linux/const.h>
9355 #include <linux/init.h>
9356 #include <cpu/cache.h>
9357
9358 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
9359 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
9360
9361 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
9362
9363 diff --git a/arch/sh/mm/mmap.c b/arch/sh/mm/mmap.c
9364 index 6777177..cb5e44f 100644
9365 --- a/arch/sh/mm/mmap.c
9366 +++ b/arch/sh/mm/mmap.c
9367 @@ -36,6 +36,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
9368 struct mm_struct *mm = current->mm;
9369 struct vm_area_struct *vma;
9370 int do_colour_align;
9371 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
9372 struct vm_unmapped_area_info info;
9373
9374 if (flags & MAP_FIXED) {
9375 @@ -55,6 +56,10 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
9376 if (filp || (flags & MAP_SHARED))
9377 do_colour_align = 1;
9378
9379 +#ifdef CONFIG_PAX_RANDMMAP
9380 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
9381 +#endif
9382 +
9383 if (addr) {
9384 if (do_colour_align)
9385 addr = COLOUR_ALIGN(addr, pgoff);
9386 @@ -62,14 +67,13 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
9387 addr = PAGE_ALIGN(addr);
9388
9389 vma = find_vma(mm, addr);
9390 - if (TASK_SIZE - len >= addr &&
9391 - (!vma || addr + len <= vma->vm_start))
9392 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
9393 return addr;
9394 }
9395
9396 info.flags = 0;
9397 info.length = len;
9398 - info.low_limit = TASK_UNMAPPED_BASE;
9399 + info.low_limit = mm->mmap_base;
9400 info.high_limit = TASK_SIZE;
9401 info.align_mask = do_colour_align ? (PAGE_MASK & shm_align_mask) : 0;
9402 info.align_offset = pgoff << PAGE_SHIFT;
9403 @@ -85,6 +89,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
9404 struct mm_struct *mm = current->mm;
9405 unsigned long addr = addr0;
9406 int do_colour_align;
9407 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
9408 struct vm_unmapped_area_info info;
9409
9410 if (flags & MAP_FIXED) {
9411 @@ -104,6 +109,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
9412 if (filp || (flags & MAP_SHARED))
9413 do_colour_align = 1;
9414
9415 +#ifdef CONFIG_PAX_RANDMMAP
9416 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
9417 +#endif
9418 +
9419 /* requesting a specific address */
9420 if (addr) {
9421 if (do_colour_align)
9422 @@ -112,8 +121,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
9423 addr = PAGE_ALIGN(addr);
9424
9425 vma = find_vma(mm, addr);
9426 - if (TASK_SIZE - len >= addr &&
9427 - (!vma || addr + len <= vma->vm_start))
9428 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
9429 return addr;
9430 }
9431
9432 @@ -135,6 +143,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
9433 VM_BUG_ON(addr != -ENOMEM);
9434 info.flags = 0;
9435 info.low_limit = TASK_UNMAPPED_BASE;
9436 +
9437 +#ifdef CONFIG_PAX_RANDMMAP
9438 + if (mm->pax_flags & MF_PAX_RANDMMAP)
9439 + info.low_limit += mm->delta_mmap;
9440 +#endif
9441 +
9442 info.high_limit = TASK_SIZE;
9443 addr = vm_unmapped_area(&info);
9444 }
9445 diff --git a/arch/sparc/include/asm/atomic_64.h b/arch/sparc/include/asm/atomic_64.h
9446 index be56a24..443328f 100644
9447 --- a/arch/sparc/include/asm/atomic_64.h
9448 +++ b/arch/sparc/include/asm/atomic_64.h
9449 @@ -14,18 +14,40 @@
9450 #define ATOMIC64_INIT(i) { (i) }
9451
9452 #define atomic_read(v) (*(volatile int *)&(v)->counter)
9453 +static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
9454 +{
9455 + return v->counter;
9456 +}
9457 #define atomic64_read(v) (*(volatile long *)&(v)->counter)
9458 +static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
9459 +{
9460 + return v->counter;
9461 +}
9462
9463 #define atomic_set(v, i) (((v)->counter) = i)
9464 +static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
9465 +{
9466 + v->counter = i;
9467 +}
9468 #define atomic64_set(v, i) (((v)->counter) = i)
9469 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
9470 +{
9471 + v->counter = i;
9472 +}
9473
9474 extern void atomic_add(int, atomic_t *);
9475 +extern void atomic_add_unchecked(int, atomic_unchecked_t *);
9476 extern void atomic64_add(long, atomic64_t *);
9477 +extern void atomic64_add_unchecked(long, atomic64_unchecked_t *);
9478 extern void atomic_sub(int, atomic_t *);
9479 +extern void atomic_sub_unchecked(int, atomic_unchecked_t *);
9480 extern void atomic64_sub(long, atomic64_t *);
9481 +extern void atomic64_sub_unchecked(long, atomic64_unchecked_t *);
9482
9483 extern int atomic_add_ret(int, atomic_t *);
9484 +extern int atomic_add_ret_unchecked(int, atomic_unchecked_t *);
9485 extern long atomic64_add_ret(long, atomic64_t *);
9486 +extern long atomic64_add_ret_unchecked(long, atomic64_unchecked_t *);
9487 extern int atomic_sub_ret(int, atomic_t *);
9488 extern long atomic64_sub_ret(long, atomic64_t *);
9489
9490 @@ -33,13 +55,29 @@ extern long atomic64_sub_ret(long, atomic64_t *);
9491 #define atomic64_dec_return(v) atomic64_sub_ret(1, v)
9492
9493 #define atomic_inc_return(v) atomic_add_ret(1, v)
9494 +static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
9495 +{
9496 + return atomic_add_ret_unchecked(1, v);
9497 +}
9498 #define atomic64_inc_return(v) atomic64_add_ret(1, v)
9499 +static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
9500 +{
9501 + return atomic64_add_ret_unchecked(1, v);
9502 +}
9503
9504 #define atomic_sub_return(i, v) atomic_sub_ret(i, v)
9505 #define atomic64_sub_return(i, v) atomic64_sub_ret(i, v)
9506
9507 #define atomic_add_return(i, v) atomic_add_ret(i, v)
9508 +static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
9509 +{
9510 + return atomic_add_ret_unchecked(i, v);
9511 +}
9512 #define atomic64_add_return(i, v) atomic64_add_ret(i, v)
9513 +static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
9514 +{
9515 + return atomic64_add_ret_unchecked(i, v);
9516 +}
9517
9518 /*
9519 * atomic_inc_and_test - increment and test
9520 @@ -50,6 +88,10 @@ extern long atomic64_sub_ret(long, atomic64_t *);
9521 * other cases.
9522 */
9523 #define atomic_inc_and_test(v) (atomic_inc_return(v) == 0)
9524 +static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
9525 +{
9526 + return atomic_inc_return_unchecked(v) == 0;
9527 +}
9528 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
9529
9530 #define atomic_sub_and_test(i, v) (atomic_sub_ret(i, v) == 0)
9531 @@ -59,25 +101,60 @@ extern long atomic64_sub_ret(long, atomic64_t *);
9532 #define atomic64_dec_and_test(v) (atomic64_sub_ret(1, v) == 0)
9533
9534 #define atomic_inc(v) atomic_add(1, v)
9535 +static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
9536 +{
9537 + atomic_add_unchecked(1, v);
9538 +}
9539 #define atomic64_inc(v) atomic64_add(1, v)
9540 +static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
9541 +{
9542 + atomic64_add_unchecked(1, v);
9543 +}
9544
9545 #define atomic_dec(v) atomic_sub(1, v)
9546 +static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
9547 +{
9548 + atomic_sub_unchecked(1, v);
9549 +}
9550 #define atomic64_dec(v) atomic64_sub(1, v)
9551 +static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
9552 +{
9553 + atomic64_sub_unchecked(1, v);
9554 +}
9555
9556 #define atomic_add_negative(i, v) (atomic_add_ret(i, v) < 0)
9557 #define atomic64_add_negative(i, v) (atomic64_add_ret(i, v) < 0)
9558
9559 #define atomic_cmpxchg(v, o, n) (cmpxchg(&((v)->counter), (o), (n)))
9560 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
9561 +{
9562 + return cmpxchg(&v->counter, old, new);
9563 +}
9564 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
9565 +static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
9566 +{
9567 + return xchg(&v->counter, new);
9568 +}
9569
9570 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
9571 {
9572 - int c, old;
9573 + int c, old, new;
9574 c = atomic_read(v);
9575 for (;;) {
9576 - if (unlikely(c == (u)))
9577 + if (unlikely(c == u))
9578 break;
9579 - old = atomic_cmpxchg((v), c, c + (a));
9580 +
9581 + asm volatile("addcc %2, %0, %0\n"
9582 +
9583 +#ifdef CONFIG_PAX_REFCOUNT
9584 + "tvs %%icc, 6\n"
9585 +#endif
9586 +
9587 + : "=r" (new)
9588 + : "0" (c), "ir" (a)
9589 + : "cc");
9590 +
9591 + old = atomic_cmpxchg(v, c, new);
9592 if (likely(old == c))
9593 break;
9594 c = old;
9595 @@ -88,20 +165,35 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
9596 #define atomic64_cmpxchg(v, o, n) \
9597 ((__typeof__((v)->counter))cmpxchg(&((v)->counter), (o), (n)))
9598 #define atomic64_xchg(v, new) (xchg(&((v)->counter), new))
9599 +static inline long atomic64_xchg_unchecked(atomic64_unchecked_t *v, long new)
9600 +{
9601 + return xchg(&v->counter, new);
9602 +}
9603
9604 static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
9605 {
9606 - long c, old;
9607 + long c, old, new;
9608 c = atomic64_read(v);
9609 for (;;) {
9610 - if (unlikely(c == (u)))
9611 + if (unlikely(c == u))
9612 break;
9613 - old = atomic64_cmpxchg((v), c, c + (a));
9614 +
9615 + asm volatile("addcc %2, %0, %0\n"
9616 +
9617 +#ifdef CONFIG_PAX_REFCOUNT
9618 + "tvs %%xcc, 6\n"
9619 +#endif
9620 +
9621 + : "=r" (new)
9622 + : "0" (c), "ir" (a)
9623 + : "cc");
9624 +
9625 + old = atomic64_cmpxchg(v, c, new);
9626 if (likely(old == c))
9627 break;
9628 c = old;
9629 }
9630 - return c != (u);
9631 + return c != u;
9632 }
9633
9634 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
9635 diff --git a/arch/sparc/include/asm/cache.h b/arch/sparc/include/asm/cache.h
9636 index 5bb6991..5c2132e 100644
9637 --- a/arch/sparc/include/asm/cache.h
9638 +++ b/arch/sparc/include/asm/cache.h
9639 @@ -7,10 +7,12 @@
9640 #ifndef _SPARC_CACHE_H
9641 #define _SPARC_CACHE_H
9642
9643 +#include <linux/const.h>
9644 +
9645 #define ARCH_SLAB_MINALIGN __alignof__(unsigned long long)
9646
9647 #define L1_CACHE_SHIFT 5
9648 -#define L1_CACHE_BYTES 32
9649 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
9650
9651 #ifdef CONFIG_SPARC32
9652 #define SMP_CACHE_BYTES_SHIFT 5
9653 diff --git a/arch/sparc/include/asm/elf_32.h b/arch/sparc/include/asm/elf_32.h
9654 index a24e41f..47677ff 100644
9655 --- a/arch/sparc/include/asm/elf_32.h
9656 +++ b/arch/sparc/include/asm/elf_32.h
9657 @@ -114,6 +114,13 @@ typedef struct {
9658
9659 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE)
9660
9661 +#ifdef CONFIG_PAX_ASLR
9662 +#define PAX_ELF_ET_DYN_BASE 0x10000UL
9663 +
9664 +#define PAX_DELTA_MMAP_LEN 16
9665 +#define PAX_DELTA_STACK_LEN 16
9666 +#endif
9667 +
9668 /* This yields a mask that user programs can use to figure out what
9669 instruction set this cpu supports. This can NOT be done in userspace
9670 on Sparc. */
9671 diff --git a/arch/sparc/include/asm/elf_64.h b/arch/sparc/include/asm/elf_64.h
9672 index 370ca1e..d4f4a98 100644
9673 --- a/arch/sparc/include/asm/elf_64.h
9674 +++ b/arch/sparc/include/asm/elf_64.h
9675 @@ -189,6 +189,13 @@ typedef struct {
9676 #define ELF_ET_DYN_BASE 0x0000010000000000UL
9677 #define COMPAT_ELF_ET_DYN_BASE 0x0000000070000000UL
9678
9679 +#ifdef CONFIG_PAX_ASLR
9680 +#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_32BIT) ? 0x10000UL : 0x100000UL)
9681 +
9682 +#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_32BIT) ? 14 : 28)
9683 +#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_32BIT) ? 15 : 29)
9684 +#endif
9685 +
9686 extern unsigned long sparc64_elf_hwcap;
9687 #define ELF_HWCAP sparc64_elf_hwcap
9688
9689 diff --git a/arch/sparc/include/asm/pgalloc_32.h b/arch/sparc/include/asm/pgalloc_32.h
9690 index 9b1c36d..209298b 100644
9691 --- a/arch/sparc/include/asm/pgalloc_32.h
9692 +++ b/arch/sparc/include/asm/pgalloc_32.h
9693 @@ -33,6 +33,7 @@ static inline void pgd_set(pgd_t * pgdp, pmd_t * pmdp)
9694 }
9695
9696 #define pgd_populate(MM, PGD, PMD) pgd_set(PGD, PMD)
9697 +#define pgd_populate_kernel(MM, PGD, PMD) pgd_populate((MM), (PGD), (PMD))
9698
9699 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm,
9700 unsigned long address)
9701 diff --git a/arch/sparc/include/asm/pgalloc_64.h b/arch/sparc/include/asm/pgalloc_64.h
9702 index bcfe063..b333142 100644
9703 --- a/arch/sparc/include/asm/pgalloc_64.h
9704 +++ b/arch/sparc/include/asm/pgalloc_64.h
9705 @@ -26,6 +26,7 @@ static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
9706 }
9707
9708 #define pud_populate(MM, PUD, PMD) pud_set(PUD, PMD)
9709 +#define pud_populate_kernel(MM, PUD, PMD) pud_populate((MM), (PUD), (PMD))
9710
9711 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr)
9712 {
9713 diff --git a/arch/sparc/include/asm/pgtable.h b/arch/sparc/include/asm/pgtable.h
9714 index 59ba6f6..4518128 100644
9715 --- a/arch/sparc/include/asm/pgtable.h
9716 +++ b/arch/sparc/include/asm/pgtable.h
9717 @@ -5,4 +5,8 @@
9718 #else
9719 #include <asm/pgtable_32.h>
9720 #endif
9721 +
9722 +#define ktla_ktva(addr) (addr)
9723 +#define ktva_ktla(addr) (addr)
9724 +
9725 #endif
9726 diff --git a/arch/sparc/include/asm/pgtable_32.h b/arch/sparc/include/asm/pgtable_32.h
9727 index 502f632..da1917f 100644
9728 --- a/arch/sparc/include/asm/pgtable_32.h
9729 +++ b/arch/sparc/include/asm/pgtable_32.h
9730 @@ -50,6 +50,9 @@ extern unsigned long calc_highpages(void);
9731 #define PAGE_SHARED SRMMU_PAGE_SHARED
9732 #define PAGE_COPY SRMMU_PAGE_COPY
9733 #define PAGE_READONLY SRMMU_PAGE_RDONLY
9734 +#define PAGE_SHARED_NOEXEC SRMMU_PAGE_SHARED_NOEXEC
9735 +#define PAGE_COPY_NOEXEC SRMMU_PAGE_COPY_NOEXEC
9736 +#define PAGE_READONLY_NOEXEC SRMMU_PAGE_RDONLY_NOEXEC
9737 #define PAGE_KERNEL SRMMU_PAGE_KERNEL
9738
9739 /* Top-level page directory - dummy used by init-mm.
9740 @@ -62,18 +65,18 @@ extern unsigned long ptr_in_current_pgd;
9741
9742 /* xwr */
9743 #define __P000 PAGE_NONE
9744 -#define __P001 PAGE_READONLY
9745 -#define __P010 PAGE_COPY
9746 -#define __P011 PAGE_COPY
9747 +#define __P001 PAGE_READONLY_NOEXEC
9748 +#define __P010 PAGE_COPY_NOEXEC
9749 +#define __P011 PAGE_COPY_NOEXEC
9750 #define __P100 PAGE_READONLY
9751 #define __P101 PAGE_READONLY
9752 #define __P110 PAGE_COPY
9753 #define __P111 PAGE_COPY
9754
9755 #define __S000 PAGE_NONE
9756 -#define __S001 PAGE_READONLY
9757 -#define __S010 PAGE_SHARED
9758 -#define __S011 PAGE_SHARED
9759 +#define __S001 PAGE_READONLY_NOEXEC
9760 +#define __S010 PAGE_SHARED_NOEXEC
9761 +#define __S011 PAGE_SHARED_NOEXEC
9762 #define __S100 PAGE_READONLY
9763 #define __S101 PAGE_READONLY
9764 #define __S110 PAGE_SHARED
9765 diff --git a/arch/sparc/include/asm/pgtsrmmu.h b/arch/sparc/include/asm/pgtsrmmu.h
9766 index 79da178..c2eede8 100644
9767 --- a/arch/sparc/include/asm/pgtsrmmu.h
9768 +++ b/arch/sparc/include/asm/pgtsrmmu.h
9769 @@ -115,6 +115,11 @@
9770 SRMMU_EXEC | SRMMU_REF)
9771 #define SRMMU_PAGE_RDONLY __pgprot(SRMMU_VALID | SRMMU_CACHE | \
9772 SRMMU_EXEC | SRMMU_REF)
9773 +
9774 +#define SRMMU_PAGE_SHARED_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_WRITE | SRMMU_REF)
9775 +#define SRMMU_PAGE_COPY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
9776 +#define SRMMU_PAGE_RDONLY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
9777 +
9778 #define SRMMU_PAGE_KERNEL __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_PRIV | \
9779 SRMMU_DIRTY | SRMMU_REF)
9780
9781 diff --git a/arch/sparc/include/asm/spinlock_64.h b/arch/sparc/include/asm/spinlock_64.h
9782 index 9689176..63c18ea 100644
9783 --- a/arch/sparc/include/asm/spinlock_64.h
9784 +++ b/arch/sparc/include/asm/spinlock_64.h
9785 @@ -92,14 +92,19 @@ static inline void arch_spin_lock_flags(arch_spinlock_t *lock, unsigned long fla
9786
9787 /* Multi-reader locks, these are much saner than the 32-bit Sparc ones... */
9788
9789 -static void inline arch_read_lock(arch_rwlock_t *lock)
9790 +static inline void arch_read_lock(arch_rwlock_t *lock)
9791 {
9792 unsigned long tmp1, tmp2;
9793
9794 __asm__ __volatile__ (
9795 "1: ldsw [%2], %0\n"
9796 " brlz,pn %0, 2f\n"
9797 -"4: add %0, 1, %1\n"
9798 +"4: addcc %0, 1, %1\n"
9799 +
9800 +#ifdef CONFIG_PAX_REFCOUNT
9801 +" tvs %%icc, 6\n"
9802 +#endif
9803 +
9804 " cas [%2], %0, %1\n"
9805 " cmp %0, %1\n"
9806 " bne,pn %%icc, 1b\n"
9807 @@ -112,10 +117,10 @@ static void inline arch_read_lock(arch_rwlock_t *lock)
9808 " .previous"
9809 : "=&r" (tmp1), "=&r" (tmp2)
9810 : "r" (lock)
9811 - : "memory");
9812 + : "memory", "cc");
9813 }
9814
9815 -static int inline arch_read_trylock(arch_rwlock_t *lock)
9816 +static inline int arch_read_trylock(arch_rwlock_t *lock)
9817 {
9818 int tmp1, tmp2;
9819
9820 @@ -123,7 +128,12 @@ static int inline arch_read_trylock(arch_rwlock_t *lock)
9821 "1: ldsw [%2], %0\n"
9822 " brlz,a,pn %0, 2f\n"
9823 " mov 0, %0\n"
9824 -" add %0, 1, %1\n"
9825 +" addcc %0, 1, %1\n"
9826 +
9827 +#ifdef CONFIG_PAX_REFCOUNT
9828 +" tvs %%icc, 6\n"
9829 +#endif
9830 +
9831 " cas [%2], %0, %1\n"
9832 " cmp %0, %1\n"
9833 " bne,pn %%icc, 1b\n"
9834 @@ -136,13 +146,18 @@ static int inline arch_read_trylock(arch_rwlock_t *lock)
9835 return tmp1;
9836 }
9837
9838 -static void inline arch_read_unlock(arch_rwlock_t *lock)
9839 +static inline void arch_read_unlock(arch_rwlock_t *lock)
9840 {
9841 unsigned long tmp1, tmp2;
9842
9843 __asm__ __volatile__(
9844 "1: lduw [%2], %0\n"
9845 -" sub %0, 1, %1\n"
9846 +" subcc %0, 1, %1\n"
9847 +
9848 +#ifdef CONFIG_PAX_REFCOUNT
9849 +" tvs %%icc, 6\n"
9850 +#endif
9851 +
9852 " cas [%2], %0, %1\n"
9853 " cmp %0, %1\n"
9854 " bne,pn %%xcc, 1b\n"
9855 @@ -152,7 +167,7 @@ static void inline arch_read_unlock(arch_rwlock_t *lock)
9856 : "memory");
9857 }
9858
9859 -static void inline arch_write_lock(arch_rwlock_t *lock)
9860 +static inline void arch_write_lock(arch_rwlock_t *lock)
9861 {
9862 unsigned long mask, tmp1, tmp2;
9863
9864 @@ -177,7 +192,7 @@ static void inline arch_write_lock(arch_rwlock_t *lock)
9865 : "memory");
9866 }
9867
9868 -static void inline arch_write_unlock(arch_rwlock_t *lock)
9869 +static inline void arch_write_unlock(arch_rwlock_t *lock)
9870 {
9871 __asm__ __volatile__(
9872 " stw %%g0, [%0]"
9873 @@ -186,7 +201,7 @@ static void inline arch_write_unlock(arch_rwlock_t *lock)
9874 : "memory");
9875 }
9876
9877 -static int inline arch_write_trylock(arch_rwlock_t *lock)
9878 +static inline int arch_write_trylock(arch_rwlock_t *lock)
9879 {
9880 unsigned long mask, tmp1, tmp2, result;
9881
9882 diff --git a/arch/sparc/include/asm/thread_info_32.h b/arch/sparc/include/asm/thread_info_32.h
9883 index 96efa7a..16858bf 100644
9884 --- a/arch/sparc/include/asm/thread_info_32.h
9885 +++ b/arch/sparc/include/asm/thread_info_32.h
9886 @@ -49,6 +49,8 @@ struct thread_info {
9887 unsigned long w_saved;
9888
9889 struct restart_block restart_block;
9890 +
9891 + unsigned long lowest_stack;
9892 };
9893
9894 /*
9895 diff --git a/arch/sparc/include/asm/thread_info_64.h b/arch/sparc/include/asm/thread_info_64.h
9896 index a5f01ac..703b554 100644
9897 --- a/arch/sparc/include/asm/thread_info_64.h
9898 +++ b/arch/sparc/include/asm/thread_info_64.h
9899 @@ -63,6 +63,8 @@ struct thread_info {
9900 struct pt_regs *kern_una_regs;
9901 unsigned int kern_una_insn;
9902
9903 + unsigned long lowest_stack;
9904 +
9905 unsigned long fpregs[0] __attribute__ ((aligned(64)));
9906 };
9907
9908 @@ -188,12 +190,13 @@ register struct thread_info *current_thread_info_reg asm("g6");
9909 #define TIF_NEED_RESCHED 3 /* rescheduling necessary */
9910 /* flag bit 4 is available */
9911 #define TIF_UNALIGNED 5 /* allowed to do unaligned accesses */
9912 -/* flag bit 6 is available */
9913 +#define TIF_GRSEC_SETXID 6 /* update credentials on syscall entry/exit */
9914 #define TIF_32BIT 7 /* 32-bit binary */
9915 #define TIF_NOHZ 8 /* in adaptive nohz mode */
9916 #define TIF_SECCOMP 9 /* secure computing */
9917 #define TIF_SYSCALL_AUDIT 10 /* syscall auditing active */
9918 #define TIF_SYSCALL_TRACEPOINT 11 /* syscall tracepoint instrumentation */
9919 +
9920 /* NOTE: Thread flags >= 12 should be ones we have no interest
9921 * in using in assembly, else we can't use the mask as
9922 * an immediate value in instructions such as andcc.
9923 @@ -213,12 +216,18 @@ register struct thread_info *current_thread_info_reg asm("g6");
9924 #define _TIF_SYSCALL_AUDIT (1<<TIF_SYSCALL_AUDIT)
9925 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
9926 #define _TIF_POLLING_NRFLAG (1<<TIF_POLLING_NRFLAG)
9927 +#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
9928
9929 #define _TIF_USER_WORK_MASK ((0xff << TI_FLAG_WSAVED_SHIFT) | \
9930 _TIF_DO_NOTIFY_RESUME_MASK | \
9931 _TIF_NEED_RESCHED)
9932 #define _TIF_DO_NOTIFY_RESUME_MASK (_TIF_NOTIFY_RESUME | _TIF_SIGPENDING)
9933
9934 +#define _TIF_WORK_SYSCALL \
9935 + (_TIF_SYSCALL_TRACE | _TIF_SECCOMP | _TIF_SYSCALL_AUDIT | \
9936 + _TIF_SYSCALL_TRACEPOINT | _TIF_NOHZ | _TIF_GRSEC_SETXID)
9937 +
9938 +
9939 /*
9940 * Thread-synchronous status.
9941 *
9942 diff --git a/arch/sparc/include/asm/uaccess.h b/arch/sparc/include/asm/uaccess.h
9943 index 0167d26..767bb0c 100644
9944 --- a/arch/sparc/include/asm/uaccess.h
9945 +++ b/arch/sparc/include/asm/uaccess.h
9946 @@ -1,5 +1,6 @@
9947 #ifndef ___ASM_SPARC_UACCESS_H
9948 #define ___ASM_SPARC_UACCESS_H
9949 +
9950 #if defined(__sparc__) && defined(__arch64__)
9951 #include <asm/uaccess_64.h>
9952 #else
9953 diff --git a/arch/sparc/include/asm/uaccess_32.h b/arch/sparc/include/asm/uaccess_32.h
9954 index 53a28dd..50c38c3 100644
9955 --- a/arch/sparc/include/asm/uaccess_32.h
9956 +++ b/arch/sparc/include/asm/uaccess_32.h
9957 @@ -250,27 +250,46 @@ extern unsigned long __copy_user(void __user *to, const void __user *from, unsig
9958
9959 static inline unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
9960 {
9961 - if (n && __access_ok((unsigned long) to, n))
9962 + if ((long)n < 0)
9963 + return n;
9964 +
9965 + if (n && __access_ok((unsigned long) to, n)) {
9966 + if (!__builtin_constant_p(n))
9967 + check_object_size(from, n, true);
9968 return __copy_user(to, (__force void __user *) from, n);
9969 - else
9970 + } else
9971 return n;
9972 }
9973
9974 static inline unsigned long __copy_to_user(void __user *to, const void *from, unsigned long n)
9975 {
9976 + if ((long)n < 0)
9977 + return n;
9978 +
9979 + if (!__builtin_constant_p(n))
9980 + check_object_size(from, n, true);
9981 +
9982 return __copy_user(to, (__force void __user *) from, n);
9983 }
9984
9985 static inline unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
9986 {
9987 - if (n && __access_ok((unsigned long) from, n))
9988 + if ((long)n < 0)
9989 + return n;
9990 +
9991 + if (n && __access_ok((unsigned long) from, n)) {
9992 + if (!__builtin_constant_p(n))
9993 + check_object_size(to, n, false);
9994 return __copy_user((__force void __user *) to, from, n);
9995 - else
9996 + } else
9997 return n;
9998 }
9999
10000 static inline unsigned long __copy_from_user(void *to, const void __user *from, unsigned long n)
10001 {
10002 + if ((long)n < 0)
10003 + return n;
10004 +
10005 return __copy_user((__force void __user *) to, from, n);
10006 }
10007
10008 diff --git a/arch/sparc/include/asm/uaccess_64.h b/arch/sparc/include/asm/uaccess_64.h
10009 index ad7e178..c9e7423 100644
10010 --- a/arch/sparc/include/asm/uaccess_64.h
10011 +++ b/arch/sparc/include/asm/uaccess_64.h
10012 @@ -10,6 +10,7 @@
10013 #include <linux/compiler.h>
10014 #include <linux/string.h>
10015 #include <linux/thread_info.h>
10016 +#include <linux/kernel.h>
10017 #include <asm/asi.h>
10018 #include <asm/spitfire.h>
10019 #include <asm-generic/uaccess-unaligned.h>
10020 @@ -214,8 +215,15 @@ extern unsigned long copy_from_user_fixup(void *to, const void __user *from,
10021 static inline unsigned long __must_check
10022 copy_from_user(void *to, const void __user *from, unsigned long size)
10023 {
10024 - unsigned long ret = ___copy_from_user(to, from, size);
10025 + unsigned long ret;
10026
10027 + if ((long)size < 0 || size > INT_MAX)
10028 + return size;
10029 +
10030 + if (!__builtin_constant_p(size))
10031 + check_object_size(to, size, false);
10032 +
10033 + ret = ___copy_from_user(to, from, size);
10034 if (unlikely(ret))
10035 ret = copy_from_user_fixup(to, from, size);
10036
10037 @@ -231,8 +239,15 @@ extern unsigned long copy_to_user_fixup(void __user *to, const void *from,
10038 static inline unsigned long __must_check
10039 copy_to_user(void __user *to, const void *from, unsigned long size)
10040 {
10041 - unsigned long ret = ___copy_to_user(to, from, size);
10042 + unsigned long ret;
10043
10044 + if ((long)size < 0 || size > INT_MAX)
10045 + return size;
10046 +
10047 + if (!__builtin_constant_p(size))
10048 + check_object_size(from, size, true);
10049 +
10050 + ret = ___copy_to_user(to, from, size);
10051 if (unlikely(ret))
10052 ret = copy_to_user_fixup(to, from, size);
10053 return ret;
10054 diff --git a/arch/sparc/kernel/Makefile b/arch/sparc/kernel/Makefile
10055 index d15cc17..d0ae796 100644
10056 --- a/arch/sparc/kernel/Makefile
10057 +++ b/arch/sparc/kernel/Makefile
10058 @@ -4,7 +4,7 @@
10059 #
10060
10061 asflags-y := -ansi
10062 -ccflags-y := -Werror
10063 +#ccflags-y := -Werror
10064
10065 extra-y := head_$(BITS).o
10066
10067 diff --git a/arch/sparc/kernel/process_32.c b/arch/sparc/kernel/process_32.c
10068 index fdd819d..5af08c8 100644
10069 --- a/arch/sparc/kernel/process_32.c
10070 +++ b/arch/sparc/kernel/process_32.c
10071 @@ -116,14 +116,14 @@ void show_regs(struct pt_regs *r)
10072
10073 printk("PSR: %08lx PC: %08lx NPC: %08lx Y: %08lx %s\n",
10074 r->psr, r->pc, r->npc, r->y, print_tainted());
10075 - printk("PC: <%pS>\n", (void *) r->pc);
10076 + printk("PC: <%pA>\n", (void *) r->pc);
10077 printk("%%G: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
10078 r->u_regs[0], r->u_regs[1], r->u_regs[2], r->u_regs[3],
10079 r->u_regs[4], r->u_regs[5], r->u_regs[6], r->u_regs[7]);
10080 printk("%%O: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
10081 r->u_regs[8], r->u_regs[9], r->u_regs[10], r->u_regs[11],
10082 r->u_regs[12], r->u_regs[13], r->u_regs[14], r->u_regs[15]);
10083 - printk("RPC: <%pS>\n", (void *) r->u_regs[15]);
10084 + printk("RPC: <%pA>\n", (void *) r->u_regs[15]);
10085
10086 printk("%%L: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
10087 rw->locals[0], rw->locals[1], rw->locals[2], rw->locals[3],
10088 @@ -160,7 +160,7 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
10089 rw = (struct reg_window32 *) fp;
10090 pc = rw->ins[7];
10091 printk("[%08lx : ", pc);
10092 - printk("%pS ] ", (void *) pc);
10093 + printk("%pA ] ", (void *) pc);
10094 fp = rw->ins[6];
10095 } while (++count < 16);
10096 printk("\n");
10097 diff --git a/arch/sparc/kernel/process_64.c b/arch/sparc/kernel/process_64.c
10098 index 32a280e..84fc6a9 100644
10099 --- a/arch/sparc/kernel/process_64.c
10100 +++ b/arch/sparc/kernel/process_64.c
10101 @@ -159,7 +159,7 @@ static void show_regwindow(struct pt_regs *regs)
10102 printk("i4: %016lx i5: %016lx i6: %016lx i7: %016lx\n",
10103 rwk->ins[4], rwk->ins[5], rwk->ins[6], rwk->ins[7]);
10104 if (regs->tstate & TSTATE_PRIV)
10105 - printk("I7: <%pS>\n", (void *) rwk->ins[7]);
10106 + printk("I7: <%pA>\n", (void *) rwk->ins[7]);
10107 }
10108
10109 void show_regs(struct pt_regs *regs)
10110 @@ -168,7 +168,7 @@ void show_regs(struct pt_regs *regs)
10111
10112 printk("TSTATE: %016lx TPC: %016lx TNPC: %016lx Y: %08x %s\n", regs->tstate,
10113 regs->tpc, regs->tnpc, regs->y, print_tainted());
10114 - printk("TPC: <%pS>\n", (void *) regs->tpc);
10115 + printk("TPC: <%pA>\n", (void *) regs->tpc);
10116 printk("g0: %016lx g1: %016lx g2: %016lx g3: %016lx\n",
10117 regs->u_regs[0], regs->u_regs[1], regs->u_regs[2],
10118 regs->u_regs[3]);
10119 @@ -181,7 +181,7 @@ void show_regs(struct pt_regs *regs)
10120 printk("o4: %016lx o5: %016lx sp: %016lx ret_pc: %016lx\n",
10121 regs->u_regs[12], regs->u_regs[13], regs->u_regs[14],
10122 regs->u_regs[15]);
10123 - printk("RPC: <%pS>\n", (void *) regs->u_regs[15]);
10124 + printk("RPC: <%pA>\n", (void *) regs->u_regs[15]);
10125 show_regwindow(regs);
10126 show_stack(current, (unsigned long *) regs->u_regs[UREG_FP]);
10127 }
10128 @@ -270,7 +270,7 @@ void arch_trigger_all_cpu_backtrace(void)
10129 ((tp && tp->task) ? tp->task->pid : -1));
10130
10131 if (gp->tstate & TSTATE_PRIV) {
10132 - printk(" TPC[%pS] O7[%pS] I7[%pS] RPC[%pS]\n",
10133 + printk(" TPC[%pA] O7[%pA] I7[%pA] RPC[%pA]\n",
10134 (void *) gp->tpc,
10135 (void *) gp->o7,
10136 (void *) gp->i7,
10137 diff --git a/arch/sparc/kernel/prom_common.c b/arch/sparc/kernel/prom_common.c
10138 index 79cc0d1..ec62734 100644
10139 --- a/arch/sparc/kernel/prom_common.c
10140 +++ b/arch/sparc/kernel/prom_common.c
10141 @@ -144,7 +144,7 @@ static int __init prom_common_nextprop(phandle node, char *prev, char *buf)
10142
10143 unsigned int prom_early_allocated __initdata;
10144
10145 -static struct of_pdt_ops prom_sparc_ops __initdata = {
10146 +static struct of_pdt_ops prom_sparc_ops __initconst = {
10147 .nextprop = prom_common_nextprop,
10148 .getproplen = prom_getproplen,
10149 .getproperty = prom_getproperty,
10150 diff --git a/arch/sparc/kernel/ptrace_64.c b/arch/sparc/kernel/ptrace_64.c
10151 index c13c9f2..d572c34 100644
10152 --- a/arch/sparc/kernel/ptrace_64.c
10153 +++ b/arch/sparc/kernel/ptrace_64.c
10154 @@ -1060,6 +1060,10 @@ long arch_ptrace(struct task_struct *child, long request,
10155 return ret;
10156 }
10157
10158 +#ifdef CONFIG_GRKERNSEC_SETXID
10159 +extern void gr_delayed_cred_worker(void);
10160 +#endif
10161 +
10162 asmlinkage int syscall_trace_enter(struct pt_regs *regs)
10163 {
10164 int ret = 0;
10165 @@ -1070,6 +1074,11 @@ asmlinkage int syscall_trace_enter(struct pt_regs *regs)
10166 if (test_thread_flag(TIF_NOHZ))
10167 user_exit();
10168
10169 +#ifdef CONFIG_GRKERNSEC_SETXID
10170 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
10171 + gr_delayed_cred_worker();
10172 +#endif
10173 +
10174 if (test_thread_flag(TIF_SYSCALL_TRACE))
10175 ret = tracehook_report_syscall_entry(regs);
10176
10177 @@ -1093,6 +1102,11 @@ asmlinkage void syscall_trace_leave(struct pt_regs *regs)
10178 if (test_thread_flag(TIF_NOHZ))
10179 user_exit();
10180
10181 +#ifdef CONFIG_GRKERNSEC_SETXID
10182 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
10183 + gr_delayed_cred_worker();
10184 +#endif
10185 +
10186 audit_syscall_exit(regs);
10187
10188 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
10189 diff --git a/arch/sparc/kernel/smp_64.c b/arch/sparc/kernel/smp_64.c
10190 index b085311..6f885f7 100644
10191 --- a/arch/sparc/kernel/smp_64.c
10192 +++ b/arch/sparc/kernel/smp_64.c
10193 @@ -870,8 +870,8 @@ extern unsigned long xcall_flush_dcache_page_cheetah;
10194 extern unsigned long xcall_flush_dcache_page_spitfire;
10195
10196 #ifdef CONFIG_DEBUG_DCFLUSH
10197 -extern atomic_t dcpage_flushes;
10198 -extern atomic_t dcpage_flushes_xcall;
10199 +extern atomic_unchecked_t dcpage_flushes;
10200 +extern atomic_unchecked_t dcpage_flushes_xcall;
10201 #endif
10202
10203 static inline void __local_flush_dcache_page(struct page *page)
10204 @@ -895,7 +895,7 @@ void smp_flush_dcache_page_impl(struct page *page, int cpu)
10205 return;
10206
10207 #ifdef CONFIG_DEBUG_DCFLUSH
10208 - atomic_inc(&dcpage_flushes);
10209 + atomic_inc_unchecked(&dcpage_flushes);
10210 #endif
10211
10212 this_cpu = get_cpu();
10213 @@ -919,7 +919,7 @@ void smp_flush_dcache_page_impl(struct page *page, int cpu)
10214 xcall_deliver(data0, __pa(pg_addr),
10215 (u64) pg_addr, cpumask_of(cpu));
10216 #ifdef CONFIG_DEBUG_DCFLUSH
10217 - atomic_inc(&dcpage_flushes_xcall);
10218 + atomic_inc_unchecked(&dcpage_flushes_xcall);
10219 #endif
10220 }
10221 }
10222 @@ -938,7 +938,7 @@ void flush_dcache_page_all(struct mm_struct *mm, struct page *page)
10223 preempt_disable();
10224
10225 #ifdef CONFIG_DEBUG_DCFLUSH
10226 - atomic_inc(&dcpage_flushes);
10227 + atomic_inc_unchecked(&dcpage_flushes);
10228 #endif
10229 data0 = 0;
10230 pg_addr = page_address(page);
10231 @@ -955,7 +955,7 @@ void flush_dcache_page_all(struct mm_struct *mm, struct page *page)
10232 xcall_deliver(data0, __pa(pg_addr),
10233 (u64) pg_addr, cpu_online_mask);
10234 #ifdef CONFIG_DEBUG_DCFLUSH
10235 - atomic_inc(&dcpage_flushes_xcall);
10236 + atomic_inc_unchecked(&dcpage_flushes_xcall);
10237 #endif
10238 }
10239 __local_flush_dcache_page(page);
10240 diff --git a/arch/sparc/kernel/sys_sparc_32.c b/arch/sparc/kernel/sys_sparc_32.c
10241 index 3a8d184..49498a8 100644
10242 --- a/arch/sparc/kernel/sys_sparc_32.c
10243 +++ b/arch/sparc/kernel/sys_sparc_32.c
10244 @@ -52,7 +52,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
10245 if (len > TASK_SIZE - PAGE_SIZE)
10246 return -ENOMEM;
10247 if (!addr)
10248 - addr = TASK_UNMAPPED_BASE;
10249 + addr = current->mm->mmap_base;
10250
10251 info.flags = 0;
10252 info.length = len;
10253 diff --git a/arch/sparc/kernel/sys_sparc_64.c b/arch/sparc/kernel/sys_sparc_64.c
10254 index beb0b5a..5a153f7 100644
10255 --- a/arch/sparc/kernel/sys_sparc_64.c
10256 +++ b/arch/sparc/kernel/sys_sparc_64.c
10257 @@ -88,13 +88,14 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
10258 struct vm_area_struct * vma;
10259 unsigned long task_size = TASK_SIZE;
10260 int do_color_align;
10261 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
10262 struct vm_unmapped_area_info info;
10263
10264 if (flags & MAP_FIXED) {
10265 /* We do not accept a shared mapping if it would violate
10266 * cache aliasing constraints.
10267 */
10268 - if ((flags & MAP_SHARED) &&
10269 + if ((filp || (flags & MAP_SHARED)) &&
10270 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
10271 return -EINVAL;
10272 return addr;
10273 @@ -109,6 +110,10 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
10274 if (filp || (flags & MAP_SHARED))
10275 do_color_align = 1;
10276
10277 +#ifdef CONFIG_PAX_RANDMMAP
10278 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
10279 +#endif
10280 +
10281 if (addr) {
10282 if (do_color_align)
10283 addr = COLOR_ALIGN(addr, pgoff);
10284 @@ -116,22 +121,28 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
10285 addr = PAGE_ALIGN(addr);
10286
10287 vma = find_vma(mm, addr);
10288 - if (task_size - len >= addr &&
10289 - (!vma || addr + len <= vma->vm_start))
10290 + if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
10291 return addr;
10292 }
10293
10294 info.flags = 0;
10295 info.length = len;
10296 - info.low_limit = TASK_UNMAPPED_BASE;
10297 + info.low_limit = mm->mmap_base;
10298 info.high_limit = min(task_size, VA_EXCLUDE_START);
10299 info.align_mask = do_color_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
10300 info.align_offset = pgoff << PAGE_SHIFT;
10301 + info.threadstack_offset = offset;
10302 addr = vm_unmapped_area(&info);
10303
10304 if ((addr & ~PAGE_MASK) && task_size > VA_EXCLUDE_END) {
10305 VM_BUG_ON(addr != -ENOMEM);
10306 info.low_limit = VA_EXCLUDE_END;
10307 +
10308 +#ifdef CONFIG_PAX_RANDMMAP
10309 + if (mm->pax_flags & MF_PAX_RANDMMAP)
10310 + info.low_limit += mm->delta_mmap;
10311 +#endif
10312 +
10313 info.high_limit = task_size;
10314 addr = vm_unmapped_area(&info);
10315 }
10316 @@ -149,6 +160,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
10317 unsigned long task_size = STACK_TOP32;
10318 unsigned long addr = addr0;
10319 int do_color_align;
10320 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
10321 struct vm_unmapped_area_info info;
10322
10323 /* This should only ever run for 32-bit processes. */
10324 @@ -158,7 +170,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
10325 /* We do not accept a shared mapping if it would violate
10326 * cache aliasing constraints.
10327 */
10328 - if ((flags & MAP_SHARED) &&
10329 + if ((filp || (flags & MAP_SHARED)) &&
10330 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
10331 return -EINVAL;
10332 return addr;
10333 @@ -171,6 +183,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
10334 if (filp || (flags & MAP_SHARED))
10335 do_color_align = 1;
10336
10337 +#ifdef CONFIG_PAX_RANDMMAP
10338 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
10339 +#endif
10340 +
10341 /* requesting a specific address */
10342 if (addr) {
10343 if (do_color_align)
10344 @@ -179,8 +195,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
10345 addr = PAGE_ALIGN(addr);
10346
10347 vma = find_vma(mm, addr);
10348 - if (task_size - len >= addr &&
10349 - (!vma || addr + len <= vma->vm_start))
10350 + if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
10351 return addr;
10352 }
10353
10354 @@ -190,6 +205,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
10355 info.high_limit = mm->mmap_base;
10356 info.align_mask = do_color_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
10357 info.align_offset = pgoff << PAGE_SHIFT;
10358 + info.threadstack_offset = offset;
10359 addr = vm_unmapped_area(&info);
10360
10361 /*
10362 @@ -202,6 +218,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
10363 VM_BUG_ON(addr != -ENOMEM);
10364 info.flags = 0;
10365 info.low_limit = TASK_UNMAPPED_BASE;
10366 +
10367 +#ifdef CONFIG_PAX_RANDMMAP
10368 + if (mm->pax_flags & MF_PAX_RANDMMAP)
10369 + info.low_limit += mm->delta_mmap;
10370 +#endif
10371 +
10372 info.high_limit = STACK_TOP32;
10373 addr = vm_unmapped_area(&info);
10374 }
10375 @@ -258,10 +280,14 @@ unsigned long get_fb_unmapped_area(struct file *filp, unsigned long orig_addr, u
10376 EXPORT_SYMBOL(get_fb_unmapped_area);
10377
10378 /* Essentially the same as PowerPC. */
10379 -static unsigned long mmap_rnd(void)
10380 +static unsigned long mmap_rnd(struct mm_struct *mm)
10381 {
10382 unsigned long rnd = 0UL;
10383
10384 +#ifdef CONFIG_PAX_RANDMMAP
10385 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
10386 +#endif
10387 +
10388 if (current->flags & PF_RANDOMIZE) {
10389 unsigned long val = get_random_int();
10390 if (test_thread_flag(TIF_32BIT))
10391 @@ -274,7 +300,7 @@ static unsigned long mmap_rnd(void)
10392
10393 void arch_pick_mmap_layout(struct mm_struct *mm)
10394 {
10395 - unsigned long random_factor = mmap_rnd();
10396 + unsigned long random_factor = mmap_rnd(mm);
10397 unsigned long gap;
10398
10399 /*
10400 @@ -287,6 +313,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
10401 gap == RLIM_INFINITY ||
10402 sysctl_legacy_va_layout) {
10403 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
10404 +
10405 +#ifdef CONFIG_PAX_RANDMMAP
10406 + if (mm->pax_flags & MF_PAX_RANDMMAP)
10407 + mm->mmap_base += mm->delta_mmap;
10408 +#endif
10409 +
10410 mm->get_unmapped_area = arch_get_unmapped_area;
10411 } else {
10412 /* We know it's 32-bit */
10413 @@ -298,6 +330,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
10414 gap = (task_size / 6 * 5);
10415
10416 mm->mmap_base = PAGE_ALIGN(task_size - gap - random_factor);
10417 +
10418 +#ifdef CONFIG_PAX_RANDMMAP
10419 + if (mm->pax_flags & MF_PAX_RANDMMAP)
10420 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
10421 +#endif
10422 +
10423 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
10424 }
10425 }
10426 diff --git a/arch/sparc/kernel/syscalls.S b/arch/sparc/kernel/syscalls.S
10427 index 87729ff..d87fb1f 100644
10428 --- a/arch/sparc/kernel/syscalls.S
10429 +++ b/arch/sparc/kernel/syscalls.S
10430 @@ -52,7 +52,7 @@ sys32_rt_sigreturn:
10431 #endif
10432 .align 32
10433 1: ldx [%g6 + TI_FLAGS], %l5
10434 - andcc %l5, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT|_TIF_NOHZ), %g0
10435 + andcc %l5, _TIF_WORK_SYSCALL, %g0
10436 be,pt %icc, rtrap
10437 nop
10438 call syscall_trace_leave
10439 @@ -184,12 +184,13 @@ linux_sparc_syscall32:
10440
10441 srl %i3, 0, %o3 ! IEU0
10442 srl %i2, 0, %o2 ! IEU0 Group
10443 - andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT|_TIF_NOHZ), %g0
10444 + andcc %l0, _TIF_WORK_SYSCALL, %g0
10445 bne,pn %icc, linux_syscall_trace32 ! CTI
10446 mov %i0, %l5 ! IEU1
10447 5: call %l7 ! CTI Group brk forced
10448 srl %i5, 0, %o5 ! IEU1
10449 - ba,a,pt %xcc, 3f
10450 + ba,pt %xcc, 3f
10451 + sra %o0, 0, %o0
10452
10453 /* Linux native system calls enter here... */
10454 .align 32
10455 @@ -207,7 +208,7 @@ linux_sparc_syscall:
10456
10457 mov %i3, %o3 ! IEU1
10458 mov %i4, %o4 ! IEU0 Group
10459 - andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT|_TIF_NOHZ), %g0
10460 + andcc %l0, _TIF_WORK_SYSCALL, %g0
10461 bne,pn %icc, linux_syscall_trace ! CTI Group
10462 mov %i0, %l5 ! IEU0
10463 2: call %l7 ! CTI Group brk forced
10464 @@ -217,13 +218,12 @@ linux_sparc_syscall:
10465 3: stx %o0, [%sp + PTREGS_OFF + PT_V9_I0]
10466 ret_sys_call:
10467 ldx [%sp + PTREGS_OFF + PT_V9_TSTATE], %g3
10468 - sra %o0, 0, %o0
10469 mov %ulo(TSTATE_XCARRY | TSTATE_ICARRY), %g2
10470 sllx %g2, 32, %g2
10471
10472 cmp %o0, -ERESTART_RESTARTBLOCK
10473 bgeu,pn %xcc, 1f
10474 - andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT|_TIF_NOHZ), %g0
10475 + andcc %l0, _TIF_WORK_SYSCALL, %g0
10476 ldx [%sp + PTREGS_OFF + PT_V9_TNPC], %l1 ! pc = npc
10477
10478 2:
10479 diff --git a/arch/sparc/kernel/traps_32.c b/arch/sparc/kernel/traps_32.c
10480 index 6629829..036032d 100644
10481 --- a/arch/sparc/kernel/traps_32.c
10482 +++ b/arch/sparc/kernel/traps_32.c
10483 @@ -44,6 +44,8 @@ static void instruction_dump(unsigned long *pc)
10484 #define __SAVE __asm__ __volatile__("save %sp, -0x40, %sp\n\t")
10485 #define __RESTORE __asm__ __volatile__("restore %g0, %g0, %g0\n\t")
10486
10487 +extern void gr_handle_kernel_exploit(void);
10488 +
10489 void die_if_kernel(char *str, struct pt_regs *regs)
10490 {
10491 static int die_counter;
10492 @@ -76,15 +78,17 @@ void die_if_kernel(char *str, struct pt_regs *regs)
10493 count++ < 30 &&
10494 (((unsigned long) rw) >= PAGE_OFFSET) &&
10495 !(((unsigned long) rw) & 0x7)) {
10496 - printk("Caller[%08lx]: %pS\n", rw->ins[7],
10497 + printk("Caller[%08lx]: %pA\n", rw->ins[7],
10498 (void *) rw->ins[7]);
10499 rw = (struct reg_window32 *)rw->ins[6];
10500 }
10501 }
10502 printk("Instruction DUMP:");
10503 instruction_dump ((unsigned long *) regs->pc);
10504 - if(regs->psr & PSR_PS)
10505 + if(regs->psr & PSR_PS) {
10506 + gr_handle_kernel_exploit();
10507 do_exit(SIGKILL);
10508 + }
10509 do_exit(SIGSEGV);
10510 }
10511
10512 diff --git a/arch/sparc/kernel/traps_64.c b/arch/sparc/kernel/traps_64.c
10513 index 4ced92f..965eeed 100644
10514 --- a/arch/sparc/kernel/traps_64.c
10515 +++ b/arch/sparc/kernel/traps_64.c
10516 @@ -77,7 +77,7 @@ static void dump_tl1_traplog(struct tl1_traplog *p)
10517 i + 1,
10518 p->trapstack[i].tstate, p->trapstack[i].tpc,
10519 p->trapstack[i].tnpc, p->trapstack[i].tt);
10520 - printk("TRAPLOG: TPC<%pS>\n", (void *) p->trapstack[i].tpc);
10521 + printk("TRAPLOG: TPC<%pA>\n", (void *) p->trapstack[i].tpc);
10522 }
10523 }
10524
10525 @@ -97,6 +97,12 @@ void bad_trap(struct pt_regs *regs, long lvl)
10526
10527 lvl -= 0x100;
10528 if (regs->tstate & TSTATE_PRIV) {
10529 +
10530 +#ifdef CONFIG_PAX_REFCOUNT
10531 + if (lvl == 6)
10532 + pax_report_refcount_overflow(regs);
10533 +#endif
10534 +
10535 sprintf(buffer, "Kernel bad sw trap %lx", lvl);
10536 die_if_kernel(buffer, regs);
10537 }
10538 @@ -115,11 +121,16 @@ void bad_trap(struct pt_regs *regs, long lvl)
10539 void bad_trap_tl1(struct pt_regs *regs, long lvl)
10540 {
10541 char buffer[32];
10542 -
10543 +
10544 if (notify_die(DIE_TRAP_TL1, "bad trap tl1", regs,
10545 0, lvl, SIGTRAP) == NOTIFY_STOP)
10546 return;
10547
10548 +#ifdef CONFIG_PAX_REFCOUNT
10549 + if (lvl == 6)
10550 + pax_report_refcount_overflow(regs);
10551 +#endif
10552 +
10553 dump_tl1_traplog((struct tl1_traplog *)(regs + 1));
10554
10555 sprintf (buffer, "Bad trap %lx at tl>0", lvl);
10556 @@ -1149,7 +1160,7 @@ static void cheetah_log_errors(struct pt_regs *regs, struct cheetah_err_info *in
10557 regs->tpc, regs->tnpc, regs->u_regs[UREG_I7], regs->tstate);
10558 printk("%s" "ERROR(%d): ",
10559 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id());
10560 - printk("TPC<%pS>\n", (void *) regs->tpc);
10561 + printk("TPC<%pA>\n", (void *) regs->tpc);
10562 printk("%s" "ERROR(%d): M_SYND(%lx), E_SYND(%lx)%s%s\n",
10563 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id(),
10564 (afsr & CHAFSR_M_SYNDROME) >> CHAFSR_M_SYNDROME_SHIFT,
10565 @@ -1756,7 +1767,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
10566 smp_processor_id(),
10567 (type & 0x1) ? 'I' : 'D',
10568 regs->tpc);
10569 - printk(KERN_EMERG "TPC<%pS>\n", (void *) regs->tpc);
10570 + printk(KERN_EMERG "TPC<%pA>\n", (void *) regs->tpc);
10571 panic("Irrecoverable Cheetah+ parity error.");
10572 }
10573
10574 @@ -1764,7 +1775,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
10575 smp_processor_id(),
10576 (type & 0x1) ? 'I' : 'D',
10577 regs->tpc);
10578 - printk(KERN_WARNING "TPC<%pS>\n", (void *) regs->tpc);
10579 + printk(KERN_WARNING "TPC<%pA>\n", (void *) regs->tpc);
10580 }
10581
10582 struct sun4v_error_entry {
10583 @@ -1837,8 +1848,8 @@ struct sun4v_error_entry {
10584 /*0x38*/u64 reserved_5;
10585 };
10586
10587 -static atomic_t sun4v_resum_oflow_cnt = ATOMIC_INIT(0);
10588 -static atomic_t sun4v_nonresum_oflow_cnt = ATOMIC_INIT(0);
10589 +static atomic_unchecked_t sun4v_resum_oflow_cnt = ATOMIC_INIT(0);
10590 +static atomic_unchecked_t sun4v_nonresum_oflow_cnt = ATOMIC_INIT(0);
10591
10592 static const char *sun4v_err_type_to_str(u8 type)
10593 {
10594 @@ -1930,7 +1941,7 @@ static void sun4v_report_real_raddr(const char *pfx, struct pt_regs *regs)
10595 }
10596
10597 static void sun4v_log_error(struct pt_regs *regs, struct sun4v_error_entry *ent,
10598 - int cpu, const char *pfx, atomic_t *ocnt)
10599 + int cpu, const char *pfx, atomic_unchecked_t *ocnt)
10600 {
10601 u64 *raw_ptr = (u64 *) ent;
10602 u32 attrs;
10603 @@ -1988,8 +1999,8 @@ static void sun4v_log_error(struct pt_regs *regs, struct sun4v_error_entry *ent,
10604
10605 show_regs(regs);
10606
10607 - if ((cnt = atomic_read(ocnt)) != 0) {
10608 - atomic_set(ocnt, 0);
10609 + if ((cnt = atomic_read_unchecked(ocnt)) != 0) {
10610 + atomic_set_unchecked(ocnt, 0);
10611 wmb();
10612 printk("%s: Queue overflowed %d times.\n",
10613 pfx, cnt);
10614 @@ -2046,7 +2057,7 @@ out:
10615 */
10616 void sun4v_resum_overflow(struct pt_regs *regs)
10617 {
10618 - atomic_inc(&sun4v_resum_oflow_cnt);
10619 + atomic_inc_unchecked(&sun4v_resum_oflow_cnt);
10620 }
10621
10622 /* We run with %pil set to PIL_NORMAL_MAX and PSTATE_IE enabled in %pstate.
10623 @@ -2099,7 +2110,7 @@ void sun4v_nonresum_overflow(struct pt_regs *regs)
10624 /* XXX Actually even this can make not that much sense. Perhaps
10625 * XXX we should just pull the plug and panic directly from here?
10626 */
10627 - atomic_inc(&sun4v_nonresum_oflow_cnt);
10628 + atomic_inc_unchecked(&sun4v_nonresum_oflow_cnt);
10629 }
10630
10631 unsigned long sun4v_err_itlb_vaddr;
10632 @@ -2114,9 +2125,9 @@ void sun4v_itlb_error_report(struct pt_regs *regs, int tl)
10633
10634 printk(KERN_EMERG "SUN4V-ITLB: Error at TPC[%lx], tl %d\n",
10635 regs->tpc, tl);
10636 - printk(KERN_EMERG "SUN4V-ITLB: TPC<%pS>\n", (void *) regs->tpc);
10637 + printk(KERN_EMERG "SUN4V-ITLB: TPC<%pA>\n", (void *) regs->tpc);
10638 printk(KERN_EMERG "SUN4V-ITLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
10639 - printk(KERN_EMERG "SUN4V-ITLB: O7<%pS>\n",
10640 + printk(KERN_EMERG "SUN4V-ITLB: O7<%pA>\n",
10641 (void *) regs->u_regs[UREG_I7]);
10642 printk(KERN_EMERG "SUN4V-ITLB: vaddr[%lx] ctx[%lx] "
10643 "pte[%lx] error[%lx]\n",
10644 @@ -2138,9 +2149,9 @@ void sun4v_dtlb_error_report(struct pt_regs *regs, int tl)
10645
10646 printk(KERN_EMERG "SUN4V-DTLB: Error at TPC[%lx], tl %d\n",
10647 regs->tpc, tl);
10648 - printk(KERN_EMERG "SUN4V-DTLB: TPC<%pS>\n", (void *) regs->tpc);
10649 + printk(KERN_EMERG "SUN4V-DTLB: TPC<%pA>\n", (void *) regs->tpc);
10650 printk(KERN_EMERG "SUN4V-DTLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
10651 - printk(KERN_EMERG "SUN4V-DTLB: O7<%pS>\n",
10652 + printk(KERN_EMERG "SUN4V-DTLB: O7<%pA>\n",
10653 (void *) regs->u_regs[UREG_I7]);
10654 printk(KERN_EMERG "SUN4V-DTLB: vaddr[%lx] ctx[%lx] "
10655 "pte[%lx] error[%lx]\n",
10656 @@ -2359,13 +2370,13 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
10657 fp = (unsigned long)sf->fp + STACK_BIAS;
10658 }
10659
10660 - printk(" [%016lx] %pS\n", pc, (void *) pc);
10661 + printk(" [%016lx] %pA\n", pc, (void *) pc);
10662 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
10663 if ((pc + 8UL) == (unsigned long) &return_to_handler) {
10664 int index = tsk->curr_ret_stack;
10665 if (tsk->ret_stack && index >= graph) {
10666 pc = tsk->ret_stack[index - graph].ret;
10667 - printk(" [%016lx] %pS\n", pc, (void *) pc);
10668 + printk(" [%016lx] %pA\n", pc, (void *) pc);
10669 graph++;
10670 }
10671 }
10672 @@ -2383,6 +2394,8 @@ static inline struct reg_window *kernel_stack_up(struct reg_window *rw)
10673 return (struct reg_window *) (fp + STACK_BIAS);
10674 }
10675
10676 +extern void gr_handle_kernel_exploit(void);
10677 +
10678 void die_if_kernel(char *str, struct pt_regs *regs)
10679 {
10680 static int die_counter;
10681 @@ -2411,7 +2424,7 @@ void die_if_kernel(char *str, struct pt_regs *regs)
10682 while (rw &&
10683 count++ < 30 &&
10684 kstack_valid(tp, (unsigned long) rw)) {
10685 - printk("Caller[%016lx]: %pS\n", rw->ins[7],
10686 + printk("Caller[%016lx]: %pA\n", rw->ins[7],
10687 (void *) rw->ins[7]);
10688
10689 rw = kernel_stack_up(rw);
10690 @@ -2424,8 +2437,10 @@ void die_if_kernel(char *str, struct pt_regs *regs)
10691 }
10692 user_instruction_dump ((unsigned int __user *) regs->tpc);
10693 }
10694 - if (regs->tstate & TSTATE_PRIV)
10695 + if (regs->tstate & TSTATE_PRIV) {
10696 + gr_handle_kernel_exploit();
10697 do_exit(SIGKILL);
10698 + }
10699 do_exit(SIGSEGV);
10700 }
10701 EXPORT_SYMBOL(die_if_kernel);
10702 diff --git a/arch/sparc/kernel/unaligned_64.c b/arch/sparc/kernel/unaligned_64.c
10703 index 3c1a7cb..73e1923 100644
10704 --- a/arch/sparc/kernel/unaligned_64.c
10705 +++ b/arch/sparc/kernel/unaligned_64.c
10706 @@ -289,7 +289,7 @@ static void log_unaligned(struct pt_regs *regs)
10707 static DEFINE_RATELIMIT_STATE(ratelimit, 5 * HZ, 5);
10708
10709 if (__ratelimit(&ratelimit)) {
10710 - printk("Kernel unaligned access at TPC[%lx] %pS\n",
10711 + printk("Kernel unaligned access at TPC[%lx] %pA\n",
10712 regs->tpc, (void *) regs->tpc);
10713 }
10714 }
10715 diff --git a/arch/sparc/lib/Makefile b/arch/sparc/lib/Makefile
10716 index dbe119b..089c7c1 100644
10717 --- a/arch/sparc/lib/Makefile
10718 +++ b/arch/sparc/lib/Makefile
10719 @@ -2,7 +2,7 @@
10720 #
10721
10722 asflags-y := -ansi -DST_DIV0=0x02
10723 -ccflags-y := -Werror
10724 +#ccflags-y := -Werror
10725
10726 lib-$(CONFIG_SPARC32) += ashrdi3.o
10727 lib-$(CONFIG_SPARC32) += memcpy.o memset.o
10728 diff --git a/arch/sparc/lib/atomic_64.S b/arch/sparc/lib/atomic_64.S
10729 index 85c233d..68500e0 100644
10730 --- a/arch/sparc/lib/atomic_64.S
10731 +++ b/arch/sparc/lib/atomic_64.S
10732 @@ -17,7 +17,12 @@
10733 ENTRY(atomic_add) /* %o0 = increment, %o1 = atomic_ptr */
10734 BACKOFF_SETUP(%o2)
10735 1: lduw [%o1], %g1
10736 - add %g1, %o0, %g7
10737 + addcc %g1, %o0, %g7
10738 +
10739 +#ifdef CONFIG_PAX_REFCOUNT
10740 + tvs %icc, 6
10741 +#endif
10742 +
10743 cas [%o1], %g1, %g7
10744 cmp %g1, %g7
10745 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
10746 @@ -27,10 +32,28 @@ ENTRY(atomic_add) /* %o0 = increment, %o1 = atomic_ptr */
10747 2: BACKOFF_SPIN(%o2, %o3, 1b)
10748 ENDPROC(atomic_add)
10749
10750 +ENTRY(atomic_add_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
10751 + BACKOFF_SETUP(%o2)
10752 +1: lduw [%o1], %g1
10753 + add %g1, %o0, %g7
10754 + cas [%o1], %g1, %g7
10755 + cmp %g1, %g7
10756 + bne,pn %icc, 2f
10757 + nop
10758 + retl
10759 + nop
10760 +2: BACKOFF_SPIN(%o2, %o3, 1b)
10761 +ENDPROC(atomic_add_unchecked)
10762 +
10763 ENTRY(atomic_sub) /* %o0 = decrement, %o1 = atomic_ptr */
10764 BACKOFF_SETUP(%o2)
10765 1: lduw [%o1], %g1
10766 - sub %g1, %o0, %g7
10767 + subcc %g1, %o0, %g7
10768 +
10769 +#ifdef CONFIG_PAX_REFCOUNT
10770 + tvs %icc, 6
10771 +#endif
10772 +
10773 cas [%o1], %g1, %g7
10774 cmp %g1, %g7
10775 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
10776 @@ -40,10 +63,28 @@ ENTRY(atomic_sub) /* %o0 = decrement, %o1 = atomic_ptr */
10777 2: BACKOFF_SPIN(%o2, %o3, 1b)
10778 ENDPROC(atomic_sub)
10779
10780 +ENTRY(atomic_sub_unchecked) /* %o0 = decrement, %o1 = atomic_ptr */
10781 + BACKOFF_SETUP(%o2)
10782 +1: lduw [%o1], %g1
10783 + sub %g1, %o0, %g7
10784 + cas [%o1], %g1, %g7
10785 + cmp %g1, %g7
10786 + bne,pn %icc, 2f
10787 + nop
10788 + retl
10789 + nop
10790 +2: BACKOFF_SPIN(%o2, %o3, 1b)
10791 +ENDPROC(atomic_sub_unchecked)
10792 +
10793 ENTRY(atomic_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
10794 BACKOFF_SETUP(%o2)
10795 1: lduw [%o1], %g1
10796 - add %g1, %o0, %g7
10797 + addcc %g1, %o0, %g7
10798 +
10799 +#ifdef CONFIG_PAX_REFCOUNT
10800 + tvs %icc, 6
10801 +#endif
10802 +
10803 cas [%o1], %g1, %g7
10804 cmp %g1, %g7
10805 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
10806 @@ -53,10 +94,29 @@ ENTRY(atomic_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
10807 2: BACKOFF_SPIN(%o2, %o3, 1b)
10808 ENDPROC(atomic_add_ret)
10809
10810 +ENTRY(atomic_add_ret_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
10811 + BACKOFF_SETUP(%o2)
10812 +1: lduw [%o1], %g1
10813 + addcc %g1, %o0, %g7
10814 + cas [%o1], %g1, %g7
10815 + cmp %g1, %g7
10816 + bne,pn %icc, 2f
10817 + add %g7, %o0, %g7
10818 + sra %g7, 0, %o0
10819 + retl
10820 + nop
10821 +2: BACKOFF_SPIN(%o2, %o3, 1b)
10822 +ENDPROC(atomic_add_ret_unchecked)
10823 +
10824 ENTRY(atomic_sub_ret) /* %o0 = decrement, %o1 = atomic_ptr */
10825 BACKOFF_SETUP(%o2)
10826 1: lduw [%o1], %g1
10827 - sub %g1, %o0, %g7
10828 + subcc %g1, %o0, %g7
10829 +
10830 +#ifdef CONFIG_PAX_REFCOUNT
10831 + tvs %icc, 6
10832 +#endif
10833 +
10834 cas [%o1], %g1, %g7
10835 cmp %g1, %g7
10836 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
10837 @@ -69,7 +129,12 @@ ENDPROC(atomic_sub_ret)
10838 ENTRY(atomic64_add) /* %o0 = increment, %o1 = atomic_ptr */
10839 BACKOFF_SETUP(%o2)
10840 1: ldx [%o1], %g1
10841 - add %g1, %o0, %g7
10842 + addcc %g1, %o0, %g7
10843 +
10844 +#ifdef CONFIG_PAX_REFCOUNT
10845 + tvs %xcc, 6
10846 +#endif
10847 +
10848 casx [%o1], %g1, %g7
10849 cmp %g1, %g7
10850 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
10851 @@ -79,10 +144,28 @@ ENTRY(atomic64_add) /* %o0 = increment, %o1 = atomic_ptr */
10852 2: BACKOFF_SPIN(%o2, %o3, 1b)
10853 ENDPROC(atomic64_add)
10854
10855 +ENTRY(atomic64_add_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
10856 + BACKOFF_SETUP(%o2)
10857 +1: ldx [%o1], %g1
10858 + addcc %g1, %o0, %g7
10859 + casx [%o1], %g1, %g7
10860 + cmp %g1, %g7
10861 + bne,pn %xcc, 2f
10862 + nop
10863 + retl
10864 + nop
10865 +2: BACKOFF_SPIN(%o2, %o3, 1b)
10866 +ENDPROC(atomic64_add_unchecked)
10867 +
10868 ENTRY(atomic64_sub) /* %o0 = decrement, %o1 = atomic_ptr */
10869 BACKOFF_SETUP(%o2)
10870 1: ldx [%o1], %g1
10871 - sub %g1, %o0, %g7
10872 + subcc %g1, %o0, %g7
10873 +
10874 +#ifdef CONFIG_PAX_REFCOUNT
10875 + tvs %xcc, 6
10876 +#endif
10877 +
10878 casx [%o1], %g1, %g7
10879 cmp %g1, %g7
10880 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
10881 @@ -92,10 +175,28 @@ ENTRY(atomic64_sub) /* %o0 = decrement, %o1 = atomic_ptr */
10882 2: BACKOFF_SPIN(%o2, %o3, 1b)
10883 ENDPROC(atomic64_sub)
10884
10885 +ENTRY(atomic64_sub_unchecked) /* %o0 = decrement, %o1 = atomic_ptr */
10886 + BACKOFF_SETUP(%o2)
10887 +1: ldx [%o1], %g1
10888 + subcc %g1, %o0, %g7
10889 + casx [%o1], %g1, %g7
10890 + cmp %g1, %g7
10891 + bne,pn %xcc, 2f
10892 + nop
10893 + retl
10894 + nop
10895 +2: BACKOFF_SPIN(%o2, %o3, 1b)
10896 +ENDPROC(atomic64_sub_unchecked)
10897 +
10898 ENTRY(atomic64_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
10899 BACKOFF_SETUP(%o2)
10900 1: ldx [%o1], %g1
10901 - add %g1, %o0, %g7
10902 + addcc %g1, %o0, %g7
10903 +
10904 +#ifdef CONFIG_PAX_REFCOUNT
10905 + tvs %xcc, 6
10906 +#endif
10907 +
10908 casx [%o1], %g1, %g7
10909 cmp %g1, %g7
10910 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
10911 @@ -105,10 +206,29 @@ ENTRY(atomic64_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
10912 2: BACKOFF_SPIN(%o2, %o3, 1b)
10913 ENDPROC(atomic64_add_ret)
10914
10915 +ENTRY(atomic64_add_ret_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
10916 + BACKOFF_SETUP(%o2)
10917 +1: ldx [%o1], %g1
10918 + addcc %g1, %o0, %g7
10919 + casx [%o1], %g1, %g7
10920 + cmp %g1, %g7
10921 + bne,pn %xcc, 2f
10922 + add %g7, %o0, %g7
10923 + mov %g7, %o0
10924 + retl
10925 + nop
10926 +2: BACKOFF_SPIN(%o2, %o3, 1b)
10927 +ENDPROC(atomic64_add_ret_unchecked)
10928 +
10929 ENTRY(atomic64_sub_ret) /* %o0 = decrement, %o1 = atomic_ptr */
10930 BACKOFF_SETUP(%o2)
10931 1: ldx [%o1], %g1
10932 - sub %g1, %o0, %g7
10933 + subcc %g1, %o0, %g7
10934 +
10935 +#ifdef CONFIG_PAX_REFCOUNT
10936 + tvs %xcc, 6
10937 +#endif
10938 +
10939 casx [%o1], %g1, %g7
10940 cmp %g1, %g7
10941 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
10942 diff --git a/arch/sparc/lib/ksyms.c b/arch/sparc/lib/ksyms.c
10943 index 323335b..ed85ea2 100644
10944 --- a/arch/sparc/lib/ksyms.c
10945 +++ b/arch/sparc/lib/ksyms.c
10946 @@ -100,12 +100,18 @@ EXPORT_SYMBOL(__clear_user);
10947
10948 /* Atomic counter implementation. */
10949 EXPORT_SYMBOL(atomic_add);
10950 +EXPORT_SYMBOL(atomic_add_unchecked);
10951 EXPORT_SYMBOL(atomic_add_ret);
10952 +EXPORT_SYMBOL(atomic_add_ret_unchecked);
10953 EXPORT_SYMBOL(atomic_sub);
10954 +EXPORT_SYMBOL(atomic_sub_unchecked);
10955 EXPORT_SYMBOL(atomic_sub_ret);
10956 EXPORT_SYMBOL(atomic64_add);
10957 +EXPORT_SYMBOL(atomic64_add_unchecked);
10958 EXPORT_SYMBOL(atomic64_add_ret);
10959 +EXPORT_SYMBOL(atomic64_add_ret_unchecked);
10960 EXPORT_SYMBOL(atomic64_sub);
10961 +EXPORT_SYMBOL(atomic64_sub_unchecked);
10962 EXPORT_SYMBOL(atomic64_sub_ret);
10963 EXPORT_SYMBOL(atomic64_dec_if_positive);
10964
10965 diff --git a/arch/sparc/mm/Makefile b/arch/sparc/mm/Makefile
10966 index 30c3ecc..736f015 100644
10967 --- a/arch/sparc/mm/Makefile
10968 +++ b/arch/sparc/mm/Makefile
10969 @@ -2,7 +2,7 @@
10970 #
10971
10972 asflags-y := -ansi
10973 -ccflags-y := -Werror
10974 +#ccflags-y := -Werror
10975
10976 obj-$(CONFIG_SPARC64) += ultra.o tlb.o tsb.o gup.o
10977 obj-y += fault_$(BITS).o
10978 diff --git a/arch/sparc/mm/fault_32.c b/arch/sparc/mm/fault_32.c
10979 index 59dbd46..1dd7f5e 100644
10980 --- a/arch/sparc/mm/fault_32.c
10981 +++ b/arch/sparc/mm/fault_32.c
10982 @@ -21,6 +21,9 @@
10983 #include <linux/perf_event.h>
10984 #include <linux/interrupt.h>
10985 #include <linux/kdebug.h>
10986 +#include <linux/slab.h>
10987 +#include <linux/pagemap.h>
10988 +#include <linux/compiler.h>
10989
10990 #include <asm/page.h>
10991 #include <asm/pgtable.h>
10992 @@ -159,6 +162,277 @@ static unsigned long compute_si_addr(struct pt_regs *regs, int text_fault)
10993 return safe_compute_effective_address(regs, insn);
10994 }
10995
10996 +#ifdef CONFIG_PAX_PAGEEXEC
10997 +#ifdef CONFIG_PAX_DLRESOLVE
10998 +static void pax_emuplt_close(struct vm_area_struct *vma)
10999 +{
11000 + vma->vm_mm->call_dl_resolve = 0UL;
11001 +}
11002 +
11003 +static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
11004 +{
11005 + unsigned int *kaddr;
11006 +
11007 + vmf->page = alloc_page(GFP_HIGHUSER);
11008 + if (!vmf->page)
11009 + return VM_FAULT_OOM;
11010 +
11011 + kaddr = kmap(vmf->page);
11012 + memset(kaddr, 0, PAGE_SIZE);
11013 + kaddr[0] = 0x9DE3BFA8U; /* save */
11014 + flush_dcache_page(vmf->page);
11015 + kunmap(vmf->page);
11016 + return VM_FAULT_MAJOR;
11017 +}
11018 +
11019 +static const struct vm_operations_struct pax_vm_ops = {
11020 + .close = pax_emuplt_close,
11021 + .fault = pax_emuplt_fault
11022 +};
11023 +
11024 +static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
11025 +{
11026 + int ret;
11027 +
11028 + INIT_LIST_HEAD(&vma->anon_vma_chain);
11029 + vma->vm_mm = current->mm;
11030 + vma->vm_start = addr;
11031 + vma->vm_end = addr + PAGE_SIZE;
11032 + vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
11033 + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
11034 + vma->vm_ops = &pax_vm_ops;
11035 +
11036 + ret = insert_vm_struct(current->mm, vma);
11037 + if (ret)
11038 + return ret;
11039 +
11040 + ++current->mm->total_vm;
11041 + return 0;
11042 +}
11043 +#endif
11044 +
11045 +/*
11046 + * PaX: decide what to do with offenders (regs->pc = fault address)
11047 + *
11048 + * returns 1 when task should be killed
11049 + * 2 when patched PLT trampoline was detected
11050 + * 3 when unpatched PLT trampoline was detected
11051 + */
11052 +static int pax_handle_fetch_fault(struct pt_regs *regs)
11053 +{
11054 +
11055 +#ifdef CONFIG_PAX_EMUPLT
11056 + int err;
11057 +
11058 + do { /* PaX: patched PLT emulation #1 */
11059 + unsigned int sethi1, sethi2, jmpl;
11060 +
11061 + err = get_user(sethi1, (unsigned int *)regs->pc);
11062 + err |= get_user(sethi2, (unsigned int *)(regs->pc+4));
11063 + err |= get_user(jmpl, (unsigned int *)(regs->pc+8));
11064 +
11065 + if (err)
11066 + break;
11067 +
11068 + if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
11069 + (sethi2 & 0xFFC00000U) == 0x03000000U &&
11070 + (jmpl & 0xFFFFE000U) == 0x81C06000U)
11071 + {
11072 + unsigned int addr;
11073 +
11074 + regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
11075 + addr = regs->u_regs[UREG_G1];
11076 + addr += (((jmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
11077 + regs->pc = addr;
11078 + regs->npc = addr+4;
11079 + return 2;
11080 + }
11081 + } while (0);
11082 +
11083 + do { /* PaX: patched PLT emulation #2 */
11084 + unsigned int ba;
11085 +
11086 + err = get_user(ba, (unsigned int *)regs->pc);
11087 +
11088 + if (err)
11089 + break;
11090 +
11091 + if ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30480000U) {
11092 + unsigned int addr;
11093 +
11094 + if ((ba & 0xFFC00000U) == 0x30800000U)
11095 + addr = regs->pc + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
11096 + else
11097 + addr = regs->pc + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
11098 + regs->pc = addr;
11099 + regs->npc = addr+4;
11100 + return 2;
11101 + }
11102 + } while (0);
11103 +
11104 + do { /* PaX: patched PLT emulation #3 */
11105 + unsigned int sethi, bajmpl, nop;
11106 +
11107 + err = get_user(sethi, (unsigned int *)regs->pc);
11108 + err |= get_user(bajmpl, (unsigned int *)(regs->pc+4));
11109 + err |= get_user(nop, (unsigned int *)(regs->pc+8));
11110 +
11111 + if (err)
11112 + break;
11113 +
11114 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
11115 + ((bajmpl & 0xFFFFE000U) == 0x81C06000U || (bajmpl & 0xFFF80000U) == 0x30480000U) &&
11116 + nop == 0x01000000U)
11117 + {
11118 + unsigned int addr;
11119 +
11120 + addr = (sethi & 0x003FFFFFU) << 10;
11121 + regs->u_regs[UREG_G1] = addr;
11122 + if ((bajmpl & 0xFFFFE000U) == 0x81C06000U)
11123 + addr += (((bajmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
11124 + else
11125 + addr = regs->pc + ((((bajmpl | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
11126 + regs->pc = addr;
11127 + regs->npc = addr+4;
11128 + return 2;
11129 + }
11130 + } while (0);
11131 +
11132 + do { /* PaX: unpatched PLT emulation step 1 */
11133 + unsigned int sethi, ba, nop;
11134 +
11135 + err = get_user(sethi, (unsigned int *)regs->pc);
11136 + err |= get_user(ba, (unsigned int *)(regs->pc+4));
11137 + err |= get_user(nop, (unsigned int *)(regs->pc+8));
11138 +
11139 + if (err)
11140 + break;
11141 +
11142 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
11143 + ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
11144 + nop == 0x01000000U)
11145 + {
11146 + unsigned int addr, save, call;
11147 +
11148 + if ((ba & 0xFFC00000U) == 0x30800000U)
11149 + addr = regs->pc + 4 + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
11150 + else
11151 + addr = regs->pc + 4 + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
11152 +
11153 + err = get_user(save, (unsigned int *)addr);
11154 + err |= get_user(call, (unsigned int *)(addr+4));
11155 + err |= get_user(nop, (unsigned int *)(addr+8));
11156 + if (err)
11157 + break;
11158 +
11159 +#ifdef CONFIG_PAX_DLRESOLVE
11160 + if (save == 0x9DE3BFA8U &&
11161 + (call & 0xC0000000U) == 0x40000000U &&
11162 + nop == 0x01000000U)
11163 + {
11164 + struct vm_area_struct *vma;
11165 + unsigned long call_dl_resolve;
11166 +
11167 + down_read(&current->mm->mmap_sem);
11168 + call_dl_resolve = current->mm->call_dl_resolve;
11169 + up_read(&current->mm->mmap_sem);
11170 + if (likely(call_dl_resolve))
11171 + goto emulate;
11172 +
11173 + vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
11174 +
11175 + down_write(&current->mm->mmap_sem);
11176 + if (current->mm->call_dl_resolve) {
11177 + call_dl_resolve = current->mm->call_dl_resolve;
11178 + up_write(&current->mm->mmap_sem);
11179 + if (vma)
11180 + kmem_cache_free(vm_area_cachep, vma);
11181 + goto emulate;
11182 + }
11183 +
11184 + call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
11185 + if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
11186 + up_write(&current->mm->mmap_sem);
11187 + if (vma)
11188 + kmem_cache_free(vm_area_cachep, vma);
11189 + return 1;
11190 + }
11191 +
11192 + if (pax_insert_vma(vma, call_dl_resolve)) {
11193 + up_write(&current->mm->mmap_sem);
11194 + kmem_cache_free(vm_area_cachep, vma);
11195 + return 1;
11196 + }
11197 +
11198 + current->mm->call_dl_resolve = call_dl_resolve;
11199 + up_write(&current->mm->mmap_sem);
11200 +
11201 +emulate:
11202 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
11203 + regs->pc = call_dl_resolve;
11204 + regs->npc = addr+4;
11205 + return 3;
11206 + }
11207 +#endif
11208 +
11209 + /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
11210 + if ((save & 0xFFC00000U) == 0x05000000U &&
11211 + (call & 0xFFFFE000U) == 0x85C0A000U &&
11212 + nop == 0x01000000U)
11213 + {
11214 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
11215 + regs->u_regs[UREG_G2] = addr + 4;
11216 + addr = (save & 0x003FFFFFU) << 10;
11217 + addr += (((call | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
11218 + regs->pc = addr;
11219 + regs->npc = addr+4;
11220 + return 3;
11221 + }
11222 + }
11223 + } while (0);
11224 +
11225 + do { /* PaX: unpatched PLT emulation step 2 */
11226 + unsigned int save, call, nop;
11227 +
11228 + err = get_user(save, (unsigned int *)(regs->pc-4));
11229 + err |= get_user(call, (unsigned int *)regs->pc);
11230 + err |= get_user(nop, (unsigned int *)(regs->pc+4));
11231 + if (err)
11232 + break;
11233 +
11234 + if (save == 0x9DE3BFA8U &&
11235 + (call & 0xC0000000U) == 0x40000000U &&
11236 + nop == 0x01000000U)
11237 + {
11238 + unsigned int dl_resolve = regs->pc + ((((call | 0xC0000000U) ^ 0x20000000U) + 0x20000000U) << 2);
11239 +
11240 + regs->u_regs[UREG_RETPC] = regs->pc;
11241 + regs->pc = dl_resolve;
11242 + regs->npc = dl_resolve+4;
11243 + return 3;
11244 + }
11245 + } while (0);
11246 +#endif
11247 +
11248 + return 1;
11249 +}
11250 +
11251 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
11252 +{
11253 + unsigned long i;
11254 +
11255 + printk(KERN_ERR "PAX: bytes at PC: ");
11256 + for (i = 0; i < 8; i++) {
11257 + unsigned int c;
11258 + if (get_user(c, (unsigned int *)pc+i))
11259 + printk(KERN_CONT "???????? ");
11260 + else
11261 + printk(KERN_CONT "%08x ", c);
11262 + }
11263 + printk("\n");
11264 +}
11265 +#endif
11266 +
11267 static noinline void do_fault_siginfo(int code, int sig, struct pt_regs *regs,
11268 int text_fault)
11269 {
11270 @@ -229,6 +503,24 @@ good_area:
11271 if (!(vma->vm_flags & VM_WRITE))
11272 goto bad_area;
11273 } else {
11274 +
11275 +#ifdef CONFIG_PAX_PAGEEXEC
11276 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && text_fault && !(vma->vm_flags & VM_EXEC)) {
11277 + up_read(&mm->mmap_sem);
11278 + switch (pax_handle_fetch_fault(regs)) {
11279 +
11280 +#ifdef CONFIG_PAX_EMUPLT
11281 + case 2:
11282 + case 3:
11283 + return;
11284 +#endif
11285 +
11286 + }
11287 + pax_report_fault(regs, (void *)regs->pc, (void *)regs->u_regs[UREG_FP]);
11288 + do_group_exit(SIGKILL);
11289 + }
11290 +#endif
11291 +
11292 /* Allow reads even for write-only mappings */
11293 if (!(vma->vm_flags & (VM_READ | VM_EXEC)))
11294 goto bad_area;
11295 diff --git a/arch/sparc/mm/fault_64.c b/arch/sparc/mm/fault_64.c
11296 index 69bb818..6ca35c8 100644
11297 --- a/arch/sparc/mm/fault_64.c
11298 +++ b/arch/sparc/mm/fault_64.c
11299 @@ -22,6 +22,9 @@
11300 #include <linux/kdebug.h>
11301 #include <linux/percpu.h>
11302 #include <linux/context_tracking.h>
11303 +#include <linux/slab.h>
11304 +#include <linux/pagemap.h>
11305 +#include <linux/compiler.h>
11306
11307 #include <asm/page.h>
11308 #include <asm/pgtable.h>
11309 @@ -75,7 +78,7 @@ static void __kprobes bad_kernel_pc(struct pt_regs *regs, unsigned long vaddr)
11310 printk(KERN_CRIT "OOPS: Bogus kernel PC [%016lx] in fault handler\n",
11311 regs->tpc);
11312 printk(KERN_CRIT "OOPS: RPC [%016lx]\n", regs->u_regs[15]);
11313 - printk("OOPS: RPC <%pS>\n", (void *) regs->u_regs[15]);
11314 + printk("OOPS: RPC <%pA>\n", (void *) regs->u_regs[15]);
11315 printk(KERN_CRIT "OOPS: Fault was to vaddr[%lx]\n", vaddr);
11316 dump_stack();
11317 unhandled_fault(regs->tpc, current, regs);
11318 @@ -271,6 +274,466 @@ static void noinline __kprobes bogus_32bit_fault_address(struct pt_regs *regs,
11319 show_regs(regs);
11320 }
11321
11322 +#ifdef CONFIG_PAX_PAGEEXEC
11323 +#ifdef CONFIG_PAX_DLRESOLVE
11324 +static void pax_emuplt_close(struct vm_area_struct *vma)
11325 +{
11326 + vma->vm_mm->call_dl_resolve = 0UL;
11327 +}
11328 +
11329 +static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
11330 +{
11331 + unsigned int *kaddr;
11332 +
11333 + vmf->page = alloc_page(GFP_HIGHUSER);
11334 + if (!vmf->page)
11335 + return VM_FAULT_OOM;
11336 +
11337 + kaddr = kmap(vmf->page);
11338 + memset(kaddr, 0, PAGE_SIZE);
11339 + kaddr[0] = 0x9DE3BFA8U; /* save */
11340 + flush_dcache_page(vmf->page);
11341 + kunmap(vmf->page);
11342 + return VM_FAULT_MAJOR;
11343 +}
11344 +
11345 +static const struct vm_operations_struct pax_vm_ops = {
11346 + .close = pax_emuplt_close,
11347 + .fault = pax_emuplt_fault
11348 +};
11349 +
11350 +static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
11351 +{
11352 + int ret;
11353 +
11354 + INIT_LIST_HEAD(&vma->anon_vma_chain);
11355 + vma->vm_mm = current->mm;
11356 + vma->vm_start = addr;
11357 + vma->vm_end = addr + PAGE_SIZE;
11358 + vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
11359 + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
11360 + vma->vm_ops = &pax_vm_ops;
11361 +
11362 + ret = insert_vm_struct(current->mm, vma);
11363 + if (ret)
11364 + return ret;
11365 +
11366 + ++current->mm->total_vm;
11367 + return 0;
11368 +}
11369 +#endif
11370 +
11371 +/*
11372 + * PaX: decide what to do with offenders (regs->tpc = fault address)
11373 + *
11374 + * returns 1 when task should be killed
11375 + * 2 when patched PLT trampoline was detected
11376 + * 3 when unpatched PLT trampoline was detected
11377 + */
11378 +static int pax_handle_fetch_fault(struct pt_regs *regs)
11379 +{
11380 +
11381 +#ifdef CONFIG_PAX_EMUPLT
11382 + int err;
11383 +
11384 + do { /* PaX: patched PLT emulation #1 */
11385 + unsigned int sethi1, sethi2, jmpl;
11386 +
11387 + err = get_user(sethi1, (unsigned int *)regs->tpc);
11388 + err |= get_user(sethi2, (unsigned int *)(regs->tpc+4));
11389 + err |= get_user(jmpl, (unsigned int *)(regs->tpc+8));
11390 +
11391 + if (err)
11392 + break;
11393 +
11394 + if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
11395 + (sethi2 & 0xFFC00000U) == 0x03000000U &&
11396 + (jmpl & 0xFFFFE000U) == 0x81C06000U)
11397 + {
11398 + unsigned long addr;
11399 +
11400 + regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
11401 + addr = regs->u_regs[UREG_G1];
11402 + addr += (((jmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
11403 +
11404 + if (test_thread_flag(TIF_32BIT))
11405 + addr &= 0xFFFFFFFFUL;
11406 +
11407 + regs->tpc = addr;
11408 + regs->tnpc = addr+4;
11409 + return 2;
11410 + }
11411 + } while (0);
11412 +
11413 + do { /* PaX: patched PLT emulation #2 */
11414 + unsigned int ba;
11415 +
11416 + err = get_user(ba, (unsigned int *)regs->tpc);
11417 +
11418 + if (err)
11419 + break;
11420 +
11421 + if ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30480000U) {
11422 + unsigned long addr;
11423 +
11424 + if ((ba & 0xFFC00000U) == 0x30800000U)
11425 + addr = regs->tpc + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
11426 + else
11427 + addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
11428 +
11429 + if (test_thread_flag(TIF_32BIT))
11430 + addr &= 0xFFFFFFFFUL;
11431 +
11432 + regs->tpc = addr;
11433 + regs->tnpc = addr+4;
11434 + return 2;
11435 + }
11436 + } while (0);
11437 +
11438 + do { /* PaX: patched PLT emulation #3 */
11439 + unsigned int sethi, bajmpl, nop;
11440 +
11441 + err = get_user(sethi, (unsigned int *)regs->tpc);
11442 + err |= get_user(bajmpl, (unsigned int *)(regs->tpc+4));
11443 + err |= get_user(nop, (unsigned int *)(regs->tpc+8));
11444 +
11445 + if (err)
11446 + break;
11447 +
11448 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
11449 + ((bajmpl & 0xFFFFE000U) == 0x81C06000U || (bajmpl & 0xFFF80000U) == 0x30480000U) &&
11450 + nop == 0x01000000U)
11451 + {
11452 + unsigned long addr;
11453 +
11454 + addr = (sethi & 0x003FFFFFU) << 10;
11455 + regs->u_regs[UREG_G1] = addr;
11456 + if ((bajmpl & 0xFFFFE000U) == 0x81C06000U)
11457 + addr += (((bajmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
11458 + else
11459 + addr = regs->tpc + ((((bajmpl | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
11460 +
11461 + if (test_thread_flag(TIF_32BIT))
11462 + addr &= 0xFFFFFFFFUL;
11463 +
11464 + regs->tpc = addr;
11465 + regs->tnpc = addr+4;
11466 + return 2;
11467 + }
11468 + } while (0);
11469 +
11470 + do { /* PaX: patched PLT emulation #4 */
11471 + unsigned int sethi, mov1, call, mov2;
11472 +
11473 + err = get_user(sethi, (unsigned int *)regs->tpc);
11474 + err |= get_user(mov1, (unsigned int *)(regs->tpc+4));
11475 + err |= get_user(call, (unsigned int *)(regs->tpc+8));
11476 + err |= get_user(mov2, (unsigned int *)(regs->tpc+12));
11477 +
11478 + if (err)
11479 + break;
11480 +
11481 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
11482 + mov1 == 0x8210000FU &&
11483 + (call & 0xC0000000U) == 0x40000000U &&
11484 + mov2 == 0x9E100001U)
11485 + {
11486 + unsigned long addr;
11487 +
11488 + regs->u_regs[UREG_G1] = regs->u_regs[UREG_RETPC];
11489 + addr = regs->tpc + 4 + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
11490 +
11491 + if (test_thread_flag(TIF_32BIT))
11492 + addr &= 0xFFFFFFFFUL;
11493 +
11494 + regs->tpc = addr;
11495 + regs->tnpc = addr+4;
11496 + return 2;
11497 + }
11498 + } while (0);
11499 +
11500 + do { /* PaX: patched PLT emulation #5 */
11501 + unsigned int sethi, sethi1, sethi2, or1, or2, sllx, jmpl, nop;
11502 +
11503 + err = get_user(sethi, (unsigned int *)regs->tpc);
11504 + err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
11505 + err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
11506 + err |= get_user(or1, (unsigned int *)(regs->tpc+12));
11507 + err |= get_user(or2, (unsigned int *)(regs->tpc+16));
11508 + err |= get_user(sllx, (unsigned int *)(regs->tpc+20));
11509 + err |= get_user(jmpl, (unsigned int *)(regs->tpc+24));
11510 + err |= get_user(nop, (unsigned int *)(regs->tpc+28));
11511 +
11512 + if (err)
11513 + break;
11514 +
11515 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
11516 + (sethi1 & 0xFFC00000U) == 0x03000000U &&
11517 + (sethi2 & 0xFFC00000U) == 0x0B000000U &&
11518 + (or1 & 0xFFFFE000U) == 0x82106000U &&
11519 + (or2 & 0xFFFFE000U) == 0x8A116000U &&
11520 + sllx == 0x83287020U &&
11521 + jmpl == 0x81C04005U &&
11522 + nop == 0x01000000U)
11523 + {
11524 + unsigned long addr;
11525 +
11526 + regs->u_regs[UREG_G1] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
11527 + regs->u_regs[UREG_G1] <<= 32;
11528 + regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
11529 + addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
11530 + regs->tpc = addr;
11531 + regs->tnpc = addr+4;
11532 + return 2;
11533 + }
11534 + } while (0);
11535 +
11536 + do { /* PaX: patched PLT emulation #6 */
11537 + unsigned int sethi, sethi1, sethi2, sllx, or, jmpl, nop;
11538 +
11539 + err = get_user(sethi, (unsigned int *)regs->tpc);
11540 + err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
11541 + err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
11542 + err |= get_user(sllx, (unsigned int *)(regs->tpc+12));
11543 + err |= get_user(or, (unsigned int *)(regs->tpc+16));
11544 + err |= get_user(jmpl, (unsigned int *)(regs->tpc+20));
11545 + err |= get_user(nop, (unsigned int *)(regs->tpc+24));
11546 +
11547 + if (err)
11548 + break;
11549 +
11550 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
11551 + (sethi1 & 0xFFC00000U) == 0x03000000U &&
11552 + (sethi2 & 0xFFC00000U) == 0x0B000000U &&
11553 + sllx == 0x83287020U &&
11554 + (or & 0xFFFFE000U) == 0x8A116000U &&
11555 + jmpl == 0x81C04005U &&
11556 + nop == 0x01000000U)
11557 + {
11558 + unsigned long addr;
11559 +
11560 + regs->u_regs[UREG_G1] = (sethi1 & 0x003FFFFFU) << 10;
11561 + regs->u_regs[UREG_G1] <<= 32;
11562 + regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or & 0x3FFU);
11563 + addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
11564 + regs->tpc = addr;
11565 + regs->tnpc = addr+4;
11566 + return 2;
11567 + }
11568 + } while (0);
11569 +
11570 + do { /* PaX: unpatched PLT emulation step 1 */
11571 + unsigned int sethi, ba, nop;
11572 +
11573 + err = get_user(sethi, (unsigned int *)regs->tpc);
11574 + err |= get_user(ba, (unsigned int *)(regs->tpc+4));
11575 + err |= get_user(nop, (unsigned int *)(regs->tpc+8));
11576 +
11577 + if (err)
11578 + break;
11579 +
11580 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
11581 + ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
11582 + nop == 0x01000000U)
11583 + {
11584 + unsigned long addr;
11585 + unsigned int save, call;
11586 + unsigned int sethi1, sethi2, or1, or2, sllx, add, jmpl;
11587 +
11588 + if ((ba & 0xFFC00000U) == 0x30800000U)
11589 + addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
11590 + else
11591 + addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
11592 +
11593 + if (test_thread_flag(TIF_32BIT))
11594 + addr &= 0xFFFFFFFFUL;
11595 +
11596 + err = get_user(save, (unsigned int *)addr);
11597 + err |= get_user(call, (unsigned int *)(addr+4));
11598 + err |= get_user(nop, (unsigned int *)(addr+8));
11599 + if (err)
11600 + break;
11601 +
11602 +#ifdef CONFIG_PAX_DLRESOLVE
11603 + if (save == 0x9DE3BFA8U &&
11604 + (call & 0xC0000000U) == 0x40000000U &&
11605 + nop == 0x01000000U)
11606 + {
11607 + struct vm_area_struct *vma;
11608 + unsigned long call_dl_resolve;
11609 +
11610 + down_read(&current->mm->mmap_sem);
11611 + call_dl_resolve = current->mm->call_dl_resolve;
11612 + up_read(&current->mm->mmap_sem);
11613 + if (likely(call_dl_resolve))
11614 + goto emulate;
11615 +
11616 + vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
11617 +
11618 + down_write(&current->mm->mmap_sem);
11619 + if (current->mm->call_dl_resolve) {
11620 + call_dl_resolve = current->mm->call_dl_resolve;
11621 + up_write(&current->mm->mmap_sem);
11622 + if (vma)
11623 + kmem_cache_free(vm_area_cachep, vma);
11624 + goto emulate;
11625 + }
11626 +
11627 + call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
11628 + if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
11629 + up_write(&current->mm->mmap_sem);
11630 + if (vma)
11631 + kmem_cache_free(vm_area_cachep, vma);
11632 + return 1;
11633 + }
11634 +
11635 + if (pax_insert_vma(vma, call_dl_resolve)) {
11636 + up_write(&current->mm->mmap_sem);
11637 + kmem_cache_free(vm_area_cachep, vma);
11638 + return 1;
11639 + }
11640 +
11641 + current->mm->call_dl_resolve = call_dl_resolve;
11642 + up_write(&current->mm->mmap_sem);
11643 +
11644 +emulate:
11645 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
11646 + regs->tpc = call_dl_resolve;
11647 + regs->tnpc = addr+4;
11648 + return 3;
11649 + }
11650 +#endif
11651 +
11652 + /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
11653 + if ((save & 0xFFC00000U) == 0x05000000U &&
11654 + (call & 0xFFFFE000U) == 0x85C0A000U &&
11655 + nop == 0x01000000U)
11656 + {
11657 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
11658 + regs->u_regs[UREG_G2] = addr + 4;
11659 + addr = (save & 0x003FFFFFU) << 10;
11660 + addr += (((call | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
11661 +
11662 + if (test_thread_flag(TIF_32BIT))
11663 + addr &= 0xFFFFFFFFUL;
11664 +
11665 + regs->tpc = addr;
11666 + regs->tnpc = addr+4;
11667 + return 3;
11668 + }
11669 +
11670 + /* PaX: 64-bit PLT stub */
11671 + err = get_user(sethi1, (unsigned int *)addr);
11672 + err |= get_user(sethi2, (unsigned int *)(addr+4));
11673 + err |= get_user(or1, (unsigned int *)(addr+8));
11674 + err |= get_user(or2, (unsigned int *)(addr+12));
11675 + err |= get_user(sllx, (unsigned int *)(addr+16));
11676 + err |= get_user(add, (unsigned int *)(addr+20));
11677 + err |= get_user(jmpl, (unsigned int *)(addr+24));
11678 + err |= get_user(nop, (unsigned int *)(addr+28));
11679 + if (err)
11680 + break;
11681 +
11682 + if ((sethi1 & 0xFFC00000U) == 0x09000000U &&
11683 + (sethi2 & 0xFFC00000U) == 0x0B000000U &&
11684 + (or1 & 0xFFFFE000U) == 0x88112000U &&
11685 + (or2 & 0xFFFFE000U) == 0x8A116000U &&
11686 + sllx == 0x89293020U &&
11687 + add == 0x8A010005U &&
11688 + jmpl == 0x89C14000U &&
11689 + nop == 0x01000000U)
11690 + {
11691 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
11692 + regs->u_regs[UREG_G4] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
11693 + regs->u_regs[UREG_G4] <<= 32;
11694 + regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
11695 + regs->u_regs[UREG_G5] += regs->u_regs[UREG_G4];
11696 + regs->u_regs[UREG_G4] = addr + 24;
11697 + addr = regs->u_regs[UREG_G5];
11698 + regs->tpc = addr;
11699 + regs->tnpc = addr+4;
11700 + return 3;
11701 + }
11702 + }
11703 + } while (0);
11704 +
11705 +#ifdef CONFIG_PAX_DLRESOLVE
11706 + do { /* PaX: unpatched PLT emulation step 2 */
11707 + unsigned int save, call, nop;
11708 +
11709 + err = get_user(save, (unsigned int *)(regs->tpc-4));
11710 + err |= get_user(call, (unsigned int *)regs->tpc);
11711 + err |= get_user(nop, (unsigned int *)(regs->tpc+4));
11712 + if (err)
11713 + break;
11714 +
11715 + if (save == 0x9DE3BFA8U &&
11716 + (call & 0xC0000000U) == 0x40000000U &&
11717 + nop == 0x01000000U)
11718 + {
11719 + unsigned long dl_resolve = regs->tpc + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
11720 +
11721 + if (test_thread_flag(TIF_32BIT))
11722 + dl_resolve &= 0xFFFFFFFFUL;
11723 +
11724 + regs->u_regs[UREG_RETPC] = regs->tpc;
11725 + regs->tpc = dl_resolve;
11726 + regs->tnpc = dl_resolve+4;
11727 + return 3;
11728 + }
11729 + } while (0);
11730 +#endif
11731 +
11732 + do { /* PaX: patched PLT emulation #7, must be AFTER the unpatched PLT emulation */
11733 + unsigned int sethi, ba, nop;
11734 +
11735 + err = get_user(sethi, (unsigned int *)regs->tpc);
11736 + err |= get_user(ba, (unsigned int *)(regs->tpc+4));
11737 + err |= get_user(nop, (unsigned int *)(regs->tpc+8));
11738 +
11739 + if (err)
11740 + break;
11741 +
11742 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
11743 + (ba & 0xFFF00000U) == 0x30600000U &&
11744 + nop == 0x01000000U)
11745 + {
11746 + unsigned long addr;
11747 +
11748 + addr = (sethi & 0x003FFFFFU) << 10;
11749 + regs->u_regs[UREG_G1] = addr;
11750 + addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
11751 +
11752 + if (test_thread_flag(TIF_32BIT))
11753 + addr &= 0xFFFFFFFFUL;
11754 +
11755 + regs->tpc = addr;
11756 + regs->tnpc = addr+4;
11757 + return 2;
11758 + }
11759 + } while (0);
11760 +
11761 +#endif
11762 +
11763 + return 1;
11764 +}
11765 +
11766 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
11767 +{
11768 + unsigned long i;
11769 +
11770 + printk(KERN_ERR "PAX: bytes at PC: ");
11771 + for (i = 0; i < 8; i++) {
11772 + unsigned int c;
11773 + if (get_user(c, (unsigned int *)pc+i))
11774 + printk(KERN_CONT "???????? ");
11775 + else
11776 + printk(KERN_CONT "%08x ", c);
11777 + }
11778 + printk("\n");
11779 +}
11780 +#endif
11781 +
11782 asmlinkage void __kprobes do_sparc64_fault(struct pt_regs *regs)
11783 {
11784 enum ctx_state prev_state = exception_enter();
11785 @@ -344,6 +807,29 @@ retry:
11786 if (!vma)
11787 goto bad_area;
11788
11789 +#ifdef CONFIG_PAX_PAGEEXEC
11790 + /* PaX: detect ITLB misses on non-exec pages */
11791 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && vma->vm_start <= address &&
11792 + !(vma->vm_flags & VM_EXEC) && (fault_code & FAULT_CODE_ITLB))
11793 + {
11794 + if (address != regs->tpc)
11795 + goto good_area;
11796 +
11797 + up_read(&mm->mmap_sem);
11798 + switch (pax_handle_fetch_fault(regs)) {
11799 +
11800 +#ifdef CONFIG_PAX_EMUPLT
11801 + case 2:
11802 + case 3:
11803 + return;
11804 +#endif
11805 +
11806 + }
11807 + pax_report_fault(regs, (void *)regs->tpc, (void *)(regs->u_regs[UREG_FP] + STACK_BIAS));
11808 + do_group_exit(SIGKILL);
11809 + }
11810 +#endif
11811 +
11812 /* Pure DTLB misses do not tell us whether the fault causing
11813 * load/store/atomic was a write or not, it only says that there
11814 * was no match. So in such a case we (carefully) read the
11815 diff --git a/arch/sparc/mm/hugetlbpage.c b/arch/sparc/mm/hugetlbpage.c
11816 index 3096317..a7b7654 100644
11817 --- a/arch/sparc/mm/hugetlbpage.c
11818 +++ b/arch/sparc/mm/hugetlbpage.c
11819 @@ -26,7 +26,8 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *filp,
11820 unsigned long addr,
11821 unsigned long len,
11822 unsigned long pgoff,
11823 - unsigned long flags)
11824 + unsigned long flags,
11825 + unsigned long offset)
11826 {
11827 unsigned long task_size = TASK_SIZE;
11828 struct vm_unmapped_area_info info;
11829 @@ -36,15 +37,22 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *filp,
11830
11831 info.flags = 0;
11832 info.length = len;
11833 - info.low_limit = TASK_UNMAPPED_BASE;
11834 + info.low_limit = mm->mmap_base;
11835 info.high_limit = min(task_size, VA_EXCLUDE_START);
11836 info.align_mask = PAGE_MASK & ~HPAGE_MASK;
11837 info.align_offset = 0;
11838 + info.threadstack_offset = offset;
11839 addr = vm_unmapped_area(&info);
11840
11841 if ((addr & ~PAGE_MASK) && task_size > VA_EXCLUDE_END) {
11842 VM_BUG_ON(addr != -ENOMEM);
11843 info.low_limit = VA_EXCLUDE_END;
11844 +
11845 +#ifdef CONFIG_PAX_RANDMMAP
11846 + if (mm->pax_flags & MF_PAX_RANDMMAP)
11847 + info.low_limit += mm->delta_mmap;
11848 +#endif
11849 +
11850 info.high_limit = task_size;
11851 addr = vm_unmapped_area(&info);
11852 }
11853 @@ -56,7 +64,8 @@ static unsigned long
11854 hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
11855 const unsigned long len,
11856 const unsigned long pgoff,
11857 - const unsigned long flags)
11858 + const unsigned long flags,
11859 + const unsigned long offset)
11860 {
11861 struct mm_struct *mm = current->mm;
11862 unsigned long addr = addr0;
11863 @@ -71,6 +80,7 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
11864 info.high_limit = mm->mmap_base;
11865 info.align_mask = PAGE_MASK & ~HPAGE_MASK;
11866 info.align_offset = 0;
11867 + info.threadstack_offset = offset;
11868 addr = vm_unmapped_area(&info);
11869
11870 /*
11871 @@ -83,6 +93,12 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
11872 VM_BUG_ON(addr != -ENOMEM);
11873 info.flags = 0;
11874 info.low_limit = TASK_UNMAPPED_BASE;
11875 +
11876 +#ifdef CONFIG_PAX_RANDMMAP
11877 + if (mm->pax_flags & MF_PAX_RANDMMAP)
11878 + info.low_limit += mm->delta_mmap;
11879 +#endif
11880 +
11881 info.high_limit = STACK_TOP32;
11882 addr = vm_unmapped_area(&info);
11883 }
11884 @@ -97,6 +113,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
11885 struct mm_struct *mm = current->mm;
11886 struct vm_area_struct *vma;
11887 unsigned long task_size = TASK_SIZE;
11888 + unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
11889
11890 if (test_thread_flag(TIF_32BIT))
11891 task_size = STACK_TOP32;
11892 @@ -112,19 +129,22 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
11893 return addr;
11894 }
11895
11896 +#ifdef CONFIG_PAX_RANDMMAP
11897 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
11898 +#endif
11899 +
11900 if (addr) {
11901 addr = ALIGN(addr, HPAGE_SIZE);
11902 vma = find_vma(mm, addr);
11903 - if (task_size - len >= addr &&
11904 - (!vma || addr + len <= vma->vm_start))
11905 + if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
11906 return addr;
11907 }
11908 if (mm->get_unmapped_area == arch_get_unmapped_area)
11909 return hugetlb_get_unmapped_area_bottomup(file, addr, len,
11910 - pgoff, flags);
11911 + pgoff, flags, offset);
11912 else
11913 return hugetlb_get_unmapped_area_topdown(file, addr, len,
11914 - pgoff, flags);
11915 + pgoff, flags, offset);
11916 }
11917
11918 pte_t *huge_pte_alloc(struct mm_struct *mm,
11919 diff --git a/arch/sparc/mm/init_64.c b/arch/sparc/mm/init_64.c
11920 index 5322e53..f820c5e 100644
11921 --- a/arch/sparc/mm/init_64.c
11922 +++ b/arch/sparc/mm/init_64.c
11923 @@ -188,9 +188,9 @@ unsigned long sparc64_kern_sec_context __read_mostly;
11924 int num_kernel_image_mappings;
11925
11926 #ifdef CONFIG_DEBUG_DCFLUSH
11927 -atomic_t dcpage_flushes = ATOMIC_INIT(0);
11928 +atomic_unchecked_t dcpage_flushes = ATOMIC_INIT(0);
11929 #ifdef CONFIG_SMP
11930 -atomic_t dcpage_flushes_xcall = ATOMIC_INIT(0);
11931 +atomic_unchecked_t dcpage_flushes_xcall = ATOMIC_INIT(0);
11932 #endif
11933 #endif
11934
11935 @@ -198,7 +198,7 @@ inline void flush_dcache_page_impl(struct page *page)
11936 {
11937 BUG_ON(tlb_type == hypervisor);
11938 #ifdef CONFIG_DEBUG_DCFLUSH
11939 - atomic_inc(&dcpage_flushes);
11940 + atomic_inc_unchecked(&dcpage_flushes);
11941 #endif
11942
11943 #ifdef DCACHE_ALIASING_POSSIBLE
11944 @@ -466,10 +466,10 @@ void mmu_info(struct seq_file *m)
11945
11946 #ifdef CONFIG_DEBUG_DCFLUSH
11947 seq_printf(m, "DCPageFlushes\t: %d\n",
11948 - atomic_read(&dcpage_flushes));
11949 + atomic_read_unchecked(&dcpage_flushes));
11950 #ifdef CONFIG_SMP
11951 seq_printf(m, "DCPageFlushesXC\t: %d\n",
11952 - atomic_read(&dcpage_flushes_xcall));
11953 + atomic_read_unchecked(&dcpage_flushes_xcall));
11954 #endif /* CONFIG_SMP */
11955 #endif /* CONFIG_DEBUG_DCFLUSH */
11956 }
11957 diff --git a/arch/tile/Kconfig b/arch/tile/Kconfig
11958 index b3692ce..e4517c9 100644
11959 --- a/arch/tile/Kconfig
11960 +++ b/arch/tile/Kconfig
11961 @@ -184,6 +184,7 @@ source "kernel/Kconfig.hz"
11962
11963 config KEXEC
11964 bool "kexec system call"
11965 + depends on !GRKERNSEC_KMEM
11966 ---help---
11967 kexec is a system call that implements the ability to shutdown your
11968 current kernel, and to start another kernel. It is like a reboot
11969 diff --git a/arch/tile/include/asm/atomic_64.h b/arch/tile/include/asm/atomic_64.h
11970 index ad220ee..2f537b3 100644
11971 --- a/arch/tile/include/asm/atomic_64.h
11972 +++ b/arch/tile/include/asm/atomic_64.h
11973 @@ -105,6 +105,16 @@ static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
11974
11975 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
11976
11977 +#define atomic64_read_unchecked(v) atomic64_read(v)
11978 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
11979 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
11980 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
11981 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
11982 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
11983 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
11984 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
11985 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
11986 +
11987 /* Atomic dec and inc don't implement barrier, so provide them if needed. */
11988 #define smp_mb__before_atomic_dec() smp_mb()
11989 #define smp_mb__after_atomic_dec() smp_mb()
11990 diff --git a/arch/tile/include/asm/cache.h b/arch/tile/include/asm/cache.h
11991 index 6160761..00cac88 100644
11992 --- a/arch/tile/include/asm/cache.h
11993 +++ b/arch/tile/include/asm/cache.h
11994 @@ -15,11 +15,12 @@
11995 #ifndef _ASM_TILE_CACHE_H
11996 #define _ASM_TILE_CACHE_H
11997
11998 +#include <linux/const.h>
11999 #include <arch/chip.h>
12000
12001 /* bytes per L1 data cache line */
12002 #define L1_CACHE_SHIFT CHIP_L1D_LOG_LINE_SIZE()
12003 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
12004 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
12005
12006 /* bytes per L2 cache line */
12007 #define L2_CACHE_SHIFT CHIP_L2_LOG_LINE_SIZE()
12008 diff --git a/arch/tile/include/asm/uaccess.h b/arch/tile/include/asm/uaccess.h
12009 index b6cde32..c0cb736 100644
12010 --- a/arch/tile/include/asm/uaccess.h
12011 +++ b/arch/tile/include/asm/uaccess.h
12012 @@ -414,9 +414,9 @@ static inline unsigned long __must_check copy_from_user(void *to,
12013 const void __user *from,
12014 unsigned long n)
12015 {
12016 - int sz = __compiletime_object_size(to);
12017 + size_t sz = __compiletime_object_size(to);
12018
12019 - if (likely(sz == -1 || sz >= n))
12020 + if (likely(sz == (size_t)-1 || sz >= n))
12021 n = _copy_from_user(to, from, n);
12022 else
12023 copy_from_user_overflow();
12024 diff --git a/arch/tile/mm/hugetlbpage.c b/arch/tile/mm/hugetlbpage.c
12025 index 0cb3bba..7338b2d 100644
12026 --- a/arch/tile/mm/hugetlbpage.c
12027 +++ b/arch/tile/mm/hugetlbpage.c
12028 @@ -212,6 +212,7 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *file,
12029 info.high_limit = TASK_SIZE;
12030 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
12031 info.align_offset = 0;
12032 + info.threadstack_offset = 0;
12033 return vm_unmapped_area(&info);
12034 }
12035
12036 @@ -229,6 +230,7 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
12037 info.high_limit = current->mm->mmap_base;
12038 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
12039 info.align_offset = 0;
12040 + info.threadstack_offset = 0;
12041 addr = vm_unmapped_area(&info);
12042
12043 /*
12044 diff --git a/arch/um/Makefile b/arch/um/Makefile
12045 index 36e658a..71a5c5a 100644
12046 --- a/arch/um/Makefile
12047 +++ b/arch/um/Makefile
12048 @@ -72,6 +72,10 @@ USER_CFLAGS = $(patsubst $(KERNEL_DEFINES),,$(patsubst -D__KERNEL__,,\
12049 $(patsubst -I%,,$(KBUILD_CFLAGS)))) $(ARCH_INCLUDE) $(MODE_INCLUDE) \
12050 $(filter -I%,$(CFLAGS)) -D_FILE_OFFSET_BITS=64 -idirafter include
12051
12052 +ifdef CONSTIFY_PLUGIN
12053 +USER_CFLAGS += -fplugin-arg-constify_plugin-no-constify
12054 +endif
12055 +
12056 #This will adjust *FLAGS accordingly to the platform.
12057 include $(srctree)/$(ARCH_DIR)/Makefile-os-$(OS)
12058
12059 diff --git a/arch/um/include/asm/cache.h b/arch/um/include/asm/cache.h
12060 index 19e1bdd..3665b77 100644
12061 --- a/arch/um/include/asm/cache.h
12062 +++ b/arch/um/include/asm/cache.h
12063 @@ -1,6 +1,7 @@
12064 #ifndef __UM_CACHE_H
12065 #define __UM_CACHE_H
12066
12067 +#include <linux/const.h>
12068
12069 #if defined(CONFIG_UML_X86) && !defined(CONFIG_64BIT)
12070 # define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
12071 @@ -12,6 +13,6 @@
12072 # define L1_CACHE_SHIFT 5
12073 #endif
12074
12075 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
12076 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
12077
12078 #endif
12079 diff --git a/arch/um/include/asm/kmap_types.h b/arch/um/include/asm/kmap_types.h
12080 index 2e0a6b1..a64d0f5 100644
12081 --- a/arch/um/include/asm/kmap_types.h
12082 +++ b/arch/um/include/asm/kmap_types.h
12083 @@ -8,6 +8,6 @@
12084
12085 /* No more #include "asm/arch/kmap_types.h" ! */
12086
12087 -#define KM_TYPE_NR 14
12088 +#define KM_TYPE_NR 15
12089
12090 #endif
12091 diff --git a/arch/um/include/asm/page.h b/arch/um/include/asm/page.h
12092 index 5ff53d9..5850cdf 100644
12093 --- a/arch/um/include/asm/page.h
12094 +++ b/arch/um/include/asm/page.h
12095 @@ -14,6 +14,9 @@
12096 #define PAGE_SIZE (_AC(1, UL) << PAGE_SHIFT)
12097 #define PAGE_MASK (~(PAGE_SIZE-1))
12098
12099 +#define ktla_ktva(addr) (addr)
12100 +#define ktva_ktla(addr) (addr)
12101 +
12102 #ifndef __ASSEMBLY__
12103
12104 struct page;
12105 diff --git a/arch/um/include/asm/pgtable-3level.h b/arch/um/include/asm/pgtable-3level.h
12106 index 0032f92..cd151e0 100644
12107 --- a/arch/um/include/asm/pgtable-3level.h
12108 +++ b/arch/um/include/asm/pgtable-3level.h
12109 @@ -58,6 +58,7 @@
12110 #define pud_present(x) (pud_val(x) & _PAGE_PRESENT)
12111 #define pud_populate(mm, pud, pmd) \
12112 set_pud(pud, __pud(_PAGE_TABLE + __pa(pmd)))
12113 +#define pud_populate_kernel(mm, pud, pmd) pud_populate((mm), (pud), (pmd))
12114
12115 #ifdef CONFIG_64BIT
12116 #define set_pud(pudptr, pudval) set_64bit((u64 *) (pudptr), pud_val(pudval))
12117 diff --git a/arch/um/kernel/process.c b/arch/um/kernel/process.c
12118 index eecc414..48adb87 100644
12119 --- a/arch/um/kernel/process.c
12120 +++ b/arch/um/kernel/process.c
12121 @@ -356,22 +356,6 @@ int singlestepping(void * t)
12122 return 2;
12123 }
12124
12125 -/*
12126 - * Only x86 and x86_64 have an arch_align_stack().
12127 - * All other arches have "#define arch_align_stack(x) (x)"
12128 - * in their asm/system.h
12129 - * As this is included in UML from asm-um/system-generic.h,
12130 - * we can use it to behave as the subarch does.
12131 - */
12132 -#ifndef arch_align_stack
12133 -unsigned long arch_align_stack(unsigned long sp)
12134 -{
12135 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
12136 - sp -= get_random_int() % 8192;
12137 - return sp & ~0xf;
12138 -}
12139 -#endif
12140 -
12141 unsigned long get_wchan(struct task_struct *p)
12142 {
12143 unsigned long stack_page, sp, ip;
12144 diff --git a/arch/unicore32/include/asm/cache.h b/arch/unicore32/include/asm/cache.h
12145 index ad8f795..2c7eec6 100644
12146 --- a/arch/unicore32/include/asm/cache.h
12147 +++ b/arch/unicore32/include/asm/cache.h
12148 @@ -12,8 +12,10 @@
12149 #ifndef __UNICORE_CACHE_H__
12150 #define __UNICORE_CACHE_H__
12151
12152 -#define L1_CACHE_SHIFT (5)
12153 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
12154 +#include <linux/const.h>
12155 +
12156 +#define L1_CACHE_SHIFT 5
12157 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
12158
12159 /*
12160 * Memory returned by kmalloc() may be used for DMA, so we must make
12161 diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
12162 index 0952ecd..9cf578c 100644
12163 --- a/arch/x86/Kconfig
12164 +++ b/arch/x86/Kconfig
12165 @@ -249,7 +249,7 @@ config X86_HT
12166
12167 config X86_32_LAZY_GS
12168 def_bool y
12169 - depends on X86_32 && !CC_STACKPROTECTOR
12170 + depends on X86_32 && !CC_STACKPROTECTOR && !PAX_MEMORY_UDEREF
12171
12172 config ARCH_HWEIGHT_CFLAGS
12173 string
12174 @@ -602,6 +602,7 @@ config SCHED_OMIT_FRAME_POINTER
12175
12176 menuconfig HYPERVISOR_GUEST
12177 bool "Linux guest support"
12178 + depends on !GRKERNSEC_CONFIG_AUTO || GRKERNSEC_CONFIG_VIRT_GUEST || (GRKERNSEC_CONFIG_VIRT_HOST && GRKERNSEC_CONFIG_VIRT_XEN)
12179 ---help---
12180 Say Y here to enable options for running Linux under various hyper-
12181 visors. This option enables basic hypervisor detection and platform
12182 @@ -1127,7 +1128,7 @@ choice
12183
12184 config NOHIGHMEM
12185 bool "off"
12186 - depends on !X86_NUMAQ
12187 + depends on !X86_NUMAQ && !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
12188 ---help---
12189 Linux can use up to 64 Gigabytes of physical memory on x86 systems.
12190 However, the address space of 32-bit x86 processors is only 4
12191 @@ -1164,7 +1165,7 @@ config NOHIGHMEM
12192
12193 config HIGHMEM4G
12194 bool "4GB"
12195 - depends on !X86_NUMAQ
12196 + depends on !X86_NUMAQ && !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
12197 ---help---
12198 Select this if you have a 32-bit processor and between 1 and 4
12199 gigabytes of physical RAM.
12200 @@ -1217,7 +1218,7 @@ config PAGE_OFFSET
12201 hex
12202 default 0xB0000000 if VMSPLIT_3G_OPT
12203 default 0x80000000 if VMSPLIT_2G
12204 - default 0x78000000 if VMSPLIT_2G_OPT
12205 + default 0x70000000 if VMSPLIT_2G_OPT
12206 default 0x40000000 if VMSPLIT_1G
12207 default 0xC0000000
12208 depends on X86_32
12209 @@ -1619,6 +1620,7 @@ config SECCOMP
12210
12211 config CC_STACKPROTECTOR
12212 bool "Enable -fstack-protector buffer overflow detection"
12213 + depends on X86_64 || !PAX_MEMORY_UDEREF
12214 ---help---
12215 This option turns on the -fstack-protector GCC feature. This
12216 feature puts, at the beginning of functions, a canary value on
12217 @@ -1637,6 +1639,7 @@ source kernel/Kconfig.hz
12218
12219 config KEXEC
12220 bool "kexec system call"
12221 + depends on !GRKERNSEC_KMEM
12222 ---help---
12223 kexec is a system call that implements the ability to shutdown your
12224 current kernel, and to start another kernel. It is like a reboot
12225 @@ -1738,6 +1741,8 @@ config X86_NEED_RELOCS
12226 config PHYSICAL_ALIGN
12227 hex "Alignment value to which kernel should be aligned"
12228 default "0x1000000"
12229 + range 0x200000 0x1000000 if PAX_KERNEXEC && X86_PAE
12230 + range 0x400000 0x1000000 if PAX_KERNEXEC && !X86_PAE
12231 range 0x2000 0x1000000 if X86_32
12232 range 0x200000 0x1000000 if X86_64
12233 ---help---
12234 @@ -1817,9 +1822,10 @@ config DEBUG_HOTPLUG_CPU0
12235 If unsure, say N.
12236
12237 config COMPAT_VDSO
12238 - def_bool y
12239 + def_bool n
12240 prompt "Compat VDSO support"
12241 depends on X86_32 || IA32_EMULATION
12242 + depends on !PAX_PAGEEXEC && !PAX_SEGMEXEC && !PAX_KERNEXEC && !PAX_MEMORY_UDEREF
12243 ---help---
12244 Map the 32-bit VDSO to the predictable old-style address too.
12245
12246 diff --git a/arch/x86/Kconfig.cpu b/arch/x86/Kconfig.cpu
12247 index c026cca..14657ae 100644
12248 --- a/arch/x86/Kconfig.cpu
12249 +++ b/arch/x86/Kconfig.cpu
12250 @@ -319,7 +319,7 @@ config X86_PPRO_FENCE
12251
12252 config X86_F00F_BUG
12253 def_bool y
12254 - depends on M586MMX || M586TSC || M586 || M486
12255 + depends on (M586MMX || M586TSC || M586 || M486) && !PAX_KERNEXEC
12256
12257 config X86_INVD_BUG
12258 def_bool y
12259 @@ -327,7 +327,7 @@ config X86_INVD_BUG
12260
12261 config X86_ALIGNMENT_16
12262 def_bool y
12263 - depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || MELAN || MK6 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
12264 + depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || X86_ELAN || MK8 || MK7 || MK6 || MCORE2 || MPENTIUM4 || MPENTIUMIII || MPENTIUMII || M686 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
12265
12266 config X86_INTEL_USERCOPY
12267 def_bool y
12268 @@ -373,7 +373,7 @@ config X86_CMPXCHG64
12269 # generates cmov.
12270 config X86_CMOV
12271 def_bool y
12272 - depends on (MK8 || MK7 || MCORE2 || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
12273 + depends on (MK8 || MK7 || MCORE2 || MPSC || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
12274
12275 config X86_MINIMUM_CPU_FAMILY
12276 int
12277 diff --git a/arch/x86/Kconfig.debug b/arch/x86/Kconfig.debug
12278 index 0f3621e..282f24b 100644
12279 --- a/arch/x86/Kconfig.debug
12280 +++ b/arch/x86/Kconfig.debug
12281 @@ -84,7 +84,7 @@ config X86_PTDUMP
12282 config DEBUG_RODATA
12283 bool "Write protect kernel read-only data structures"
12284 default y
12285 - depends on DEBUG_KERNEL
12286 + depends on DEBUG_KERNEL && BROKEN
12287 ---help---
12288 Mark the kernel read-only data as write-protected in the pagetables,
12289 in order to catch accidental (and incorrect) writes to such const
12290 @@ -102,7 +102,7 @@ config DEBUG_RODATA_TEST
12291
12292 config DEBUG_SET_MODULE_RONX
12293 bool "Set loadable kernel module data as NX and text as RO"
12294 - depends on MODULES
12295 + depends on MODULES && BROKEN
12296 ---help---
12297 This option helps catch unintended modifications to loadable
12298 kernel module's text and read-only data. It also prevents execution
12299 diff --git a/arch/x86/Makefile b/arch/x86/Makefile
12300 index 57d0215..b4373fb 100644
12301 --- a/arch/x86/Makefile
12302 +++ b/arch/x86/Makefile
12303 @@ -49,14 +49,12 @@ ifeq ($(CONFIG_X86_32),y)
12304 # CPU-specific tuning. Anything which can be shared with UML should go here.
12305 include $(srctree)/arch/x86/Makefile_32.cpu
12306 KBUILD_CFLAGS += $(cflags-y)
12307 -
12308 - # temporary until string.h is fixed
12309 - KBUILD_CFLAGS += -ffreestanding
12310 else
12311 BITS := 64
12312 UTS_MACHINE := x86_64
12313 CHECKFLAGS += -D__x86_64__ -m64
12314
12315 + biarch := $(call cc-option,-m64)
12316 KBUILD_AFLAGS += -m64
12317 KBUILD_CFLAGS += -m64
12318
12319 @@ -89,6 +87,9 @@ else
12320 KBUILD_CFLAGS += -maccumulate-outgoing-args
12321 endif
12322
12323 +# temporary until string.h is fixed
12324 +KBUILD_CFLAGS += -ffreestanding
12325 +
12326 ifdef CONFIG_CC_STACKPROTECTOR
12327 cc_has_sp := $(srctree)/scripts/gcc-x86_$(BITS)-has-stack-protector.sh
12328 ifeq ($(shell $(CONFIG_SHELL) $(cc_has_sp) $(CC) $(KBUILD_CPPFLAGS) $(biarch)),y)
12329 @@ -247,3 +248,12 @@ define archhelp
12330 echo ' FDINITRD=file initrd for the booted kernel'
12331 echo ' kvmconfig - Enable additional options for guest kernel support'
12332 endef
12333 +
12334 +define OLD_LD
12335 +
12336 +*** ${VERSION}.${PATCHLEVEL} PaX kernels no longer build correctly with old versions of binutils.
12337 +*** Please upgrade your binutils to 2.18 or newer
12338 +endef
12339 +
12340 +archprepare:
12341 + $(if $(LDFLAGS_BUILD_ID),,$(error $(OLD_LD)))
12342 diff --git a/arch/x86/boot/Makefile b/arch/x86/boot/Makefile
12343 index d9c1195..a26ca0d 100644
12344 --- a/arch/x86/boot/Makefile
12345 +++ b/arch/x86/boot/Makefile
12346 @@ -65,6 +65,9 @@ KBUILD_CFLAGS := $(USERINCLUDE) -m32 -g -Os -D_SETUP -D__KERNEL__ \
12347 $(call cc-option, -fno-unit-at-a-time)) \
12348 $(call cc-option, -fno-stack-protector) \
12349 $(call cc-option, -mpreferred-stack-boundary=2)
12350 +ifdef CONSTIFY_PLUGIN
12351 +KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
12352 +endif
12353 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
12354 GCOV_PROFILE := n
12355
12356 diff --git a/arch/x86/boot/bitops.h b/arch/x86/boot/bitops.h
12357 index 878e4b9..20537ab 100644
12358 --- a/arch/x86/boot/bitops.h
12359 +++ b/arch/x86/boot/bitops.h
12360 @@ -26,7 +26,7 @@ static inline int variable_test_bit(int nr, const void *addr)
12361 u8 v;
12362 const u32 *p = (const u32 *)addr;
12363
12364 - asm("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
12365 + asm volatile("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
12366 return v;
12367 }
12368
12369 @@ -37,7 +37,7 @@ static inline int variable_test_bit(int nr, const void *addr)
12370
12371 static inline void set_bit(int nr, void *addr)
12372 {
12373 - asm("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
12374 + asm volatile("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
12375 }
12376
12377 #endif /* BOOT_BITOPS_H */
12378 diff --git a/arch/x86/boot/boot.h b/arch/x86/boot/boot.h
12379 index ef72bae..353a184 100644
12380 --- a/arch/x86/boot/boot.h
12381 +++ b/arch/x86/boot/boot.h
12382 @@ -85,7 +85,7 @@ static inline void io_delay(void)
12383 static inline u16 ds(void)
12384 {
12385 u16 seg;
12386 - asm("movw %%ds,%0" : "=rm" (seg));
12387 + asm volatile("movw %%ds,%0" : "=rm" (seg));
12388 return seg;
12389 }
12390
12391 @@ -181,7 +181,7 @@ static inline void wrgs32(u32 v, addr_t addr)
12392 static inline int memcmp(const void *s1, const void *s2, size_t len)
12393 {
12394 u8 diff;
12395 - asm("repe; cmpsb; setnz %0"
12396 + asm volatile("repe; cmpsb; setnz %0"
12397 : "=qm" (diff), "+D" (s1), "+S" (s2), "+c" (len));
12398 return diff;
12399 }
12400 diff --git a/arch/x86/boot/compressed/Makefile b/arch/x86/boot/compressed/Makefile
12401 index c8a6792..2402765 100644
12402 --- a/arch/x86/boot/compressed/Makefile
12403 +++ b/arch/x86/boot/compressed/Makefile
12404 @@ -16,6 +16,9 @@ KBUILD_CFLAGS += $(cflags-y)
12405 KBUILD_CFLAGS += -mno-mmx -mno-sse
12406 KBUILD_CFLAGS += $(call cc-option,-ffreestanding)
12407 KBUILD_CFLAGS += $(call cc-option,-fno-stack-protector)
12408 +ifdef CONSTIFY_PLUGIN
12409 +KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
12410 +endif
12411
12412 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
12413 GCOV_PROFILE := n
12414 diff --git a/arch/x86/boot/compressed/efi_stub_32.S b/arch/x86/boot/compressed/efi_stub_32.S
12415 index a53440e..c3dbf1e 100644
12416 --- a/arch/x86/boot/compressed/efi_stub_32.S
12417 +++ b/arch/x86/boot/compressed/efi_stub_32.S
12418 @@ -46,16 +46,13 @@ ENTRY(efi_call_phys)
12419 * parameter 2, ..., param n. To make things easy, we save the return
12420 * address of efi_call_phys in a global variable.
12421 */
12422 - popl %ecx
12423 - movl %ecx, saved_return_addr(%edx)
12424 - /* get the function pointer into ECX*/
12425 - popl %ecx
12426 - movl %ecx, efi_rt_function_ptr(%edx)
12427 + popl saved_return_addr(%edx)
12428 + popl efi_rt_function_ptr(%edx)
12429
12430 /*
12431 * 3. Call the physical function.
12432 */
12433 - call *%ecx
12434 + call *efi_rt_function_ptr(%edx)
12435
12436 /*
12437 * 4. Balance the stack. And because EAX contain the return value,
12438 @@ -67,15 +64,12 @@ ENTRY(efi_call_phys)
12439 1: popl %edx
12440 subl $1b, %edx
12441
12442 - movl efi_rt_function_ptr(%edx), %ecx
12443 - pushl %ecx
12444 + pushl efi_rt_function_ptr(%edx)
12445
12446 /*
12447 * 10. Push the saved return address onto the stack and return.
12448 */
12449 - movl saved_return_addr(%edx), %ecx
12450 - pushl %ecx
12451 - ret
12452 + jmpl *saved_return_addr(%edx)
12453 ENDPROC(efi_call_phys)
12454 .previous
12455
12456 diff --git a/arch/x86/boot/compressed/head_32.S b/arch/x86/boot/compressed/head_32.S
12457 index 5d6f689..9d06730 100644
12458 --- a/arch/x86/boot/compressed/head_32.S
12459 +++ b/arch/x86/boot/compressed/head_32.S
12460 @@ -118,7 +118,7 @@ preferred_addr:
12461 notl %eax
12462 andl %eax, %ebx
12463 #else
12464 - movl $LOAD_PHYSICAL_ADDR, %ebx
12465 + movl $____LOAD_PHYSICAL_ADDR, %ebx
12466 #endif
12467
12468 /* Target address to relocate to for decompression */
12469 diff --git a/arch/x86/boot/compressed/head_64.S b/arch/x86/boot/compressed/head_64.S
12470 index c337422..2c5be72 100644
12471 --- a/arch/x86/boot/compressed/head_64.S
12472 +++ b/arch/x86/boot/compressed/head_64.S
12473 @@ -95,7 +95,7 @@ ENTRY(startup_32)
12474 notl %eax
12475 andl %eax, %ebx
12476 #else
12477 - movl $LOAD_PHYSICAL_ADDR, %ebx
12478 + movl $____LOAD_PHYSICAL_ADDR, %ebx
12479 #endif
12480
12481 /* Target address to relocate to for decompression */
12482 @@ -270,7 +270,7 @@ preferred_addr:
12483 notq %rax
12484 andq %rax, %rbp
12485 #else
12486 - movq $LOAD_PHYSICAL_ADDR, %rbp
12487 + movq $____LOAD_PHYSICAL_ADDR, %rbp
12488 #endif
12489
12490 /* Target address to relocate to for decompression */
12491 @@ -362,8 +362,8 @@ gdt:
12492 .long gdt
12493 .word 0
12494 .quad 0x0000000000000000 /* NULL descriptor */
12495 - .quad 0x00af9a000000ffff /* __KERNEL_CS */
12496 - .quad 0x00cf92000000ffff /* __KERNEL_DS */
12497 + .quad 0x00af9b000000ffff /* __KERNEL_CS */
12498 + .quad 0x00cf93000000ffff /* __KERNEL_DS */
12499 .quad 0x0080890000000000 /* TS descriptor */
12500 .quad 0x0000000000000000 /* TS continued */
12501 gdt_end:
12502 diff --git a/arch/x86/boot/compressed/misc.c b/arch/x86/boot/compressed/misc.c
12503 index 434f077..f20f3ff 100644
12504 --- a/arch/x86/boot/compressed/misc.c
12505 +++ b/arch/x86/boot/compressed/misc.c
12506 @@ -224,7 +224,7 @@ void __putstr(const char *s)
12507
12508 void *memset(void *s, int c, size_t n)
12509 {
12510 - int i;
12511 + size_t i;
12512 char *ss = s;
12513
12514 for (i = 0; i < n; i++)
12515 @@ -283,7 +283,7 @@ static void handle_relocations(void *output, unsigned long output_len)
12516 * Calculate the delta between where vmlinux was linked to load
12517 * and where it was actually loaded.
12518 */
12519 - delta = min_addr - LOAD_PHYSICAL_ADDR;
12520 + delta = min_addr - ____LOAD_PHYSICAL_ADDR;
12521 if (!delta) {
12522 debug_putstr("No relocation needed... ");
12523 return;
12524 @@ -353,7 +353,7 @@ static void parse_elf(void *output)
12525 Elf32_Ehdr ehdr;
12526 Elf32_Phdr *phdrs, *phdr;
12527 #endif
12528 - void *dest;
12529 + void *dest, *prev;
12530 int i;
12531
12532 memcpy(&ehdr, output, sizeof(ehdr));
12533 @@ -380,13 +380,16 @@ static void parse_elf(void *output)
12534 case PT_LOAD:
12535 #ifdef CONFIG_RELOCATABLE
12536 dest = output;
12537 - dest += (phdr->p_paddr - LOAD_PHYSICAL_ADDR);
12538 + dest += (phdr->p_paddr - ____LOAD_PHYSICAL_ADDR);
12539 #else
12540 dest = (void *)(phdr->p_paddr);
12541 #endif
12542 memcpy(dest,
12543 output + phdr->p_offset,
12544 phdr->p_filesz);
12545 + if (i)
12546 + memset(prev, 0xff, dest - prev);
12547 + prev = dest + phdr->p_filesz;
12548 break;
12549 default: /* Ignore other PT_* */ break;
12550 }
12551 @@ -432,7 +435,7 @@ asmlinkage void decompress_kernel(void *rmode, memptr heap,
12552 error("Destination address too large");
12553 #endif
12554 #ifndef CONFIG_RELOCATABLE
12555 - if ((unsigned long)output != LOAD_PHYSICAL_ADDR)
12556 + if ((unsigned long)output != ____LOAD_PHYSICAL_ADDR)
12557 error("Wrong destination address");
12558 #endif
12559
12560 diff --git a/arch/x86/boot/cpucheck.c b/arch/x86/boot/cpucheck.c
12561 index 4d3ff03..e4972ff 100644
12562 --- a/arch/x86/boot/cpucheck.c
12563 +++ b/arch/x86/boot/cpucheck.c
12564 @@ -74,7 +74,7 @@ static int has_fpu(void)
12565 u16 fcw = -1, fsw = -1;
12566 u32 cr0;
12567
12568 - asm("movl %%cr0,%0" : "=r" (cr0));
12569 + asm volatile("movl %%cr0,%0" : "=r" (cr0));
12570 if (cr0 & (X86_CR0_EM|X86_CR0_TS)) {
12571 cr0 &= ~(X86_CR0_EM|X86_CR0_TS);
12572 asm volatile("movl %0,%%cr0" : : "r" (cr0));
12573 @@ -90,7 +90,7 @@ static int has_eflag(u32 mask)
12574 {
12575 u32 f0, f1;
12576
12577 - asm("pushfl ; "
12578 + asm volatile("pushfl ; "
12579 "pushfl ; "
12580 "popl %0 ; "
12581 "movl %0,%1 ; "
12582 @@ -115,7 +115,7 @@ static void get_flags(void)
12583 set_bit(X86_FEATURE_FPU, cpu.flags);
12584
12585 if (has_eflag(X86_EFLAGS_ID)) {
12586 - asm("cpuid"
12587 + asm volatile("cpuid"
12588 : "=a" (max_intel_level),
12589 "=b" (cpu_vendor[0]),
12590 "=d" (cpu_vendor[1]),
12591 @@ -124,7 +124,7 @@ static void get_flags(void)
12592
12593 if (max_intel_level >= 0x00000001 &&
12594 max_intel_level <= 0x0000ffff) {
12595 - asm("cpuid"
12596 + asm volatile("cpuid"
12597 : "=a" (tfms),
12598 "=c" (cpu.flags[4]),
12599 "=d" (cpu.flags[0])
12600 @@ -136,7 +136,7 @@ static void get_flags(void)
12601 cpu.model += ((tfms >> 16) & 0xf) << 4;
12602 }
12603
12604 - asm("cpuid"
12605 + asm volatile("cpuid"
12606 : "=a" (max_amd_level)
12607 : "a" (0x80000000)
12608 : "ebx", "ecx", "edx");
12609 @@ -144,7 +144,7 @@ static void get_flags(void)
12610 if (max_amd_level >= 0x80000001 &&
12611 max_amd_level <= 0x8000ffff) {
12612 u32 eax = 0x80000001;
12613 - asm("cpuid"
12614 + asm volatile("cpuid"
12615 : "+a" (eax),
12616 "=c" (cpu.flags[6]),
12617 "=d" (cpu.flags[1])
12618 @@ -203,9 +203,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
12619 u32 ecx = MSR_K7_HWCR;
12620 u32 eax, edx;
12621
12622 - asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
12623 + asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
12624 eax &= ~(1 << 15);
12625 - asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
12626 + asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
12627
12628 get_flags(); /* Make sure it really did something */
12629 err = check_flags();
12630 @@ -218,9 +218,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
12631 u32 ecx = MSR_VIA_FCR;
12632 u32 eax, edx;
12633
12634 - asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
12635 + asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
12636 eax |= (1<<1)|(1<<7);
12637 - asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
12638 + asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
12639
12640 set_bit(X86_FEATURE_CX8, cpu.flags);
12641 err = check_flags();
12642 @@ -231,12 +231,12 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
12643 u32 eax, edx;
12644 u32 level = 1;
12645
12646 - asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
12647 - asm("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
12648 - asm("cpuid"
12649 + asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
12650 + asm volatile("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
12651 + asm volatile("cpuid"
12652 : "+a" (level), "=d" (cpu.flags[0])
12653 : : "ecx", "ebx");
12654 - asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
12655 + asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
12656
12657 err = check_flags();
12658 }
12659 diff --git a/arch/x86/boot/header.S b/arch/x86/boot/header.S
12660 index 9ec06a1..2c25e79 100644
12661 --- a/arch/x86/boot/header.S
12662 +++ b/arch/x86/boot/header.S
12663 @@ -409,10 +409,14 @@ setup_data: .quad 0 # 64-bit physical pointer to
12664 # single linked list of
12665 # struct setup_data
12666
12667 -pref_address: .quad LOAD_PHYSICAL_ADDR # preferred load addr
12668 +pref_address: .quad ____LOAD_PHYSICAL_ADDR # preferred load addr
12669
12670 #define ZO_INIT_SIZE (ZO__end - ZO_startup_32 + ZO_z_extract_offset)
12671 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
12672 +#define VO_INIT_SIZE (VO__end - VO__text - __PAGE_OFFSET - ____LOAD_PHYSICAL_ADDR)
12673 +#else
12674 #define VO_INIT_SIZE (VO__end - VO__text)
12675 +#endif
12676 #if ZO_INIT_SIZE > VO_INIT_SIZE
12677 #define INIT_SIZE ZO_INIT_SIZE
12678 #else
12679 diff --git a/arch/x86/boot/memory.c b/arch/x86/boot/memory.c
12680 index db75d07..8e6d0af 100644
12681 --- a/arch/x86/boot/memory.c
12682 +++ b/arch/x86/boot/memory.c
12683 @@ -19,7 +19,7 @@
12684
12685 static int detect_memory_e820(void)
12686 {
12687 - int count = 0;
12688 + unsigned int count = 0;
12689 struct biosregs ireg, oreg;
12690 struct e820entry *desc = boot_params.e820_map;
12691 static struct e820entry buf; /* static so it is zeroed */
12692 diff --git a/arch/x86/boot/video-vesa.c b/arch/x86/boot/video-vesa.c
12693 index 11e8c6e..fdbb1ed 100644
12694 --- a/arch/x86/boot/video-vesa.c
12695 +++ b/arch/x86/boot/video-vesa.c
12696 @@ -200,6 +200,7 @@ static void vesa_store_pm_info(void)
12697
12698 boot_params.screen_info.vesapm_seg = oreg.es;
12699 boot_params.screen_info.vesapm_off = oreg.di;
12700 + boot_params.screen_info.vesapm_size = oreg.cx;
12701 }
12702
12703 /*
12704 diff --git a/arch/x86/boot/video.c b/arch/x86/boot/video.c
12705 index 43eda28..5ab5fdb 100644
12706 --- a/arch/x86/boot/video.c
12707 +++ b/arch/x86/boot/video.c
12708 @@ -96,7 +96,7 @@ static void store_mode_params(void)
12709 static unsigned int get_entry(void)
12710 {
12711 char entry_buf[4];
12712 - int i, len = 0;
12713 + unsigned int i, len = 0;
12714 int key;
12715 unsigned int v;
12716
12717 diff --git a/arch/x86/crypto/aes-x86_64-asm_64.S b/arch/x86/crypto/aes-x86_64-asm_64.S
12718 index 9105655..41779c1 100644
12719 --- a/arch/x86/crypto/aes-x86_64-asm_64.S
12720 +++ b/arch/x86/crypto/aes-x86_64-asm_64.S
12721 @@ -8,6 +8,8 @@
12722 * including this sentence is retained in full.
12723 */
12724
12725 +#include <asm/alternative-asm.h>
12726 +
12727 .extern crypto_ft_tab
12728 .extern crypto_it_tab
12729 .extern crypto_fl_tab
12730 @@ -70,6 +72,8 @@
12731 je B192; \
12732 leaq 32(r9),r9;
12733
12734 +#define ret pax_force_retaddr; ret
12735 +
12736 #define epilogue(FUNC,r1,r2,r3,r4,r5,r6,r7,r8,r9) \
12737 movq r1,r2; \
12738 movq r3,r4; \
12739 diff --git a/arch/x86/crypto/aesni-intel_asm.S b/arch/x86/crypto/aesni-intel_asm.S
12740 index 477e9d7..c92c7d8 100644
12741 --- a/arch/x86/crypto/aesni-intel_asm.S
12742 +++ b/arch/x86/crypto/aesni-intel_asm.S
12743 @@ -31,6 +31,7 @@
12744
12745 #include <linux/linkage.h>
12746 #include <asm/inst.h>
12747 +#include <asm/alternative-asm.h>
12748
12749 #ifdef __x86_64__
12750 .data
12751 @@ -205,7 +206,7 @@ enc: .octa 0x2
12752 * num_initial_blocks = b mod 4
12753 * encrypt the initial num_initial_blocks blocks and apply ghash on
12754 * the ciphertext
12755 -* %r10, %r11, %r12, %rax, %xmm5, %xmm6, %xmm7, %xmm8, %xmm9 registers
12756 +* %r10, %r11, %r15, %rax, %xmm5, %xmm6, %xmm7, %xmm8, %xmm9 registers
12757 * are clobbered
12758 * arg1, %arg2, %arg3, %r14 are used as a pointer only, not modified
12759 */
12760 @@ -214,8 +215,8 @@ enc: .octa 0x2
12761 .macro INITIAL_BLOCKS_DEC num_initial_blocks TMP1 TMP2 TMP3 TMP4 TMP5 XMM0 XMM1 \
12762 XMM2 XMM3 XMM4 XMMDst TMP6 TMP7 i i_seq operation
12763 mov arg7, %r10 # %r10 = AAD
12764 - mov arg8, %r12 # %r12 = aadLen
12765 - mov %r12, %r11
12766 + mov arg8, %r15 # %r15 = aadLen
12767 + mov %r15, %r11
12768 pxor %xmm\i, %xmm\i
12769 _get_AAD_loop\num_initial_blocks\operation:
12770 movd (%r10), \TMP1
12771 @@ -223,15 +224,15 @@ _get_AAD_loop\num_initial_blocks\operation:
12772 psrldq $4, %xmm\i
12773 pxor \TMP1, %xmm\i
12774 add $4, %r10
12775 - sub $4, %r12
12776 + sub $4, %r15
12777 jne _get_AAD_loop\num_initial_blocks\operation
12778 cmp $16, %r11
12779 je _get_AAD_loop2_done\num_initial_blocks\operation
12780 - mov $16, %r12
12781 + mov $16, %r15
12782 _get_AAD_loop2\num_initial_blocks\operation:
12783 psrldq $4, %xmm\i
12784 - sub $4, %r12
12785 - cmp %r11, %r12
12786 + sub $4, %r15
12787 + cmp %r11, %r15
12788 jne _get_AAD_loop2\num_initial_blocks\operation
12789 _get_AAD_loop2_done\num_initial_blocks\operation:
12790 movdqa SHUF_MASK(%rip), %xmm14
12791 @@ -443,7 +444,7 @@ _initial_blocks_done\num_initial_blocks\operation:
12792 * num_initial_blocks = b mod 4
12793 * encrypt the initial num_initial_blocks blocks and apply ghash on
12794 * the ciphertext
12795 -* %r10, %r11, %r12, %rax, %xmm5, %xmm6, %xmm7, %xmm8, %xmm9 registers
12796 +* %r10, %r11, %r15, %rax, %xmm5, %xmm6, %xmm7, %xmm8, %xmm9 registers
12797 * are clobbered
12798 * arg1, %arg2, %arg3, %r14 are used as a pointer only, not modified
12799 */
12800 @@ -452,8 +453,8 @@ _initial_blocks_done\num_initial_blocks\operation:
12801 .macro INITIAL_BLOCKS_ENC num_initial_blocks TMP1 TMP2 TMP3 TMP4 TMP5 XMM0 XMM1 \
12802 XMM2 XMM3 XMM4 XMMDst TMP6 TMP7 i i_seq operation
12803 mov arg7, %r10 # %r10 = AAD
12804 - mov arg8, %r12 # %r12 = aadLen
12805 - mov %r12, %r11
12806 + mov arg8, %r15 # %r15 = aadLen
12807 + mov %r15, %r11
12808 pxor %xmm\i, %xmm\i
12809 _get_AAD_loop\num_initial_blocks\operation:
12810 movd (%r10), \TMP1
12811 @@ -461,15 +462,15 @@ _get_AAD_loop\num_initial_blocks\operation:
12812 psrldq $4, %xmm\i
12813 pxor \TMP1, %xmm\i
12814 add $4, %r10
12815 - sub $4, %r12
12816 + sub $4, %r15
12817 jne _get_AAD_loop\num_initial_blocks\operation
12818 cmp $16, %r11
12819 je _get_AAD_loop2_done\num_initial_blocks\operation
12820 - mov $16, %r12
12821 + mov $16, %r15
12822 _get_AAD_loop2\num_initial_blocks\operation:
12823 psrldq $4, %xmm\i
12824 - sub $4, %r12
12825 - cmp %r11, %r12
12826 + sub $4, %r15
12827 + cmp %r11, %r15
12828 jne _get_AAD_loop2\num_initial_blocks\operation
12829 _get_AAD_loop2_done\num_initial_blocks\operation:
12830 movdqa SHUF_MASK(%rip), %xmm14
12831 @@ -1269,7 +1270,7 @@ TMP7 XMM1 XMM2 XMM3 XMM4 XMMDst
12832 *
12833 *****************************************************************************/
12834 ENTRY(aesni_gcm_dec)
12835 - push %r12
12836 + push %r15
12837 push %r13
12838 push %r14
12839 mov %rsp, %r14
12840 @@ -1279,8 +1280,8 @@ ENTRY(aesni_gcm_dec)
12841 */
12842 sub $VARIABLE_OFFSET, %rsp
12843 and $~63, %rsp # align rsp to 64 bytes
12844 - mov %arg6, %r12
12845 - movdqu (%r12), %xmm13 # %xmm13 = HashKey
12846 + mov %arg6, %r15
12847 + movdqu (%r15), %xmm13 # %xmm13 = HashKey
12848 movdqa SHUF_MASK(%rip), %xmm2
12849 PSHUFB_XMM %xmm2, %xmm13
12850
12851 @@ -1308,10 +1309,10 @@ ENTRY(aesni_gcm_dec)
12852 movdqa %xmm13, HashKey(%rsp) # store HashKey<<1 (mod poly)
12853 mov %arg4, %r13 # save the number of bytes of plaintext/ciphertext
12854 and $-16, %r13 # %r13 = %r13 - (%r13 mod 16)
12855 - mov %r13, %r12
12856 - and $(3<<4), %r12
12857 + mov %r13, %r15
12858 + and $(3<<4), %r15
12859 jz _initial_num_blocks_is_0_decrypt
12860 - cmp $(2<<4), %r12
12861 + cmp $(2<<4), %r15
12862 jb _initial_num_blocks_is_1_decrypt
12863 je _initial_num_blocks_is_2_decrypt
12864 _initial_num_blocks_is_3_decrypt:
12865 @@ -1361,16 +1362,16 @@ _zero_cipher_left_decrypt:
12866 sub $16, %r11
12867 add %r13, %r11
12868 movdqu (%arg3,%r11,1), %xmm1 # receive the last <16 byte block
12869 - lea SHIFT_MASK+16(%rip), %r12
12870 - sub %r13, %r12
12871 + lea SHIFT_MASK+16(%rip), %r15
12872 + sub %r13, %r15
12873 # adjust the shuffle mask pointer to be able to shift 16-%r13 bytes
12874 # (%r13 is the number of bytes in plaintext mod 16)
12875 - movdqu (%r12), %xmm2 # get the appropriate shuffle mask
12876 + movdqu (%r15), %xmm2 # get the appropriate shuffle mask
12877 PSHUFB_XMM %xmm2, %xmm1 # right shift 16-%r13 butes
12878
12879 movdqa %xmm1, %xmm2
12880 pxor %xmm1, %xmm0 # Ciphertext XOR E(K, Yn)
12881 - movdqu ALL_F-SHIFT_MASK(%r12), %xmm1
12882 + movdqu ALL_F-SHIFT_MASK(%r15), %xmm1
12883 # get the appropriate mask to mask out top 16-%r13 bytes of %xmm0
12884 pand %xmm1, %xmm0 # mask out top 16-%r13 bytes of %xmm0
12885 pand %xmm1, %xmm2
12886 @@ -1399,9 +1400,9 @@ _less_than_8_bytes_left_decrypt:
12887 sub $1, %r13
12888 jne _less_than_8_bytes_left_decrypt
12889 _multiple_of_16_bytes_decrypt:
12890 - mov arg8, %r12 # %r13 = aadLen (number of bytes)
12891 - shl $3, %r12 # convert into number of bits
12892 - movd %r12d, %xmm15 # len(A) in %xmm15
12893 + mov arg8, %r15 # %r13 = aadLen (number of bytes)
12894 + shl $3, %r15 # convert into number of bits
12895 + movd %r15d, %xmm15 # len(A) in %xmm15
12896 shl $3, %arg4 # len(C) in bits (*128)
12897 MOVQ_R64_XMM %arg4, %xmm1
12898 pslldq $8, %xmm15 # %xmm15 = len(A)||0x0000000000000000
12899 @@ -1440,7 +1441,8 @@ _return_T_done_decrypt:
12900 mov %r14, %rsp
12901 pop %r14
12902 pop %r13
12903 - pop %r12
12904 + pop %r15
12905 + pax_force_retaddr
12906 ret
12907 ENDPROC(aesni_gcm_dec)
12908
12909 @@ -1529,7 +1531,7 @@ ENDPROC(aesni_gcm_dec)
12910 * poly = x^128 + x^127 + x^126 + x^121 + 1
12911 ***************************************************************************/
12912 ENTRY(aesni_gcm_enc)
12913 - push %r12
12914 + push %r15
12915 push %r13
12916 push %r14
12917 mov %rsp, %r14
12918 @@ -1539,8 +1541,8 @@ ENTRY(aesni_gcm_enc)
12919 #
12920 sub $VARIABLE_OFFSET, %rsp
12921 and $~63, %rsp
12922 - mov %arg6, %r12
12923 - movdqu (%r12), %xmm13
12924 + mov %arg6, %r15
12925 + movdqu (%r15), %xmm13
12926 movdqa SHUF_MASK(%rip), %xmm2
12927 PSHUFB_XMM %xmm2, %xmm13
12928
12929 @@ -1564,13 +1566,13 @@ ENTRY(aesni_gcm_enc)
12930 movdqa %xmm13, HashKey(%rsp)
12931 mov %arg4, %r13 # %xmm13 holds HashKey<<1 (mod poly)
12932 and $-16, %r13
12933 - mov %r13, %r12
12934 + mov %r13, %r15
12935
12936 # Encrypt first few blocks
12937
12938 - and $(3<<4), %r12
12939 + and $(3<<4), %r15
12940 jz _initial_num_blocks_is_0_encrypt
12941 - cmp $(2<<4), %r12
12942 + cmp $(2<<4), %r15
12943 jb _initial_num_blocks_is_1_encrypt
12944 je _initial_num_blocks_is_2_encrypt
12945 _initial_num_blocks_is_3_encrypt:
12946 @@ -1623,14 +1625,14 @@ _zero_cipher_left_encrypt:
12947 sub $16, %r11
12948 add %r13, %r11
12949 movdqu (%arg3,%r11,1), %xmm1 # receive the last <16 byte blocks
12950 - lea SHIFT_MASK+16(%rip), %r12
12951 - sub %r13, %r12
12952 + lea SHIFT_MASK+16(%rip), %r15
12953 + sub %r13, %r15
12954 # adjust the shuffle mask pointer to be able to shift 16-r13 bytes
12955 # (%r13 is the number of bytes in plaintext mod 16)
12956 - movdqu (%r12), %xmm2 # get the appropriate shuffle mask
12957 + movdqu (%r15), %xmm2 # get the appropriate shuffle mask
12958 PSHUFB_XMM %xmm2, %xmm1 # shift right 16-r13 byte
12959 pxor %xmm1, %xmm0 # Plaintext XOR Encrypt(K, Yn)
12960 - movdqu ALL_F-SHIFT_MASK(%r12), %xmm1
12961 + movdqu ALL_F-SHIFT_MASK(%r15), %xmm1
12962 # get the appropriate mask to mask out top 16-r13 bytes of xmm0
12963 pand %xmm1, %xmm0 # mask out top 16-r13 bytes of xmm0
12964 movdqa SHUF_MASK(%rip), %xmm10
12965 @@ -1663,9 +1665,9 @@ _less_than_8_bytes_left_encrypt:
12966 sub $1, %r13
12967 jne _less_than_8_bytes_left_encrypt
12968 _multiple_of_16_bytes_encrypt:
12969 - mov arg8, %r12 # %r12 = addLen (number of bytes)
12970 - shl $3, %r12
12971 - movd %r12d, %xmm15 # len(A) in %xmm15
12972 + mov arg8, %r15 # %r15 = addLen (number of bytes)
12973 + shl $3, %r15
12974 + movd %r15d, %xmm15 # len(A) in %xmm15
12975 shl $3, %arg4 # len(C) in bits (*128)
12976 MOVQ_R64_XMM %arg4, %xmm1
12977 pslldq $8, %xmm15 # %xmm15 = len(A)||0x0000000000000000
12978 @@ -1704,7 +1706,8 @@ _return_T_done_encrypt:
12979 mov %r14, %rsp
12980 pop %r14
12981 pop %r13
12982 - pop %r12
12983 + pop %r15
12984 + pax_force_retaddr
12985 ret
12986 ENDPROC(aesni_gcm_enc)
12987
12988 @@ -1722,6 +1725,7 @@ _key_expansion_256a:
12989 pxor %xmm1, %xmm0
12990 movaps %xmm0, (TKEYP)
12991 add $0x10, TKEYP
12992 + pax_force_retaddr
12993 ret
12994 ENDPROC(_key_expansion_128)
12995 ENDPROC(_key_expansion_256a)
12996 @@ -1748,6 +1752,7 @@ _key_expansion_192a:
12997 shufps $0b01001110, %xmm2, %xmm1
12998 movaps %xmm1, 0x10(TKEYP)
12999 add $0x20, TKEYP
13000 + pax_force_retaddr
13001 ret
13002 ENDPROC(_key_expansion_192a)
13003
13004 @@ -1768,6 +1773,7 @@ _key_expansion_192b:
13005
13006 movaps %xmm0, (TKEYP)
13007 add $0x10, TKEYP
13008 + pax_force_retaddr
13009 ret
13010 ENDPROC(_key_expansion_192b)
13011
13012 @@ -1781,6 +1787,7 @@ _key_expansion_256b:
13013 pxor %xmm1, %xmm2
13014 movaps %xmm2, (TKEYP)
13015 add $0x10, TKEYP
13016 + pax_force_retaddr
13017 ret
13018 ENDPROC(_key_expansion_256b)
13019
13020 @@ -1894,6 +1901,7 @@ ENTRY(aesni_set_key)
13021 #ifndef __x86_64__
13022 popl KEYP
13023 #endif
13024 + pax_force_retaddr
13025 ret
13026 ENDPROC(aesni_set_key)
13027
13028 @@ -1916,6 +1924,7 @@ ENTRY(aesni_enc)
13029 popl KLEN
13030 popl KEYP
13031 #endif
13032 + pax_force_retaddr
13033 ret
13034 ENDPROC(aesni_enc)
13035
13036 @@ -1974,6 +1983,7 @@ _aesni_enc1:
13037 AESENC KEY STATE
13038 movaps 0x70(TKEYP), KEY
13039 AESENCLAST KEY STATE
13040 + pax_force_retaddr
13041 ret
13042 ENDPROC(_aesni_enc1)
13043
13044 @@ -2083,6 +2093,7 @@ _aesni_enc4:
13045 AESENCLAST KEY STATE2
13046 AESENCLAST KEY STATE3
13047 AESENCLAST KEY STATE4
13048 + pax_force_retaddr
13049 ret
13050 ENDPROC(_aesni_enc4)
13051
13052 @@ -2106,6 +2117,7 @@ ENTRY(aesni_dec)
13053 popl KLEN
13054 popl KEYP
13055 #endif
13056 + pax_force_retaddr
13057 ret
13058 ENDPROC(aesni_dec)
13059
13060 @@ -2164,6 +2176,7 @@ _aesni_dec1:
13061 AESDEC KEY STATE
13062 movaps 0x70(TKEYP), KEY
13063 AESDECLAST KEY STATE
13064 + pax_force_retaddr
13065 ret
13066 ENDPROC(_aesni_dec1)
13067
13068 @@ -2273,6 +2286,7 @@ _aesni_dec4:
13069 AESDECLAST KEY STATE2
13070 AESDECLAST KEY STATE3
13071 AESDECLAST KEY STATE4
13072 + pax_force_retaddr
13073 ret
13074 ENDPROC(_aesni_dec4)
13075
13076 @@ -2331,6 +2345,7 @@ ENTRY(aesni_ecb_enc)
13077 popl KEYP
13078 popl LEN
13079 #endif
13080 + pax_force_retaddr
13081 ret
13082 ENDPROC(aesni_ecb_enc)
13083
13084 @@ -2390,6 +2405,7 @@ ENTRY(aesni_ecb_dec)
13085 popl KEYP
13086 popl LEN
13087 #endif
13088 + pax_force_retaddr
13089 ret
13090 ENDPROC(aesni_ecb_dec)
13091
13092 @@ -2432,6 +2448,7 @@ ENTRY(aesni_cbc_enc)
13093 popl LEN
13094 popl IVP
13095 #endif
13096 + pax_force_retaddr
13097 ret
13098 ENDPROC(aesni_cbc_enc)
13099
13100 @@ -2523,6 +2540,7 @@ ENTRY(aesni_cbc_dec)
13101 popl LEN
13102 popl IVP
13103 #endif
13104 + pax_force_retaddr
13105 ret
13106 ENDPROC(aesni_cbc_dec)
13107
13108 @@ -2550,6 +2568,7 @@ _aesni_inc_init:
13109 mov $1, TCTR_LOW
13110 MOVQ_R64_XMM TCTR_LOW INC
13111 MOVQ_R64_XMM CTR TCTR_LOW
13112 + pax_force_retaddr
13113 ret
13114 ENDPROC(_aesni_inc_init)
13115
13116 @@ -2579,6 +2598,7 @@ _aesni_inc:
13117 .Linc_low:
13118 movaps CTR, IV
13119 PSHUFB_XMM BSWAP_MASK IV
13120 + pax_force_retaddr
13121 ret
13122 ENDPROC(_aesni_inc)
13123
13124 @@ -2640,6 +2660,7 @@ ENTRY(aesni_ctr_enc)
13125 .Lctr_enc_ret:
13126 movups IV, (IVP)
13127 .Lctr_enc_just_ret:
13128 + pax_force_retaddr
13129 ret
13130 ENDPROC(aesni_ctr_enc)
13131
13132 @@ -2766,6 +2787,7 @@ ENTRY(aesni_xts_crypt8)
13133 pxor INC, STATE4
13134 movdqu STATE4, 0x70(OUTP)
13135
13136 + pax_force_retaddr
13137 ret
13138 ENDPROC(aesni_xts_crypt8)
13139
13140 diff --git a/arch/x86/crypto/blowfish-x86_64-asm_64.S b/arch/x86/crypto/blowfish-x86_64-asm_64.S
13141 index 246c670..466e2d6 100644
13142 --- a/arch/x86/crypto/blowfish-x86_64-asm_64.S
13143 +++ b/arch/x86/crypto/blowfish-x86_64-asm_64.S
13144 @@ -21,6 +21,7 @@
13145 */
13146
13147 #include <linux/linkage.h>
13148 +#include <asm/alternative-asm.h>
13149
13150 .file "blowfish-x86_64-asm.S"
13151 .text
13152 @@ -149,9 +150,11 @@ ENTRY(__blowfish_enc_blk)
13153 jnz .L__enc_xor;
13154
13155 write_block();
13156 + pax_force_retaddr
13157 ret;
13158 .L__enc_xor:
13159 xor_block();
13160 + pax_force_retaddr
13161 ret;
13162 ENDPROC(__blowfish_enc_blk)
13163
13164 @@ -183,6 +186,7 @@ ENTRY(blowfish_dec_blk)
13165
13166 movq %r11, %rbp;
13167
13168 + pax_force_retaddr
13169 ret;
13170 ENDPROC(blowfish_dec_blk)
13171
13172 @@ -334,6 +338,7 @@ ENTRY(__blowfish_enc_blk_4way)
13173
13174 popq %rbx;
13175 popq %rbp;
13176 + pax_force_retaddr
13177 ret;
13178
13179 .L__enc_xor4:
13180 @@ -341,6 +346,7 @@ ENTRY(__blowfish_enc_blk_4way)
13181
13182 popq %rbx;
13183 popq %rbp;
13184 + pax_force_retaddr
13185 ret;
13186 ENDPROC(__blowfish_enc_blk_4way)
13187
13188 @@ -375,5 +381,6 @@ ENTRY(blowfish_dec_blk_4way)
13189 popq %rbx;
13190 popq %rbp;
13191
13192 + pax_force_retaddr
13193 ret;
13194 ENDPROC(blowfish_dec_blk_4way)
13195 diff --git a/arch/x86/crypto/camellia-aesni-avx-asm_64.S b/arch/x86/crypto/camellia-aesni-avx-asm_64.S
13196 index ce71f92..1dce7ec 100644
13197 --- a/arch/x86/crypto/camellia-aesni-avx-asm_64.S
13198 +++ b/arch/x86/crypto/camellia-aesni-avx-asm_64.S
13199 @@ -16,6 +16,7 @@
13200 */
13201
13202 #include <linux/linkage.h>
13203 +#include <asm/alternative-asm.h>
13204
13205 #define CAMELLIA_TABLE_BYTE_LEN 272
13206
13207 @@ -191,6 +192,7 @@ roundsm16_x0_x1_x2_x3_x4_x5_x6_x7_y0_y1_y2_y3_y4_y5_y6_y7_cd:
13208 roundsm16(%xmm0, %xmm1, %xmm2, %xmm3, %xmm4, %xmm5, %xmm6, %xmm7,
13209 %xmm8, %xmm9, %xmm10, %xmm11, %xmm12, %xmm13, %xmm14, %xmm15,
13210 %rcx, (%r9));
13211 + pax_force_retaddr
13212 ret;
13213 ENDPROC(roundsm16_x0_x1_x2_x3_x4_x5_x6_x7_y0_y1_y2_y3_y4_y5_y6_y7_cd)
13214
13215 @@ -199,6 +201,7 @@ roundsm16_x4_x5_x6_x7_x0_x1_x2_x3_y4_y5_y6_y7_y0_y1_y2_y3_ab:
13216 roundsm16(%xmm4, %xmm5, %xmm6, %xmm7, %xmm0, %xmm1, %xmm2, %xmm3,
13217 %xmm12, %xmm13, %xmm14, %xmm15, %xmm8, %xmm9, %xmm10, %xmm11,
13218 %rax, (%r9));
13219 + pax_force_retaddr
13220 ret;
13221 ENDPROC(roundsm16_x4_x5_x6_x7_x0_x1_x2_x3_y4_y5_y6_y7_y0_y1_y2_y3_ab)
13222
13223 @@ -780,6 +783,7 @@ __camellia_enc_blk16:
13224 %xmm8, %xmm9, %xmm10, %xmm11, %xmm12, %xmm13, %xmm14,
13225 %xmm15, (key_table)(CTX, %r8, 8), (%rax), 1 * 16(%rax));
13226
13227 + pax_force_retaddr
13228 ret;
13229
13230 .align 8
13231 @@ -865,6 +869,7 @@ __camellia_dec_blk16:
13232 %xmm8, %xmm9, %xmm10, %xmm11, %xmm12, %xmm13, %xmm14,
13233 %xmm15, (key_table)(CTX), (%rax), 1 * 16(%rax));
13234
13235 + pax_force_retaddr
13236 ret;
13237
13238 .align 8
13239 @@ -904,6 +909,7 @@ ENTRY(camellia_ecb_enc_16way)
13240 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
13241 %xmm8, %rsi);
13242
13243 + pax_force_retaddr
13244 ret;
13245 ENDPROC(camellia_ecb_enc_16way)
13246
13247 @@ -932,6 +938,7 @@ ENTRY(camellia_ecb_dec_16way)
13248 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
13249 %xmm8, %rsi);
13250
13251 + pax_force_retaddr
13252 ret;
13253 ENDPROC(camellia_ecb_dec_16way)
13254
13255 @@ -981,6 +988,7 @@ ENTRY(camellia_cbc_dec_16way)
13256 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
13257 %xmm8, %rsi);
13258
13259 + pax_force_retaddr
13260 ret;
13261 ENDPROC(camellia_cbc_dec_16way)
13262
13263 @@ -1092,6 +1100,7 @@ ENTRY(camellia_ctr_16way)
13264 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
13265 %xmm8, %rsi);
13266
13267 + pax_force_retaddr
13268 ret;
13269 ENDPROC(camellia_ctr_16way)
13270
13271 @@ -1234,6 +1243,7 @@ camellia_xts_crypt_16way:
13272 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
13273 %xmm8, %rsi);
13274
13275 + pax_force_retaddr
13276 ret;
13277 ENDPROC(camellia_xts_crypt_16way)
13278
13279 diff --git a/arch/x86/crypto/camellia-aesni-avx2-asm_64.S b/arch/x86/crypto/camellia-aesni-avx2-asm_64.S
13280 index 0e0b886..5a3123c 100644
13281 --- a/arch/x86/crypto/camellia-aesni-avx2-asm_64.S
13282 +++ b/arch/x86/crypto/camellia-aesni-avx2-asm_64.S
13283 @@ -11,6 +11,7 @@
13284 */
13285
13286 #include <linux/linkage.h>
13287 +#include <asm/alternative-asm.h>
13288
13289 #define CAMELLIA_TABLE_BYTE_LEN 272
13290
13291 @@ -230,6 +231,7 @@ roundsm32_x0_x1_x2_x3_x4_x5_x6_x7_y0_y1_y2_y3_y4_y5_y6_y7_cd:
13292 roundsm32(%ymm0, %ymm1, %ymm2, %ymm3, %ymm4, %ymm5, %ymm6, %ymm7,
13293 %ymm8, %ymm9, %ymm10, %ymm11, %ymm12, %ymm13, %ymm14, %ymm15,
13294 %rcx, (%r9));
13295 + pax_force_retaddr
13296 ret;
13297 ENDPROC(roundsm32_x0_x1_x2_x3_x4_x5_x6_x7_y0_y1_y2_y3_y4_y5_y6_y7_cd)
13298
13299 @@ -238,6 +240,7 @@ roundsm32_x4_x5_x6_x7_x0_x1_x2_x3_y4_y5_y6_y7_y0_y1_y2_y3_ab:
13300 roundsm32(%ymm4, %ymm5, %ymm6, %ymm7, %ymm0, %ymm1, %ymm2, %ymm3,
13301 %ymm12, %ymm13, %ymm14, %ymm15, %ymm8, %ymm9, %ymm10, %ymm11,
13302 %rax, (%r9));
13303 + pax_force_retaddr
13304 ret;
13305 ENDPROC(roundsm32_x4_x5_x6_x7_x0_x1_x2_x3_y4_y5_y6_y7_y0_y1_y2_y3_ab)
13306
13307 @@ -820,6 +823,7 @@ __camellia_enc_blk32:
13308 %ymm8, %ymm9, %ymm10, %ymm11, %ymm12, %ymm13, %ymm14,
13309 %ymm15, (key_table)(CTX, %r8, 8), (%rax), 1 * 32(%rax));
13310
13311 + pax_force_retaddr
13312 ret;
13313
13314 .align 8
13315 @@ -905,6 +909,7 @@ __camellia_dec_blk32:
13316 %ymm8, %ymm9, %ymm10, %ymm11, %ymm12, %ymm13, %ymm14,
13317 %ymm15, (key_table)(CTX), (%rax), 1 * 32(%rax));
13318
13319 + pax_force_retaddr
13320 ret;
13321
13322 .align 8
13323 @@ -948,6 +953,7 @@ ENTRY(camellia_ecb_enc_32way)
13324
13325 vzeroupper;
13326
13327 + pax_force_retaddr
13328 ret;
13329 ENDPROC(camellia_ecb_enc_32way)
13330
13331 @@ -980,6 +986,7 @@ ENTRY(camellia_ecb_dec_32way)
13332
13333 vzeroupper;
13334
13335 + pax_force_retaddr
13336 ret;
13337 ENDPROC(camellia_ecb_dec_32way)
13338
13339 @@ -1046,6 +1053,7 @@ ENTRY(camellia_cbc_dec_32way)
13340
13341 vzeroupper;
13342
13343 + pax_force_retaddr
13344 ret;
13345 ENDPROC(camellia_cbc_dec_32way)
13346
13347 @@ -1184,6 +1192,7 @@ ENTRY(camellia_ctr_32way)
13348
13349 vzeroupper;
13350
13351 + pax_force_retaddr
13352 ret;
13353 ENDPROC(camellia_ctr_32way)
13354
13355 @@ -1349,6 +1358,7 @@ camellia_xts_crypt_32way:
13356
13357 vzeroupper;
13358
13359 + pax_force_retaddr
13360 ret;
13361 ENDPROC(camellia_xts_crypt_32way)
13362
13363 diff --git a/arch/x86/crypto/camellia-x86_64-asm_64.S b/arch/x86/crypto/camellia-x86_64-asm_64.S
13364 index 310319c..db3d7b5 100644
13365 --- a/arch/x86/crypto/camellia-x86_64-asm_64.S
13366 +++ b/arch/x86/crypto/camellia-x86_64-asm_64.S
13367 @@ -21,6 +21,7 @@
13368 */
13369
13370 #include <linux/linkage.h>
13371 +#include <asm/alternative-asm.h>
13372
13373 .file "camellia-x86_64-asm_64.S"
13374 .text
13375 @@ -228,12 +229,14 @@ ENTRY(__camellia_enc_blk)
13376 enc_outunpack(mov, RT1);
13377
13378 movq RRBP, %rbp;
13379 + pax_force_retaddr
13380 ret;
13381
13382 .L__enc_xor:
13383 enc_outunpack(xor, RT1);
13384
13385 movq RRBP, %rbp;
13386 + pax_force_retaddr
13387 ret;
13388 ENDPROC(__camellia_enc_blk)
13389
13390 @@ -272,6 +275,7 @@ ENTRY(camellia_dec_blk)
13391 dec_outunpack();
13392
13393 movq RRBP, %rbp;
13394 + pax_force_retaddr
13395 ret;
13396 ENDPROC(camellia_dec_blk)
13397
13398 @@ -463,6 +467,7 @@ ENTRY(__camellia_enc_blk_2way)
13399
13400 movq RRBP, %rbp;
13401 popq %rbx;
13402 + pax_force_retaddr
13403 ret;
13404
13405 .L__enc2_xor:
13406 @@ -470,6 +475,7 @@ ENTRY(__camellia_enc_blk_2way)
13407
13408 movq RRBP, %rbp;
13409 popq %rbx;
13410 + pax_force_retaddr
13411 ret;
13412 ENDPROC(__camellia_enc_blk_2way)
13413
13414 @@ -510,5 +516,6 @@ ENTRY(camellia_dec_blk_2way)
13415
13416 movq RRBP, %rbp;
13417 movq RXOR, %rbx;
13418 + pax_force_retaddr
13419 ret;
13420 ENDPROC(camellia_dec_blk_2way)
13421 diff --git a/arch/x86/crypto/cast5-avx-x86_64-asm_64.S b/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
13422 index c35fd5d..2d8c7db 100644
13423 --- a/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
13424 +++ b/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
13425 @@ -24,6 +24,7 @@
13426 */
13427
13428 #include <linux/linkage.h>
13429 +#include <asm/alternative-asm.h>
13430
13431 .file "cast5-avx-x86_64-asm_64.S"
13432
13433 @@ -281,6 +282,7 @@ __cast5_enc_blk16:
13434 outunpack_blocks(RR3, RL3, RTMP, RX, RKM);
13435 outunpack_blocks(RR4, RL4, RTMP, RX, RKM);
13436
13437 + pax_force_retaddr
13438 ret;
13439 ENDPROC(__cast5_enc_blk16)
13440
13441 @@ -352,6 +354,7 @@ __cast5_dec_blk16:
13442 outunpack_blocks(RR3, RL3, RTMP, RX, RKM);
13443 outunpack_blocks(RR4, RL4, RTMP, RX, RKM);
13444
13445 + pax_force_retaddr
13446 ret;
13447
13448 .L__skip_dec:
13449 @@ -388,6 +391,7 @@ ENTRY(cast5_ecb_enc_16way)
13450 vmovdqu RR4, (6*4*4)(%r11);
13451 vmovdqu RL4, (7*4*4)(%r11);
13452
13453 + pax_force_retaddr
13454 ret;
13455 ENDPROC(cast5_ecb_enc_16way)
13456
13457 @@ -420,6 +424,7 @@ ENTRY(cast5_ecb_dec_16way)
13458 vmovdqu RR4, (6*4*4)(%r11);
13459 vmovdqu RL4, (7*4*4)(%r11);
13460
13461 + pax_force_retaddr
13462 ret;
13463 ENDPROC(cast5_ecb_dec_16way)
13464
13465 @@ -430,10 +435,10 @@ ENTRY(cast5_cbc_dec_16way)
13466 * %rdx: src
13467 */
13468
13469 - pushq %r12;
13470 + pushq %r14;
13471
13472 movq %rsi, %r11;
13473 - movq %rdx, %r12;
13474 + movq %rdx, %r14;
13475
13476 vmovdqu (0*16)(%rdx), RL1;
13477 vmovdqu (1*16)(%rdx), RR1;
13478 @@ -447,16 +452,16 @@ ENTRY(cast5_cbc_dec_16way)
13479 call __cast5_dec_blk16;
13480
13481 /* xor with src */
13482 - vmovq (%r12), RX;
13483 + vmovq (%r14), RX;
13484 vpshufd $0x4f, RX, RX;
13485 vpxor RX, RR1, RR1;
13486 - vpxor 0*16+8(%r12), RL1, RL1;
13487 - vpxor 1*16+8(%r12), RR2, RR2;
13488 - vpxor 2*16+8(%r12), RL2, RL2;
13489 - vpxor 3*16+8(%r12), RR3, RR3;
13490 - vpxor 4*16+8(%r12), RL3, RL3;
13491 - vpxor 5*16+8(%r12), RR4, RR4;
13492 - vpxor 6*16+8(%r12), RL4, RL4;
13493 + vpxor 0*16+8(%r14), RL1, RL1;
13494 + vpxor 1*16+8(%r14), RR2, RR2;
13495 + vpxor 2*16+8(%r14), RL2, RL2;
13496 + vpxor 3*16+8(%r14), RR3, RR3;
13497 + vpxor 4*16+8(%r14), RL3, RL3;
13498 + vpxor 5*16+8(%r14), RR4, RR4;
13499 + vpxor 6*16+8(%r14), RL4, RL4;
13500
13501 vmovdqu RR1, (0*16)(%r11);
13502 vmovdqu RL1, (1*16)(%r11);
13503 @@ -467,8 +472,9 @@ ENTRY(cast5_cbc_dec_16way)
13504 vmovdqu RR4, (6*16)(%r11);
13505 vmovdqu RL4, (7*16)(%r11);
13506
13507 - popq %r12;
13508 + popq %r14;
13509
13510 + pax_force_retaddr
13511 ret;
13512 ENDPROC(cast5_cbc_dec_16way)
13513
13514 @@ -480,10 +486,10 @@ ENTRY(cast5_ctr_16way)
13515 * %rcx: iv (big endian, 64bit)
13516 */
13517
13518 - pushq %r12;
13519 + pushq %r14;
13520
13521 movq %rsi, %r11;
13522 - movq %rdx, %r12;
13523 + movq %rdx, %r14;
13524
13525 vpcmpeqd RTMP, RTMP, RTMP;
13526 vpsrldq $8, RTMP, RTMP; /* low: -1, high: 0 */
13527 @@ -523,14 +529,14 @@ ENTRY(cast5_ctr_16way)
13528 call __cast5_enc_blk16;
13529
13530 /* dst = src ^ iv */
13531 - vpxor (0*16)(%r12), RR1, RR1;
13532 - vpxor (1*16)(%r12), RL1, RL1;
13533 - vpxor (2*16)(%r12), RR2, RR2;
13534 - vpxor (3*16)(%r12), RL2, RL2;
13535 - vpxor (4*16)(%r12), RR3, RR3;
13536 - vpxor (5*16)(%r12), RL3, RL3;
13537 - vpxor (6*16)(%r12), RR4, RR4;
13538 - vpxor (7*16)(%r12), RL4, RL4;
13539 + vpxor (0*16)(%r14), RR1, RR1;
13540 + vpxor (1*16)(%r14), RL1, RL1;
13541 + vpxor (2*16)(%r14), RR2, RR2;
13542 + vpxor (3*16)(%r14), RL2, RL2;
13543 + vpxor (4*16)(%r14), RR3, RR3;
13544 + vpxor (5*16)(%r14), RL3, RL3;
13545 + vpxor (6*16)(%r14), RR4, RR4;
13546 + vpxor (7*16)(%r14), RL4, RL4;
13547 vmovdqu RR1, (0*16)(%r11);
13548 vmovdqu RL1, (1*16)(%r11);
13549 vmovdqu RR2, (2*16)(%r11);
13550 @@ -540,7 +546,8 @@ ENTRY(cast5_ctr_16way)
13551 vmovdqu RR4, (6*16)(%r11);
13552 vmovdqu RL4, (7*16)(%r11);
13553
13554 - popq %r12;
13555 + popq %r14;
13556
13557 + pax_force_retaddr
13558 ret;
13559 ENDPROC(cast5_ctr_16way)
13560 diff --git a/arch/x86/crypto/cast6-avx-x86_64-asm_64.S b/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
13561 index e3531f8..e123f35 100644
13562 --- a/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
13563 +++ b/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
13564 @@ -24,6 +24,7 @@
13565 */
13566
13567 #include <linux/linkage.h>
13568 +#include <asm/alternative-asm.h>
13569 #include "glue_helper-asm-avx.S"
13570
13571 .file "cast6-avx-x86_64-asm_64.S"
13572 @@ -295,6 +296,7 @@ __cast6_enc_blk8:
13573 outunpack_blocks(RA1, RB1, RC1, RD1, RTMP, RX, RKRF, RKM);
13574 outunpack_blocks(RA2, RB2, RC2, RD2, RTMP, RX, RKRF, RKM);
13575
13576 + pax_force_retaddr
13577 ret;
13578 ENDPROC(__cast6_enc_blk8)
13579
13580 @@ -340,6 +342,7 @@ __cast6_dec_blk8:
13581 outunpack_blocks(RA1, RB1, RC1, RD1, RTMP, RX, RKRF, RKM);
13582 outunpack_blocks(RA2, RB2, RC2, RD2, RTMP, RX, RKRF, RKM);
13583
13584 + pax_force_retaddr
13585 ret;
13586 ENDPROC(__cast6_dec_blk8)
13587
13588 @@ -358,6 +361,7 @@ ENTRY(cast6_ecb_enc_8way)
13589
13590 store_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13591
13592 + pax_force_retaddr
13593 ret;
13594 ENDPROC(cast6_ecb_enc_8way)
13595
13596 @@ -376,6 +380,7 @@ ENTRY(cast6_ecb_dec_8way)
13597
13598 store_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13599
13600 + pax_force_retaddr
13601 ret;
13602 ENDPROC(cast6_ecb_dec_8way)
13603
13604 @@ -386,19 +391,20 @@ ENTRY(cast6_cbc_dec_8way)
13605 * %rdx: src
13606 */
13607
13608 - pushq %r12;
13609 + pushq %r14;
13610
13611 movq %rsi, %r11;
13612 - movq %rdx, %r12;
13613 + movq %rdx, %r14;
13614
13615 load_8way(%rdx, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13616
13617 call __cast6_dec_blk8;
13618
13619 - store_cbc_8way(%r12, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13620 + store_cbc_8way(%r14, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13621
13622 - popq %r12;
13623 + popq %r14;
13624
13625 + pax_force_retaddr
13626 ret;
13627 ENDPROC(cast6_cbc_dec_8way)
13628
13629 @@ -410,20 +416,21 @@ ENTRY(cast6_ctr_8way)
13630 * %rcx: iv (little endian, 128bit)
13631 */
13632
13633 - pushq %r12;
13634 + pushq %r14;
13635
13636 movq %rsi, %r11;
13637 - movq %rdx, %r12;
13638 + movq %rdx, %r14;
13639
13640 load_ctr_8way(%rcx, .Lbswap128_mask, RA1, RB1, RC1, RD1, RA2, RB2, RC2,
13641 RD2, RX, RKR, RKM);
13642
13643 call __cast6_enc_blk8;
13644
13645 - store_ctr_8way(%r12, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13646 + store_ctr_8way(%r14, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13647
13648 - popq %r12;
13649 + popq %r14;
13650
13651 + pax_force_retaddr
13652 ret;
13653 ENDPROC(cast6_ctr_8way)
13654
13655 @@ -446,6 +453,7 @@ ENTRY(cast6_xts_enc_8way)
13656 /* dst <= regs xor IVs(in dst) */
13657 store_xts_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13658
13659 + pax_force_retaddr
13660 ret;
13661 ENDPROC(cast6_xts_enc_8way)
13662
13663 @@ -468,5 +476,6 @@ ENTRY(cast6_xts_dec_8way)
13664 /* dst <= regs xor IVs(in dst) */
13665 store_xts_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13666
13667 + pax_force_retaddr
13668 ret;
13669 ENDPROC(cast6_xts_dec_8way)
13670 diff --git a/arch/x86/crypto/crc32c-pcl-intel-asm_64.S b/arch/x86/crypto/crc32c-pcl-intel-asm_64.S
13671 index dbc4339..de6e120 100644
13672 --- a/arch/x86/crypto/crc32c-pcl-intel-asm_64.S
13673 +++ b/arch/x86/crypto/crc32c-pcl-intel-asm_64.S
13674 @@ -45,6 +45,7 @@
13675
13676 #include <asm/inst.h>
13677 #include <linux/linkage.h>
13678 +#include <asm/alternative-asm.h>
13679
13680 ## ISCSI CRC 32 Implementation with crc32 and pclmulqdq Instruction
13681
13682 @@ -312,6 +313,7 @@ do_return:
13683 popq %rsi
13684 popq %rdi
13685 popq %rbx
13686 + pax_force_retaddr
13687 ret
13688
13689 ################################################################
13690 diff --git a/arch/x86/crypto/ghash-clmulni-intel_asm.S b/arch/x86/crypto/ghash-clmulni-intel_asm.S
13691 index 185fad4..ff4cd36 100644
13692 --- a/arch/x86/crypto/ghash-clmulni-intel_asm.S
13693 +++ b/arch/x86/crypto/ghash-clmulni-intel_asm.S
13694 @@ -18,6 +18,7 @@
13695
13696 #include <linux/linkage.h>
13697 #include <asm/inst.h>
13698 +#include <asm/alternative-asm.h>
13699
13700 .data
13701
13702 @@ -89,6 +90,7 @@ __clmul_gf128mul_ble:
13703 psrlq $1, T2
13704 pxor T2, T1
13705 pxor T1, DATA
13706 + pax_force_retaddr
13707 ret
13708 ENDPROC(__clmul_gf128mul_ble)
13709
13710 @@ -101,6 +103,7 @@ ENTRY(clmul_ghash_mul)
13711 call __clmul_gf128mul_ble
13712 PSHUFB_XMM BSWAP DATA
13713 movups DATA, (%rdi)
13714 + pax_force_retaddr
13715 ret
13716 ENDPROC(clmul_ghash_mul)
13717
13718 @@ -128,5 +131,6 @@ ENTRY(clmul_ghash_update)
13719 PSHUFB_XMM BSWAP DATA
13720 movups DATA, (%rdi)
13721 .Lupdate_just_ret:
13722 + pax_force_retaddr
13723 ret
13724 ENDPROC(clmul_ghash_update)
13725 diff --git a/arch/x86/crypto/salsa20-x86_64-asm_64.S b/arch/x86/crypto/salsa20-x86_64-asm_64.S
13726 index 9279e0b..c4b3d2c 100644
13727 --- a/arch/x86/crypto/salsa20-x86_64-asm_64.S
13728 +++ b/arch/x86/crypto/salsa20-x86_64-asm_64.S
13729 @@ -1,4 +1,5 @@
13730 #include <linux/linkage.h>
13731 +#include <asm/alternative-asm.h>
13732
13733 # enter salsa20_encrypt_bytes
13734 ENTRY(salsa20_encrypt_bytes)
13735 @@ -789,6 +790,7 @@ ENTRY(salsa20_encrypt_bytes)
13736 add %r11,%rsp
13737 mov %rdi,%rax
13738 mov %rsi,%rdx
13739 + pax_force_retaddr
13740 ret
13741 # bytesatleast65:
13742 ._bytesatleast65:
13743 @@ -889,6 +891,7 @@ ENTRY(salsa20_keysetup)
13744 add %r11,%rsp
13745 mov %rdi,%rax
13746 mov %rsi,%rdx
13747 + pax_force_retaddr
13748 ret
13749 ENDPROC(salsa20_keysetup)
13750
13751 @@ -914,5 +917,6 @@ ENTRY(salsa20_ivsetup)
13752 add %r11,%rsp
13753 mov %rdi,%rax
13754 mov %rsi,%rdx
13755 + pax_force_retaddr
13756 ret
13757 ENDPROC(salsa20_ivsetup)
13758 diff --git a/arch/x86/crypto/serpent-avx-x86_64-asm_64.S b/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
13759 index 2f202f4..d9164d6 100644
13760 --- a/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
13761 +++ b/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
13762 @@ -24,6 +24,7 @@
13763 */
13764
13765 #include <linux/linkage.h>
13766 +#include <asm/alternative-asm.h>
13767 #include "glue_helper-asm-avx.S"
13768
13769 .file "serpent-avx-x86_64-asm_64.S"
13770 @@ -618,6 +619,7 @@ __serpent_enc_blk8_avx:
13771 write_blocks(RA1, RB1, RC1, RD1, RK0, RK1, RK2);
13772 write_blocks(RA2, RB2, RC2, RD2, RK0, RK1, RK2);
13773
13774 + pax_force_retaddr
13775 ret;
13776 ENDPROC(__serpent_enc_blk8_avx)
13777
13778 @@ -672,6 +674,7 @@ __serpent_dec_blk8_avx:
13779 write_blocks(RC1, RD1, RB1, RE1, RK0, RK1, RK2);
13780 write_blocks(RC2, RD2, RB2, RE2, RK0, RK1, RK2);
13781
13782 + pax_force_retaddr
13783 ret;
13784 ENDPROC(__serpent_dec_blk8_avx)
13785
13786 @@ -688,6 +691,7 @@ ENTRY(serpent_ecb_enc_8way_avx)
13787
13788 store_8way(%rsi, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13789
13790 + pax_force_retaddr
13791 ret;
13792 ENDPROC(serpent_ecb_enc_8way_avx)
13793
13794 @@ -704,6 +708,7 @@ ENTRY(serpent_ecb_dec_8way_avx)
13795
13796 store_8way(%rsi, RC1, RD1, RB1, RE1, RC2, RD2, RB2, RE2);
13797
13798 + pax_force_retaddr
13799 ret;
13800 ENDPROC(serpent_ecb_dec_8way_avx)
13801
13802 @@ -720,6 +725,7 @@ ENTRY(serpent_cbc_dec_8way_avx)
13803
13804 store_cbc_8way(%rdx, %rsi, RC1, RD1, RB1, RE1, RC2, RD2, RB2, RE2);
13805
13806 + pax_force_retaddr
13807 ret;
13808 ENDPROC(serpent_cbc_dec_8way_avx)
13809
13810 @@ -738,6 +744,7 @@ ENTRY(serpent_ctr_8way_avx)
13811
13812 store_ctr_8way(%rdx, %rsi, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13813
13814 + pax_force_retaddr
13815 ret;
13816 ENDPROC(serpent_ctr_8way_avx)
13817
13818 @@ -758,6 +765,7 @@ ENTRY(serpent_xts_enc_8way_avx)
13819 /* dst <= regs xor IVs(in dst) */
13820 store_xts_8way(%rsi, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13821
13822 + pax_force_retaddr
13823 ret;
13824 ENDPROC(serpent_xts_enc_8way_avx)
13825
13826 @@ -778,5 +786,6 @@ ENTRY(serpent_xts_dec_8way_avx)
13827 /* dst <= regs xor IVs(in dst) */
13828 store_xts_8way(%rsi, RC1, RD1, RB1, RE1, RC2, RD2, RB2, RE2);
13829
13830 + pax_force_retaddr
13831 ret;
13832 ENDPROC(serpent_xts_dec_8way_avx)
13833 diff --git a/arch/x86/crypto/serpent-avx2-asm_64.S b/arch/x86/crypto/serpent-avx2-asm_64.S
13834 index b222085..abd483c 100644
13835 --- a/arch/x86/crypto/serpent-avx2-asm_64.S
13836 +++ b/arch/x86/crypto/serpent-avx2-asm_64.S
13837 @@ -15,6 +15,7 @@
13838 */
13839
13840 #include <linux/linkage.h>
13841 +#include <asm/alternative-asm.h>
13842 #include "glue_helper-asm-avx2.S"
13843
13844 .file "serpent-avx2-asm_64.S"
13845 @@ -610,6 +611,7 @@ __serpent_enc_blk16:
13846 write_blocks(RA1, RB1, RC1, RD1, RK0, RK1, RK2);
13847 write_blocks(RA2, RB2, RC2, RD2, RK0, RK1, RK2);
13848
13849 + pax_force_retaddr
13850 ret;
13851 ENDPROC(__serpent_enc_blk16)
13852
13853 @@ -664,6 +666,7 @@ __serpent_dec_blk16:
13854 write_blocks(RC1, RD1, RB1, RE1, RK0, RK1, RK2);
13855 write_blocks(RC2, RD2, RB2, RE2, RK0, RK1, RK2);
13856
13857 + pax_force_retaddr
13858 ret;
13859 ENDPROC(__serpent_dec_blk16)
13860
13861 @@ -684,6 +687,7 @@ ENTRY(serpent_ecb_enc_16way)
13862
13863 vzeroupper;
13864
13865 + pax_force_retaddr
13866 ret;
13867 ENDPROC(serpent_ecb_enc_16way)
13868
13869 @@ -704,6 +708,7 @@ ENTRY(serpent_ecb_dec_16way)
13870
13871 vzeroupper;
13872
13873 + pax_force_retaddr
13874 ret;
13875 ENDPROC(serpent_ecb_dec_16way)
13876
13877 @@ -725,6 +730,7 @@ ENTRY(serpent_cbc_dec_16way)
13878
13879 vzeroupper;
13880
13881 + pax_force_retaddr
13882 ret;
13883 ENDPROC(serpent_cbc_dec_16way)
13884
13885 @@ -748,6 +754,7 @@ ENTRY(serpent_ctr_16way)
13886
13887 vzeroupper;
13888
13889 + pax_force_retaddr
13890 ret;
13891 ENDPROC(serpent_ctr_16way)
13892
13893 @@ -772,6 +779,7 @@ ENTRY(serpent_xts_enc_16way)
13894
13895 vzeroupper;
13896
13897 + pax_force_retaddr
13898 ret;
13899 ENDPROC(serpent_xts_enc_16way)
13900
13901 @@ -796,5 +804,6 @@ ENTRY(serpent_xts_dec_16way)
13902
13903 vzeroupper;
13904
13905 + pax_force_retaddr
13906 ret;
13907 ENDPROC(serpent_xts_dec_16way)
13908 diff --git a/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S b/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
13909 index acc066c..1559cc4 100644
13910 --- a/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
13911 +++ b/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
13912 @@ -25,6 +25,7 @@
13913 */
13914
13915 #include <linux/linkage.h>
13916 +#include <asm/alternative-asm.h>
13917
13918 .file "serpent-sse2-x86_64-asm_64.S"
13919 .text
13920 @@ -690,12 +691,14 @@ ENTRY(__serpent_enc_blk_8way)
13921 write_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
13922 write_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
13923
13924 + pax_force_retaddr
13925 ret;
13926
13927 .L__enc_xor8:
13928 xor_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
13929 xor_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
13930
13931 + pax_force_retaddr
13932 ret;
13933 ENDPROC(__serpent_enc_blk_8way)
13934
13935 @@ -750,5 +753,6 @@ ENTRY(serpent_dec_blk_8way)
13936 write_blocks(%rsi, RC1, RD1, RB1, RE1, RK0, RK1, RK2);
13937 write_blocks(%rax, RC2, RD2, RB2, RE2, RK0, RK1, RK2);
13938
13939 + pax_force_retaddr
13940 ret;
13941 ENDPROC(serpent_dec_blk_8way)
13942 diff --git a/arch/x86/crypto/sha1_ssse3_asm.S b/arch/x86/crypto/sha1_ssse3_asm.S
13943 index a410950..9dfe7ad 100644
13944 --- a/arch/x86/crypto/sha1_ssse3_asm.S
13945 +++ b/arch/x86/crypto/sha1_ssse3_asm.S
13946 @@ -29,6 +29,7 @@
13947 */
13948
13949 #include <linux/linkage.h>
13950 +#include <asm/alternative-asm.h>
13951
13952 #define CTX %rdi // arg1
13953 #define BUF %rsi // arg2
13954 @@ -75,9 +76,9 @@
13955
13956 push %rbx
13957 push %rbp
13958 - push %r12
13959 + push %r14
13960
13961 - mov %rsp, %r12
13962 + mov %rsp, %r14
13963 sub $64, %rsp # allocate workspace
13964 and $~15, %rsp # align stack
13965
13966 @@ -99,11 +100,12 @@
13967 xor %rax, %rax
13968 rep stosq
13969
13970 - mov %r12, %rsp # deallocate workspace
13971 + mov %r14, %rsp # deallocate workspace
13972
13973 - pop %r12
13974 + pop %r14
13975 pop %rbp
13976 pop %rbx
13977 + pax_force_retaddr
13978 ret
13979
13980 ENDPROC(\name)
13981 diff --git a/arch/x86/crypto/sha256-avx-asm.S b/arch/x86/crypto/sha256-avx-asm.S
13982 index 642f156..51a513c 100644
13983 --- a/arch/x86/crypto/sha256-avx-asm.S
13984 +++ b/arch/x86/crypto/sha256-avx-asm.S
13985 @@ -49,6 +49,7 @@
13986
13987 #ifdef CONFIG_AS_AVX
13988 #include <linux/linkage.h>
13989 +#include <asm/alternative-asm.h>
13990
13991 ## assume buffers not aligned
13992 #define VMOVDQ vmovdqu
13993 @@ -460,6 +461,7 @@ done_hash:
13994 popq %r13
13995 popq %rbp
13996 popq %rbx
13997 + pax_force_retaddr
13998 ret
13999 ENDPROC(sha256_transform_avx)
14000
14001 diff --git a/arch/x86/crypto/sha256-avx2-asm.S b/arch/x86/crypto/sha256-avx2-asm.S
14002 index 9e86944..3795e6a 100644
14003 --- a/arch/x86/crypto/sha256-avx2-asm.S
14004 +++ b/arch/x86/crypto/sha256-avx2-asm.S
14005 @@ -50,6 +50,7 @@
14006
14007 #ifdef CONFIG_AS_AVX2
14008 #include <linux/linkage.h>
14009 +#include <asm/alternative-asm.h>
14010
14011 ## assume buffers not aligned
14012 #define VMOVDQ vmovdqu
14013 @@ -720,6 +721,7 @@ done_hash:
14014 popq %r12
14015 popq %rbp
14016 popq %rbx
14017 + pax_force_retaddr
14018 ret
14019 ENDPROC(sha256_transform_rorx)
14020
14021 diff --git a/arch/x86/crypto/sha256-ssse3-asm.S b/arch/x86/crypto/sha256-ssse3-asm.S
14022 index f833b74..8c62a9e 100644
14023 --- a/arch/x86/crypto/sha256-ssse3-asm.S
14024 +++ b/arch/x86/crypto/sha256-ssse3-asm.S
14025 @@ -47,6 +47,7 @@
14026 ########################################################################
14027
14028 #include <linux/linkage.h>
14029 +#include <asm/alternative-asm.h>
14030
14031 ## assume buffers not aligned
14032 #define MOVDQ movdqu
14033 @@ -471,6 +472,7 @@ done_hash:
14034 popq %rbp
14035 popq %rbx
14036
14037 + pax_force_retaddr
14038 ret
14039 ENDPROC(sha256_transform_ssse3)
14040
14041 diff --git a/arch/x86/crypto/sha512-avx-asm.S b/arch/x86/crypto/sha512-avx-asm.S
14042 index 974dde9..a823ff9 100644
14043 --- a/arch/x86/crypto/sha512-avx-asm.S
14044 +++ b/arch/x86/crypto/sha512-avx-asm.S
14045 @@ -49,6 +49,7 @@
14046
14047 #ifdef CONFIG_AS_AVX
14048 #include <linux/linkage.h>
14049 +#include <asm/alternative-asm.h>
14050
14051 .text
14052
14053 @@ -364,6 +365,7 @@ updateblock:
14054 mov frame_RSPSAVE(%rsp), %rsp
14055
14056 nowork:
14057 + pax_force_retaddr
14058 ret
14059 ENDPROC(sha512_transform_avx)
14060
14061 diff --git a/arch/x86/crypto/sha512-avx2-asm.S b/arch/x86/crypto/sha512-avx2-asm.S
14062 index 568b961..ed20c37 100644
14063 --- a/arch/x86/crypto/sha512-avx2-asm.S
14064 +++ b/arch/x86/crypto/sha512-avx2-asm.S
14065 @@ -51,6 +51,7 @@
14066
14067 #ifdef CONFIG_AS_AVX2
14068 #include <linux/linkage.h>
14069 +#include <asm/alternative-asm.h>
14070
14071 .text
14072
14073 @@ -678,6 +679,7 @@ done_hash:
14074
14075 # Restore Stack Pointer
14076 mov frame_RSPSAVE(%rsp), %rsp
14077 + pax_force_retaddr
14078 ret
14079 ENDPROC(sha512_transform_rorx)
14080
14081 diff --git a/arch/x86/crypto/sha512-ssse3-asm.S b/arch/x86/crypto/sha512-ssse3-asm.S
14082 index fb56855..6edd768 100644
14083 --- a/arch/x86/crypto/sha512-ssse3-asm.S
14084 +++ b/arch/x86/crypto/sha512-ssse3-asm.S
14085 @@ -48,6 +48,7 @@
14086 ########################################################################
14087
14088 #include <linux/linkage.h>
14089 +#include <asm/alternative-asm.h>
14090
14091 .text
14092
14093 @@ -363,6 +364,7 @@ updateblock:
14094 mov frame_RSPSAVE(%rsp), %rsp
14095
14096 nowork:
14097 + pax_force_retaddr
14098 ret
14099 ENDPROC(sha512_transform_ssse3)
14100
14101 diff --git a/arch/x86/crypto/twofish-avx-x86_64-asm_64.S b/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
14102 index 0505813..b067311 100644
14103 --- a/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
14104 +++ b/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
14105 @@ -24,6 +24,7 @@
14106 */
14107
14108 #include <linux/linkage.h>
14109 +#include <asm/alternative-asm.h>
14110 #include "glue_helper-asm-avx.S"
14111
14112 .file "twofish-avx-x86_64-asm_64.S"
14113 @@ -284,6 +285,7 @@ __twofish_enc_blk8:
14114 outunpack_blocks(RC1, RD1, RA1, RB1, RK1, RX0, RY0, RK2);
14115 outunpack_blocks(RC2, RD2, RA2, RB2, RK1, RX0, RY0, RK2);
14116
14117 + pax_force_retaddr
14118 ret;
14119 ENDPROC(__twofish_enc_blk8)
14120
14121 @@ -324,6 +326,7 @@ __twofish_dec_blk8:
14122 outunpack_blocks(RA1, RB1, RC1, RD1, RK1, RX0, RY0, RK2);
14123 outunpack_blocks(RA2, RB2, RC2, RD2, RK1, RX0, RY0, RK2);
14124
14125 + pax_force_retaddr
14126 ret;
14127 ENDPROC(__twofish_dec_blk8)
14128
14129 @@ -342,6 +345,7 @@ ENTRY(twofish_ecb_enc_8way)
14130
14131 store_8way(%r11, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
14132
14133 + pax_force_retaddr
14134 ret;
14135 ENDPROC(twofish_ecb_enc_8way)
14136
14137 @@ -360,6 +364,7 @@ ENTRY(twofish_ecb_dec_8way)
14138
14139 store_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14140
14141 + pax_force_retaddr
14142 ret;
14143 ENDPROC(twofish_ecb_dec_8way)
14144
14145 @@ -370,19 +375,20 @@ ENTRY(twofish_cbc_dec_8way)
14146 * %rdx: src
14147 */
14148
14149 - pushq %r12;
14150 + pushq %r14;
14151
14152 movq %rsi, %r11;
14153 - movq %rdx, %r12;
14154 + movq %rdx, %r14;
14155
14156 load_8way(%rdx, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
14157
14158 call __twofish_dec_blk8;
14159
14160 - store_cbc_8way(%r12, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14161 + store_cbc_8way(%r14, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14162
14163 - popq %r12;
14164 + popq %r14;
14165
14166 + pax_force_retaddr
14167 ret;
14168 ENDPROC(twofish_cbc_dec_8way)
14169
14170 @@ -394,20 +400,21 @@ ENTRY(twofish_ctr_8way)
14171 * %rcx: iv (little endian, 128bit)
14172 */
14173
14174 - pushq %r12;
14175 + pushq %r14;
14176
14177 movq %rsi, %r11;
14178 - movq %rdx, %r12;
14179 + movq %rdx, %r14;
14180
14181 load_ctr_8way(%rcx, .Lbswap128_mask, RA1, RB1, RC1, RD1, RA2, RB2, RC2,
14182 RD2, RX0, RX1, RY0);
14183
14184 call __twofish_enc_blk8;
14185
14186 - store_ctr_8way(%r12, %r11, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
14187 + store_ctr_8way(%r14, %r11, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
14188
14189 - popq %r12;
14190 + popq %r14;
14191
14192 + pax_force_retaddr
14193 ret;
14194 ENDPROC(twofish_ctr_8way)
14195
14196 @@ -430,6 +437,7 @@ ENTRY(twofish_xts_enc_8way)
14197 /* dst <= regs xor IVs(in dst) */
14198 store_xts_8way(%r11, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
14199
14200 + pax_force_retaddr
14201 ret;
14202 ENDPROC(twofish_xts_enc_8way)
14203
14204 @@ -452,5 +460,6 @@ ENTRY(twofish_xts_dec_8way)
14205 /* dst <= regs xor IVs(in dst) */
14206 store_xts_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14207
14208 + pax_force_retaddr
14209 ret;
14210 ENDPROC(twofish_xts_dec_8way)
14211 diff --git a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
14212 index 1c3b7ce..02f578d 100644
14213 --- a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
14214 +++ b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
14215 @@ -21,6 +21,7 @@
14216 */
14217
14218 #include <linux/linkage.h>
14219 +#include <asm/alternative-asm.h>
14220
14221 .file "twofish-x86_64-asm-3way.S"
14222 .text
14223 @@ -258,6 +259,7 @@ ENTRY(__twofish_enc_blk_3way)
14224 popq %r13;
14225 popq %r14;
14226 popq %r15;
14227 + pax_force_retaddr
14228 ret;
14229
14230 .L__enc_xor3:
14231 @@ -269,6 +271,7 @@ ENTRY(__twofish_enc_blk_3way)
14232 popq %r13;
14233 popq %r14;
14234 popq %r15;
14235 + pax_force_retaddr
14236 ret;
14237 ENDPROC(__twofish_enc_blk_3way)
14238
14239 @@ -308,5 +311,6 @@ ENTRY(twofish_dec_blk_3way)
14240 popq %r13;
14241 popq %r14;
14242 popq %r15;
14243 + pax_force_retaddr
14244 ret;
14245 ENDPROC(twofish_dec_blk_3way)
14246 diff --git a/arch/x86/crypto/twofish-x86_64-asm_64.S b/arch/x86/crypto/twofish-x86_64-asm_64.S
14247 index a039d21..524b8b2 100644
14248 --- a/arch/x86/crypto/twofish-x86_64-asm_64.S
14249 +++ b/arch/x86/crypto/twofish-x86_64-asm_64.S
14250 @@ -22,6 +22,7 @@
14251
14252 #include <linux/linkage.h>
14253 #include <asm/asm-offsets.h>
14254 +#include <asm/alternative-asm.h>
14255
14256 #define a_offset 0
14257 #define b_offset 4
14258 @@ -265,6 +266,7 @@ ENTRY(twofish_enc_blk)
14259
14260 popq R1
14261 movq $1,%rax
14262 + pax_force_retaddr
14263 ret
14264 ENDPROC(twofish_enc_blk)
14265
14266 @@ -317,5 +319,6 @@ ENTRY(twofish_dec_blk)
14267
14268 popq R1
14269 movq $1,%rax
14270 + pax_force_retaddr
14271 ret
14272 ENDPROC(twofish_dec_blk)
14273 diff --git a/arch/x86/ia32/ia32_aout.c b/arch/x86/ia32/ia32_aout.c
14274 index d21ff89..6da8e6e 100644
14275 --- a/arch/x86/ia32/ia32_aout.c
14276 +++ b/arch/x86/ia32/ia32_aout.c
14277 @@ -153,6 +153,8 @@ static int aout_core_dump(struct coredump_params *cprm)
14278 unsigned long dump_start, dump_size;
14279 struct user32 dump;
14280
14281 + memset(&dump, 0, sizeof(dump));
14282 +
14283 fs = get_fs();
14284 set_fs(KERNEL_DS);
14285 has_dumped = 1;
14286 diff --git a/arch/x86/ia32/ia32_signal.c b/arch/x86/ia32/ia32_signal.c
14287 index 2206757..85cbcfa 100644
14288 --- a/arch/x86/ia32/ia32_signal.c
14289 +++ b/arch/x86/ia32/ia32_signal.c
14290 @@ -218,7 +218,7 @@ asmlinkage long sys32_sigreturn(void)
14291 if (__get_user(set.sig[0], &frame->sc.oldmask)
14292 || (_COMPAT_NSIG_WORDS > 1
14293 && __copy_from_user((((char *) &set.sig) + 4),
14294 - &frame->extramask,
14295 + frame->extramask,
14296 sizeof(frame->extramask))))
14297 goto badframe;
14298
14299 @@ -338,7 +338,7 @@ static void __user *get_sigframe(struct ksignal *ksig, struct pt_regs *regs,
14300 sp -= frame_size;
14301 /* Align the stack pointer according to the i386 ABI,
14302 * i.e. so that on function entry ((sp + 4) & 15) == 0. */
14303 - sp = ((sp + 4) & -16ul) - 4;
14304 + sp = ((sp - 12) & -16ul) - 4;
14305 return (void __user *) sp;
14306 }
14307
14308 @@ -386,7 +386,7 @@ int ia32_setup_frame(int sig, struct ksignal *ksig,
14309 restorer = VDSO32_SYMBOL(current->mm->context.vdso,
14310 sigreturn);
14311 else
14312 - restorer = &frame->retcode;
14313 + restorer = frame->retcode;
14314 }
14315
14316 put_user_try {
14317 @@ -396,7 +396,7 @@ int ia32_setup_frame(int sig, struct ksignal *ksig,
14318 * These are actually not used anymore, but left because some
14319 * gdb versions depend on them as a marker.
14320 */
14321 - put_user_ex(*((u64 *)&code), (u64 __user *)frame->retcode);
14322 + put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
14323 } put_user_catch(err);
14324
14325 if (err)
14326 @@ -438,7 +438,7 @@ int ia32_setup_rt_frame(int sig, struct ksignal *ksig,
14327 0xb8,
14328 __NR_ia32_rt_sigreturn,
14329 0x80cd,
14330 - 0,
14331 + 0
14332 };
14333
14334 frame = get_sigframe(ksig, regs, sizeof(*frame), &fpstate);
14335 @@ -461,16 +461,18 @@ int ia32_setup_rt_frame(int sig, struct ksignal *ksig,
14336
14337 if (ksig->ka.sa.sa_flags & SA_RESTORER)
14338 restorer = ksig->ka.sa.sa_restorer;
14339 + else if (current->mm->context.vdso)
14340 + /* Return stub is in 32bit vsyscall page */
14341 + restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
14342 else
14343 - restorer = VDSO32_SYMBOL(current->mm->context.vdso,
14344 - rt_sigreturn);
14345 + restorer = frame->retcode;
14346 put_user_ex(ptr_to_compat(restorer), &frame->pretcode);
14347
14348 /*
14349 * Not actually used anymore, but left because some gdb
14350 * versions need it.
14351 */
14352 - put_user_ex(*((u64 *)&code), (u64 __user *)frame->retcode);
14353 + put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
14354 } put_user_catch(err);
14355
14356 err |= copy_siginfo_to_user32(&frame->info, &ksig->info);
14357 diff --git a/arch/x86/ia32/ia32entry.S b/arch/x86/ia32/ia32entry.S
14358 index 4299eb0..c0687a7 100644
14359 --- a/arch/x86/ia32/ia32entry.S
14360 +++ b/arch/x86/ia32/ia32entry.S
14361 @@ -15,8 +15,10 @@
14362 #include <asm/irqflags.h>
14363 #include <asm/asm.h>
14364 #include <asm/smap.h>
14365 +#include <asm/pgtable.h>
14366 #include <linux/linkage.h>
14367 #include <linux/err.h>
14368 +#include <asm/alternative-asm.h>
14369
14370 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
14371 #include <linux/elf-em.h>
14372 @@ -62,12 +64,12 @@
14373 */
14374 .macro LOAD_ARGS32 offset, _r9=0
14375 .if \_r9
14376 - movl \offset+16(%rsp),%r9d
14377 + movl \offset+R9(%rsp),%r9d
14378 .endif
14379 - movl \offset+40(%rsp),%ecx
14380 - movl \offset+48(%rsp),%edx
14381 - movl \offset+56(%rsp),%esi
14382 - movl \offset+64(%rsp),%edi
14383 + movl \offset+RCX(%rsp),%ecx
14384 + movl \offset+RDX(%rsp),%edx
14385 + movl \offset+RSI(%rsp),%esi
14386 + movl \offset+RDI(%rsp),%edi
14387 movl %eax,%eax /* zero extension */
14388 .endm
14389
14390 @@ -96,6 +98,32 @@ ENTRY(native_irq_enable_sysexit)
14391 ENDPROC(native_irq_enable_sysexit)
14392 #endif
14393
14394 + .macro pax_enter_kernel_user
14395 + pax_set_fptr_mask
14396 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14397 + call pax_enter_kernel_user
14398 +#endif
14399 + .endm
14400 +
14401 + .macro pax_exit_kernel_user
14402 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14403 + call pax_exit_kernel_user
14404 +#endif
14405 +#ifdef CONFIG_PAX_RANDKSTACK
14406 + pushq %rax
14407 + pushq %r11
14408 + call pax_randomize_kstack
14409 + popq %r11
14410 + popq %rax
14411 +#endif
14412 + .endm
14413 +
14414 + .macro pax_erase_kstack
14415 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
14416 + call pax_erase_kstack
14417 +#endif
14418 + .endm
14419 +
14420 /*
14421 * 32bit SYSENTER instruction entry.
14422 *
14423 @@ -122,12 +150,6 @@ ENTRY(ia32_sysenter_target)
14424 CFI_REGISTER rsp,rbp
14425 SWAPGS_UNSAFE_STACK
14426 movq PER_CPU_VAR(kernel_stack), %rsp
14427 - addq $(KERNEL_STACK_OFFSET),%rsp
14428 - /*
14429 - * No need to follow this irqs on/off section: the syscall
14430 - * disabled irqs, here we enable it straight after entry:
14431 - */
14432 - ENABLE_INTERRUPTS(CLBR_NONE)
14433 movl %ebp,%ebp /* zero extension */
14434 pushq_cfi $__USER32_DS
14435 /*CFI_REL_OFFSET ss,0*/
14436 @@ -135,24 +157,49 @@ ENTRY(ia32_sysenter_target)
14437 CFI_REL_OFFSET rsp,0
14438 pushfq_cfi
14439 /*CFI_REL_OFFSET rflags,0*/
14440 - movl TI_sysenter_return+THREAD_INFO(%rsp,3*8-KERNEL_STACK_OFFSET),%r10d
14441 - CFI_REGISTER rip,r10
14442 + orl $X86_EFLAGS_IF,(%rsp)
14443 + GET_THREAD_INFO(%r11)
14444 + movl TI_sysenter_return(%r11), %r11d
14445 + CFI_REGISTER rip,r11
14446 pushq_cfi $__USER32_CS
14447 /*CFI_REL_OFFSET cs,0*/
14448 movl %eax, %eax
14449 - pushq_cfi %r10
14450 + pushq_cfi %r11
14451 CFI_REL_OFFSET rip,0
14452 pushq_cfi %rax
14453 cld
14454 SAVE_ARGS 0,1,0
14455 + pax_enter_kernel_user
14456 +
14457 +#ifdef CONFIG_PAX_RANDKSTACK
14458 + pax_erase_kstack
14459 +#endif
14460 +
14461 + /*
14462 + * No need to follow this irqs on/off section: the syscall
14463 + * disabled irqs, here we enable it straight after entry:
14464 + */
14465 + ENABLE_INTERRUPTS(CLBR_NONE)
14466 /* no need to do an access_ok check here because rbp has been
14467 32bit zero extended */
14468 +
14469 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14470 + addq pax_user_shadow_base,%rbp
14471 + ASM_PAX_OPEN_USERLAND
14472 +#endif
14473 +
14474 ASM_STAC
14475 1: movl (%rbp),%ebp
14476 _ASM_EXTABLE(1b,ia32_badarg)
14477 ASM_CLAC
14478 - orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14479 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14480 +
14481 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14482 + ASM_PAX_CLOSE_USERLAND
14483 +#endif
14484 +
14485 + GET_THREAD_INFO(%r11)
14486 + orl $TS_COMPAT,TI_status(%r11)
14487 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
14488 CFI_REMEMBER_STATE
14489 jnz sysenter_tracesys
14490 cmpq $(IA32_NR_syscalls-1),%rax
14491 @@ -162,15 +209,18 @@ sysenter_do_call:
14492 sysenter_dispatch:
14493 call *ia32_sys_call_table(,%rax,8)
14494 movq %rax,RAX-ARGOFFSET(%rsp)
14495 + GET_THREAD_INFO(%r11)
14496 DISABLE_INTERRUPTS(CLBR_NONE)
14497 TRACE_IRQS_OFF
14498 - testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14499 + testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
14500 jnz sysexit_audit
14501 sysexit_from_sys_call:
14502 - andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14503 + pax_exit_kernel_user
14504 + pax_erase_kstack
14505 + andl $~TS_COMPAT,TI_status(%r11)
14506 /* clear IF, that popfq doesn't enable interrupts early */
14507 - andl $~0x200,EFLAGS-R11(%rsp)
14508 - movl RIP-R11(%rsp),%edx /* User %eip */
14509 + andl $~X86_EFLAGS_IF,EFLAGS(%rsp)
14510 + movl RIP(%rsp),%edx /* User %eip */
14511 CFI_REGISTER rip,rdx
14512 RESTORE_ARGS 0,24,0,0,0,0
14513 xorq %r8,%r8
14514 @@ -193,6 +243,9 @@ sysexit_from_sys_call:
14515 movl %eax,%esi /* 2nd arg: syscall number */
14516 movl $AUDIT_ARCH_I386,%edi /* 1st arg: audit arch */
14517 call __audit_syscall_entry
14518 +
14519 + pax_erase_kstack
14520 +
14521 movl RAX-ARGOFFSET(%rsp),%eax /* reload syscall number */
14522 cmpq $(IA32_NR_syscalls-1),%rax
14523 ja ia32_badsys
14524 @@ -204,7 +257,7 @@ sysexit_from_sys_call:
14525 .endm
14526
14527 .macro auditsys_exit exit
14528 - testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14529 + testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
14530 jnz ia32_ret_from_sys_call
14531 TRACE_IRQS_ON
14532 ENABLE_INTERRUPTS(CLBR_NONE)
14533 @@ -215,11 +268,12 @@ sysexit_from_sys_call:
14534 1: setbe %al /* 1 if error, 0 if not */
14535 movzbl %al,%edi /* zero-extend that into %edi */
14536 call __audit_syscall_exit
14537 + GET_THREAD_INFO(%r11)
14538 movq RAX-ARGOFFSET(%rsp),%rax /* reload syscall return value */
14539 movl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),%edi
14540 DISABLE_INTERRUPTS(CLBR_NONE)
14541 TRACE_IRQS_OFF
14542 - testl %edi,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14543 + testl %edi,TI_flags(%r11)
14544 jz \exit
14545 CLEAR_RREGS -ARGOFFSET
14546 jmp int_with_check
14547 @@ -237,7 +291,7 @@ sysexit_audit:
14548
14549 sysenter_tracesys:
14550 #ifdef CONFIG_AUDITSYSCALL
14551 - testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14552 + testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
14553 jz sysenter_auditsys
14554 #endif
14555 SAVE_REST
14556 @@ -249,6 +303,9 @@ sysenter_tracesys:
14557 RESTORE_REST
14558 cmpq $(IA32_NR_syscalls-1),%rax
14559 ja int_ret_from_sys_call /* sysenter_tracesys has set RAX(%rsp) */
14560 +
14561 + pax_erase_kstack
14562 +
14563 jmp sysenter_do_call
14564 CFI_ENDPROC
14565 ENDPROC(ia32_sysenter_target)
14566 @@ -276,19 +333,25 @@ ENDPROC(ia32_sysenter_target)
14567 ENTRY(ia32_cstar_target)
14568 CFI_STARTPROC32 simple
14569 CFI_SIGNAL_FRAME
14570 - CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
14571 + CFI_DEF_CFA rsp,0
14572 CFI_REGISTER rip,rcx
14573 /*CFI_REGISTER rflags,r11*/
14574 SWAPGS_UNSAFE_STACK
14575 movl %esp,%r8d
14576 CFI_REGISTER rsp,r8
14577 movq PER_CPU_VAR(kernel_stack),%rsp
14578 + SAVE_ARGS 8*6,0,0
14579 + pax_enter_kernel_user
14580 +
14581 +#ifdef CONFIG_PAX_RANDKSTACK
14582 + pax_erase_kstack
14583 +#endif
14584 +
14585 /*
14586 * No need to follow this irqs on/off section: the syscall
14587 * disabled irqs and here we enable it straight after entry:
14588 */
14589 ENABLE_INTERRUPTS(CLBR_NONE)
14590 - SAVE_ARGS 8,0,0
14591 movl %eax,%eax /* zero extension */
14592 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
14593 movq %rcx,RIP-ARGOFFSET(%rsp)
14594 @@ -304,12 +367,25 @@ ENTRY(ia32_cstar_target)
14595 /* no need to do an access_ok check here because r8 has been
14596 32bit zero extended */
14597 /* hardware stack frame is complete now */
14598 +
14599 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14600 + ASM_PAX_OPEN_USERLAND
14601 + movq pax_user_shadow_base,%r8
14602 + addq RSP-ARGOFFSET(%rsp),%r8
14603 +#endif
14604 +
14605 ASM_STAC
14606 1: movl (%r8),%r9d
14607 _ASM_EXTABLE(1b,ia32_badarg)
14608 ASM_CLAC
14609 - orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14610 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14611 +
14612 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14613 + ASM_PAX_CLOSE_USERLAND
14614 +#endif
14615 +
14616 + GET_THREAD_INFO(%r11)
14617 + orl $TS_COMPAT,TI_status(%r11)
14618 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
14619 CFI_REMEMBER_STATE
14620 jnz cstar_tracesys
14621 cmpq $IA32_NR_syscalls-1,%rax
14622 @@ -319,13 +395,16 @@ cstar_do_call:
14623 cstar_dispatch:
14624 call *ia32_sys_call_table(,%rax,8)
14625 movq %rax,RAX-ARGOFFSET(%rsp)
14626 + GET_THREAD_INFO(%r11)
14627 DISABLE_INTERRUPTS(CLBR_NONE)
14628 TRACE_IRQS_OFF
14629 - testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14630 + testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
14631 jnz sysretl_audit
14632 sysretl_from_sys_call:
14633 - andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14634 - RESTORE_ARGS 0,-ARG_SKIP,0,0,0
14635 + pax_exit_kernel_user
14636 + pax_erase_kstack
14637 + andl $~TS_COMPAT,TI_status(%r11)
14638 + RESTORE_ARGS 0,-ORIG_RAX,0,0,0
14639 movl RIP-ARGOFFSET(%rsp),%ecx
14640 CFI_REGISTER rip,rcx
14641 movl EFLAGS-ARGOFFSET(%rsp),%r11d
14642 @@ -352,7 +431,7 @@ sysretl_audit:
14643
14644 cstar_tracesys:
14645 #ifdef CONFIG_AUDITSYSCALL
14646 - testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14647 + testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
14648 jz cstar_auditsys
14649 #endif
14650 xchgl %r9d,%ebp
14651 @@ -366,11 +445,19 @@ cstar_tracesys:
14652 xchgl %ebp,%r9d
14653 cmpq $(IA32_NR_syscalls-1),%rax
14654 ja int_ret_from_sys_call /* cstar_tracesys has set RAX(%rsp) */
14655 +
14656 + pax_erase_kstack
14657 +
14658 jmp cstar_do_call
14659 END(ia32_cstar_target)
14660
14661 ia32_badarg:
14662 ASM_CLAC
14663 +
14664 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14665 + ASM_PAX_CLOSE_USERLAND
14666 +#endif
14667 +
14668 movq $-EFAULT,%rax
14669 jmp ia32_sysret
14670 CFI_ENDPROC
14671 @@ -407,19 +494,26 @@ ENTRY(ia32_syscall)
14672 CFI_REL_OFFSET rip,RIP-RIP
14673 PARAVIRT_ADJUST_EXCEPTION_FRAME
14674 SWAPGS
14675 - /*
14676 - * No need to follow this irqs on/off section: the syscall
14677 - * disabled irqs and here we enable it straight after entry:
14678 - */
14679 - ENABLE_INTERRUPTS(CLBR_NONE)
14680 movl %eax,%eax
14681 pushq_cfi %rax
14682 cld
14683 /* note the registers are not zero extended to the sf.
14684 this could be a problem. */
14685 SAVE_ARGS 0,1,0
14686 - orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14687 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14688 + pax_enter_kernel_user
14689 +
14690 +#ifdef CONFIG_PAX_RANDKSTACK
14691 + pax_erase_kstack
14692 +#endif
14693 +
14694 + /*
14695 + * No need to follow this irqs on/off section: the syscall
14696 + * disabled irqs and here we enable it straight after entry:
14697 + */
14698 + ENABLE_INTERRUPTS(CLBR_NONE)
14699 + GET_THREAD_INFO(%r11)
14700 + orl $TS_COMPAT,TI_status(%r11)
14701 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
14702 jnz ia32_tracesys
14703 cmpq $(IA32_NR_syscalls-1),%rax
14704 ja ia32_badsys
14705 @@ -442,6 +536,9 @@ ia32_tracesys:
14706 RESTORE_REST
14707 cmpq $(IA32_NR_syscalls-1),%rax
14708 ja int_ret_from_sys_call /* ia32_tracesys has set RAX(%rsp) */
14709 +
14710 + pax_erase_kstack
14711 +
14712 jmp ia32_do_call
14713 END(ia32_syscall)
14714
14715 diff --git a/arch/x86/ia32/sys_ia32.c b/arch/x86/ia32/sys_ia32.c
14716 index 8e0ceec..af13504 100644
14717 --- a/arch/x86/ia32/sys_ia32.c
14718 +++ b/arch/x86/ia32/sys_ia32.c
14719 @@ -69,8 +69,8 @@ asmlinkage long sys32_ftruncate64(unsigned int fd, unsigned long offset_low,
14720 */
14721 static int cp_stat64(struct stat64 __user *ubuf, struct kstat *stat)
14722 {
14723 - typeof(ubuf->st_uid) uid = 0;
14724 - typeof(ubuf->st_gid) gid = 0;
14725 + typeof(((struct stat64 *)0)->st_uid) uid = 0;
14726 + typeof(((struct stat64 *)0)->st_gid) gid = 0;
14727 SET_UID(uid, from_kuid_munged(current_user_ns(), stat->uid));
14728 SET_GID(gid, from_kgid_munged(current_user_ns(), stat->gid));
14729 if (!access_ok(VERIFY_WRITE, ubuf, sizeof(struct stat64)) ||
14730 diff --git a/arch/x86/include/asm/alternative-asm.h b/arch/x86/include/asm/alternative-asm.h
14731 index 372231c..51b537d 100644
14732 --- a/arch/x86/include/asm/alternative-asm.h
14733 +++ b/arch/x86/include/asm/alternative-asm.h
14734 @@ -18,6 +18,45 @@
14735 .endm
14736 #endif
14737
14738 +#ifdef KERNEXEC_PLUGIN
14739 + .macro pax_force_retaddr_bts rip=0
14740 + btsq $63,\rip(%rsp)
14741 + .endm
14742 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
14743 + .macro pax_force_retaddr rip=0, reload=0
14744 + btsq $63,\rip(%rsp)
14745 + .endm
14746 + .macro pax_force_fptr ptr
14747 + btsq $63,\ptr
14748 + .endm
14749 + .macro pax_set_fptr_mask
14750 + .endm
14751 +#endif
14752 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
14753 + .macro pax_force_retaddr rip=0, reload=0
14754 + .if \reload
14755 + pax_set_fptr_mask
14756 + .endif
14757 + orq %r12,\rip(%rsp)
14758 + .endm
14759 + .macro pax_force_fptr ptr
14760 + orq %r12,\ptr
14761 + .endm
14762 + .macro pax_set_fptr_mask
14763 + movabs $0x8000000000000000,%r12
14764 + .endm
14765 +#endif
14766 +#else
14767 + .macro pax_force_retaddr rip=0, reload=0
14768 + .endm
14769 + .macro pax_force_fptr ptr
14770 + .endm
14771 + .macro pax_force_retaddr_bts rip=0
14772 + .endm
14773 + .macro pax_set_fptr_mask
14774 + .endm
14775 +#endif
14776 +
14777 .macro altinstruction_entry orig alt feature orig_len alt_len
14778 .long \orig - .
14779 .long \alt - .
14780 diff --git a/arch/x86/include/asm/alternative.h b/arch/x86/include/asm/alternative.h
14781 index 0a3f9c9..c9d081d 100644
14782 --- a/arch/x86/include/asm/alternative.h
14783 +++ b/arch/x86/include/asm/alternative.h
14784 @@ -106,7 +106,7 @@ static inline int alternatives_text_reserved(void *start, void *end)
14785 ".pushsection .discard,\"aw\",@progbits\n" \
14786 DISCARD_ENTRY(1) \
14787 ".popsection\n" \
14788 - ".pushsection .altinstr_replacement, \"ax\"\n" \
14789 + ".pushsection .altinstr_replacement, \"a\"\n" \
14790 ALTINSTR_REPLACEMENT(newinstr, feature, 1) \
14791 ".popsection"
14792
14793 @@ -120,7 +120,7 @@ static inline int alternatives_text_reserved(void *start, void *end)
14794 DISCARD_ENTRY(1) \
14795 DISCARD_ENTRY(2) \
14796 ".popsection\n" \
14797 - ".pushsection .altinstr_replacement, \"ax\"\n" \
14798 + ".pushsection .altinstr_replacement, \"a\"\n" \
14799 ALTINSTR_REPLACEMENT(newinstr1, feature1, 1) \
14800 ALTINSTR_REPLACEMENT(newinstr2, feature2, 2) \
14801 ".popsection"
14802 diff --git a/arch/x86/include/asm/apic.h b/arch/x86/include/asm/apic.h
14803 index 1d2091a..f5074c1 100644
14804 --- a/arch/x86/include/asm/apic.h
14805 +++ b/arch/x86/include/asm/apic.h
14806 @@ -45,7 +45,7 @@ static inline void generic_apic_probe(void)
14807
14808 #ifdef CONFIG_X86_LOCAL_APIC
14809
14810 -extern unsigned int apic_verbosity;
14811 +extern int apic_verbosity;
14812 extern int local_apic_timer_c2_ok;
14813
14814 extern int disable_apic;
14815 diff --git a/arch/x86/include/asm/apm.h b/arch/x86/include/asm/apm.h
14816 index 20370c6..a2eb9b0 100644
14817 --- a/arch/x86/include/asm/apm.h
14818 +++ b/arch/x86/include/asm/apm.h
14819 @@ -34,7 +34,7 @@ static inline void apm_bios_call_asm(u32 func, u32 ebx_in, u32 ecx_in,
14820 __asm__ __volatile__(APM_DO_ZERO_SEGS
14821 "pushl %%edi\n\t"
14822 "pushl %%ebp\n\t"
14823 - "lcall *%%cs:apm_bios_entry\n\t"
14824 + "lcall *%%ss:apm_bios_entry\n\t"
14825 "setc %%al\n\t"
14826 "popl %%ebp\n\t"
14827 "popl %%edi\n\t"
14828 @@ -58,7 +58,7 @@ static inline u8 apm_bios_call_simple_asm(u32 func, u32 ebx_in,
14829 __asm__ __volatile__(APM_DO_ZERO_SEGS
14830 "pushl %%edi\n\t"
14831 "pushl %%ebp\n\t"
14832 - "lcall *%%cs:apm_bios_entry\n\t"
14833 + "lcall *%%ss:apm_bios_entry\n\t"
14834 "setc %%bl\n\t"
14835 "popl %%ebp\n\t"
14836 "popl %%edi\n\t"
14837 diff --git a/arch/x86/include/asm/atomic.h b/arch/x86/include/asm/atomic.h
14838 index b17f4f4..9620151 100644
14839 --- a/arch/x86/include/asm/atomic.h
14840 +++ b/arch/x86/include/asm/atomic.h
14841 @@ -23,7 +23,18 @@
14842 */
14843 static inline int atomic_read(const atomic_t *v)
14844 {
14845 - return (*(volatile int *)&(v)->counter);
14846 + return (*(volatile const int *)&(v)->counter);
14847 +}
14848 +
14849 +/**
14850 + * atomic_read_unchecked - read atomic variable
14851 + * @v: pointer of type atomic_unchecked_t
14852 + *
14853 + * Atomically reads the value of @v.
14854 + */
14855 +static inline int __intentional_overflow(-1) atomic_read_unchecked(const atomic_unchecked_t *v)
14856 +{
14857 + return (*(volatile const int *)&(v)->counter);
14858 }
14859
14860 /**
14861 @@ -39,6 +50,18 @@ static inline void atomic_set(atomic_t *v, int i)
14862 }
14863
14864 /**
14865 + * atomic_set_unchecked - set atomic variable
14866 + * @v: pointer of type atomic_unchecked_t
14867 + * @i: required value
14868 + *
14869 + * Atomically sets the value of @v to @i.
14870 + */
14871 +static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
14872 +{
14873 + v->counter = i;
14874 +}
14875 +
14876 +/**
14877 * atomic_add - add integer to atomic variable
14878 * @i: integer value to add
14879 * @v: pointer of type atomic_t
14880 @@ -47,7 +70,29 @@ static inline void atomic_set(atomic_t *v, int i)
14881 */
14882 static inline void atomic_add(int i, atomic_t *v)
14883 {
14884 - asm volatile(LOCK_PREFIX "addl %1,%0"
14885 + asm volatile(LOCK_PREFIX "addl %1,%0\n"
14886 +
14887 +#ifdef CONFIG_PAX_REFCOUNT
14888 + "jno 0f\n"
14889 + LOCK_PREFIX "subl %1,%0\n"
14890 + "int $4\n0:\n"
14891 + _ASM_EXTABLE(0b, 0b)
14892 +#endif
14893 +
14894 + : "+m" (v->counter)
14895 + : "ir" (i));
14896 +}
14897 +
14898 +/**
14899 + * atomic_add_unchecked - add integer to atomic variable
14900 + * @i: integer value to add
14901 + * @v: pointer of type atomic_unchecked_t
14902 + *
14903 + * Atomically adds @i to @v.
14904 + */
14905 +static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
14906 +{
14907 + asm volatile(LOCK_PREFIX "addl %1,%0\n"
14908 : "+m" (v->counter)
14909 : "ir" (i));
14910 }
14911 @@ -61,7 +106,29 @@ static inline void atomic_add(int i, atomic_t *v)
14912 */
14913 static inline void atomic_sub(int i, atomic_t *v)
14914 {
14915 - asm volatile(LOCK_PREFIX "subl %1,%0"
14916 + asm volatile(LOCK_PREFIX "subl %1,%0\n"
14917 +
14918 +#ifdef CONFIG_PAX_REFCOUNT
14919 + "jno 0f\n"
14920 + LOCK_PREFIX "addl %1,%0\n"
14921 + "int $4\n0:\n"
14922 + _ASM_EXTABLE(0b, 0b)
14923 +#endif
14924 +
14925 + : "+m" (v->counter)
14926 + : "ir" (i));
14927 +}
14928 +
14929 +/**
14930 + * atomic_sub_unchecked - subtract integer from atomic variable
14931 + * @i: integer value to subtract
14932 + * @v: pointer of type atomic_unchecked_t
14933 + *
14934 + * Atomically subtracts @i from @v.
14935 + */
14936 +static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
14937 +{
14938 + asm volatile(LOCK_PREFIX "subl %1,%0\n"
14939 : "+m" (v->counter)
14940 : "ir" (i));
14941 }
14942 @@ -77,7 +144,7 @@ static inline void atomic_sub(int i, atomic_t *v)
14943 */
14944 static inline int atomic_sub_and_test(int i, atomic_t *v)
14945 {
14946 - GEN_BINARY_RMWcc(LOCK_PREFIX "subl", v->counter, "er", i, "%0", "e");
14947 + GEN_BINARY_RMWcc(LOCK_PREFIX "subl", LOCK_PREFIX "addl", v->counter, "er", i, "%0", "e");
14948 }
14949
14950 /**
14951 @@ -88,7 +155,27 @@ static inline int atomic_sub_and_test(int i, atomic_t *v)
14952 */
14953 static inline void atomic_inc(atomic_t *v)
14954 {
14955 - asm volatile(LOCK_PREFIX "incl %0"
14956 + asm volatile(LOCK_PREFIX "incl %0\n"
14957 +
14958 +#ifdef CONFIG_PAX_REFCOUNT
14959 + "jno 0f\n"
14960 + LOCK_PREFIX "decl %0\n"
14961 + "int $4\n0:\n"
14962 + _ASM_EXTABLE(0b, 0b)
14963 +#endif
14964 +
14965 + : "+m" (v->counter));
14966 +}
14967 +
14968 +/**
14969 + * atomic_inc_unchecked - increment atomic variable
14970 + * @v: pointer of type atomic_unchecked_t
14971 + *
14972 + * Atomically increments @v by 1.
14973 + */
14974 +static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
14975 +{
14976 + asm volatile(LOCK_PREFIX "incl %0\n"
14977 : "+m" (v->counter));
14978 }
14979
14980 @@ -100,7 +187,27 @@ static inline void atomic_inc(atomic_t *v)
14981 */
14982 static inline void atomic_dec(atomic_t *v)
14983 {
14984 - asm volatile(LOCK_PREFIX "decl %0"
14985 + asm volatile(LOCK_PREFIX "decl %0\n"
14986 +
14987 +#ifdef CONFIG_PAX_REFCOUNT
14988 + "jno 0f\n"
14989 + LOCK_PREFIX "incl %0\n"
14990 + "int $4\n0:\n"
14991 + _ASM_EXTABLE(0b, 0b)
14992 +#endif
14993 +
14994 + : "+m" (v->counter));
14995 +}
14996 +
14997 +/**
14998 + * atomic_dec_unchecked - decrement atomic variable
14999 + * @v: pointer of type atomic_unchecked_t
15000 + *
15001 + * Atomically decrements @v by 1.
15002 + */
15003 +static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
15004 +{
15005 + asm volatile(LOCK_PREFIX "decl %0\n"
15006 : "+m" (v->counter));
15007 }
15008
15009 @@ -114,7 +221,7 @@ static inline void atomic_dec(atomic_t *v)
15010 */
15011 static inline int atomic_dec_and_test(atomic_t *v)
15012 {
15013 - GEN_UNARY_RMWcc(LOCK_PREFIX "decl", v->counter, "%0", "e");
15014 + GEN_UNARY_RMWcc(LOCK_PREFIX "decl", LOCK_PREFIX "incl", v->counter, "%0", "e");
15015 }
15016
15017 /**
15018 @@ -127,7 +234,20 @@ static inline int atomic_dec_and_test(atomic_t *v)
15019 */
15020 static inline int atomic_inc_and_test(atomic_t *v)
15021 {
15022 - GEN_UNARY_RMWcc(LOCK_PREFIX "incl", v->counter, "%0", "e");
15023 + GEN_UNARY_RMWcc(LOCK_PREFIX "incl", LOCK_PREFIX "decl", v->counter, "%0", "e");
15024 +}
15025 +
15026 +/**
15027 + * atomic_inc_and_test_unchecked - increment and test
15028 + * @v: pointer of type atomic_unchecked_t
15029 + *
15030 + * Atomically increments @v by 1
15031 + * and returns true if the result is zero, or false for all
15032 + * other cases.
15033 + */
15034 +static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
15035 +{
15036 + GEN_UNARY_RMWcc_unchecked(LOCK_PREFIX "incl", v->counter, "%0", "e");
15037 }
15038
15039 /**
15040 @@ -141,7 +261,7 @@ static inline int atomic_inc_and_test(atomic_t *v)
15041 */
15042 static inline int atomic_add_negative(int i, atomic_t *v)
15043 {
15044 - GEN_BINARY_RMWcc(LOCK_PREFIX "addl", v->counter, "er", i, "%0", "s");
15045 + GEN_BINARY_RMWcc(LOCK_PREFIX "addl", LOCK_PREFIX "subl", v->counter, "er", i, "%0", "s");
15046 }
15047
15048 /**
15049 @@ -153,6 +273,18 @@ static inline int atomic_add_negative(int i, atomic_t *v)
15050 */
15051 static inline int atomic_add_return(int i, atomic_t *v)
15052 {
15053 + return i + xadd_check_overflow(&v->counter, i);
15054 +}
15055 +
15056 +/**
15057 + * atomic_add_return_unchecked - add integer and return
15058 + * @i: integer value to add
15059 + * @v: pointer of type atomic_unchecked_t
15060 + *
15061 + * Atomically adds @i to @v and returns @i + @v
15062 + */
15063 +static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
15064 +{
15065 return i + xadd(&v->counter, i);
15066 }
15067
15068 @@ -169,9 +301,18 @@ static inline int atomic_sub_return(int i, atomic_t *v)
15069 }
15070
15071 #define atomic_inc_return(v) (atomic_add_return(1, v))
15072 +static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
15073 +{
15074 + return atomic_add_return_unchecked(1, v);
15075 +}
15076 #define atomic_dec_return(v) (atomic_sub_return(1, v))
15077
15078 -static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
15079 +static inline int __intentional_overflow(-1) atomic_cmpxchg(atomic_t *v, int old, int new)
15080 +{
15081 + return cmpxchg(&v->counter, old, new);
15082 +}
15083 +
15084 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
15085 {
15086 return cmpxchg(&v->counter, old, new);
15087 }
15088 @@ -181,6 +322,11 @@ static inline int atomic_xchg(atomic_t *v, int new)
15089 return xchg(&v->counter, new);
15090 }
15091
15092 +static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
15093 +{
15094 + return xchg(&v->counter, new);
15095 +}
15096 +
15097 /**
15098 * __atomic_add_unless - add unless the number is already a given value
15099 * @v: pointer of type atomic_t
15100 @@ -190,14 +336,27 @@ static inline int atomic_xchg(atomic_t *v, int new)
15101 * Atomically adds @a to @v, so long as @v was not already @u.
15102 * Returns the old value of @v.
15103 */
15104 -static inline int __atomic_add_unless(atomic_t *v, int a, int u)
15105 +static inline int __intentional_overflow(-1) __atomic_add_unless(atomic_t *v, int a, int u)
15106 {
15107 - int c, old;
15108 + int c, old, new;
15109 c = atomic_read(v);
15110 for (;;) {
15111 - if (unlikely(c == (u)))
15112 + if (unlikely(c == u))
15113 break;
15114 - old = atomic_cmpxchg((v), c, c + (a));
15115 +
15116 + asm volatile("addl %2,%0\n"
15117 +
15118 +#ifdef CONFIG_PAX_REFCOUNT
15119 + "jno 0f\n"
15120 + "subl %2,%0\n"
15121 + "int $4\n0:\n"
15122 + _ASM_EXTABLE(0b, 0b)
15123 +#endif
15124 +
15125 + : "=r" (new)
15126 + : "0" (c), "ir" (a));
15127 +
15128 + old = atomic_cmpxchg(v, c, new);
15129 if (likely(old == c))
15130 break;
15131 c = old;
15132 @@ -206,6 +365,49 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
15133 }
15134
15135 /**
15136 + * atomic_inc_not_zero_hint - increment if not null
15137 + * @v: pointer of type atomic_t
15138 + * @hint: probable value of the atomic before the increment
15139 + *
15140 + * This version of atomic_inc_not_zero() gives a hint of probable
15141 + * value of the atomic. This helps processor to not read the memory
15142 + * before doing the atomic read/modify/write cycle, lowering
15143 + * number of bus transactions on some arches.
15144 + *
15145 + * Returns: 0 if increment was not done, 1 otherwise.
15146 + */
15147 +#define atomic_inc_not_zero_hint atomic_inc_not_zero_hint
15148 +static inline int atomic_inc_not_zero_hint(atomic_t *v, int hint)
15149 +{
15150 + int val, c = hint, new;
15151 +
15152 + /* sanity test, should be removed by compiler if hint is a constant */
15153 + if (!hint)
15154 + return __atomic_add_unless(v, 1, 0);
15155 +
15156 + do {
15157 + asm volatile("incl %0\n"
15158 +
15159 +#ifdef CONFIG_PAX_REFCOUNT
15160 + "jno 0f\n"
15161 + "decl %0\n"
15162 + "int $4\n0:\n"
15163 + _ASM_EXTABLE(0b, 0b)
15164 +#endif
15165 +
15166 + : "=r" (new)
15167 + : "0" (c));
15168 +
15169 + val = atomic_cmpxchg(v, c, new);
15170 + if (val == c)
15171 + return 1;
15172 + c = val;
15173 + } while (c);
15174 +
15175 + return 0;
15176 +}
15177 +
15178 +/**
15179 * atomic_inc_short - increment of a short integer
15180 * @v: pointer to type int
15181 *
15182 @@ -234,14 +436,37 @@ static inline void atomic_or_long(unsigned long *v1, unsigned long v2)
15183 #endif
15184
15185 /* These are x86-specific, used by some header files */
15186 -#define atomic_clear_mask(mask, addr) \
15187 - asm volatile(LOCK_PREFIX "andl %0,%1" \
15188 - : : "r" (~(mask)), "m" (*(addr)) : "memory")
15189 +static inline void atomic_clear_mask(unsigned int mask, atomic_t *v)
15190 +{
15191 + asm volatile(LOCK_PREFIX "andl %1,%0"
15192 + : "+m" (v->counter)
15193 + : "r" (~(mask))
15194 + : "memory");
15195 +}
15196
15197 -#define atomic_set_mask(mask, addr) \
15198 - asm volatile(LOCK_PREFIX "orl %0,%1" \
15199 - : : "r" ((unsigned)(mask)), "m" (*(addr)) \
15200 - : "memory")
15201 +static inline void atomic_clear_mask_unchecked(unsigned int mask, atomic_unchecked_t *v)
15202 +{
15203 + asm volatile(LOCK_PREFIX "andl %1,%0"
15204 + : "+m" (v->counter)
15205 + : "r" (~(mask))
15206 + : "memory");
15207 +}
15208 +
15209 +static inline void atomic_set_mask(unsigned int mask, atomic_t *v)
15210 +{
15211 + asm volatile(LOCK_PREFIX "orl %1,%0"
15212 + : "+m" (v->counter)
15213 + : "r" (mask)
15214 + : "memory");
15215 +}
15216 +
15217 +static inline void atomic_set_mask_unchecked(unsigned int mask, atomic_unchecked_t *v)
15218 +{
15219 + asm volatile(LOCK_PREFIX "orl %1,%0"
15220 + : "+m" (v->counter)
15221 + : "r" (mask)
15222 + : "memory");
15223 +}
15224
15225 /* Atomic operations are already serializing on x86 */
15226 #define smp_mb__before_atomic_dec() barrier()
15227 diff --git a/arch/x86/include/asm/atomic64_32.h b/arch/x86/include/asm/atomic64_32.h
15228 index b154de7..bf18a5a 100644
15229 --- a/arch/x86/include/asm/atomic64_32.h
15230 +++ b/arch/x86/include/asm/atomic64_32.h
15231 @@ -12,6 +12,14 @@ typedef struct {
15232 u64 __aligned(8) counter;
15233 } atomic64_t;
15234
15235 +#ifdef CONFIG_PAX_REFCOUNT
15236 +typedef struct {
15237 + u64 __aligned(8) counter;
15238 +} atomic64_unchecked_t;
15239 +#else
15240 +typedef atomic64_t atomic64_unchecked_t;
15241 +#endif
15242 +
15243 #define ATOMIC64_INIT(val) { (val) }
15244
15245 #define __ATOMIC64_DECL(sym) void atomic64_##sym(atomic64_t *, ...)
15246 @@ -37,21 +45,31 @@ typedef struct {
15247 ATOMIC64_DECL_ONE(sym##_386)
15248
15249 ATOMIC64_DECL_ONE(add_386);
15250 +ATOMIC64_DECL_ONE(add_unchecked_386);
15251 ATOMIC64_DECL_ONE(sub_386);
15252 +ATOMIC64_DECL_ONE(sub_unchecked_386);
15253 ATOMIC64_DECL_ONE(inc_386);
15254 +ATOMIC64_DECL_ONE(inc_unchecked_386);
15255 ATOMIC64_DECL_ONE(dec_386);
15256 +ATOMIC64_DECL_ONE(dec_unchecked_386);
15257 #endif
15258
15259 #define alternative_atomic64(f, out, in...) \
15260 __alternative_atomic64(f, f, ASM_OUTPUT2(out), ## in)
15261
15262 ATOMIC64_DECL(read);
15263 +ATOMIC64_DECL(read_unchecked);
15264 ATOMIC64_DECL(set);
15265 +ATOMIC64_DECL(set_unchecked);
15266 ATOMIC64_DECL(xchg);
15267 ATOMIC64_DECL(add_return);
15268 +ATOMIC64_DECL(add_return_unchecked);
15269 ATOMIC64_DECL(sub_return);
15270 +ATOMIC64_DECL(sub_return_unchecked);
15271 ATOMIC64_DECL(inc_return);
15272 +ATOMIC64_DECL(inc_return_unchecked);
15273 ATOMIC64_DECL(dec_return);
15274 +ATOMIC64_DECL(dec_return_unchecked);
15275 ATOMIC64_DECL(dec_if_positive);
15276 ATOMIC64_DECL(inc_not_zero);
15277 ATOMIC64_DECL(add_unless);
15278 @@ -77,6 +95,21 @@ static inline long long atomic64_cmpxchg(atomic64_t *v, long long o, long long n
15279 }
15280
15281 /**
15282 + * atomic64_cmpxchg_unchecked - cmpxchg atomic64 variable
15283 + * @p: pointer to type atomic64_unchecked_t
15284 + * @o: expected value
15285 + * @n: new value
15286 + *
15287 + * Atomically sets @v to @n if it was equal to @o and returns
15288 + * the old value.
15289 + */
15290 +
15291 +static inline long long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long long o, long long n)
15292 +{
15293 + return cmpxchg64(&v->counter, o, n);
15294 +}
15295 +
15296 +/**
15297 * atomic64_xchg - xchg atomic64 variable
15298 * @v: pointer to type atomic64_t
15299 * @n: value to assign
15300 @@ -112,6 +145,22 @@ static inline void atomic64_set(atomic64_t *v, long long i)
15301 }
15302
15303 /**
15304 + * atomic64_set_unchecked - set atomic64 variable
15305 + * @v: pointer to type atomic64_unchecked_t
15306 + * @n: value to assign
15307 + *
15308 + * Atomically sets the value of @v to @n.
15309 + */
15310 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long long i)
15311 +{
15312 + unsigned high = (unsigned)(i >> 32);
15313 + unsigned low = (unsigned)i;
15314 + alternative_atomic64(set, /* no output */,
15315 + "S" (v), "b" (low), "c" (high)
15316 + : "eax", "edx", "memory");
15317 +}
15318 +
15319 +/**
15320 * atomic64_read - read atomic64 variable
15321 * @v: pointer to type atomic64_t
15322 *
15323 @@ -125,6 +174,19 @@ static inline long long atomic64_read(const atomic64_t *v)
15324 }
15325
15326 /**
15327 + * atomic64_read_unchecked - read atomic64 variable
15328 + * @v: pointer to type atomic64_unchecked_t
15329 + *
15330 + * Atomically reads the value of @v and returns it.
15331 + */
15332 +static inline long long __intentional_overflow(-1) atomic64_read_unchecked(atomic64_unchecked_t *v)
15333 +{
15334 + long long r;
15335 + alternative_atomic64(read, "=&A" (r), "c" (v) : "memory");
15336 + return r;
15337 + }
15338 +
15339 +/**
15340 * atomic64_add_return - add and return
15341 * @i: integer value to add
15342 * @v: pointer to type atomic64_t
15343 @@ -139,6 +201,21 @@ static inline long long atomic64_add_return(long long i, atomic64_t *v)
15344 return i;
15345 }
15346
15347 +/**
15348 + * atomic64_add_return_unchecked - add and return
15349 + * @i: integer value to add
15350 + * @v: pointer to type atomic64_unchecked_t
15351 + *
15352 + * Atomically adds @i to @v and returns @i + *@v
15353 + */
15354 +static inline long long atomic64_add_return_unchecked(long long i, atomic64_unchecked_t *v)
15355 +{
15356 + alternative_atomic64(add_return_unchecked,
15357 + ASM_OUTPUT2("+A" (i), "+c" (v)),
15358 + ASM_NO_INPUT_CLOBBER("memory"));
15359 + return i;
15360 +}
15361 +
15362 /*
15363 * Other variants with different arithmetic operators:
15364 */
15365 @@ -158,6 +235,14 @@ static inline long long atomic64_inc_return(atomic64_t *v)
15366 return a;
15367 }
15368
15369 +static inline long long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
15370 +{
15371 + long long a;
15372 + alternative_atomic64(inc_return_unchecked, "=&A" (a),
15373 + "S" (v) : "memory", "ecx");
15374 + return a;
15375 +}
15376 +
15377 static inline long long atomic64_dec_return(atomic64_t *v)
15378 {
15379 long long a;
15380 @@ -182,6 +267,21 @@ static inline long long atomic64_add(long long i, atomic64_t *v)
15381 }
15382
15383 /**
15384 + * atomic64_add_unchecked - add integer to atomic64 variable
15385 + * @i: integer value to add
15386 + * @v: pointer to type atomic64_unchecked_t
15387 + *
15388 + * Atomically adds @i to @v.
15389 + */
15390 +static inline long long atomic64_add_unchecked(long long i, atomic64_unchecked_t *v)
15391 +{
15392 + __alternative_atomic64(add_unchecked, add_return_unchecked,
15393 + ASM_OUTPUT2("+A" (i), "+c" (v)),
15394 + ASM_NO_INPUT_CLOBBER("memory"));
15395 + return i;
15396 +}
15397 +
15398 +/**
15399 * atomic64_sub - subtract the atomic64 variable
15400 * @i: integer value to subtract
15401 * @v: pointer to type atomic64_t
15402 diff --git a/arch/x86/include/asm/atomic64_64.h b/arch/x86/include/asm/atomic64_64.h
15403 index 46e9052..ae45136 100644
15404 --- a/arch/x86/include/asm/atomic64_64.h
15405 +++ b/arch/x86/include/asm/atomic64_64.h
15406 @@ -18,7 +18,19 @@
15407 */
15408 static inline long atomic64_read(const atomic64_t *v)
15409 {
15410 - return (*(volatile long *)&(v)->counter);
15411 + return (*(volatile const long *)&(v)->counter);
15412 +}
15413 +
15414 +/**
15415 + * atomic64_read_unchecked - read atomic64 variable
15416 + * @v: pointer of type atomic64_unchecked_t
15417 + *
15418 + * Atomically reads the value of @v.
15419 + * Doesn't imply a read memory barrier.
15420 + */
15421 +static inline long __intentional_overflow(-1) atomic64_read_unchecked(const atomic64_unchecked_t *v)
15422 +{
15423 + return (*(volatile const long *)&(v)->counter);
15424 }
15425
15426 /**
15427 @@ -34,6 +46,18 @@ static inline void atomic64_set(atomic64_t *v, long i)
15428 }
15429
15430 /**
15431 + * atomic64_set_unchecked - set atomic64 variable
15432 + * @v: pointer to type atomic64_unchecked_t
15433 + * @i: required value
15434 + *
15435 + * Atomically sets the value of @v to @i.
15436 + */
15437 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
15438 +{
15439 + v->counter = i;
15440 +}
15441 +
15442 +/**
15443 * atomic64_add - add integer to atomic64 variable
15444 * @i: integer value to add
15445 * @v: pointer to type atomic64_t
15446 @@ -42,6 +66,28 @@ static inline void atomic64_set(atomic64_t *v, long i)
15447 */
15448 static inline void atomic64_add(long i, atomic64_t *v)
15449 {
15450 + asm volatile(LOCK_PREFIX "addq %1,%0\n"
15451 +
15452 +#ifdef CONFIG_PAX_REFCOUNT
15453 + "jno 0f\n"
15454 + LOCK_PREFIX "subq %1,%0\n"
15455 + "int $4\n0:\n"
15456 + _ASM_EXTABLE(0b, 0b)
15457 +#endif
15458 +
15459 + : "=m" (v->counter)
15460 + : "er" (i), "m" (v->counter));
15461 +}
15462 +
15463 +/**
15464 + * atomic64_add_unchecked - add integer to atomic64 variable
15465 + * @i: integer value to add
15466 + * @v: pointer to type atomic64_unchecked_t
15467 + *
15468 + * Atomically adds @i to @v.
15469 + */
15470 +static inline void atomic64_add_unchecked(long i, atomic64_unchecked_t *v)
15471 +{
15472 asm volatile(LOCK_PREFIX "addq %1,%0"
15473 : "=m" (v->counter)
15474 : "er" (i), "m" (v->counter));
15475 @@ -56,7 +102,29 @@ static inline void atomic64_add(long i, atomic64_t *v)
15476 */
15477 static inline void atomic64_sub(long i, atomic64_t *v)
15478 {
15479 - asm volatile(LOCK_PREFIX "subq %1,%0"
15480 + asm volatile(LOCK_PREFIX "subq %1,%0\n"
15481 +
15482 +#ifdef CONFIG_PAX_REFCOUNT
15483 + "jno 0f\n"
15484 + LOCK_PREFIX "addq %1,%0\n"
15485 + "int $4\n0:\n"
15486 + _ASM_EXTABLE(0b, 0b)
15487 +#endif
15488 +
15489 + : "=m" (v->counter)
15490 + : "er" (i), "m" (v->counter));
15491 +}
15492 +
15493 +/**
15494 + * atomic64_sub_unchecked - subtract the atomic64 variable
15495 + * @i: integer value to subtract
15496 + * @v: pointer to type atomic64_unchecked_t
15497 + *
15498 + * Atomically subtracts @i from @v.
15499 + */
15500 +static inline void atomic64_sub_unchecked(long i, atomic64_unchecked_t *v)
15501 +{
15502 + asm volatile(LOCK_PREFIX "subq %1,%0\n"
15503 : "=m" (v->counter)
15504 : "er" (i), "m" (v->counter));
15505 }
15506 @@ -72,7 +140,7 @@ static inline void atomic64_sub(long i, atomic64_t *v)
15507 */
15508 static inline int atomic64_sub_and_test(long i, atomic64_t *v)
15509 {
15510 - GEN_BINARY_RMWcc(LOCK_PREFIX "subq", v->counter, "er", i, "%0", "e");
15511 + GEN_BINARY_RMWcc(LOCK_PREFIX "subq", LOCK_PREFIX "addq", v->counter, "er", i, "%0", "e");
15512 }
15513
15514 /**
15515 @@ -83,6 +151,27 @@ static inline int atomic64_sub_and_test(long i, atomic64_t *v)
15516 */
15517 static inline void atomic64_inc(atomic64_t *v)
15518 {
15519 + asm volatile(LOCK_PREFIX "incq %0\n"
15520 +
15521 +#ifdef CONFIG_PAX_REFCOUNT
15522 + "jno 0f\n"
15523 + LOCK_PREFIX "decq %0\n"
15524 + "int $4\n0:\n"
15525 + _ASM_EXTABLE(0b, 0b)
15526 +#endif
15527 +
15528 + : "=m" (v->counter)
15529 + : "m" (v->counter));
15530 +}
15531 +
15532 +/**
15533 + * atomic64_inc_unchecked - increment atomic64 variable
15534 + * @v: pointer to type atomic64_unchecked_t
15535 + *
15536 + * Atomically increments @v by 1.
15537 + */
15538 +static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
15539 +{
15540 asm volatile(LOCK_PREFIX "incq %0"
15541 : "=m" (v->counter)
15542 : "m" (v->counter));
15543 @@ -96,7 +185,28 @@ static inline void atomic64_inc(atomic64_t *v)
15544 */
15545 static inline void atomic64_dec(atomic64_t *v)
15546 {
15547 - asm volatile(LOCK_PREFIX "decq %0"
15548 + asm volatile(LOCK_PREFIX "decq %0\n"
15549 +
15550 +#ifdef CONFIG_PAX_REFCOUNT
15551 + "jno 0f\n"
15552 + LOCK_PREFIX "incq %0\n"
15553 + "int $4\n0:\n"
15554 + _ASM_EXTABLE(0b, 0b)
15555 +#endif
15556 +
15557 + : "=m" (v->counter)
15558 + : "m" (v->counter));
15559 +}
15560 +
15561 +/**
15562 + * atomic64_dec_unchecked - decrement atomic64 variable
15563 + * @v: pointer to type atomic64_t
15564 + *
15565 + * Atomically decrements @v by 1.
15566 + */
15567 +static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
15568 +{
15569 + asm volatile(LOCK_PREFIX "decq %0\n"
15570 : "=m" (v->counter)
15571 : "m" (v->counter));
15572 }
15573 @@ -111,7 +221,7 @@ static inline void atomic64_dec(atomic64_t *v)
15574 */
15575 static inline int atomic64_dec_and_test(atomic64_t *v)
15576 {
15577 - GEN_UNARY_RMWcc(LOCK_PREFIX "decq", v->counter, "%0", "e");
15578 + GEN_UNARY_RMWcc(LOCK_PREFIX "decq", LOCK_PREFIX "incq", v->counter, "%0", "e");
15579 }
15580
15581 /**
15582 @@ -124,7 +234,7 @@ static inline int atomic64_dec_and_test(atomic64_t *v)
15583 */
15584 static inline int atomic64_inc_and_test(atomic64_t *v)
15585 {
15586 - GEN_UNARY_RMWcc(LOCK_PREFIX "incq", v->counter, "%0", "e");
15587 + GEN_UNARY_RMWcc(LOCK_PREFIX "incq", LOCK_PREFIX "decq", v->counter, "%0", "e");
15588 }
15589
15590 /**
15591 @@ -138,7 +248,7 @@ static inline int atomic64_inc_and_test(atomic64_t *v)
15592 */
15593 static inline int atomic64_add_negative(long i, atomic64_t *v)
15594 {
15595 - GEN_BINARY_RMWcc(LOCK_PREFIX "addq", v->counter, "er", i, "%0", "s");
15596 + GEN_BINARY_RMWcc(LOCK_PREFIX "addq", LOCK_PREFIX "subq", v->counter, "er", i, "%0", "s");
15597 }
15598
15599 /**
15600 @@ -150,6 +260,18 @@ static inline int atomic64_add_negative(long i, atomic64_t *v)
15601 */
15602 static inline long atomic64_add_return(long i, atomic64_t *v)
15603 {
15604 + return i + xadd_check_overflow(&v->counter, i);
15605 +}
15606 +
15607 +/**
15608 + * atomic64_add_return_unchecked - add and return
15609 + * @i: integer value to add
15610 + * @v: pointer to type atomic64_unchecked_t
15611 + *
15612 + * Atomically adds @i to @v and returns @i + @v
15613 + */
15614 +static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
15615 +{
15616 return i + xadd(&v->counter, i);
15617 }
15618
15619 @@ -159,6 +281,10 @@ static inline long atomic64_sub_return(long i, atomic64_t *v)
15620 }
15621
15622 #define atomic64_inc_return(v) (atomic64_add_return(1, (v)))
15623 +static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
15624 +{
15625 + return atomic64_add_return_unchecked(1, v);
15626 +}
15627 #define atomic64_dec_return(v) (atomic64_sub_return(1, (v)))
15628
15629 static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
15630 @@ -166,6 +292,11 @@ static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
15631 return cmpxchg(&v->counter, old, new);
15632 }
15633
15634 +static inline long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long old, long new)
15635 +{
15636 + return cmpxchg(&v->counter, old, new);
15637 +}
15638 +
15639 static inline long atomic64_xchg(atomic64_t *v, long new)
15640 {
15641 return xchg(&v->counter, new);
15642 @@ -182,17 +313,30 @@ static inline long atomic64_xchg(atomic64_t *v, long new)
15643 */
15644 static inline int atomic64_add_unless(atomic64_t *v, long a, long u)
15645 {
15646 - long c, old;
15647 + long c, old, new;
15648 c = atomic64_read(v);
15649 for (;;) {
15650 - if (unlikely(c == (u)))
15651 + if (unlikely(c == u))
15652 break;
15653 - old = atomic64_cmpxchg((v), c, c + (a));
15654 +
15655 + asm volatile("add %2,%0\n"
15656 +
15657 +#ifdef CONFIG_PAX_REFCOUNT
15658 + "jno 0f\n"
15659 + "sub %2,%0\n"
15660 + "int $4\n0:\n"
15661 + _ASM_EXTABLE(0b, 0b)
15662 +#endif
15663 +
15664 + : "=r" (new)
15665 + : "0" (c), "ir" (a));
15666 +
15667 + old = atomic64_cmpxchg(v, c, new);
15668 if (likely(old == c))
15669 break;
15670 c = old;
15671 }
15672 - return c != (u);
15673 + return c != u;
15674 }
15675
15676 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
15677 diff --git a/arch/x86/include/asm/bitops.h b/arch/x86/include/asm/bitops.h
15678 index 9fc1af7..fc71228 100644
15679 --- a/arch/x86/include/asm/bitops.h
15680 +++ b/arch/x86/include/asm/bitops.h
15681 @@ -49,7 +49,7 @@
15682 * a mask operation on a byte.
15683 */
15684 #define IS_IMMEDIATE(nr) (__builtin_constant_p(nr))
15685 -#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((void *)(addr) + ((nr)>>3))
15686 +#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((volatile void *)(addr) + ((nr)>>3))
15687 #define CONST_MASK(nr) (1 << ((nr) & 7))
15688
15689 /**
15690 @@ -205,7 +205,7 @@ static inline void change_bit(long nr, volatile unsigned long *addr)
15691 */
15692 static inline int test_and_set_bit(long nr, volatile unsigned long *addr)
15693 {
15694 - GEN_BINARY_RMWcc(LOCK_PREFIX "bts", *addr, "Ir", nr, "%0", "c");
15695 + GEN_BINARY_RMWcc_unchecked(LOCK_PREFIX "bts", *addr, "Ir", nr, "%0", "c");
15696 }
15697
15698 /**
15699 @@ -251,7 +251,7 @@ static inline int __test_and_set_bit(long nr, volatile unsigned long *addr)
15700 */
15701 static inline int test_and_clear_bit(long nr, volatile unsigned long *addr)
15702 {
15703 - GEN_BINARY_RMWcc(LOCK_PREFIX "btr", *addr, "Ir", nr, "%0", "c");
15704 + GEN_BINARY_RMWcc_unchecked(LOCK_PREFIX "btr", *addr, "Ir", nr, "%0", "c");
15705 }
15706
15707 /**
15708 @@ -304,7 +304,7 @@ static inline int __test_and_change_bit(long nr, volatile unsigned long *addr)
15709 */
15710 static inline int test_and_change_bit(long nr, volatile unsigned long *addr)
15711 {
15712 - GEN_BINARY_RMWcc(LOCK_PREFIX "btc", *addr, "Ir", nr, "%0", "c");
15713 + GEN_BINARY_RMWcc_unchecked(LOCK_PREFIX "btc", *addr, "Ir", nr, "%0", "c");
15714 }
15715
15716 static __always_inline int constant_test_bit(long nr, const volatile unsigned long *addr)
15717 @@ -345,7 +345,7 @@ static int test_bit(int nr, const volatile unsigned long *addr);
15718 *
15719 * Undefined if no bit exists, so code should check against 0 first.
15720 */
15721 -static inline unsigned long __ffs(unsigned long word)
15722 +static inline unsigned long __intentional_overflow(-1) __ffs(unsigned long word)
15723 {
15724 asm("rep; bsf %1,%0"
15725 : "=r" (word)
15726 @@ -359,7 +359,7 @@ static inline unsigned long __ffs(unsigned long word)
15727 *
15728 * Undefined if no zero exists, so code should check against ~0UL first.
15729 */
15730 -static inline unsigned long ffz(unsigned long word)
15731 +static inline unsigned long __intentional_overflow(-1) ffz(unsigned long word)
15732 {
15733 asm("rep; bsf %1,%0"
15734 : "=r" (word)
15735 @@ -373,7 +373,7 @@ static inline unsigned long ffz(unsigned long word)
15736 *
15737 * Undefined if no set bit exists, so code should check against 0 first.
15738 */
15739 -static inline unsigned long __fls(unsigned long word)
15740 +static inline unsigned long __intentional_overflow(-1) __fls(unsigned long word)
15741 {
15742 asm("bsr %1,%0"
15743 : "=r" (word)
15744 @@ -436,7 +436,7 @@ static inline int ffs(int x)
15745 * set bit if value is nonzero. The last (most significant) bit is
15746 * at position 32.
15747 */
15748 -static inline int fls(int x)
15749 +static inline int __intentional_overflow(-1) fls(int x)
15750 {
15751 int r;
15752
15753 @@ -478,7 +478,7 @@ static inline int fls(int x)
15754 * at position 64.
15755 */
15756 #ifdef CONFIG_X86_64
15757 -static __always_inline int fls64(__u64 x)
15758 +static __always_inline long fls64(__u64 x)
15759 {
15760 int bitpos = -1;
15761 /*
15762 diff --git a/arch/x86/include/asm/boot.h b/arch/x86/include/asm/boot.h
15763 index 4fa687a..60f2d39 100644
15764 --- a/arch/x86/include/asm/boot.h
15765 +++ b/arch/x86/include/asm/boot.h
15766 @@ -6,10 +6,15 @@
15767 #include <uapi/asm/boot.h>
15768
15769 /* Physical address where kernel should be loaded. */
15770 -#define LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
15771 +#define ____LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
15772 + (CONFIG_PHYSICAL_ALIGN - 1)) \
15773 & ~(CONFIG_PHYSICAL_ALIGN - 1))
15774
15775 +#ifndef __ASSEMBLY__
15776 +extern unsigned char __LOAD_PHYSICAL_ADDR[];
15777 +#define LOAD_PHYSICAL_ADDR ((unsigned long)__LOAD_PHYSICAL_ADDR)
15778 +#endif
15779 +
15780 /* Minimum kernel alignment, as a power of two */
15781 #ifdef CONFIG_X86_64
15782 #define MIN_KERNEL_ALIGN_LG2 PMD_SHIFT
15783 diff --git a/arch/x86/include/asm/cache.h b/arch/x86/include/asm/cache.h
15784 index 48f99f1..d78ebf9 100644
15785 --- a/arch/x86/include/asm/cache.h
15786 +++ b/arch/x86/include/asm/cache.h
15787 @@ -5,12 +5,13 @@
15788
15789 /* L1 cache line size */
15790 #define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
15791 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
15792 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
15793
15794 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
15795 +#define __read_only __attribute__((__section__(".data..read_only")))
15796
15797 #define INTERNODE_CACHE_SHIFT CONFIG_X86_INTERNODE_CACHE_SHIFT
15798 -#define INTERNODE_CACHE_BYTES (1 << INTERNODE_CACHE_SHIFT)
15799 +#define INTERNODE_CACHE_BYTES (_AC(1,UL) << INTERNODE_CACHE_SHIFT)
15800
15801 #ifdef CONFIG_X86_VSMP
15802 #ifdef CONFIG_SMP
15803 diff --git a/arch/x86/include/asm/cacheflush.h b/arch/x86/include/asm/cacheflush.h
15804 index 9863ee3..4a1f8e1 100644
15805 --- a/arch/x86/include/asm/cacheflush.h
15806 +++ b/arch/x86/include/asm/cacheflush.h
15807 @@ -27,7 +27,7 @@ static inline unsigned long get_page_memtype(struct page *pg)
15808 unsigned long pg_flags = pg->flags & _PGMT_MASK;
15809
15810 if (pg_flags == _PGMT_DEFAULT)
15811 - return -1;
15812 + return ~0UL;
15813 else if (pg_flags == _PGMT_WC)
15814 return _PAGE_CACHE_WC;
15815 else if (pg_flags == _PGMT_UC_MINUS)
15816 diff --git a/arch/x86/include/asm/calling.h b/arch/x86/include/asm/calling.h
15817 index cb4c73b..c473c29 100644
15818 --- a/arch/x86/include/asm/calling.h
15819 +++ b/arch/x86/include/asm/calling.h
15820 @@ -82,103 +82,113 @@ For 32-bit we have the following conventions - kernel is built with
15821 #define RSP 152
15822 #define SS 160
15823
15824 -#define ARGOFFSET R11
15825 -#define SWFRAME ORIG_RAX
15826 +#define ARGOFFSET R15
15827
15828 .macro SAVE_ARGS addskip=0, save_rcx=1, save_r891011=1
15829 - subq $9*8+\addskip, %rsp
15830 - CFI_ADJUST_CFA_OFFSET 9*8+\addskip
15831 - movq_cfi rdi, 8*8
15832 - movq_cfi rsi, 7*8
15833 - movq_cfi rdx, 6*8
15834 + subq $ORIG_RAX-ARGOFFSET+\addskip, %rsp
15835 + CFI_ADJUST_CFA_OFFSET ORIG_RAX-ARGOFFSET+\addskip
15836 + movq_cfi rdi, RDI
15837 + movq_cfi rsi, RSI
15838 + movq_cfi rdx, RDX
15839
15840 .if \save_rcx
15841 - movq_cfi rcx, 5*8
15842 + movq_cfi rcx, RCX
15843 .endif
15844
15845 - movq_cfi rax, 4*8
15846 + movq_cfi rax, RAX
15847
15848 .if \save_r891011
15849 - movq_cfi r8, 3*8
15850 - movq_cfi r9, 2*8
15851 - movq_cfi r10, 1*8
15852 - movq_cfi r11, 0*8
15853 + movq_cfi r8, R8
15854 + movq_cfi r9, R9
15855 + movq_cfi r10, R10
15856 + movq_cfi r11, R11
15857 .endif
15858
15859 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
15860 + movq_cfi r12, R12
15861 +#endif
15862 +
15863 .endm
15864
15865 -#define ARG_SKIP (9*8)
15866 +#define ARG_SKIP ORIG_RAX
15867
15868 .macro RESTORE_ARGS rstor_rax=1, addskip=0, rstor_rcx=1, rstor_r11=1, \
15869 rstor_r8910=1, rstor_rdx=1
15870 +
15871 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
15872 + movq_cfi_restore R12, r12
15873 +#endif
15874 +
15875 .if \rstor_r11
15876 - movq_cfi_restore 0*8, r11
15877 + movq_cfi_restore R11, r11
15878 .endif
15879
15880 .if \rstor_r8910
15881 - movq_cfi_restore 1*8, r10
15882 - movq_cfi_restore 2*8, r9
15883 - movq_cfi_restore 3*8, r8
15884 + movq_cfi_restore R10, r10
15885 + movq_cfi_restore R9, r9
15886 + movq_cfi_restore R8, r8
15887 .endif
15888
15889 .if \rstor_rax
15890 - movq_cfi_restore 4*8, rax
15891 + movq_cfi_restore RAX, rax
15892 .endif
15893
15894 .if \rstor_rcx
15895 - movq_cfi_restore 5*8, rcx
15896 + movq_cfi_restore RCX, rcx
15897 .endif
15898
15899 .if \rstor_rdx
15900 - movq_cfi_restore 6*8, rdx
15901 + movq_cfi_restore RDX, rdx
15902 .endif
15903
15904 - movq_cfi_restore 7*8, rsi
15905 - movq_cfi_restore 8*8, rdi
15906 + movq_cfi_restore RSI, rsi
15907 + movq_cfi_restore RDI, rdi
15908
15909 - .if ARG_SKIP+\addskip > 0
15910 - addq $ARG_SKIP+\addskip, %rsp
15911 - CFI_ADJUST_CFA_OFFSET -(ARG_SKIP+\addskip)
15912 + .if ORIG_RAX+\addskip > 0
15913 + addq $ORIG_RAX+\addskip, %rsp
15914 + CFI_ADJUST_CFA_OFFSET -(ORIG_RAX+\addskip)
15915 .endif
15916 .endm
15917
15918 - .macro LOAD_ARGS offset, skiprax=0
15919 - movq \offset(%rsp), %r11
15920 - movq \offset+8(%rsp), %r10
15921 - movq \offset+16(%rsp), %r9
15922 - movq \offset+24(%rsp), %r8
15923 - movq \offset+40(%rsp), %rcx
15924 - movq \offset+48(%rsp), %rdx
15925 - movq \offset+56(%rsp), %rsi
15926 - movq \offset+64(%rsp), %rdi
15927 + .macro LOAD_ARGS skiprax=0
15928 + movq R11(%rsp), %r11
15929 + movq R10(%rsp), %r10
15930 + movq R9(%rsp), %r9
15931 + movq R8(%rsp), %r8
15932 + movq RCX(%rsp), %rcx
15933 + movq RDX(%rsp), %rdx
15934 + movq RSI(%rsp), %rsi
15935 + movq RDI(%rsp), %rdi
15936 .if \skiprax
15937 .else
15938 - movq \offset+72(%rsp), %rax
15939 + movq RAX(%rsp), %rax
15940 .endif
15941 .endm
15942
15943 -#define REST_SKIP (6*8)
15944 -
15945 .macro SAVE_REST
15946 - subq $REST_SKIP, %rsp
15947 - CFI_ADJUST_CFA_OFFSET REST_SKIP
15948 - movq_cfi rbx, 5*8
15949 - movq_cfi rbp, 4*8
15950 - movq_cfi r12, 3*8
15951 - movq_cfi r13, 2*8
15952 - movq_cfi r14, 1*8
15953 - movq_cfi r15, 0*8
15954 + movq_cfi rbx, RBX
15955 + movq_cfi rbp, RBP
15956 +
15957 +#ifndef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
15958 + movq_cfi r12, R12
15959 +#endif
15960 +
15961 + movq_cfi r13, R13
15962 + movq_cfi r14, R14
15963 + movq_cfi r15, R15
15964 .endm
15965
15966 .macro RESTORE_REST
15967 - movq_cfi_restore 0*8, r15
15968 - movq_cfi_restore 1*8, r14
15969 - movq_cfi_restore 2*8, r13
15970 - movq_cfi_restore 3*8, r12
15971 - movq_cfi_restore 4*8, rbp
15972 - movq_cfi_restore 5*8, rbx
15973 - addq $REST_SKIP, %rsp
15974 - CFI_ADJUST_CFA_OFFSET -(REST_SKIP)
15975 + movq_cfi_restore R15, r15
15976 + movq_cfi_restore R14, r14
15977 + movq_cfi_restore R13, r13
15978 +
15979 +#ifndef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
15980 + movq_cfi_restore R12, r12
15981 +#endif
15982 +
15983 + movq_cfi_restore RBP, rbp
15984 + movq_cfi_restore RBX, rbx
15985 .endm
15986
15987 .macro SAVE_ALL
15988 diff --git a/arch/x86/include/asm/checksum_32.h b/arch/x86/include/asm/checksum_32.h
15989 index f50de69..2b0a458 100644
15990 --- a/arch/x86/include/asm/checksum_32.h
15991 +++ b/arch/x86/include/asm/checksum_32.h
15992 @@ -31,6 +31,14 @@ asmlinkage __wsum csum_partial_copy_generic(const void *src, void *dst,
15993 int len, __wsum sum,
15994 int *src_err_ptr, int *dst_err_ptr);
15995
15996 +asmlinkage __wsum csum_partial_copy_generic_to_user(const void *src, void *dst,
15997 + int len, __wsum sum,
15998 + int *src_err_ptr, int *dst_err_ptr);
15999 +
16000 +asmlinkage __wsum csum_partial_copy_generic_from_user(const void *src, void *dst,
16001 + int len, __wsum sum,
16002 + int *src_err_ptr, int *dst_err_ptr);
16003 +
16004 /*
16005 * Note: when you get a NULL pointer exception here this means someone
16006 * passed in an incorrect kernel address to one of these functions.
16007 @@ -53,7 +61,7 @@ static inline __wsum csum_partial_copy_from_user(const void __user *src,
16008
16009 might_sleep();
16010 stac();
16011 - ret = csum_partial_copy_generic((__force void *)src, dst,
16012 + ret = csum_partial_copy_generic_from_user((__force void *)src, dst,
16013 len, sum, err_ptr, NULL);
16014 clac();
16015
16016 @@ -187,7 +195,7 @@ static inline __wsum csum_and_copy_to_user(const void *src,
16017 might_sleep();
16018 if (access_ok(VERIFY_WRITE, dst, len)) {
16019 stac();
16020 - ret = csum_partial_copy_generic(src, (__force void *)dst,
16021 + ret = csum_partial_copy_generic_to_user(src, (__force void *)dst,
16022 len, sum, NULL, err_ptr);
16023 clac();
16024 return ret;
16025 diff --git a/arch/x86/include/asm/cmpxchg.h b/arch/x86/include/asm/cmpxchg.h
16026 index d47786a..ce1b05d 100644
16027 --- a/arch/x86/include/asm/cmpxchg.h
16028 +++ b/arch/x86/include/asm/cmpxchg.h
16029 @@ -14,8 +14,12 @@ extern void __cmpxchg_wrong_size(void)
16030 __compiletime_error("Bad argument size for cmpxchg");
16031 extern void __xadd_wrong_size(void)
16032 __compiletime_error("Bad argument size for xadd");
16033 +extern void __xadd_check_overflow_wrong_size(void)
16034 + __compiletime_error("Bad argument size for xadd_check_overflow");
16035 extern void __add_wrong_size(void)
16036 __compiletime_error("Bad argument size for add");
16037 +extern void __add_check_overflow_wrong_size(void)
16038 + __compiletime_error("Bad argument size for add_check_overflow");
16039
16040 /*
16041 * Constants for operation sizes. On 32-bit, the 64-bit size it set to
16042 @@ -67,6 +71,34 @@ extern void __add_wrong_size(void)
16043 __ret; \
16044 })
16045
16046 +#define __xchg_op_check_overflow(ptr, arg, op, lock) \
16047 + ({ \
16048 + __typeof__ (*(ptr)) __ret = (arg); \
16049 + switch (sizeof(*(ptr))) { \
16050 + case __X86_CASE_L: \
16051 + asm volatile (lock #op "l %0, %1\n" \
16052 + "jno 0f\n" \
16053 + "mov %0,%1\n" \
16054 + "int $4\n0:\n" \
16055 + _ASM_EXTABLE(0b, 0b) \
16056 + : "+r" (__ret), "+m" (*(ptr)) \
16057 + : : "memory", "cc"); \
16058 + break; \
16059 + case __X86_CASE_Q: \
16060 + asm volatile (lock #op "q %q0, %1\n" \
16061 + "jno 0f\n" \
16062 + "mov %0,%1\n" \
16063 + "int $4\n0:\n" \
16064 + _ASM_EXTABLE(0b, 0b) \
16065 + : "+r" (__ret), "+m" (*(ptr)) \
16066 + : : "memory", "cc"); \
16067 + break; \
16068 + default: \
16069 + __ ## op ## _check_overflow_wrong_size(); \
16070 + } \
16071 + __ret; \
16072 + })
16073 +
16074 /*
16075 * Note: no "lock" prefix even on SMP: xchg always implies lock anyway.
16076 * Since this is generally used to protect other memory information, we
16077 @@ -167,6 +199,9 @@ extern void __add_wrong_size(void)
16078 #define xadd_sync(ptr, inc) __xadd((ptr), (inc), "lock; ")
16079 #define xadd_local(ptr, inc) __xadd((ptr), (inc), "")
16080
16081 +#define __xadd_check_overflow(ptr, inc, lock) __xchg_op_check_overflow((ptr), (inc), xadd, lock)
16082 +#define xadd_check_overflow(ptr, inc) __xadd_check_overflow((ptr), (inc), LOCK_PREFIX)
16083 +
16084 #define __add(ptr, inc, lock) \
16085 ({ \
16086 __typeof__ (*(ptr)) __ret = (inc); \
16087 diff --git a/arch/x86/include/asm/compat.h b/arch/x86/include/asm/compat.h
16088 index 59c6c40..5e0b22c 100644
16089 --- a/arch/x86/include/asm/compat.h
16090 +++ b/arch/x86/include/asm/compat.h
16091 @@ -41,7 +41,7 @@ typedef s64 __attribute__((aligned(4))) compat_s64;
16092 typedef u32 compat_uint_t;
16093 typedef u32 compat_ulong_t;
16094 typedef u64 __attribute__((aligned(4))) compat_u64;
16095 -typedef u32 compat_uptr_t;
16096 +typedef u32 __user compat_uptr_t;
16097
16098 struct compat_timespec {
16099 compat_time_t tv_sec;
16100 diff --git a/arch/x86/include/asm/cpufeature.h b/arch/x86/include/asm/cpufeature.h
16101 index 89270b4..f0abf8e 100644
16102 --- a/arch/x86/include/asm/cpufeature.h
16103 +++ b/arch/x86/include/asm/cpufeature.h
16104 @@ -203,7 +203,7 @@
16105 #define X86_FEATURE_DECODEASSISTS (8*32+12) /* AMD Decode Assists support */
16106 #define X86_FEATURE_PAUSEFILTER (8*32+13) /* AMD filtered pause intercept */
16107 #define X86_FEATURE_PFTHRESHOLD (8*32+14) /* AMD pause filter threshold */
16108 -
16109 +#define X86_FEATURE_STRONGUDEREF (8*32+31) /* PaX PCID based strong UDEREF */
16110
16111 /* Intel-defined CPU features, CPUID level 0x00000007:0 (ebx), word 9 */
16112 #define X86_FEATURE_FSGSBASE (9*32+ 0) /* {RD/WR}{FS/GS}BASE instructions*/
16113 @@ -211,7 +211,7 @@
16114 #define X86_FEATURE_BMI1 (9*32+ 3) /* 1st group bit manipulation extensions */
16115 #define X86_FEATURE_HLE (9*32+ 4) /* Hardware Lock Elision */
16116 #define X86_FEATURE_AVX2 (9*32+ 5) /* AVX2 instructions */
16117 -#define X86_FEATURE_SMEP (9*32+ 7) /* Supervisor Mode Execution Protection */
16118 +#define X86_FEATURE_SMEP (9*32+ 7) /* Supervisor Mode Execution Prevention */
16119 #define X86_FEATURE_BMI2 (9*32+ 8) /* 2nd group bit manipulation extensions */
16120 #define X86_FEATURE_ERMS (9*32+ 9) /* Enhanced REP MOVSB/STOSB */
16121 #define X86_FEATURE_INVPCID (9*32+10) /* Invalidate Processor Context ID */
16122 @@ -353,6 +353,7 @@ extern const char * const x86_power_flags[32];
16123 #undef cpu_has_centaur_mcr
16124 #define cpu_has_centaur_mcr 0
16125
16126 +#define cpu_has_pcid boot_cpu_has(X86_FEATURE_PCID)
16127 #endif /* CONFIG_X86_64 */
16128
16129 #if __GNUC__ >= 4
16130 @@ -405,7 +406,8 @@ static __always_inline __pure bool __static_cpu_has(u16 bit)
16131
16132 #ifdef CONFIG_X86_DEBUG_STATIC_CPU_HAS
16133 t_warn:
16134 - warn_pre_alternatives();
16135 + if (bit != X86_FEATURE_PCID && bit != X86_FEATURE_INVPCID)
16136 + warn_pre_alternatives();
16137 return false;
16138 #endif
16139
16140 @@ -425,7 +427,7 @@ static __always_inline __pure bool __static_cpu_has(u16 bit)
16141 ".section .discard,\"aw\",@progbits\n"
16142 " .byte 0xff + (4f-3f) - (2b-1b)\n" /* size check */
16143 ".previous\n"
16144 - ".section .altinstr_replacement,\"ax\"\n"
16145 + ".section .altinstr_replacement,\"a\"\n"
16146 "3: movb $1,%0\n"
16147 "4:\n"
16148 ".previous\n"
16149 @@ -462,7 +464,7 @@ static __always_inline __pure bool _static_cpu_has_safe(u16 bit)
16150 " .byte 2b - 1b\n" /* src len */
16151 " .byte 4f - 3f\n" /* repl len */
16152 ".previous\n"
16153 - ".section .altinstr_replacement,\"ax\"\n"
16154 + ".section .altinstr_replacement,\"a\"\n"
16155 "3: .byte 0xe9\n .long %l[t_no] - 2b\n"
16156 "4:\n"
16157 ".previous\n"
16158 @@ -495,7 +497,7 @@ static __always_inline __pure bool _static_cpu_has_safe(u16 bit)
16159 ".section .discard,\"aw\",@progbits\n"
16160 " .byte 0xff + (4f-3f) - (2b-1b)\n" /* size check */
16161 ".previous\n"
16162 - ".section .altinstr_replacement,\"ax\"\n"
16163 + ".section .altinstr_replacement,\"a\"\n"
16164 "3: movb $0,%0\n"
16165 "4:\n"
16166 ".previous\n"
16167 @@ -509,7 +511,7 @@ static __always_inline __pure bool _static_cpu_has_safe(u16 bit)
16168 ".section .discard,\"aw\",@progbits\n"
16169 " .byte 0xff + (6f-5f) - (4b-3b)\n" /* size check */
16170 ".previous\n"
16171 - ".section .altinstr_replacement,\"ax\"\n"
16172 + ".section .altinstr_replacement,\"a\"\n"
16173 "5: movb $1,%0\n"
16174 "6:\n"
16175 ".previous\n"
16176 diff --git a/arch/x86/include/asm/desc.h b/arch/x86/include/asm/desc.h
16177 index 50d033a..37deb26 100644
16178 --- a/arch/x86/include/asm/desc.h
16179 +++ b/arch/x86/include/asm/desc.h
16180 @@ -4,6 +4,7 @@
16181 #include <asm/desc_defs.h>
16182 #include <asm/ldt.h>
16183 #include <asm/mmu.h>
16184 +#include <asm/pgtable.h>
16185
16186 #include <linux/smp.h>
16187 #include <linux/percpu.h>
16188 @@ -17,6 +18,7 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
16189
16190 desc->type = (info->read_exec_only ^ 1) << 1;
16191 desc->type |= info->contents << 2;
16192 + desc->type |= info->seg_not_present ^ 1;
16193
16194 desc->s = 1;
16195 desc->dpl = 0x3;
16196 @@ -35,19 +37,14 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
16197 }
16198
16199 extern struct desc_ptr idt_descr;
16200 -extern gate_desc idt_table[];
16201 -extern struct desc_ptr debug_idt_descr;
16202 -extern gate_desc debug_idt_table[];
16203 -
16204 -struct gdt_page {
16205 - struct desc_struct gdt[GDT_ENTRIES];
16206 -} __attribute__((aligned(PAGE_SIZE)));
16207 -
16208 -DECLARE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page);
16209 +extern gate_desc idt_table[IDT_ENTRIES];
16210 +extern const struct desc_ptr debug_idt_descr;
16211 +extern gate_desc debug_idt_table[IDT_ENTRIES];
16212
16213 +extern struct desc_struct cpu_gdt_table[NR_CPUS][PAGE_SIZE / sizeof(struct desc_struct)];
16214 static inline struct desc_struct *get_cpu_gdt_table(unsigned int cpu)
16215 {
16216 - return per_cpu(gdt_page, cpu).gdt;
16217 + return cpu_gdt_table[cpu];
16218 }
16219
16220 #ifdef CONFIG_X86_64
16221 @@ -72,8 +69,14 @@ static inline void pack_gate(gate_desc *gate, unsigned char type,
16222 unsigned long base, unsigned dpl, unsigned flags,
16223 unsigned short seg)
16224 {
16225 - gate->a = (seg << 16) | (base & 0xffff);
16226 - gate->b = (base & 0xffff0000) | (((0x80 | type | (dpl << 5)) & 0xff) << 8);
16227 + gate->gate.offset_low = base;
16228 + gate->gate.seg = seg;
16229 + gate->gate.reserved = 0;
16230 + gate->gate.type = type;
16231 + gate->gate.s = 0;
16232 + gate->gate.dpl = dpl;
16233 + gate->gate.p = 1;
16234 + gate->gate.offset_high = base >> 16;
16235 }
16236
16237 #endif
16238 @@ -118,12 +121,16 @@ static inline void paravirt_free_ldt(struct desc_struct *ldt, unsigned entries)
16239
16240 static inline void native_write_idt_entry(gate_desc *idt, int entry, const gate_desc *gate)
16241 {
16242 + pax_open_kernel();
16243 memcpy(&idt[entry], gate, sizeof(*gate));
16244 + pax_close_kernel();
16245 }
16246
16247 static inline void native_write_ldt_entry(struct desc_struct *ldt, int entry, const void *desc)
16248 {
16249 + pax_open_kernel();
16250 memcpy(&ldt[entry], desc, 8);
16251 + pax_close_kernel();
16252 }
16253
16254 static inline void
16255 @@ -137,7 +144,9 @@ native_write_gdt_entry(struct desc_struct *gdt, int entry, const void *desc, int
16256 default: size = sizeof(*gdt); break;
16257 }
16258
16259 + pax_open_kernel();
16260 memcpy(&gdt[entry], desc, size);
16261 + pax_close_kernel();
16262 }
16263
16264 static inline void pack_descriptor(struct desc_struct *desc, unsigned long base,
16265 @@ -210,7 +219,9 @@ static inline void native_set_ldt(const void *addr, unsigned int entries)
16266
16267 static inline void native_load_tr_desc(void)
16268 {
16269 + pax_open_kernel();
16270 asm volatile("ltr %w0"::"q" (GDT_ENTRY_TSS*8));
16271 + pax_close_kernel();
16272 }
16273
16274 static inline void native_load_gdt(const struct desc_ptr *dtr)
16275 @@ -247,8 +258,10 @@ static inline void native_load_tls(struct thread_struct *t, unsigned int cpu)
16276 struct desc_struct *gdt = get_cpu_gdt_table(cpu);
16277 unsigned int i;
16278
16279 + pax_open_kernel();
16280 for (i = 0; i < GDT_ENTRY_TLS_ENTRIES; i++)
16281 gdt[GDT_ENTRY_TLS_MIN + i] = t->tls_array[i];
16282 + pax_close_kernel();
16283 }
16284
16285 #define _LDT_empty(info) \
16286 @@ -287,7 +300,7 @@ static inline void load_LDT(mm_context_t *pc)
16287 preempt_enable();
16288 }
16289
16290 -static inline unsigned long get_desc_base(const struct desc_struct *desc)
16291 +static inline unsigned long __intentional_overflow(-1) get_desc_base(const struct desc_struct *desc)
16292 {
16293 return (unsigned)(desc->base0 | ((desc->base1) << 16) | ((desc->base2) << 24));
16294 }
16295 @@ -311,7 +324,7 @@ static inline void set_desc_limit(struct desc_struct *desc, unsigned long limit)
16296 }
16297
16298 #ifdef CONFIG_X86_64
16299 -static inline void set_nmi_gate(int gate, void *addr)
16300 +static inline void set_nmi_gate(int gate, const void *addr)
16301 {
16302 gate_desc s;
16303
16304 @@ -321,14 +334,14 @@ static inline void set_nmi_gate(int gate, void *addr)
16305 #endif
16306
16307 #ifdef CONFIG_TRACING
16308 -extern struct desc_ptr trace_idt_descr;
16309 -extern gate_desc trace_idt_table[];
16310 +extern const struct desc_ptr trace_idt_descr;
16311 +extern gate_desc trace_idt_table[IDT_ENTRIES];
16312 static inline void write_trace_idt_entry(int entry, const gate_desc *gate)
16313 {
16314 write_idt_entry(trace_idt_table, entry, gate);
16315 }
16316
16317 -static inline void _trace_set_gate(int gate, unsigned type, void *addr,
16318 +static inline void _trace_set_gate(int gate, unsigned type, const void *addr,
16319 unsigned dpl, unsigned ist, unsigned seg)
16320 {
16321 gate_desc s;
16322 @@ -348,7 +361,7 @@ static inline void write_trace_idt_entry(int entry, const gate_desc *gate)
16323 #define _trace_set_gate(gate, type, addr, dpl, ist, seg)
16324 #endif
16325
16326 -static inline void _set_gate(int gate, unsigned type, void *addr,
16327 +static inline void _set_gate(int gate, unsigned type, const void *addr,
16328 unsigned dpl, unsigned ist, unsigned seg)
16329 {
16330 gate_desc s;
16331 @@ -371,9 +384,9 @@ static inline void _set_gate(int gate, unsigned type, void *addr,
16332 #define set_intr_gate(n, addr) \
16333 do { \
16334 BUG_ON((unsigned)n > 0xFF); \
16335 - _set_gate(n, GATE_INTERRUPT, (void *)addr, 0, 0, \
16336 + _set_gate(n, GATE_INTERRUPT, (const void *)addr, 0, 0, \
16337 __KERNEL_CS); \
16338 - _trace_set_gate(n, GATE_INTERRUPT, (void *)trace_##addr,\
16339 + _trace_set_gate(n, GATE_INTERRUPT, (const void *)trace_##addr,\
16340 0, 0, __KERNEL_CS); \
16341 } while (0)
16342
16343 @@ -401,19 +414,19 @@ static inline void alloc_system_vector(int vector)
16344 /*
16345 * This routine sets up an interrupt gate at directory privilege level 3.
16346 */
16347 -static inline void set_system_intr_gate(unsigned int n, void *addr)
16348 +static inline void set_system_intr_gate(unsigned int n, const void *addr)
16349 {
16350 BUG_ON((unsigned)n > 0xFF);
16351 _set_gate(n, GATE_INTERRUPT, addr, 0x3, 0, __KERNEL_CS);
16352 }
16353
16354 -static inline void set_system_trap_gate(unsigned int n, void *addr)
16355 +static inline void set_system_trap_gate(unsigned int n, const void *addr)
16356 {
16357 BUG_ON((unsigned)n > 0xFF);
16358 _set_gate(n, GATE_TRAP, addr, 0x3, 0, __KERNEL_CS);
16359 }
16360
16361 -static inline void set_trap_gate(unsigned int n, void *addr)
16362 +static inline void set_trap_gate(unsigned int n, const void *addr)
16363 {
16364 BUG_ON((unsigned)n > 0xFF);
16365 _set_gate(n, GATE_TRAP, addr, 0, 0, __KERNEL_CS);
16366 @@ -422,16 +435,16 @@ static inline void set_trap_gate(unsigned int n, void *addr)
16367 static inline void set_task_gate(unsigned int n, unsigned int gdt_entry)
16368 {
16369 BUG_ON((unsigned)n > 0xFF);
16370 - _set_gate(n, GATE_TASK, (void *)0, 0, 0, (gdt_entry<<3));
16371 + _set_gate(n, GATE_TASK, (const void *)0, 0, 0, (gdt_entry<<3));
16372 }
16373
16374 -static inline void set_intr_gate_ist(int n, void *addr, unsigned ist)
16375 +static inline void set_intr_gate_ist(int n, const void *addr, unsigned ist)
16376 {
16377 BUG_ON((unsigned)n > 0xFF);
16378 _set_gate(n, GATE_INTERRUPT, addr, 0, ist, __KERNEL_CS);
16379 }
16380
16381 -static inline void set_system_intr_gate_ist(int n, void *addr, unsigned ist)
16382 +static inline void set_system_intr_gate_ist(int n, const void *addr, unsigned ist)
16383 {
16384 BUG_ON((unsigned)n > 0xFF);
16385 _set_gate(n, GATE_INTERRUPT, addr, 0x3, ist, __KERNEL_CS);
16386 @@ -503,4 +516,17 @@ static inline void load_current_idt(void)
16387 else
16388 load_idt((const struct desc_ptr *)&idt_descr);
16389 }
16390 +
16391 +#ifdef CONFIG_X86_32
16392 +static inline void set_user_cs(unsigned long base, unsigned long limit, int cpu)
16393 +{
16394 + struct desc_struct d;
16395 +
16396 + if (likely(limit))
16397 + limit = (limit - 1UL) >> PAGE_SHIFT;
16398 + pack_descriptor(&d, base, limit, 0xFB, 0xC);
16399 + write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_DEFAULT_USER_CS, &d, DESCTYPE_S);
16400 +}
16401 +#endif
16402 +
16403 #endif /* _ASM_X86_DESC_H */
16404 diff --git a/arch/x86/include/asm/desc_defs.h b/arch/x86/include/asm/desc_defs.h
16405 index 278441f..b95a174 100644
16406 --- a/arch/x86/include/asm/desc_defs.h
16407 +++ b/arch/x86/include/asm/desc_defs.h
16408 @@ -31,6 +31,12 @@ struct desc_struct {
16409 unsigned base1: 8, type: 4, s: 1, dpl: 2, p: 1;
16410 unsigned limit: 4, avl: 1, l: 1, d: 1, g: 1, base2: 8;
16411 };
16412 + struct {
16413 + u16 offset_low;
16414 + u16 seg;
16415 + unsigned reserved: 8, type: 4, s: 1, dpl: 2, p: 1;
16416 + unsigned offset_high: 16;
16417 + } gate;
16418 };
16419 } __attribute__((packed));
16420
16421 diff --git a/arch/x86/include/asm/div64.h b/arch/x86/include/asm/div64.h
16422 index ced283a..ffe04cc 100644
16423 --- a/arch/x86/include/asm/div64.h
16424 +++ b/arch/x86/include/asm/div64.h
16425 @@ -39,7 +39,7 @@
16426 __mod; \
16427 })
16428
16429 -static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
16430 +static inline u64 __intentional_overflow(-1) div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
16431 {
16432 union {
16433 u64 v64;
16434 diff --git a/arch/x86/include/asm/elf.h b/arch/x86/include/asm/elf.h
16435 index 9c999c1..3860cb8 100644
16436 --- a/arch/x86/include/asm/elf.h
16437 +++ b/arch/x86/include/asm/elf.h
16438 @@ -243,7 +243,25 @@ extern int force_personality32;
16439 the loader. We need to make sure that it is out of the way of the program
16440 that it will "exec", and that there is sufficient room for the brk. */
16441
16442 +#ifdef CONFIG_PAX_SEGMEXEC
16443 +#define ELF_ET_DYN_BASE ((current->mm->pax_flags & MF_PAX_SEGMEXEC) ? SEGMEXEC_TASK_SIZE/3*2 : TASK_SIZE/3*2)
16444 +#else
16445 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
16446 +#endif
16447 +
16448 +#ifdef CONFIG_PAX_ASLR
16449 +#ifdef CONFIG_X86_32
16450 +#define PAX_ELF_ET_DYN_BASE 0x10000000UL
16451 +
16452 +#define PAX_DELTA_MMAP_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
16453 +#define PAX_DELTA_STACK_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
16454 +#else
16455 +#define PAX_ELF_ET_DYN_BASE 0x400000UL
16456 +
16457 +#define PAX_DELTA_MMAP_LEN ((test_thread_flag(TIF_ADDR32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
16458 +#define PAX_DELTA_STACK_LEN ((test_thread_flag(TIF_ADDR32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
16459 +#endif
16460 +#endif
16461
16462 /* This yields a mask that user programs can use to figure out what
16463 instruction set this CPU supports. This could be done in user space,
16464 @@ -296,16 +314,12 @@ do { \
16465
16466 #define ARCH_DLINFO \
16467 do { \
16468 - if (vdso_enabled) \
16469 - NEW_AUX_ENT(AT_SYSINFO_EHDR, \
16470 - (unsigned long)current->mm->context.vdso); \
16471 + NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
16472 } while (0)
16473
16474 #define ARCH_DLINFO_X32 \
16475 do { \
16476 - if (vdso_enabled) \
16477 - NEW_AUX_ENT(AT_SYSINFO_EHDR, \
16478 - (unsigned long)current->mm->context.vdso); \
16479 + NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
16480 } while (0)
16481
16482 #define AT_SYSINFO 32
16483 @@ -320,7 +334,7 @@ else \
16484
16485 #endif /* !CONFIG_X86_32 */
16486
16487 -#define VDSO_CURRENT_BASE ((unsigned long)current->mm->context.vdso)
16488 +#define VDSO_CURRENT_BASE (current->mm->context.vdso)
16489
16490 #define VDSO_ENTRY \
16491 ((unsigned long)VDSO32_SYMBOL(VDSO_CURRENT_BASE, vsyscall))
16492 @@ -336,9 +350,6 @@ extern int x32_setup_additional_pages(struct linux_binprm *bprm,
16493 extern int syscall32_setup_pages(struct linux_binprm *, int exstack);
16494 #define compat_arch_setup_additional_pages syscall32_setup_pages
16495
16496 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
16497 -#define arch_randomize_brk arch_randomize_brk
16498 -
16499 /*
16500 * True on X86_32 or when emulating IA32 on X86_64
16501 */
16502 diff --git a/arch/x86/include/asm/emergency-restart.h b/arch/x86/include/asm/emergency-restart.h
16503 index 77a99ac..39ff7f5 100644
16504 --- a/arch/x86/include/asm/emergency-restart.h
16505 +++ b/arch/x86/include/asm/emergency-restart.h
16506 @@ -1,6 +1,6 @@
16507 #ifndef _ASM_X86_EMERGENCY_RESTART_H
16508 #define _ASM_X86_EMERGENCY_RESTART_H
16509
16510 -extern void machine_emergency_restart(void);
16511 +extern void machine_emergency_restart(void) __noreturn;
16512
16513 #endif /* _ASM_X86_EMERGENCY_RESTART_H */
16514 diff --git a/arch/x86/include/asm/floppy.h b/arch/x86/include/asm/floppy.h
16515 index d3d7469..677ef72 100644
16516 --- a/arch/x86/include/asm/floppy.h
16517 +++ b/arch/x86/include/asm/floppy.h
16518 @@ -229,18 +229,18 @@ static struct fd_routine_l {
16519 int (*_dma_setup)(char *addr, unsigned long size, int mode, int io);
16520 } fd_routine[] = {
16521 {
16522 - request_dma,
16523 - free_dma,
16524 - get_dma_residue,
16525 - dma_mem_alloc,
16526 - hard_dma_setup
16527 + ._request_dma = request_dma,
16528 + ._free_dma = free_dma,
16529 + ._get_dma_residue = get_dma_residue,
16530 + ._dma_mem_alloc = dma_mem_alloc,
16531 + ._dma_setup = hard_dma_setup
16532 },
16533 {
16534 - vdma_request_dma,
16535 - vdma_nop,
16536 - vdma_get_dma_residue,
16537 - vdma_mem_alloc,
16538 - vdma_dma_setup
16539 + ._request_dma = vdma_request_dma,
16540 + ._free_dma = vdma_nop,
16541 + ._get_dma_residue = vdma_get_dma_residue,
16542 + ._dma_mem_alloc = vdma_mem_alloc,
16543 + ._dma_setup = vdma_dma_setup
16544 }
16545 };
16546
16547 diff --git a/arch/x86/include/asm/fpu-internal.h b/arch/x86/include/asm/fpu-internal.h
16548 index cea1c76..6c0d79b 100644
16549 --- a/arch/x86/include/asm/fpu-internal.h
16550 +++ b/arch/x86/include/asm/fpu-internal.h
16551 @@ -124,8 +124,11 @@ static inline void sanitize_i387_state(struct task_struct *tsk)
16552 #define user_insn(insn, output, input...) \
16553 ({ \
16554 int err; \
16555 + pax_open_userland(); \
16556 asm volatile(ASM_STAC "\n" \
16557 - "1:" #insn "\n\t" \
16558 + "1:" \
16559 + __copyuser_seg \
16560 + #insn "\n\t" \
16561 "2: " ASM_CLAC "\n" \
16562 ".section .fixup,\"ax\"\n" \
16563 "3: movl $-1,%[err]\n" \
16564 @@ -134,6 +137,7 @@ static inline void sanitize_i387_state(struct task_struct *tsk)
16565 _ASM_EXTABLE(1b, 3b) \
16566 : [err] "=r" (err), output \
16567 : "0"(0), input); \
16568 + pax_close_userland(); \
16569 err; \
16570 })
16571
16572 @@ -298,7 +302,7 @@ static inline int restore_fpu_checking(struct task_struct *tsk)
16573 "fnclex\n\t"
16574 "emms\n\t"
16575 "fildl %P[addr]" /* set F?P to defined value */
16576 - : : [addr] "m" (tsk->thread.fpu.has_fpu));
16577 + : : [addr] "m" (init_tss[raw_smp_processor_id()].x86_tss.sp0));
16578 }
16579
16580 return fpu_restore_checking(&tsk->thread.fpu);
16581 diff --git a/arch/x86/include/asm/futex.h b/arch/x86/include/asm/futex.h
16582 index be27ba1..04a8801 100644
16583 --- a/arch/x86/include/asm/futex.h
16584 +++ b/arch/x86/include/asm/futex.h
16585 @@ -12,6 +12,7 @@
16586 #include <asm/smap.h>
16587
16588 #define __futex_atomic_op1(insn, ret, oldval, uaddr, oparg) \
16589 + typecheck(u32 __user *, uaddr); \
16590 asm volatile("\t" ASM_STAC "\n" \
16591 "1:\t" insn "\n" \
16592 "2:\t" ASM_CLAC "\n" \
16593 @@ -20,15 +21,16 @@
16594 "\tjmp\t2b\n" \
16595 "\t.previous\n" \
16596 _ASM_EXTABLE(1b, 3b) \
16597 - : "=r" (oldval), "=r" (ret), "+m" (*uaddr) \
16598 + : "=r" (oldval), "=r" (ret), "+m" (*(u32 __user *)____m(uaddr)) \
16599 : "i" (-EFAULT), "0" (oparg), "1" (0))
16600
16601 #define __futex_atomic_op2(insn, ret, oldval, uaddr, oparg) \
16602 + typecheck(u32 __user *, uaddr); \
16603 asm volatile("\t" ASM_STAC "\n" \
16604 "1:\tmovl %2, %0\n" \
16605 "\tmovl\t%0, %3\n" \
16606 "\t" insn "\n" \
16607 - "2:\t" LOCK_PREFIX "cmpxchgl %3, %2\n" \
16608 + "2:\t" LOCK_PREFIX __copyuser_seg"cmpxchgl %3, %2\n" \
16609 "\tjnz\t1b\n" \
16610 "3:\t" ASM_CLAC "\n" \
16611 "\t.section .fixup,\"ax\"\n" \
16612 @@ -38,7 +40,7 @@
16613 _ASM_EXTABLE(1b, 4b) \
16614 _ASM_EXTABLE(2b, 4b) \
16615 : "=&a" (oldval), "=&r" (ret), \
16616 - "+m" (*uaddr), "=&r" (tem) \
16617 + "+m" (*(u32 __user *)____m(uaddr)), "=&r" (tem) \
16618 : "r" (oparg), "i" (-EFAULT), "1" (0))
16619
16620 static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
16621 @@ -57,12 +59,13 @@ static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
16622
16623 pagefault_disable();
16624
16625 + pax_open_userland();
16626 switch (op) {
16627 case FUTEX_OP_SET:
16628 - __futex_atomic_op1("xchgl %0, %2", ret, oldval, uaddr, oparg);
16629 + __futex_atomic_op1(__copyuser_seg"xchgl %0, %2", ret, oldval, uaddr, oparg);
16630 break;
16631 case FUTEX_OP_ADD:
16632 - __futex_atomic_op1(LOCK_PREFIX "xaddl %0, %2", ret, oldval,
16633 + __futex_atomic_op1(LOCK_PREFIX __copyuser_seg"xaddl %0, %2", ret, oldval,
16634 uaddr, oparg);
16635 break;
16636 case FUTEX_OP_OR:
16637 @@ -77,6 +80,7 @@ static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
16638 default:
16639 ret = -ENOSYS;
16640 }
16641 + pax_close_userland();
16642
16643 pagefault_enable();
16644
16645 @@ -115,18 +119,20 @@ static inline int futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
16646 if (!access_ok(VERIFY_WRITE, uaddr, sizeof(u32)))
16647 return -EFAULT;
16648
16649 + pax_open_userland();
16650 asm volatile("\t" ASM_STAC "\n"
16651 - "1:\t" LOCK_PREFIX "cmpxchgl %4, %2\n"
16652 + "1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgl %4, %2\n"
16653 "2:\t" ASM_CLAC "\n"
16654 "\t.section .fixup, \"ax\"\n"
16655 "3:\tmov %3, %0\n"
16656 "\tjmp 2b\n"
16657 "\t.previous\n"
16658 _ASM_EXTABLE(1b, 3b)
16659 - : "+r" (ret), "=a" (oldval), "+m" (*uaddr)
16660 + : "+r" (ret), "=a" (oldval), "+m" (*(u32 __user *)____m(uaddr))
16661 : "i" (-EFAULT), "r" (newval), "1" (oldval)
16662 : "memory"
16663 );
16664 + pax_close_userland();
16665
16666 *uval = oldval;
16667 return ret;
16668 diff --git a/arch/x86/include/asm/hw_irq.h b/arch/x86/include/asm/hw_irq.h
16669 index cba45d9..86344ba 100644
16670 --- a/arch/x86/include/asm/hw_irq.h
16671 +++ b/arch/x86/include/asm/hw_irq.h
16672 @@ -165,8 +165,8 @@ extern void setup_ioapic_dest(void);
16673 extern void enable_IO_APIC(void);
16674
16675 /* Statistics */
16676 -extern atomic_t irq_err_count;
16677 -extern atomic_t irq_mis_count;
16678 +extern atomic_unchecked_t irq_err_count;
16679 +extern atomic_unchecked_t irq_mis_count;
16680
16681 /* EISA */
16682 extern void eisa_set_level_irq(unsigned int irq);
16683 diff --git a/arch/x86/include/asm/i8259.h b/arch/x86/include/asm/i8259.h
16684 index a203659..9889f1c 100644
16685 --- a/arch/x86/include/asm/i8259.h
16686 +++ b/arch/x86/include/asm/i8259.h
16687 @@ -62,7 +62,7 @@ struct legacy_pic {
16688 void (*init)(int auto_eoi);
16689 int (*irq_pending)(unsigned int irq);
16690 void (*make_irq)(unsigned int irq);
16691 -};
16692 +} __do_const;
16693
16694 extern struct legacy_pic *legacy_pic;
16695 extern struct legacy_pic null_legacy_pic;
16696 diff --git a/arch/x86/include/asm/io.h b/arch/x86/include/asm/io.h
16697 index 34f69cb..6d95446 100644
16698 --- a/arch/x86/include/asm/io.h
16699 +++ b/arch/x86/include/asm/io.h
16700 @@ -51,12 +51,12 @@ static inline void name(type val, volatile void __iomem *addr) \
16701 "m" (*(volatile type __force *)addr) barrier); }
16702
16703 build_mmio_read(readb, "b", unsigned char, "=q", :"memory")
16704 -build_mmio_read(readw, "w", unsigned short, "=r", :"memory")
16705 -build_mmio_read(readl, "l", unsigned int, "=r", :"memory")
16706 +build_mmio_read(__intentional_overflow(-1) readw, "w", unsigned short, "=r", :"memory")
16707 +build_mmio_read(__intentional_overflow(-1) readl, "l", unsigned int, "=r", :"memory")
16708
16709 build_mmio_read(__readb, "b", unsigned char, "=q", )
16710 -build_mmio_read(__readw, "w", unsigned short, "=r", )
16711 -build_mmio_read(__readl, "l", unsigned int, "=r", )
16712 +build_mmio_read(__intentional_overflow(-1) __readw, "w", unsigned short, "=r", )
16713 +build_mmio_read(__intentional_overflow(-1) __readl, "l", unsigned int, "=r", )
16714
16715 build_mmio_write(writeb, "b", unsigned char, "q", :"memory")
16716 build_mmio_write(writew, "w", unsigned short, "r", :"memory")
16717 @@ -184,7 +184,7 @@ static inline void __iomem *ioremap(resource_size_t offset, unsigned long size)
16718 return ioremap_nocache(offset, size);
16719 }
16720
16721 -extern void iounmap(volatile void __iomem *addr);
16722 +extern void iounmap(const volatile void __iomem *addr);
16723
16724 extern void set_iounmap_nonlazy(void);
16725
16726 @@ -194,6 +194,17 @@ extern void set_iounmap_nonlazy(void);
16727
16728 #include <linux/vmalloc.h>
16729
16730 +#define ARCH_HAS_VALID_PHYS_ADDR_RANGE
16731 +static inline int valid_phys_addr_range(unsigned long addr, size_t count)
16732 +{
16733 + return ((addr + count + PAGE_SIZE - 1) >> PAGE_SHIFT) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
16734 +}
16735 +
16736 +static inline int valid_mmap_phys_addr_range(unsigned long pfn, size_t count)
16737 +{
16738 + return (pfn + (count >> PAGE_SHIFT)) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
16739 +}
16740 +
16741 /*
16742 * Convert a virtual cached pointer to an uncached pointer
16743 */
16744 diff --git a/arch/x86/include/asm/irqflags.h b/arch/x86/include/asm/irqflags.h
16745 index bba3cf8..06bc8da 100644
16746 --- a/arch/x86/include/asm/irqflags.h
16747 +++ b/arch/x86/include/asm/irqflags.h
16748 @@ -141,6 +141,11 @@ static inline notrace unsigned long arch_local_irq_save(void)
16749 sti; \
16750 sysexit
16751
16752 +#define GET_CR0_INTO_RDI mov %cr0, %rdi
16753 +#define SET_RDI_INTO_CR0 mov %rdi, %cr0
16754 +#define GET_CR3_INTO_RDI mov %cr3, %rdi
16755 +#define SET_RDI_INTO_CR3 mov %rdi, %cr3
16756 +
16757 #else
16758 #define INTERRUPT_RETURN iret
16759 #define ENABLE_INTERRUPTS_SYSEXIT sti; sysexit
16760 diff --git a/arch/x86/include/asm/kprobes.h b/arch/x86/include/asm/kprobes.h
16761 index 9454c16..e4100e3 100644
16762 --- a/arch/x86/include/asm/kprobes.h
16763 +++ b/arch/x86/include/asm/kprobes.h
16764 @@ -38,13 +38,8 @@ typedef u8 kprobe_opcode_t;
16765 #define RELATIVEJUMP_SIZE 5
16766 #define RELATIVECALL_OPCODE 0xe8
16767 #define RELATIVE_ADDR_SIZE 4
16768 -#define MAX_STACK_SIZE 64
16769 -#define MIN_STACK_SIZE(ADDR) \
16770 - (((MAX_STACK_SIZE) < (((unsigned long)current_thread_info()) + \
16771 - THREAD_SIZE - (unsigned long)(ADDR))) \
16772 - ? (MAX_STACK_SIZE) \
16773 - : (((unsigned long)current_thread_info()) + \
16774 - THREAD_SIZE - (unsigned long)(ADDR)))
16775 +#define MAX_STACK_SIZE 64UL
16776 +#define MIN_STACK_SIZE(ADDR) min(MAX_STACK_SIZE, current->thread.sp0 - (unsigned long)(ADDR))
16777
16778 #define flush_insn_slot(p) do { } while (0)
16779
16780 diff --git a/arch/x86/include/asm/local.h b/arch/x86/include/asm/local.h
16781 index 4ad6560..75c7bdd 100644
16782 --- a/arch/x86/include/asm/local.h
16783 +++ b/arch/x86/include/asm/local.h
16784 @@ -10,33 +10,97 @@ typedef struct {
16785 atomic_long_t a;
16786 } local_t;
16787
16788 +typedef struct {
16789 + atomic_long_unchecked_t a;
16790 +} local_unchecked_t;
16791 +
16792 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
16793
16794 #define local_read(l) atomic_long_read(&(l)->a)
16795 +#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
16796 #define local_set(l, i) atomic_long_set(&(l)->a, (i))
16797 +#define local_set_unchecked(l, i) atomic_long_set_unchecked(&(l)->a, (i))
16798
16799 static inline void local_inc(local_t *l)
16800 {
16801 - asm volatile(_ASM_INC "%0"
16802 + asm volatile(_ASM_INC "%0\n"
16803 +
16804 +#ifdef CONFIG_PAX_REFCOUNT
16805 + "jno 0f\n"
16806 + _ASM_DEC "%0\n"
16807 + "int $4\n0:\n"
16808 + _ASM_EXTABLE(0b, 0b)
16809 +#endif
16810 +
16811 + : "+m" (l->a.counter));
16812 +}
16813 +
16814 +static inline void local_inc_unchecked(local_unchecked_t *l)
16815 +{
16816 + asm volatile(_ASM_INC "%0\n"
16817 : "+m" (l->a.counter));
16818 }
16819
16820 static inline void local_dec(local_t *l)
16821 {
16822 - asm volatile(_ASM_DEC "%0"
16823 + asm volatile(_ASM_DEC "%0\n"
16824 +
16825 +#ifdef CONFIG_PAX_REFCOUNT
16826 + "jno 0f\n"
16827 + _ASM_INC "%0\n"
16828 + "int $4\n0:\n"
16829 + _ASM_EXTABLE(0b, 0b)
16830 +#endif
16831 +
16832 + : "+m" (l->a.counter));
16833 +}
16834 +
16835 +static inline void local_dec_unchecked(local_unchecked_t *l)
16836 +{
16837 + asm volatile(_ASM_DEC "%0\n"
16838 : "+m" (l->a.counter));
16839 }
16840
16841 static inline void local_add(long i, local_t *l)
16842 {
16843 - asm volatile(_ASM_ADD "%1,%0"
16844 + asm volatile(_ASM_ADD "%1,%0\n"
16845 +
16846 +#ifdef CONFIG_PAX_REFCOUNT
16847 + "jno 0f\n"
16848 + _ASM_SUB "%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_add_unchecked(long i, local_unchecked_t *l)
16858 +{
16859 + asm volatile(_ASM_ADD "%1,%0\n"
16860 : "+m" (l->a.counter)
16861 : "ir" (i));
16862 }
16863
16864 static inline void local_sub(long i, local_t *l)
16865 {
16866 - asm volatile(_ASM_SUB "%1,%0"
16867 + asm volatile(_ASM_SUB "%1,%0\n"
16868 +
16869 +#ifdef CONFIG_PAX_REFCOUNT
16870 + "jno 0f\n"
16871 + _ASM_ADD "%1,%0\n"
16872 + "int $4\n0:\n"
16873 + _ASM_EXTABLE(0b, 0b)
16874 +#endif
16875 +
16876 + : "+m" (l->a.counter)
16877 + : "ir" (i));
16878 +}
16879 +
16880 +static inline void local_sub_unchecked(long i, local_unchecked_t *l)
16881 +{
16882 + asm volatile(_ASM_SUB "%1,%0\n"
16883 : "+m" (l->a.counter)
16884 : "ir" (i));
16885 }
16886 @@ -52,7 +116,7 @@ static inline void local_sub(long i, local_t *l)
16887 */
16888 static inline int local_sub_and_test(long i, local_t *l)
16889 {
16890 - GEN_BINARY_RMWcc(_ASM_SUB, l->a.counter, "er", i, "%0", "e");
16891 + GEN_BINARY_RMWcc(_ASM_SUB, _ASM_ADD, l->a.counter, "er", i, "%0", "e");
16892 }
16893
16894 /**
16895 @@ -65,7 +129,7 @@ static inline int local_sub_and_test(long i, local_t *l)
16896 */
16897 static inline int local_dec_and_test(local_t *l)
16898 {
16899 - GEN_UNARY_RMWcc(_ASM_DEC, l->a.counter, "%0", "e");
16900 + GEN_UNARY_RMWcc(_ASM_DEC, _ASM_INC, l->a.counter, "%0", "e");
16901 }
16902
16903 /**
16904 @@ -78,7 +142,7 @@ static inline int local_dec_and_test(local_t *l)
16905 */
16906 static inline int local_inc_and_test(local_t *l)
16907 {
16908 - GEN_UNARY_RMWcc(_ASM_INC, l->a.counter, "%0", "e");
16909 + GEN_UNARY_RMWcc(_ASM_INC, _ASM_DEC, l->a.counter, "%0", "e");
16910 }
16911
16912 /**
16913 @@ -92,7 +156,7 @@ static inline int local_inc_and_test(local_t *l)
16914 */
16915 static inline int local_add_negative(long i, local_t *l)
16916 {
16917 - GEN_BINARY_RMWcc(_ASM_ADD, l->a.counter, "er", i, "%0", "s");
16918 + GEN_BINARY_RMWcc(_ASM_ADD, _ASM_SUB, l->a.counter, "er", i, "%0", "s");
16919 }
16920
16921 /**
16922 @@ -105,6 +169,30 @@ static inline int local_add_negative(long i, local_t *l)
16923 static inline long local_add_return(long i, local_t *l)
16924 {
16925 long __i = i;
16926 + asm volatile(_ASM_XADD "%0, %1\n"
16927 +
16928 +#ifdef CONFIG_PAX_REFCOUNT
16929 + "jno 0f\n"
16930 + _ASM_MOV "%0,%1\n"
16931 + "int $4\n0:\n"
16932 + _ASM_EXTABLE(0b, 0b)
16933 +#endif
16934 +
16935 + : "+r" (i), "+m" (l->a.counter)
16936 + : : "memory");
16937 + return i + __i;
16938 +}
16939 +
16940 +/**
16941 + * local_add_return_unchecked - add and return
16942 + * @i: integer value to add
16943 + * @l: pointer to type local_unchecked_t
16944 + *
16945 + * Atomically adds @i to @l and returns @i + @l
16946 + */
16947 +static inline long local_add_return_unchecked(long i, local_unchecked_t *l)
16948 +{
16949 + long __i = i;
16950 asm volatile(_ASM_XADD "%0, %1;"
16951 : "+r" (i), "+m" (l->a.counter)
16952 : : "memory");
16953 @@ -121,6 +209,8 @@ static inline long local_sub_return(long i, local_t *l)
16954
16955 #define local_cmpxchg(l, o, n) \
16956 (cmpxchg_local(&((l)->a.counter), (o), (n)))
16957 +#define local_cmpxchg_unchecked(l, o, n) \
16958 + (cmpxchg_local(&((l)->a.counter), (o), (n)))
16959 /* Always has a lock prefix */
16960 #define local_xchg(l, n) (xchg(&((l)->a.counter), (n)))
16961
16962 diff --git a/arch/x86/include/asm/mman.h b/arch/x86/include/asm/mman.h
16963 new file mode 100644
16964 index 0000000..2bfd3ba
16965 --- /dev/null
16966 +++ b/arch/x86/include/asm/mman.h
16967 @@ -0,0 +1,15 @@
16968 +#ifndef _X86_MMAN_H
16969 +#define _X86_MMAN_H
16970 +
16971 +#include <uapi/asm/mman.h>
16972 +
16973 +#ifdef __KERNEL__
16974 +#ifndef __ASSEMBLY__
16975 +#ifdef CONFIG_X86_32
16976 +#define arch_mmap_check i386_mmap_check
16977 +int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags);
16978 +#endif
16979 +#endif
16980 +#endif
16981 +
16982 +#endif /* X86_MMAN_H */
16983 diff --git a/arch/x86/include/asm/mmu.h b/arch/x86/include/asm/mmu.h
16984 index 5f55e69..e20bfb1 100644
16985 --- a/arch/x86/include/asm/mmu.h
16986 +++ b/arch/x86/include/asm/mmu.h
16987 @@ -9,7 +9,7 @@
16988 * we put the segment information here.
16989 */
16990 typedef struct {
16991 - void *ldt;
16992 + struct desc_struct *ldt;
16993 int size;
16994
16995 #ifdef CONFIG_X86_64
16996 @@ -18,7 +18,19 @@ typedef struct {
16997 #endif
16998
16999 struct mutex lock;
17000 - void *vdso;
17001 + unsigned long vdso;
17002 +
17003 +#ifdef CONFIG_X86_32
17004 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
17005 + unsigned long user_cs_base;
17006 + unsigned long user_cs_limit;
17007 +
17008 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
17009 + cpumask_t cpu_user_cs_mask;
17010 +#endif
17011 +
17012 +#endif
17013 +#endif
17014 } mm_context_t;
17015
17016 #ifdef CONFIG_SMP
17017 diff --git a/arch/x86/include/asm/mmu_context.h b/arch/x86/include/asm/mmu_context.h
17018 index be12c53..4d24039 100644
17019 --- a/arch/x86/include/asm/mmu_context.h
17020 +++ b/arch/x86/include/asm/mmu_context.h
17021 @@ -24,6 +24,20 @@ void destroy_context(struct mm_struct *mm);
17022
17023 static inline void enter_lazy_tlb(struct mm_struct *mm, struct task_struct *tsk)
17024 {
17025 +
17026 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17027 + if (!(static_cpu_has(X86_FEATURE_PCID))) {
17028 + unsigned int i;
17029 + pgd_t *pgd;
17030 +
17031 + pax_open_kernel();
17032 + pgd = get_cpu_pgd(smp_processor_id(), kernel);
17033 + for (i = USER_PGD_PTRS; i < 2 * USER_PGD_PTRS; ++i)
17034 + set_pgd_batched(pgd+i, native_make_pgd(0));
17035 + pax_close_kernel();
17036 + }
17037 +#endif
17038 +
17039 #ifdef CONFIG_SMP
17040 if (this_cpu_read(cpu_tlbstate.state) == TLBSTATE_OK)
17041 this_cpu_write(cpu_tlbstate.state, TLBSTATE_LAZY);
17042 @@ -34,16 +48,59 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
17043 struct task_struct *tsk)
17044 {
17045 unsigned cpu = smp_processor_id();
17046 +#if defined(CONFIG_X86_32) && defined(CONFIG_SMP) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
17047 + int tlbstate = TLBSTATE_OK;
17048 +#endif
17049
17050 if (likely(prev != next)) {
17051 #ifdef CONFIG_SMP
17052 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
17053 + tlbstate = this_cpu_read(cpu_tlbstate.state);
17054 +#endif
17055 this_cpu_write(cpu_tlbstate.state, TLBSTATE_OK);
17056 this_cpu_write(cpu_tlbstate.active_mm, next);
17057 #endif
17058 cpumask_set_cpu(cpu, mm_cpumask(next));
17059
17060 /* Re-load page tables */
17061 +#ifdef CONFIG_PAX_PER_CPU_PGD
17062 + pax_open_kernel();
17063 +
17064 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17065 + if (static_cpu_has(X86_FEATURE_PCID))
17066 + __clone_user_pgds(get_cpu_pgd(cpu, user), next->pgd);
17067 + else
17068 +#endif
17069 +
17070 + __clone_user_pgds(get_cpu_pgd(cpu, kernel), next->pgd);
17071 + __shadow_user_pgds(get_cpu_pgd(cpu, kernel) + USER_PGD_PTRS, next->pgd);
17072 + pax_close_kernel();
17073 + 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));
17074 +
17075 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17076 + if (static_cpu_has(X86_FEATURE_PCID)) {
17077 + if (static_cpu_has(X86_FEATURE_INVPCID)) {
17078 + u64 descriptor[2];
17079 + descriptor[0] = PCID_USER;
17080 + asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_CONTEXT) : "memory");
17081 + if (!static_cpu_has(X86_FEATURE_STRONGUDEREF)) {
17082 + descriptor[0] = PCID_KERNEL;
17083 + asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_CONTEXT) : "memory");
17084 + }
17085 + } else {
17086 + write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER);
17087 + if (static_cpu_has(X86_FEATURE_STRONGUDEREF))
17088 + write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL | PCID_NOFLUSH);
17089 + else
17090 + write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL);
17091 + }
17092 + } else
17093 +#endif
17094 +
17095 + load_cr3(get_cpu_pgd(cpu, kernel));
17096 +#else
17097 load_cr3(next->pgd);
17098 +#endif
17099
17100 /* Stop flush ipis for the previous mm */
17101 cpumask_clear_cpu(cpu, mm_cpumask(prev));
17102 @@ -51,9 +108,67 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
17103 /* Load the LDT, if the LDT is different: */
17104 if (unlikely(prev->context.ldt != next->context.ldt))
17105 load_LDT_nolock(&next->context);
17106 +
17107 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
17108 + if (!(__supported_pte_mask & _PAGE_NX)) {
17109 + smp_mb__before_clear_bit();
17110 + cpu_clear(cpu, prev->context.cpu_user_cs_mask);
17111 + smp_mb__after_clear_bit();
17112 + cpu_set(cpu, next->context.cpu_user_cs_mask);
17113 + }
17114 +#endif
17115 +
17116 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
17117 + if (unlikely(prev->context.user_cs_base != next->context.user_cs_base ||
17118 + prev->context.user_cs_limit != next->context.user_cs_limit))
17119 + set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
17120 +#ifdef CONFIG_SMP
17121 + else if (unlikely(tlbstate != TLBSTATE_OK))
17122 + set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
17123 +#endif
17124 +#endif
17125 +
17126 }
17127 + else {
17128 +
17129 +#ifdef CONFIG_PAX_PER_CPU_PGD
17130 + pax_open_kernel();
17131 +
17132 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17133 + if (static_cpu_has(X86_FEATURE_PCID))
17134 + __clone_user_pgds(get_cpu_pgd(cpu, user), next->pgd);
17135 + else
17136 +#endif
17137 +
17138 + __clone_user_pgds(get_cpu_pgd(cpu, kernel), next->pgd);
17139 + __shadow_user_pgds(get_cpu_pgd(cpu, kernel) + USER_PGD_PTRS, next->pgd);
17140 + pax_close_kernel();
17141 + 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));
17142 +
17143 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17144 + if (static_cpu_has(X86_FEATURE_PCID)) {
17145 + if (static_cpu_has(X86_FEATURE_INVPCID)) {
17146 + u64 descriptor[2];
17147 + descriptor[0] = PCID_USER;
17148 + asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_CONTEXT) : "memory");
17149 + if (!static_cpu_has(X86_FEATURE_STRONGUDEREF)) {
17150 + descriptor[0] = PCID_KERNEL;
17151 + asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_CONTEXT) : "memory");
17152 + }
17153 + } else {
17154 + write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER);
17155 + if (static_cpu_has(X86_FEATURE_STRONGUDEREF))
17156 + write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL | PCID_NOFLUSH);
17157 + else
17158 + write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL);
17159 + }
17160 + } else
17161 +#endif
17162 +
17163 + load_cr3(get_cpu_pgd(cpu, kernel));
17164 +#endif
17165 +
17166 #ifdef CONFIG_SMP
17167 - else {
17168 this_cpu_write(cpu_tlbstate.state, TLBSTATE_OK);
17169 BUG_ON(this_cpu_read(cpu_tlbstate.active_mm) != next);
17170
17171 @@ -70,11 +185,28 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
17172 * tlb flush IPI delivery. We must reload CR3
17173 * to make sure to use no freed page tables.
17174 */
17175 +
17176 +#ifndef CONFIG_PAX_PER_CPU_PGD
17177 load_cr3(next->pgd);
17178 +#endif
17179 +
17180 load_LDT_nolock(&next->context);
17181 +
17182 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
17183 + if (!(__supported_pte_mask & _PAGE_NX))
17184 + cpu_set(cpu, next->context.cpu_user_cs_mask);
17185 +#endif
17186 +
17187 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
17188 +#ifdef CONFIG_PAX_PAGEEXEC
17189 + if (!((next->pax_flags & MF_PAX_PAGEEXEC) && (__supported_pte_mask & _PAGE_NX)))
17190 +#endif
17191 + set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
17192 +#endif
17193 +
17194 }
17195 +#endif
17196 }
17197 -#endif
17198 }
17199
17200 #define activate_mm(prev, next) \
17201 diff --git a/arch/x86/include/asm/module.h b/arch/x86/include/asm/module.h
17202 index e3b7819..b257c64 100644
17203 --- a/arch/x86/include/asm/module.h
17204 +++ b/arch/x86/include/asm/module.h
17205 @@ -5,6 +5,7 @@
17206
17207 #ifdef CONFIG_X86_64
17208 /* X86_64 does not define MODULE_PROC_FAMILY */
17209 +#define MODULE_PROC_FAMILY ""
17210 #elif defined CONFIG_M486
17211 #define MODULE_PROC_FAMILY "486 "
17212 #elif defined CONFIG_M586
17213 @@ -57,8 +58,20 @@
17214 #error unknown processor family
17215 #endif
17216
17217 -#ifdef CONFIG_X86_32
17218 -# define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY
17219 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
17220 +#define MODULE_PAX_KERNEXEC "KERNEXEC_BTS "
17221 +#elif defined(CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR)
17222 +#define MODULE_PAX_KERNEXEC "KERNEXEC_OR "
17223 +#else
17224 +#define MODULE_PAX_KERNEXEC ""
17225 #endif
17226
17227 +#ifdef CONFIG_PAX_MEMORY_UDEREF
17228 +#define MODULE_PAX_UDEREF "UDEREF "
17229 +#else
17230 +#define MODULE_PAX_UDEREF ""
17231 +#endif
17232 +
17233 +#define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY MODULE_PAX_KERNEXEC MODULE_PAX_UDEREF
17234 +
17235 #endif /* _ASM_X86_MODULE_H */
17236 diff --git a/arch/x86/include/asm/nmi.h b/arch/x86/include/asm/nmi.h
17237 index 86f9301..b365cda 100644
17238 --- a/arch/x86/include/asm/nmi.h
17239 +++ b/arch/x86/include/asm/nmi.h
17240 @@ -40,11 +40,11 @@ struct nmiaction {
17241 nmi_handler_t handler;
17242 unsigned long flags;
17243 const char *name;
17244 -};
17245 +} __do_const;
17246
17247 #define register_nmi_handler(t, fn, fg, n, init...) \
17248 ({ \
17249 - static struct nmiaction init fn##_na = { \
17250 + static const struct nmiaction init fn##_na = { \
17251 .handler = (fn), \
17252 .name = (n), \
17253 .flags = (fg), \
17254 @@ -52,7 +52,7 @@ struct nmiaction {
17255 __register_nmi_handler((t), &fn##_na); \
17256 })
17257
17258 -int __register_nmi_handler(unsigned int, struct nmiaction *);
17259 +int __register_nmi_handler(unsigned int, const struct nmiaction *);
17260
17261 void unregister_nmi_handler(unsigned int, const char *);
17262
17263 diff --git a/arch/x86/include/asm/page.h b/arch/x86/include/asm/page.h
17264 index c878924..21f4889 100644
17265 --- a/arch/x86/include/asm/page.h
17266 +++ b/arch/x86/include/asm/page.h
17267 @@ -52,6 +52,7 @@ static inline void copy_user_page(void *to, void *from, unsigned long vaddr,
17268 __phys_addr_symbol(__phys_reloc_hide((unsigned long)(x)))
17269
17270 #define __va(x) ((void *)((unsigned long)(x)+PAGE_OFFSET))
17271 +#define __early_va(x) ((void *)((unsigned long)(x)+__START_KERNEL_map - phys_base))
17272
17273 #define __boot_va(x) __va(x)
17274 #define __boot_pa(x) __pa(x)
17275 diff --git a/arch/x86/include/asm/page_64.h b/arch/x86/include/asm/page_64.h
17276 index 0f1ddee..e2fc3d1 100644
17277 --- a/arch/x86/include/asm/page_64.h
17278 +++ b/arch/x86/include/asm/page_64.h
17279 @@ -7,9 +7,9 @@
17280
17281 /* duplicated to the one in bootmem.h */
17282 extern unsigned long max_pfn;
17283 -extern unsigned long phys_base;
17284 +extern const unsigned long phys_base;
17285
17286 -static inline unsigned long __phys_addr_nodebug(unsigned long x)
17287 +static inline unsigned long __intentional_overflow(-1) __phys_addr_nodebug(unsigned long x)
17288 {
17289 unsigned long y = x - __START_KERNEL_map;
17290
17291 diff --git a/arch/x86/include/asm/paravirt.h b/arch/x86/include/asm/paravirt.h
17292 index 401f350..dee5d13 100644
17293 --- a/arch/x86/include/asm/paravirt.h
17294 +++ b/arch/x86/include/asm/paravirt.h
17295 @@ -560,7 +560,7 @@ static inline pmd_t __pmd(pmdval_t val)
17296 return (pmd_t) { ret };
17297 }
17298
17299 -static inline pmdval_t pmd_val(pmd_t pmd)
17300 +static inline __intentional_overflow(-1) pmdval_t pmd_val(pmd_t pmd)
17301 {
17302 pmdval_t ret;
17303
17304 @@ -626,6 +626,18 @@ static inline void set_pgd(pgd_t *pgdp, pgd_t pgd)
17305 val);
17306 }
17307
17308 +static inline void set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
17309 +{
17310 + pgdval_t val = native_pgd_val(pgd);
17311 +
17312 + if (sizeof(pgdval_t) > sizeof(long))
17313 + PVOP_VCALL3(pv_mmu_ops.set_pgd_batched, pgdp,
17314 + val, (u64)val >> 32);
17315 + else
17316 + PVOP_VCALL2(pv_mmu_ops.set_pgd_batched, pgdp,
17317 + val);
17318 +}
17319 +
17320 static inline void pgd_clear(pgd_t *pgdp)
17321 {
17322 set_pgd(pgdp, __pgd(0));
17323 @@ -710,6 +722,21 @@ static inline void __set_fixmap(unsigned /* enum fixed_addresses */ idx,
17324 pv_mmu_ops.set_fixmap(idx, phys, flags);
17325 }
17326
17327 +#ifdef CONFIG_PAX_KERNEXEC
17328 +static inline unsigned long pax_open_kernel(void)
17329 +{
17330 + return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_open_kernel);
17331 +}
17332 +
17333 +static inline unsigned long pax_close_kernel(void)
17334 +{
17335 + return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_close_kernel);
17336 +}
17337 +#else
17338 +static inline unsigned long pax_open_kernel(void) { return 0; }
17339 +static inline unsigned long pax_close_kernel(void) { return 0; }
17340 +#endif
17341 +
17342 #if defined(CONFIG_SMP) && defined(CONFIG_PARAVIRT_SPINLOCKS)
17343
17344 static __always_inline void __ticket_lock_spinning(struct arch_spinlock *lock,
17345 @@ -906,7 +933,7 @@ extern void default_banner(void);
17346
17347 #define PARA_PATCH(struct, off) ((PARAVIRT_PATCH_##struct + (off)) / 4)
17348 #define PARA_SITE(ptype, clobbers, ops) _PVSITE(ptype, clobbers, ops, .long, 4)
17349 -#define PARA_INDIRECT(addr) *%cs:addr
17350 +#define PARA_INDIRECT(addr) *%ss:addr
17351 #endif
17352
17353 #define INTERRUPT_RETURN \
17354 @@ -981,6 +1008,21 @@ extern void default_banner(void);
17355 PARA_SITE(PARA_PATCH(pv_cpu_ops, PV_CPU_irq_enable_sysexit), \
17356 CLBR_NONE, \
17357 jmp PARA_INDIRECT(pv_cpu_ops+PV_CPU_irq_enable_sysexit))
17358 +
17359 +#define GET_CR0_INTO_RDI \
17360 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0); \
17361 + mov %rax,%rdi
17362 +
17363 +#define SET_RDI_INTO_CR0 \
17364 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
17365 +
17366 +#define GET_CR3_INTO_RDI \
17367 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_read_cr3); \
17368 + mov %rax,%rdi
17369 +
17370 +#define SET_RDI_INTO_CR3 \
17371 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_write_cr3)
17372 +
17373 #endif /* CONFIG_X86_32 */
17374
17375 #endif /* __ASSEMBLY__ */
17376 diff --git a/arch/x86/include/asm/paravirt_types.h b/arch/x86/include/asm/paravirt_types.h
17377 index aab8f67..0fb0ee4 100644
17378 --- a/arch/x86/include/asm/paravirt_types.h
17379 +++ b/arch/x86/include/asm/paravirt_types.h
17380 @@ -84,7 +84,7 @@ struct pv_init_ops {
17381 */
17382 unsigned (*patch)(u8 type, u16 clobber, void *insnbuf,
17383 unsigned long addr, unsigned len);
17384 -};
17385 +} __no_const __no_randomize_layout;
17386
17387
17388 struct pv_lazy_ops {
17389 @@ -92,13 +92,13 @@ struct pv_lazy_ops {
17390 void (*enter)(void);
17391 void (*leave)(void);
17392 void (*flush)(void);
17393 -};
17394 +} __no_randomize_layout;
17395
17396 struct pv_time_ops {
17397 unsigned long long (*sched_clock)(void);
17398 unsigned long long (*steal_clock)(int cpu);
17399 unsigned long (*get_tsc_khz)(void);
17400 -};
17401 +} __no_const __no_randomize_layout;
17402
17403 struct pv_cpu_ops {
17404 /* hooks for various privileged instructions */
17405 @@ -192,7 +192,7 @@ struct pv_cpu_ops {
17406
17407 void (*start_context_switch)(struct task_struct *prev);
17408 void (*end_context_switch)(struct task_struct *next);
17409 -};
17410 +} __no_const __no_randomize_layout;
17411
17412 struct pv_irq_ops {
17413 /*
17414 @@ -215,7 +215,7 @@ struct pv_irq_ops {
17415 #ifdef CONFIG_X86_64
17416 void (*adjust_exception_frame)(void);
17417 #endif
17418 -};
17419 +} __no_randomize_layout;
17420
17421 struct pv_apic_ops {
17422 #ifdef CONFIG_X86_LOCAL_APIC
17423 @@ -223,7 +223,7 @@ struct pv_apic_ops {
17424 unsigned long start_eip,
17425 unsigned long start_esp);
17426 #endif
17427 -};
17428 +} __no_const __no_randomize_layout;
17429
17430 struct pv_mmu_ops {
17431 unsigned long (*read_cr2)(void);
17432 @@ -313,6 +313,7 @@ struct pv_mmu_ops {
17433 struct paravirt_callee_save make_pud;
17434
17435 void (*set_pgd)(pgd_t *pudp, pgd_t pgdval);
17436 + void (*set_pgd_batched)(pgd_t *pudp, pgd_t pgdval);
17437 #endif /* PAGETABLE_LEVELS == 4 */
17438 #endif /* PAGETABLE_LEVELS >= 3 */
17439
17440 @@ -324,7 +325,13 @@ struct pv_mmu_ops {
17441 an mfn. We can tell which is which from the index. */
17442 void (*set_fixmap)(unsigned /* enum fixed_addresses */ idx,
17443 phys_addr_t phys, pgprot_t flags);
17444 -};
17445 +
17446 +#ifdef CONFIG_PAX_KERNEXEC
17447 + unsigned long (*pax_open_kernel)(void);
17448 + unsigned long (*pax_close_kernel)(void);
17449 +#endif
17450 +
17451 +} __no_randomize_layout;
17452
17453 struct arch_spinlock;
17454 #ifdef CONFIG_SMP
17455 @@ -336,11 +343,14 @@ typedef u16 __ticket_t;
17456 struct pv_lock_ops {
17457 struct paravirt_callee_save lock_spinning;
17458 void (*unlock_kick)(struct arch_spinlock *lock, __ticket_t ticket);
17459 -};
17460 +} __no_randomize_layout;
17461
17462 /* This contains all the paravirt structures: we get a convenient
17463 * number for each function using the offset which we use to indicate
17464 - * what to patch. */
17465 + * what to patch.
17466 + * shouldn't be randomized due to the "NEAT TRICK" in paravirt.c
17467 + */
17468 +
17469 struct paravirt_patch_template {
17470 struct pv_init_ops pv_init_ops;
17471 struct pv_time_ops pv_time_ops;
17472 @@ -349,7 +359,7 @@ struct paravirt_patch_template {
17473 struct pv_apic_ops pv_apic_ops;
17474 struct pv_mmu_ops pv_mmu_ops;
17475 struct pv_lock_ops pv_lock_ops;
17476 -};
17477 +} __no_randomize_layout;
17478
17479 extern struct pv_info pv_info;
17480 extern struct pv_init_ops pv_init_ops;
17481 diff --git a/arch/x86/include/asm/pgalloc.h b/arch/x86/include/asm/pgalloc.h
17482 index c4412e9..90e88c5 100644
17483 --- a/arch/x86/include/asm/pgalloc.h
17484 +++ b/arch/x86/include/asm/pgalloc.h
17485 @@ -63,6 +63,13 @@ static inline void pmd_populate_kernel(struct mm_struct *mm,
17486 pmd_t *pmd, pte_t *pte)
17487 {
17488 paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
17489 + set_pmd(pmd, __pmd(__pa(pte) | _KERNPG_TABLE));
17490 +}
17491 +
17492 +static inline void pmd_populate_user(struct mm_struct *mm,
17493 + pmd_t *pmd, pte_t *pte)
17494 +{
17495 + paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
17496 set_pmd(pmd, __pmd(__pa(pte) | _PAGE_TABLE));
17497 }
17498
17499 @@ -108,12 +115,22 @@ static inline void __pmd_free_tlb(struct mmu_gather *tlb, pmd_t *pmd,
17500
17501 #ifdef CONFIG_X86_PAE
17502 extern void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd);
17503 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
17504 +{
17505 + pud_populate(mm, pudp, pmd);
17506 +}
17507 #else /* !CONFIG_X86_PAE */
17508 static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
17509 {
17510 paravirt_alloc_pmd(mm, __pa(pmd) >> PAGE_SHIFT);
17511 set_pud(pud, __pud(_PAGE_TABLE | __pa(pmd)));
17512 }
17513 +
17514 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
17515 +{
17516 + paravirt_alloc_pmd(mm, __pa(pmd) >> PAGE_SHIFT);
17517 + set_pud(pud, __pud(_KERNPG_TABLE | __pa(pmd)));
17518 +}
17519 #endif /* CONFIG_X86_PAE */
17520
17521 #if PAGETABLE_LEVELS > 3
17522 @@ -123,6 +140,12 @@ static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
17523 set_pgd(pgd, __pgd(_PAGE_TABLE | __pa(pud)));
17524 }
17525
17526 +static inline void pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
17527 +{
17528 + paravirt_alloc_pud(mm, __pa(pud) >> PAGE_SHIFT);
17529 + set_pgd(pgd, __pgd(_KERNPG_TABLE | __pa(pud)));
17530 +}
17531 +
17532 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
17533 {
17534 return (pud_t *)get_zeroed_page(GFP_KERNEL|__GFP_REPEAT);
17535 diff --git a/arch/x86/include/asm/pgtable-2level.h b/arch/x86/include/asm/pgtable-2level.h
17536 index 3bf2dd0..23d2a9f 100644
17537 --- a/arch/x86/include/asm/pgtable-2level.h
17538 +++ b/arch/x86/include/asm/pgtable-2level.h
17539 @@ -18,7 +18,9 @@ static inline void native_set_pte(pte_t *ptep , pte_t pte)
17540
17541 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
17542 {
17543 + pax_open_kernel();
17544 *pmdp = pmd;
17545 + pax_close_kernel();
17546 }
17547
17548 static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
17549 diff --git a/arch/x86/include/asm/pgtable-3level.h b/arch/x86/include/asm/pgtable-3level.h
17550 index 81bb91b..9392125 100644
17551 --- a/arch/x86/include/asm/pgtable-3level.h
17552 +++ b/arch/x86/include/asm/pgtable-3level.h
17553 @@ -92,12 +92,16 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
17554
17555 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
17556 {
17557 + pax_open_kernel();
17558 set_64bit((unsigned long long *)(pmdp), native_pmd_val(pmd));
17559 + pax_close_kernel();
17560 }
17561
17562 static inline void native_set_pud(pud_t *pudp, pud_t pud)
17563 {
17564 + pax_open_kernel();
17565 set_64bit((unsigned long long *)(pudp), native_pud_val(pud));
17566 + pax_close_kernel();
17567 }
17568
17569 /*
17570 diff --git a/arch/x86/include/asm/pgtable.h b/arch/x86/include/asm/pgtable.h
17571 index bbc8b12..f228861 100644
17572 --- a/arch/x86/include/asm/pgtable.h
17573 +++ b/arch/x86/include/asm/pgtable.h
17574 @@ -45,6 +45,7 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
17575
17576 #ifndef __PAGETABLE_PUD_FOLDED
17577 #define set_pgd(pgdp, pgd) native_set_pgd(pgdp, pgd)
17578 +#define set_pgd_batched(pgdp, pgd) native_set_pgd_batched(pgdp, pgd)
17579 #define pgd_clear(pgd) native_pgd_clear(pgd)
17580 #endif
17581
17582 @@ -82,12 +83,51 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
17583
17584 #define arch_end_context_switch(prev) do {} while(0)
17585
17586 +#define pax_open_kernel() native_pax_open_kernel()
17587 +#define pax_close_kernel() native_pax_close_kernel()
17588 #endif /* CONFIG_PARAVIRT */
17589
17590 +#define __HAVE_ARCH_PAX_OPEN_KERNEL
17591 +#define __HAVE_ARCH_PAX_CLOSE_KERNEL
17592 +
17593 +#ifdef CONFIG_PAX_KERNEXEC
17594 +static inline unsigned long native_pax_open_kernel(void)
17595 +{
17596 + unsigned long cr0;
17597 +
17598 + preempt_disable();
17599 + barrier();
17600 + cr0 = read_cr0() ^ X86_CR0_WP;
17601 + BUG_ON(cr0 & X86_CR0_WP);
17602 + write_cr0(cr0);
17603 + return cr0 ^ X86_CR0_WP;
17604 +}
17605 +
17606 +static inline unsigned long native_pax_close_kernel(void)
17607 +{
17608 + unsigned long cr0;
17609 +
17610 + cr0 = read_cr0() ^ X86_CR0_WP;
17611 + BUG_ON(!(cr0 & X86_CR0_WP));
17612 + write_cr0(cr0);
17613 + barrier();
17614 + preempt_enable_no_resched();
17615 + return cr0 ^ X86_CR0_WP;
17616 +}
17617 +#else
17618 +static inline unsigned long native_pax_open_kernel(void) { return 0; }
17619 +static inline unsigned long native_pax_close_kernel(void) { return 0; }
17620 +#endif
17621 +
17622 /*
17623 * The following only work if pte_present() is true.
17624 * Undefined behaviour if not..
17625 */
17626 +static inline int pte_user(pte_t pte)
17627 +{
17628 + return pte_val(pte) & _PAGE_USER;
17629 +}
17630 +
17631 static inline int pte_dirty(pte_t pte)
17632 {
17633 return pte_flags(pte) & _PAGE_DIRTY;
17634 @@ -148,6 +188,11 @@ static inline unsigned long pud_pfn(pud_t pud)
17635 return (pud_val(pud) & PTE_PFN_MASK) >> PAGE_SHIFT;
17636 }
17637
17638 +static inline unsigned long pgd_pfn(pgd_t pgd)
17639 +{
17640 + return (pgd_val(pgd) & PTE_PFN_MASK) >> PAGE_SHIFT;
17641 +}
17642 +
17643 #define pte_page(pte) pfn_to_page(pte_pfn(pte))
17644
17645 static inline int pmd_large(pmd_t pte)
17646 @@ -201,9 +246,29 @@ static inline pte_t pte_wrprotect(pte_t pte)
17647 return pte_clear_flags(pte, _PAGE_RW);
17648 }
17649
17650 +static inline pte_t pte_mkread(pte_t pte)
17651 +{
17652 + return __pte(pte_val(pte) | _PAGE_USER);
17653 +}
17654 +
17655 static inline pte_t pte_mkexec(pte_t pte)
17656 {
17657 - return pte_clear_flags(pte, _PAGE_NX);
17658 +#ifdef CONFIG_X86_PAE
17659 + if (__supported_pte_mask & _PAGE_NX)
17660 + return pte_clear_flags(pte, _PAGE_NX);
17661 + else
17662 +#endif
17663 + return pte_set_flags(pte, _PAGE_USER);
17664 +}
17665 +
17666 +static inline pte_t pte_exprotect(pte_t pte)
17667 +{
17668 +#ifdef CONFIG_X86_PAE
17669 + if (__supported_pte_mask & _PAGE_NX)
17670 + return pte_set_flags(pte, _PAGE_NX);
17671 + else
17672 +#endif
17673 + return pte_clear_flags(pte, _PAGE_USER);
17674 }
17675
17676 static inline pte_t pte_mkdirty(pte_t pte)
17677 @@ -430,6 +495,16 @@ pte_t *populate_extra_pte(unsigned long vaddr);
17678 #endif
17679
17680 #ifndef __ASSEMBLY__
17681 +
17682 +#ifdef CONFIG_PAX_PER_CPU_PGD
17683 +extern pgd_t cpu_pgd[NR_CPUS][2][PTRS_PER_PGD];
17684 +enum cpu_pgd_type {kernel = 0, user = 1};
17685 +static inline pgd_t *get_cpu_pgd(unsigned int cpu, enum cpu_pgd_type type)
17686 +{
17687 + return cpu_pgd[cpu][type];
17688 +}
17689 +#endif
17690 +
17691 #include <linux/mm_types.h>
17692 #include <linux/mmdebug.h>
17693 #include <linux/log2.h>
17694 @@ -570,7 +645,7 @@ static inline unsigned long pud_page_vaddr(pud_t pud)
17695 * Currently stuck as a macro due to indirect forward reference to
17696 * linux/mmzone.h's __section_mem_map_addr() definition:
17697 */
17698 -#define pud_page(pud) pfn_to_page(pud_val(pud) >> PAGE_SHIFT)
17699 +#define pud_page(pud) pfn_to_page((pud_val(pud) & PTE_PFN_MASK) >> PAGE_SHIFT)
17700
17701 /* Find an entry in the second-level page table.. */
17702 static inline pmd_t *pmd_offset(pud_t *pud, unsigned long address)
17703 @@ -610,7 +685,7 @@ static inline unsigned long pgd_page_vaddr(pgd_t pgd)
17704 * Currently stuck as a macro due to indirect forward reference to
17705 * linux/mmzone.h's __section_mem_map_addr() definition:
17706 */
17707 -#define pgd_page(pgd) pfn_to_page(pgd_val(pgd) >> PAGE_SHIFT)
17708 +#define pgd_page(pgd) pfn_to_page((pgd_val(pgd) & PTE_PFN_MASK) >> PAGE_SHIFT)
17709
17710 /* to find an entry in a page-table-directory. */
17711 static inline unsigned long pud_index(unsigned long address)
17712 @@ -625,7 +700,7 @@ static inline pud_t *pud_offset(pgd_t *pgd, unsigned long address)
17713
17714 static inline int pgd_bad(pgd_t pgd)
17715 {
17716 - return (pgd_flags(pgd) & ~_PAGE_USER) != _KERNPG_TABLE;
17717 + return (pgd_flags(pgd) & ~(_PAGE_USER | _PAGE_NX)) != _KERNPG_TABLE;
17718 }
17719
17720 static inline int pgd_none(pgd_t pgd)
17721 @@ -648,7 +723,12 @@ static inline int pgd_none(pgd_t pgd)
17722 * pgd_offset() returns a (pgd_t *)
17723 * pgd_index() is used get the offset into the pgd page's array of pgd_t's;
17724 */
17725 -#define pgd_offset(mm, address) ((mm)->pgd + pgd_index((address)))
17726 +#define pgd_offset(mm, address) ((mm)->pgd + pgd_index(address))
17727 +
17728 +#ifdef CONFIG_PAX_PER_CPU_PGD
17729 +#define pgd_offset_cpu(cpu, type, address) (get_cpu_pgd(cpu, type) + pgd_index(address))
17730 +#endif
17731 +
17732 /*
17733 * a shortcut which implies the use of the kernel's pgd, instead
17734 * of a process's
17735 @@ -659,6 +739,23 @@ static inline int pgd_none(pgd_t pgd)
17736 #define KERNEL_PGD_BOUNDARY pgd_index(PAGE_OFFSET)
17737 #define KERNEL_PGD_PTRS (PTRS_PER_PGD - KERNEL_PGD_BOUNDARY)
17738
17739 +#ifdef CONFIG_X86_32
17740 +#define USER_PGD_PTRS KERNEL_PGD_BOUNDARY
17741 +#else
17742 +#define TASK_SIZE_MAX_SHIFT CONFIG_TASK_SIZE_MAX_SHIFT
17743 +#define USER_PGD_PTRS (_AC(1,UL) << (TASK_SIZE_MAX_SHIFT - PGDIR_SHIFT))
17744 +
17745 +#ifdef CONFIG_PAX_MEMORY_UDEREF
17746 +#ifdef __ASSEMBLY__
17747 +#define pax_user_shadow_base pax_user_shadow_base(%rip)
17748 +#else
17749 +extern unsigned long pax_user_shadow_base;
17750 +extern pgdval_t clone_pgd_mask;
17751 +#endif
17752 +#endif
17753 +
17754 +#endif
17755 +
17756 #ifndef __ASSEMBLY__
17757
17758 extern int direct_gbpages;
17759 @@ -825,11 +922,24 @@ static inline void pmdp_set_wrprotect(struct mm_struct *mm,
17760 * dst and src can be on the same page, but the range must not overlap,
17761 * and must not cross a page boundary.
17762 */
17763 -static inline void clone_pgd_range(pgd_t *dst, pgd_t *src, int count)
17764 +static inline void clone_pgd_range(pgd_t *dst, const pgd_t *src, int count)
17765 {
17766 - memcpy(dst, src, count * sizeof(pgd_t));
17767 + pax_open_kernel();
17768 + while (count--)
17769 + *dst++ = *src++;
17770 + pax_close_kernel();
17771 }
17772
17773 +#ifdef CONFIG_PAX_PER_CPU_PGD
17774 +extern void __clone_user_pgds(pgd_t *dst, const pgd_t *src);
17775 +#endif
17776 +
17777 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17778 +extern void __shadow_user_pgds(pgd_t *dst, const pgd_t *src);
17779 +#else
17780 +static inline void __shadow_user_pgds(pgd_t *dst, const pgd_t *src) {}
17781 +#endif
17782 +
17783 #define PTE_SHIFT ilog2(PTRS_PER_PTE)
17784 static inline int page_level_shift(enum pg_level level)
17785 {
17786 diff --git a/arch/x86/include/asm/pgtable_32.h b/arch/x86/include/asm/pgtable_32.h
17787 index 9ee3221..b979c6b 100644
17788 --- a/arch/x86/include/asm/pgtable_32.h
17789 +++ b/arch/x86/include/asm/pgtable_32.h
17790 @@ -25,9 +25,6 @@
17791 struct mm_struct;
17792 struct vm_area_struct;
17793
17794 -extern pgd_t swapper_pg_dir[1024];
17795 -extern pgd_t initial_page_table[1024];
17796 -
17797 static inline void pgtable_cache_init(void) { }
17798 static inline void check_pgt_cache(void) { }
17799 void paging_init(void);
17800 @@ -48,6 +45,12 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
17801 # include <asm/pgtable-2level.h>
17802 #endif
17803
17804 +extern pgd_t swapper_pg_dir[PTRS_PER_PGD];
17805 +extern pgd_t initial_page_table[PTRS_PER_PGD];
17806 +#ifdef CONFIG_X86_PAE
17807 +extern pmd_t swapper_pm_dir[PTRS_PER_PGD][PTRS_PER_PMD];
17808 +#endif
17809 +
17810 #if defined(CONFIG_HIGHPTE)
17811 #define pte_offset_map(dir, address) \
17812 ((pte_t *)kmap_atomic(pmd_page(*(dir))) + \
17813 @@ -62,12 +65,17 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
17814 /* Clear a kernel PTE and flush it from the TLB */
17815 #define kpte_clear_flush(ptep, vaddr) \
17816 do { \
17817 + pax_open_kernel(); \
17818 pte_clear(&init_mm, (vaddr), (ptep)); \
17819 + pax_close_kernel(); \
17820 __flush_tlb_one((vaddr)); \
17821 } while (0)
17822
17823 #endif /* !__ASSEMBLY__ */
17824
17825 +#define HAVE_ARCH_UNMAPPED_AREA
17826 +#define HAVE_ARCH_UNMAPPED_AREA_TOPDOWN
17827 +
17828 /*
17829 * kern_addr_valid() is (1) for FLATMEM and (0) for
17830 * SPARSEMEM and DISCONTIGMEM
17831 diff --git a/arch/x86/include/asm/pgtable_32_types.h b/arch/x86/include/asm/pgtable_32_types.h
17832 index ed5903b..c7fe163 100644
17833 --- a/arch/x86/include/asm/pgtable_32_types.h
17834 +++ b/arch/x86/include/asm/pgtable_32_types.h
17835 @@ -8,7 +8,7 @@
17836 */
17837 #ifdef CONFIG_X86_PAE
17838 # include <asm/pgtable-3level_types.h>
17839 -# define PMD_SIZE (1UL << PMD_SHIFT)
17840 +# define PMD_SIZE (_AC(1, UL) << PMD_SHIFT)
17841 # define PMD_MASK (~(PMD_SIZE - 1))
17842 #else
17843 # include <asm/pgtable-2level_types.h>
17844 @@ -46,6 +46,19 @@ extern bool __vmalloc_start_set; /* set once high_memory is set */
17845 # define VMALLOC_END (FIXADDR_START - 2 * PAGE_SIZE)
17846 #endif
17847
17848 +#ifdef CONFIG_PAX_KERNEXEC
17849 +#ifndef __ASSEMBLY__
17850 +extern unsigned char MODULES_EXEC_VADDR[];
17851 +extern unsigned char MODULES_EXEC_END[];
17852 +#endif
17853 +#include <asm/boot.h>
17854 +#define ktla_ktva(addr) (addr + LOAD_PHYSICAL_ADDR + PAGE_OFFSET)
17855 +#define ktva_ktla(addr) (addr - LOAD_PHYSICAL_ADDR - PAGE_OFFSET)
17856 +#else
17857 +#define ktla_ktva(addr) (addr)
17858 +#define ktva_ktla(addr) (addr)
17859 +#endif
17860 +
17861 #define MODULES_VADDR VMALLOC_START
17862 #define MODULES_END VMALLOC_END
17863 #define MODULES_LEN (MODULES_VADDR - MODULES_END)
17864 diff --git a/arch/x86/include/asm/pgtable_64.h b/arch/x86/include/asm/pgtable_64.h
17865 index e22c1db..23a625a 100644
17866 --- a/arch/x86/include/asm/pgtable_64.h
17867 +++ b/arch/x86/include/asm/pgtable_64.h
17868 @@ -16,10 +16,14 @@
17869
17870 extern pud_t level3_kernel_pgt[512];
17871 extern pud_t level3_ident_pgt[512];
17872 +extern pud_t level3_vmalloc_start_pgt[512];
17873 +extern pud_t level3_vmalloc_end_pgt[512];
17874 +extern pud_t level3_vmemmap_pgt[512];
17875 +extern pud_t level2_vmemmap_pgt[512];
17876 extern pmd_t level2_kernel_pgt[512];
17877 extern pmd_t level2_fixmap_pgt[512];
17878 -extern pmd_t level2_ident_pgt[512];
17879 -extern pgd_t init_level4_pgt[];
17880 +extern pmd_t level2_ident_pgt[512*2];
17881 +extern pgd_t init_level4_pgt[512];
17882
17883 #define swapper_pg_dir init_level4_pgt
17884
17885 @@ -61,7 +65,9 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
17886
17887 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
17888 {
17889 + pax_open_kernel();
17890 *pmdp = pmd;
17891 + pax_close_kernel();
17892 }
17893
17894 static inline void native_pmd_clear(pmd_t *pmd)
17895 @@ -97,7 +103,9 @@ static inline pmd_t native_pmdp_get_and_clear(pmd_t *xp)
17896
17897 static inline void native_set_pud(pud_t *pudp, pud_t pud)
17898 {
17899 + pax_open_kernel();
17900 *pudp = pud;
17901 + pax_close_kernel();
17902 }
17903
17904 static inline void native_pud_clear(pud_t *pud)
17905 @@ -107,6 +115,13 @@ static inline void native_pud_clear(pud_t *pud)
17906
17907 static inline void native_set_pgd(pgd_t *pgdp, pgd_t pgd)
17908 {
17909 + pax_open_kernel();
17910 + *pgdp = pgd;
17911 + pax_close_kernel();
17912 +}
17913 +
17914 +static inline void native_set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
17915 +{
17916 *pgdp = pgd;
17917 }
17918
17919 diff --git a/arch/x86/include/asm/pgtable_64_types.h b/arch/x86/include/asm/pgtable_64_types.h
17920 index 2d88344..4679fc3 100644
17921 --- a/arch/x86/include/asm/pgtable_64_types.h
17922 +++ b/arch/x86/include/asm/pgtable_64_types.h
17923 @@ -61,6 +61,11 @@ typedef struct { pteval_t pte; } pte_t;
17924 #define MODULES_VADDR _AC(0xffffffffa0000000, UL)
17925 #define MODULES_END _AC(0xffffffffff000000, UL)
17926 #define MODULES_LEN (MODULES_END - MODULES_VADDR)
17927 +#define MODULES_EXEC_VADDR MODULES_VADDR
17928 +#define MODULES_EXEC_END MODULES_END
17929 +
17930 +#define ktla_ktva(addr) (addr)
17931 +#define ktva_ktla(addr) (addr)
17932
17933 #define EARLY_DYNAMIC_PAGE_TABLES 64
17934
17935 diff --git a/arch/x86/include/asm/pgtable_types.h b/arch/x86/include/asm/pgtable_types.h
17936 index 840c127..a8f297b 100644
17937 --- a/arch/x86/include/asm/pgtable_types.h
17938 +++ b/arch/x86/include/asm/pgtable_types.h
17939 @@ -16,13 +16,12 @@
17940 #define _PAGE_BIT_PSE 7 /* 4 MB (or 2MB) page */
17941 #define _PAGE_BIT_PAT 7 /* on 4KB pages */
17942 #define _PAGE_BIT_GLOBAL 8 /* Global TLB entry PPro+ */
17943 -#define _PAGE_BIT_UNUSED1 9 /* available for programmer */
17944 +#define _PAGE_BIT_SPECIAL 9 /* special mappings, no associated struct page */
17945 #define _PAGE_BIT_IOMAP 10 /* flag used to indicate IO mapping */
17946 #define _PAGE_BIT_HIDDEN 11 /* hidden by kmemcheck */
17947 #define _PAGE_BIT_PAT_LARGE 12 /* On 2MB or 1GB pages */
17948 -#define _PAGE_BIT_SPECIAL _PAGE_BIT_UNUSED1
17949 -#define _PAGE_BIT_CPA_TEST _PAGE_BIT_UNUSED1
17950 -#define _PAGE_BIT_SPLITTING _PAGE_BIT_UNUSED1 /* only valid on a PSE pmd */
17951 +#define _PAGE_BIT_CPA_TEST _PAGE_BIT_SPECIAL
17952 +#define _PAGE_BIT_SPLITTING _PAGE_BIT_SPECIAL /* only valid on a PSE pmd */
17953 #define _PAGE_BIT_NX 63 /* No execute: only valid after cpuid check */
17954
17955 /* If _PAGE_BIT_PRESENT is clear, we use these: */
17956 @@ -40,7 +39,6 @@
17957 #define _PAGE_DIRTY (_AT(pteval_t, 1) << _PAGE_BIT_DIRTY)
17958 #define _PAGE_PSE (_AT(pteval_t, 1) << _PAGE_BIT_PSE)
17959 #define _PAGE_GLOBAL (_AT(pteval_t, 1) << _PAGE_BIT_GLOBAL)
17960 -#define _PAGE_UNUSED1 (_AT(pteval_t, 1) << _PAGE_BIT_UNUSED1)
17961 #define _PAGE_IOMAP (_AT(pteval_t, 1) << _PAGE_BIT_IOMAP)
17962 #define _PAGE_PAT (_AT(pteval_t, 1) << _PAGE_BIT_PAT)
17963 #define _PAGE_PAT_LARGE (_AT(pteval_t, 1) << _PAGE_BIT_PAT_LARGE)
17964 @@ -87,8 +85,10 @@
17965
17966 #if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
17967 #define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_NX)
17968 -#else
17969 +#elif defined(CONFIG_KMEMCHECK) || defined(CONFIG_MEM_SOFT_DIRTY)
17970 #define _PAGE_NX (_AT(pteval_t, 0))
17971 +#else
17972 +#define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_HIDDEN)
17973 #endif
17974
17975 #define _PAGE_FILE (_AT(pteval_t, 1) << _PAGE_BIT_FILE)
17976 @@ -147,6 +147,9 @@
17977 #define PAGE_READONLY_EXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | \
17978 _PAGE_ACCESSED)
17979
17980 +#define PAGE_READONLY_NOEXEC PAGE_READONLY
17981 +#define PAGE_SHARED_NOEXEC PAGE_SHARED
17982 +
17983 #define __PAGE_KERNEL_EXEC \
17984 (_PAGE_PRESENT | _PAGE_RW | _PAGE_DIRTY | _PAGE_ACCESSED | _PAGE_GLOBAL)
17985 #define __PAGE_KERNEL (__PAGE_KERNEL_EXEC | _PAGE_NX)
17986 @@ -157,7 +160,7 @@
17987 #define __PAGE_KERNEL_WC (__PAGE_KERNEL | _PAGE_CACHE_WC)
17988 #define __PAGE_KERNEL_NOCACHE (__PAGE_KERNEL | _PAGE_PCD | _PAGE_PWT)
17989 #define __PAGE_KERNEL_UC_MINUS (__PAGE_KERNEL | _PAGE_PCD)
17990 -#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RX | _PAGE_USER)
17991 +#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RO | _PAGE_USER)
17992 #define __PAGE_KERNEL_VVAR (__PAGE_KERNEL_RO | _PAGE_USER)
17993 #define __PAGE_KERNEL_VVAR_NOCACHE (__PAGE_KERNEL_VVAR | _PAGE_PCD | _PAGE_PWT)
17994 #define __PAGE_KERNEL_LARGE (__PAGE_KERNEL | _PAGE_PSE)
17995 @@ -219,8 +222,8 @@
17996 * bits are combined, this will alow user to access the high address mapped
17997 * VDSO in the presence of CONFIG_COMPAT_VDSO
17998 */
17999 -#define PTE_IDENT_ATTR 0x003 /* PRESENT+RW */
18000 -#define PDE_IDENT_ATTR 0x067 /* PRESENT+RW+USER+DIRTY+ACCESSED */
18001 +#define PTE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
18002 +#define PDE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
18003 #define PGD_IDENT_ATTR 0x001 /* PRESENT (no other attributes) */
18004 #endif
18005
18006 @@ -258,7 +261,17 @@ static inline pgdval_t pgd_flags(pgd_t pgd)
18007 {
18008 return native_pgd_val(pgd) & PTE_FLAGS_MASK;
18009 }
18010 +#endif
18011
18012 +#if PAGETABLE_LEVELS == 3
18013 +#include <asm-generic/pgtable-nopud.h>
18014 +#endif
18015 +
18016 +#if PAGETABLE_LEVELS == 2
18017 +#include <asm-generic/pgtable-nopmd.h>
18018 +#endif
18019 +
18020 +#ifndef __ASSEMBLY__
18021 #if PAGETABLE_LEVELS > 3
18022 typedef struct { pudval_t pud; } pud_t;
18023
18024 @@ -272,8 +285,6 @@ static inline pudval_t native_pud_val(pud_t pud)
18025 return pud.pud;
18026 }
18027 #else
18028 -#include <asm-generic/pgtable-nopud.h>
18029 -
18030 static inline pudval_t native_pud_val(pud_t pud)
18031 {
18032 return native_pgd_val(pud.pgd);
18033 @@ -293,8 +304,6 @@ static inline pmdval_t native_pmd_val(pmd_t pmd)
18034 return pmd.pmd;
18035 }
18036 #else
18037 -#include <asm-generic/pgtable-nopmd.h>
18038 -
18039 static inline pmdval_t native_pmd_val(pmd_t pmd)
18040 {
18041 return native_pgd_val(pmd.pud.pgd);
18042 @@ -334,7 +343,6 @@ typedef struct page *pgtable_t;
18043
18044 extern pteval_t __supported_pte_mask;
18045 extern void set_nx(void);
18046 -extern int nx_enabled;
18047
18048 #define pgprot_writecombine pgprot_writecombine
18049 extern pgprot_t pgprot_writecombine(pgprot_t prot);
18050 diff --git a/arch/x86/include/asm/preempt.h b/arch/x86/include/asm/preempt.h
18051 index c8b0519..fd29e73 100644
18052 --- a/arch/x86/include/asm/preempt.h
18053 +++ b/arch/x86/include/asm/preempt.h
18054 @@ -87,7 +87,7 @@ static __always_inline void __preempt_count_sub(int val)
18055 */
18056 static __always_inline bool __preempt_count_dec_and_test(void)
18057 {
18058 - GEN_UNARY_RMWcc("decl", __preempt_count, __percpu_arg(0), "e");
18059 + GEN_UNARY_RMWcc("decl", "incl", __preempt_count, __percpu_arg(0), "e");
18060 }
18061
18062 /*
18063 diff --git a/arch/x86/include/asm/processor.h b/arch/x86/include/asm/processor.h
18064 index 7b034a4..4fe3e3f 100644
18065 --- a/arch/x86/include/asm/processor.h
18066 +++ b/arch/x86/include/asm/processor.h
18067 @@ -128,7 +128,7 @@ struct cpuinfo_x86 {
18068 /* Index into per_cpu list: */
18069 u16 cpu_index;
18070 u32 microcode;
18071 -} __attribute__((__aligned__(SMP_CACHE_BYTES)));
18072 +} __attribute__((__aligned__(SMP_CACHE_BYTES))) __randomize_layout;
18073
18074 #define X86_VENDOR_INTEL 0
18075 #define X86_VENDOR_CYRIX 1
18076 @@ -199,9 +199,21 @@ static inline void native_cpuid(unsigned int *eax, unsigned int *ebx,
18077 : "memory");
18078 }
18079
18080 +/* invpcid (%rdx),%rax */
18081 +#define __ASM_INVPCID ".byte 0x66,0x0f,0x38,0x82,0x02"
18082 +
18083 +#define INVPCID_SINGLE_ADDRESS 0UL
18084 +#define INVPCID_SINGLE_CONTEXT 1UL
18085 +#define INVPCID_ALL_GLOBAL 2UL
18086 +#define INVPCID_ALL_MONGLOBAL 3UL
18087 +
18088 +#define PCID_KERNEL 0UL
18089 +#define PCID_USER 1UL
18090 +#define PCID_NOFLUSH (1UL << 63)
18091 +
18092 static inline void load_cr3(pgd_t *pgdir)
18093 {
18094 - write_cr3(__pa(pgdir));
18095 + write_cr3(__pa(pgdir) | PCID_KERNEL);
18096 }
18097
18098 #ifdef CONFIG_X86_32
18099 @@ -283,7 +295,7 @@ struct tss_struct {
18100
18101 } ____cacheline_aligned;
18102
18103 -DECLARE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss);
18104 +extern struct tss_struct init_tss[NR_CPUS];
18105
18106 /*
18107 * Save the original ist values for checking stack pointers during debugging
18108 @@ -453,6 +465,7 @@ struct thread_struct {
18109 unsigned short ds;
18110 unsigned short fsindex;
18111 unsigned short gsindex;
18112 + unsigned short ss;
18113 #endif
18114 #ifdef CONFIG_X86_32
18115 unsigned long ip;
18116 @@ -562,29 +575,8 @@ static inline void load_sp0(struct tss_struct *tss,
18117 extern unsigned long mmu_cr4_features;
18118 extern u32 *trampoline_cr4_features;
18119
18120 -static inline void set_in_cr4(unsigned long mask)
18121 -{
18122 - unsigned long cr4;
18123 -
18124 - mmu_cr4_features |= mask;
18125 - if (trampoline_cr4_features)
18126 - *trampoline_cr4_features = mmu_cr4_features;
18127 - cr4 = read_cr4();
18128 - cr4 |= mask;
18129 - write_cr4(cr4);
18130 -}
18131 -
18132 -static inline void clear_in_cr4(unsigned long mask)
18133 -{
18134 - unsigned long cr4;
18135 -
18136 - mmu_cr4_features &= ~mask;
18137 - if (trampoline_cr4_features)
18138 - *trampoline_cr4_features = mmu_cr4_features;
18139 - cr4 = read_cr4();
18140 - cr4 &= ~mask;
18141 - write_cr4(cr4);
18142 -}
18143 +extern void set_in_cr4(unsigned long mask);
18144 +extern void clear_in_cr4(unsigned long mask);
18145
18146 typedef struct {
18147 unsigned long seg;
18148 @@ -833,11 +825,18 @@ static inline void spin_lock_prefetch(const void *x)
18149 */
18150 #define TASK_SIZE PAGE_OFFSET
18151 #define TASK_SIZE_MAX TASK_SIZE
18152 +
18153 +#ifdef CONFIG_PAX_SEGMEXEC
18154 +#define SEGMEXEC_TASK_SIZE (TASK_SIZE / 2)
18155 +#define STACK_TOP ((current->mm->pax_flags & MF_PAX_SEGMEXEC)?SEGMEXEC_TASK_SIZE:TASK_SIZE)
18156 +#else
18157 #define STACK_TOP TASK_SIZE
18158 -#define STACK_TOP_MAX STACK_TOP
18159 +#endif
18160 +
18161 +#define STACK_TOP_MAX TASK_SIZE
18162
18163 #define INIT_THREAD { \
18164 - .sp0 = sizeof(init_stack) + (long)&init_stack, \
18165 + .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
18166 .vm86_info = NULL, \
18167 .sysenter_cs = __KERNEL_CS, \
18168 .io_bitmap_ptr = NULL, \
18169 @@ -851,7 +850,7 @@ static inline void spin_lock_prefetch(const void *x)
18170 */
18171 #define INIT_TSS { \
18172 .x86_tss = { \
18173 - .sp0 = sizeof(init_stack) + (long)&init_stack, \
18174 + .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
18175 .ss0 = __KERNEL_DS, \
18176 .ss1 = __KERNEL_CS, \
18177 .io_bitmap_base = INVALID_IO_BITMAP_OFFSET, \
18178 @@ -862,11 +861,7 @@ static inline void spin_lock_prefetch(const void *x)
18179 extern unsigned long thread_saved_pc(struct task_struct *tsk);
18180
18181 #define THREAD_SIZE_LONGS (THREAD_SIZE/sizeof(unsigned long))
18182 -#define KSTK_TOP(info) \
18183 -({ \
18184 - unsigned long *__ptr = (unsigned long *)(info); \
18185 - (unsigned long)(&__ptr[THREAD_SIZE_LONGS]); \
18186 -})
18187 +#define KSTK_TOP(info) ((container_of(info, struct task_struct, tinfo))->thread.sp0)
18188
18189 /*
18190 * The below -8 is to reserve 8 bytes on top of the ring0 stack.
18191 @@ -881,7 +876,7 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
18192 #define task_pt_regs(task) \
18193 ({ \
18194 struct pt_regs *__regs__; \
18195 - __regs__ = (struct pt_regs *)(KSTK_TOP(task_stack_page(task))-8); \
18196 + __regs__ = (struct pt_regs *)((task)->thread.sp0); \
18197 __regs__ - 1; \
18198 })
18199
18200 @@ -891,13 +886,13 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
18201 /*
18202 * User space process size. 47bits minus one guard page.
18203 */
18204 -#define TASK_SIZE_MAX ((1UL << 47) - PAGE_SIZE)
18205 +#define TASK_SIZE_MAX ((1UL << TASK_SIZE_MAX_SHIFT) - PAGE_SIZE)
18206
18207 /* This decides where the kernel will search for a free chunk of vm
18208 * space during mmap's.
18209 */
18210 #define IA32_PAGE_OFFSET ((current->personality & ADDR_LIMIT_3GB) ? \
18211 - 0xc0000000 : 0xFFFFe000)
18212 + 0xc0000000 : 0xFFFFf000)
18213
18214 #define TASK_SIZE (test_thread_flag(TIF_ADDR32) ? \
18215 IA32_PAGE_OFFSET : TASK_SIZE_MAX)
18216 @@ -908,11 +903,11 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
18217 #define STACK_TOP_MAX TASK_SIZE_MAX
18218
18219 #define INIT_THREAD { \
18220 - .sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
18221 + .sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
18222 }
18223
18224 #define INIT_TSS { \
18225 - .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
18226 + .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
18227 }
18228
18229 /*
18230 @@ -940,6 +935,10 @@ extern void start_thread(struct pt_regs *regs, unsigned long new_ip,
18231 */
18232 #define TASK_UNMAPPED_BASE (PAGE_ALIGN(TASK_SIZE / 3))
18233
18234 +#ifdef CONFIG_PAX_SEGMEXEC
18235 +#define SEGMEXEC_TASK_UNMAPPED_BASE (PAGE_ALIGN(SEGMEXEC_TASK_SIZE / 3))
18236 +#endif
18237 +
18238 #define KSTK_EIP(task) (task_pt_regs(task)->ip)
18239
18240 /* Get/set a process' ability to use the timestamp counter instruction */
18241 @@ -966,7 +965,7 @@ static inline uint32_t hypervisor_cpuid_base(const char *sig, uint32_t leaves)
18242 return 0;
18243 }
18244
18245 -extern unsigned long arch_align_stack(unsigned long sp);
18246 +#define arch_align_stack(x) ((x) & ~0xfUL)
18247 extern void free_init_pages(char *what, unsigned long begin, unsigned long end);
18248
18249 void default_idle(void);
18250 @@ -976,6 +975,6 @@ bool xen_set_default_idle(void);
18251 #define xen_set_default_idle 0
18252 #endif
18253
18254 -void stop_this_cpu(void *dummy);
18255 +void stop_this_cpu(void *dummy) __noreturn;
18256 void df_debug(struct pt_regs *regs, long error_code);
18257 #endif /* _ASM_X86_PROCESSOR_H */
18258 diff --git a/arch/x86/include/asm/ptrace.h b/arch/x86/include/asm/ptrace.h
18259 index 942a086..6c26446 100644
18260 --- a/arch/x86/include/asm/ptrace.h
18261 +++ b/arch/x86/include/asm/ptrace.h
18262 @@ -85,28 +85,29 @@ static inline unsigned long regs_return_value(struct pt_regs *regs)
18263 }
18264
18265 /*
18266 - * user_mode_vm(regs) determines whether a register set came from user mode.
18267 + * user_mode(regs) determines whether a register set came from user mode.
18268 * This is true if V8086 mode was enabled OR if the register set was from
18269 * protected mode with RPL-3 CS value. This tricky test checks that with
18270 * one comparison. Many places in the kernel can bypass this full check
18271 - * if they have already ruled out V8086 mode, so user_mode(regs) can be used.
18272 + * if they have already ruled out V8086 mode, so user_mode_novm(regs) can
18273 + * be used.
18274 */
18275 -static inline int user_mode(struct pt_regs *regs)
18276 +static inline int user_mode_novm(struct pt_regs *regs)
18277 {
18278 #ifdef CONFIG_X86_32
18279 return (regs->cs & SEGMENT_RPL_MASK) == USER_RPL;
18280 #else
18281 - return !!(regs->cs & 3);
18282 + return !!(regs->cs & SEGMENT_RPL_MASK);
18283 #endif
18284 }
18285
18286 -static inline int user_mode_vm(struct pt_regs *regs)
18287 +static inline int user_mode(struct pt_regs *regs)
18288 {
18289 #ifdef CONFIG_X86_32
18290 return ((regs->cs & SEGMENT_RPL_MASK) | (regs->flags & X86_VM_MASK)) >=
18291 USER_RPL;
18292 #else
18293 - return user_mode(regs);
18294 + return user_mode_novm(regs);
18295 #endif
18296 }
18297
18298 @@ -122,15 +123,16 @@ static inline int v8086_mode(struct pt_regs *regs)
18299 #ifdef CONFIG_X86_64
18300 static inline bool user_64bit_mode(struct pt_regs *regs)
18301 {
18302 + unsigned long cs = regs->cs & 0xffff;
18303 #ifndef CONFIG_PARAVIRT
18304 /*
18305 * On non-paravirt systems, this is the only long mode CPL 3
18306 * selector. We do not allow long mode selectors in the LDT.
18307 */
18308 - return regs->cs == __USER_CS;
18309 + return cs == __USER_CS;
18310 #else
18311 /* Headers are too twisted for this to go in paravirt.h. */
18312 - return regs->cs == __USER_CS || regs->cs == pv_info.extra_user_64bit_cs;
18313 + return cs == __USER_CS || cs == pv_info.extra_user_64bit_cs;
18314 #endif
18315 }
18316
18317 @@ -181,9 +183,11 @@ static inline unsigned long regs_get_register(struct pt_regs *regs,
18318 * Traps from the kernel do not save sp and ss.
18319 * Use the helper function to retrieve sp.
18320 */
18321 - if (offset == offsetof(struct pt_regs, sp) &&
18322 - regs->cs == __KERNEL_CS)
18323 - return kernel_stack_pointer(regs);
18324 + if (offset == offsetof(struct pt_regs, sp)) {
18325 + unsigned long cs = regs->cs & 0xffff;
18326 + if (cs == __KERNEL_CS || cs == __KERNEXEC_KERNEL_CS)
18327 + return kernel_stack_pointer(regs);
18328 + }
18329 #endif
18330 return *(unsigned long *)((unsigned long)regs + offset);
18331 }
18332 diff --git a/arch/x86/include/asm/realmode.h b/arch/x86/include/asm/realmode.h
18333 index 9c6b890..5305f53 100644
18334 --- a/arch/x86/include/asm/realmode.h
18335 +++ b/arch/x86/include/asm/realmode.h
18336 @@ -22,16 +22,14 @@ struct real_mode_header {
18337 #endif
18338 /* APM/BIOS reboot */
18339 u32 machine_real_restart_asm;
18340 -#ifdef CONFIG_X86_64
18341 u32 machine_real_restart_seg;
18342 -#endif
18343 };
18344
18345 /* This must match data at trampoline_32/64.S */
18346 struct trampoline_header {
18347 #ifdef CONFIG_X86_32
18348 u32 start;
18349 - u16 gdt_pad;
18350 + u16 boot_cs;
18351 u16 gdt_limit;
18352 u32 gdt_base;
18353 #else
18354 diff --git a/arch/x86/include/asm/reboot.h b/arch/x86/include/asm/reboot.h
18355 index a82c4f1..ac45053 100644
18356 --- a/arch/x86/include/asm/reboot.h
18357 +++ b/arch/x86/include/asm/reboot.h
18358 @@ -6,13 +6,13 @@
18359 struct pt_regs;
18360
18361 struct machine_ops {
18362 - void (*restart)(char *cmd);
18363 - void (*halt)(void);
18364 - void (*power_off)(void);
18365 + void (* __noreturn restart)(char *cmd);
18366 + void (* __noreturn halt)(void);
18367 + void (* __noreturn power_off)(void);
18368 void (*shutdown)(void);
18369 void (*crash_shutdown)(struct pt_regs *);
18370 - void (*emergency_restart)(void);
18371 -};
18372 + void (* __noreturn emergency_restart)(void);
18373 +} __no_const;
18374
18375 extern struct machine_ops machine_ops;
18376
18377 diff --git a/arch/x86/include/asm/rmwcc.h b/arch/x86/include/asm/rmwcc.h
18378 index 8f7866a..e442f20 100644
18379 --- a/arch/x86/include/asm/rmwcc.h
18380 +++ b/arch/x86/include/asm/rmwcc.h
18381 @@ -3,7 +3,34 @@
18382
18383 #ifdef CC_HAVE_ASM_GOTO
18384
18385 -#define __GEN_RMWcc(fullop, var, cc, ...) \
18386 +#ifdef CONFIG_PAX_REFCOUNT
18387 +#define __GEN_RMWcc(fullop, fullantiop, var, cc, ...) \
18388 +do { \
18389 + asm_volatile_goto (fullop \
18390 + ";jno 0f\n" \
18391 + fullantiop \
18392 + ";int $4\n0:\n" \
18393 + _ASM_EXTABLE(0b, 0b) \
18394 + ";j" cc " %l[cc_label]" \
18395 + : : "m" (var), ## __VA_ARGS__ \
18396 + : "memory" : cc_label); \
18397 + return 0; \
18398 +cc_label: \
18399 + return 1; \
18400 +} while (0)
18401 +#else
18402 +#define __GEN_RMWcc(fullop, fullantiop, var, cc, ...) \
18403 +do { \
18404 + asm_volatile_goto (fullop ";j" cc " %l[cc_label]" \
18405 + : : "m" (var), ## __VA_ARGS__ \
18406 + : "memory" : cc_label); \
18407 + return 0; \
18408 +cc_label: \
18409 + return 1; \
18410 +} while (0)
18411 +#endif
18412 +
18413 +#define __GEN_RMWcc_unchecked(fullop, var, cc, ...) \
18414 do { \
18415 asm_volatile_goto (fullop "; j" cc " %l[cc_label]" \
18416 : : "m" (var), ## __VA_ARGS__ \
18417 @@ -13,15 +40,46 @@ cc_label: \
18418 return 1; \
18419 } while (0)
18420
18421 -#define GEN_UNARY_RMWcc(op, var, arg0, cc) \
18422 - __GEN_RMWcc(op " " arg0, var, cc)
18423 +#define GEN_UNARY_RMWcc(op, antiop, var, arg0, cc) \
18424 + __GEN_RMWcc(op " " arg0, antiop " " arg0, var, cc)
18425
18426 -#define GEN_BINARY_RMWcc(op, var, vcon, val, arg0, cc) \
18427 - __GEN_RMWcc(op " %1, " arg0, var, cc, vcon (val))
18428 +#define GEN_UNARY_RMWcc_unchecked(op, var, arg0, cc) \
18429 + __GEN_RMWcc_unchecked(op " " arg0, var, cc)
18430 +
18431 +#define GEN_BINARY_RMWcc(op, antiop, var, vcon, val, arg0, cc) \
18432 + __GEN_RMWcc(op " %1, " arg0, antiop " %1, " arg0, var, cc, vcon (val))
18433 +
18434 +#define GEN_BINARY_RMWcc_unchecked(op, var, vcon, val, arg0, cc) \
18435 + __GEN_RMWcc_unchecked(op " %1, " arg0, var, cc, vcon (val))
18436
18437 #else /* !CC_HAVE_ASM_GOTO */
18438
18439 -#define __GEN_RMWcc(fullop, var, cc, ...) \
18440 +#ifdef CONFIG_PAX_REFCOUNT
18441 +#define __GEN_RMWcc(fullop, fullantiop, var, cc, ...) \
18442 +do { \
18443 + char c; \
18444 + asm volatile (fullop \
18445 + ";jno 0f\n" \
18446 + fullantiop \
18447 + ";int $4\n0:\n" \
18448 + _ASM_EXTABLE(0b, 0b) \
18449 + "; set" cc " %1" \
18450 + : "+m" (var), "=qm" (c) \
18451 + : __VA_ARGS__ : "memory"); \
18452 + return c != 0; \
18453 +} while (0)
18454 +#else
18455 +#define __GEN_RMWcc(fullop, fullantiop, var, cc, ...) \
18456 +do { \
18457 + char c; \
18458 + asm volatile (fullop "; set" cc " %1" \
18459 + : "+m" (var), "=qm" (c) \
18460 + : __VA_ARGS__ : "memory"); \
18461 + return c != 0; \
18462 +} while (0)
18463 +#endif
18464 +
18465 +#define __GEN_RMWcc_unchecked(fullop, var, cc, ...) \
18466 do { \
18467 char c; \
18468 asm volatile (fullop "; set" cc " %1" \
18469 @@ -30,11 +88,17 @@ do { \
18470 return c != 0; \
18471 } while (0)
18472
18473 -#define GEN_UNARY_RMWcc(op, var, arg0, cc) \
18474 - __GEN_RMWcc(op " " arg0, var, cc)
18475 +#define GEN_UNARY_RMWcc(op, antiop, var, arg0, cc) \
18476 + __GEN_RMWcc(op " " arg0, antiop " " arg0, var, cc)
18477 +
18478 +#define GEN_UNARY_RMWcc_unchecked(op, var, arg0, cc) \
18479 + __GEN_RMWcc_unchecked(op " " arg0, var, cc)
18480 +
18481 +#define GEN_BINARY_RMWcc(op, antiop, var, vcon, val, arg0, cc) \
18482 + __GEN_RMWcc(op " %2, " arg0, antiop " %2, " arg0, var, cc, vcon (val))
18483
18484 -#define GEN_BINARY_RMWcc(op, var, vcon, val, arg0, cc) \
18485 - __GEN_RMWcc(op " %2, " arg0, var, cc, vcon (val))
18486 +#define GEN_BINARY_RMWcc_unchecked(op, var, vcon, val, arg0, cc) \
18487 + __GEN_RMWcc_unchecked(op " %2, " arg0, var, cc, vcon (val))
18488
18489 #endif /* CC_HAVE_ASM_GOTO */
18490
18491 diff --git a/arch/x86/include/asm/rwsem.h b/arch/x86/include/asm/rwsem.h
18492 index cad82c9..2e5c5c1 100644
18493 --- a/arch/x86/include/asm/rwsem.h
18494 +++ b/arch/x86/include/asm/rwsem.h
18495 @@ -64,6 +64,14 @@ static inline void __down_read(struct rw_semaphore *sem)
18496 {
18497 asm volatile("# beginning down_read\n\t"
18498 LOCK_PREFIX _ASM_INC "(%1)\n\t"
18499 +
18500 +#ifdef CONFIG_PAX_REFCOUNT
18501 + "jno 0f\n"
18502 + LOCK_PREFIX _ASM_DEC "(%1)\n"
18503 + "int $4\n0:\n"
18504 + _ASM_EXTABLE(0b, 0b)
18505 +#endif
18506 +
18507 /* adds 0x00000001 */
18508 " jns 1f\n"
18509 " call call_rwsem_down_read_failed\n"
18510 @@ -85,6 +93,14 @@ static inline int __down_read_trylock(struct rw_semaphore *sem)
18511 "1:\n\t"
18512 " mov %1,%2\n\t"
18513 " add %3,%2\n\t"
18514 +
18515 +#ifdef CONFIG_PAX_REFCOUNT
18516 + "jno 0f\n"
18517 + "sub %3,%2\n"
18518 + "int $4\n0:\n"
18519 + _ASM_EXTABLE(0b, 0b)
18520 +#endif
18521 +
18522 " jle 2f\n\t"
18523 LOCK_PREFIX " cmpxchg %2,%0\n\t"
18524 " jnz 1b\n\t"
18525 @@ -104,6 +120,14 @@ static inline void __down_write_nested(struct rw_semaphore *sem, int subclass)
18526 long tmp;
18527 asm volatile("# beginning down_write\n\t"
18528 LOCK_PREFIX " xadd %1,(%2)\n\t"
18529 +
18530 +#ifdef CONFIG_PAX_REFCOUNT
18531 + "jno 0f\n"
18532 + "mov %1,(%2)\n"
18533 + "int $4\n0:\n"
18534 + _ASM_EXTABLE(0b, 0b)
18535 +#endif
18536 +
18537 /* adds 0xffff0001, returns the old value */
18538 " test " __ASM_SEL(%w1,%k1) "," __ASM_SEL(%w1,%k1) "\n\t"
18539 /* was the active mask 0 before? */
18540 @@ -155,6 +179,14 @@ static inline void __up_read(struct rw_semaphore *sem)
18541 long tmp;
18542 asm volatile("# beginning __up_read\n\t"
18543 LOCK_PREFIX " xadd %1,(%2)\n\t"
18544 +
18545 +#ifdef CONFIG_PAX_REFCOUNT
18546 + "jno 0f\n"
18547 + "mov %1,(%2)\n"
18548 + "int $4\n0:\n"
18549 + _ASM_EXTABLE(0b, 0b)
18550 +#endif
18551 +
18552 /* subtracts 1, returns the old value */
18553 " jns 1f\n\t"
18554 " call call_rwsem_wake\n" /* expects old value in %edx */
18555 @@ -173,6 +205,14 @@ static inline void __up_write(struct rw_semaphore *sem)
18556 long tmp;
18557 asm volatile("# beginning __up_write\n\t"
18558 LOCK_PREFIX " xadd %1,(%2)\n\t"
18559 +
18560 +#ifdef CONFIG_PAX_REFCOUNT
18561 + "jno 0f\n"
18562 + "mov %1,(%2)\n"
18563 + "int $4\n0:\n"
18564 + _ASM_EXTABLE(0b, 0b)
18565 +#endif
18566 +
18567 /* subtracts 0xffff0001, returns the old value */
18568 " jns 1f\n\t"
18569 " call call_rwsem_wake\n" /* expects old value in %edx */
18570 @@ -190,6 +230,14 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
18571 {
18572 asm volatile("# beginning __downgrade_write\n\t"
18573 LOCK_PREFIX _ASM_ADD "%2,(%1)\n\t"
18574 +
18575 +#ifdef CONFIG_PAX_REFCOUNT
18576 + "jno 0f\n"
18577 + LOCK_PREFIX _ASM_SUB "%2,(%1)\n"
18578 + "int $4\n0:\n"
18579 + _ASM_EXTABLE(0b, 0b)
18580 +#endif
18581 +
18582 /*
18583 * transitions 0xZZZZ0001 -> 0xYYYY0001 (i386)
18584 * 0xZZZZZZZZ00000001 -> 0xYYYYYYYY00000001 (x86_64)
18585 @@ -208,7 +256,15 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
18586 */
18587 static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
18588 {
18589 - asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0"
18590 + asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0\n"
18591 +
18592 +#ifdef CONFIG_PAX_REFCOUNT
18593 + "jno 0f\n"
18594 + LOCK_PREFIX _ASM_SUB "%1,%0\n"
18595 + "int $4\n0:\n"
18596 + _ASM_EXTABLE(0b, 0b)
18597 +#endif
18598 +
18599 : "+m" (sem->count)
18600 : "er" (delta));
18601 }
18602 @@ -218,7 +274,7 @@ static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
18603 */
18604 static inline long rwsem_atomic_update(long delta, struct rw_semaphore *sem)
18605 {
18606 - return delta + xadd(&sem->count, delta);
18607 + return delta + xadd_check_overflow(&sem->count, delta);
18608 }
18609
18610 #endif /* __KERNEL__ */
18611 diff --git a/arch/x86/include/asm/segment.h b/arch/x86/include/asm/segment.h
18612 index 6f1c3a8..7744f19 100644
18613 --- a/arch/x86/include/asm/segment.h
18614 +++ b/arch/x86/include/asm/segment.h
18615 @@ -64,10 +64,15 @@
18616 * 26 - ESPFIX small SS
18617 * 27 - per-cpu [ offset to per-cpu data area ]
18618 * 28 - stack_canary-20 [ for stack protector ]
18619 - * 29 - unused
18620 - * 30 - unused
18621 + * 29 - PCI BIOS CS
18622 + * 30 - PCI BIOS DS
18623 * 31 - TSS for double fault handler
18624 */
18625 +#define GDT_ENTRY_KERNEXEC_EFI_CS (1)
18626 +#define GDT_ENTRY_KERNEXEC_EFI_DS (2)
18627 +#define __KERNEXEC_EFI_CS (GDT_ENTRY_KERNEXEC_EFI_CS*8)
18628 +#define __KERNEXEC_EFI_DS (GDT_ENTRY_KERNEXEC_EFI_DS*8)
18629 +
18630 #define GDT_ENTRY_TLS_MIN 6
18631 #define GDT_ENTRY_TLS_MAX (GDT_ENTRY_TLS_MIN + GDT_ENTRY_TLS_ENTRIES - 1)
18632
18633 @@ -79,6 +84,8 @@
18634
18635 #define GDT_ENTRY_KERNEL_CS (GDT_ENTRY_KERNEL_BASE+0)
18636
18637 +#define GDT_ENTRY_KERNEXEC_KERNEL_CS (4)
18638 +
18639 #define GDT_ENTRY_KERNEL_DS (GDT_ENTRY_KERNEL_BASE+1)
18640
18641 #define GDT_ENTRY_TSS (GDT_ENTRY_KERNEL_BASE+4)
18642 @@ -104,6 +111,12 @@
18643 #define __KERNEL_STACK_CANARY 0
18644 #endif
18645
18646 +#define GDT_ENTRY_PCIBIOS_CS (GDT_ENTRY_KERNEL_BASE+17)
18647 +#define __PCIBIOS_CS (GDT_ENTRY_PCIBIOS_CS * 8)
18648 +
18649 +#define GDT_ENTRY_PCIBIOS_DS (GDT_ENTRY_KERNEL_BASE+18)
18650 +#define __PCIBIOS_DS (GDT_ENTRY_PCIBIOS_DS * 8)
18651 +
18652 #define GDT_ENTRY_DOUBLEFAULT_TSS 31
18653
18654 /*
18655 @@ -141,7 +154,7 @@
18656 */
18657
18658 /* Matches PNP_CS32 and PNP_CS16 (they must be consecutive) */
18659 -#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xf4) == GDT_ENTRY_PNPBIOS_BASE * 8)
18660 +#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xFFFCU) == PNP_CS32 || ((x) & 0xFFFCU) == PNP_CS16)
18661
18662
18663 #else
18664 @@ -165,6 +178,8 @@
18665 #define __USER32_CS (GDT_ENTRY_DEFAULT_USER32_CS*8+3)
18666 #define __USER32_DS __USER_DS
18667
18668 +#define GDT_ENTRY_KERNEXEC_KERNEL_CS 7
18669 +
18670 #define GDT_ENTRY_TSS 8 /* needs two entries */
18671 #define GDT_ENTRY_LDT 10 /* needs two entries */
18672 #define GDT_ENTRY_TLS_MIN 12
18673 @@ -173,6 +188,8 @@
18674 #define GDT_ENTRY_PER_CPU 15 /* Abused to load per CPU data from limit */
18675 #define __PER_CPU_SEG (GDT_ENTRY_PER_CPU * 8 + 3)
18676
18677 +#define GDT_ENTRY_UDEREF_KERNEL_DS 16
18678 +
18679 /* TLS indexes for 64bit - hardcoded in arch_prctl */
18680 #define FS_TLS 0
18681 #define GS_TLS 1
18682 @@ -180,12 +197,14 @@
18683 #define GS_TLS_SEL ((GDT_ENTRY_TLS_MIN+GS_TLS)*8 + 3)
18684 #define FS_TLS_SEL ((GDT_ENTRY_TLS_MIN+FS_TLS)*8 + 3)
18685
18686 -#define GDT_ENTRIES 16
18687 +#define GDT_ENTRIES 17
18688
18689 #endif
18690
18691 #define __KERNEL_CS (GDT_ENTRY_KERNEL_CS*8)
18692 +#define __KERNEXEC_KERNEL_CS (GDT_ENTRY_KERNEXEC_KERNEL_CS*8)
18693 #define __KERNEL_DS (GDT_ENTRY_KERNEL_DS*8)
18694 +#define __UDEREF_KERNEL_DS (GDT_ENTRY_UDEREF_KERNEL_DS*8)
18695 #define __USER_DS (GDT_ENTRY_DEFAULT_USER_DS*8+3)
18696 #define __USER_CS (GDT_ENTRY_DEFAULT_USER_CS*8+3)
18697 #ifndef CONFIG_PARAVIRT
18698 @@ -268,7 +287,7 @@ static inline unsigned long get_limit(unsigned long segment)
18699 {
18700 unsigned long __limit;
18701 asm("lsll %1,%0" : "=r" (__limit) : "r" (segment));
18702 - return __limit + 1;
18703 + return __limit;
18704 }
18705
18706 #endif /* !__ASSEMBLY__ */
18707 diff --git a/arch/x86/include/asm/smap.h b/arch/x86/include/asm/smap.h
18708 index 8d3120f..352b440 100644
18709 --- a/arch/x86/include/asm/smap.h
18710 +++ b/arch/x86/include/asm/smap.h
18711 @@ -25,11 +25,40 @@
18712
18713 #include <asm/alternative-asm.h>
18714
18715 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
18716 +#define ASM_PAX_OPEN_USERLAND \
18717 + 661: jmp 663f; \
18718 + .pushsection .altinstr_replacement, "a" ; \
18719 + 662: pushq %rax; nop; \
18720 + .popsection ; \
18721 + .pushsection .altinstructions, "a" ; \
18722 + altinstruction_entry 661b, 662b, X86_FEATURE_STRONGUDEREF, 2, 2;\
18723 + .popsection ; \
18724 + call __pax_open_userland; \
18725 + popq %rax; \
18726 + 663:
18727 +
18728 +#define ASM_PAX_CLOSE_USERLAND \
18729 + 661: jmp 663f; \
18730 + .pushsection .altinstr_replacement, "a" ; \
18731 + 662: pushq %rax; nop; \
18732 + .popsection; \
18733 + .pushsection .altinstructions, "a" ; \
18734 + altinstruction_entry 661b, 662b, X86_FEATURE_STRONGUDEREF, 2, 2;\
18735 + .popsection; \
18736 + call __pax_close_userland; \
18737 + popq %rax; \
18738 + 663:
18739 +#else
18740 +#define ASM_PAX_OPEN_USERLAND
18741 +#define ASM_PAX_CLOSE_USERLAND
18742 +#endif
18743 +
18744 #ifdef CONFIG_X86_SMAP
18745
18746 #define ASM_CLAC \
18747 661: ASM_NOP3 ; \
18748 - .pushsection .altinstr_replacement, "ax" ; \
18749 + .pushsection .altinstr_replacement, "a" ; \
18750 662: __ASM_CLAC ; \
18751 .popsection ; \
18752 .pushsection .altinstructions, "a" ; \
18753 @@ -38,7 +67,7 @@
18754
18755 #define ASM_STAC \
18756 661: ASM_NOP3 ; \
18757 - .pushsection .altinstr_replacement, "ax" ; \
18758 + .pushsection .altinstr_replacement, "a" ; \
18759 662: __ASM_STAC ; \
18760 .popsection ; \
18761 .pushsection .altinstructions, "a" ; \
18762 @@ -56,6 +85,37 @@
18763
18764 #include <asm/alternative.h>
18765
18766 +#define __HAVE_ARCH_PAX_OPEN_USERLAND
18767 +#define __HAVE_ARCH_PAX_CLOSE_USERLAND
18768 +
18769 +extern void __pax_open_userland(void);
18770 +static __always_inline unsigned long pax_open_userland(void)
18771 +{
18772 +
18773 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
18774 + asm volatile(ALTERNATIVE(ASM_NOP5, "call %P[open]", X86_FEATURE_STRONGUDEREF)
18775 + :
18776 + : [open] "i" (__pax_open_userland)
18777 + : "memory", "rax");
18778 +#endif
18779 +
18780 + return 0;
18781 +}
18782 +
18783 +extern void __pax_close_userland(void);
18784 +static __always_inline unsigned long pax_close_userland(void)
18785 +{
18786 +
18787 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
18788 + asm volatile(ALTERNATIVE(ASM_NOP5, "call %P[close]", X86_FEATURE_STRONGUDEREF)
18789 + :
18790 + : [close] "i" (__pax_close_userland)
18791 + : "memory", "rax");
18792 +#endif
18793 +
18794 + return 0;
18795 +}
18796 +
18797 #ifdef CONFIG_X86_SMAP
18798
18799 static __always_inline void clac(void)
18800 diff --git a/arch/x86/include/asm/smp.h b/arch/x86/include/asm/smp.h
18801 index 4137890..03fa172 100644
18802 --- a/arch/x86/include/asm/smp.h
18803 +++ b/arch/x86/include/asm/smp.h
18804 @@ -36,7 +36,7 @@ DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_core_map);
18805 /* cpus sharing the last level cache: */
18806 DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_llc_shared_map);
18807 DECLARE_PER_CPU_READ_MOSTLY(u16, cpu_llc_id);
18808 -DECLARE_PER_CPU_READ_MOSTLY(int, cpu_number);
18809 +DECLARE_PER_CPU_READ_MOSTLY(unsigned int, cpu_number);
18810
18811 static inline struct cpumask *cpu_sibling_mask(int cpu)
18812 {
18813 @@ -79,7 +79,7 @@ struct smp_ops {
18814
18815 void (*send_call_func_ipi)(const struct cpumask *mask);
18816 void (*send_call_func_single_ipi)(int cpu);
18817 -};
18818 +} __no_const;
18819
18820 /* Globals due to paravirt */
18821 extern void set_cpu_sibling_map(int cpu);
18822 @@ -191,14 +191,8 @@ extern unsigned disabled_cpus;
18823 extern int safe_smp_processor_id(void);
18824
18825 #elif defined(CONFIG_X86_64_SMP)
18826 -#define raw_smp_processor_id() (this_cpu_read(cpu_number))
18827 -
18828 -#define stack_smp_processor_id() \
18829 -({ \
18830 - struct thread_info *ti; \
18831 - __asm__("andq %%rsp,%0; ":"=r" (ti) : "0" (CURRENT_MASK)); \
18832 - ti->cpu; \
18833 -})
18834 +#define raw_smp_processor_id() (this_cpu_read(cpu_number))
18835 +#define stack_smp_processor_id() raw_smp_processor_id()
18836 #define safe_smp_processor_id() smp_processor_id()
18837
18838 #endif
18839 diff --git a/arch/x86/include/asm/spinlock.h b/arch/x86/include/asm/spinlock.h
18840 index bf156de..1a782ab 100644
18841 --- a/arch/x86/include/asm/spinlock.h
18842 +++ b/arch/x86/include/asm/spinlock.h
18843 @@ -223,6 +223,14 @@ static inline int arch_write_can_lock(arch_rwlock_t *lock)
18844 static inline void arch_read_lock(arch_rwlock_t *rw)
18845 {
18846 asm volatile(LOCK_PREFIX READ_LOCK_SIZE(dec) " (%0)\n\t"
18847 +
18848 +#ifdef CONFIG_PAX_REFCOUNT
18849 + "jno 0f\n"
18850 + LOCK_PREFIX READ_LOCK_SIZE(inc) " (%0)\n"
18851 + "int $4\n0:\n"
18852 + _ASM_EXTABLE(0b, 0b)
18853 +#endif
18854 +
18855 "jns 1f\n"
18856 "call __read_lock_failed\n\t"
18857 "1:\n"
18858 @@ -232,6 +240,14 @@ static inline void arch_read_lock(arch_rwlock_t *rw)
18859 static inline void arch_write_lock(arch_rwlock_t *rw)
18860 {
18861 asm volatile(LOCK_PREFIX WRITE_LOCK_SUB(%1) "(%0)\n\t"
18862 +
18863 +#ifdef CONFIG_PAX_REFCOUNT
18864 + "jno 0f\n"
18865 + LOCK_PREFIX WRITE_LOCK_ADD(%1) "(%0)\n"
18866 + "int $4\n0:\n"
18867 + _ASM_EXTABLE(0b, 0b)
18868 +#endif
18869 +
18870 "jz 1f\n"
18871 "call __write_lock_failed\n\t"
18872 "1:\n"
18873 @@ -261,13 +277,29 @@ static inline int arch_write_trylock(arch_rwlock_t *lock)
18874
18875 static inline void arch_read_unlock(arch_rwlock_t *rw)
18876 {
18877 - asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0"
18878 + asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0\n"
18879 +
18880 +#ifdef CONFIG_PAX_REFCOUNT
18881 + "jno 0f\n"
18882 + LOCK_PREFIX READ_LOCK_SIZE(dec) " %0\n"
18883 + "int $4\n0:\n"
18884 + _ASM_EXTABLE(0b, 0b)
18885 +#endif
18886 +
18887 :"+m" (rw->lock) : : "memory");
18888 }
18889
18890 static inline void arch_write_unlock(arch_rwlock_t *rw)
18891 {
18892 - asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0"
18893 + asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0\n"
18894 +
18895 +#ifdef CONFIG_PAX_REFCOUNT
18896 + "jno 0f\n"
18897 + LOCK_PREFIX WRITE_LOCK_SUB(%1) "%0\n"
18898 + "int $4\n0:\n"
18899 + _ASM_EXTABLE(0b, 0b)
18900 +#endif
18901 +
18902 : "+m" (rw->write) : "i" (RW_LOCK_BIAS) : "memory");
18903 }
18904
18905 diff --git a/arch/x86/include/asm/stackprotector.h b/arch/x86/include/asm/stackprotector.h
18906 index 6a99859..03cb807 100644
18907 --- a/arch/x86/include/asm/stackprotector.h
18908 +++ b/arch/x86/include/asm/stackprotector.h
18909 @@ -47,7 +47,7 @@
18910 * head_32 for boot CPU and setup_per_cpu_areas() for others.
18911 */
18912 #define GDT_STACK_CANARY_INIT \
18913 - [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x18),
18914 + [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x17),
18915
18916 /*
18917 * Initialize the stackprotector canary value.
18918 @@ -112,7 +112,7 @@ static inline void setup_stack_canary_segment(int cpu)
18919
18920 static inline void load_stack_canary_segment(void)
18921 {
18922 -#ifdef CONFIG_X86_32
18923 +#if defined(CONFIG_X86_32) && !defined(CONFIG_PAX_MEMORY_UDEREF)
18924 asm volatile ("mov %0, %%gs" : : "r" (0));
18925 #endif
18926 }
18927 diff --git a/arch/x86/include/asm/stacktrace.h b/arch/x86/include/asm/stacktrace.h
18928 index 70bbe39..4ae2bd4 100644
18929 --- a/arch/x86/include/asm/stacktrace.h
18930 +++ b/arch/x86/include/asm/stacktrace.h
18931 @@ -11,28 +11,20 @@
18932
18933 extern int kstack_depth_to_print;
18934
18935 -struct thread_info;
18936 +struct task_struct;
18937 struct stacktrace_ops;
18938
18939 -typedef unsigned long (*walk_stack_t)(struct thread_info *tinfo,
18940 - unsigned long *stack,
18941 - unsigned long bp,
18942 - const struct stacktrace_ops *ops,
18943 - void *data,
18944 - unsigned long *end,
18945 - int *graph);
18946 +typedef unsigned long walk_stack_t(struct task_struct *task,
18947 + void *stack_start,
18948 + unsigned long *stack,
18949 + unsigned long bp,
18950 + const struct stacktrace_ops *ops,
18951 + void *data,
18952 + unsigned long *end,
18953 + int *graph);
18954
18955 -extern unsigned long
18956 -print_context_stack(struct thread_info *tinfo,
18957 - unsigned long *stack, unsigned long bp,
18958 - const struct stacktrace_ops *ops, void *data,
18959 - unsigned long *end, int *graph);
18960 -
18961 -extern unsigned long
18962 -print_context_stack_bp(struct thread_info *tinfo,
18963 - unsigned long *stack, unsigned long bp,
18964 - const struct stacktrace_ops *ops, void *data,
18965 - unsigned long *end, int *graph);
18966 +extern walk_stack_t print_context_stack;
18967 +extern walk_stack_t print_context_stack_bp;
18968
18969 /* Generic stack tracer with callbacks */
18970
18971 @@ -40,7 +32,7 @@ struct stacktrace_ops {
18972 void (*address)(void *data, unsigned long address, int reliable);
18973 /* On negative return stop dumping */
18974 int (*stack)(void *data, char *name);
18975 - walk_stack_t walk_stack;
18976 + walk_stack_t *walk_stack;
18977 };
18978
18979 void dump_trace(struct task_struct *tsk, struct pt_regs *regs,
18980 diff --git a/arch/x86/include/asm/switch_to.h b/arch/x86/include/asm/switch_to.h
18981 index d7f3b3b..3cc39f1 100644
18982 --- a/arch/x86/include/asm/switch_to.h
18983 +++ b/arch/x86/include/asm/switch_to.h
18984 @@ -108,7 +108,7 @@ do { \
18985 "call __switch_to\n\t" \
18986 "movq "__percpu_arg([current_task])",%%rsi\n\t" \
18987 __switch_canary \
18988 - "movq %P[thread_info](%%rsi),%%r8\n\t" \
18989 + "movq "__percpu_arg([thread_info])",%%r8\n\t" \
18990 "movq %%rax,%%rdi\n\t" \
18991 "testl %[_tif_fork],%P[ti_flags](%%r8)\n\t" \
18992 "jnz ret_from_fork\n\t" \
18993 @@ -119,7 +119,7 @@ do { \
18994 [threadrsp] "i" (offsetof(struct task_struct, thread.sp)), \
18995 [ti_flags] "i" (offsetof(struct thread_info, flags)), \
18996 [_tif_fork] "i" (_TIF_FORK), \
18997 - [thread_info] "i" (offsetof(struct task_struct, stack)), \
18998 + [thread_info] "m" (current_tinfo), \
18999 [current_task] "m" (current_task) \
19000 __switch_canary_iparam \
19001 : "memory", "cc" __EXTRA_CLOBBER)
19002 diff --git a/arch/x86/include/asm/thread_info.h b/arch/x86/include/asm/thread_info.h
19003 index 3ba3de4..6c113b2 100644
19004 --- a/arch/x86/include/asm/thread_info.h
19005 +++ b/arch/x86/include/asm/thread_info.h
19006 @@ -10,6 +10,7 @@
19007 #include <linux/compiler.h>
19008 #include <asm/page.h>
19009 #include <asm/types.h>
19010 +#include <asm/percpu.h>
19011
19012 /*
19013 * low level task data that entry.S needs immediate access to
19014 @@ -23,7 +24,6 @@ struct exec_domain;
19015 #include <linux/atomic.h>
19016
19017 struct thread_info {
19018 - struct task_struct *task; /* main task structure */
19019 struct exec_domain *exec_domain; /* execution domain */
19020 __u32 flags; /* low level flags */
19021 __u32 status; /* thread synchronous flags */
19022 @@ -32,19 +32,13 @@ struct thread_info {
19023 mm_segment_t addr_limit;
19024 struct restart_block restart_block;
19025 void __user *sysenter_return;
19026 -#ifdef CONFIG_X86_32
19027 - unsigned long previous_esp; /* ESP of the previous stack in
19028 - case of nested (IRQ) stacks
19029 - */
19030 - __u8 supervisor_stack[0];
19031 -#endif
19032 + unsigned long lowest_stack;
19033 unsigned int sig_on_uaccess_error:1;
19034 unsigned int uaccess_err:1; /* uaccess failed */
19035 };
19036
19037 -#define INIT_THREAD_INFO(tsk) \
19038 +#define INIT_THREAD_INFO \
19039 { \
19040 - .task = &tsk, \
19041 .exec_domain = &default_exec_domain, \
19042 .flags = 0, \
19043 .cpu = 0, \
19044 @@ -55,7 +49,7 @@ struct thread_info {
19045 }, \
19046 }
19047
19048 -#define init_thread_info (init_thread_union.thread_info)
19049 +#define init_thread_info (init_thread_union.stack)
19050 #define init_stack (init_thread_union.stack)
19051
19052 #else /* !__ASSEMBLY__ */
19053 @@ -95,6 +89,7 @@ struct thread_info {
19054 #define TIF_SYSCALL_TRACEPOINT 28 /* syscall tracepoint instrumentation */
19055 #define TIF_ADDR32 29 /* 32-bit address space on 64 bits */
19056 #define TIF_X32 30 /* 32-bit native x86-64 binary */
19057 +#define TIF_GRSEC_SETXID 31 /* update credentials on syscall entry/exit */
19058
19059 #define _TIF_SYSCALL_TRACE (1 << TIF_SYSCALL_TRACE)
19060 #define _TIF_NOTIFY_RESUME (1 << TIF_NOTIFY_RESUME)
19061 @@ -118,17 +113,18 @@ struct thread_info {
19062 #define _TIF_SYSCALL_TRACEPOINT (1 << TIF_SYSCALL_TRACEPOINT)
19063 #define _TIF_ADDR32 (1 << TIF_ADDR32)
19064 #define _TIF_X32 (1 << TIF_X32)
19065 +#define _TIF_GRSEC_SETXID (1 << TIF_GRSEC_SETXID)
19066
19067 /* work to do in syscall_trace_enter() */
19068 #define _TIF_WORK_SYSCALL_ENTRY \
19069 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_EMU | _TIF_SYSCALL_AUDIT | \
19070 _TIF_SECCOMP | _TIF_SINGLESTEP | _TIF_SYSCALL_TRACEPOINT | \
19071 - _TIF_NOHZ)
19072 + _TIF_NOHZ | _TIF_GRSEC_SETXID)
19073
19074 /* work to do in syscall_trace_leave() */
19075 #define _TIF_WORK_SYSCALL_EXIT \
19076 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_SINGLESTEP | \
19077 - _TIF_SYSCALL_TRACEPOINT | _TIF_NOHZ)
19078 + _TIF_SYSCALL_TRACEPOINT | _TIF_NOHZ | _TIF_GRSEC_SETXID)
19079
19080 /* work to do on interrupt/exception return */
19081 #define _TIF_WORK_MASK \
19082 @@ -139,7 +135,7 @@ struct thread_info {
19083 /* work to do on any return to user space */
19084 #define _TIF_ALLWORK_MASK \
19085 ((0x0000FFFF & ~_TIF_SECCOMP) | _TIF_SYSCALL_TRACEPOINT | \
19086 - _TIF_NOHZ)
19087 + _TIF_NOHZ | _TIF_GRSEC_SETXID)
19088
19089 /* Only used for 64 bit */
19090 #define _TIF_DO_NOTIFY_MASK \
19091 @@ -153,45 +149,40 @@ struct thread_info {
19092 #define _TIF_WORK_CTXSW_PREV (_TIF_WORK_CTXSW|_TIF_USER_RETURN_NOTIFY)
19093 #define _TIF_WORK_CTXSW_NEXT (_TIF_WORK_CTXSW)
19094
19095 -#ifdef CONFIG_X86_32
19096 -
19097 -#define STACK_WARN (THREAD_SIZE/8)
19098 -/*
19099 - * macros/functions for gaining access to the thread information structure
19100 - *
19101 - * preempt_count needs to be 1 initially, until the scheduler is functional.
19102 - */
19103 -#ifndef __ASSEMBLY__
19104 -
19105 -
19106 -/* how to get the current stack pointer from C */
19107 -register unsigned long current_stack_pointer asm("esp") __used;
19108 -
19109 -/* how to get the thread information struct from C */
19110 -static inline struct thread_info *current_thread_info(void)
19111 -{
19112 - return (struct thread_info *)
19113 - (current_stack_pointer & ~(THREAD_SIZE - 1));
19114 -}
19115 -
19116 -#else /* !__ASSEMBLY__ */
19117 -
19118 +#ifdef __ASSEMBLY__
19119 /* how to get the thread information struct from ASM */
19120 #define GET_THREAD_INFO(reg) \
19121 - movl $-THREAD_SIZE, reg; \
19122 - andl %esp, reg
19123 + mov PER_CPU_VAR(current_tinfo), reg
19124
19125 /* use this one if reg already contains %esp */
19126 -#define GET_THREAD_INFO_WITH_ESP(reg) \
19127 - andl $-THREAD_SIZE, reg
19128 +#define GET_THREAD_INFO_WITH_ESP(reg) GET_THREAD_INFO(reg)
19129 +#else
19130 +/* how to get the thread information struct from C */
19131 +DECLARE_PER_CPU(struct thread_info *, current_tinfo);
19132 +
19133 +static __always_inline struct thread_info *current_thread_info(void)
19134 +{
19135 + return this_cpu_read_stable(current_tinfo);
19136 +}
19137 +#endif
19138 +
19139 +#ifdef CONFIG_X86_32
19140 +
19141 +#define STACK_WARN (THREAD_SIZE/8)
19142 +/*
19143 + * macros/functions for gaining access to the thread information structure
19144 + *
19145 + * preempt_count needs to be 1 initially, until the scheduler is functional.
19146 + */
19147 +#ifndef __ASSEMBLY__
19148 +
19149 +/* how to get the current stack pointer from C */
19150 +register unsigned long current_stack_pointer asm("esp") __used;
19151
19152 #endif
19153
19154 #else /* X86_32 */
19155
19156 -#include <asm/percpu.h>
19157 -#define KERNEL_STACK_OFFSET (5*8)
19158 -
19159 /*
19160 * macros/functions for gaining access to the thread information structure
19161 * preempt_count needs to be 1 initially, until the scheduler is functional.
19162 @@ -199,27 +190,8 @@ static inline struct thread_info *current_thread_info(void)
19163 #ifndef __ASSEMBLY__
19164 DECLARE_PER_CPU(unsigned long, kernel_stack);
19165
19166 -static inline struct thread_info *current_thread_info(void)
19167 -{
19168 - struct thread_info *ti;
19169 - ti = (void *)(this_cpu_read_stable(kernel_stack) +
19170 - KERNEL_STACK_OFFSET - THREAD_SIZE);
19171 - return ti;
19172 -}
19173 -
19174 -#else /* !__ASSEMBLY__ */
19175 -
19176 -/* how to get the thread information struct from ASM */
19177 -#define GET_THREAD_INFO(reg) \
19178 - movq PER_CPU_VAR(kernel_stack),reg ; \
19179 - subq $(THREAD_SIZE-KERNEL_STACK_OFFSET),reg
19180 -
19181 -/*
19182 - * Same if PER_CPU_VAR(kernel_stack) is, perhaps with some offset, already in
19183 - * a certain register (to be used in assembler memory operands).
19184 - */
19185 -#define THREAD_INFO(reg, off) KERNEL_STACK_OFFSET+(off)-THREAD_SIZE(reg)
19186 -
19187 +/* how to get the current stack pointer from C */
19188 +register unsigned long current_stack_pointer asm("rsp") __used;
19189 #endif
19190
19191 #endif /* !X86_32 */
19192 @@ -278,5 +250,12 @@ static inline bool is_ia32_task(void)
19193 extern void arch_task_cache_init(void);
19194 extern int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src);
19195 extern void arch_release_task_struct(struct task_struct *tsk);
19196 +
19197 +#define __HAVE_THREAD_FUNCTIONS
19198 +#define task_thread_info(task) (&(task)->tinfo)
19199 +#define task_stack_page(task) ((task)->stack)
19200 +#define setup_thread_stack(p, org) do {} while (0)
19201 +#define end_of_stack(p) ((unsigned long *)task_stack_page(p) + 1)
19202 +
19203 #endif
19204 #endif /* _ASM_X86_THREAD_INFO_H */
19205 diff --git a/arch/x86/include/asm/tlbflush.h b/arch/x86/include/asm/tlbflush.h
19206 index e6d90ba..f81f114 100644
19207 --- a/arch/x86/include/asm/tlbflush.h
19208 +++ b/arch/x86/include/asm/tlbflush.h
19209 @@ -17,18 +17,44 @@
19210
19211 static inline void __native_flush_tlb(void)
19212 {
19213 + if (static_cpu_has(X86_FEATURE_INVPCID)) {
19214 + u64 descriptor[2];
19215 +
19216 + descriptor[0] = PCID_KERNEL;
19217 + asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_ALL_MONGLOBAL) : "memory");
19218 + return;
19219 + }
19220 +
19221 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19222 + if (static_cpu_has(X86_FEATURE_PCID)) {
19223 + unsigned int cpu = raw_get_cpu();
19224 +
19225 + native_write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER);
19226 + native_write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL);
19227 + raw_put_cpu_no_resched();
19228 + return;
19229 + }
19230 +#endif
19231 +
19232 native_write_cr3(native_read_cr3());
19233 }
19234
19235 static inline void __native_flush_tlb_global_irq_disabled(void)
19236 {
19237 - unsigned long cr4;
19238 + if (static_cpu_has(X86_FEATURE_INVPCID)) {
19239 + u64 descriptor[2];
19240
19241 - cr4 = native_read_cr4();
19242 - /* clear PGE */
19243 - native_write_cr4(cr4 & ~X86_CR4_PGE);
19244 - /* write old PGE again and flush TLBs */
19245 - native_write_cr4(cr4);
19246 + descriptor[0] = PCID_KERNEL;
19247 + asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_ALL_GLOBAL) : "memory");
19248 + } else {
19249 + unsigned long cr4;
19250 +
19251 + cr4 = native_read_cr4();
19252 + /* clear PGE */
19253 + native_write_cr4(cr4 & ~X86_CR4_PGE);
19254 + /* write old PGE again and flush TLBs */
19255 + native_write_cr4(cr4);
19256 + }
19257 }
19258
19259 static inline void __native_flush_tlb_global(void)
19260 @@ -49,6 +75,41 @@ static inline void __native_flush_tlb_global(void)
19261
19262 static inline void __native_flush_tlb_single(unsigned long addr)
19263 {
19264 + if (static_cpu_has(X86_FEATURE_INVPCID)) {
19265 + u64 descriptor[2];
19266 +
19267 + descriptor[0] = PCID_KERNEL;
19268 + descriptor[1] = addr;
19269 +
19270 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19271 + if (!static_cpu_has(X86_FEATURE_STRONGUDEREF) || addr >= TASK_SIZE_MAX) {
19272 + if (addr < TASK_SIZE_MAX)
19273 + descriptor[1] += pax_user_shadow_base;
19274 + asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_ADDRESS) : "memory");
19275 + }
19276 +
19277 + descriptor[0] = PCID_USER;
19278 + descriptor[1] = addr;
19279 +#endif
19280 +
19281 + asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_ADDRESS) : "memory");
19282 + return;
19283 + }
19284 +
19285 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19286 + if (static_cpu_has(X86_FEATURE_PCID)) {
19287 + unsigned int cpu = raw_get_cpu();
19288 +
19289 + native_write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER | PCID_NOFLUSH);
19290 + asm volatile("invlpg (%0)" ::"r" (addr) : "memory");
19291 + native_write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL | PCID_NOFLUSH);
19292 + raw_put_cpu_no_resched();
19293 +
19294 + if (!static_cpu_has(X86_FEATURE_STRONGUDEREF) && addr < TASK_SIZE_MAX)
19295 + addr += pax_user_shadow_base;
19296 + }
19297 +#endif
19298 +
19299 asm volatile("invlpg (%0)" ::"r" (addr) : "memory");
19300 }
19301
19302 diff --git a/arch/x86/include/asm/uaccess.h b/arch/x86/include/asm/uaccess.h
19303 index 8ec57c0..451bcfc 100644
19304 --- a/arch/x86/include/asm/uaccess.h
19305 +++ b/arch/x86/include/asm/uaccess.h
19306 @@ -7,6 +7,7 @@
19307 #include <linux/compiler.h>
19308 #include <linux/thread_info.h>
19309 #include <linux/string.h>
19310 +#include <linux/spinlock.h>
19311 #include <asm/asm.h>
19312 #include <asm/page.h>
19313 #include <asm/smap.h>
19314 @@ -29,7 +30,12 @@
19315
19316 #define get_ds() (KERNEL_DS)
19317 #define get_fs() (current_thread_info()->addr_limit)
19318 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
19319 +void __set_fs(mm_segment_t x);
19320 +void set_fs(mm_segment_t x);
19321 +#else
19322 #define set_fs(x) (current_thread_info()->addr_limit = (x))
19323 +#endif
19324
19325 #define segment_eq(a, b) ((a).seg == (b).seg)
19326
19327 @@ -77,8 +83,34 @@
19328 * checks that the pointer is in the user space range - after calling
19329 * this function, memory access functions may still return -EFAULT.
19330 */
19331 -#define access_ok(type, addr, size) \
19332 - (likely(__range_not_ok(addr, size, user_addr_max()) == 0))
19333 +extern int _cond_resched(void);
19334 +#define access_ok_noprefault(type, addr, size) (likely(__range_not_ok(addr, size, user_addr_max()) == 0))
19335 +#define access_ok(type, addr, size) \
19336 +({ \
19337 + long __size = size; \
19338 + unsigned long __addr = (unsigned long)addr; \
19339 + unsigned long __addr_ao = __addr & PAGE_MASK; \
19340 + unsigned long __end_ao = __addr + __size - 1; \
19341 + bool __ret_ao = __range_not_ok(__addr, __size, user_addr_max()) == 0;\
19342 + if (__ret_ao && unlikely((__end_ao ^ __addr_ao) & PAGE_MASK)) { \
19343 + while(__addr_ao <= __end_ao) { \
19344 + char __c_ao; \
19345 + __addr_ao += PAGE_SIZE; \
19346 + if (__size > PAGE_SIZE) \
19347 + _cond_resched(); \
19348 + if (__get_user(__c_ao, (char __user *)__addr)) \
19349 + break; \
19350 + if (type != VERIFY_WRITE) { \
19351 + __addr = __addr_ao; \
19352 + continue; \
19353 + } \
19354 + if (__put_user(__c_ao, (char __user *)__addr)) \
19355 + break; \
19356 + __addr = __addr_ao; \
19357 + } \
19358 + } \
19359 + __ret_ao; \
19360 +})
19361
19362 /*
19363 * The exception table consists of pairs of addresses relative to the
19364 @@ -168,10 +200,12 @@ __typeof__(__builtin_choose_expr(sizeof(x) > sizeof(0UL), 0ULL, 0UL))
19365 register __inttype(*(ptr)) __val_gu asm("%"_ASM_DX); \
19366 __chk_user_ptr(ptr); \
19367 might_fault(); \
19368 + pax_open_userland(); \
19369 asm volatile("call __get_user_%P3" \
19370 : "=a" (__ret_gu), "=r" (__val_gu) \
19371 : "0" (ptr), "i" (sizeof(*(ptr)))); \
19372 (x) = (__typeof__(*(ptr))) __val_gu; \
19373 + pax_close_userland(); \
19374 __ret_gu; \
19375 })
19376
19377 @@ -179,13 +213,21 @@ __typeof__(__builtin_choose_expr(sizeof(x) > sizeof(0UL), 0ULL, 0UL))
19378 asm volatile("call __put_user_" #size : "=a" (__ret_pu) \
19379 : "0" ((typeof(*(ptr)))(x)), "c" (ptr) : "ebx")
19380
19381 -
19382 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
19383 +#define __copyuser_seg "gs;"
19384 +#define __COPYUSER_SET_ES "pushl %%gs; popl %%es\n"
19385 +#define __COPYUSER_RESTORE_ES "pushl %%ss; popl %%es\n"
19386 +#else
19387 +#define __copyuser_seg
19388 +#define __COPYUSER_SET_ES
19389 +#define __COPYUSER_RESTORE_ES
19390 +#endif
19391
19392 #ifdef CONFIG_X86_32
19393 #define __put_user_asm_u64(x, addr, err, errret) \
19394 asm volatile(ASM_STAC "\n" \
19395 - "1: movl %%eax,0(%2)\n" \
19396 - "2: movl %%edx,4(%2)\n" \
19397 + "1: "__copyuser_seg"movl %%eax,0(%2)\n" \
19398 + "2: "__copyuser_seg"movl %%edx,4(%2)\n" \
19399 "3: " ASM_CLAC "\n" \
19400 ".section .fixup,\"ax\"\n" \
19401 "4: movl %3,%0\n" \
19402 @@ -198,8 +240,8 @@ __typeof__(__builtin_choose_expr(sizeof(x) > sizeof(0UL), 0ULL, 0UL))
19403
19404 #define __put_user_asm_ex_u64(x, addr) \
19405 asm volatile(ASM_STAC "\n" \
19406 - "1: movl %%eax,0(%1)\n" \
19407 - "2: movl %%edx,4(%1)\n" \
19408 + "1: "__copyuser_seg"movl %%eax,0(%1)\n" \
19409 + "2: "__copyuser_seg"movl %%edx,4(%1)\n" \
19410 "3: " ASM_CLAC "\n" \
19411 _ASM_EXTABLE_EX(1b, 2b) \
19412 _ASM_EXTABLE_EX(2b, 3b) \
19413 @@ -249,7 +291,8 @@ extern void __put_user_8(void);
19414 __typeof__(*(ptr)) __pu_val; \
19415 __chk_user_ptr(ptr); \
19416 might_fault(); \
19417 - __pu_val = x; \
19418 + __pu_val = (x); \
19419 + pax_open_userland(); \
19420 switch (sizeof(*(ptr))) { \
19421 case 1: \
19422 __put_user_x(1, __pu_val, ptr, __ret_pu); \
19423 @@ -267,6 +310,7 @@ extern void __put_user_8(void);
19424 __put_user_x(X, __pu_val, ptr, __ret_pu); \
19425 break; \
19426 } \
19427 + pax_close_userland(); \
19428 __ret_pu; \
19429 })
19430
19431 @@ -347,8 +391,10 @@ do { \
19432 } while (0)
19433
19434 #define __get_user_asm(x, addr, err, itype, rtype, ltype, errret) \
19435 +do { \
19436 + pax_open_userland(); \
19437 asm volatile(ASM_STAC "\n" \
19438 - "1: mov"itype" %2,%"rtype"1\n" \
19439 + "1: "__copyuser_seg"mov"itype" %2,%"rtype"1\n"\
19440 "2: " ASM_CLAC "\n" \
19441 ".section .fixup,\"ax\"\n" \
19442 "3: mov %3,%0\n" \
19443 @@ -356,8 +402,10 @@ do { \
19444 " jmp 2b\n" \
19445 ".previous\n" \
19446 _ASM_EXTABLE(1b, 3b) \
19447 - : "=r" (err), ltype(x) \
19448 - : "m" (__m(addr)), "i" (errret), "0" (err))
19449 + : "=r" (err), ltype (x) \
19450 + : "m" (__m(addr)), "i" (errret), "0" (err)); \
19451 + pax_close_userland(); \
19452 +} while (0)
19453
19454 #define __get_user_size_ex(x, ptr, size) \
19455 do { \
19456 @@ -381,7 +429,7 @@ do { \
19457 } while (0)
19458
19459 #define __get_user_asm_ex(x, addr, itype, rtype, ltype) \
19460 - asm volatile("1: mov"itype" %1,%"rtype"0\n" \
19461 + asm volatile("1: "__copyuser_seg"mov"itype" %1,%"rtype"0\n"\
19462 "2:\n" \
19463 _ASM_EXTABLE_EX(1b, 2b) \
19464 : ltype(x) : "m" (__m(addr)))
19465 @@ -398,13 +446,24 @@ do { \
19466 int __gu_err; \
19467 unsigned long __gu_val; \
19468 __get_user_size(__gu_val, (ptr), (size), __gu_err, -EFAULT); \
19469 - (x) = (__force __typeof__(*(ptr)))__gu_val; \
19470 + (x) = (__typeof__(*(ptr)))__gu_val; \
19471 __gu_err; \
19472 })
19473
19474 /* FIXME: this hack is definitely wrong -AK */
19475 struct __large_struct { unsigned long buf[100]; };
19476 -#define __m(x) (*(struct __large_struct __user *)(x))
19477 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19478 +#define ____m(x) \
19479 +({ \
19480 + unsigned long ____x = (unsigned long)(x); \
19481 + if (____x < pax_user_shadow_base) \
19482 + ____x += pax_user_shadow_base; \
19483 + (typeof(x))____x; \
19484 +})
19485 +#else
19486 +#define ____m(x) (x)
19487 +#endif
19488 +#define __m(x) (*(struct __large_struct __user *)____m(x))
19489
19490 /*
19491 * Tell gcc we read from memory instead of writing: this is because
19492 @@ -412,8 +471,10 @@ struct __large_struct { unsigned long buf[100]; };
19493 * aliasing issues.
19494 */
19495 #define __put_user_asm(x, addr, err, itype, rtype, ltype, errret) \
19496 +do { \
19497 + pax_open_userland(); \
19498 asm volatile(ASM_STAC "\n" \
19499 - "1: mov"itype" %"rtype"1,%2\n" \
19500 + "1: "__copyuser_seg"mov"itype" %"rtype"1,%2\n"\
19501 "2: " ASM_CLAC "\n" \
19502 ".section .fixup,\"ax\"\n" \
19503 "3: mov %3,%0\n" \
19504 @@ -421,10 +482,12 @@ struct __large_struct { unsigned long buf[100]; };
19505 ".previous\n" \
19506 _ASM_EXTABLE(1b, 3b) \
19507 : "=r"(err) \
19508 - : ltype(x), "m" (__m(addr)), "i" (errret), "0" (err))
19509 + : ltype (x), "m" (__m(addr)), "i" (errret), "0" (err));\
19510 + pax_close_userland(); \
19511 +} while (0)
19512
19513 #define __put_user_asm_ex(x, addr, itype, rtype, ltype) \
19514 - asm volatile("1: mov"itype" %"rtype"0,%1\n" \
19515 + asm volatile("1: "__copyuser_seg"mov"itype" %"rtype"0,%1\n"\
19516 "2:\n" \
19517 _ASM_EXTABLE_EX(1b, 2b) \
19518 : : ltype(x), "m" (__m(addr)))
19519 @@ -434,11 +497,13 @@ struct __large_struct { unsigned long buf[100]; };
19520 */
19521 #define uaccess_try do { \
19522 current_thread_info()->uaccess_err = 0; \
19523 + pax_open_userland(); \
19524 stac(); \
19525 barrier();
19526
19527 #define uaccess_catch(err) \
19528 clac(); \
19529 + pax_close_userland(); \
19530 (err) |= (current_thread_info()->uaccess_err ? -EFAULT : 0); \
19531 } while (0)
19532
19533 @@ -463,8 +528,12 @@ struct __large_struct { unsigned long buf[100]; };
19534 * On error, the variable @x is set to zero.
19535 */
19536
19537 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19538 +#define __get_user(x, ptr) get_user((x), (ptr))
19539 +#else
19540 #define __get_user(x, ptr) \
19541 __get_user_nocheck((x), (ptr), sizeof(*(ptr)))
19542 +#endif
19543
19544 /**
19545 * __put_user: - Write a simple value into user space, with less checking.
19546 @@ -486,8 +555,12 @@ struct __large_struct { unsigned long buf[100]; };
19547 * Returns zero on success, or -EFAULT on error.
19548 */
19549
19550 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19551 +#define __put_user(x, ptr) put_user((x), (ptr))
19552 +#else
19553 #define __put_user(x, ptr) \
19554 __put_user_nocheck((__typeof__(*(ptr)))(x), (ptr), sizeof(*(ptr)))
19555 +#endif
19556
19557 #define __get_user_unaligned __get_user
19558 #define __put_user_unaligned __put_user
19559 @@ -505,7 +578,7 @@ struct __large_struct { unsigned long buf[100]; };
19560 #define get_user_ex(x, ptr) do { \
19561 unsigned long __gue_val; \
19562 __get_user_size_ex((__gue_val), (ptr), (sizeof(*(ptr)))); \
19563 - (x) = (__force __typeof__(*(ptr)))__gue_val; \
19564 + (x) = (__typeof__(*(ptr)))__gue_val; \
19565 } while (0)
19566
19567 #define put_user_try uaccess_try
19568 @@ -536,17 +609,6 @@ extern struct movsl_mask {
19569
19570 #define ARCH_HAS_NOCACHE_UACCESS 1
19571
19572 -#ifdef CONFIG_X86_32
19573 -# include <asm/uaccess_32.h>
19574 -#else
19575 -# include <asm/uaccess_64.h>
19576 -#endif
19577 -
19578 -unsigned long __must_check _copy_from_user(void *to, const void __user *from,
19579 - unsigned n);
19580 -unsigned long __must_check _copy_to_user(void __user *to, const void *from,
19581 - unsigned n);
19582 -
19583 #ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
19584 # define copy_user_diag __compiletime_error
19585 #else
19586 @@ -556,7 +618,7 @@ unsigned long __must_check _copy_to_user(void __user *to, const void *from,
19587 extern void copy_user_diag("copy_from_user() buffer size is too small")
19588 copy_from_user_overflow(void);
19589 extern void copy_user_diag("copy_to_user() buffer size is too small")
19590 -copy_to_user_overflow(void) __asm__("copy_from_user_overflow");
19591 +copy_to_user_overflow(void);
19592
19593 #undef copy_user_diag
19594
19595 @@ -569,7 +631,7 @@ __copy_from_user_overflow(void) __asm__("copy_from_user_overflow");
19596
19597 extern void
19598 __compiletime_warning("copy_to_user() buffer size is not provably correct")
19599 -__copy_to_user_overflow(void) __asm__("copy_from_user_overflow");
19600 +__copy_to_user_overflow(void) __asm__("copy_to_user_overflow");
19601 #define __copy_to_user_overflow(size, count) __copy_to_user_overflow()
19602
19603 #else
19604 @@ -584,10 +646,16 @@ __copy_from_user_overflow(int size, unsigned long count)
19605
19606 #endif
19607
19608 +#ifdef CONFIG_X86_32
19609 +# include <asm/uaccess_32.h>
19610 +#else
19611 +# include <asm/uaccess_64.h>
19612 +#endif
19613 +
19614 static inline unsigned long __must_check
19615 copy_from_user(void *to, const void __user *from, unsigned long n)
19616 {
19617 - int sz = __compiletime_object_size(to);
19618 + size_t sz = __compiletime_object_size(to);
19619
19620 might_fault();
19621
19622 @@ -609,12 +677,15 @@ copy_from_user(void *to, const void __user *from, unsigned long n)
19623 * case, and do only runtime checking for non-constant sizes.
19624 */
19625
19626 - if (likely(sz < 0 || sz >= n))
19627 - n = _copy_from_user(to, from, n);
19628 - else if(__builtin_constant_p(n))
19629 - copy_from_user_overflow();
19630 - else
19631 - __copy_from_user_overflow(sz, n);
19632 + if (likely(sz != (size_t)-1 && sz < n)) {
19633 + if(__builtin_constant_p(n))
19634 + copy_from_user_overflow();
19635 + else
19636 + __copy_from_user_overflow(sz, n);
19637 + } if (access_ok(VERIFY_READ, from, n))
19638 + n = __copy_from_user(to, from, n);
19639 + else if ((long)n > 0)
19640 + memset(to, 0, n);
19641
19642 return n;
19643 }
19644 @@ -622,17 +693,18 @@ copy_from_user(void *to, const void __user *from, unsigned long n)
19645 static inline unsigned long __must_check
19646 copy_to_user(void __user *to, const void *from, unsigned long n)
19647 {
19648 - int sz = __compiletime_object_size(from);
19649 + size_t sz = __compiletime_object_size(from);
19650
19651 might_fault();
19652
19653 /* See the comment in copy_from_user() above. */
19654 - if (likely(sz < 0 || sz >= n))
19655 - n = _copy_to_user(to, from, n);
19656 - else if(__builtin_constant_p(n))
19657 - copy_to_user_overflow();
19658 - else
19659 - __copy_to_user_overflow(sz, n);
19660 + if (likely(sz != (size_t)-1 && sz < n)) {
19661 + if(__builtin_constant_p(n))
19662 + copy_to_user_overflow();
19663 + else
19664 + __copy_to_user_overflow(sz, n);
19665 + } else if (access_ok(VERIFY_WRITE, to, n))
19666 + n = __copy_to_user(to, from, n);
19667
19668 return n;
19669 }
19670 diff --git a/arch/x86/include/asm/uaccess_32.h b/arch/x86/include/asm/uaccess_32.h
19671 index 3c03a5d..1071638 100644
19672 --- a/arch/x86/include/asm/uaccess_32.h
19673 +++ b/arch/x86/include/asm/uaccess_32.h
19674 @@ -43,6 +43,11 @@ unsigned long __must_check __copy_from_user_ll_nocache_nozero
19675 static __always_inline unsigned long __must_check
19676 __copy_to_user_inatomic(void __user *to, const void *from, unsigned long n)
19677 {
19678 + if ((long)n < 0)
19679 + return n;
19680 +
19681 + check_object_size(from, n, true);
19682 +
19683 if (__builtin_constant_p(n)) {
19684 unsigned long ret;
19685
19686 @@ -82,12 +87,16 @@ static __always_inline unsigned long __must_check
19687 __copy_to_user(void __user *to, const void *from, unsigned long n)
19688 {
19689 might_fault();
19690 +
19691 return __copy_to_user_inatomic(to, from, n);
19692 }
19693
19694 static __always_inline unsigned long
19695 __copy_from_user_inatomic(void *to, const void __user *from, unsigned long n)
19696 {
19697 + if ((long)n < 0)
19698 + return n;
19699 +
19700 /* Avoid zeroing the tail if the copy fails..
19701 * If 'n' is constant and 1, 2, or 4, we do still zero on a failure,
19702 * but as the zeroing behaviour is only significant when n is not
19703 @@ -137,6 +146,12 @@ static __always_inline unsigned long
19704 __copy_from_user(void *to, const void __user *from, unsigned long n)
19705 {
19706 might_fault();
19707 +
19708 + if ((long)n < 0)
19709 + return n;
19710 +
19711 + check_object_size(to, n, false);
19712 +
19713 if (__builtin_constant_p(n)) {
19714 unsigned long ret;
19715
19716 @@ -159,6 +174,10 @@ static __always_inline unsigned long __copy_from_user_nocache(void *to,
19717 const void __user *from, unsigned long n)
19718 {
19719 might_fault();
19720 +
19721 + if ((long)n < 0)
19722 + return n;
19723 +
19724 if (__builtin_constant_p(n)) {
19725 unsigned long ret;
19726
19727 @@ -181,7 +200,10 @@ static __always_inline unsigned long
19728 __copy_from_user_inatomic_nocache(void *to, const void __user *from,
19729 unsigned long n)
19730 {
19731 - return __copy_from_user_ll_nocache_nozero(to, from, n);
19732 + if ((long)n < 0)
19733 + return n;
19734 +
19735 + return __copy_from_user_ll_nocache_nozero(to, from, n);
19736 }
19737
19738 #endif /* _ASM_X86_UACCESS_32_H */
19739 diff --git a/arch/x86/include/asm/uaccess_64.h b/arch/x86/include/asm/uaccess_64.h
19740 index 190413d..206c200 100644
19741 --- a/arch/x86/include/asm/uaccess_64.h
19742 +++ b/arch/x86/include/asm/uaccess_64.h
19743 @@ -10,6 +10,9 @@
19744 #include <asm/alternative.h>
19745 #include <asm/cpufeature.h>
19746 #include <asm/page.h>
19747 +#include <asm/pgtable.h>
19748 +
19749 +#define set_fs(x) (current_thread_info()->addr_limit = (x))
19750
19751 /*
19752 * Copy To/From Userspace
19753 @@ -17,14 +20,14 @@
19754
19755 /* Handles exceptions in both to and from, but doesn't do access_ok */
19756 __must_check unsigned long
19757 -copy_user_enhanced_fast_string(void *to, const void *from, unsigned len);
19758 +copy_user_enhanced_fast_string(void *to, const void *from, unsigned len) __size_overflow(3);
19759 __must_check unsigned long
19760 -copy_user_generic_string(void *to, const void *from, unsigned len);
19761 +copy_user_generic_string(void *to, const void *from, unsigned len) __size_overflow(3);
19762 __must_check unsigned long
19763 -copy_user_generic_unrolled(void *to, const void *from, unsigned len);
19764 +copy_user_generic_unrolled(void *to, const void *from, unsigned len) __size_overflow(3);
19765
19766 static __always_inline __must_check unsigned long
19767 -copy_user_generic(void *to, const void *from, unsigned len)
19768 +copy_user_generic(void *to, const void *from, unsigned long len)
19769 {
19770 unsigned ret;
19771
19772 @@ -46,121 +49,170 @@ copy_user_generic(void *to, const void *from, unsigned len)
19773 }
19774
19775 __must_check unsigned long
19776 -copy_in_user(void __user *to, const void __user *from, unsigned len);
19777 +copy_in_user(void __user *to, const void __user *from, unsigned long len);
19778
19779 static __always_inline __must_check
19780 -int __copy_from_user_nocheck(void *dst, const void __user *src, unsigned size)
19781 +unsigned long __copy_from_user_nocheck(void *dst, const void __user *src, unsigned long size)
19782 {
19783 - int ret = 0;
19784 + size_t sz = __compiletime_object_size(dst);
19785 + unsigned ret = 0;
19786 +
19787 + if (size > INT_MAX)
19788 + return size;
19789 +
19790 + check_object_size(dst, size, false);
19791 +
19792 +#ifdef CONFIG_PAX_MEMORY_UDEREF
19793 + if (!access_ok_noprefault(VERIFY_READ, src, size))
19794 + return size;
19795 +#endif
19796 +
19797 + if (unlikely(sz != (size_t)-1 && sz < size)) {
19798 + if(__builtin_constant_p(size))
19799 + copy_from_user_overflow();
19800 + else
19801 + __copy_from_user_overflow(sz, size);
19802 + return size;
19803 + }
19804
19805 if (!__builtin_constant_p(size))
19806 - return copy_user_generic(dst, (__force void *)src, size);
19807 + return copy_user_generic(dst, (__force_kernel const void *)____m(src), size);
19808 switch (size) {
19809 - case 1:__get_user_asm(*(u8 *)dst, (u8 __user *)src,
19810 + case 1:__get_user_asm(*(u8 *)dst, (const u8 __user *)src,
19811 ret, "b", "b", "=q", 1);
19812 return ret;
19813 - case 2:__get_user_asm(*(u16 *)dst, (u16 __user *)src,
19814 + case 2:__get_user_asm(*(u16 *)dst, (const u16 __user *)src,
19815 ret, "w", "w", "=r", 2);
19816 return ret;
19817 - case 4:__get_user_asm(*(u32 *)dst, (u32 __user *)src,
19818 + case 4:__get_user_asm(*(u32 *)dst, (const u32 __user *)src,
19819 ret, "l", "k", "=r", 4);
19820 return ret;
19821 - case 8:__get_user_asm(*(u64 *)dst, (u64 __user *)src,
19822 + case 8:__get_user_asm(*(u64 *)dst, (const u64 __user *)src,
19823 ret, "q", "", "=r", 8);
19824 return ret;
19825 case 10:
19826 - __get_user_asm(*(u64 *)dst, (u64 __user *)src,
19827 + __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
19828 ret, "q", "", "=r", 10);
19829 if (unlikely(ret))
19830 return ret;
19831 __get_user_asm(*(u16 *)(8 + (char *)dst),
19832 - (u16 __user *)(8 + (char __user *)src),
19833 + (const u16 __user *)(8 + (const char __user *)src),
19834 ret, "w", "w", "=r", 2);
19835 return ret;
19836 case 16:
19837 - __get_user_asm(*(u64 *)dst, (u64 __user *)src,
19838 + __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
19839 ret, "q", "", "=r", 16);
19840 if (unlikely(ret))
19841 return ret;
19842 __get_user_asm(*(u64 *)(8 + (char *)dst),
19843 - (u64 __user *)(8 + (char __user *)src),
19844 + (const u64 __user *)(8 + (const char __user *)src),
19845 ret, "q", "", "=r", 8);
19846 return ret;
19847 default:
19848 - return copy_user_generic(dst, (__force void *)src, size);
19849 + return copy_user_generic(dst, (__force_kernel const void *)____m(src), size);
19850 }
19851 }
19852
19853 static __always_inline __must_check
19854 -int __copy_from_user(void *dst, const void __user *src, unsigned size)
19855 +unsigned long __copy_from_user(void *dst, const void __user *src, unsigned long size)
19856 {
19857 might_fault();
19858 return __copy_from_user_nocheck(dst, src, size);
19859 }
19860
19861 static __always_inline __must_check
19862 -int __copy_to_user_nocheck(void __user *dst, const void *src, unsigned size)
19863 +unsigned long __copy_to_user_nocheck(void __user *dst, const void *src, unsigned long size)
19864 {
19865 - int ret = 0;
19866 + size_t sz = __compiletime_object_size(src);
19867 + unsigned ret = 0;
19868 +
19869 + if (size > INT_MAX)
19870 + return size;
19871 +
19872 + check_object_size(src, size, true);
19873 +
19874 +#ifdef CONFIG_PAX_MEMORY_UDEREF
19875 + if (!access_ok_noprefault(VERIFY_WRITE, dst, size))
19876 + return size;
19877 +#endif
19878 +
19879 + if (unlikely(sz != (size_t)-1 && sz < size)) {
19880 + if(__builtin_constant_p(size))
19881 + copy_to_user_overflow();
19882 + else
19883 + __copy_to_user_overflow(sz, size);
19884 + return size;
19885 + }
19886
19887 if (!__builtin_constant_p(size))
19888 - return copy_user_generic((__force void *)dst, src, size);
19889 + return copy_user_generic((__force_kernel void *)____m(dst), src, size);
19890 switch (size) {
19891 - case 1:__put_user_asm(*(u8 *)src, (u8 __user *)dst,
19892 + case 1:__put_user_asm(*(const u8 *)src, (u8 __user *)dst,
19893 ret, "b", "b", "iq", 1);
19894 return ret;
19895 - case 2:__put_user_asm(*(u16 *)src, (u16 __user *)dst,
19896 + case 2:__put_user_asm(*(const u16 *)src, (u16 __user *)dst,
19897 ret, "w", "w", "ir", 2);
19898 return ret;
19899 - case 4:__put_user_asm(*(u32 *)src, (u32 __user *)dst,
19900 + case 4:__put_user_asm(*(const u32 *)src, (u32 __user *)dst,
19901 ret, "l", "k", "ir", 4);
19902 return ret;
19903 - case 8:__put_user_asm(*(u64 *)src, (u64 __user *)dst,
19904 + case 8:__put_user_asm(*(const u64 *)src, (u64 __user *)dst,
19905 ret, "q", "", "er", 8);
19906 return ret;
19907 case 10:
19908 - __put_user_asm(*(u64 *)src, (u64 __user *)dst,
19909 + __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
19910 ret, "q", "", "er", 10);
19911 if (unlikely(ret))
19912 return ret;
19913 asm("":::"memory");
19914 - __put_user_asm(4[(u16 *)src], 4 + (u16 __user *)dst,
19915 + __put_user_asm(4[(const u16 *)src], 4 + (u16 __user *)dst,
19916 ret, "w", "w", "ir", 2);
19917 return ret;
19918 case 16:
19919 - __put_user_asm(*(u64 *)src, (u64 __user *)dst,
19920 + __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
19921 ret, "q", "", "er", 16);
19922 if (unlikely(ret))
19923 return ret;
19924 asm("":::"memory");
19925 - __put_user_asm(1[(u64 *)src], 1 + (u64 __user *)dst,
19926 + __put_user_asm(1[(const u64 *)src], 1 + (u64 __user *)dst,
19927 ret, "q", "", "er", 8);
19928 return ret;
19929 default:
19930 - return copy_user_generic((__force void *)dst, src, size);
19931 + return copy_user_generic((__force_kernel void *)____m(dst), src, size);
19932 }
19933 }
19934
19935 static __always_inline __must_check
19936 -int __copy_to_user(void __user *dst, const void *src, unsigned size)
19937 +unsigned long __copy_to_user(void __user *dst, const void *src, unsigned long size)
19938 {
19939 might_fault();
19940 return __copy_to_user_nocheck(dst, src, size);
19941 }
19942
19943 static __always_inline __must_check
19944 -int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
19945 +unsigned long __copy_in_user(void __user *dst, const void __user *src, unsigned size)
19946 {
19947 - int ret = 0;
19948 + unsigned ret = 0;
19949
19950 might_fault();
19951 +
19952 + if (size > INT_MAX)
19953 + return size;
19954 +
19955 +#ifdef CONFIG_PAX_MEMORY_UDEREF
19956 + if (!access_ok_noprefault(VERIFY_READ, src, size))
19957 + return size;
19958 + if (!access_ok_noprefault(VERIFY_WRITE, dst, size))
19959 + return size;
19960 +#endif
19961 +
19962 if (!__builtin_constant_p(size))
19963 - return copy_user_generic((__force void *)dst,
19964 - (__force void *)src, size);
19965 + return copy_user_generic((__force_kernel void *)____m(dst),
19966 + (__force_kernel const void *)____m(src), size);
19967 switch (size) {
19968 case 1: {
19969 u8 tmp;
19970 - __get_user_asm(tmp, (u8 __user *)src,
19971 + __get_user_asm(tmp, (const u8 __user *)src,
19972 ret, "b", "b", "=q", 1);
19973 if (likely(!ret))
19974 __put_user_asm(tmp, (u8 __user *)dst,
19975 @@ -169,7 +221,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
19976 }
19977 case 2: {
19978 u16 tmp;
19979 - __get_user_asm(tmp, (u16 __user *)src,
19980 + __get_user_asm(tmp, (const u16 __user *)src,
19981 ret, "w", "w", "=r", 2);
19982 if (likely(!ret))
19983 __put_user_asm(tmp, (u16 __user *)dst,
19984 @@ -179,7 +231,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
19985
19986 case 4: {
19987 u32 tmp;
19988 - __get_user_asm(tmp, (u32 __user *)src,
19989 + __get_user_asm(tmp, (const u32 __user *)src,
19990 ret, "l", "k", "=r", 4);
19991 if (likely(!ret))
19992 __put_user_asm(tmp, (u32 __user *)dst,
19993 @@ -188,7 +240,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
19994 }
19995 case 8: {
19996 u64 tmp;
19997 - __get_user_asm(tmp, (u64 __user *)src,
19998 + __get_user_asm(tmp, (const u64 __user *)src,
19999 ret, "q", "", "=r", 8);
20000 if (likely(!ret))
20001 __put_user_asm(tmp, (u64 __user *)dst,
20002 @@ -196,41 +248,58 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
20003 return ret;
20004 }
20005 default:
20006 - return copy_user_generic((__force void *)dst,
20007 - (__force void *)src, size);
20008 + return copy_user_generic((__force_kernel void *)____m(dst),
20009 + (__force_kernel const void *)____m(src), size);
20010 }
20011 }
20012
20013 -static __must_check __always_inline int
20014 -__copy_from_user_inatomic(void *dst, const void __user *src, unsigned size)
20015 +static __must_check __always_inline unsigned long
20016 +__copy_from_user_inatomic(void *dst, const void __user *src, unsigned long size)
20017 {
20018 - return __copy_from_user_nocheck(dst, (__force const void *)src, size);
20019 + return __copy_from_user_nocheck(dst, src, size);
20020 }
20021
20022 -static __must_check __always_inline int
20023 -__copy_to_user_inatomic(void __user *dst, const void *src, unsigned size)
20024 +static __must_check __always_inline unsigned long
20025 +__copy_to_user_inatomic(void __user *dst, const void *src, unsigned long size)
20026 {
20027 - return __copy_to_user_nocheck((__force void *)dst, src, size);
20028 + return __copy_to_user_nocheck(dst, src, size);
20029 }
20030
20031 -extern long __copy_user_nocache(void *dst, const void __user *src,
20032 - unsigned size, int zerorest);
20033 +extern unsigned long __copy_user_nocache(void *dst, const void __user *src,
20034 + unsigned long size, int zerorest);
20035
20036 -static inline int
20037 -__copy_from_user_nocache(void *dst, const void __user *src, unsigned size)
20038 +static inline unsigned long
20039 +__copy_from_user_nocache(void *dst, const void __user *src, unsigned long size)
20040 {
20041 might_fault();
20042 +
20043 + if (size > INT_MAX)
20044 + return size;
20045 +
20046 +#ifdef CONFIG_PAX_MEMORY_UDEREF
20047 + if (!access_ok_noprefault(VERIFY_READ, src, size))
20048 + return size;
20049 +#endif
20050 +
20051 return __copy_user_nocache(dst, src, size, 1);
20052 }
20053
20054 -static inline int
20055 +static inline unsigned long
20056 __copy_from_user_inatomic_nocache(void *dst, const void __user *src,
20057 - unsigned size)
20058 + unsigned long size)
20059 {
20060 + if (size > INT_MAX)
20061 + return size;
20062 +
20063 +#ifdef CONFIG_PAX_MEMORY_UDEREF
20064 + if (!access_ok_noprefault(VERIFY_READ, src, size))
20065 + return size;
20066 +#endif
20067 +
20068 return __copy_user_nocache(dst, src, size, 0);
20069 }
20070
20071 unsigned long
20072 -copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest);
20073 +copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest) __size_overflow(3);
20074
20075 #endif /* _ASM_X86_UACCESS_64_H */
20076 diff --git a/arch/x86/include/asm/word-at-a-time.h b/arch/x86/include/asm/word-at-a-time.h
20077 index 5b238981..77fdd78 100644
20078 --- a/arch/x86/include/asm/word-at-a-time.h
20079 +++ b/arch/x86/include/asm/word-at-a-time.h
20080 @@ -11,7 +11,7 @@
20081 * and shift, for example.
20082 */
20083 struct word_at_a_time {
20084 - const unsigned long one_bits, high_bits;
20085 + unsigned long one_bits, high_bits;
20086 };
20087
20088 #define WORD_AT_A_TIME_CONSTANTS { REPEAT_BYTE(0x01), REPEAT_BYTE(0x80) }
20089 diff --git a/arch/x86/include/asm/x86_init.h b/arch/x86/include/asm/x86_init.h
20090 index 0f1be11..f7542bf 100644
20091 --- a/arch/x86/include/asm/x86_init.h
20092 +++ b/arch/x86/include/asm/x86_init.h
20093 @@ -129,7 +129,7 @@ struct x86_init_ops {
20094 struct x86_init_timers timers;
20095 struct x86_init_iommu iommu;
20096 struct x86_init_pci pci;
20097 -};
20098 +} __no_const;
20099
20100 /**
20101 * struct x86_cpuinit_ops - platform specific cpu hotplug setups
20102 @@ -140,7 +140,7 @@ struct x86_cpuinit_ops {
20103 void (*setup_percpu_clockev)(void);
20104 void (*early_percpu_clock_init)(void);
20105 void (*fixup_cpu_id)(struct cpuinfo_x86 *c, int node);
20106 -};
20107 +} __no_const;
20108
20109 struct timespec;
20110
20111 @@ -168,7 +168,7 @@ struct x86_platform_ops {
20112 void (*save_sched_clock_state)(void);
20113 void (*restore_sched_clock_state)(void);
20114 void (*apic_post_init)(void);
20115 -};
20116 +} __no_const;
20117
20118 struct pci_dev;
20119 struct msi_msg;
20120 @@ -185,7 +185,7 @@ struct x86_msi_ops {
20121 int (*setup_hpet_msi)(unsigned int irq, unsigned int id);
20122 u32 (*msi_mask_irq)(struct msi_desc *desc, u32 mask, u32 flag);
20123 u32 (*msix_mask_irq)(struct msi_desc *desc, u32 flag);
20124 -};
20125 +} __no_const;
20126
20127 struct IO_APIC_route_entry;
20128 struct io_apic_irq_attr;
20129 @@ -206,7 +206,7 @@ struct x86_io_apic_ops {
20130 unsigned int destination, int vector,
20131 struct io_apic_irq_attr *attr);
20132 void (*eoi_ioapic_pin)(int apic, int pin, int vector);
20133 -};
20134 +} __no_const;
20135
20136 extern struct x86_init_ops x86_init;
20137 extern struct x86_cpuinit_ops x86_cpuinit;
20138 diff --git a/arch/x86/include/asm/xen/page.h b/arch/x86/include/asm/xen/page.h
20139 index b913915..4f5a581 100644
20140 --- a/arch/x86/include/asm/xen/page.h
20141 +++ b/arch/x86/include/asm/xen/page.h
20142 @@ -56,7 +56,7 @@ extern int m2p_remove_override(struct page *page,
20143 extern struct page *m2p_find_override(unsigned long mfn);
20144 extern unsigned long m2p_find_override_pfn(unsigned long mfn, unsigned long pfn);
20145
20146 -static inline unsigned long pfn_to_mfn(unsigned long pfn)
20147 +static inline unsigned long __intentional_overflow(-1) pfn_to_mfn(unsigned long pfn)
20148 {
20149 unsigned long mfn;
20150
20151 diff --git a/arch/x86/include/asm/xsave.h b/arch/x86/include/asm/xsave.h
20152 index 0415cda..3b22adc 100644
20153 --- a/arch/x86/include/asm/xsave.h
20154 +++ b/arch/x86/include/asm/xsave.h
20155 @@ -70,8 +70,11 @@ static inline int xsave_user(struct xsave_struct __user *buf)
20156 if (unlikely(err))
20157 return -EFAULT;
20158
20159 + pax_open_userland();
20160 __asm__ __volatile__(ASM_STAC "\n"
20161 - "1: .byte " REX_PREFIX "0x0f,0xae,0x27\n"
20162 + "1:"
20163 + __copyuser_seg
20164 + ".byte " REX_PREFIX "0x0f,0xae,0x27\n"
20165 "2: " ASM_CLAC "\n"
20166 ".section .fixup,\"ax\"\n"
20167 "3: movl $-1,%[err]\n"
20168 @@ -81,18 +84,22 @@ static inline int xsave_user(struct xsave_struct __user *buf)
20169 : [err] "=r" (err)
20170 : "D" (buf), "a" (-1), "d" (-1), "0" (0)
20171 : "memory");
20172 + pax_close_userland();
20173 return err;
20174 }
20175
20176 static inline int xrestore_user(struct xsave_struct __user *buf, u64 mask)
20177 {
20178 int err;
20179 - struct xsave_struct *xstate = ((__force struct xsave_struct *)buf);
20180 + struct xsave_struct *xstate = ((__force_kernel struct xsave_struct *)buf);
20181 u32 lmask = mask;
20182 u32 hmask = mask >> 32;
20183
20184 + pax_open_userland();
20185 __asm__ __volatile__(ASM_STAC "\n"
20186 - "1: .byte " REX_PREFIX "0x0f,0xae,0x2f\n"
20187 + "1:"
20188 + __copyuser_seg
20189 + ".byte " REX_PREFIX "0x0f,0xae,0x2f\n"
20190 "2: " ASM_CLAC "\n"
20191 ".section .fixup,\"ax\"\n"
20192 "3: movl $-1,%[err]\n"
20193 @@ -102,6 +109,7 @@ static inline int xrestore_user(struct xsave_struct __user *buf, u64 mask)
20194 : [err] "=r" (err)
20195 : "D" (xstate), "a" (lmask), "d" (hmask), "0" (0)
20196 : "memory"); /* memory required? */
20197 + pax_close_userland();
20198 return err;
20199 }
20200
20201 diff --git a/arch/x86/include/uapi/asm/e820.h b/arch/x86/include/uapi/asm/e820.h
20202 index bbae024..e1528f9 100644
20203 --- a/arch/x86/include/uapi/asm/e820.h
20204 +++ b/arch/x86/include/uapi/asm/e820.h
20205 @@ -63,7 +63,7 @@ struct e820map {
20206 #define ISA_START_ADDRESS 0xa0000
20207 #define ISA_END_ADDRESS 0x100000
20208
20209 -#define BIOS_BEGIN 0x000a0000
20210 +#define BIOS_BEGIN 0x000c0000
20211 #define BIOS_END 0x00100000
20212
20213 #define BIOS_ROM_BASE 0xffe00000
20214 diff --git a/arch/x86/include/uapi/asm/ptrace-abi.h b/arch/x86/include/uapi/asm/ptrace-abi.h
20215 index 7b0a55a..ad115bf 100644
20216 --- a/arch/x86/include/uapi/asm/ptrace-abi.h
20217 +++ b/arch/x86/include/uapi/asm/ptrace-abi.h
20218 @@ -49,7 +49,6 @@
20219 #define EFLAGS 144
20220 #define RSP 152
20221 #define SS 160
20222 -#define ARGOFFSET R11
20223 #endif /* __ASSEMBLY__ */
20224
20225 /* top of stack page */
20226 diff --git a/arch/x86/kernel/Makefile b/arch/x86/kernel/Makefile
20227 index 9b0a34e..fc7e553 100644
20228 --- a/arch/x86/kernel/Makefile
20229 +++ b/arch/x86/kernel/Makefile
20230 @@ -24,7 +24,7 @@ obj-y += time.o ioport.o ldt.o dumpstack.o nmi.o
20231 obj-y += setup.o x86_init.o i8259.o irqinit.o jump_label.o
20232 obj-$(CONFIG_IRQ_WORK) += irq_work.o
20233 obj-y += probe_roms.o
20234 -obj-$(CONFIG_X86_32) += i386_ksyms_32.o
20235 +obj-$(CONFIG_X86_32) += sys_i386_32.o i386_ksyms_32.o
20236 obj-$(CONFIG_X86_64) += sys_x86_64.o x8664_ksyms_64.o
20237 obj-y += syscall_$(BITS).o
20238 obj-$(CONFIG_X86_64) += vsyscall_64.o
20239 diff --git a/arch/x86/kernel/acpi/boot.c b/arch/x86/kernel/acpi/boot.c
20240 index 6c0b43b..e67bb31 100644
20241 --- a/arch/x86/kernel/acpi/boot.c
20242 +++ b/arch/x86/kernel/acpi/boot.c
20243 @@ -1315,7 +1315,7 @@ static int __init dmi_ignore_irq0_timer_override(const struct dmi_system_id *d)
20244 * If your system is blacklisted here, but you find that acpi=force
20245 * works for you, please contact linux-acpi@vger.kernel.org
20246 */
20247 -static struct dmi_system_id __initdata acpi_dmi_table[] = {
20248 +static const struct dmi_system_id __initconst acpi_dmi_table[] = {
20249 /*
20250 * Boxes that need ACPI disabled
20251 */
20252 @@ -1390,7 +1390,7 @@ static struct dmi_system_id __initdata acpi_dmi_table[] = {
20253 };
20254
20255 /* second table for DMI checks that should run after early-quirks */
20256 -static struct dmi_system_id __initdata acpi_dmi_table_late[] = {
20257 +static const struct dmi_system_id __initconst acpi_dmi_table_late[] = {
20258 /*
20259 * HP laptops which use a DSDT reporting as HP/SB400/10000,
20260 * which includes some code which overrides all temperature
20261 diff --git a/arch/x86/kernel/acpi/sleep.c b/arch/x86/kernel/acpi/sleep.c
20262 index 3a2ae4c..9db31d6 100644
20263 --- a/arch/x86/kernel/acpi/sleep.c
20264 +++ b/arch/x86/kernel/acpi/sleep.c
20265 @@ -99,8 +99,12 @@ int x86_acpi_suspend_lowlevel(void)
20266 #else /* CONFIG_64BIT */
20267 #ifdef CONFIG_SMP
20268 stack_start = (unsigned long)temp_stack + sizeof(temp_stack);
20269 +
20270 + pax_open_kernel();
20271 early_gdt_descr.address =
20272 (unsigned long)get_cpu_gdt_table(smp_processor_id());
20273 + pax_close_kernel();
20274 +
20275 initial_gs = per_cpu_offset(smp_processor_id());
20276 #endif
20277 initial_code = (unsigned long)wakeup_long64;
20278 diff --git a/arch/x86/kernel/acpi/wakeup_32.S b/arch/x86/kernel/acpi/wakeup_32.S
20279 index 665c6b7..eae4d56 100644
20280 --- a/arch/x86/kernel/acpi/wakeup_32.S
20281 +++ b/arch/x86/kernel/acpi/wakeup_32.S
20282 @@ -29,13 +29,11 @@ wakeup_pmode_return:
20283 # and restore the stack ... but you need gdt for this to work
20284 movl saved_context_esp, %esp
20285
20286 - movl %cs:saved_magic, %eax
20287 - cmpl $0x12345678, %eax
20288 + cmpl $0x12345678, saved_magic
20289 jne bogus_magic
20290
20291 # jump to place where we left off
20292 - movl saved_eip, %eax
20293 - jmp *%eax
20294 + jmp *(saved_eip)
20295
20296 bogus_magic:
20297 jmp bogus_magic
20298 diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c
20299 index df94598..f3b29bf 100644
20300 --- a/arch/x86/kernel/alternative.c
20301 +++ b/arch/x86/kernel/alternative.c
20302 @@ -269,6 +269,13 @@ void __init_or_module apply_alternatives(struct alt_instr *start,
20303 */
20304 for (a = start; a < end; a++) {
20305 instr = (u8 *)&a->instr_offset + a->instr_offset;
20306 +
20307 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20308 + instr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
20309 + if (instr < (u8 *)_text || (u8 *)_einittext <= instr)
20310 + instr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
20311 +#endif
20312 +
20313 replacement = (u8 *)&a->repl_offset + a->repl_offset;
20314 BUG_ON(a->replacementlen > a->instrlen);
20315 BUG_ON(a->instrlen > sizeof(insnbuf));
20316 @@ -300,10 +307,16 @@ static void alternatives_smp_lock(const s32 *start, const s32 *end,
20317 for (poff = start; poff < end; poff++) {
20318 u8 *ptr = (u8 *)poff + *poff;
20319
20320 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20321 + ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
20322 + if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
20323 + ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
20324 +#endif
20325 +
20326 if (!*poff || ptr < text || ptr >= text_end)
20327 continue;
20328 /* turn DS segment override prefix into lock prefix */
20329 - if (*ptr == 0x3e)
20330 + if (*ktla_ktva(ptr) == 0x3e)
20331 text_poke(ptr, ((unsigned char []){0xf0}), 1);
20332 }
20333 mutex_unlock(&text_mutex);
20334 @@ -318,10 +331,16 @@ static void alternatives_smp_unlock(const s32 *start, const s32 *end,
20335 for (poff = start; poff < end; poff++) {
20336 u8 *ptr = (u8 *)poff + *poff;
20337
20338 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20339 + ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
20340 + if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
20341 + ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
20342 +#endif
20343 +
20344 if (!*poff || ptr < text || ptr >= text_end)
20345 continue;
20346 /* turn lock prefix into DS segment override prefix */
20347 - if (*ptr == 0xf0)
20348 + if (*ktla_ktva(ptr) == 0xf0)
20349 text_poke(ptr, ((unsigned char []){0x3E}), 1);
20350 }
20351 mutex_unlock(&text_mutex);
20352 @@ -458,7 +477,7 @@ void __init_or_module apply_paravirt(struct paravirt_patch_site *start,
20353
20354 BUG_ON(p->len > MAX_PATCH_LEN);
20355 /* prep the buffer with the original instructions */
20356 - memcpy(insnbuf, p->instr, p->len);
20357 + memcpy(insnbuf, ktla_ktva(p->instr), p->len);
20358 used = pv_init_ops.patch(p->instrtype, p->clobbers, insnbuf,
20359 (unsigned long)p->instr, p->len);
20360
20361 @@ -505,7 +524,7 @@ void __init alternative_instructions(void)
20362 if (!uniproc_patched || num_possible_cpus() == 1)
20363 free_init_pages("SMP alternatives",
20364 (unsigned long)__smp_locks,
20365 - (unsigned long)__smp_locks_end);
20366 + PAGE_ALIGN((unsigned long)__smp_locks_end));
20367 #endif
20368
20369 apply_paravirt(__parainstructions, __parainstructions_end);
20370 @@ -525,13 +544,17 @@ void __init alternative_instructions(void)
20371 * instructions. And on the local CPU you need to be protected again NMI or MCE
20372 * handlers seeing an inconsistent instruction while you patch.
20373 */
20374 -void *__init_or_module text_poke_early(void *addr, const void *opcode,
20375 +void *__kprobes text_poke_early(void *addr, const void *opcode,
20376 size_t len)
20377 {
20378 unsigned long flags;
20379 local_irq_save(flags);
20380 - memcpy(addr, opcode, len);
20381 +
20382 + pax_open_kernel();
20383 + memcpy(ktla_ktva(addr), opcode, len);
20384 sync_core();
20385 + pax_close_kernel();
20386 +
20387 local_irq_restore(flags);
20388 /* Could also do a CLFLUSH here to speed up CPU recovery; but
20389 that causes hangs on some VIA CPUs. */
20390 @@ -553,36 +576,22 @@ void *__init_or_module text_poke_early(void *addr, const void *opcode,
20391 */
20392 void *__kprobes text_poke(void *addr, const void *opcode, size_t len)
20393 {
20394 - unsigned long flags;
20395 - char *vaddr;
20396 + unsigned char *vaddr = ktla_ktva(addr);
20397 struct page *pages[2];
20398 - int i;
20399 + size_t i;
20400
20401 if (!core_kernel_text((unsigned long)addr)) {
20402 - pages[0] = vmalloc_to_page(addr);
20403 - pages[1] = vmalloc_to_page(addr + PAGE_SIZE);
20404 + pages[0] = vmalloc_to_page(vaddr);
20405 + pages[1] = vmalloc_to_page(vaddr + PAGE_SIZE);
20406 } else {
20407 - pages[0] = virt_to_page(addr);
20408 + pages[0] = virt_to_page(vaddr);
20409 WARN_ON(!PageReserved(pages[0]));
20410 - pages[1] = virt_to_page(addr + PAGE_SIZE);
20411 + pages[1] = virt_to_page(vaddr + PAGE_SIZE);
20412 }
20413 BUG_ON(!pages[0]);
20414 - local_irq_save(flags);
20415 - set_fixmap(FIX_TEXT_POKE0, page_to_phys(pages[0]));
20416 - if (pages[1])
20417 - set_fixmap(FIX_TEXT_POKE1, page_to_phys(pages[1]));
20418 - vaddr = (char *)fix_to_virt(FIX_TEXT_POKE0);
20419 - memcpy(&vaddr[(unsigned long)addr & ~PAGE_MASK], opcode, len);
20420 - clear_fixmap(FIX_TEXT_POKE0);
20421 - if (pages[1])
20422 - clear_fixmap(FIX_TEXT_POKE1);
20423 - local_flush_tlb();
20424 - sync_core();
20425 - /* Could also do a CLFLUSH here to speed up CPU recovery; but
20426 - that causes hangs on some VIA CPUs. */
20427 + text_poke_early(addr, opcode, len);
20428 for (i = 0; i < len; i++)
20429 - BUG_ON(((char *)addr)[i] != ((char *)opcode)[i]);
20430 - local_irq_restore(flags);
20431 + BUG_ON((vaddr)[i] != ((const unsigned char *)opcode)[i]);
20432 return addr;
20433 }
20434
20435 @@ -602,7 +611,7 @@ int poke_int3_handler(struct pt_regs *regs)
20436 if (likely(!bp_patching_in_progress))
20437 return 0;
20438
20439 - if (user_mode_vm(regs) || regs->ip != (unsigned long)bp_int3_addr)
20440 + if (user_mode(regs) || regs->ip != (unsigned long)bp_int3_addr)
20441 return 0;
20442
20443 /* set up the specified breakpoint handler */
20444 @@ -636,7 +645,7 @@ int poke_int3_handler(struct pt_regs *regs)
20445 */
20446 void *text_poke_bp(void *addr, const void *opcode, size_t len, void *handler)
20447 {
20448 - unsigned char int3 = 0xcc;
20449 + const unsigned char int3 = 0xcc;
20450
20451 bp_int3_handler = handler;
20452 bp_int3_addr = (u8 *)addr + sizeof(int3);
20453 diff --git a/arch/x86/kernel/apic/apic.c b/arch/x86/kernel/apic/apic.c
20454 index d278736..0b4af9a8 100644
20455 --- a/arch/x86/kernel/apic/apic.c
20456 +++ b/arch/x86/kernel/apic/apic.c
20457 @@ -191,7 +191,7 @@ int first_system_vector = 0xfe;
20458 /*
20459 * Debug level, exported for io_apic.c
20460 */
20461 -unsigned int apic_verbosity;
20462 +int apic_verbosity;
20463
20464 int pic_mode;
20465
20466 @@ -1986,7 +1986,7 @@ static inline void __smp_error_interrupt(struct pt_regs *regs)
20467 apic_write(APIC_ESR, 0);
20468 v1 = apic_read(APIC_ESR);
20469 ack_APIC_irq();
20470 - atomic_inc(&irq_err_count);
20471 + atomic_inc_unchecked(&irq_err_count);
20472
20473 apic_printk(APIC_DEBUG, KERN_DEBUG "APIC error on CPU%d: %02x(%02x)",
20474 smp_processor_id(), v0 , v1);
20475 diff --git a/arch/x86/kernel/apic/apic_flat_64.c b/arch/x86/kernel/apic/apic_flat_64.c
20476 index 00c77cf..2dc6a2d 100644
20477 --- a/arch/x86/kernel/apic/apic_flat_64.c
20478 +++ b/arch/x86/kernel/apic/apic_flat_64.c
20479 @@ -157,7 +157,7 @@ static int flat_probe(void)
20480 return 1;
20481 }
20482
20483 -static struct apic apic_flat = {
20484 +static struct apic apic_flat __read_only = {
20485 .name = "flat",
20486 .probe = flat_probe,
20487 .acpi_madt_oem_check = flat_acpi_madt_oem_check,
20488 @@ -271,7 +271,7 @@ static int physflat_probe(void)
20489 return 0;
20490 }
20491
20492 -static struct apic apic_physflat = {
20493 +static struct apic apic_physflat __read_only = {
20494
20495 .name = "physical flat",
20496 .probe = physflat_probe,
20497 diff --git a/arch/x86/kernel/apic/apic_noop.c b/arch/x86/kernel/apic/apic_noop.c
20498 index e145f28..2752888 100644
20499 --- a/arch/x86/kernel/apic/apic_noop.c
20500 +++ b/arch/x86/kernel/apic/apic_noop.c
20501 @@ -119,7 +119,7 @@ static void noop_apic_write(u32 reg, u32 v)
20502 WARN_ON_ONCE(cpu_has_apic && !disable_apic);
20503 }
20504
20505 -struct apic apic_noop = {
20506 +struct apic apic_noop __read_only = {
20507 .name = "noop",
20508 .probe = noop_probe,
20509 .acpi_madt_oem_check = NULL,
20510 diff --git a/arch/x86/kernel/apic/bigsmp_32.c b/arch/x86/kernel/apic/bigsmp_32.c
20511 index d50e364..543bee3 100644
20512 --- a/arch/x86/kernel/apic/bigsmp_32.c
20513 +++ b/arch/x86/kernel/apic/bigsmp_32.c
20514 @@ -152,7 +152,7 @@ static int probe_bigsmp(void)
20515 return dmi_bigsmp;
20516 }
20517
20518 -static struct apic apic_bigsmp = {
20519 +static struct apic apic_bigsmp __read_only = {
20520
20521 .name = "bigsmp",
20522 .probe = probe_bigsmp,
20523 diff --git a/arch/x86/kernel/apic/es7000_32.c b/arch/x86/kernel/apic/es7000_32.c
20524 index c552247..587a316 100644
20525 --- a/arch/x86/kernel/apic/es7000_32.c
20526 +++ b/arch/x86/kernel/apic/es7000_32.c
20527 @@ -608,8 +608,7 @@ static int es7000_mps_oem_check_cluster(struct mpc_table *mpc, char *oem,
20528 return ret && es7000_apic_is_cluster();
20529 }
20530
20531 -/* We've been warned by a false positive warning.Use __refdata to keep calm. */
20532 -static struct apic __refdata apic_es7000_cluster = {
20533 +static struct apic apic_es7000_cluster __read_only = {
20534
20535 .name = "es7000",
20536 .probe = probe_es7000,
20537 @@ -675,7 +674,7 @@ static struct apic __refdata apic_es7000_cluster = {
20538 .x86_32_early_logical_apicid = es7000_early_logical_apicid,
20539 };
20540
20541 -static struct apic __refdata apic_es7000 = {
20542 +static struct apic apic_es7000 __read_only = {
20543
20544 .name = "es7000",
20545 .probe = probe_es7000,
20546 diff --git a/arch/x86/kernel/apic/io_apic.c b/arch/x86/kernel/apic/io_apic.c
20547 index e63a5bd..c0babf8 100644
20548 --- a/arch/x86/kernel/apic/io_apic.c
20549 +++ b/arch/x86/kernel/apic/io_apic.c
20550 @@ -1060,7 +1060,7 @@ int IO_APIC_get_PCI_irq_vector(int bus, int slot, int pin,
20551 }
20552 EXPORT_SYMBOL(IO_APIC_get_PCI_irq_vector);
20553
20554 -void lock_vector_lock(void)
20555 +void lock_vector_lock(void) __acquires(vector_lock)
20556 {
20557 /* Used to the online set of cpus does not change
20558 * during assign_irq_vector.
20559 @@ -1068,7 +1068,7 @@ void lock_vector_lock(void)
20560 raw_spin_lock(&vector_lock);
20561 }
20562
20563 -void unlock_vector_lock(void)
20564 +void unlock_vector_lock(void) __releases(vector_lock)
20565 {
20566 raw_spin_unlock(&vector_lock);
20567 }
20568 @@ -2367,7 +2367,7 @@ static void ack_apic_edge(struct irq_data *data)
20569 ack_APIC_irq();
20570 }
20571
20572 -atomic_t irq_mis_count;
20573 +atomic_unchecked_t irq_mis_count;
20574
20575 #ifdef CONFIG_GENERIC_PENDING_IRQ
20576 static bool io_apic_level_ack_pending(struct irq_cfg *cfg)
20577 @@ -2508,7 +2508,7 @@ static void ack_apic_level(struct irq_data *data)
20578 * at the cpu.
20579 */
20580 if (!(v & (1 << (i & 0x1f)))) {
20581 - atomic_inc(&irq_mis_count);
20582 + atomic_inc_unchecked(&irq_mis_count);
20583
20584 eoi_ioapic_irq(irq, cfg);
20585 }
20586 diff --git a/arch/x86/kernel/apic/numaq_32.c b/arch/x86/kernel/apic/numaq_32.c
20587 index 1e42e8f..daacf44 100644
20588 --- a/arch/x86/kernel/apic/numaq_32.c
20589 +++ b/arch/x86/kernel/apic/numaq_32.c
20590 @@ -455,8 +455,7 @@ static void numaq_setup_portio_remap(void)
20591 (u_long) xquad_portio, (u_long) num_quads*XQUAD_PORTIO_QUAD);
20592 }
20593
20594 -/* Use __refdata to keep false positive warning calm. */
20595 -static struct apic __refdata apic_numaq = {
20596 +static struct apic apic_numaq __read_only = {
20597
20598 .name = "NUMAQ",
20599 .probe = probe_numaq,
20600 diff --git a/arch/x86/kernel/apic/probe_32.c b/arch/x86/kernel/apic/probe_32.c
20601 index eb35ef9..f184a21 100644
20602 --- a/arch/x86/kernel/apic/probe_32.c
20603 +++ b/arch/x86/kernel/apic/probe_32.c
20604 @@ -72,7 +72,7 @@ static int probe_default(void)
20605 return 1;
20606 }
20607
20608 -static struct apic apic_default = {
20609 +static struct apic apic_default __read_only = {
20610
20611 .name = "default",
20612 .probe = probe_default,
20613 diff --git a/arch/x86/kernel/apic/summit_32.c b/arch/x86/kernel/apic/summit_32.c
20614 index 77c95c0..434f8a4 100644
20615 --- a/arch/x86/kernel/apic/summit_32.c
20616 +++ b/arch/x86/kernel/apic/summit_32.c
20617 @@ -486,7 +486,7 @@ void setup_summit(void)
20618 }
20619 #endif
20620
20621 -static struct apic apic_summit = {
20622 +static struct apic apic_summit __read_only = {
20623
20624 .name = "summit",
20625 .probe = probe_summit,
20626 diff --git a/arch/x86/kernel/apic/x2apic_cluster.c b/arch/x86/kernel/apic/x2apic_cluster.c
20627 index 140e29d..d88bc95 100644
20628 --- a/arch/x86/kernel/apic/x2apic_cluster.c
20629 +++ b/arch/x86/kernel/apic/x2apic_cluster.c
20630 @@ -183,7 +183,7 @@ update_clusterinfo(struct notifier_block *nfb, unsigned long action, void *hcpu)
20631 return notifier_from_errno(err);
20632 }
20633
20634 -static struct notifier_block __refdata x2apic_cpu_notifier = {
20635 +static struct notifier_block x2apic_cpu_notifier = {
20636 .notifier_call = update_clusterinfo,
20637 };
20638
20639 @@ -235,7 +235,7 @@ static void cluster_vector_allocation_domain(int cpu, struct cpumask *retmask,
20640 cpumask_and(retmask, mask, per_cpu(cpus_in_cluster, cpu));
20641 }
20642
20643 -static struct apic apic_x2apic_cluster = {
20644 +static struct apic apic_x2apic_cluster __read_only = {
20645
20646 .name = "cluster x2apic",
20647 .probe = x2apic_cluster_probe,
20648 diff --git a/arch/x86/kernel/apic/x2apic_phys.c b/arch/x86/kernel/apic/x2apic_phys.c
20649 index 562a76d..a003c0f 100644
20650 --- a/arch/x86/kernel/apic/x2apic_phys.c
20651 +++ b/arch/x86/kernel/apic/x2apic_phys.c
20652 @@ -89,7 +89,7 @@ static int x2apic_phys_probe(void)
20653 return apic == &apic_x2apic_phys;
20654 }
20655
20656 -static struct apic apic_x2apic_phys = {
20657 +static struct apic apic_x2apic_phys __read_only = {
20658
20659 .name = "physical x2apic",
20660 .probe = x2apic_phys_probe,
20661 diff --git a/arch/x86/kernel/apic/x2apic_uv_x.c b/arch/x86/kernel/apic/x2apic_uv_x.c
20662 index ad0dc04..0d9cc56 100644
20663 --- a/arch/x86/kernel/apic/x2apic_uv_x.c
20664 +++ b/arch/x86/kernel/apic/x2apic_uv_x.c
20665 @@ -350,7 +350,7 @@ static int uv_probe(void)
20666 return apic == &apic_x2apic_uv_x;
20667 }
20668
20669 -static struct apic __refdata apic_x2apic_uv_x = {
20670 +static struct apic apic_x2apic_uv_x __read_only = {
20671
20672 .name = "UV large system",
20673 .probe = uv_probe,
20674 diff --git a/arch/x86/kernel/apm_32.c b/arch/x86/kernel/apm_32.c
20675 index 3ab0343..814c4787 100644
20676 --- a/arch/x86/kernel/apm_32.c
20677 +++ b/arch/x86/kernel/apm_32.c
20678 @@ -433,7 +433,7 @@ static DEFINE_MUTEX(apm_mutex);
20679 * This is for buggy BIOS's that refer to (real mode) segment 0x40
20680 * even though they are called in protected mode.
20681 */
20682 -static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
20683 +static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
20684 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
20685
20686 static const char driver_version[] = "1.16ac"; /* no spaces */
20687 @@ -611,7 +611,10 @@ static long __apm_bios_call(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 @@ -620,7 +623,11 @@ static long __apm_bios_call(void *_call)
20699 &call->esi);
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
20709 return call->eax & 0xff;
20710 @@ -687,7 +694,10 @@ static long __apm_bios_call_simple(void *_call)
20711 BUG_ON(cpu != 0);
20712 gdt = get_cpu_gdt_table(cpu);
20713 save_desc_40 = gdt[0x40 / 8];
20714 +
20715 + pax_open_kernel();
20716 gdt[0x40 / 8] = bad_bios_desc;
20717 + pax_close_kernel();
20718
20719 apm_irq_save(flags);
20720 APM_DO_SAVE_SEGS;
20721 @@ -695,7 +705,11 @@ static long __apm_bios_call_simple(void *_call)
20722 &call->eax);
20723 APM_DO_RESTORE_SEGS;
20724 apm_irq_restore(flags);
20725 +
20726 + pax_open_kernel();
20727 gdt[0x40 / 8] = save_desc_40;
20728 + pax_close_kernel();
20729 +
20730 put_cpu();
20731 return error;
20732 }
20733 @@ -2362,12 +2376,15 @@ static int __init apm_init(void)
20734 * code to that CPU.
20735 */
20736 gdt = get_cpu_gdt_table(0);
20737 +
20738 + pax_open_kernel();
20739 set_desc_base(&gdt[APM_CS >> 3],
20740 (unsigned long)__va((unsigned long)apm_info.bios.cseg << 4));
20741 set_desc_base(&gdt[APM_CS_16 >> 3],
20742 (unsigned long)__va((unsigned long)apm_info.bios.cseg_16 << 4));
20743 set_desc_base(&gdt[APM_DS >> 3],
20744 (unsigned long)__va((unsigned long)apm_info.bios.dseg << 4));
20745 + pax_close_kernel();
20746
20747 proc_create("apm", 0, NULL, &apm_file_ops);
20748
20749 diff --git a/arch/x86/kernel/asm-offsets.c b/arch/x86/kernel/asm-offsets.c
20750 index 9f6b934..cf5ffb3 100644
20751 --- a/arch/x86/kernel/asm-offsets.c
20752 +++ b/arch/x86/kernel/asm-offsets.c
20753 @@ -32,6 +32,8 @@ void common(void) {
20754 OFFSET(TI_flags, thread_info, flags);
20755 OFFSET(TI_status, thread_info, status);
20756 OFFSET(TI_addr_limit, thread_info, addr_limit);
20757 + OFFSET(TI_lowest_stack, thread_info, lowest_stack);
20758 + DEFINE(TI_task_thread_sp0, offsetof(struct task_struct, thread.sp0) - offsetof(struct task_struct, tinfo));
20759
20760 BLANK();
20761 OFFSET(crypto_tfm_ctx_offset, crypto_tfm, __crt_ctx);
20762 @@ -52,8 +54,26 @@ void common(void) {
20763 OFFSET(PV_CPU_irq_enable_sysexit, pv_cpu_ops, irq_enable_sysexit);
20764 OFFSET(PV_CPU_read_cr0, pv_cpu_ops, read_cr0);
20765 OFFSET(PV_MMU_read_cr2, pv_mmu_ops, read_cr2);
20766 +
20767 +#ifdef CONFIG_PAX_KERNEXEC
20768 + OFFSET(PV_CPU_write_cr0, pv_cpu_ops, write_cr0);
20769 #endif
20770
20771 +#ifdef CONFIG_PAX_MEMORY_UDEREF
20772 + OFFSET(PV_MMU_read_cr3, pv_mmu_ops, read_cr3);
20773 + OFFSET(PV_MMU_write_cr3, pv_mmu_ops, write_cr3);
20774 +#ifdef CONFIG_X86_64
20775 + OFFSET(PV_MMU_set_pgd_batched, pv_mmu_ops, set_pgd_batched);
20776 +#endif
20777 +#endif
20778 +
20779 +#endif
20780 +
20781 + BLANK();
20782 + DEFINE(PAGE_SIZE_asm, PAGE_SIZE);
20783 + DEFINE(PAGE_SHIFT_asm, PAGE_SHIFT);
20784 + DEFINE(THREAD_SIZE_asm, THREAD_SIZE);
20785 +
20786 #ifdef CONFIG_XEN
20787 BLANK();
20788 OFFSET(XEN_vcpu_info_mask, vcpu_info, evtchn_upcall_mask);
20789 diff --git a/arch/x86/kernel/asm-offsets_64.c b/arch/x86/kernel/asm-offsets_64.c
20790 index e7c798b..2b2019b 100644
20791 --- a/arch/x86/kernel/asm-offsets_64.c
20792 +++ b/arch/x86/kernel/asm-offsets_64.c
20793 @@ -77,6 +77,7 @@ int main(void)
20794 BLANK();
20795 #undef ENTRY
20796
20797 + DEFINE(TSS_size, sizeof(struct tss_struct));
20798 OFFSET(TSS_ist, tss_struct, x86_tss.ist);
20799 BLANK();
20800
20801 diff --git a/arch/x86/kernel/cpu/Makefile b/arch/x86/kernel/cpu/Makefile
20802 index 47b56a7..efc2bc6 100644
20803 --- a/arch/x86/kernel/cpu/Makefile
20804 +++ b/arch/x86/kernel/cpu/Makefile
20805 @@ -8,10 +8,6 @@ CFLAGS_REMOVE_common.o = -pg
20806 CFLAGS_REMOVE_perf_event.o = -pg
20807 endif
20808
20809 -# Make sure load_percpu_segment has no stackprotector
20810 -nostackp := $(call cc-option, -fno-stack-protector)
20811 -CFLAGS_common.o := $(nostackp)
20812 -
20813 obj-y := intel_cacheinfo.o scattered.o topology.o
20814 obj-y += proc.o capflags.o powerflags.o common.o
20815 obj-y += rdrand.o
20816 diff --git a/arch/x86/kernel/cpu/amd.c b/arch/x86/kernel/cpu/amd.c
20817 index 59bfebc..d8f27bd 100644
20818 --- a/arch/x86/kernel/cpu/amd.c
20819 +++ b/arch/x86/kernel/cpu/amd.c
20820 @@ -753,7 +753,7 @@ static void init_amd(struct cpuinfo_x86 *c)
20821 static unsigned int amd_size_cache(struct cpuinfo_x86 *c, unsigned int size)
20822 {
20823 /* AMD errata T13 (order #21922) */
20824 - if ((c->x86 == 6)) {
20825 + if (c->x86 == 6) {
20826 /* Duron Rev A0 */
20827 if (c->x86_model == 3 && c->x86_mask == 0)
20828 size = 64;
20829 diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c
20830 index fe2bdd0..77b0d1b 100644
20831 --- a/arch/x86/kernel/cpu/common.c
20832 +++ b/arch/x86/kernel/cpu/common.c
20833 @@ -88,60 +88,6 @@ static const struct cpu_dev default_cpu = {
20834
20835 static const struct cpu_dev *this_cpu = &default_cpu;
20836
20837 -DEFINE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page) = { .gdt = {
20838 -#ifdef CONFIG_X86_64
20839 - /*
20840 - * We need valid kernel segments for data and code in long mode too
20841 - * IRET will check the segment types kkeil 2000/10/28
20842 - * Also sysret mandates a special GDT layout
20843 - *
20844 - * TLS descriptors are currently at a different place compared to i386.
20845 - * Hopefully nobody expects them at a fixed place (Wine?)
20846 - */
20847 - [GDT_ENTRY_KERNEL32_CS] = GDT_ENTRY_INIT(0xc09b, 0, 0xfffff),
20848 - [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xa09b, 0, 0xfffff),
20849 - [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc093, 0, 0xfffff),
20850 - [GDT_ENTRY_DEFAULT_USER32_CS] = GDT_ENTRY_INIT(0xc0fb, 0, 0xfffff),
20851 - [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f3, 0, 0xfffff),
20852 - [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xa0fb, 0, 0xfffff),
20853 -#else
20854 - [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xc09a, 0, 0xfffff),
20855 - [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
20856 - [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xc0fa, 0, 0xfffff),
20857 - [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f2, 0, 0xfffff),
20858 - /*
20859 - * Segments used for calling PnP BIOS have byte granularity.
20860 - * They code segments and data segments have fixed 64k limits,
20861 - * the transfer segment sizes are set at run time.
20862 - */
20863 - /* 32-bit code */
20864 - [GDT_ENTRY_PNPBIOS_CS32] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
20865 - /* 16-bit code */
20866 - [GDT_ENTRY_PNPBIOS_CS16] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
20867 - /* 16-bit data */
20868 - [GDT_ENTRY_PNPBIOS_DS] = GDT_ENTRY_INIT(0x0092, 0, 0xffff),
20869 - /* 16-bit data */
20870 - [GDT_ENTRY_PNPBIOS_TS1] = GDT_ENTRY_INIT(0x0092, 0, 0),
20871 - /* 16-bit data */
20872 - [GDT_ENTRY_PNPBIOS_TS2] = GDT_ENTRY_INIT(0x0092, 0, 0),
20873 - /*
20874 - * The APM segments have byte granularity and their bases
20875 - * are set at run time. All have 64k limits.
20876 - */
20877 - /* 32-bit code */
20878 - [GDT_ENTRY_APMBIOS_BASE] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
20879 - /* 16-bit code */
20880 - [GDT_ENTRY_APMBIOS_BASE+1] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
20881 - /* data */
20882 - [GDT_ENTRY_APMBIOS_BASE+2] = GDT_ENTRY_INIT(0x4092, 0, 0xffff),
20883 -
20884 - [GDT_ENTRY_ESPFIX_SS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
20885 - [GDT_ENTRY_PERCPU] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
20886 - GDT_STACK_CANARY_INIT
20887 -#endif
20888 -} };
20889 -EXPORT_PER_CPU_SYMBOL_GPL(gdt_page);
20890 -
20891 static int __init x86_xsave_setup(char *s)
20892 {
20893 setup_clear_cpu_cap(X86_FEATURE_XSAVE);
20894 @@ -293,6 +239,59 @@ static __always_inline void setup_smap(struct cpuinfo_x86 *c)
20895 }
20896 }
20897
20898 +#ifdef CONFIG_X86_64
20899 +static __init int setup_disable_pcid(char *arg)
20900 +{
20901 + setup_clear_cpu_cap(X86_FEATURE_PCID);
20902 + setup_clear_cpu_cap(X86_FEATURE_INVPCID);
20903 +
20904 +#ifdef CONFIG_PAX_MEMORY_UDEREF
20905 + if (clone_pgd_mask != ~(pgdval_t)0UL)
20906 + pax_user_shadow_base = 1UL << TASK_SIZE_MAX_SHIFT;
20907 +#endif
20908 +
20909 + return 1;
20910 +}
20911 +__setup("nopcid", setup_disable_pcid);
20912 +
20913 +static void setup_pcid(struct cpuinfo_x86 *c)
20914 +{
20915 + if (!cpu_has(c, X86_FEATURE_PCID)) {
20916 + clear_cpu_cap(c, X86_FEATURE_INVPCID);
20917 +
20918 +#ifdef CONFIG_PAX_MEMORY_UDEREF
20919 + if (clone_pgd_mask != ~(pgdval_t)0UL) {
20920 + pax_open_kernel();
20921 + pax_user_shadow_base = 1UL << TASK_SIZE_MAX_SHIFT;
20922 + pax_close_kernel();
20923 + printk("PAX: slow and weak UDEREF enabled\n");
20924 + } else
20925 + printk("PAX: UDEREF disabled\n");
20926 +#endif
20927 +
20928 + return;
20929 + }
20930 +
20931 + printk("PAX: PCID detected\n");
20932 + set_in_cr4(X86_CR4_PCIDE);
20933 +
20934 +#ifdef CONFIG_PAX_MEMORY_UDEREF
20935 + pax_open_kernel();
20936 + clone_pgd_mask = ~(pgdval_t)0UL;
20937 + pax_close_kernel();
20938 + if (pax_user_shadow_base)
20939 + printk("PAX: weak UDEREF enabled\n");
20940 + else {
20941 + set_cpu_cap(c, X86_FEATURE_STRONGUDEREF);
20942 + printk("PAX: strong UDEREF enabled\n");
20943 + }
20944 +#endif
20945 +
20946 + if (cpu_has(c, X86_FEATURE_INVPCID))
20947 + printk("PAX: INVPCID detected\n");
20948 +}
20949 +#endif
20950 +
20951 /*
20952 * Some CPU features depend on higher CPUID levels, which may not always
20953 * be available due to CPUID level capping or broken virtualization
20954 @@ -393,7 +392,7 @@ void switch_to_new_gdt(int cpu)
20955 {
20956 struct desc_ptr gdt_descr;
20957
20958 - gdt_descr.address = (long)get_cpu_gdt_table(cpu);
20959 + gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
20960 gdt_descr.size = GDT_SIZE - 1;
20961 load_gdt(&gdt_descr);
20962 /* Reload the per-cpu base */
20963 @@ -882,6 +881,10 @@ static void identify_cpu(struct cpuinfo_x86 *c)
20964 setup_smep(c);
20965 setup_smap(c);
20966
20967 +#ifdef CONFIG_X86_64
20968 + setup_pcid(c);
20969 +#endif
20970 +
20971 /*
20972 * The vendor-specific functions might have changed features.
20973 * Now we do "generic changes."
20974 @@ -890,6 +893,10 @@ static void identify_cpu(struct cpuinfo_x86 *c)
20975 /* Filter out anything that depends on CPUID levels we don't have */
20976 filter_cpuid_features(c, true);
20977
20978 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
20979 + setup_clear_cpu_cap(X86_FEATURE_SEP);
20980 +#endif
20981 +
20982 /* If the model name is still unset, do table lookup. */
20983 if (!c->x86_model_id[0]) {
20984 const char *p;
20985 @@ -1077,10 +1084,12 @@ static __init int setup_disablecpuid(char *arg)
20986 }
20987 __setup("clearcpuid=", setup_disablecpuid);
20988
20989 +DEFINE_PER_CPU(struct thread_info *, current_tinfo) = &init_task.tinfo;
20990 +EXPORT_PER_CPU_SYMBOL(current_tinfo);
20991 +
20992 #ifdef CONFIG_X86_64
20993 -struct desc_ptr idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) idt_table };
20994 -struct desc_ptr debug_idt_descr = { NR_VECTORS * 16 - 1,
20995 - (unsigned long) debug_idt_table };
20996 +struct desc_ptr idt_descr __read_only = { NR_VECTORS * 16 - 1, (unsigned long) idt_table };
20997 +const struct desc_ptr debug_idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) debug_idt_table };
20998
20999 DEFINE_PER_CPU_FIRST(union irq_stack_union,
21000 irq_stack_union) __aligned(PAGE_SIZE) __visible;
21001 @@ -1094,7 +1103,7 @@ DEFINE_PER_CPU(struct task_struct *, current_task) ____cacheline_aligned =
21002 EXPORT_PER_CPU_SYMBOL(current_task);
21003
21004 DEFINE_PER_CPU(unsigned long, kernel_stack) =
21005 - (unsigned long)&init_thread_union - KERNEL_STACK_OFFSET + THREAD_SIZE;
21006 + (unsigned long)&init_thread_union - 16 + THREAD_SIZE;
21007 EXPORT_PER_CPU_SYMBOL(kernel_stack);
21008
21009 DEFINE_PER_CPU(char *, irq_stack_ptr) =
21010 @@ -1244,7 +1253,7 @@ void cpu_init(void)
21011 load_ucode_ap();
21012
21013 cpu = stack_smp_processor_id();
21014 - t = &per_cpu(init_tss, cpu);
21015 + t = init_tss + cpu;
21016 oist = &per_cpu(orig_ist, cpu);
21017
21018 #ifdef CONFIG_NUMA
21019 @@ -1279,7 +1288,6 @@ void cpu_init(void)
21020 wrmsrl(MSR_KERNEL_GS_BASE, 0);
21021 barrier();
21022
21023 - x86_configure_nx();
21024 enable_x2apic();
21025
21026 /*
21027 @@ -1331,7 +1339,7 @@ void cpu_init(void)
21028 {
21029 int cpu = smp_processor_id();
21030 struct task_struct *curr = current;
21031 - struct tss_struct *t = &per_cpu(init_tss, cpu);
21032 + struct tss_struct *t = init_tss + cpu;
21033 struct thread_struct *thread = &curr->thread;
21034
21035 show_ucode_info_early();
21036 diff --git a/arch/x86/kernel/cpu/intel_cacheinfo.c b/arch/x86/kernel/cpu/intel_cacheinfo.c
21037 index 0641113..06f5ba4 100644
21038 --- a/arch/x86/kernel/cpu/intel_cacheinfo.c
21039 +++ b/arch/x86/kernel/cpu/intel_cacheinfo.c
21040 @@ -1014,6 +1014,22 @@ static struct attribute *default_attrs[] = {
21041 };
21042
21043 #ifdef CONFIG_AMD_NB
21044 +static struct attribute *default_attrs_amd_nb[] = {
21045 + &type.attr,
21046 + &level.attr,
21047 + &coherency_line_size.attr,
21048 + &physical_line_partition.attr,
21049 + &ways_of_associativity.attr,
21050 + &number_of_sets.attr,
21051 + &size.attr,
21052 + &shared_cpu_map.attr,
21053 + &shared_cpu_list.attr,
21054 + NULL,
21055 + NULL,
21056 + NULL,
21057 + NULL
21058 +};
21059 +
21060 static struct attribute **amd_l3_attrs(void)
21061 {
21062 static struct attribute **attrs;
21063 @@ -1024,18 +1040,7 @@ static struct attribute **amd_l3_attrs(void)
21064
21065 n = ARRAY_SIZE(default_attrs);
21066
21067 - if (amd_nb_has_feature(AMD_NB_L3_INDEX_DISABLE))
21068 - n += 2;
21069 -
21070 - if (amd_nb_has_feature(AMD_NB_L3_PARTITIONING))
21071 - n += 1;
21072 -
21073 - attrs = kzalloc(n * sizeof (struct attribute *), GFP_KERNEL);
21074 - if (attrs == NULL)
21075 - return attrs = default_attrs;
21076 -
21077 - for (n = 0; default_attrs[n]; n++)
21078 - attrs[n] = default_attrs[n];
21079 + attrs = default_attrs_amd_nb;
21080
21081 if (amd_nb_has_feature(AMD_NB_L3_INDEX_DISABLE)) {
21082 attrs[n++] = &cache_disable_0.attr;
21083 @@ -1086,6 +1091,13 @@ static struct kobj_type ktype_cache = {
21084 .default_attrs = default_attrs,
21085 };
21086
21087 +#ifdef CONFIG_AMD_NB
21088 +static struct kobj_type ktype_cache_amd_nb = {
21089 + .sysfs_ops = &sysfs_ops,
21090 + .default_attrs = default_attrs_amd_nb,
21091 +};
21092 +#endif
21093 +
21094 static struct kobj_type ktype_percpu_entry = {
21095 .sysfs_ops = &sysfs_ops,
21096 };
21097 @@ -1151,20 +1163,26 @@ static int cache_add_dev(struct device *dev)
21098 return retval;
21099 }
21100
21101 +#ifdef CONFIG_AMD_NB
21102 + amd_l3_attrs();
21103 +#endif
21104 +
21105 for (i = 0; i < num_cache_leaves; i++) {
21106 + struct kobj_type *ktype;
21107 +
21108 this_object = INDEX_KOBJECT_PTR(cpu, i);
21109 this_object->cpu = cpu;
21110 this_object->index = i;
21111
21112 this_leaf = CPUID4_INFO_IDX(cpu, i);
21113
21114 - ktype_cache.default_attrs = default_attrs;
21115 + ktype = &ktype_cache;
21116 #ifdef CONFIG_AMD_NB
21117 if (this_leaf->base.nb)
21118 - ktype_cache.default_attrs = amd_l3_attrs();
21119 + ktype = &ktype_cache_amd_nb;
21120 #endif
21121 retval = kobject_init_and_add(&(this_object->kobj),
21122 - &ktype_cache,
21123 + ktype,
21124 per_cpu(ici_cache_kobject, cpu),
21125 "index%1lu", i);
21126 if (unlikely(retval)) {
21127 diff --git a/arch/x86/kernel/cpu/mcheck/mce.c b/arch/x86/kernel/cpu/mcheck/mce.c
21128 index b3218cd..99a75de 100644
21129 --- a/arch/x86/kernel/cpu/mcheck/mce.c
21130 +++ b/arch/x86/kernel/cpu/mcheck/mce.c
21131 @@ -45,6 +45,7 @@
21132 #include <asm/processor.h>
21133 #include <asm/mce.h>
21134 #include <asm/msr.h>
21135 +#include <asm/local.h>
21136
21137 #include "mce-internal.h"
21138
21139 @@ -258,7 +259,7 @@ static void print_mce(struct mce *m)
21140 !(m->mcgstatus & MCG_STATUS_EIPV) ? " !INEXACT!" : "",
21141 m->cs, m->ip);
21142
21143 - if (m->cs == __KERNEL_CS)
21144 + if (m->cs == __KERNEL_CS || m->cs == __KERNEXEC_KERNEL_CS)
21145 print_symbol("{%s}", m->ip);
21146 pr_cont("\n");
21147 }
21148 @@ -291,10 +292,10 @@ static void print_mce(struct mce *m)
21149
21150 #define PANIC_TIMEOUT 5 /* 5 seconds */
21151
21152 -static atomic_t mce_paniced;
21153 +static atomic_unchecked_t mce_paniced;
21154
21155 static int fake_panic;
21156 -static atomic_t mce_fake_paniced;
21157 +static atomic_unchecked_t mce_fake_paniced;
21158
21159 /* Panic in progress. Enable interrupts and wait for final IPI */
21160 static void wait_for_panic(void)
21161 @@ -318,7 +319,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
21162 /*
21163 * Make sure only one CPU runs in machine check panic
21164 */
21165 - if (atomic_inc_return(&mce_paniced) > 1)
21166 + if (atomic_inc_return_unchecked(&mce_paniced) > 1)
21167 wait_for_panic();
21168 barrier();
21169
21170 @@ -326,7 +327,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
21171 console_verbose();
21172 } else {
21173 /* Don't log too much for fake panic */
21174 - if (atomic_inc_return(&mce_fake_paniced) > 1)
21175 + if (atomic_inc_return_unchecked(&mce_fake_paniced) > 1)
21176 return;
21177 }
21178 /* First print corrected ones that are still unlogged */
21179 @@ -365,7 +366,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
21180 if (!fake_panic) {
21181 if (panic_timeout == 0)
21182 panic_timeout = mca_cfg.panic_timeout;
21183 - panic(msg);
21184 + panic("%s", msg);
21185 } else
21186 pr_emerg(HW_ERR "Fake kernel panic: %s\n", msg);
21187 }
21188 @@ -695,7 +696,7 @@ static int mce_timed_out(u64 *t)
21189 * might have been modified by someone else.
21190 */
21191 rmb();
21192 - if (atomic_read(&mce_paniced))
21193 + if (atomic_read_unchecked(&mce_paniced))
21194 wait_for_panic();
21195 if (!mca_cfg.monarch_timeout)
21196 goto out;
21197 @@ -1666,7 +1667,7 @@ static void unexpected_machine_check(struct pt_regs *regs, long error_code)
21198 }
21199
21200 /* Call the installed machine check handler for this CPU setup. */
21201 -void (*machine_check_vector)(struct pt_regs *, long error_code) =
21202 +void (*machine_check_vector)(struct pt_regs *, long error_code) __read_only =
21203 unexpected_machine_check;
21204
21205 /*
21206 @@ -1689,7 +1690,9 @@ void mcheck_cpu_init(struct cpuinfo_x86 *c)
21207 return;
21208 }
21209
21210 + pax_open_kernel();
21211 machine_check_vector = do_machine_check;
21212 + pax_close_kernel();
21213
21214 __mcheck_cpu_init_generic();
21215 __mcheck_cpu_init_vendor(c);
21216 @@ -1703,7 +1706,7 @@ void mcheck_cpu_init(struct cpuinfo_x86 *c)
21217 */
21218
21219 static DEFINE_SPINLOCK(mce_chrdev_state_lock);
21220 -static int mce_chrdev_open_count; /* #times opened */
21221 +static local_t mce_chrdev_open_count; /* #times opened */
21222 static int mce_chrdev_open_exclu; /* already open exclusive? */
21223
21224 static int mce_chrdev_open(struct inode *inode, struct file *file)
21225 @@ -1711,7 +1714,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
21226 spin_lock(&mce_chrdev_state_lock);
21227
21228 if (mce_chrdev_open_exclu ||
21229 - (mce_chrdev_open_count && (file->f_flags & O_EXCL))) {
21230 + (local_read(&mce_chrdev_open_count) && (file->f_flags & O_EXCL))) {
21231 spin_unlock(&mce_chrdev_state_lock);
21232
21233 return -EBUSY;
21234 @@ -1719,7 +1722,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
21235
21236 if (file->f_flags & O_EXCL)
21237 mce_chrdev_open_exclu = 1;
21238 - mce_chrdev_open_count++;
21239 + local_inc(&mce_chrdev_open_count);
21240
21241 spin_unlock(&mce_chrdev_state_lock);
21242
21243 @@ -1730,7 +1733,7 @@ static int mce_chrdev_release(struct inode *inode, struct file *file)
21244 {
21245 spin_lock(&mce_chrdev_state_lock);
21246
21247 - mce_chrdev_open_count--;
21248 + local_dec(&mce_chrdev_open_count);
21249 mce_chrdev_open_exclu = 0;
21250
21251 spin_unlock(&mce_chrdev_state_lock);
21252 @@ -2404,7 +2407,7 @@ static __init void mce_init_banks(void)
21253
21254 for (i = 0; i < mca_cfg.banks; i++) {
21255 struct mce_bank *b = &mce_banks[i];
21256 - struct device_attribute *a = &b->attr;
21257 + device_attribute_no_const *a = &b->attr;
21258
21259 sysfs_attr_init(&a->attr);
21260 a->attr.name = b->attrname;
21261 @@ -2472,7 +2475,7 @@ struct dentry *mce_get_debugfs_dir(void)
21262 static void mce_reset(void)
21263 {
21264 cpu_missing = 0;
21265 - atomic_set(&mce_fake_paniced, 0);
21266 + atomic_set_unchecked(&mce_fake_paniced, 0);
21267 atomic_set(&mce_executing, 0);
21268 atomic_set(&mce_callin, 0);
21269 atomic_set(&global_nwo, 0);
21270 diff --git a/arch/x86/kernel/cpu/mcheck/p5.c b/arch/x86/kernel/cpu/mcheck/p5.c
21271 index 1c044b1..37a2a43 100644
21272 --- a/arch/x86/kernel/cpu/mcheck/p5.c
21273 +++ b/arch/x86/kernel/cpu/mcheck/p5.c
21274 @@ -11,6 +11,7 @@
21275 #include <asm/processor.h>
21276 #include <asm/mce.h>
21277 #include <asm/msr.h>
21278 +#include <asm/pgtable.h>
21279
21280 /* By default disabled */
21281 int mce_p5_enabled __read_mostly;
21282 @@ -49,7 +50,9 @@ void intel_p5_mcheck_init(struct cpuinfo_x86 *c)
21283 if (!cpu_has(c, X86_FEATURE_MCE))
21284 return;
21285
21286 + pax_open_kernel();
21287 machine_check_vector = pentium_machine_check;
21288 + pax_close_kernel();
21289 /* Make sure the vector pointer is visible before we enable MCEs: */
21290 wmb();
21291
21292 diff --git a/arch/x86/kernel/cpu/mcheck/winchip.c b/arch/x86/kernel/cpu/mcheck/winchip.c
21293 index e9a701a..35317d6 100644
21294 --- a/arch/x86/kernel/cpu/mcheck/winchip.c
21295 +++ b/arch/x86/kernel/cpu/mcheck/winchip.c
21296 @@ -10,6 +10,7 @@
21297 #include <asm/processor.h>
21298 #include <asm/mce.h>
21299 #include <asm/msr.h>
21300 +#include <asm/pgtable.h>
21301
21302 /* Machine check handler for WinChip C6: */
21303 static void winchip_machine_check(struct pt_regs *regs, long error_code)
21304 @@ -23,7 +24,9 @@ void winchip_mcheck_init(struct cpuinfo_x86 *c)
21305 {
21306 u32 lo, hi;
21307
21308 + pax_open_kernel();
21309 machine_check_vector = winchip_machine_check;
21310 + pax_close_kernel();
21311 /* Make sure the vector pointer is visible before we enable MCEs: */
21312 wmb();
21313
21314 diff --git a/arch/x86/kernel/cpu/mtrr/main.c b/arch/x86/kernel/cpu/mtrr/main.c
21315 index f961de9..8a9d332 100644
21316 --- a/arch/x86/kernel/cpu/mtrr/main.c
21317 +++ b/arch/x86/kernel/cpu/mtrr/main.c
21318 @@ -66,7 +66,7 @@ static DEFINE_MUTEX(mtrr_mutex);
21319 u64 size_or_mask, size_and_mask;
21320 static bool mtrr_aps_delayed_init;
21321
21322 -static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM];
21323 +static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM] __read_only;
21324
21325 const struct mtrr_ops *mtrr_if;
21326
21327 diff --git a/arch/x86/kernel/cpu/mtrr/mtrr.h b/arch/x86/kernel/cpu/mtrr/mtrr.h
21328 index df5e41f..816c719 100644
21329 --- a/arch/x86/kernel/cpu/mtrr/mtrr.h
21330 +++ b/arch/x86/kernel/cpu/mtrr/mtrr.h
21331 @@ -25,7 +25,7 @@ struct mtrr_ops {
21332 int (*validate_add_page)(unsigned long base, unsigned long size,
21333 unsigned int type);
21334 int (*have_wrcomb)(void);
21335 -};
21336 +} __do_const;
21337
21338 extern int generic_get_free_region(unsigned long base, unsigned long size,
21339 int replace_reg);
21340 diff --git a/arch/x86/kernel/cpu/perf_event.c b/arch/x86/kernel/cpu/perf_event.c
21341 index db6cdbe..faaf834 100644
21342 --- a/arch/x86/kernel/cpu/perf_event.c
21343 +++ b/arch/x86/kernel/cpu/perf_event.c
21344 @@ -1351,7 +1351,7 @@ static void __init pmu_check_apic(void)
21345 pr_info("no hardware sampling interrupt available.\n");
21346 }
21347
21348 -static struct attribute_group x86_pmu_format_group = {
21349 +static attribute_group_no_const x86_pmu_format_group = {
21350 .name = "format",
21351 .attrs = NULL,
21352 };
21353 @@ -1450,7 +1450,7 @@ static struct attribute *events_attr[] = {
21354 NULL,
21355 };
21356
21357 -static struct attribute_group x86_pmu_events_group = {
21358 +static attribute_group_no_const x86_pmu_events_group = {
21359 .name = "events",
21360 .attrs = events_attr,
21361 };
21362 @@ -1961,7 +1961,7 @@ static unsigned long get_segment_base(unsigned int segment)
21363 if (idx > GDT_ENTRIES)
21364 return 0;
21365
21366 - desc = __this_cpu_ptr(&gdt_page.gdt[0]);
21367 + desc = get_cpu_gdt_table(smp_processor_id());
21368 }
21369
21370 return get_desc_base(desc + idx);
21371 @@ -2051,7 +2051,7 @@ perf_callchain_user(struct perf_callchain_entry *entry, struct pt_regs *regs)
21372 break;
21373
21374 perf_callchain_store(entry, frame.return_address);
21375 - fp = frame.next_frame;
21376 + fp = (const void __force_user *)frame.next_frame;
21377 }
21378 }
21379
21380 diff --git a/arch/x86/kernel/cpu/perf_event_amd_iommu.c b/arch/x86/kernel/cpu/perf_event_amd_iommu.c
21381 index 639d128..e92d7e5 100644
21382 --- a/arch/x86/kernel/cpu/perf_event_amd_iommu.c
21383 +++ b/arch/x86/kernel/cpu/perf_event_amd_iommu.c
21384 @@ -405,7 +405,7 @@ static void perf_iommu_del(struct perf_event *event, int flags)
21385 static __init int _init_events_attrs(struct perf_amd_iommu *perf_iommu)
21386 {
21387 struct attribute **attrs;
21388 - struct attribute_group *attr_group;
21389 + attribute_group_no_const *attr_group;
21390 int i = 0, j;
21391
21392 while (amd_iommu_v2_event_descs[i].attr.attr.name)
21393 diff --git a/arch/x86/kernel/cpu/perf_event_intel.c b/arch/x86/kernel/cpu/perf_event_intel.c
21394 index 0fa4f24..17990ed 100644
21395 --- a/arch/x86/kernel/cpu/perf_event_intel.c
21396 +++ b/arch/x86/kernel/cpu/perf_event_intel.c
21397 @@ -2314,10 +2314,10 @@ __init int intel_pmu_init(void)
21398 * v2 and above have a perf capabilities MSR
21399 */
21400 if (version > 1) {
21401 - u64 capabilities;
21402 + u64 capabilities = x86_pmu.intel_cap.capabilities;
21403
21404 - rdmsrl(MSR_IA32_PERF_CAPABILITIES, capabilities);
21405 - x86_pmu.intel_cap.capabilities = capabilities;
21406 + if (rdmsrl_safe(MSR_IA32_PERF_CAPABILITIES, &x86_pmu.intel_cap.capabilities))
21407 + x86_pmu.intel_cap.capabilities = capabilities;
21408 }
21409
21410 intel_ds_init();
21411 diff --git a/arch/x86/kernel/cpu/perf_event_intel_uncore.c b/arch/x86/kernel/cpu/perf_event_intel_uncore.c
21412 index 29c2487..a5606fa 100644
21413 --- a/arch/x86/kernel/cpu/perf_event_intel_uncore.c
21414 +++ b/arch/x86/kernel/cpu/perf_event_intel_uncore.c
21415 @@ -3318,7 +3318,7 @@ static void __init uncore_types_exit(struct intel_uncore_type **types)
21416 static int __init uncore_type_init(struct intel_uncore_type *type)
21417 {
21418 struct intel_uncore_pmu *pmus;
21419 - struct attribute_group *attr_group;
21420 + attribute_group_no_const *attr_group;
21421 struct attribute **attrs;
21422 int i, j;
21423
21424 diff --git a/arch/x86/kernel/cpu/perf_event_intel_uncore.h b/arch/x86/kernel/cpu/perf_event_intel_uncore.h
21425 index a80ab71..4089da5 100644
21426 --- a/arch/x86/kernel/cpu/perf_event_intel_uncore.h
21427 +++ b/arch/x86/kernel/cpu/perf_event_intel_uncore.h
21428 @@ -498,7 +498,7 @@ struct intel_uncore_box {
21429 struct uncore_event_desc {
21430 struct kobj_attribute attr;
21431 const char *config;
21432 -};
21433 +} __do_const;
21434
21435 #define INTEL_UNCORE_EVENT_DESC(_name, _config) \
21436 { \
21437 diff --git a/arch/x86/kernel/cpuid.c b/arch/x86/kernel/cpuid.c
21438 index 7d9481c..99c7e4b 100644
21439 --- a/arch/x86/kernel/cpuid.c
21440 +++ b/arch/x86/kernel/cpuid.c
21441 @@ -170,7 +170,7 @@ static int cpuid_class_cpu_callback(struct notifier_block *nfb,
21442 return notifier_from_errno(err);
21443 }
21444
21445 -static struct notifier_block __refdata cpuid_class_cpu_notifier =
21446 +static struct notifier_block cpuid_class_cpu_notifier =
21447 {
21448 .notifier_call = cpuid_class_cpu_callback,
21449 };
21450 diff --git a/arch/x86/kernel/crash.c b/arch/x86/kernel/crash.c
21451 index 18677a9..f67c45b 100644
21452 --- a/arch/x86/kernel/crash.c
21453 +++ b/arch/x86/kernel/crash.c
21454 @@ -58,10 +58,8 @@ static void kdump_nmi_callback(int cpu, struct pt_regs *regs)
21455 {
21456 #ifdef CONFIG_X86_32
21457 struct pt_regs fixed_regs;
21458 -#endif
21459
21460 -#ifdef CONFIG_X86_32
21461 - if (!user_mode_vm(regs)) {
21462 + if (!user_mode(regs)) {
21463 crash_fixup_ss_esp(&fixed_regs, regs);
21464 regs = &fixed_regs;
21465 }
21466 diff --git a/arch/x86/kernel/crash_dump_64.c b/arch/x86/kernel/crash_dump_64.c
21467 index afa64ad..dce67dd 100644
21468 --- a/arch/x86/kernel/crash_dump_64.c
21469 +++ b/arch/x86/kernel/crash_dump_64.c
21470 @@ -36,7 +36,7 @@ ssize_t copy_oldmem_page(unsigned long pfn, char *buf,
21471 return -ENOMEM;
21472
21473 if (userbuf) {
21474 - if (copy_to_user(buf, vaddr + offset, csize)) {
21475 + if (copy_to_user((char __force_user *)buf, vaddr + offset, csize)) {
21476 iounmap(vaddr);
21477 return -EFAULT;
21478 }
21479 diff --git a/arch/x86/kernel/doublefault.c b/arch/x86/kernel/doublefault.c
21480 index 5d3fe8d..02e1429 100644
21481 --- a/arch/x86/kernel/doublefault.c
21482 +++ b/arch/x86/kernel/doublefault.c
21483 @@ -13,7 +13,7 @@
21484
21485 #define DOUBLEFAULT_STACKSIZE (1024)
21486 static unsigned long doublefault_stack[DOUBLEFAULT_STACKSIZE];
21487 -#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE)
21488 +#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE-2)
21489
21490 #define ptr_ok(x) ((x) > PAGE_OFFSET && (x) < PAGE_OFFSET + MAXMEM)
21491
21492 @@ -23,7 +23,7 @@ static void doublefault_fn(void)
21493 unsigned long gdt, tss;
21494
21495 native_store_gdt(&gdt_desc);
21496 - gdt = gdt_desc.address;
21497 + gdt = (unsigned long)gdt_desc.address;
21498
21499 printk(KERN_EMERG "PANIC: double fault, gdt at %08lx [%d bytes]\n", gdt, gdt_desc.size);
21500
21501 @@ -60,10 +60,10 @@ struct tss_struct doublefault_tss __cacheline_aligned = {
21502 /* 0x2 bit is always set */
21503 .flags = X86_EFLAGS_SF | 0x2,
21504 .sp = STACK_START,
21505 - .es = __USER_DS,
21506 + .es = __KERNEL_DS,
21507 .cs = __KERNEL_CS,
21508 .ss = __KERNEL_DS,
21509 - .ds = __USER_DS,
21510 + .ds = __KERNEL_DS,
21511 .fs = __KERNEL_PERCPU,
21512
21513 .__cr3 = __pa_nodebug(swapper_pg_dir),
21514 diff --git a/arch/x86/kernel/dumpstack.c b/arch/x86/kernel/dumpstack.c
21515 index d9c12d3..7858b62 100644
21516 --- a/arch/x86/kernel/dumpstack.c
21517 +++ b/arch/x86/kernel/dumpstack.c
21518 @@ -2,6 +2,9 @@
21519 * Copyright (C) 1991, 1992 Linus Torvalds
21520 * Copyright (C) 2000, 2001, 2002 Andi Kleen, SuSE Labs
21521 */
21522 +#ifdef CONFIG_GRKERNSEC_HIDESYM
21523 +#define __INCLUDED_BY_HIDESYM 1
21524 +#endif
21525 #include <linux/kallsyms.h>
21526 #include <linux/kprobes.h>
21527 #include <linux/uaccess.h>
21528 @@ -40,16 +43,14 @@ void printk_address(unsigned long address)
21529 static void
21530 print_ftrace_graph_addr(unsigned long addr, void *data,
21531 const struct stacktrace_ops *ops,
21532 - struct thread_info *tinfo, int *graph)
21533 + struct task_struct *task, int *graph)
21534 {
21535 - struct task_struct *task;
21536 unsigned long ret_addr;
21537 int index;
21538
21539 if (addr != (unsigned long)return_to_handler)
21540 return;
21541
21542 - task = tinfo->task;
21543 index = task->curr_ret_stack;
21544
21545 if (!task->ret_stack || index < *graph)
21546 @@ -66,7 +67,7 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
21547 static inline void
21548 print_ftrace_graph_addr(unsigned long addr, void *data,
21549 const struct stacktrace_ops *ops,
21550 - struct thread_info *tinfo, int *graph)
21551 + struct task_struct *task, int *graph)
21552 { }
21553 #endif
21554
21555 @@ -77,10 +78,8 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
21556 * severe exception (double fault, nmi, stack fault, debug, mce) hardware stack
21557 */
21558
21559 -static inline int valid_stack_ptr(struct thread_info *tinfo,
21560 - void *p, unsigned int size, void *end)
21561 +static inline int valid_stack_ptr(void *t, void *p, unsigned int size, void *end)
21562 {
21563 - void *t = tinfo;
21564 if (end) {
21565 if (p < end && p >= (end-THREAD_SIZE))
21566 return 1;
21567 @@ -91,14 +90,14 @@ static inline int valid_stack_ptr(struct thread_info *tinfo,
21568 }
21569
21570 unsigned long
21571 -print_context_stack(struct thread_info *tinfo,
21572 +print_context_stack(struct task_struct *task, void *stack_start,
21573 unsigned long *stack, unsigned long bp,
21574 const struct stacktrace_ops *ops, void *data,
21575 unsigned long *end, int *graph)
21576 {
21577 struct stack_frame *frame = (struct stack_frame *)bp;
21578
21579 - while (valid_stack_ptr(tinfo, stack, sizeof(*stack), end)) {
21580 + while (valid_stack_ptr(stack_start, stack, sizeof(*stack), end)) {
21581 unsigned long addr;
21582
21583 addr = *stack;
21584 @@ -110,7 +109,7 @@ print_context_stack(struct thread_info *tinfo,
21585 } else {
21586 ops->address(data, addr, 0);
21587 }
21588 - print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
21589 + print_ftrace_graph_addr(addr, data, ops, task, graph);
21590 }
21591 stack++;
21592 }
21593 @@ -119,7 +118,7 @@ print_context_stack(struct thread_info *tinfo,
21594 EXPORT_SYMBOL_GPL(print_context_stack);
21595
21596 unsigned long
21597 -print_context_stack_bp(struct thread_info *tinfo,
21598 +print_context_stack_bp(struct task_struct *task, void *stack_start,
21599 unsigned long *stack, unsigned long bp,
21600 const struct stacktrace_ops *ops, void *data,
21601 unsigned long *end, int *graph)
21602 @@ -127,7 +126,7 @@ print_context_stack_bp(struct thread_info *tinfo,
21603 struct stack_frame *frame = (struct stack_frame *)bp;
21604 unsigned long *ret_addr = &frame->return_address;
21605
21606 - while (valid_stack_ptr(tinfo, ret_addr, sizeof(*ret_addr), end)) {
21607 + while (valid_stack_ptr(stack_start, ret_addr, sizeof(*ret_addr), end)) {
21608 unsigned long addr = *ret_addr;
21609
21610 if (!__kernel_text_address(addr))
21611 @@ -136,7 +135,7 @@ print_context_stack_bp(struct thread_info *tinfo,
21612 ops->address(data, addr, 1);
21613 frame = frame->next_frame;
21614 ret_addr = &frame->return_address;
21615 - print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
21616 + print_ftrace_graph_addr(addr, data, ops, task, graph);
21617 }
21618
21619 return (unsigned long)frame;
21620 @@ -155,7 +154,7 @@ static int print_trace_stack(void *data, char *name)
21621 static void print_trace_address(void *data, unsigned long addr, int reliable)
21622 {
21623 touch_nmi_watchdog();
21624 - printk(data);
21625 + printk("%s", (char *)data);
21626 printk_stack_address(addr, reliable);
21627 }
21628
21629 @@ -224,6 +223,8 @@ unsigned __kprobes long oops_begin(void)
21630 }
21631 EXPORT_SYMBOL_GPL(oops_begin);
21632
21633 +extern void gr_handle_kernel_exploit(void);
21634 +
21635 void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
21636 {
21637 if (regs && kexec_should_crash(current))
21638 @@ -245,7 +246,10 @@ void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
21639 panic("Fatal exception in interrupt");
21640 if (panic_on_oops)
21641 panic("Fatal exception");
21642 - do_exit(signr);
21643 +
21644 + gr_handle_kernel_exploit();
21645 +
21646 + do_group_exit(signr);
21647 }
21648
21649 int __kprobes __die(const char *str, struct pt_regs *regs, long err)
21650 @@ -273,7 +277,7 @@ int __kprobes __die(const char *str, struct pt_regs *regs, long err)
21651 print_modules();
21652 show_regs(regs);
21653 #ifdef CONFIG_X86_32
21654 - if (user_mode_vm(regs)) {
21655 + if (user_mode(regs)) {
21656 sp = regs->sp;
21657 ss = regs->ss & 0xffff;
21658 } else {
21659 @@ -301,7 +305,7 @@ void die(const char *str, struct pt_regs *regs, long err)
21660 unsigned long flags = oops_begin();
21661 int sig = SIGSEGV;
21662
21663 - if (!user_mode_vm(regs))
21664 + if (!user_mode(regs))
21665 report_bug(regs->ip, regs);
21666
21667 if (__die(str, regs, err))
21668 diff --git a/arch/x86/kernel/dumpstack_32.c b/arch/x86/kernel/dumpstack_32.c
21669 index f2a1770..540657f 100644
21670 --- a/arch/x86/kernel/dumpstack_32.c
21671 +++ b/arch/x86/kernel/dumpstack_32.c
21672 @@ -38,15 +38,13 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
21673 bp = stack_frame(task, regs);
21674
21675 for (;;) {
21676 - struct thread_info *context;
21677 + void *stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
21678
21679 - context = (struct thread_info *)
21680 - ((unsigned long)stack & (~(THREAD_SIZE - 1)));
21681 - bp = ops->walk_stack(context, stack, bp, ops, data, NULL, &graph);
21682 + bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
21683
21684 - stack = (unsigned long *)context->previous_esp;
21685 - if (!stack)
21686 + if (stack_start == task_stack_page(task))
21687 break;
21688 + stack = *(unsigned long **)stack_start;
21689 if (ops->stack(data, "IRQ") < 0)
21690 break;
21691 touch_nmi_watchdog();
21692 @@ -87,27 +85,28 @@ void show_regs(struct pt_regs *regs)
21693 int i;
21694
21695 show_regs_print_info(KERN_EMERG);
21696 - __show_regs(regs, !user_mode_vm(regs));
21697 + __show_regs(regs, !user_mode(regs));
21698
21699 /*
21700 * When in-kernel, we also print out the stack and code at the
21701 * time of the fault..
21702 */
21703 - if (!user_mode_vm(regs)) {
21704 + if (!user_mode(regs)) {
21705 unsigned int code_prologue = code_bytes * 43 / 64;
21706 unsigned int code_len = code_bytes;
21707 unsigned char c;
21708 u8 *ip;
21709 + unsigned long cs_base = get_desc_base(&get_cpu_gdt_table(0)[(0xffff & regs->cs) >> 3]);
21710
21711 pr_emerg("Stack:\n");
21712 show_stack_log_lvl(NULL, regs, &regs->sp, 0, KERN_EMERG);
21713
21714 pr_emerg("Code:");
21715
21716 - ip = (u8 *)regs->ip - code_prologue;
21717 + ip = (u8 *)regs->ip - code_prologue + cs_base;
21718 if (ip < (u8 *)PAGE_OFFSET || probe_kernel_address(ip, c)) {
21719 /* try starting at IP */
21720 - ip = (u8 *)regs->ip;
21721 + ip = (u8 *)regs->ip + cs_base;
21722 code_len = code_len - code_prologue + 1;
21723 }
21724 for (i = 0; i < code_len; i++, ip++) {
21725 @@ -116,7 +115,7 @@ void show_regs(struct pt_regs *regs)
21726 pr_cont(" Bad EIP value.");
21727 break;
21728 }
21729 - if (ip == (u8 *)regs->ip)
21730 + if (ip == (u8 *)regs->ip + cs_base)
21731 pr_cont(" <%02x>", c);
21732 else
21733 pr_cont(" %02x", c);
21734 @@ -129,6 +128,7 @@ int is_valid_bugaddr(unsigned long ip)
21735 {
21736 unsigned short ud2;
21737
21738 + ip = ktla_ktva(ip);
21739 if (ip < PAGE_OFFSET)
21740 return 0;
21741 if (probe_kernel_address((unsigned short *)ip, ud2))
21742 @@ -136,3 +136,15 @@ int is_valid_bugaddr(unsigned long ip)
21743
21744 return ud2 == 0x0b0f;
21745 }
21746 +
21747 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
21748 +void pax_check_alloca(unsigned long size)
21749 +{
21750 + unsigned long sp = (unsigned long)&sp, stack_left;
21751 +
21752 + /* all kernel stacks are of the same size */
21753 + stack_left = sp & (THREAD_SIZE - 1);
21754 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
21755 +}
21756 +EXPORT_SYMBOL(pax_check_alloca);
21757 +#endif
21758 diff --git a/arch/x86/kernel/dumpstack_64.c b/arch/x86/kernel/dumpstack_64.c
21759 index addb207..99635fa 100644
21760 --- a/arch/x86/kernel/dumpstack_64.c
21761 +++ b/arch/x86/kernel/dumpstack_64.c
21762 @@ -119,9 +119,9 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
21763 unsigned long *irq_stack_end =
21764 (unsigned long *)per_cpu(irq_stack_ptr, cpu);
21765 unsigned used = 0;
21766 - struct thread_info *tinfo;
21767 int graph = 0;
21768 unsigned long dummy;
21769 + void *stack_start;
21770
21771 if (!task)
21772 task = current;
21773 @@ -142,10 +142,10 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
21774 * current stack address. If the stacks consist of nested
21775 * exceptions
21776 */
21777 - tinfo = task_thread_info(task);
21778 for (;;) {
21779 char *id;
21780 unsigned long *estack_end;
21781 +
21782 estack_end = in_exception_stack(cpu, (unsigned long)stack,
21783 &used, &id);
21784
21785 @@ -153,7 +153,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
21786 if (ops->stack(data, id) < 0)
21787 break;
21788
21789 - bp = ops->walk_stack(tinfo, stack, bp, ops,
21790 + bp = ops->walk_stack(task, estack_end - EXCEPTION_STKSZ, stack, bp, ops,
21791 data, estack_end, &graph);
21792 ops->stack(data, "<EOE>");
21793 /*
21794 @@ -161,6 +161,8 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
21795 * second-to-last pointer (index -2 to end) in the
21796 * exception stack:
21797 */
21798 + if ((u16)estack_end[-1] != __KERNEL_DS)
21799 + goto out;
21800 stack = (unsigned long *) estack_end[-2];
21801 continue;
21802 }
21803 @@ -172,7 +174,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
21804 if (in_irq_stack(stack, irq_stack, irq_stack_end)) {
21805 if (ops->stack(data, "IRQ") < 0)
21806 break;
21807 - bp = ops->walk_stack(tinfo, stack, bp,
21808 + bp = ops->walk_stack(task, irq_stack, stack, bp,
21809 ops, data, irq_stack_end, &graph);
21810 /*
21811 * We link to the next stack (which would be
21812 @@ -191,7 +193,9 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
21813 /*
21814 * This handles the process stack:
21815 */
21816 - bp = ops->walk_stack(tinfo, stack, bp, ops, data, NULL, &graph);
21817 + stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
21818 + bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
21819 +out:
21820 put_cpu();
21821 }
21822 EXPORT_SYMBOL(dump_trace);
21823 @@ -300,3 +304,50 @@ int is_valid_bugaddr(unsigned long ip)
21824
21825 return ud2 == 0x0b0f;
21826 }
21827 +
21828 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
21829 +void pax_check_alloca(unsigned long size)
21830 +{
21831 + unsigned long sp = (unsigned long)&sp, stack_start, stack_end;
21832 + unsigned cpu, used;
21833 + char *id;
21834 +
21835 + /* check the process stack first */
21836 + stack_start = (unsigned long)task_stack_page(current);
21837 + stack_end = stack_start + THREAD_SIZE;
21838 + if (likely(stack_start <= sp && sp < stack_end)) {
21839 + unsigned long stack_left = sp & (THREAD_SIZE - 1);
21840 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
21841 + return;
21842 + }
21843 +
21844 + cpu = get_cpu();
21845 +
21846 + /* check the irq stacks */
21847 + stack_end = (unsigned long)per_cpu(irq_stack_ptr, cpu);
21848 + stack_start = stack_end - IRQ_STACK_SIZE;
21849 + if (stack_start <= sp && sp < stack_end) {
21850 + unsigned long stack_left = sp & (IRQ_STACK_SIZE - 1);
21851 + put_cpu();
21852 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
21853 + return;
21854 + }
21855 +
21856 + /* check the exception stacks */
21857 + used = 0;
21858 + stack_end = (unsigned long)in_exception_stack(cpu, sp, &used, &id);
21859 + stack_start = stack_end - EXCEPTION_STKSZ;
21860 + if (stack_end && stack_start <= sp && sp < stack_end) {
21861 + unsigned long stack_left = sp & (EXCEPTION_STKSZ - 1);
21862 + put_cpu();
21863 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
21864 + return;
21865 + }
21866 +
21867 + put_cpu();
21868 +
21869 + /* unknown stack */
21870 + BUG();
21871 +}
21872 +EXPORT_SYMBOL(pax_check_alloca);
21873 +#endif
21874 diff --git a/arch/x86/kernel/e820.c b/arch/x86/kernel/e820.c
21875 index 174da5f..5e55606 100644
21876 --- a/arch/x86/kernel/e820.c
21877 +++ b/arch/x86/kernel/e820.c
21878 @@ -803,8 +803,8 @@ unsigned long __init e820_end_of_low_ram_pfn(void)
21879
21880 static void early_panic(char *msg)
21881 {
21882 - early_printk(msg);
21883 - panic(msg);
21884 + early_printk("%s", msg);
21885 + panic("%s", msg);
21886 }
21887
21888 static int userdef __initdata;
21889 diff --git a/arch/x86/kernel/early_printk.c b/arch/x86/kernel/early_printk.c
21890 index 01d1c18..8073693 100644
21891 --- a/arch/x86/kernel/early_printk.c
21892 +++ b/arch/x86/kernel/early_printk.c
21893 @@ -7,6 +7,7 @@
21894 #include <linux/pci_regs.h>
21895 #include <linux/pci_ids.h>
21896 #include <linux/errno.h>
21897 +#include <linux/sched.h>
21898 #include <asm/io.h>
21899 #include <asm/processor.h>
21900 #include <asm/fcntl.h>
21901 diff --git a/arch/x86/kernel/entry_32.S b/arch/x86/kernel/entry_32.S
21902 index a2a4f46..6cab058 100644
21903 --- a/arch/x86/kernel/entry_32.S
21904 +++ b/arch/x86/kernel/entry_32.S
21905 @@ -177,13 +177,153 @@
21906 /*CFI_REL_OFFSET gs, PT_GS*/
21907 .endm
21908 .macro SET_KERNEL_GS reg
21909 +
21910 +#ifdef CONFIG_CC_STACKPROTECTOR
21911 movl $(__KERNEL_STACK_CANARY), \reg
21912 +#elif defined(CONFIG_PAX_MEMORY_UDEREF)
21913 + movl $(__USER_DS), \reg
21914 +#else
21915 + xorl \reg, \reg
21916 +#endif
21917 +
21918 movl \reg, %gs
21919 .endm
21920
21921 #endif /* CONFIG_X86_32_LAZY_GS */
21922
21923 -.macro SAVE_ALL
21924 +.macro pax_enter_kernel
21925 +#ifdef CONFIG_PAX_KERNEXEC
21926 + call pax_enter_kernel
21927 +#endif
21928 +.endm
21929 +
21930 +.macro pax_exit_kernel
21931 +#ifdef CONFIG_PAX_KERNEXEC
21932 + call pax_exit_kernel
21933 +#endif
21934 +.endm
21935 +
21936 +#ifdef CONFIG_PAX_KERNEXEC
21937 +ENTRY(pax_enter_kernel)
21938 +#ifdef CONFIG_PARAVIRT
21939 + pushl %eax
21940 + pushl %ecx
21941 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0)
21942 + mov %eax, %esi
21943 +#else
21944 + mov %cr0, %esi
21945 +#endif
21946 + bts $16, %esi
21947 + jnc 1f
21948 + mov %cs, %esi
21949 + cmp $__KERNEL_CS, %esi
21950 + jz 3f
21951 + ljmp $__KERNEL_CS, $3f
21952 +1: ljmp $__KERNEXEC_KERNEL_CS, $2f
21953 +2:
21954 +#ifdef CONFIG_PARAVIRT
21955 + mov %esi, %eax
21956 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
21957 +#else
21958 + mov %esi, %cr0
21959 +#endif
21960 +3:
21961 +#ifdef CONFIG_PARAVIRT
21962 + popl %ecx
21963 + popl %eax
21964 +#endif
21965 + ret
21966 +ENDPROC(pax_enter_kernel)
21967 +
21968 +ENTRY(pax_exit_kernel)
21969 +#ifdef CONFIG_PARAVIRT
21970 + pushl %eax
21971 + pushl %ecx
21972 +#endif
21973 + mov %cs, %esi
21974 + cmp $__KERNEXEC_KERNEL_CS, %esi
21975 + jnz 2f
21976 +#ifdef CONFIG_PARAVIRT
21977 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0);
21978 + mov %eax, %esi
21979 +#else
21980 + mov %cr0, %esi
21981 +#endif
21982 + btr $16, %esi
21983 + ljmp $__KERNEL_CS, $1f
21984 +1:
21985 +#ifdef CONFIG_PARAVIRT
21986 + mov %esi, %eax
21987 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0);
21988 +#else
21989 + mov %esi, %cr0
21990 +#endif
21991 +2:
21992 +#ifdef CONFIG_PARAVIRT
21993 + popl %ecx
21994 + popl %eax
21995 +#endif
21996 + ret
21997 +ENDPROC(pax_exit_kernel)
21998 +#endif
21999 +
22000 + .macro pax_erase_kstack
22001 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
22002 + call pax_erase_kstack
22003 +#endif
22004 + .endm
22005 +
22006 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
22007 +/*
22008 + * ebp: thread_info
22009 + */
22010 +ENTRY(pax_erase_kstack)
22011 + pushl %edi
22012 + pushl %ecx
22013 + pushl %eax
22014 +
22015 + mov TI_lowest_stack(%ebp), %edi
22016 + mov $-0xBEEF, %eax
22017 + std
22018 +
22019 +1: mov %edi, %ecx
22020 + and $THREAD_SIZE_asm - 1, %ecx
22021 + shr $2, %ecx
22022 + repne scasl
22023 + jecxz 2f
22024 +
22025 + cmp $2*16, %ecx
22026 + jc 2f
22027 +
22028 + mov $2*16, %ecx
22029 + repe scasl
22030 + jecxz 2f
22031 + jne 1b
22032 +
22033 +2: cld
22034 + mov %esp, %ecx
22035 + sub %edi, %ecx
22036 +
22037 + cmp $THREAD_SIZE_asm, %ecx
22038 + jb 3f
22039 + ud2
22040 +3:
22041 +
22042 + shr $2, %ecx
22043 + rep stosl
22044 +
22045 + mov TI_task_thread_sp0(%ebp), %edi
22046 + sub $128, %edi
22047 + mov %edi, TI_lowest_stack(%ebp)
22048 +
22049 + popl %eax
22050 + popl %ecx
22051 + popl %edi
22052 + ret
22053 +ENDPROC(pax_erase_kstack)
22054 +#endif
22055 +
22056 +.macro __SAVE_ALL _DS
22057 cld
22058 PUSH_GS
22059 pushl_cfi %fs
22060 @@ -206,7 +346,7 @@
22061 CFI_REL_OFFSET ecx, 0
22062 pushl_cfi %ebx
22063 CFI_REL_OFFSET ebx, 0
22064 - movl $(__USER_DS), %edx
22065 + movl $\_DS, %edx
22066 movl %edx, %ds
22067 movl %edx, %es
22068 movl $(__KERNEL_PERCPU), %edx
22069 @@ -214,6 +354,15 @@
22070 SET_KERNEL_GS %edx
22071 .endm
22072
22073 +.macro SAVE_ALL
22074 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
22075 + __SAVE_ALL __KERNEL_DS
22076 + pax_enter_kernel
22077 +#else
22078 + __SAVE_ALL __USER_DS
22079 +#endif
22080 +.endm
22081 +
22082 .macro RESTORE_INT_REGS
22083 popl_cfi %ebx
22084 CFI_RESTORE ebx
22085 @@ -297,7 +446,7 @@ ENTRY(ret_from_fork)
22086 popfl_cfi
22087 jmp syscall_exit
22088 CFI_ENDPROC
22089 -END(ret_from_fork)
22090 +ENDPROC(ret_from_fork)
22091
22092 ENTRY(ret_from_kernel_thread)
22093 CFI_STARTPROC
22094 @@ -344,7 +493,15 @@ ret_from_intr:
22095 andl $SEGMENT_RPL_MASK, %eax
22096 #endif
22097 cmpl $USER_RPL, %eax
22098 +
22099 +#ifdef CONFIG_PAX_KERNEXEC
22100 + jae resume_userspace
22101 +
22102 + pax_exit_kernel
22103 + jmp resume_kernel
22104 +#else
22105 jb resume_kernel # not returning to v8086 or userspace
22106 +#endif
22107
22108 ENTRY(resume_userspace)
22109 LOCKDEP_SYS_EXIT
22110 @@ -356,8 +513,8 @@ ENTRY(resume_userspace)
22111 andl $_TIF_WORK_MASK, %ecx # is there any work to be done on
22112 # int/exception return?
22113 jne work_pending
22114 - jmp restore_all
22115 -END(ret_from_exception)
22116 + jmp restore_all_pax
22117 +ENDPROC(ret_from_exception)
22118
22119 #ifdef CONFIG_PREEMPT
22120 ENTRY(resume_kernel)
22121 @@ -369,7 +526,7 @@ need_resched:
22122 jz restore_all
22123 call preempt_schedule_irq
22124 jmp need_resched
22125 -END(resume_kernel)
22126 +ENDPROC(resume_kernel)
22127 #endif
22128 CFI_ENDPROC
22129 /*
22130 @@ -403,30 +560,45 @@ sysenter_past_esp:
22131 /*CFI_REL_OFFSET cs, 0*/
22132 /*
22133 * Push current_thread_info()->sysenter_return to the stack.
22134 - * A tiny bit of offset fixup is necessary - 4*4 means the 4 words
22135 - * pushed above; +8 corresponds to copy_thread's esp0 setting.
22136 */
22137 - pushl_cfi ((TI_sysenter_return)-THREAD_SIZE+8+4*4)(%esp)
22138 + pushl_cfi $0
22139 CFI_REL_OFFSET eip, 0
22140
22141 pushl_cfi %eax
22142 SAVE_ALL
22143 + GET_THREAD_INFO(%ebp)
22144 + movl TI_sysenter_return(%ebp),%ebp
22145 + movl %ebp,PT_EIP(%esp)
22146 ENABLE_INTERRUPTS(CLBR_NONE)
22147
22148 /*
22149 * Load the potential sixth argument from user stack.
22150 * Careful about security.
22151 */
22152 + movl PT_OLDESP(%esp),%ebp
22153 +
22154 +#ifdef CONFIG_PAX_MEMORY_UDEREF
22155 + mov PT_OLDSS(%esp),%ds
22156 +1: movl %ds:(%ebp),%ebp
22157 + push %ss
22158 + pop %ds
22159 +#else
22160 cmpl $__PAGE_OFFSET-3,%ebp
22161 jae syscall_fault
22162 ASM_STAC
22163 1: movl (%ebp),%ebp
22164 ASM_CLAC
22165 +#endif
22166 +
22167 movl %ebp,PT_EBP(%esp)
22168 _ASM_EXTABLE(1b,syscall_fault)
22169
22170 GET_THREAD_INFO(%ebp)
22171
22172 +#ifdef CONFIG_PAX_RANDKSTACK
22173 + pax_erase_kstack
22174 +#endif
22175 +
22176 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
22177 jnz sysenter_audit
22178 sysenter_do_call:
22179 @@ -441,12 +613,24 @@ sysenter_do_call:
22180 testl $_TIF_ALLWORK_MASK, %ecx
22181 jne sysexit_audit
22182 sysenter_exit:
22183 +
22184 +#ifdef CONFIG_PAX_RANDKSTACK
22185 + pushl_cfi %eax
22186 + movl %esp, %eax
22187 + call pax_randomize_kstack
22188 + popl_cfi %eax
22189 +#endif
22190 +
22191 + pax_erase_kstack
22192 +
22193 /* if something modifies registers it must also disable sysexit */
22194 movl PT_EIP(%esp), %edx
22195 movl PT_OLDESP(%esp), %ecx
22196 xorl %ebp,%ebp
22197 TRACE_IRQS_ON
22198 1: mov PT_FS(%esp), %fs
22199 +2: mov PT_DS(%esp), %ds
22200 +3: mov PT_ES(%esp), %es
22201 PTGS_TO_GS
22202 ENABLE_INTERRUPTS_SYSEXIT
22203
22204 @@ -463,6 +647,9 @@ sysenter_audit:
22205 movl %eax,%edx /* 2nd arg: syscall number */
22206 movl $AUDIT_ARCH_I386,%eax /* 1st arg: audit arch */
22207 call __audit_syscall_entry
22208 +
22209 + pax_erase_kstack
22210 +
22211 pushl_cfi %ebx
22212 movl PT_EAX(%esp),%eax /* reload syscall number */
22213 jmp sysenter_do_call
22214 @@ -488,10 +675,16 @@ sysexit_audit:
22215
22216 CFI_ENDPROC
22217 .pushsection .fixup,"ax"
22218 -2: movl $0,PT_FS(%esp)
22219 +4: movl $0,PT_FS(%esp)
22220 + jmp 1b
22221 +5: movl $0,PT_DS(%esp)
22222 + jmp 1b
22223 +6: movl $0,PT_ES(%esp)
22224 jmp 1b
22225 .popsection
22226 - _ASM_EXTABLE(1b,2b)
22227 + _ASM_EXTABLE(1b,4b)
22228 + _ASM_EXTABLE(2b,5b)
22229 + _ASM_EXTABLE(3b,6b)
22230 PTGS_TO_GS_EX
22231 ENDPROC(ia32_sysenter_target)
22232
22233 @@ -506,6 +699,11 @@ ENTRY(system_call)
22234 pushl_cfi %eax # save orig_eax
22235 SAVE_ALL
22236 GET_THREAD_INFO(%ebp)
22237 +
22238 +#ifdef CONFIG_PAX_RANDKSTACK
22239 + pax_erase_kstack
22240 +#endif
22241 +
22242 # system call tracing in operation / emulation
22243 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
22244 jnz syscall_trace_entry
22245 @@ -524,6 +722,15 @@ syscall_exit:
22246 testl $_TIF_ALLWORK_MASK, %ecx # current->work
22247 jne syscall_exit_work
22248
22249 +restore_all_pax:
22250 +
22251 +#ifdef CONFIG_PAX_RANDKSTACK
22252 + movl %esp, %eax
22253 + call pax_randomize_kstack
22254 +#endif
22255 +
22256 + pax_erase_kstack
22257 +
22258 restore_all:
22259 TRACE_IRQS_IRET
22260 restore_all_notrace:
22261 @@ -580,14 +787,34 @@ ldt_ss:
22262 * compensating for the offset by changing to the ESPFIX segment with
22263 * a base address that matches for the difference.
22264 */
22265 -#define GDT_ESPFIX_SS PER_CPU_VAR(gdt_page) + (GDT_ENTRY_ESPFIX_SS * 8)
22266 +#define GDT_ESPFIX_SS (GDT_ENTRY_ESPFIX_SS * 8)(%ebx)
22267 mov %esp, %edx /* load kernel esp */
22268 mov PT_OLDESP(%esp), %eax /* load userspace esp */
22269 mov %dx, %ax /* eax: new kernel esp */
22270 sub %eax, %edx /* offset (low word is 0) */
22271 +#ifdef CONFIG_SMP
22272 + movl PER_CPU_VAR(cpu_number), %ebx
22273 + shll $PAGE_SHIFT_asm, %ebx
22274 + addl $cpu_gdt_table, %ebx
22275 +#else
22276 + movl $cpu_gdt_table, %ebx
22277 +#endif
22278 shr $16, %edx
22279 - mov %dl, GDT_ESPFIX_SS + 4 /* bits 16..23 */
22280 - mov %dh, GDT_ESPFIX_SS + 7 /* bits 24..31 */
22281 +
22282 +#ifdef CONFIG_PAX_KERNEXEC
22283 + mov %cr0, %esi
22284 + btr $16, %esi
22285 + mov %esi, %cr0
22286 +#endif
22287 +
22288 + mov %dl, 4 + GDT_ESPFIX_SS /* bits 16..23 */
22289 + mov %dh, 7 + GDT_ESPFIX_SS /* bits 24..31 */
22290 +
22291 +#ifdef CONFIG_PAX_KERNEXEC
22292 + bts $16, %esi
22293 + mov %esi, %cr0
22294 +#endif
22295 +
22296 pushl_cfi $__ESPFIX_SS
22297 pushl_cfi %eax /* new kernel esp */
22298 /* Disable interrupts, but do not irqtrace this section: we
22299 @@ -616,20 +843,18 @@ work_resched:
22300 movl TI_flags(%ebp), %ecx
22301 andl $_TIF_WORK_MASK, %ecx # is there any work to be done other
22302 # than syscall tracing?
22303 - jz restore_all
22304 + jz restore_all_pax
22305 testb $_TIF_NEED_RESCHED, %cl
22306 jnz work_resched
22307
22308 work_notifysig: # deal with pending signals and
22309 # notify-resume requests
22310 + movl %esp, %eax
22311 #ifdef CONFIG_VM86
22312 testl $X86_EFLAGS_VM, PT_EFLAGS(%esp)
22313 - movl %esp, %eax
22314 jne work_notifysig_v86 # returning to kernel-space or
22315 # vm86-space
22316 1:
22317 -#else
22318 - movl %esp, %eax
22319 #endif
22320 TRACE_IRQS_ON
22321 ENABLE_INTERRUPTS(CLBR_NONE)
22322 @@ -650,7 +875,7 @@ work_notifysig_v86:
22323 movl %eax, %esp
22324 jmp 1b
22325 #endif
22326 -END(work_pending)
22327 +ENDPROC(work_pending)
22328
22329 # perform syscall exit tracing
22330 ALIGN
22331 @@ -658,11 +883,14 @@ syscall_trace_entry:
22332 movl $-ENOSYS,PT_EAX(%esp)
22333 movl %esp, %eax
22334 call syscall_trace_enter
22335 +
22336 + pax_erase_kstack
22337 +
22338 /* What it returned is what we'll actually use. */
22339 cmpl $(NR_syscalls), %eax
22340 jnae syscall_call
22341 jmp syscall_exit
22342 -END(syscall_trace_entry)
22343 +ENDPROC(syscall_trace_entry)
22344
22345 # perform syscall exit tracing
22346 ALIGN
22347 @@ -675,21 +903,25 @@ syscall_exit_work:
22348 movl %esp, %eax
22349 call syscall_trace_leave
22350 jmp resume_userspace
22351 -END(syscall_exit_work)
22352 +ENDPROC(syscall_exit_work)
22353 CFI_ENDPROC
22354
22355 RING0_INT_FRAME # can't unwind into user space anyway
22356 syscall_fault:
22357 +#ifdef CONFIG_PAX_MEMORY_UDEREF
22358 + push %ss
22359 + pop %ds
22360 +#endif
22361 ASM_CLAC
22362 GET_THREAD_INFO(%ebp)
22363 movl $-EFAULT,PT_EAX(%esp)
22364 jmp resume_userspace
22365 -END(syscall_fault)
22366 +ENDPROC(syscall_fault)
22367
22368 syscall_badsys:
22369 movl $-ENOSYS,PT_EAX(%esp)
22370 jmp resume_userspace
22371 -END(syscall_badsys)
22372 +ENDPROC(syscall_badsys)
22373 CFI_ENDPROC
22374 /*
22375 * End of kprobes section
22376 @@ -705,8 +937,15 @@ END(syscall_badsys)
22377 * normal stack and adjusts ESP with the matching offset.
22378 */
22379 /* fixup the stack */
22380 - mov GDT_ESPFIX_SS + 4, %al /* bits 16..23 */
22381 - mov GDT_ESPFIX_SS + 7, %ah /* bits 24..31 */
22382 +#ifdef CONFIG_SMP
22383 + movl PER_CPU_VAR(cpu_number), %ebx
22384 + shll $PAGE_SHIFT_asm, %ebx
22385 + addl $cpu_gdt_table, %ebx
22386 +#else
22387 + movl $cpu_gdt_table, %ebx
22388 +#endif
22389 + mov 4 + GDT_ESPFIX_SS, %al /* bits 16..23 */
22390 + mov 7 + GDT_ESPFIX_SS, %ah /* bits 24..31 */
22391 shl $16, %eax
22392 addl %esp, %eax /* the adjusted stack pointer */
22393 pushl_cfi $__KERNEL_DS
22394 @@ -759,7 +998,7 @@ vector=vector+1
22395 .endr
22396 2: jmp common_interrupt
22397 .endr
22398 -END(irq_entries_start)
22399 +ENDPROC(irq_entries_start)
22400
22401 .previous
22402 END(interrupt)
22403 @@ -820,7 +1059,7 @@ ENTRY(coprocessor_error)
22404 pushl_cfi $do_coprocessor_error
22405 jmp error_code
22406 CFI_ENDPROC
22407 -END(coprocessor_error)
22408 +ENDPROC(coprocessor_error)
22409
22410 ENTRY(simd_coprocessor_error)
22411 RING0_INT_FRAME
22412 @@ -833,7 +1072,7 @@ ENTRY(simd_coprocessor_error)
22413 .section .altinstructions,"a"
22414 altinstruction_entry 661b, 663f, X86_FEATURE_XMM, 662b-661b, 664f-663f
22415 .previous
22416 -.section .altinstr_replacement,"ax"
22417 +.section .altinstr_replacement,"a"
22418 663: pushl $do_simd_coprocessor_error
22419 664:
22420 .previous
22421 @@ -842,7 +1081,7 @@ ENTRY(simd_coprocessor_error)
22422 #endif
22423 jmp error_code
22424 CFI_ENDPROC
22425 -END(simd_coprocessor_error)
22426 +ENDPROC(simd_coprocessor_error)
22427
22428 ENTRY(device_not_available)
22429 RING0_INT_FRAME
22430 @@ -851,18 +1090,18 @@ ENTRY(device_not_available)
22431 pushl_cfi $do_device_not_available
22432 jmp error_code
22433 CFI_ENDPROC
22434 -END(device_not_available)
22435 +ENDPROC(device_not_available)
22436
22437 #ifdef CONFIG_PARAVIRT
22438 ENTRY(native_iret)
22439 iret
22440 _ASM_EXTABLE(native_iret, iret_exc)
22441 -END(native_iret)
22442 +ENDPROC(native_iret)
22443
22444 ENTRY(native_irq_enable_sysexit)
22445 sti
22446 sysexit
22447 -END(native_irq_enable_sysexit)
22448 +ENDPROC(native_irq_enable_sysexit)
22449 #endif
22450
22451 ENTRY(overflow)
22452 @@ -872,7 +1111,7 @@ ENTRY(overflow)
22453 pushl_cfi $do_overflow
22454 jmp error_code
22455 CFI_ENDPROC
22456 -END(overflow)
22457 +ENDPROC(overflow)
22458
22459 ENTRY(bounds)
22460 RING0_INT_FRAME
22461 @@ -881,7 +1120,7 @@ ENTRY(bounds)
22462 pushl_cfi $do_bounds
22463 jmp error_code
22464 CFI_ENDPROC
22465 -END(bounds)
22466 +ENDPROC(bounds)
22467
22468 ENTRY(invalid_op)
22469 RING0_INT_FRAME
22470 @@ -890,7 +1129,7 @@ ENTRY(invalid_op)
22471 pushl_cfi $do_invalid_op
22472 jmp error_code
22473 CFI_ENDPROC
22474 -END(invalid_op)
22475 +ENDPROC(invalid_op)
22476
22477 ENTRY(coprocessor_segment_overrun)
22478 RING0_INT_FRAME
22479 @@ -899,7 +1138,7 @@ ENTRY(coprocessor_segment_overrun)
22480 pushl_cfi $do_coprocessor_segment_overrun
22481 jmp error_code
22482 CFI_ENDPROC
22483 -END(coprocessor_segment_overrun)
22484 +ENDPROC(coprocessor_segment_overrun)
22485
22486 ENTRY(invalid_TSS)
22487 RING0_EC_FRAME
22488 @@ -907,7 +1146,7 @@ ENTRY(invalid_TSS)
22489 pushl_cfi $do_invalid_TSS
22490 jmp error_code
22491 CFI_ENDPROC
22492 -END(invalid_TSS)
22493 +ENDPROC(invalid_TSS)
22494
22495 ENTRY(segment_not_present)
22496 RING0_EC_FRAME
22497 @@ -915,7 +1154,7 @@ ENTRY(segment_not_present)
22498 pushl_cfi $do_segment_not_present
22499 jmp error_code
22500 CFI_ENDPROC
22501 -END(segment_not_present)
22502 +ENDPROC(segment_not_present)
22503
22504 ENTRY(stack_segment)
22505 RING0_EC_FRAME
22506 @@ -923,7 +1162,7 @@ ENTRY(stack_segment)
22507 pushl_cfi $do_stack_segment
22508 jmp error_code
22509 CFI_ENDPROC
22510 -END(stack_segment)
22511 +ENDPROC(stack_segment)
22512
22513 ENTRY(alignment_check)
22514 RING0_EC_FRAME
22515 @@ -931,7 +1170,7 @@ ENTRY(alignment_check)
22516 pushl_cfi $do_alignment_check
22517 jmp error_code
22518 CFI_ENDPROC
22519 -END(alignment_check)
22520 +ENDPROC(alignment_check)
22521
22522 ENTRY(divide_error)
22523 RING0_INT_FRAME
22524 @@ -940,7 +1179,7 @@ ENTRY(divide_error)
22525 pushl_cfi $do_divide_error
22526 jmp error_code
22527 CFI_ENDPROC
22528 -END(divide_error)
22529 +ENDPROC(divide_error)
22530
22531 #ifdef CONFIG_X86_MCE
22532 ENTRY(machine_check)
22533 @@ -950,7 +1189,7 @@ ENTRY(machine_check)
22534 pushl_cfi machine_check_vector
22535 jmp error_code
22536 CFI_ENDPROC
22537 -END(machine_check)
22538 +ENDPROC(machine_check)
22539 #endif
22540
22541 ENTRY(spurious_interrupt_bug)
22542 @@ -960,7 +1199,7 @@ ENTRY(spurious_interrupt_bug)
22543 pushl_cfi $do_spurious_interrupt_bug
22544 jmp error_code
22545 CFI_ENDPROC
22546 -END(spurious_interrupt_bug)
22547 +ENDPROC(spurious_interrupt_bug)
22548 /*
22549 * End of kprobes section
22550 */
22551 @@ -1070,7 +1309,7 @@ BUILD_INTERRUPT3(hyperv_callback_vector, HYPERVISOR_CALLBACK_VECTOR,
22552
22553 ENTRY(mcount)
22554 ret
22555 -END(mcount)
22556 +ENDPROC(mcount)
22557
22558 ENTRY(ftrace_caller)
22559 cmpl $0, function_trace_stop
22560 @@ -1103,7 +1342,7 @@ ftrace_graph_call:
22561 .globl ftrace_stub
22562 ftrace_stub:
22563 ret
22564 -END(ftrace_caller)
22565 +ENDPROC(ftrace_caller)
22566
22567 ENTRY(ftrace_regs_caller)
22568 pushf /* push flags before compare (in cs location) */
22569 @@ -1207,7 +1446,7 @@ trace:
22570 popl %ecx
22571 popl %eax
22572 jmp ftrace_stub
22573 -END(mcount)
22574 +ENDPROC(mcount)
22575 #endif /* CONFIG_DYNAMIC_FTRACE */
22576 #endif /* CONFIG_FUNCTION_TRACER */
22577
22578 @@ -1225,7 +1464,7 @@ ENTRY(ftrace_graph_caller)
22579 popl %ecx
22580 popl %eax
22581 ret
22582 -END(ftrace_graph_caller)
22583 +ENDPROC(ftrace_graph_caller)
22584
22585 .globl return_to_handler
22586 return_to_handler:
22587 @@ -1291,15 +1530,18 @@ error_code:
22588 movl $-1, PT_ORIG_EAX(%esp) # no syscall to restart
22589 REG_TO_PTGS %ecx
22590 SET_KERNEL_GS %ecx
22591 - movl $(__USER_DS), %ecx
22592 + movl $(__KERNEL_DS), %ecx
22593 movl %ecx, %ds
22594 movl %ecx, %es
22595 +
22596 + pax_enter_kernel
22597 +
22598 TRACE_IRQS_OFF
22599 movl %esp,%eax # pt_regs pointer
22600 call *%edi
22601 jmp ret_from_exception
22602 CFI_ENDPROC
22603 -END(page_fault)
22604 +ENDPROC(page_fault)
22605
22606 /*
22607 * Debug traps and NMI can happen at the one SYSENTER instruction
22608 @@ -1342,7 +1584,7 @@ debug_stack_correct:
22609 call do_debug
22610 jmp ret_from_exception
22611 CFI_ENDPROC
22612 -END(debug)
22613 +ENDPROC(debug)
22614
22615 /*
22616 * NMI is doubly nasty. It can happen _while_ we're handling
22617 @@ -1380,6 +1622,9 @@ nmi_stack_correct:
22618 xorl %edx,%edx # zero error code
22619 movl %esp,%eax # pt_regs pointer
22620 call do_nmi
22621 +
22622 + pax_exit_kernel
22623 +
22624 jmp restore_all_notrace
22625 CFI_ENDPROC
22626
22627 @@ -1416,12 +1661,15 @@ nmi_espfix_stack:
22628 FIXUP_ESPFIX_STACK # %eax == %esp
22629 xorl %edx,%edx # zero error code
22630 call do_nmi
22631 +
22632 + pax_exit_kernel
22633 +
22634 RESTORE_REGS
22635 lss 12+4(%esp), %esp # back to espfix stack
22636 CFI_ADJUST_CFA_OFFSET -24
22637 jmp irq_return
22638 CFI_ENDPROC
22639 -END(nmi)
22640 +ENDPROC(nmi)
22641
22642 ENTRY(int3)
22643 RING0_INT_FRAME
22644 @@ -1434,14 +1682,14 @@ ENTRY(int3)
22645 call do_int3
22646 jmp ret_from_exception
22647 CFI_ENDPROC
22648 -END(int3)
22649 +ENDPROC(int3)
22650
22651 ENTRY(general_protection)
22652 RING0_EC_FRAME
22653 pushl_cfi $do_general_protection
22654 jmp error_code
22655 CFI_ENDPROC
22656 -END(general_protection)
22657 +ENDPROC(general_protection)
22658
22659 #ifdef CONFIG_KVM_GUEST
22660 ENTRY(async_page_fault)
22661 @@ -1450,7 +1698,7 @@ ENTRY(async_page_fault)
22662 pushl_cfi $do_async_page_fault
22663 jmp error_code
22664 CFI_ENDPROC
22665 -END(async_page_fault)
22666 +ENDPROC(async_page_fault)
22667 #endif
22668
22669 /*
22670 diff --git a/arch/x86/kernel/entry_64.S b/arch/x86/kernel/entry_64.S
22671 index 1e96c36..3ff710a 100644
22672 --- a/arch/x86/kernel/entry_64.S
22673 +++ b/arch/x86/kernel/entry_64.S
22674 @@ -59,6 +59,8 @@
22675 #include <asm/context_tracking.h>
22676 #include <asm/smap.h>
22677 #include <linux/err.h>
22678 +#include <asm/pgtable.h>
22679 +#include <asm/alternative-asm.h>
22680
22681 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
22682 #include <linux/elf-em.h>
22683 @@ -80,8 +82,9 @@
22684 #ifdef CONFIG_DYNAMIC_FTRACE
22685
22686 ENTRY(function_hook)
22687 + pax_force_retaddr
22688 retq
22689 -END(function_hook)
22690 +ENDPROC(function_hook)
22691
22692 /* skip is set if stack has been adjusted */
22693 .macro ftrace_caller_setup skip=0
22694 @@ -122,8 +125,9 @@ GLOBAL(ftrace_graph_call)
22695 #endif
22696
22697 GLOBAL(ftrace_stub)
22698 + pax_force_retaddr
22699 retq
22700 -END(ftrace_caller)
22701 +ENDPROC(ftrace_caller)
22702
22703 ENTRY(ftrace_regs_caller)
22704 /* Save the current flags before compare (in SS location)*/
22705 @@ -191,7 +195,7 @@ ftrace_restore_flags:
22706 popfq
22707 jmp ftrace_stub
22708
22709 -END(ftrace_regs_caller)
22710 +ENDPROC(ftrace_regs_caller)
22711
22712
22713 #else /* ! CONFIG_DYNAMIC_FTRACE */
22714 @@ -212,6 +216,7 @@ ENTRY(function_hook)
22715 #endif
22716
22717 GLOBAL(ftrace_stub)
22718 + pax_force_retaddr
22719 retq
22720
22721 trace:
22722 @@ -225,12 +230,13 @@ trace:
22723 #endif
22724 subq $MCOUNT_INSN_SIZE, %rdi
22725
22726 + pax_force_fptr ftrace_trace_function
22727 call *ftrace_trace_function
22728
22729 MCOUNT_RESTORE_FRAME
22730
22731 jmp ftrace_stub
22732 -END(function_hook)
22733 +ENDPROC(function_hook)
22734 #endif /* CONFIG_DYNAMIC_FTRACE */
22735 #endif /* CONFIG_FUNCTION_TRACER */
22736
22737 @@ -252,8 +258,9 @@ ENTRY(ftrace_graph_caller)
22738
22739 MCOUNT_RESTORE_FRAME
22740
22741 + pax_force_retaddr
22742 retq
22743 -END(ftrace_graph_caller)
22744 +ENDPROC(ftrace_graph_caller)
22745
22746 GLOBAL(return_to_handler)
22747 subq $24, %rsp
22748 @@ -269,7 +276,9 @@ GLOBAL(return_to_handler)
22749 movq 8(%rsp), %rdx
22750 movq (%rsp), %rax
22751 addq $24, %rsp
22752 + pax_force_fptr %rdi
22753 jmp *%rdi
22754 +ENDPROC(return_to_handler)
22755 #endif
22756
22757
22758 @@ -284,6 +293,430 @@ ENTRY(native_usergs_sysret64)
22759 ENDPROC(native_usergs_sysret64)
22760 #endif /* CONFIG_PARAVIRT */
22761
22762 + .macro ljmpq sel, off
22763 +#if defined(CONFIG_MPSC) || defined(CONFIG_MCORE2) || defined (CONFIG_MATOM)
22764 + .byte 0x48; ljmp *1234f(%rip)
22765 + .pushsection .rodata
22766 + .align 16
22767 + 1234: .quad \off; .word \sel
22768 + .popsection
22769 +#else
22770 + pushq $\sel
22771 + pushq $\off
22772 + lretq
22773 +#endif
22774 + .endm
22775 +
22776 + .macro pax_enter_kernel
22777 + pax_set_fptr_mask
22778 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
22779 + call pax_enter_kernel
22780 +#endif
22781 + .endm
22782 +
22783 + .macro pax_exit_kernel
22784 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
22785 + call pax_exit_kernel
22786 +#endif
22787 +
22788 + .endm
22789 +
22790 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
22791 +ENTRY(pax_enter_kernel)
22792 + pushq %rdi
22793 +
22794 +#ifdef CONFIG_PARAVIRT
22795 + PV_SAVE_REGS(CLBR_RDI)
22796 +#endif
22797 +
22798 +#ifdef CONFIG_PAX_KERNEXEC
22799 + GET_CR0_INTO_RDI
22800 + bts $16,%rdi
22801 + jnc 3f
22802 + mov %cs,%edi
22803 + cmp $__KERNEL_CS,%edi
22804 + jnz 2f
22805 +1:
22806 +#endif
22807 +
22808 +#ifdef CONFIG_PAX_MEMORY_UDEREF
22809 + 661: jmp 111f
22810 + .pushsection .altinstr_replacement, "a"
22811 + 662: ASM_NOP2
22812 + .popsection
22813 + .pushsection .altinstructions, "a"
22814 + altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
22815 + .popsection
22816 + GET_CR3_INTO_RDI
22817 + cmp $0,%dil
22818 + jnz 112f
22819 + mov $__KERNEL_DS,%edi
22820 + mov %edi,%ss
22821 + jmp 111f
22822 +112: cmp $1,%dil
22823 + jz 113f
22824 + ud2
22825 +113: sub $4097,%rdi
22826 + bts $63,%rdi
22827 + SET_RDI_INTO_CR3
22828 + mov $__UDEREF_KERNEL_DS,%edi
22829 + mov %edi,%ss
22830 +111:
22831 +#endif
22832 +
22833 +#ifdef CONFIG_PARAVIRT
22834 + PV_RESTORE_REGS(CLBR_RDI)
22835 +#endif
22836 +
22837 + popq %rdi
22838 + pax_force_retaddr
22839 + retq
22840 +
22841 +#ifdef CONFIG_PAX_KERNEXEC
22842 +2: ljmpq __KERNEL_CS,1b
22843 +3: ljmpq __KERNEXEC_KERNEL_CS,4f
22844 +4: SET_RDI_INTO_CR0
22845 + jmp 1b
22846 +#endif
22847 +ENDPROC(pax_enter_kernel)
22848 +
22849 +ENTRY(pax_exit_kernel)
22850 + pushq %rdi
22851 +
22852 +#ifdef CONFIG_PARAVIRT
22853 + PV_SAVE_REGS(CLBR_RDI)
22854 +#endif
22855 +
22856 +#ifdef CONFIG_PAX_KERNEXEC
22857 + mov %cs,%rdi
22858 + cmp $__KERNEXEC_KERNEL_CS,%edi
22859 + jz 2f
22860 + GET_CR0_INTO_RDI
22861 + bts $16,%rdi
22862 + jnc 4f
22863 +1:
22864 +#endif
22865 +
22866 +#ifdef CONFIG_PAX_MEMORY_UDEREF
22867 + 661: jmp 111f
22868 + .pushsection .altinstr_replacement, "a"
22869 + 662: ASM_NOP2
22870 + .popsection
22871 + .pushsection .altinstructions, "a"
22872 + altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
22873 + .popsection
22874 + mov %ss,%edi
22875 + cmp $__UDEREF_KERNEL_DS,%edi
22876 + jnz 111f
22877 + GET_CR3_INTO_RDI
22878 + cmp $0,%dil
22879 + jz 112f
22880 + ud2
22881 +112: add $4097,%rdi
22882 + bts $63,%rdi
22883 + SET_RDI_INTO_CR3
22884 + mov $__KERNEL_DS,%edi
22885 + mov %edi,%ss
22886 +111:
22887 +#endif
22888 +
22889 +#ifdef CONFIG_PARAVIRT
22890 + PV_RESTORE_REGS(CLBR_RDI);
22891 +#endif
22892 +
22893 + popq %rdi
22894 + pax_force_retaddr
22895 + retq
22896 +
22897 +#ifdef CONFIG_PAX_KERNEXEC
22898 +2: GET_CR0_INTO_RDI
22899 + btr $16,%rdi
22900 + jnc 4f
22901 + ljmpq __KERNEL_CS,3f
22902 +3: SET_RDI_INTO_CR0
22903 + jmp 1b
22904 +4: ud2
22905 + jmp 4b
22906 +#endif
22907 +ENDPROC(pax_exit_kernel)
22908 +#endif
22909 +
22910 + .macro pax_enter_kernel_user
22911 + pax_set_fptr_mask
22912 +#ifdef CONFIG_PAX_MEMORY_UDEREF
22913 + call pax_enter_kernel_user
22914 +#endif
22915 + .endm
22916 +
22917 + .macro pax_exit_kernel_user
22918 +#ifdef CONFIG_PAX_MEMORY_UDEREF
22919 + call pax_exit_kernel_user
22920 +#endif
22921 +#ifdef CONFIG_PAX_RANDKSTACK
22922 + pushq %rax
22923 + pushq %r11
22924 + call pax_randomize_kstack
22925 + popq %r11
22926 + popq %rax
22927 +#endif
22928 + .endm
22929 +
22930 +#ifdef CONFIG_PAX_MEMORY_UDEREF
22931 +ENTRY(pax_enter_kernel_user)
22932 + pushq %rdi
22933 + pushq %rbx
22934 +
22935 +#ifdef CONFIG_PARAVIRT
22936 + PV_SAVE_REGS(CLBR_RDI)
22937 +#endif
22938 +
22939 + 661: jmp 111f
22940 + .pushsection .altinstr_replacement, "a"
22941 + 662: ASM_NOP2
22942 + .popsection
22943 + .pushsection .altinstructions, "a"
22944 + altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
22945 + .popsection
22946 + GET_CR3_INTO_RDI
22947 + cmp $1,%dil
22948 + jnz 4f
22949 + sub $4097,%rdi
22950 + bts $63,%rdi
22951 + SET_RDI_INTO_CR3
22952 + jmp 3f
22953 +111:
22954 +
22955 + GET_CR3_INTO_RDI
22956 + mov %rdi,%rbx
22957 + add $__START_KERNEL_map,%rbx
22958 + sub phys_base(%rip),%rbx
22959 +
22960 +#ifdef CONFIG_PARAVIRT
22961 + cmpl $0, pv_info+PARAVIRT_enabled
22962 + jz 1f
22963 + pushq %rdi
22964 + i = 0
22965 + .rept USER_PGD_PTRS
22966 + mov i*8(%rbx),%rsi
22967 + mov $0,%sil
22968 + lea i*8(%rbx),%rdi
22969 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
22970 + i = i + 1
22971 + .endr
22972 + popq %rdi
22973 + jmp 2f
22974 +1:
22975 +#endif
22976 +
22977 + i = 0
22978 + .rept USER_PGD_PTRS
22979 + movb $0,i*8(%rbx)
22980 + i = i + 1
22981 + .endr
22982 +
22983 +2: SET_RDI_INTO_CR3
22984 +
22985 +#ifdef CONFIG_PAX_KERNEXEC
22986 + GET_CR0_INTO_RDI
22987 + bts $16,%rdi
22988 + SET_RDI_INTO_CR0
22989 +#endif
22990 +
22991 +3:
22992 +
22993 +#ifdef CONFIG_PARAVIRT
22994 + PV_RESTORE_REGS(CLBR_RDI)
22995 +#endif
22996 +
22997 + popq %rbx
22998 + popq %rdi
22999 + pax_force_retaddr
23000 + retq
23001 +4: ud2
23002 +ENDPROC(pax_enter_kernel_user)
23003 +
23004 +ENTRY(pax_exit_kernel_user)
23005 + pushq %rdi
23006 + pushq %rbx
23007 +
23008 +#ifdef CONFIG_PARAVIRT
23009 + PV_SAVE_REGS(CLBR_RDI)
23010 +#endif
23011 +
23012 + GET_CR3_INTO_RDI
23013 + 661: jmp 1f
23014 + .pushsection .altinstr_replacement, "a"
23015 + 662: ASM_NOP2
23016 + .popsection
23017 + .pushsection .altinstructions, "a"
23018 + altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
23019 + .popsection
23020 + cmp $0,%dil
23021 + jnz 3f
23022 + add $4097,%rdi
23023 + bts $63,%rdi
23024 + SET_RDI_INTO_CR3
23025 + jmp 2f
23026 +1:
23027 +
23028 + mov %rdi,%rbx
23029 +
23030 +#ifdef CONFIG_PAX_KERNEXEC
23031 + GET_CR0_INTO_RDI
23032 + btr $16,%rdi
23033 + jnc 3f
23034 + SET_RDI_INTO_CR0
23035 +#endif
23036 +
23037 + add $__START_KERNEL_map,%rbx
23038 + sub phys_base(%rip),%rbx
23039 +
23040 +#ifdef CONFIG_PARAVIRT
23041 + cmpl $0, pv_info+PARAVIRT_enabled
23042 + jz 1f
23043 + i = 0
23044 + .rept USER_PGD_PTRS
23045 + mov i*8(%rbx),%rsi
23046 + mov $0x67,%sil
23047 + lea i*8(%rbx),%rdi
23048 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
23049 + i = i + 1
23050 + .endr
23051 + jmp 2f
23052 +1:
23053 +#endif
23054 +
23055 + i = 0
23056 + .rept USER_PGD_PTRS
23057 + movb $0x67,i*8(%rbx)
23058 + i = i + 1
23059 + .endr
23060 +2:
23061 +
23062 +#ifdef CONFIG_PARAVIRT
23063 + PV_RESTORE_REGS(CLBR_RDI)
23064 +#endif
23065 +
23066 + popq %rbx
23067 + popq %rdi
23068 + pax_force_retaddr
23069 + retq
23070 +3: ud2
23071 +ENDPROC(pax_exit_kernel_user)
23072 +#endif
23073 +
23074 + .macro pax_enter_kernel_nmi
23075 + pax_set_fptr_mask
23076 +
23077 +#ifdef CONFIG_PAX_KERNEXEC
23078 + GET_CR0_INTO_RDI
23079 + bts $16,%rdi
23080 + jc 110f
23081 + SET_RDI_INTO_CR0
23082 + or $2,%ebx
23083 +110:
23084 +#endif
23085 +
23086 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23087 + 661: jmp 111f
23088 + .pushsection .altinstr_replacement, "a"
23089 + 662: ASM_NOP2
23090 + .popsection
23091 + .pushsection .altinstructions, "a"
23092 + altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
23093 + .popsection
23094 + GET_CR3_INTO_RDI
23095 + cmp $0,%dil
23096 + jz 111f
23097 + sub $4097,%rdi
23098 + or $4,%ebx
23099 + bts $63,%rdi
23100 + SET_RDI_INTO_CR3
23101 + mov $__UDEREF_KERNEL_DS,%edi
23102 + mov %edi,%ss
23103 +111:
23104 +#endif
23105 + .endm
23106 +
23107 + .macro pax_exit_kernel_nmi
23108 +#ifdef CONFIG_PAX_KERNEXEC
23109 + btr $1,%ebx
23110 + jnc 110f
23111 + GET_CR0_INTO_RDI
23112 + btr $16,%rdi
23113 + SET_RDI_INTO_CR0
23114 +110:
23115 +#endif
23116 +
23117 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23118 + btr $2,%ebx
23119 + jnc 111f
23120 + GET_CR3_INTO_RDI
23121 + add $4097,%rdi
23122 + bts $63,%rdi
23123 + SET_RDI_INTO_CR3
23124 + mov $__KERNEL_DS,%edi
23125 + mov %edi,%ss
23126 +111:
23127 +#endif
23128 + .endm
23129 +
23130 + .macro pax_erase_kstack
23131 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
23132 + call pax_erase_kstack
23133 +#endif
23134 + .endm
23135 +
23136 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
23137 +ENTRY(pax_erase_kstack)
23138 + pushq %rdi
23139 + pushq %rcx
23140 + pushq %rax
23141 + pushq %r11
23142 +
23143 + GET_THREAD_INFO(%r11)
23144 + mov TI_lowest_stack(%r11), %rdi
23145 + mov $-0xBEEF, %rax
23146 + std
23147 +
23148 +1: mov %edi, %ecx
23149 + and $THREAD_SIZE_asm - 1, %ecx
23150 + shr $3, %ecx
23151 + repne scasq
23152 + jecxz 2f
23153 +
23154 + cmp $2*8, %ecx
23155 + jc 2f
23156 +
23157 + mov $2*8, %ecx
23158 + repe scasq
23159 + jecxz 2f
23160 + jne 1b
23161 +
23162 +2: cld
23163 + mov %esp, %ecx
23164 + sub %edi, %ecx
23165 +
23166 + cmp $THREAD_SIZE_asm, %rcx
23167 + jb 3f
23168 + ud2
23169 +3:
23170 +
23171 + shr $3, %ecx
23172 + rep stosq
23173 +
23174 + mov TI_task_thread_sp0(%r11), %rdi
23175 + sub $256, %rdi
23176 + mov %rdi, TI_lowest_stack(%r11)
23177 +
23178 + popq %r11
23179 + popq %rax
23180 + popq %rcx
23181 + popq %rdi
23182 + pax_force_retaddr
23183 + ret
23184 +ENDPROC(pax_erase_kstack)
23185 +#endif
23186
23187 .macro TRACE_IRQS_IRETQ offset=ARGOFFSET
23188 #ifdef CONFIG_TRACE_IRQFLAGS
23189 @@ -320,7 +753,7 @@ ENDPROC(native_usergs_sysret64)
23190 .endm
23191
23192 .macro TRACE_IRQS_IRETQ_DEBUG offset=ARGOFFSET
23193 - bt $9,EFLAGS-\offset(%rsp) /* interrupts off? */
23194 + bt $X86_EFLAGS_IF_BIT,EFLAGS-\offset(%rsp) /* interrupts off? */
23195 jnc 1f
23196 TRACE_IRQS_ON_DEBUG
23197 1:
23198 @@ -358,27 +791,6 @@ ENDPROC(native_usergs_sysret64)
23199 movq \tmp,R11+\offset(%rsp)
23200 .endm
23201
23202 - .macro FAKE_STACK_FRAME child_rip
23203 - /* push in order ss, rsp, eflags, cs, rip */
23204 - xorl %eax, %eax
23205 - pushq_cfi $__KERNEL_DS /* ss */
23206 - /*CFI_REL_OFFSET ss,0*/
23207 - pushq_cfi %rax /* rsp */
23208 - CFI_REL_OFFSET rsp,0
23209 - pushq_cfi $(X86_EFLAGS_IF|X86_EFLAGS_FIXED) /* eflags - interrupts on */
23210 - /*CFI_REL_OFFSET rflags,0*/
23211 - pushq_cfi $__KERNEL_CS /* cs */
23212 - /*CFI_REL_OFFSET cs,0*/
23213 - pushq_cfi \child_rip /* rip */
23214 - CFI_REL_OFFSET rip,0
23215 - pushq_cfi %rax /* orig rax */
23216 - .endm
23217 -
23218 - .macro UNFAKE_STACK_FRAME
23219 - addq $8*6, %rsp
23220 - CFI_ADJUST_CFA_OFFSET -(6*8)
23221 - .endm
23222 -
23223 /*
23224 * initial frame state for interrupts (and exceptions without error code)
23225 */
23226 @@ -445,25 +857,26 @@ ENDPROC(native_usergs_sysret64)
23227 /* save partial stack frame */
23228 .macro SAVE_ARGS_IRQ
23229 cld
23230 - /* start from rbp in pt_regs and jump over */
23231 - movq_cfi rdi, (RDI-RBP)
23232 - movq_cfi rsi, (RSI-RBP)
23233 - movq_cfi rdx, (RDX-RBP)
23234 - movq_cfi rcx, (RCX-RBP)
23235 - movq_cfi rax, (RAX-RBP)
23236 - movq_cfi r8, (R8-RBP)
23237 - movq_cfi r9, (R9-RBP)
23238 - movq_cfi r10, (R10-RBP)
23239 - movq_cfi r11, (R11-RBP)
23240 + /* start from r15 in pt_regs and jump over */
23241 + movq_cfi rdi, RDI
23242 + movq_cfi rsi, RSI
23243 + movq_cfi rdx, RDX
23244 + movq_cfi rcx, RCX
23245 + movq_cfi rax, RAX
23246 + movq_cfi r8, R8
23247 + movq_cfi r9, R9
23248 + movq_cfi r10, R10
23249 + movq_cfi r11, R11
23250 + movq_cfi r12, R12
23251
23252 /* Save rbp so that we can unwind from get_irq_regs() */
23253 - movq_cfi rbp, 0
23254 + movq_cfi rbp, RBP
23255
23256 /* Save previous stack value */
23257 movq %rsp, %rsi
23258
23259 - leaq -RBP(%rsp),%rdi /* arg1 for handler */
23260 - testl $3, CS-RBP(%rsi)
23261 + movq %rsp,%rdi /* arg1 for handler */
23262 + testb $3, CS(%rsi)
23263 je 1f
23264 SWAPGS
23265 /*
23266 @@ -483,6 +896,18 @@ ENDPROC(native_usergs_sysret64)
23267 0x06 /* DW_OP_deref */, \
23268 0x08 /* DW_OP_const1u */, SS+8-RBP, \
23269 0x22 /* DW_OP_plus */
23270 +
23271 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23272 + testb $3, CS(%rdi)
23273 + jnz 1f
23274 + pax_enter_kernel
23275 + jmp 2f
23276 +1: pax_enter_kernel_user
23277 +2:
23278 +#else
23279 + pax_enter_kernel
23280 +#endif
23281 +
23282 /* We entered an interrupt context - irqs are off: */
23283 TRACE_IRQS_OFF
23284 .endm
23285 @@ -514,9 +939,52 @@ ENTRY(save_paranoid)
23286 js 1f /* negative -> in kernel */
23287 SWAPGS
23288 xorl %ebx,%ebx
23289 -1: ret
23290 +1:
23291 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23292 + testb $3, CS+8(%rsp)
23293 + jnz 1f
23294 + pax_enter_kernel
23295 + jmp 2f
23296 +1: pax_enter_kernel_user
23297 +2:
23298 +#else
23299 + pax_enter_kernel
23300 +#endif
23301 + pax_force_retaddr
23302 + ret
23303 CFI_ENDPROC
23304 -END(save_paranoid)
23305 +ENDPROC(save_paranoid)
23306 +
23307 +ENTRY(save_paranoid_nmi)
23308 + XCPT_FRAME 1 RDI+8
23309 + cld
23310 + movq_cfi rdi, RDI+8
23311 + movq_cfi rsi, RSI+8
23312 + movq_cfi rdx, RDX+8
23313 + movq_cfi rcx, RCX+8
23314 + movq_cfi rax, RAX+8
23315 + movq_cfi r8, R8+8
23316 + movq_cfi r9, R9+8
23317 + movq_cfi r10, R10+8
23318 + movq_cfi r11, R11+8
23319 + movq_cfi rbx, RBX+8
23320 + movq_cfi rbp, RBP+8
23321 + movq_cfi r12, R12+8
23322 + movq_cfi r13, R13+8
23323 + movq_cfi r14, R14+8
23324 + movq_cfi r15, R15+8
23325 + movl $1,%ebx
23326 + movl $MSR_GS_BASE,%ecx
23327 + rdmsr
23328 + testl %edx,%edx
23329 + js 1f /* negative -> in kernel */
23330 + SWAPGS
23331 + xorl %ebx,%ebx
23332 +1: pax_enter_kernel_nmi
23333 + pax_force_retaddr
23334 + ret
23335 + CFI_ENDPROC
23336 +ENDPROC(save_paranoid_nmi)
23337 .popsection
23338
23339 /*
23340 @@ -538,7 +1006,7 @@ ENTRY(ret_from_fork)
23341
23342 RESTORE_REST
23343
23344 - testl $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
23345 + testb $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
23346 jz 1f
23347
23348 testl $_TIF_IA32, TI_flags(%rcx) # 32-bit compat task needs IRET
23349 @@ -548,15 +1016,13 @@ ENTRY(ret_from_fork)
23350 jmp ret_from_sys_call # go to the SYSRET fastpath
23351
23352 1:
23353 - subq $REST_SKIP, %rsp # leave space for volatiles
23354 - CFI_ADJUST_CFA_OFFSET REST_SKIP
23355 movq %rbp, %rdi
23356 call *%rbx
23357 movl $0, RAX(%rsp)
23358 RESTORE_REST
23359 jmp int_ret_from_sys_call
23360 CFI_ENDPROC
23361 -END(ret_from_fork)
23362 +ENDPROC(ret_from_fork)
23363
23364 /*
23365 * System call entry. Up to 6 arguments in registers are supported.
23366 @@ -593,7 +1059,7 @@ END(ret_from_fork)
23367 ENTRY(system_call)
23368 CFI_STARTPROC simple
23369 CFI_SIGNAL_FRAME
23370 - CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
23371 + CFI_DEF_CFA rsp,0
23372 CFI_REGISTER rip,rcx
23373 /*CFI_REGISTER rflags,r11*/
23374 SWAPGS_UNSAFE_STACK
23375 @@ -606,16 +1072,23 @@ GLOBAL(system_call_after_swapgs)
23376
23377 movq %rsp,PER_CPU_VAR(old_rsp)
23378 movq PER_CPU_VAR(kernel_stack),%rsp
23379 + SAVE_ARGS 8*6,0
23380 + pax_enter_kernel_user
23381 +
23382 +#ifdef CONFIG_PAX_RANDKSTACK
23383 + pax_erase_kstack
23384 +#endif
23385 +
23386 /*
23387 * No need to follow this irqs off/on section - it's straight
23388 * and short:
23389 */
23390 ENABLE_INTERRUPTS(CLBR_NONE)
23391 - SAVE_ARGS 8,0
23392 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
23393 movq %rcx,RIP-ARGOFFSET(%rsp)
23394 CFI_REL_OFFSET rip,RIP-ARGOFFSET
23395 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
23396 + GET_THREAD_INFO(%rcx)
23397 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%rcx)
23398 jnz tracesys
23399 system_call_fastpath:
23400 #if __SYSCALL_MASK == ~0
23401 @@ -639,10 +1112,13 @@ sysret_check:
23402 LOCKDEP_SYS_EXIT
23403 DISABLE_INTERRUPTS(CLBR_NONE)
23404 TRACE_IRQS_OFF
23405 - movl TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET),%edx
23406 + GET_THREAD_INFO(%rcx)
23407 + movl TI_flags(%rcx),%edx
23408 andl %edi,%edx
23409 jnz sysret_careful
23410 CFI_REMEMBER_STATE
23411 + pax_exit_kernel_user
23412 + pax_erase_kstack
23413 /*
23414 * sysretq will re-enable interrupts:
23415 */
23416 @@ -701,6 +1177,9 @@ auditsys:
23417 movq %rax,%rsi /* 2nd arg: syscall number */
23418 movl $AUDIT_ARCH_X86_64,%edi /* 1st arg: audit arch */
23419 call __audit_syscall_entry
23420 +
23421 + pax_erase_kstack
23422 +
23423 LOAD_ARGS 0 /* reload call-clobbered registers */
23424 jmp system_call_fastpath
23425
23426 @@ -722,7 +1201,7 @@ sysret_audit:
23427 /* Do syscall tracing */
23428 tracesys:
23429 #ifdef CONFIG_AUDITSYSCALL
23430 - testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
23431 + testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%rcx)
23432 jz auditsys
23433 #endif
23434 SAVE_REST
23435 @@ -730,12 +1209,15 @@ tracesys:
23436 FIXUP_TOP_OF_STACK %rdi
23437 movq %rsp,%rdi
23438 call syscall_trace_enter
23439 +
23440 + pax_erase_kstack
23441 +
23442 /*
23443 * Reload arg registers from stack in case ptrace changed them.
23444 * We don't reload %rax because syscall_trace_enter() returned
23445 * the value it wants us to use in the table lookup.
23446 */
23447 - LOAD_ARGS ARGOFFSET, 1
23448 + LOAD_ARGS 1
23449 RESTORE_REST
23450 #if __SYSCALL_MASK == ~0
23451 cmpq $__NR_syscall_max,%rax
23452 @@ -765,7 +1247,9 @@ GLOBAL(int_with_check)
23453 andl %edi,%edx
23454 jnz int_careful
23455 andl $~TS_COMPAT,TI_status(%rcx)
23456 - jmp retint_swapgs
23457 + pax_exit_kernel_user
23458 + pax_erase_kstack
23459 + jmp retint_swapgs_pax
23460
23461 /* Either reschedule or signal or syscall exit tracking needed. */
23462 /* First do a reschedule test. */
23463 @@ -811,7 +1295,7 @@ int_restore_rest:
23464 TRACE_IRQS_OFF
23465 jmp int_with_check
23466 CFI_ENDPROC
23467 -END(system_call)
23468 +ENDPROC(system_call)
23469
23470 .macro FORK_LIKE func
23471 ENTRY(stub_\func)
23472 @@ -824,9 +1308,10 @@ ENTRY(stub_\func)
23473 DEFAULT_FRAME 0 8 /* offset 8: return address */
23474 call sys_\func
23475 RESTORE_TOP_OF_STACK %r11, 8
23476 - ret $REST_SKIP /* pop extended registers */
23477 + pax_force_retaddr
23478 + ret
23479 CFI_ENDPROC
23480 -END(stub_\func)
23481 +ENDPROC(stub_\func)
23482 .endm
23483
23484 .macro FIXED_FRAME label,func
23485 @@ -836,9 +1321,10 @@ ENTRY(\label)
23486 FIXUP_TOP_OF_STACK %r11, 8-ARGOFFSET
23487 call \func
23488 RESTORE_TOP_OF_STACK %r11, 8-ARGOFFSET
23489 + pax_force_retaddr
23490 ret
23491 CFI_ENDPROC
23492 -END(\label)
23493 +ENDPROC(\label)
23494 .endm
23495
23496 FORK_LIKE clone
23497 @@ -846,19 +1332,6 @@ END(\label)
23498 FORK_LIKE vfork
23499 FIXED_FRAME stub_iopl, sys_iopl
23500
23501 -ENTRY(ptregscall_common)
23502 - DEFAULT_FRAME 1 8 /* offset 8: return address */
23503 - RESTORE_TOP_OF_STACK %r11, 8
23504 - movq_cfi_restore R15+8, r15
23505 - movq_cfi_restore R14+8, r14
23506 - movq_cfi_restore R13+8, r13
23507 - movq_cfi_restore R12+8, r12
23508 - movq_cfi_restore RBP+8, rbp
23509 - movq_cfi_restore RBX+8, rbx
23510 - ret $REST_SKIP /* pop extended registers */
23511 - CFI_ENDPROC
23512 -END(ptregscall_common)
23513 -
23514 ENTRY(stub_execve)
23515 CFI_STARTPROC
23516 addq $8, %rsp
23517 @@ -870,7 +1343,7 @@ ENTRY(stub_execve)
23518 RESTORE_REST
23519 jmp int_ret_from_sys_call
23520 CFI_ENDPROC
23521 -END(stub_execve)
23522 +ENDPROC(stub_execve)
23523
23524 /*
23525 * sigreturn is special because it needs to restore all registers on return.
23526 @@ -887,7 +1360,7 @@ ENTRY(stub_rt_sigreturn)
23527 RESTORE_REST
23528 jmp int_ret_from_sys_call
23529 CFI_ENDPROC
23530 -END(stub_rt_sigreturn)
23531 +ENDPROC(stub_rt_sigreturn)
23532
23533 #ifdef CONFIG_X86_X32_ABI
23534 ENTRY(stub_x32_rt_sigreturn)
23535 @@ -901,7 +1374,7 @@ ENTRY(stub_x32_rt_sigreturn)
23536 RESTORE_REST
23537 jmp int_ret_from_sys_call
23538 CFI_ENDPROC
23539 -END(stub_x32_rt_sigreturn)
23540 +ENDPROC(stub_x32_rt_sigreturn)
23541
23542 ENTRY(stub_x32_execve)
23543 CFI_STARTPROC
23544 @@ -915,7 +1388,7 @@ ENTRY(stub_x32_execve)
23545 RESTORE_REST
23546 jmp int_ret_from_sys_call
23547 CFI_ENDPROC
23548 -END(stub_x32_execve)
23549 +ENDPROC(stub_x32_execve)
23550
23551 #endif
23552
23553 @@ -952,7 +1425,7 @@ vector=vector+1
23554 2: jmp common_interrupt
23555 .endr
23556 CFI_ENDPROC
23557 -END(irq_entries_start)
23558 +ENDPROC(irq_entries_start)
23559
23560 .previous
23561 END(interrupt)
23562 @@ -969,8 +1442,8 @@ END(interrupt)
23563 /* 0(%rsp): ~(interrupt number) */
23564 .macro interrupt func
23565 /* reserve pt_regs for scratch regs and rbp */
23566 - subq $ORIG_RAX-RBP, %rsp
23567 - CFI_ADJUST_CFA_OFFSET ORIG_RAX-RBP
23568 + subq $ORIG_RAX, %rsp
23569 + CFI_ADJUST_CFA_OFFSET ORIG_RAX
23570 SAVE_ARGS_IRQ
23571 call \func
23572 .endm
23573 @@ -997,14 +1470,14 @@ ret_from_intr:
23574
23575 /* Restore saved previous stack */
23576 popq %rsi
23577 - CFI_DEF_CFA rsi,SS+8-RBP /* reg/off reset after def_cfa_expr */
23578 - leaq ARGOFFSET-RBP(%rsi), %rsp
23579 + CFI_DEF_CFA rsi,SS+8 /* reg/off reset after def_cfa_expr */
23580 + movq %rsi, %rsp
23581 CFI_DEF_CFA_REGISTER rsp
23582 - CFI_ADJUST_CFA_OFFSET RBP-ARGOFFSET
23583 + CFI_ADJUST_CFA_OFFSET -ARGOFFSET
23584
23585 exit_intr:
23586 GET_THREAD_INFO(%rcx)
23587 - testl $3,CS-ARGOFFSET(%rsp)
23588 + testb $3,CS-ARGOFFSET(%rsp)
23589 je retint_kernel
23590
23591 /* Interrupt came from user space */
23592 @@ -1026,12 +1499,16 @@ retint_swapgs: /* return to user-space */
23593 * The iretq could re-enable interrupts:
23594 */
23595 DISABLE_INTERRUPTS(CLBR_ANY)
23596 + pax_exit_kernel_user
23597 +retint_swapgs_pax:
23598 TRACE_IRQS_IRETQ
23599 SWAPGS
23600 jmp restore_args
23601
23602 retint_restore_args: /* return to kernel space */
23603 DISABLE_INTERRUPTS(CLBR_ANY)
23604 + pax_exit_kernel
23605 + pax_force_retaddr (RIP-ARGOFFSET)
23606 /*
23607 * The iretq could re-enable interrupts:
23608 */
23609 @@ -1112,7 +1589,7 @@ ENTRY(retint_kernel)
23610 #endif
23611
23612 CFI_ENDPROC
23613 -END(common_interrupt)
23614 +ENDPROC(common_interrupt)
23615 /*
23616 * End of kprobes section
23617 */
23618 @@ -1130,7 +1607,7 @@ ENTRY(\sym)
23619 interrupt \do_sym
23620 jmp ret_from_intr
23621 CFI_ENDPROC
23622 -END(\sym)
23623 +ENDPROC(\sym)
23624 .endm
23625
23626 #ifdef CONFIG_TRACING
23627 @@ -1218,7 +1695,7 @@ ENTRY(\sym)
23628 call \do_sym
23629 jmp error_exit /* %ebx: no swapgs flag */
23630 CFI_ENDPROC
23631 -END(\sym)
23632 +ENDPROC(\sym)
23633 .endm
23634
23635 .macro paranoidzeroentry sym do_sym
23636 @@ -1236,10 +1713,10 @@ ENTRY(\sym)
23637 call \do_sym
23638 jmp paranoid_exit /* %ebx: no swapgs flag */
23639 CFI_ENDPROC
23640 -END(\sym)
23641 +ENDPROC(\sym)
23642 .endm
23643
23644 -#define INIT_TSS_IST(x) PER_CPU_VAR(init_tss) + (TSS_ist + ((x) - 1) * 8)
23645 +#define INIT_TSS_IST(x) (TSS_ist + ((x) - 1) * 8)(%r13)
23646 .macro paranoidzeroentry_ist sym do_sym ist
23647 ENTRY(\sym)
23648 INTR_FRAME
23649 @@ -1252,12 +1729,18 @@ ENTRY(\sym)
23650 TRACE_IRQS_OFF_DEBUG
23651 movq %rsp,%rdi /* pt_regs pointer */
23652 xorl %esi,%esi /* no error code */
23653 +#ifdef CONFIG_SMP
23654 + imul $TSS_size, PER_CPU_VAR(cpu_number), %r13d
23655 + lea init_tss(%r13), %r13
23656 +#else
23657 + lea init_tss(%rip), %r13
23658 +#endif
23659 subq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
23660 call \do_sym
23661 addq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
23662 jmp paranoid_exit /* %ebx: no swapgs flag */
23663 CFI_ENDPROC
23664 -END(\sym)
23665 +ENDPROC(\sym)
23666 .endm
23667
23668 .macro errorentry sym do_sym
23669 @@ -1275,7 +1758,7 @@ ENTRY(\sym)
23670 call \do_sym
23671 jmp error_exit /* %ebx: no swapgs flag */
23672 CFI_ENDPROC
23673 -END(\sym)
23674 +ENDPROC(\sym)
23675 .endm
23676
23677 #ifdef CONFIG_TRACING
23678 @@ -1306,7 +1789,7 @@ ENTRY(\sym)
23679 call \do_sym
23680 jmp paranoid_exit /* %ebx: no swapgs flag */
23681 CFI_ENDPROC
23682 -END(\sym)
23683 +ENDPROC(\sym)
23684 .endm
23685
23686 zeroentry divide_error do_divide_error
23687 @@ -1336,9 +1819,10 @@ gs_change:
23688 2: mfence /* workaround */
23689 SWAPGS
23690 popfq_cfi
23691 + pax_force_retaddr
23692 ret
23693 CFI_ENDPROC
23694 -END(native_load_gs_index)
23695 +ENDPROC(native_load_gs_index)
23696
23697 _ASM_EXTABLE(gs_change,bad_gs)
23698 .section .fixup,"ax"
23699 @@ -1366,9 +1850,10 @@ ENTRY(do_softirq_own_stack)
23700 CFI_DEF_CFA_REGISTER rsp
23701 CFI_ADJUST_CFA_OFFSET -8
23702 decl PER_CPU_VAR(irq_count)
23703 + pax_force_retaddr
23704 ret
23705 CFI_ENDPROC
23706 -END(do_softirq_own_stack)
23707 +ENDPROC(do_softirq_own_stack)
23708
23709 #ifdef CONFIG_XEN
23710 zeroentry xen_hypervisor_callback xen_do_hypervisor_callback
23711 @@ -1406,7 +1891,7 @@ ENTRY(xen_do_hypervisor_callback) # do_hypervisor_callback(struct *pt_regs)
23712 decl PER_CPU_VAR(irq_count)
23713 jmp error_exit
23714 CFI_ENDPROC
23715 -END(xen_do_hypervisor_callback)
23716 +ENDPROC(xen_do_hypervisor_callback)
23717
23718 /*
23719 * Hypervisor uses this for application faults while it executes.
23720 @@ -1465,7 +1950,7 @@ ENTRY(xen_failsafe_callback)
23721 SAVE_ALL
23722 jmp error_exit
23723 CFI_ENDPROC
23724 -END(xen_failsafe_callback)
23725 +ENDPROC(xen_failsafe_callback)
23726
23727 apicinterrupt3 HYPERVISOR_CALLBACK_VECTOR \
23728 xen_hvm_callback_vector xen_evtchn_do_upcall
23729 @@ -1517,18 +2002,33 @@ ENTRY(paranoid_exit)
23730 DEFAULT_FRAME
23731 DISABLE_INTERRUPTS(CLBR_NONE)
23732 TRACE_IRQS_OFF_DEBUG
23733 - testl %ebx,%ebx /* swapgs needed? */
23734 + testl $1,%ebx /* swapgs needed? */
23735 jnz paranoid_restore
23736 - testl $3,CS(%rsp)
23737 + testb $3,CS(%rsp)
23738 jnz paranoid_userspace
23739 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23740 + pax_exit_kernel
23741 + TRACE_IRQS_IRETQ 0
23742 + SWAPGS_UNSAFE_STACK
23743 + RESTORE_ALL 8
23744 + pax_force_retaddr_bts
23745 + jmp irq_return
23746 +#endif
23747 paranoid_swapgs:
23748 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23749 + pax_exit_kernel_user
23750 +#else
23751 + pax_exit_kernel
23752 +#endif
23753 TRACE_IRQS_IRETQ 0
23754 SWAPGS_UNSAFE_STACK
23755 RESTORE_ALL 8
23756 jmp irq_return
23757 paranoid_restore:
23758 + pax_exit_kernel
23759 TRACE_IRQS_IRETQ_DEBUG 0
23760 RESTORE_ALL 8
23761 + pax_force_retaddr_bts
23762 jmp irq_return
23763 paranoid_userspace:
23764 GET_THREAD_INFO(%rcx)
23765 @@ -1557,7 +2057,7 @@ paranoid_schedule:
23766 TRACE_IRQS_OFF
23767 jmp paranoid_userspace
23768 CFI_ENDPROC
23769 -END(paranoid_exit)
23770 +ENDPROC(paranoid_exit)
23771
23772 /*
23773 * Exception entry point. This expects an error code/orig_rax on the stack.
23774 @@ -1584,12 +2084,23 @@ ENTRY(error_entry)
23775 movq_cfi r14, R14+8
23776 movq_cfi r15, R15+8
23777 xorl %ebx,%ebx
23778 - testl $3,CS+8(%rsp)
23779 + testb $3,CS+8(%rsp)
23780 je error_kernelspace
23781 error_swapgs:
23782 SWAPGS
23783 error_sti:
23784 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23785 + testb $3, CS+8(%rsp)
23786 + jnz 1f
23787 + pax_enter_kernel
23788 + jmp 2f
23789 +1: pax_enter_kernel_user
23790 +2:
23791 +#else
23792 + pax_enter_kernel
23793 +#endif
23794 TRACE_IRQS_OFF
23795 + pax_force_retaddr
23796 ret
23797
23798 /*
23799 @@ -1616,7 +2127,7 @@ bstep_iret:
23800 movq %rcx,RIP+8(%rsp)
23801 jmp error_swapgs
23802 CFI_ENDPROC
23803 -END(error_entry)
23804 +ENDPROC(error_entry)
23805
23806
23807 /* ebx: no swapgs flag (1: don't need swapgs, 0: need it) */
23808 @@ -1627,7 +2138,7 @@ ENTRY(error_exit)
23809 DISABLE_INTERRUPTS(CLBR_NONE)
23810 TRACE_IRQS_OFF
23811 GET_THREAD_INFO(%rcx)
23812 - testl %eax,%eax
23813 + testl $1,%eax
23814 jne retint_kernel
23815 LOCKDEP_SYS_EXIT_IRQ
23816 movl TI_flags(%rcx),%edx
23817 @@ -1636,7 +2147,7 @@ ENTRY(error_exit)
23818 jnz retint_careful
23819 jmp retint_swapgs
23820 CFI_ENDPROC
23821 -END(error_exit)
23822 +ENDPROC(error_exit)
23823
23824 /*
23825 * Test if a given stack is an NMI stack or not.
23826 @@ -1694,9 +2205,11 @@ ENTRY(nmi)
23827 * If %cs was not the kernel segment, then the NMI triggered in user
23828 * space, which means it is definitely not nested.
23829 */
23830 + cmpl $__KERNEXEC_KERNEL_CS, 16(%rsp)
23831 + je 1f
23832 cmpl $__KERNEL_CS, 16(%rsp)
23833 jne first_nmi
23834 -
23835 +1:
23836 /*
23837 * Check the special variable on the stack to see if NMIs are
23838 * executing.
23839 @@ -1730,8 +2243,7 @@ nested_nmi:
23840
23841 1:
23842 /* Set up the interrupted NMIs stack to jump to repeat_nmi */
23843 - leaq -1*8(%rsp), %rdx
23844 - movq %rdx, %rsp
23845 + subq $8, %rsp
23846 CFI_ADJUST_CFA_OFFSET 1*8
23847 leaq -10*8(%rsp), %rdx
23848 pushq_cfi $__KERNEL_DS
23849 @@ -1749,6 +2261,7 @@ nested_nmi_out:
23850 CFI_RESTORE rdx
23851
23852 /* No need to check faults here */
23853 +# pax_force_retaddr_bts
23854 INTERRUPT_RETURN
23855
23856 CFI_RESTORE_STATE
23857 @@ -1845,13 +2358,13 @@ end_repeat_nmi:
23858 subq $ORIG_RAX-R15, %rsp
23859 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
23860 /*
23861 - * Use save_paranoid to handle SWAPGS, but no need to use paranoid_exit
23862 + * Use save_paranoid_nmi to handle SWAPGS, but no need to use paranoid_exit
23863 * as we should not be calling schedule in NMI context.
23864 * Even with normal interrupts enabled. An NMI should not be
23865 * setting NEED_RESCHED or anything that normal interrupts and
23866 * exceptions might do.
23867 */
23868 - call save_paranoid
23869 + call save_paranoid_nmi
23870 DEFAULT_FRAME 0
23871
23872 /*
23873 @@ -1861,9 +2374,9 @@ end_repeat_nmi:
23874 * NMI itself takes a page fault, the page fault that was preempted
23875 * will read the information from the NMI page fault and not the
23876 * origin fault. Save it off and restore it if it changes.
23877 - * Use the r12 callee-saved register.
23878 + * Use the r13 callee-saved register.
23879 */
23880 - movq %cr2, %r12
23881 + movq %cr2, %r13
23882
23883 /* paranoidentry do_nmi, 0; without TRACE_IRQS_OFF */
23884 movq %rsp,%rdi
23885 @@ -1872,31 +2385,36 @@ end_repeat_nmi:
23886
23887 /* Did the NMI take a page fault? Restore cr2 if it did */
23888 movq %cr2, %rcx
23889 - cmpq %rcx, %r12
23890 + cmpq %rcx, %r13
23891 je 1f
23892 - movq %r12, %cr2
23893 + movq %r13, %cr2
23894 1:
23895
23896 - testl %ebx,%ebx /* swapgs needed? */
23897 + testl $1,%ebx /* swapgs needed? */
23898 jnz nmi_restore
23899 nmi_swapgs:
23900 SWAPGS_UNSAFE_STACK
23901 nmi_restore:
23902 + pax_exit_kernel_nmi
23903 /* Pop the extra iret frame at once */
23904 RESTORE_ALL 6*8
23905 + testb $3, 8(%rsp)
23906 + jnz 1f
23907 + pax_force_retaddr_bts
23908 +1:
23909
23910 /* Clear the NMI executing stack variable */
23911 movq $0, 5*8(%rsp)
23912 jmp irq_return
23913 CFI_ENDPROC
23914 -END(nmi)
23915 +ENDPROC(nmi)
23916
23917 ENTRY(ignore_sysret)
23918 CFI_STARTPROC
23919 mov $-ENOSYS,%eax
23920 sysret
23921 CFI_ENDPROC
23922 -END(ignore_sysret)
23923 +ENDPROC(ignore_sysret)
23924
23925 /*
23926 * End of kprobes section
23927 diff --git a/arch/x86/kernel/ftrace.c b/arch/x86/kernel/ftrace.c
23928 index e625319..b9abb9d 100644
23929 --- a/arch/x86/kernel/ftrace.c
23930 +++ b/arch/x86/kernel/ftrace.c
23931 @@ -104,6 +104,8 @@ ftrace_modify_code_direct(unsigned long ip, unsigned const char *old_code,
23932 {
23933 unsigned char replaced[MCOUNT_INSN_SIZE];
23934
23935 + ip = ktla_ktva(ip);
23936 +
23937 /*
23938 * Note: Due to modules and __init, code can
23939 * disappear and change, we need to protect against faulting
23940 @@ -229,7 +231,7 @@ static int update_ftrace_func(unsigned long ip, void *new)
23941 unsigned char old[MCOUNT_INSN_SIZE];
23942 int ret;
23943
23944 - memcpy(old, (void *)ip, MCOUNT_INSN_SIZE);
23945 + memcpy(old, (void *)ktla_ktva(ip), MCOUNT_INSN_SIZE);
23946
23947 ftrace_update_func = ip;
23948 /* Make sure the breakpoints see the ftrace_update_func update */
23949 @@ -306,7 +308,7 @@ static int ftrace_write(unsigned long ip, const char *val, int size)
23950 * kernel identity mapping to modify code.
23951 */
23952 if (within(ip, (unsigned long)_text, (unsigned long)_etext))
23953 - ip = (unsigned long)__va(__pa_symbol(ip));
23954 + ip = (unsigned long)__va(__pa_symbol(ktla_ktva(ip)));
23955
23956 return probe_kernel_write((void *)ip, val, size);
23957 }
23958 @@ -316,7 +318,7 @@ static int add_break(unsigned long ip, const char *old)
23959 unsigned char replaced[MCOUNT_INSN_SIZE];
23960 unsigned char brk = BREAKPOINT_INSTRUCTION;
23961
23962 - if (probe_kernel_read(replaced, (void *)ip, MCOUNT_INSN_SIZE))
23963 + if (probe_kernel_read(replaced, (void *)ktla_ktva(ip), MCOUNT_INSN_SIZE))
23964 return -EFAULT;
23965
23966 /* Make sure it is what we expect it to be */
23967 @@ -664,7 +666,7 @@ ftrace_modify_code(unsigned long ip, unsigned const char *old_code,
23968 return ret;
23969
23970 fail_update:
23971 - probe_kernel_write((void *)ip, &old_code[0], 1);
23972 + probe_kernel_write((void *)ktla_ktva(ip), &old_code[0], 1);
23973 goto out;
23974 }
23975
23976 diff --git a/arch/x86/kernel/head64.c b/arch/x86/kernel/head64.c
23977 index 85126cc..1bbce17 100644
23978 --- a/arch/x86/kernel/head64.c
23979 +++ b/arch/x86/kernel/head64.c
23980 @@ -67,12 +67,12 @@ again:
23981 pgd = *pgd_p;
23982
23983 /*
23984 - * The use of __START_KERNEL_map rather than __PAGE_OFFSET here is
23985 - * critical -- __PAGE_OFFSET would point us back into the dynamic
23986 + * The use of __early_va rather than __va here is critical:
23987 + * __va would point us back into the dynamic
23988 * range and we might end up looping forever...
23989 */
23990 if (pgd)
23991 - pud_p = (pudval_t *)((pgd & PTE_PFN_MASK) + __START_KERNEL_map - phys_base);
23992 + pud_p = (pudval_t *)(__early_va(pgd & PTE_PFN_MASK));
23993 else {
23994 if (next_early_pgt >= EARLY_DYNAMIC_PAGE_TABLES) {
23995 reset_early_page_tables();
23996 @@ -82,13 +82,13 @@ again:
23997 pud_p = (pudval_t *)early_dynamic_pgts[next_early_pgt++];
23998 for (i = 0; i < PTRS_PER_PUD; i++)
23999 pud_p[i] = 0;
24000 - *pgd_p = (pgdval_t)pud_p - __START_KERNEL_map + phys_base + _KERNPG_TABLE;
24001 + *pgd_p = (pgdval_t)__pa(pud_p) + _KERNPG_TABLE;
24002 }
24003 pud_p += pud_index(address);
24004 pud = *pud_p;
24005
24006 if (pud)
24007 - pmd_p = (pmdval_t *)((pud & PTE_PFN_MASK) + __START_KERNEL_map - phys_base);
24008 + pmd_p = (pmdval_t *)(__early_va(pud & PTE_PFN_MASK));
24009 else {
24010 if (next_early_pgt >= EARLY_DYNAMIC_PAGE_TABLES) {
24011 reset_early_page_tables();
24012 @@ -98,7 +98,7 @@ again:
24013 pmd_p = (pmdval_t *)early_dynamic_pgts[next_early_pgt++];
24014 for (i = 0; i < PTRS_PER_PMD; i++)
24015 pmd_p[i] = 0;
24016 - *pud_p = (pudval_t)pmd_p - __START_KERNEL_map + phys_base + _KERNPG_TABLE;
24017 + *pud_p = (pudval_t)__pa(pmd_p) + _KERNPG_TABLE;
24018 }
24019 pmd = (physaddr & PMD_MASK) + early_pmd_flags;
24020 pmd_p[pmd_index(address)] = pmd;
24021 @@ -175,7 +175,6 @@ asmlinkage void __init x86_64_start_kernel(char * real_mode_data)
24022 if (console_loglevel == 10)
24023 early_printk("Kernel alive\n");
24024
24025 - clear_page(init_level4_pgt);
24026 /* set init_level4_pgt kernel high mapping*/
24027 init_level4_pgt[511] = early_level4_pgt[511];
24028
24029 diff --git a/arch/x86/kernel/head_32.S b/arch/x86/kernel/head_32.S
24030 index f36bd42..56ee1534 100644
24031 --- a/arch/x86/kernel/head_32.S
24032 +++ b/arch/x86/kernel/head_32.S
24033 @@ -26,6 +26,12 @@
24034 /* Physical address */
24035 #define pa(X) ((X) - __PAGE_OFFSET)
24036
24037 +#ifdef CONFIG_PAX_KERNEXEC
24038 +#define ta(X) (X)
24039 +#else
24040 +#define ta(X) ((X) - __PAGE_OFFSET)
24041 +#endif
24042 +
24043 /*
24044 * References to members of the new_cpu_data structure.
24045 */
24046 @@ -55,11 +61,7 @@
24047 * and small than max_low_pfn, otherwise will waste some page table entries
24048 */
24049
24050 -#if PTRS_PER_PMD > 1
24051 -#define PAGE_TABLE_SIZE(pages) (((pages) / PTRS_PER_PMD) + PTRS_PER_PGD)
24052 -#else
24053 -#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PGD)
24054 -#endif
24055 +#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PTE)
24056
24057 /* Number of possible pages in the lowmem region */
24058 LOWMEM_PAGES = (((1<<32) - __PAGE_OFFSET) >> PAGE_SHIFT)
24059 @@ -78,6 +80,12 @@ INIT_MAP_SIZE = PAGE_TABLE_SIZE(KERNEL_PAGES) * PAGE_SIZE
24060 RESERVE_BRK(pagetables, INIT_MAP_SIZE)
24061
24062 /*
24063 + * Real beginning of normal "text" segment
24064 + */
24065 +ENTRY(stext)
24066 +ENTRY(_stext)
24067 +
24068 +/*
24069 * 32-bit kernel entrypoint; only used by the boot CPU. On entry,
24070 * %esi points to the real-mode code as a 32-bit pointer.
24071 * CS and DS must be 4 GB flat segments, but we don't depend on
24072 @@ -85,6 +93,13 @@ RESERVE_BRK(pagetables, INIT_MAP_SIZE)
24073 * can.
24074 */
24075 __HEAD
24076 +
24077 +#ifdef CONFIG_PAX_KERNEXEC
24078 + jmp startup_32
24079 +/* PaX: fill first page in .text with int3 to catch NULL derefs in kernel mode */
24080 +.fill PAGE_SIZE-5,1,0xcc
24081 +#endif
24082 +
24083 ENTRY(startup_32)
24084 movl pa(stack_start),%ecx
24085
24086 @@ -106,6 +121,59 @@ ENTRY(startup_32)
24087 2:
24088 leal -__PAGE_OFFSET(%ecx),%esp
24089
24090 +#ifdef CONFIG_SMP
24091 + movl $pa(cpu_gdt_table),%edi
24092 + movl $__per_cpu_load,%eax
24093 + movw %ax,GDT_ENTRY_PERCPU * 8 + 2(%edi)
24094 + rorl $16,%eax
24095 + movb %al,GDT_ENTRY_PERCPU * 8 + 4(%edi)
24096 + movb %ah,GDT_ENTRY_PERCPU * 8 + 7(%edi)
24097 + movl $__per_cpu_end - 1,%eax
24098 + subl $__per_cpu_start,%eax
24099 + movw %ax,GDT_ENTRY_PERCPU * 8 + 0(%edi)
24100 +#endif
24101 +
24102 +#ifdef CONFIG_PAX_MEMORY_UDEREF
24103 + movl $NR_CPUS,%ecx
24104 + movl $pa(cpu_gdt_table),%edi
24105 +1:
24106 + movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c09700),GDT_ENTRY_KERNEL_DS * 8 + 4(%edi)
24107 + movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0fb00),GDT_ENTRY_DEFAULT_USER_CS * 8 + 4(%edi)
24108 + movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0f300),GDT_ENTRY_DEFAULT_USER_DS * 8 + 4(%edi)
24109 + addl $PAGE_SIZE_asm,%edi
24110 + loop 1b
24111 +#endif
24112 +
24113 +#ifdef CONFIG_PAX_KERNEXEC
24114 + movl $pa(boot_gdt),%edi
24115 + movl $__LOAD_PHYSICAL_ADDR,%eax
24116 + movw %ax,GDT_ENTRY_BOOT_CS * 8 + 2(%edi)
24117 + rorl $16,%eax
24118 + movb %al,GDT_ENTRY_BOOT_CS * 8 + 4(%edi)
24119 + movb %ah,GDT_ENTRY_BOOT_CS * 8 + 7(%edi)
24120 + rorl $16,%eax
24121 +
24122 + ljmp $(__BOOT_CS),$1f
24123 +1:
24124 +
24125 + movl $NR_CPUS,%ecx
24126 + movl $pa(cpu_gdt_table),%edi
24127 + addl $__PAGE_OFFSET,%eax
24128 +1:
24129 + movb $0xc0,GDT_ENTRY_KERNEL_CS * 8 + 6(%edi)
24130 + movb $0xc0,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 6(%edi)
24131 + movw %ax,GDT_ENTRY_KERNEL_CS * 8 + 2(%edi)
24132 + movw %ax,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 2(%edi)
24133 + rorl $16,%eax
24134 + movb %al,GDT_ENTRY_KERNEL_CS * 8 + 4(%edi)
24135 + movb %al,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 4(%edi)
24136 + movb %ah,GDT_ENTRY_KERNEL_CS * 8 + 7(%edi)
24137 + movb %ah,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 7(%edi)
24138 + rorl $16,%eax
24139 + addl $PAGE_SIZE_asm,%edi
24140 + loop 1b
24141 +#endif
24142 +
24143 /*
24144 * Clear BSS first so that there are no surprises...
24145 */
24146 @@ -201,8 +269,11 @@ ENTRY(startup_32)
24147 movl %eax, pa(max_pfn_mapped)
24148
24149 /* Do early initialization of the fixmap area */
24150 - movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
24151 - movl %eax,pa(initial_pg_pmd+0x1000*KPMDS-8)
24152 +#ifdef CONFIG_COMPAT_VDSO
24153 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_pg_pmd+0x1000*KPMDS-8)
24154 +#else
24155 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_pg_pmd+0x1000*KPMDS-8)
24156 +#endif
24157 #else /* Not PAE */
24158
24159 page_pde_offset = (__PAGE_OFFSET >> 20);
24160 @@ -232,8 +303,11 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
24161 movl %eax, pa(max_pfn_mapped)
24162
24163 /* Do early initialization of the fixmap area */
24164 - movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
24165 - movl %eax,pa(initial_page_table+0xffc)
24166 +#ifdef CONFIG_COMPAT_VDSO
24167 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_page_table+0xffc)
24168 +#else
24169 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_page_table+0xffc)
24170 +#endif
24171 #endif
24172
24173 #ifdef CONFIG_PARAVIRT
24174 @@ -247,9 +321,7 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
24175 cmpl $num_subarch_entries, %eax
24176 jae bad_subarch
24177
24178 - movl pa(subarch_entries)(,%eax,4), %eax
24179 - subl $__PAGE_OFFSET, %eax
24180 - jmp *%eax
24181 + jmp *pa(subarch_entries)(,%eax,4)
24182
24183 bad_subarch:
24184 WEAK(lguest_entry)
24185 @@ -261,10 +333,10 @@ WEAK(xen_entry)
24186 __INITDATA
24187
24188 subarch_entries:
24189 - .long default_entry /* normal x86/PC */
24190 - .long lguest_entry /* lguest hypervisor */
24191 - .long xen_entry /* Xen hypervisor */
24192 - .long default_entry /* Moorestown MID */
24193 + .long ta(default_entry) /* normal x86/PC */
24194 + .long ta(lguest_entry) /* lguest hypervisor */
24195 + .long ta(xen_entry) /* Xen hypervisor */
24196 + .long ta(default_entry) /* Moorestown MID */
24197 num_subarch_entries = (. - subarch_entries) / 4
24198 .previous
24199 #else
24200 @@ -354,6 +426,7 @@ default_entry:
24201 movl pa(mmu_cr4_features),%eax
24202 movl %eax,%cr4
24203
24204 +#ifdef CONFIG_X86_PAE
24205 testb $X86_CR4_PAE, %al # check if PAE is enabled
24206 jz enable_paging
24207
24208 @@ -382,6 +455,9 @@ default_entry:
24209 /* Make changes effective */
24210 wrmsr
24211
24212 + btsl $_PAGE_BIT_NX-32,pa(__supported_pte_mask+4)
24213 +#endif
24214 +
24215 enable_paging:
24216
24217 /*
24218 @@ -449,14 +525,20 @@ is486:
24219 1: movl $(__KERNEL_DS),%eax # reload all the segment registers
24220 movl %eax,%ss # after changing gdt.
24221
24222 - movl $(__USER_DS),%eax # DS/ES contains default USER segment
24223 +# movl $(__KERNEL_DS),%eax # DS/ES contains default KERNEL segment
24224 movl %eax,%ds
24225 movl %eax,%es
24226
24227 movl $(__KERNEL_PERCPU), %eax
24228 movl %eax,%fs # set this cpu's percpu
24229
24230 +#ifdef CONFIG_CC_STACKPROTECTOR
24231 movl $(__KERNEL_STACK_CANARY),%eax
24232 +#elif defined(CONFIG_PAX_MEMORY_UDEREF)
24233 + movl $(__USER_DS),%eax
24234 +#else
24235 + xorl %eax,%eax
24236 +#endif
24237 movl %eax,%gs
24238
24239 xorl %eax,%eax # Clear LDT
24240 @@ -512,8 +594,11 @@ setup_once:
24241 * relocation. Manually set base address in stack canary
24242 * segment descriptor.
24243 */
24244 - movl $gdt_page,%eax
24245 + movl $cpu_gdt_table,%eax
24246 movl $stack_canary,%ecx
24247 +#ifdef CONFIG_SMP
24248 + addl $__per_cpu_load,%ecx
24249 +#endif
24250 movw %cx, 8 * GDT_ENTRY_STACK_CANARY + 2(%eax)
24251 shrl $16, %ecx
24252 movb %cl, 8 * GDT_ENTRY_STACK_CANARY + 4(%eax)
24253 @@ -548,7 +633,7 @@ ENTRY(early_idt_handler)
24254 cmpl $2,(%esp) # X86_TRAP_NMI
24255 je is_nmi # Ignore NMI
24256
24257 - cmpl $2,%ss:early_recursion_flag
24258 + cmpl $1,%ss:early_recursion_flag
24259 je hlt_loop
24260 incl %ss:early_recursion_flag
24261
24262 @@ -586,8 +671,8 @@ ENTRY(early_idt_handler)
24263 pushl (20+6*4)(%esp) /* trapno */
24264 pushl $fault_msg
24265 call printk
24266 -#endif
24267 call dump_stack
24268 +#endif
24269 hlt_loop:
24270 hlt
24271 jmp hlt_loop
24272 @@ -607,8 +692,11 @@ ENDPROC(early_idt_handler)
24273 /* This is the default interrupt "handler" :-) */
24274 ALIGN
24275 ignore_int:
24276 - cld
24277 #ifdef CONFIG_PRINTK
24278 + cmpl $2,%ss:early_recursion_flag
24279 + je hlt_loop
24280 + incl %ss:early_recursion_flag
24281 + cld
24282 pushl %eax
24283 pushl %ecx
24284 pushl %edx
24285 @@ -617,9 +705,6 @@ ignore_int:
24286 movl $(__KERNEL_DS),%eax
24287 movl %eax,%ds
24288 movl %eax,%es
24289 - cmpl $2,early_recursion_flag
24290 - je hlt_loop
24291 - incl early_recursion_flag
24292 pushl 16(%esp)
24293 pushl 24(%esp)
24294 pushl 32(%esp)
24295 @@ -653,29 +738,34 @@ ENTRY(setup_once_ref)
24296 /*
24297 * BSS section
24298 */
24299 -__PAGE_ALIGNED_BSS
24300 - .align PAGE_SIZE
24301 #ifdef CONFIG_X86_PAE
24302 +.section .initial_pg_pmd,"a",@progbits
24303 initial_pg_pmd:
24304 .fill 1024*KPMDS,4,0
24305 #else
24306 +.section .initial_page_table,"a",@progbits
24307 ENTRY(initial_page_table)
24308 .fill 1024,4,0
24309 #endif
24310 +.section .initial_pg_fixmap,"a",@progbits
24311 initial_pg_fixmap:
24312 .fill 1024,4,0
24313 +.section .empty_zero_page,"a",@progbits
24314 ENTRY(empty_zero_page)
24315 .fill 4096,1,0
24316 +.section .swapper_pg_dir,"a",@progbits
24317 ENTRY(swapper_pg_dir)
24318 +#ifdef CONFIG_X86_PAE
24319 + .fill 4,8,0
24320 +#else
24321 .fill 1024,4,0
24322 +#endif
24323
24324 /*
24325 * This starts the data section.
24326 */
24327 #ifdef CONFIG_X86_PAE
24328 -__PAGE_ALIGNED_DATA
24329 - /* Page-aligned for the benefit of paravirt? */
24330 - .align PAGE_SIZE
24331 +.section .initial_page_table,"a",@progbits
24332 ENTRY(initial_page_table)
24333 .long pa(initial_pg_pmd+PGD_IDENT_ATTR),0 /* low identity map */
24334 # if KPMDS == 3
24335 @@ -694,12 +784,20 @@ ENTRY(initial_page_table)
24336 # error "Kernel PMDs should be 1, 2 or 3"
24337 # endif
24338 .align PAGE_SIZE /* needs to be page-sized too */
24339 +
24340 +#ifdef CONFIG_PAX_PER_CPU_PGD
24341 +ENTRY(cpu_pgd)
24342 + .rept 2*NR_CPUS
24343 + .fill 4,8,0
24344 + .endr
24345 +#endif
24346 +
24347 #endif
24348
24349 .data
24350 .balign 4
24351 ENTRY(stack_start)
24352 - .long init_thread_union+THREAD_SIZE
24353 + .long init_thread_union+THREAD_SIZE-8
24354
24355 __INITRODATA
24356 int_msg:
24357 @@ -727,7 +825,7 @@ fault_msg:
24358 * segment size, and 32-bit linear address value:
24359 */
24360
24361 - .data
24362 +.section .rodata,"a",@progbits
24363 .globl boot_gdt_descr
24364 .globl idt_descr
24365
24366 @@ -736,7 +834,7 @@ fault_msg:
24367 .word 0 # 32 bit align gdt_desc.address
24368 boot_gdt_descr:
24369 .word __BOOT_DS+7
24370 - .long boot_gdt - __PAGE_OFFSET
24371 + .long pa(boot_gdt)
24372
24373 .word 0 # 32-bit align idt_desc.address
24374 idt_descr:
24375 @@ -747,7 +845,7 @@ idt_descr:
24376 .word 0 # 32 bit align gdt_desc.address
24377 ENTRY(early_gdt_descr)
24378 .word GDT_ENTRIES*8-1
24379 - .long gdt_page /* Overwritten for secondary CPUs */
24380 + .long cpu_gdt_table /* Overwritten for secondary CPUs */
24381
24382 /*
24383 * The boot_gdt must mirror the equivalent in setup.S and is
24384 @@ -756,5 +854,65 @@ ENTRY(early_gdt_descr)
24385 .align L1_CACHE_BYTES
24386 ENTRY(boot_gdt)
24387 .fill GDT_ENTRY_BOOT_CS,8,0
24388 - .quad 0x00cf9a000000ffff /* kernel 4GB code at 0x00000000 */
24389 - .quad 0x00cf92000000ffff /* kernel 4GB data at 0x00000000 */
24390 + .quad 0x00cf9b000000ffff /* kernel 4GB code at 0x00000000 */
24391 + .quad 0x00cf93000000ffff /* kernel 4GB data at 0x00000000 */
24392 +
24393 + .align PAGE_SIZE_asm
24394 +ENTRY(cpu_gdt_table)
24395 + .rept NR_CPUS
24396 + .quad 0x0000000000000000 /* NULL descriptor */
24397 + .quad 0x0000000000000000 /* 0x0b reserved */
24398 + .quad 0x0000000000000000 /* 0x13 reserved */
24399 + .quad 0x0000000000000000 /* 0x1b reserved */
24400 +
24401 +#ifdef CONFIG_PAX_KERNEXEC
24402 + .quad 0x00cf9b000000ffff /* 0x20 alternate kernel 4GB code at 0x00000000 */
24403 +#else
24404 + .quad 0x0000000000000000 /* 0x20 unused */
24405 +#endif
24406 +
24407 + .quad 0x0000000000000000 /* 0x28 unused */
24408 + .quad 0x0000000000000000 /* 0x33 TLS entry 1 */
24409 + .quad 0x0000000000000000 /* 0x3b TLS entry 2 */
24410 + .quad 0x0000000000000000 /* 0x43 TLS entry 3 */
24411 + .quad 0x0000000000000000 /* 0x4b reserved */
24412 + .quad 0x0000000000000000 /* 0x53 reserved */
24413 + .quad 0x0000000000000000 /* 0x5b reserved */
24414 +
24415 + .quad 0x00cf9b000000ffff /* 0x60 kernel 4GB code at 0x00000000 */
24416 + .quad 0x00cf93000000ffff /* 0x68 kernel 4GB data at 0x00000000 */
24417 + .quad 0x00cffb000000ffff /* 0x73 user 4GB code at 0x00000000 */
24418 + .quad 0x00cff3000000ffff /* 0x7b user 4GB data at 0x00000000 */
24419 +
24420 + .quad 0x0000000000000000 /* 0x80 TSS descriptor */
24421 + .quad 0x0000000000000000 /* 0x88 LDT descriptor */
24422 +
24423 + /*
24424 + * Segments used for calling PnP BIOS have byte granularity.
24425 + * The code segments and data segments have fixed 64k limits,
24426 + * the transfer segment sizes are set at run time.
24427 + */
24428 + .quad 0x00409b000000ffff /* 0x90 32-bit code */
24429 + .quad 0x00009b000000ffff /* 0x98 16-bit code */
24430 + .quad 0x000093000000ffff /* 0xa0 16-bit data */
24431 + .quad 0x0000930000000000 /* 0xa8 16-bit data */
24432 + .quad 0x0000930000000000 /* 0xb0 16-bit data */
24433 +
24434 + /*
24435 + * The APM segments have byte granularity and their bases
24436 + * are set at run time. All have 64k limits.
24437 + */
24438 + .quad 0x00409b000000ffff /* 0xb8 APM CS code */
24439 + .quad 0x00009b000000ffff /* 0xc0 APM CS 16 code (16 bit) */
24440 + .quad 0x004093000000ffff /* 0xc8 APM DS data */
24441 +
24442 + .quad 0x00c0930000000000 /* 0xd0 - ESPFIX SS */
24443 + .quad 0x0040930000000000 /* 0xd8 - PERCPU */
24444 + .quad 0x0040910000000017 /* 0xe0 - STACK_CANARY */
24445 + .quad 0x0000000000000000 /* 0xe8 - PCIBIOS_CS */
24446 + .quad 0x0000000000000000 /* 0xf0 - PCIBIOS_DS */
24447 + .quad 0x0000000000000000 /* 0xf8 - GDT entry 31: double-fault TSS */
24448 +
24449 + /* Be sure this is zeroed to avoid false validations in Xen */
24450 + .fill PAGE_SIZE_asm - GDT_SIZE,1,0
24451 + .endr
24452 diff --git a/arch/x86/kernel/head_64.S b/arch/x86/kernel/head_64.S
24453 index a468c0a..c7dec74 100644
24454 --- a/arch/x86/kernel/head_64.S
24455 +++ b/arch/x86/kernel/head_64.S
24456 @@ -20,6 +20,8 @@
24457 #include <asm/processor-flags.h>
24458 #include <asm/percpu.h>
24459 #include <asm/nops.h>
24460 +#include <asm/cpufeature.h>
24461 +#include <asm/alternative-asm.h>
24462
24463 #ifdef CONFIG_PARAVIRT
24464 #include <asm/asm-offsets.h>
24465 @@ -41,6 +43,12 @@ L4_PAGE_OFFSET = pgd_index(__PAGE_OFFSET)
24466 L3_PAGE_OFFSET = pud_index(__PAGE_OFFSET)
24467 L4_START_KERNEL = pgd_index(__START_KERNEL_map)
24468 L3_START_KERNEL = pud_index(__START_KERNEL_map)
24469 +L4_VMALLOC_START = pgd_index(VMALLOC_START)
24470 +L3_VMALLOC_START = pud_index(VMALLOC_START)
24471 +L4_VMALLOC_END = pgd_index(VMALLOC_END)
24472 +L3_VMALLOC_END = pud_index(VMALLOC_END)
24473 +L4_VMEMMAP_START = pgd_index(VMEMMAP_START)
24474 +L3_VMEMMAP_START = pud_index(VMEMMAP_START)
24475
24476 .text
24477 __HEAD
24478 @@ -89,11 +97,24 @@ startup_64:
24479 * Fixup the physical addresses in the page table
24480 */
24481 addq %rbp, early_level4_pgt + (L4_START_KERNEL*8)(%rip)
24482 + addq %rbp, init_level4_pgt + (L4_PAGE_OFFSET*8)(%rip)
24483 + addq %rbp, init_level4_pgt + (L4_VMALLOC_START*8)(%rip)
24484 + addq %rbp, init_level4_pgt + (L4_VMALLOC_END*8)(%rip)
24485 + addq %rbp, init_level4_pgt + (L4_VMEMMAP_START*8)(%rip)
24486 + addq %rbp, init_level4_pgt + (L4_START_KERNEL*8)(%rip)
24487
24488 - addq %rbp, level3_kernel_pgt + (510*8)(%rip)
24489 - addq %rbp, level3_kernel_pgt + (511*8)(%rip)
24490 + addq %rbp, level3_ident_pgt + (0*8)(%rip)
24491 +#ifndef CONFIG_XEN
24492 + addq %rbp, level3_ident_pgt + (1*8)(%rip)
24493 +#endif
24494 +
24495 + addq %rbp, level3_vmemmap_pgt + (L3_VMEMMAP_START*8)(%rip)
24496 +
24497 + addq %rbp, level3_kernel_pgt + (L3_START_KERNEL*8)(%rip)
24498 + addq %rbp, level3_kernel_pgt + ((L3_START_KERNEL+1)*8)(%rip)
24499
24500 addq %rbp, level2_fixmap_pgt + (506*8)(%rip)
24501 + addq %rbp, level2_fixmap_pgt + (507*8)(%rip)
24502
24503 /*
24504 * Set up the identity mapping for the switchover. These
24505 @@ -177,8 +198,8 @@ ENTRY(secondary_startup_64)
24506 movq $(init_level4_pgt - __START_KERNEL_map), %rax
24507 1:
24508
24509 - /* Enable PAE mode and PGE */
24510 - movl $(X86_CR4_PAE | X86_CR4_PGE), %ecx
24511 + /* Enable PAE mode and PSE/PGE */
24512 + movl $(X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE), %ecx
24513 movq %rcx, %cr4
24514
24515 /* Setup early boot stage 4 level pagetables. */
24516 @@ -199,10 +220,19 @@ ENTRY(secondary_startup_64)
24517 movl $MSR_EFER, %ecx
24518 rdmsr
24519 btsl $_EFER_SCE, %eax /* Enable System Call */
24520 - btl $20,%edi /* No Execute supported? */
24521 + btl $(X86_FEATURE_NX & 31),%edi /* No Execute supported? */
24522 jnc 1f
24523 btsl $_EFER_NX, %eax
24524 btsq $_PAGE_BIT_NX,early_pmd_flags(%rip)
24525 +#ifndef CONFIG_EFI
24526 + btsq $_PAGE_BIT_NX, init_level4_pgt + 8*L4_PAGE_OFFSET(%rip)
24527 +#endif
24528 + btsq $_PAGE_BIT_NX, init_level4_pgt + 8*L4_VMALLOC_START(%rip)
24529 + btsq $_PAGE_BIT_NX, init_level4_pgt + 8*L4_VMALLOC_END(%rip)
24530 + btsq $_PAGE_BIT_NX, init_level4_pgt + 8*L4_VMEMMAP_START(%rip)
24531 + btsq $_PAGE_BIT_NX, level2_fixmap_pgt + 8*506(%rip)
24532 + btsq $_PAGE_BIT_NX, level2_fixmap_pgt + 8*507(%rip)
24533 + btsq $_PAGE_BIT_NX, __supported_pte_mask(%rip)
24534 1: wrmsr /* Make changes effective */
24535
24536 /* Setup cr0 */
24537 @@ -282,6 +312,7 @@ ENTRY(secondary_startup_64)
24538 * REX.W + FF /5 JMP m16:64 Jump far, absolute indirect,
24539 * address given in m16:64.
24540 */
24541 + pax_set_fptr_mask
24542 movq initial_code(%rip),%rax
24543 pushq $0 # fake return address to stop unwinder
24544 pushq $__KERNEL_CS # set correct cs
24545 @@ -313,7 +344,7 @@ ENDPROC(start_cpu0)
24546 .quad INIT_PER_CPU_VAR(irq_stack_union)
24547
24548 GLOBAL(stack_start)
24549 - .quad init_thread_union+THREAD_SIZE-8
24550 + .quad init_thread_union+THREAD_SIZE-16
24551 .word 0
24552 __FINITDATA
24553
24554 @@ -391,7 +422,7 @@ ENTRY(early_idt_handler)
24555 call dump_stack
24556 #ifdef CONFIG_KALLSYMS
24557 leaq early_idt_ripmsg(%rip),%rdi
24558 - movq 40(%rsp),%rsi # %rip again
24559 + movq 88(%rsp),%rsi # %rip again
24560 call __print_symbol
24561 #endif
24562 #endif /* EARLY_PRINTK */
24563 @@ -420,6 +451,7 @@ ENDPROC(early_idt_handler)
24564 early_recursion_flag:
24565 .long 0
24566
24567 + .section .rodata,"a",@progbits
24568 #ifdef CONFIG_EARLY_PRINTK
24569 early_idt_msg:
24570 .asciz "PANIC: early exception %02lx rip %lx:%lx error %lx cr2 %lx\n"
24571 @@ -447,29 +479,52 @@ NEXT_PAGE(early_level4_pgt)
24572 NEXT_PAGE(early_dynamic_pgts)
24573 .fill 512*EARLY_DYNAMIC_PAGE_TABLES,8,0
24574
24575 - .data
24576 + .section .rodata,"a",@progbits
24577
24578 -#ifndef CONFIG_XEN
24579 NEXT_PAGE(init_level4_pgt)
24580 - .fill 512,8,0
24581 -#else
24582 -NEXT_PAGE(init_level4_pgt)
24583 - .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
24584 .org init_level4_pgt + L4_PAGE_OFFSET*8, 0
24585 .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
24586 + .org init_level4_pgt + L4_VMALLOC_START*8, 0
24587 + .quad level3_vmalloc_start_pgt - __START_KERNEL_map + _KERNPG_TABLE
24588 + .org init_level4_pgt + L4_VMALLOC_END*8, 0
24589 + .quad level3_vmalloc_end_pgt - __START_KERNEL_map + _KERNPG_TABLE
24590 + .org init_level4_pgt + L4_VMEMMAP_START*8, 0
24591 + .quad level3_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
24592 .org init_level4_pgt + L4_START_KERNEL*8, 0
24593 /* (2^48-(2*1024*1024*1024))/(2^39) = 511 */
24594 .quad level3_kernel_pgt - __START_KERNEL_map + _PAGE_TABLE
24595
24596 +#ifdef CONFIG_PAX_PER_CPU_PGD
24597 +NEXT_PAGE(cpu_pgd)
24598 + .rept 2*NR_CPUS
24599 + .fill 512,8,0
24600 + .endr
24601 +#endif
24602 +
24603 NEXT_PAGE(level3_ident_pgt)
24604 .quad level2_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
24605 +#ifdef CONFIG_XEN
24606 .fill 511, 8, 0
24607 +#else
24608 + .quad level2_ident_pgt + PAGE_SIZE - __START_KERNEL_map + _KERNPG_TABLE
24609 + .fill 510,8,0
24610 +#endif
24611 +
24612 +NEXT_PAGE(level3_vmalloc_start_pgt)
24613 + .fill 512,8,0
24614 +
24615 +NEXT_PAGE(level3_vmalloc_end_pgt)
24616 + .fill 512,8,0
24617 +
24618 +NEXT_PAGE(level3_vmemmap_pgt)
24619 + .fill L3_VMEMMAP_START,8,0
24620 + .quad level2_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
24621 +
24622 NEXT_PAGE(level2_ident_pgt)
24623 - /* Since I easily can, map the first 1G.
24624 + /* Since I easily can, map the first 2G.
24625 * Don't set NX because code runs from these pages.
24626 */
24627 - PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, PTRS_PER_PMD)
24628 -#endif
24629 + PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, 2*PTRS_PER_PMD)
24630
24631 NEXT_PAGE(level3_kernel_pgt)
24632 .fill L3_START_KERNEL,8,0
24633 @@ -477,6 +532,9 @@ NEXT_PAGE(level3_kernel_pgt)
24634 .quad level2_kernel_pgt - __START_KERNEL_map + _KERNPG_TABLE
24635 .quad level2_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
24636
24637 +NEXT_PAGE(level2_vmemmap_pgt)
24638 + .fill 512,8,0
24639 +
24640 NEXT_PAGE(level2_kernel_pgt)
24641 /*
24642 * 512 MB kernel mapping. We spend a full page on this pagetable
24643 @@ -494,28 +552,64 @@ NEXT_PAGE(level2_kernel_pgt)
24644 NEXT_PAGE(level2_fixmap_pgt)
24645 .fill 506,8,0
24646 .quad level1_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
24647 - /* 8MB reserved for vsyscalls + a 2MB hole = 4 + 1 entries */
24648 - .fill 5,8,0
24649 + .quad level1_vsyscall_pgt - __START_KERNEL_map + _PAGE_TABLE
24650 + /* 6MB reserved for vsyscalls + a 2MB hole = 3 + 1 entries */
24651 + .fill 4,8,0
24652
24653 NEXT_PAGE(level1_fixmap_pgt)
24654 .fill 512,8,0
24655
24656 +NEXT_PAGE(level1_vsyscall_pgt)
24657 + .fill 512,8,0
24658 +
24659 #undef PMDS
24660
24661 - .data
24662 + .align PAGE_SIZE
24663 +ENTRY(cpu_gdt_table)
24664 + .rept NR_CPUS
24665 + .quad 0x0000000000000000 /* NULL descriptor */
24666 + .quad 0x00cf9b000000ffff /* __KERNEL32_CS */
24667 + .quad 0x00af9b000000ffff /* __KERNEL_CS */
24668 + .quad 0x00cf93000000ffff /* __KERNEL_DS */
24669 + .quad 0x00cffb000000ffff /* __USER32_CS */
24670 + .quad 0x00cff3000000ffff /* __USER_DS, __USER32_DS */
24671 + .quad 0x00affb000000ffff /* __USER_CS */
24672 +
24673 +#ifdef CONFIG_PAX_KERNEXEC
24674 + .quad 0x00af9b000000ffff /* __KERNEXEC_KERNEL_CS */
24675 +#else
24676 + .quad 0x0 /* unused */
24677 +#endif
24678 +
24679 + .quad 0,0 /* TSS */
24680 + .quad 0,0 /* LDT */
24681 + .quad 0,0,0 /* three TLS descriptors */
24682 + .quad 0x0000f40000000000 /* node/CPU stored in limit */
24683 + /* asm/segment.h:GDT_ENTRIES must match this */
24684 +
24685 +#ifdef CONFIG_PAX_MEMORY_UDEREF
24686 + .quad 0x00cf93000000ffff /* __UDEREF_KERNEL_DS */
24687 +#else
24688 + .quad 0x0 /* unused */
24689 +#endif
24690 +
24691 + /* zero the remaining page */
24692 + .fill PAGE_SIZE / 8 - GDT_ENTRIES,8,0
24693 + .endr
24694 +
24695 .align 16
24696 .globl early_gdt_descr
24697 early_gdt_descr:
24698 .word GDT_ENTRIES*8-1
24699 early_gdt_descr_base:
24700 - .quad INIT_PER_CPU_VAR(gdt_page)
24701 + .quad cpu_gdt_table
24702
24703 ENTRY(phys_base)
24704 /* This must match the first entry in level2_kernel_pgt */
24705 .quad 0x0000000000000000
24706
24707 #include "../../x86/xen/xen-head.S"
24708 -
24709 - __PAGE_ALIGNED_BSS
24710 +
24711 + .section .rodata,"a",@progbits
24712 NEXT_PAGE(empty_zero_page)
24713 .skip PAGE_SIZE
24714 diff --git a/arch/x86/kernel/i386_ksyms_32.c b/arch/x86/kernel/i386_ksyms_32.c
24715 index 05fd74f..c3548b1 100644
24716 --- a/arch/x86/kernel/i386_ksyms_32.c
24717 +++ b/arch/x86/kernel/i386_ksyms_32.c
24718 @@ -20,8 +20,12 @@ extern void cmpxchg8b_emu(void);
24719 EXPORT_SYMBOL(cmpxchg8b_emu);
24720 #endif
24721
24722 +EXPORT_SYMBOL_GPL(cpu_gdt_table);
24723 +
24724 /* Networking helper routines. */
24725 EXPORT_SYMBOL(csum_partial_copy_generic);
24726 +EXPORT_SYMBOL(csum_partial_copy_generic_to_user);
24727 +EXPORT_SYMBOL(csum_partial_copy_generic_from_user);
24728
24729 EXPORT_SYMBOL(__get_user_1);
24730 EXPORT_SYMBOL(__get_user_2);
24731 @@ -44,3 +48,11 @@ EXPORT_SYMBOL(___preempt_schedule);
24732 EXPORT_SYMBOL(___preempt_schedule_context);
24733 #endif
24734 #endif
24735 +
24736 +#ifdef CONFIG_PAX_KERNEXEC
24737 +EXPORT_SYMBOL(__LOAD_PHYSICAL_ADDR);
24738 +#endif
24739 +
24740 +#ifdef CONFIG_PAX_PER_CPU_PGD
24741 +EXPORT_SYMBOL(cpu_pgd);
24742 +#endif
24743 diff --git a/arch/x86/kernel/i387.c b/arch/x86/kernel/i387.c
24744 index d5dd808..b6432cf 100644
24745 --- a/arch/x86/kernel/i387.c
24746 +++ b/arch/x86/kernel/i387.c
24747 @@ -51,7 +51,7 @@ static inline bool interrupted_kernel_fpu_idle(void)
24748 static inline bool interrupted_user_mode(void)
24749 {
24750 struct pt_regs *regs = get_irq_regs();
24751 - return regs && user_mode_vm(regs);
24752 + return regs && user_mode(regs);
24753 }
24754
24755 /*
24756 diff --git a/arch/x86/kernel/i8259.c b/arch/x86/kernel/i8259.c
24757 index 2e977b5..5f2c273 100644
24758 --- a/arch/x86/kernel/i8259.c
24759 +++ b/arch/x86/kernel/i8259.c
24760 @@ -110,7 +110,7 @@ static int i8259A_irq_pending(unsigned int irq)
24761 static void make_8259A_irq(unsigned int irq)
24762 {
24763 disable_irq_nosync(irq);
24764 - io_apic_irqs &= ~(1<<irq);
24765 + io_apic_irqs &= ~(1UL<<irq);
24766 irq_set_chip_and_handler_name(irq, &i8259A_chip, handle_level_irq,
24767 i8259A_chip.name);
24768 enable_irq(irq);
24769 @@ -209,7 +209,7 @@ spurious_8259A_irq:
24770 "spurious 8259A interrupt: IRQ%d.\n", irq);
24771 spurious_irq_mask |= irqmask;
24772 }
24773 - atomic_inc(&irq_err_count);
24774 + atomic_inc_unchecked(&irq_err_count);
24775 /*
24776 * Theoretically we do not have to handle this IRQ,
24777 * but in Linux this does not cause problems and is
24778 @@ -332,14 +332,16 @@ static void init_8259A(int auto_eoi)
24779 /* (slave's support for AEOI in flat mode is to be investigated) */
24780 outb_pic(SLAVE_ICW4_DEFAULT, PIC_SLAVE_IMR);
24781
24782 + pax_open_kernel();
24783 if (auto_eoi)
24784 /*
24785 * In AEOI mode we just have to mask the interrupt
24786 * when acking.
24787 */
24788 - i8259A_chip.irq_mask_ack = disable_8259A_irq;
24789 + *(void **)&i8259A_chip.irq_mask_ack = disable_8259A_irq;
24790 else
24791 - i8259A_chip.irq_mask_ack = mask_and_ack_8259A;
24792 + *(void **)&i8259A_chip.irq_mask_ack = mask_and_ack_8259A;
24793 + pax_close_kernel();
24794
24795 udelay(100); /* wait for 8259A to initialize */
24796
24797 diff --git a/arch/x86/kernel/io_delay.c b/arch/x86/kernel/io_delay.c
24798 index a979b5b..1d6db75 100644
24799 --- a/arch/x86/kernel/io_delay.c
24800 +++ b/arch/x86/kernel/io_delay.c
24801 @@ -58,7 +58,7 @@ static int __init dmi_io_delay_0xed_port(const struct dmi_system_id *id)
24802 * Quirk table for systems that misbehave (lock up, etc.) if port
24803 * 0x80 is used:
24804 */
24805 -static struct dmi_system_id __initdata io_delay_0xed_port_dmi_table[] = {
24806 +static const struct dmi_system_id __initconst io_delay_0xed_port_dmi_table[] = {
24807 {
24808 .callback = dmi_io_delay_0xed_port,
24809 .ident = "Compaq Presario V6000",
24810 diff --git a/arch/x86/kernel/ioport.c b/arch/x86/kernel/ioport.c
24811 index 4ddaf66..49d5c18 100644
24812 --- a/arch/x86/kernel/ioport.c
24813 +++ b/arch/x86/kernel/ioport.c
24814 @@ -6,6 +6,7 @@
24815 #include <linux/sched.h>
24816 #include <linux/kernel.h>
24817 #include <linux/capability.h>
24818 +#include <linux/security.h>
24819 #include <linux/errno.h>
24820 #include <linux/types.h>
24821 #include <linux/ioport.h>
24822 @@ -30,6 +31,12 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
24823 return -EINVAL;
24824 if (turn_on && !capable(CAP_SYS_RAWIO))
24825 return -EPERM;
24826 +#ifdef CONFIG_GRKERNSEC_IO
24827 + if (turn_on && grsec_disable_privio) {
24828 + gr_handle_ioperm();
24829 + return -ENODEV;
24830 + }
24831 +#endif
24832
24833 /*
24834 * If it's the first ioperm() call in this thread's lifetime, set the
24835 @@ -54,7 +61,7 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
24836 * because the ->io_bitmap_max value must match the bitmap
24837 * contents:
24838 */
24839 - tss = &per_cpu(init_tss, get_cpu());
24840 + tss = init_tss + get_cpu();
24841
24842 if (turn_on)
24843 bitmap_clear(t->io_bitmap_ptr, from, num);
24844 @@ -105,6 +112,12 @@ SYSCALL_DEFINE1(iopl, unsigned int, level)
24845 if (level > old) {
24846 if (!capable(CAP_SYS_RAWIO))
24847 return -EPERM;
24848 +#ifdef CONFIG_GRKERNSEC_IO
24849 + if (grsec_disable_privio) {
24850 + gr_handle_iopl();
24851 + return -ENODEV;
24852 + }
24853 +#endif
24854 }
24855 regs->flags = (regs->flags & ~X86_EFLAGS_IOPL) | (level << 12);
24856 t->iopl = level << 12;
24857 diff --git a/arch/x86/kernel/irq.c b/arch/x86/kernel/irq.c
24858 index 22d0687..e07b2a5 100644
24859 --- a/arch/x86/kernel/irq.c
24860 +++ b/arch/x86/kernel/irq.c
24861 @@ -21,7 +21,7 @@
24862 #define CREATE_TRACE_POINTS
24863 #include <asm/trace/irq_vectors.h>
24864
24865 -atomic_t irq_err_count;
24866 +atomic_unchecked_t irq_err_count;
24867
24868 /* Function pointer for generic interrupt vector handling */
24869 void (*x86_platform_ipi_callback)(void) = NULL;
24870 @@ -125,9 +125,9 @@ int arch_show_interrupts(struct seq_file *p, int prec)
24871 seq_printf(p, "%10u ", per_cpu(mce_poll_count, j));
24872 seq_printf(p, " Machine check polls\n");
24873 #endif
24874 - seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read(&irq_err_count));
24875 + seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read_unchecked(&irq_err_count));
24876 #if defined(CONFIG_X86_IO_APIC)
24877 - seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read(&irq_mis_count));
24878 + seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read_unchecked(&irq_mis_count));
24879 #endif
24880 return 0;
24881 }
24882 @@ -167,7 +167,7 @@ u64 arch_irq_stat_cpu(unsigned int cpu)
24883
24884 u64 arch_irq_stat(void)
24885 {
24886 - u64 sum = atomic_read(&irq_err_count);
24887 + u64 sum = atomic_read_unchecked(&irq_err_count);
24888 return sum;
24889 }
24890
24891 diff --git a/arch/x86/kernel/irq_32.c b/arch/x86/kernel/irq_32.c
24892 index d7fcbed..1f747f7 100644
24893 --- a/arch/x86/kernel/irq_32.c
24894 +++ b/arch/x86/kernel/irq_32.c
24895 @@ -39,7 +39,7 @@ static int check_stack_overflow(void)
24896 __asm__ __volatile__("andl %%esp,%0" :
24897 "=r" (sp) : "0" (THREAD_SIZE - 1));
24898
24899 - return sp < (sizeof(struct thread_info) + STACK_WARN);
24900 + return sp < STACK_WARN;
24901 }
24902
24903 static void print_stack_overflow(void)
24904 @@ -59,8 +59,8 @@ static inline void print_stack_overflow(void) { }
24905 * per-CPU IRQ handling contexts (thread information and stack)
24906 */
24907 union irq_ctx {
24908 - struct thread_info tinfo;
24909 - u32 stack[THREAD_SIZE/sizeof(u32)];
24910 + unsigned long previous_esp;
24911 + u32 stack[THREAD_SIZE/sizeof(u32)];
24912 } __attribute__((aligned(THREAD_SIZE)));
24913
24914 static DEFINE_PER_CPU(union irq_ctx *, hardirq_ctx);
24915 @@ -80,10 +80,9 @@ static void call_on_stack(void *func, void *stack)
24916 static inline int
24917 execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
24918 {
24919 - union irq_ctx *curctx, *irqctx;
24920 + union irq_ctx *irqctx;
24921 u32 *isp, arg1, arg2;
24922
24923 - curctx = (union irq_ctx *) current_thread_info();
24924 irqctx = __this_cpu_read(hardirq_ctx);
24925
24926 /*
24927 @@ -92,13 +91,16 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
24928 * handler) we can't do that and just have to keep using the
24929 * current stack (which is the irq stack already after all)
24930 */
24931 - if (unlikely(curctx == irqctx))
24932 + if (unlikely((void *)current_stack_pointer - (void *)irqctx < THREAD_SIZE))
24933 return 0;
24934
24935 /* build the stack frame on the IRQ stack */
24936 - isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
24937 - irqctx->tinfo.task = curctx->tinfo.task;
24938 - irqctx->tinfo.previous_esp = current_stack_pointer;
24939 + isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
24940 + irqctx->previous_esp = current_stack_pointer;
24941 +
24942 +#ifdef CONFIG_PAX_MEMORY_UDEREF
24943 + __set_fs(MAKE_MM_SEG(0));
24944 +#endif
24945
24946 if (unlikely(overflow))
24947 call_on_stack(print_stack_overflow, isp);
24948 @@ -110,6 +112,11 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
24949 : "0" (irq), "1" (desc), "2" (isp),
24950 "D" (desc->handle_irq)
24951 : "memory", "cc", "ecx");
24952 +
24953 +#ifdef CONFIG_PAX_MEMORY_UDEREF
24954 + __set_fs(current_thread_info()->addr_limit);
24955 +#endif
24956 +
24957 return 1;
24958 }
24959
24960 @@ -118,48 +125,34 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
24961 */
24962 void irq_ctx_init(int cpu)
24963 {
24964 - union irq_ctx *irqctx;
24965 -
24966 if (per_cpu(hardirq_ctx, cpu))
24967 return;
24968
24969 - irqctx = page_address(alloc_pages_node(cpu_to_node(cpu),
24970 - THREADINFO_GFP,
24971 - THREAD_SIZE_ORDER));
24972 - memset(&irqctx->tinfo, 0, sizeof(struct thread_info));
24973 - irqctx->tinfo.cpu = cpu;
24974 - irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
24975 -
24976 - per_cpu(hardirq_ctx, cpu) = irqctx;
24977 -
24978 - irqctx = page_address(alloc_pages_node(cpu_to_node(cpu),
24979 - THREADINFO_GFP,
24980 - THREAD_SIZE_ORDER));
24981 - memset(&irqctx->tinfo, 0, sizeof(struct thread_info));
24982 - irqctx->tinfo.cpu = cpu;
24983 - irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
24984 -
24985 - per_cpu(softirq_ctx, cpu) = irqctx;
24986 -
24987 - printk(KERN_DEBUG "CPU %u irqstacks, hard=%p soft=%p\n",
24988 - cpu, per_cpu(hardirq_ctx, cpu), per_cpu(softirq_ctx, cpu));
24989 + per_cpu(hardirq_ctx, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREADINFO_GFP, THREAD_SIZE_ORDER));
24990 + per_cpu(softirq_ctx, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREADINFO_GFP, THREAD_SIZE_ORDER));
24991 }
24992
24993 void do_softirq_own_stack(void)
24994 {
24995 - struct thread_info *curctx;
24996 union irq_ctx *irqctx;
24997 u32 *isp;
24998
24999 - curctx = current_thread_info();
25000 irqctx = __this_cpu_read(softirq_ctx);
25001 - irqctx->tinfo.task = curctx->task;
25002 - irqctx->tinfo.previous_esp = current_stack_pointer;
25003 + irqctx->previous_esp = current_stack_pointer;
25004
25005 /* build the stack frame on the softirq stack */
25006 - isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
25007 + isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
25008 +
25009 +#ifdef CONFIG_PAX_MEMORY_UDEREF
25010 + __set_fs(MAKE_MM_SEG(0));
25011 +#endif
25012
25013 call_on_stack(__do_softirq, isp);
25014 +
25015 +#ifdef CONFIG_PAX_MEMORY_UDEREF
25016 + __set_fs(current_thread_info()->addr_limit);
25017 +#endif
25018 +
25019 }
25020
25021 bool handle_irq(unsigned irq, struct pt_regs *regs)
25022 @@ -173,7 +166,7 @@ bool handle_irq(unsigned irq, struct pt_regs *regs)
25023 if (unlikely(!desc))
25024 return false;
25025
25026 - if (user_mode_vm(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
25027 + if (user_mode(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
25028 if (unlikely(overflow))
25029 print_stack_overflow();
25030 desc->handle_irq(irq, desc);
25031 diff --git a/arch/x86/kernel/irq_64.c b/arch/x86/kernel/irq_64.c
25032 index 4d1c746..232961d 100644
25033 --- a/arch/x86/kernel/irq_64.c
25034 +++ b/arch/x86/kernel/irq_64.c
25035 @@ -44,7 +44,7 @@ static inline void stack_overflow_check(struct pt_regs *regs)
25036 u64 estack_top, estack_bottom;
25037 u64 curbase = (u64)task_stack_page(current);
25038
25039 - if (user_mode_vm(regs))
25040 + if (user_mode(regs))
25041 return;
25042
25043 if (regs->sp >= curbase + sizeof(struct thread_info) +
25044 diff --git a/arch/x86/kernel/jump_label.c b/arch/x86/kernel/jump_label.c
25045 index 26d5a55..a01160a 100644
25046 --- a/arch/x86/kernel/jump_label.c
25047 +++ b/arch/x86/kernel/jump_label.c
25048 @@ -51,7 +51,7 @@ static void __jump_label_transform(struct jump_entry *entry,
25049 * Jump label is enabled for the first time.
25050 * So we expect a default_nop...
25051 */
25052 - if (unlikely(memcmp((void *)entry->code, default_nop, 5)
25053 + if (unlikely(memcmp((void *)ktla_ktva(entry->code), default_nop, 5)
25054 != 0))
25055 bug_at((void *)entry->code, __LINE__);
25056 } else {
25057 @@ -59,7 +59,7 @@ static void __jump_label_transform(struct jump_entry *entry,
25058 * ...otherwise expect an ideal_nop. Otherwise
25059 * something went horribly wrong.
25060 */
25061 - if (unlikely(memcmp((void *)entry->code, ideal_nop, 5)
25062 + if (unlikely(memcmp((void *)ktla_ktva(entry->code), ideal_nop, 5)
25063 != 0))
25064 bug_at((void *)entry->code, __LINE__);
25065 }
25066 @@ -75,13 +75,13 @@ static void __jump_label_transform(struct jump_entry *entry,
25067 * are converting the default nop to the ideal nop.
25068 */
25069 if (init) {
25070 - if (unlikely(memcmp((void *)entry->code, default_nop, 5) != 0))
25071 + if (unlikely(memcmp((void *)ktla_ktva(entry->code), default_nop, 5) != 0))
25072 bug_at((void *)entry->code, __LINE__);
25073 } else {
25074 code.jump = 0xe9;
25075 code.offset = entry->target -
25076 (entry->code + JUMP_LABEL_NOP_SIZE);
25077 - if (unlikely(memcmp((void *)entry->code, &code, 5) != 0))
25078 + if (unlikely(memcmp((void *)ktla_ktva(entry->code), &code, 5) != 0))
25079 bug_at((void *)entry->code, __LINE__);
25080 }
25081 memcpy(&code, ideal_nops[NOP_ATOMIC5], JUMP_LABEL_NOP_SIZE);
25082 diff --git a/arch/x86/kernel/kgdb.c b/arch/x86/kernel/kgdb.c
25083 index 836f832..a8bda67 100644
25084 --- a/arch/x86/kernel/kgdb.c
25085 +++ b/arch/x86/kernel/kgdb.c
25086 @@ -127,11 +127,11 @@ char *dbg_get_reg(int regno, void *mem, struct pt_regs *regs)
25087 #ifdef CONFIG_X86_32
25088 switch (regno) {
25089 case GDB_SS:
25090 - if (!user_mode_vm(regs))
25091 + if (!user_mode(regs))
25092 *(unsigned long *)mem = __KERNEL_DS;
25093 break;
25094 case GDB_SP:
25095 - if (!user_mode_vm(regs))
25096 + if (!user_mode(regs))
25097 *(unsigned long *)mem = kernel_stack_pointer(regs);
25098 break;
25099 case GDB_GS:
25100 @@ -229,7 +229,10 @@ static void kgdb_correct_hw_break(void)
25101 bp->attr.bp_addr = breakinfo[breakno].addr;
25102 bp->attr.bp_len = breakinfo[breakno].len;
25103 bp->attr.bp_type = breakinfo[breakno].type;
25104 - info->address = breakinfo[breakno].addr;
25105 + if (breakinfo[breakno].type == X86_BREAKPOINT_EXECUTE)
25106 + info->address = ktla_ktva(breakinfo[breakno].addr);
25107 + else
25108 + info->address = breakinfo[breakno].addr;
25109 info->len = breakinfo[breakno].len;
25110 info->type = breakinfo[breakno].type;
25111 val = arch_install_hw_breakpoint(bp);
25112 @@ -476,12 +479,12 @@ int kgdb_arch_handle_exception(int e_vector, int signo, int err_code,
25113 case 'k':
25114 /* clear the trace bit */
25115 linux_regs->flags &= ~X86_EFLAGS_TF;
25116 - atomic_set(&kgdb_cpu_doing_single_step, -1);
25117 + atomic_set_unchecked(&kgdb_cpu_doing_single_step, -1);
25118
25119 /* set the trace bit if we're stepping */
25120 if (remcomInBuffer[0] == 's') {
25121 linux_regs->flags |= X86_EFLAGS_TF;
25122 - atomic_set(&kgdb_cpu_doing_single_step,
25123 + atomic_set_unchecked(&kgdb_cpu_doing_single_step,
25124 raw_smp_processor_id());
25125 }
25126
25127 @@ -546,7 +549,7 @@ static int __kgdb_notify(struct die_args *args, unsigned long cmd)
25128
25129 switch (cmd) {
25130 case DIE_DEBUG:
25131 - if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
25132 + if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
25133 if (user_mode(regs))
25134 return single_step_cont(regs, args);
25135 break;
25136 @@ -751,11 +754,11 @@ int kgdb_arch_set_breakpoint(struct kgdb_bkpt *bpt)
25137 #endif /* CONFIG_DEBUG_RODATA */
25138
25139 bpt->type = BP_BREAKPOINT;
25140 - err = probe_kernel_read(bpt->saved_instr, (char *)bpt->bpt_addr,
25141 + err = probe_kernel_read(bpt->saved_instr, ktla_ktva((char *)bpt->bpt_addr),
25142 BREAK_INSTR_SIZE);
25143 if (err)
25144 return err;
25145 - err = probe_kernel_write((char *)bpt->bpt_addr,
25146 + err = probe_kernel_write(ktla_ktva((char *)bpt->bpt_addr),
25147 arch_kgdb_ops.gdb_bpt_instr, BREAK_INSTR_SIZE);
25148 #ifdef CONFIG_DEBUG_RODATA
25149 if (!err)
25150 @@ -768,7 +771,7 @@ int kgdb_arch_set_breakpoint(struct kgdb_bkpt *bpt)
25151 return -EBUSY;
25152 text_poke((void *)bpt->bpt_addr, arch_kgdb_ops.gdb_bpt_instr,
25153 BREAK_INSTR_SIZE);
25154 - err = probe_kernel_read(opc, (char *)bpt->bpt_addr, BREAK_INSTR_SIZE);
25155 + err = probe_kernel_read(opc, ktla_ktva((char *)bpt->bpt_addr), BREAK_INSTR_SIZE);
25156 if (err)
25157 return err;
25158 if (memcmp(opc, arch_kgdb_ops.gdb_bpt_instr, BREAK_INSTR_SIZE))
25159 @@ -793,13 +796,13 @@ int kgdb_arch_remove_breakpoint(struct kgdb_bkpt *bpt)
25160 if (mutex_is_locked(&text_mutex))
25161 goto knl_write;
25162 text_poke((void *)bpt->bpt_addr, bpt->saved_instr, BREAK_INSTR_SIZE);
25163 - err = probe_kernel_read(opc, (char *)bpt->bpt_addr, BREAK_INSTR_SIZE);
25164 + err = probe_kernel_read(opc, ktla_ktva((char *)bpt->bpt_addr), BREAK_INSTR_SIZE);
25165 if (err || memcmp(opc, bpt->saved_instr, BREAK_INSTR_SIZE))
25166 goto knl_write;
25167 return err;
25168 knl_write:
25169 #endif /* CONFIG_DEBUG_RODATA */
25170 - return probe_kernel_write((char *)bpt->bpt_addr,
25171 + return probe_kernel_write(ktla_ktva((char *)bpt->bpt_addr),
25172 (char *)bpt->saved_instr, BREAK_INSTR_SIZE);
25173 }
25174
25175 diff --git a/arch/x86/kernel/kprobes/core.c b/arch/x86/kernel/kprobes/core.c
25176 index 79a3f96..6ba030a 100644
25177 --- a/arch/x86/kernel/kprobes/core.c
25178 +++ b/arch/x86/kernel/kprobes/core.c
25179 @@ -119,9 +119,12 @@ static void __kprobes __synthesize_relative_insn(void *from, void *to, u8 op)
25180 s32 raddr;
25181 } __packed *insn;
25182
25183 - insn = (struct __arch_relative_insn *)from;
25184 + insn = (struct __arch_relative_insn *)ktla_ktva(from);
25185 +
25186 + pax_open_kernel();
25187 insn->raddr = (s32)((long)(to) - ((long)(from) + 5));
25188 insn->op = op;
25189 + pax_close_kernel();
25190 }
25191
25192 /* Insert a jump instruction at address 'from', which jumps to address 'to'.*/
25193 @@ -164,7 +167,7 @@ int __kprobes can_boost(kprobe_opcode_t *opcodes)
25194 kprobe_opcode_t opcode;
25195 kprobe_opcode_t *orig_opcodes = opcodes;
25196
25197 - if (search_exception_tables((unsigned long)opcodes))
25198 + if (search_exception_tables(ktva_ktla((unsigned long)opcodes)))
25199 return 0; /* Page fault may occur on this address. */
25200
25201 retry:
25202 @@ -238,9 +241,9 @@ __recover_probed_insn(kprobe_opcode_t *buf, unsigned long addr)
25203 * for the first byte, we can recover the original instruction
25204 * from it and kp->opcode.
25205 */
25206 - memcpy(buf, kp->addr, MAX_INSN_SIZE * sizeof(kprobe_opcode_t));
25207 + memcpy(buf, ktla_ktva(kp->addr), MAX_INSN_SIZE * sizeof(kprobe_opcode_t));
25208 buf[0] = kp->opcode;
25209 - return (unsigned long)buf;
25210 + return ktva_ktla((unsigned long)buf);
25211 }
25212
25213 /*
25214 @@ -332,7 +335,9 @@ int __kprobes __copy_instruction(u8 *dest, u8 *src)
25215 /* Another subsystem puts a breakpoint, failed to recover */
25216 if (insn.opcode.bytes[0] == BREAKPOINT_INSTRUCTION)
25217 return 0;
25218 + pax_open_kernel();
25219 memcpy(dest, insn.kaddr, insn.length);
25220 + pax_close_kernel();
25221
25222 #ifdef CONFIG_X86_64
25223 if (insn_rip_relative(&insn)) {
25224 @@ -359,7 +364,9 @@ int __kprobes __copy_instruction(u8 *dest, u8 *src)
25225 return 0;
25226 }
25227 disp = (u8 *) dest + insn_offset_displacement(&insn);
25228 + pax_open_kernel();
25229 *(s32 *) disp = (s32) newdisp;
25230 + pax_close_kernel();
25231 }
25232 #endif
25233 return insn.length;
25234 @@ -498,7 +505,7 @@ setup_singlestep(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *k
25235 * nor set current_kprobe, because it doesn't use single
25236 * stepping.
25237 */
25238 - regs->ip = (unsigned long)p->ainsn.insn;
25239 + regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
25240 preempt_enable_no_resched();
25241 return;
25242 }
25243 @@ -515,9 +522,9 @@ setup_singlestep(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *k
25244 regs->flags &= ~X86_EFLAGS_IF;
25245 /* single step inline if the instruction is an int3 */
25246 if (p->opcode == BREAKPOINT_INSTRUCTION)
25247 - regs->ip = (unsigned long)p->addr;
25248 + regs->ip = ktla_ktva((unsigned long)p->addr);
25249 else
25250 - regs->ip = (unsigned long)p->ainsn.insn;
25251 + regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
25252 }
25253
25254 /*
25255 @@ -596,7 +603,7 @@ static int __kprobes kprobe_handler(struct pt_regs *regs)
25256 setup_singlestep(p, regs, kcb, 0);
25257 return 1;
25258 }
25259 - } else if (*addr != BREAKPOINT_INSTRUCTION) {
25260 + } else if (*(kprobe_opcode_t *)ktla_ktva((unsigned long)addr) != BREAKPOINT_INSTRUCTION) {
25261 /*
25262 * The breakpoint instruction was removed right
25263 * after we hit it. Another cpu has removed
25264 @@ -642,6 +649,9 @@ static void __used __kprobes kretprobe_trampoline_holder(void)
25265 " movq %rax, 152(%rsp)\n"
25266 RESTORE_REGS_STRING
25267 " popfq\n"
25268 +#ifdef KERNEXEC_PLUGIN
25269 + " btsq $63,(%rsp)\n"
25270 +#endif
25271 #else
25272 " pushf\n"
25273 SAVE_REGS_STRING
25274 @@ -779,7 +789,7 @@ static void __kprobes
25275 resume_execution(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *kcb)
25276 {
25277 unsigned long *tos = stack_addr(regs);
25278 - unsigned long copy_ip = (unsigned long)p->ainsn.insn;
25279 + unsigned long copy_ip = ktva_ktla((unsigned long)p->ainsn.insn);
25280 unsigned long orig_ip = (unsigned long)p->addr;
25281 kprobe_opcode_t *insn = p->ainsn.insn;
25282
25283 @@ -961,7 +971,7 @@ kprobe_exceptions_notify(struct notifier_block *self, unsigned long val, void *d
25284 struct die_args *args = data;
25285 int ret = NOTIFY_DONE;
25286
25287 - if (args->regs && user_mode_vm(args->regs))
25288 + if (args->regs && user_mode(args->regs))
25289 return ret;
25290
25291 switch (val) {
25292 diff --git a/arch/x86/kernel/kprobes/opt.c b/arch/x86/kernel/kprobes/opt.c
25293 index 898160b..758cde8 100644
25294 --- a/arch/x86/kernel/kprobes/opt.c
25295 +++ b/arch/x86/kernel/kprobes/opt.c
25296 @@ -79,6 +79,7 @@ found:
25297 /* Insert a move instruction which sets a pointer to eax/rdi (1st arg). */
25298 static void __kprobes synthesize_set_arg1(kprobe_opcode_t *addr, unsigned long val)
25299 {
25300 + pax_open_kernel();
25301 #ifdef CONFIG_X86_64
25302 *addr++ = 0x48;
25303 *addr++ = 0xbf;
25304 @@ -86,6 +87,7 @@ static void __kprobes synthesize_set_arg1(kprobe_opcode_t *addr, unsigned long v
25305 *addr++ = 0xb8;
25306 #endif
25307 *(unsigned long *)addr = val;
25308 + pax_close_kernel();
25309 }
25310
25311 asm (
25312 @@ -335,7 +337,7 @@ int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
25313 * Verify if the address gap is in 2GB range, because this uses
25314 * a relative jump.
25315 */
25316 - rel = (long)op->optinsn.insn - (long)op->kp.addr + RELATIVEJUMP_SIZE;
25317 + rel = (long)op->optinsn.insn - ktla_ktva((long)op->kp.addr) + RELATIVEJUMP_SIZE;
25318 if (abs(rel) > 0x7fffffff)
25319 return -ERANGE;
25320
25321 @@ -350,16 +352,18 @@ int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
25322 op->optinsn.size = ret;
25323
25324 /* Copy arch-dep-instance from template */
25325 - memcpy(buf, &optprobe_template_entry, TMPL_END_IDX);
25326 + pax_open_kernel();
25327 + memcpy(buf, ktla_ktva(&optprobe_template_entry), TMPL_END_IDX);
25328 + pax_close_kernel();
25329
25330 /* Set probe information */
25331 synthesize_set_arg1(buf + TMPL_MOVE_IDX, (unsigned long)op);
25332
25333 /* Set probe function call */
25334 - synthesize_relcall(buf + TMPL_CALL_IDX, optimized_callback);
25335 + synthesize_relcall(ktva_ktla(buf) + TMPL_CALL_IDX, optimized_callback);
25336
25337 /* Set returning jmp instruction at the tail of out-of-line buffer */
25338 - synthesize_reljump(buf + TMPL_END_IDX + op->optinsn.size,
25339 + synthesize_reljump(ktva_ktla(buf) + TMPL_END_IDX + op->optinsn.size,
25340 (u8 *)op->kp.addr + op->optinsn.size);
25341
25342 flush_icache_range((unsigned long) buf,
25343 @@ -384,7 +388,7 @@ void __kprobes arch_optimize_kprobes(struct list_head *oplist)
25344 WARN_ON(kprobe_disabled(&op->kp));
25345
25346 /* Backup instructions which will be replaced by jump address */
25347 - memcpy(op->optinsn.copied_insn, op->kp.addr + INT3_SIZE,
25348 + memcpy(op->optinsn.copied_insn, ktla_ktva(op->kp.addr) + INT3_SIZE,
25349 RELATIVE_ADDR_SIZE);
25350
25351 insn_buf[0] = RELATIVEJUMP_OPCODE;
25352 @@ -433,7 +437,7 @@ setup_detour_execution(struct kprobe *p, struct pt_regs *regs, int reenter)
25353 /* This kprobe is really able to run optimized path. */
25354 op = container_of(p, struct optimized_kprobe, kp);
25355 /* Detour through copied instructions */
25356 - regs->ip = (unsigned long)op->optinsn.insn + TMPL_END_IDX;
25357 + regs->ip = ktva_ktla((unsigned long)op->optinsn.insn) + TMPL_END_IDX;
25358 if (!reenter)
25359 reset_current_kprobe();
25360 preempt_enable_no_resched();
25361 diff --git a/arch/x86/kernel/ldt.c b/arch/x86/kernel/ldt.c
25362 index ebc9873..37b8776 100644
25363 --- a/arch/x86/kernel/ldt.c
25364 +++ b/arch/x86/kernel/ldt.c
25365 @@ -66,13 +66,13 @@ static int alloc_ldt(mm_context_t *pc, int mincount, int reload)
25366 if (reload) {
25367 #ifdef CONFIG_SMP
25368 preempt_disable();
25369 - load_LDT(pc);
25370 + load_LDT_nolock(pc);
25371 if (!cpumask_equal(mm_cpumask(current->mm),
25372 cpumask_of(smp_processor_id())))
25373 smp_call_function(flush_ldt, current->mm, 1);
25374 preempt_enable();
25375 #else
25376 - load_LDT(pc);
25377 + load_LDT_nolock(pc);
25378 #endif
25379 }
25380 if (oldsize) {
25381 @@ -94,7 +94,7 @@ static inline int copy_ldt(mm_context_t *new, mm_context_t *old)
25382 return err;
25383
25384 for (i = 0; i < old->size; i++)
25385 - write_ldt_entry(new->ldt, i, old->ldt + i * LDT_ENTRY_SIZE);
25386 + write_ldt_entry(new->ldt, i, old->ldt + i);
25387 return 0;
25388 }
25389
25390 @@ -115,6 +115,24 @@ int init_new_context(struct task_struct *tsk, struct mm_struct *mm)
25391 retval = copy_ldt(&mm->context, &old_mm->context);
25392 mutex_unlock(&old_mm->context.lock);
25393 }
25394 +
25395 + if (tsk == current) {
25396 + mm->context.vdso = 0;
25397 +
25398 +#ifdef CONFIG_X86_32
25399 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
25400 + mm->context.user_cs_base = 0UL;
25401 + mm->context.user_cs_limit = ~0UL;
25402 +
25403 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
25404 + cpus_clear(mm->context.cpu_user_cs_mask);
25405 +#endif
25406 +
25407 +#endif
25408 +#endif
25409 +
25410 + }
25411 +
25412 return retval;
25413 }
25414
25415 @@ -229,6 +247,24 @@ static int write_ldt(void __user *ptr, unsigned long bytecount, int oldmode)
25416 }
25417 }
25418
25419 +#ifdef CONFIG_PAX_SEGMEXEC
25420 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (ldt_info.contents & MODIFY_LDT_CONTENTS_CODE)) {
25421 + error = -EINVAL;
25422 + goto out_unlock;
25423 + }
25424 +#endif
25425 +
25426 + /*
25427 + * On x86-64 we do not support 16-bit segments due to
25428 + * IRET leaking the high bits of the kernel stack address.
25429 + */
25430 +#ifdef CONFIG_X86_64
25431 + if (!ldt_info.seg_32bit) {
25432 + error = -EINVAL;
25433 + goto out_unlock;
25434 + }
25435 +#endif
25436 +
25437 fill_ldt(&ldt, &ldt_info);
25438 if (oldmode)
25439 ldt.avl = 0;
25440 diff --git a/arch/x86/kernel/machine_kexec_32.c b/arch/x86/kernel/machine_kexec_32.c
25441 index 5b19e4d..6476a76 100644
25442 --- a/arch/x86/kernel/machine_kexec_32.c
25443 +++ b/arch/x86/kernel/machine_kexec_32.c
25444 @@ -26,7 +26,7 @@
25445 #include <asm/cacheflush.h>
25446 #include <asm/debugreg.h>
25447
25448 -static void set_idt(void *newidt, __u16 limit)
25449 +static void set_idt(struct desc_struct *newidt, __u16 limit)
25450 {
25451 struct desc_ptr curidt;
25452
25453 @@ -38,7 +38,7 @@ static void set_idt(void *newidt, __u16 limit)
25454 }
25455
25456
25457 -static void set_gdt(void *newgdt, __u16 limit)
25458 +static void set_gdt(struct desc_struct *newgdt, __u16 limit)
25459 {
25460 struct desc_ptr curgdt;
25461
25462 @@ -216,7 +216,7 @@ void machine_kexec(struct kimage *image)
25463 }
25464
25465 control_page = page_address(image->control_code_page);
25466 - memcpy(control_page, relocate_kernel, KEXEC_CONTROL_CODE_MAX_SIZE);
25467 + memcpy(control_page, (void *)ktla_ktva((unsigned long)relocate_kernel), KEXEC_CONTROL_CODE_MAX_SIZE);
25468
25469 relocate_kernel_ptr = control_page;
25470 page_list[PA_CONTROL_PAGE] = __pa(control_page);
25471 diff --git a/arch/x86/kernel/microcode_core.c b/arch/x86/kernel/microcode_core.c
25472 index 15c9876..0a43909 100644
25473 --- a/arch/x86/kernel/microcode_core.c
25474 +++ b/arch/x86/kernel/microcode_core.c
25475 @@ -513,7 +513,7 @@ mc_cpu_callback(struct notifier_block *nb, unsigned long action, void *hcpu)
25476 return NOTIFY_OK;
25477 }
25478
25479 -static struct notifier_block __refdata mc_cpu_notifier = {
25480 +static struct notifier_block mc_cpu_notifier = {
25481 .notifier_call = mc_cpu_callback,
25482 };
25483
25484 diff --git a/arch/x86/kernel/microcode_intel.c b/arch/x86/kernel/microcode_intel.c
25485 index 5fb2ceb..3ae90bb 100644
25486 --- a/arch/x86/kernel/microcode_intel.c
25487 +++ b/arch/x86/kernel/microcode_intel.c
25488 @@ -293,13 +293,13 @@ static enum ucode_state request_microcode_fw(int cpu, struct device *device,
25489
25490 static int get_ucode_user(void *to, const void *from, size_t n)
25491 {
25492 - return copy_from_user(to, from, n);
25493 + return copy_from_user(to, (const void __force_user *)from, n);
25494 }
25495
25496 static enum ucode_state
25497 request_microcode_user(int cpu, const void __user *buf, size_t size)
25498 {
25499 - return generic_load_microcode(cpu, (void *)buf, size, &get_ucode_user);
25500 + return generic_load_microcode(cpu, (__force_kernel void *)buf, size, &get_ucode_user);
25501 }
25502
25503 static void microcode_fini_cpu(int cpu)
25504 diff --git a/arch/x86/kernel/module.c b/arch/x86/kernel/module.c
25505 index 18be189..4a9fe40 100644
25506 --- a/arch/x86/kernel/module.c
25507 +++ b/arch/x86/kernel/module.c
25508 @@ -43,15 +43,60 @@ do { \
25509 } while (0)
25510 #endif
25511
25512 -void *module_alloc(unsigned long size)
25513 +static inline void *__module_alloc(unsigned long size, pgprot_t prot)
25514 {
25515 - if (PAGE_ALIGN(size) > MODULES_LEN)
25516 + if (!size || PAGE_ALIGN(size) > MODULES_LEN)
25517 return NULL;
25518 return __vmalloc_node_range(size, 1, MODULES_VADDR, MODULES_END,
25519 - GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
25520 + GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, prot,
25521 NUMA_NO_NODE, __builtin_return_address(0));
25522 }
25523
25524 +void *module_alloc(unsigned long size)
25525 +{
25526 +
25527 +#ifdef CONFIG_PAX_KERNEXEC
25528 + return __module_alloc(size, PAGE_KERNEL);
25529 +#else
25530 + return __module_alloc(size, PAGE_KERNEL_EXEC);
25531 +#endif
25532 +
25533 +}
25534 +
25535 +#ifdef CONFIG_PAX_KERNEXEC
25536 +#ifdef CONFIG_X86_32
25537 +void *module_alloc_exec(unsigned long size)
25538 +{
25539 + struct vm_struct *area;
25540 +
25541 + if (size == 0)
25542 + return NULL;
25543 +
25544 + area = __get_vm_area(size, VM_ALLOC, (unsigned long)&MODULES_EXEC_VADDR, (unsigned long)&MODULES_EXEC_END);
25545 + return area ? area->addr : NULL;
25546 +}
25547 +EXPORT_SYMBOL(module_alloc_exec);
25548 +
25549 +void module_free_exec(struct module *mod, void *module_region)
25550 +{
25551 + vunmap(module_region);
25552 +}
25553 +EXPORT_SYMBOL(module_free_exec);
25554 +#else
25555 +void module_free_exec(struct module *mod, void *module_region)
25556 +{
25557 + module_free(mod, module_region);
25558 +}
25559 +EXPORT_SYMBOL(module_free_exec);
25560 +
25561 +void *module_alloc_exec(unsigned long size)
25562 +{
25563 + return __module_alloc(size, PAGE_KERNEL_RX);
25564 +}
25565 +EXPORT_SYMBOL(module_alloc_exec);
25566 +#endif
25567 +#endif
25568 +
25569 #ifdef CONFIG_X86_32
25570 int apply_relocate(Elf32_Shdr *sechdrs,
25571 const char *strtab,
25572 @@ -62,14 +107,16 @@ int apply_relocate(Elf32_Shdr *sechdrs,
25573 unsigned int i;
25574 Elf32_Rel *rel = (void *)sechdrs[relsec].sh_addr;
25575 Elf32_Sym *sym;
25576 - uint32_t *location;
25577 + uint32_t *plocation, location;
25578
25579 DEBUGP("Applying relocate section %u to %u\n",
25580 relsec, sechdrs[relsec].sh_info);
25581 for (i = 0; i < sechdrs[relsec].sh_size / sizeof(*rel); i++) {
25582 /* This is where to make the change */
25583 - location = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr
25584 - + rel[i].r_offset;
25585 + plocation = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr + rel[i].r_offset;
25586 + location = (uint32_t)plocation;
25587 + if (sechdrs[sechdrs[relsec].sh_info].sh_flags & SHF_EXECINSTR)
25588 + plocation = ktla_ktva((void *)plocation);
25589 /* This is the symbol it is referring to. Note that all
25590 undefined symbols have been resolved. */
25591 sym = (Elf32_Sym *)sechdrs[symindex].sh_addr
25592 @@ -78,11 +125,15 @@ int apply_relocate(Elf32_Shdr *sechdrs,
25593 switch (ELF32_R_TYPE(rel[i].r_info)) {
25594 case R_386_32:
25595 /* We add the value into the location given */
25596 - *location += sym->st_value;
25597 + pax_open_kernel();
25598 + *plocation += sym->st_value;
25599 + pax_close_kernel();
25600 break;
25601 case R_386_PC32:
25602 /* Add the value, subtract its position */
25603 - *location += sym->st_value - (uint32_t)location;
25604 + pax_open_kernel();
25605 + *plocation += sym->st_value - location;
25606 + pax_close_kernel();
25607 break;
25608 default:
25609 pr_err("%s: Unknown relocation: %u\n",
25610 @@ -127,21 +178,30 @@ int apply_relocate_add(Elf64_Shdr *sechdrs,
25611 case R_X86_64_NONE:
25612 break;
25613 case R_X86_64_64:
25614 + pax_open_kernel();
25615 *(u64 *)loc = val;
25616 + pax_close_kernel();
25617 break;
25618 case R_X86_64_32:
25619 + pax_open_kernel();
25620 *(u32 *)loc = val;
25621 + pax_close_kernel();
25622 if (val != *(u32 *)loc)
25623 goto overflow;
25624 break;
25625 case R_X86_64_32S:
25626 + pax_open_kernel();
25627 *(s32 *)loc = val;
25628 + pax_close_kernel();
25629 if ((s64)val != *(s32 *)loc)
25630 goto overflow;
25631 break;
25632 case R_X86_64_PC32:
25633 val -= (u64)loc;
25634 + pax_open_kernel();
25635 *(u32 *)loc = val;
25636 + pax_close_kernel();
25637 +
25638 #if 0
25639 if ((s64)val != *(s32 *)loc)
25640 goto overflow;
25641 diff --git a/arch/x86/kernel/msr.c b/arch/x86/kernel/msr.c
25642 index 05266b5..3432443 100644
25643 --- a/arch/x86/kernel/msr.c
25644 +++ b/arch/x86/kernel/msr.c
25645 @@ -37,6 +37,7 @@
25646 #include <linux/notifier.h>
25647 #include <linux/uaccess.h>
25648 #include <linux/gfp.h>
25649 +#include <linux/grsecurity.h>
25650
25651 #include <asm/processor.h>
25652 #include <asm/msr.h>
25653 @@ -103,6 +104,11 @@ static ssize_t msr_write(struct file *file, const char __user *buf,
25654 int err = 0;
25655 ssize_t bytes = 0;
25656
25657 +#ifdef CONFIG_GRKERNSEC_KMEM
25658 + gr_handle_msr_write();
25659 + return -EPERM;
25660 +#endif
25661 +
25662 if (count % 8)
25663 return -EINVAL; /* Invalid chunk size */
25664
25665 @@ -150,6 +156,10 @@ static long msr_ioctl(struct file *file, unsigned int ioc, unsigned long arg)
25666 err = -EBADF;
25667 break;
25668 }
25669 +#ifdef CONFIG_GRKERNSEC_KMEM
25670 + gr_handle_msr_write();
25671 + return -EPERM;
25672 +#endif
25673 if (copy_from_user(&regs, uregs, sizeof regs)) {
25674 err = -EFAULT;
25675 break;
25676 @@ -233,7 +243,7 @@ static int msr_class_cpu_callback(struct notifier_block *nfb,
25677 return notifier_from_errno(err);
25678 }
25679
25680 -static struct notifier_block __refdata msr_class_cpu_notifier = {
25681 +static struct notifier_block msr_class_cpu_notifier = {
25682 .notifier_call = msr_class_cpu_callback,
25683 };
25684
25685 diff --git a/arch/x86/kernel/nmi.c b/arch/x86/kernel/nmi.c
25686 index 6fcb49c..5b3f4ff 100644
25687 --- a/arch/x86/kernel/nmi.c
25688 +++ b/arch/x86/kernel/nmi.c
25689 @@ -138,7 +138,7 @@ static int __kprobes nmi_handle(unsigned int type, struct pt_regs *regs, bool b2
25690 return handled;
25691 }
25692
25693 -int __register_nmi_handler(unsigned int type, struct nmiaction *action)
25694 +int __register_nmi_handler(unsigned int type, const struct nmiaction *action)
25695 {
25696 struct nmi_desc *desc = nmi_to_desc(type);
25697 unsigned long flags;
25698 @@ -162,9 +162,9 @@ int __register_nmi_handler(unsigned int type, struct nmiaction *action)
25699 * event confuses some handlers (kdump uses this flag)
25700 */
25701 if (action->flags & NMI_FLAG_FIRST)
25702 - list_add_rcu(&action->list, &desc->head);
25703 + pax_list_add_rcu((struct list_head *)&action->list, &desc->head);
25704 else
25705 - list_add_tail_rcu(&action->list, &desc->head);
25706 + pax_list_add_tail_rcu((struct list_head *)&action->list, &desc->head);
25707
25708 spin_unlock_irqrestore(&desc->lock, flags);
25709 return 0;
25710 @@ -187,7 +187,7 @@ void unregister_nmi_handler(unsigned int type, const char *name)
25711 if (!strcmp(n->name, name)) {
25712 WARN(in_nmi(),
25713 "Trying to free NMI (%s) from NMI context!\n", n->name);
25714 - list_del_rcu(&n->list);
25715 + pax_list_del_rcu((struct list_head *)&n->list);
25716 break;
25717 }
25718 }
25719 @@ -512,6 +512,17 @@ static inline void nmi_nesting_postprocess(void)
25720 dotraplinkage notrace __kprobes void
25721 do_nmi(struct pt_regs *regs, long error_code)
25722 {
25723 +
25724 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
25725 + if (!user_mode(regs)) {
25726 + unsigned long cs = regs->cs & 0xFFFF;
25727 + unsigned long ip = ktva_ktla(regs->ip);
25728 +
25729 + if ((cs == __KERNEL_CS || cs == __KERNEXEC_KERNEL_CS) && ip <= (unsigned long)_etext)
25730 + regs->ip = ip;
25731 + }
25732 +#endif
25733 +
25734 nmi_nesting_preprocess(regs);
25735
25736 nmi_enter();
25737 diff --git a/arch/x86/kernel/nmi_selftest.c b/arch/x86/kernel/nmi_selftest.c
25738 index 6d9582e..f746287 100644
25739 --- a/arch/x86/kernel/nmi_selftest.c
25740 +++ b/arch/x86/kernel/nmi_selftest.c
25741 @@ -43,7 +43,7 @@ static void __init init_nmi_testsuite(void)
25742 {
25743 /* trap all the unknown NMIs we may generate */
25744 register_nmi_handler(NMI_UNKNOWN, nmi_unk_cb, 0, "nmi_selftest_unk",
25745 - __initdata);
25746 + __initconst);
25747 }
25748
25749 static void __init cleanup_nmi_testsuite(void)
25750 @@ -66,7 +66,7 @@ static void __init test_nmi_ipi(struct cpumask *mask)
25751 unsigned long timeout;
25752
25753 if (register_nmi_handler(NMI_LOCAL, test_nmi_ipi_callback,
25754 - NMI_FLAG_FIRST, "nmi_selftest", __initdata)) {
25755 + NMI_FLAG_FIRST, "nmi_selftest", __initconst)) {
25756 nmi_fail = FAILURE;
25757 return;
25758 }
25759 diff --git a/arch/x86/kernel/paravirt-spinlocks.c b/arch/x86/kernel/paravirt-spinlocks.c
25760 index bbb6c73..24a58ef 100644
25761 --- a/arch/x86/kernel/paravirt-spinlocks.c
25762 +++ b/arch/x86/kernel/paravirt-spinlocks.c
25763 @@ -8,7 +8,7 @@
25764
25765 #include <asm/paravirt.h>
25766
25767 -struct pv_lock_ops pv_lock_ops = {
25768 +struct pv_lock_ops pv_lock_ops __read_only = {
25769 #ifdef CONFIG_SMP
25770 .lock_spinning = __PV_IS_CALLEE_SAVE(paravirt_nop),
25771 .unlock_kick = paravirt_nop,
25772 diff --git a/arch/x86/kernel/paravirt.c b/arch/x86/kernel/paravirt.c
25773 index 1b10af8..0b58cbc 100644
25774 --- a/arch/x86/kernel/paravirt.c
25775 +++ b/arch/x86/kernel/paravirt.c
25776 @@ -55,6 +55,9 @@ u64 _paravirt_ident_64(u64 x)
25777 {
25778 return x;
25779 }
25780 +#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
25781 +PV_CALLEE_SAVE_REGS_THUNK(_paravirt_ident_64);
25782 +#endif
25783
25784 void __init default_banner(void)
25785 {
25786 @@ -142,15 +145,19 @@ unsigned paravirt_patch_default(u8 type, u16 clobbers, void *insnbuf,
25787 if (opfunc == NULL)
25788 /* If there's no function, patch it with a ud2a (BUG) */
25789 ret = paravirt_patch_insns(insnbuf, len, ud2a, ud2a+sizeof(ud2a));
25790 - else if (opfunc == _paravirt_nop)
25791 + else if (opfunc == (void *)_paravirt_nop)
25792 /* If the operation is a nop, then nop the callsite */
25793 ret = paravirt_patch_nop();
25794
25795 /* identity functions just return their single argument */
25796 - else if (opfunc == _paravirt_ident_32)
25797 + else if (opfunc == (void *)_paravirt_ident_32)
25798 ret = paravirt_patch_ident_32(insnbuf, len);
25799 - else if (opfunc == _paravirt_ident_64)
25800 + else if (opfunc == (void *)_paravirt_ident_64)
25801 ret = paravirt_patch_ident_64(insnbuf, len);
25802 +#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
25803 + else if (opfunc == (void *)__raw_callee_save__paravirt_ident_64)
25804 + ret = paravirt_patch_ident_64(insnbuf, len);
25805 +#endif
25806
25807 else if (type == PARAVIRT_PATCH(pv_cpu_ops.iret) ||
25808 type == PARAVIRT_PATCH(pv_cpu_ops.irq_enable_sysexit) ||
25809 @@ -175,7 +182,7 @@ unsigned paravirt_patch_insns(void *insnbuf, unsigned len,
25810 if (insn_len > len || start == NULL)
25811 insn_len = len;
25812 else
25813 - memcpy(insnbuf, start, insn_len);
25814 + memcpy(insnbuf, ktla_ktva(start), insn_len);
25815
25816 return insn_len;
25817 }
25818 @@ -299,7 +306,7 @@ enum paravirt_lazy_mode paravirt_get_lazy_mode(void)
25819 return this_cpu_read(paravirt_lazy_mode);
25820 }
25821
25822 -struct pv_info pv_info = {
25823 +struct pv_info pv_info __read_only = {
25824 .name = "bare hardware",
25825 .paravirt_enabled = 0,
25826 .kernel_rpl = 0,
25827 @@ -310,16 +317,16 @@ struct pv_info pv_info = {
25828 #endif
25829 };
25830
25831 -struct pv_init_ops pv_init_ops = {
25832 +struct pv_init_ops pv_init_ops __read_only = {
25833 .patch = native_patch,
25834 };
25835
25836 -struct pv_time_ops pv_time_ops = {
25837 +struct pv_time_ops pv_time_ops __read_only = {
25838 .sched_clock = native_sched_clock,
25839 .steal_clock = native_steal_clock,
25840 };
25841
25842 -__visible struct pv_irq_ops pv_irq_ops = {
25843 +__visible struct pv_irq_ops pv_irq_ops __read_only = {
25844 .save_fl = __PV_IS_CALLEE_SAVE(native_save_fl),
25845 .restore_fl = __PV_IS_CALLEE_SAVE(native_restore_fl),
25846 .irq_disable = __PV_IS_CALLEE_SAVE(native_irq_disable),
25847 @@ -331,7 +338,7 @@ __visible struct pv_irq_ops pv_irq_ops = {
25848 #endif
25849 };
25850
25851 -__visible struct pv_cpu_ops pv_cpu_ops = {
25852 +__visible struct pv_cpu_ops pv_cpu_ops __read_only = {
25853 .cpuid = native_cpuid,
25854 .get_debugreg = native_get_debugreg,
25855 .set_debugreg = native_set_debugreg,
25856 @@ -389,21 +396,26 @@ __visible struct pv_cpu_ops pv_cpu_ops = {
25857 .end_context_switch = paravirt_nop,
25858 };
25859
25860 -struct pv_apic_ops pv_apic_ops = {
25861 +struct pv_apic_ops pv_apic_ops __read_only= {
25862 #ifdef CONFIG_X86_LOCAL_APIC
25863 .startup_ipi_hook = paravirt_nop,
25864 #endif
25865 };
25866
25867 -#if defined(CONFIG_X86_32) && !defined(CONFIG_X86_PAE)
25868 +#ifdef CONFIG_X86_32
25869 +#ifdef CONFIG_X86_PAE
25870 +/* 64-bit pagetable entries */
25871 +#define PTE_IDENT PV_CALLEE_SAVE(_paravirt_ident_64)
25872 +#else
25873 /* 32-bit pagetable entries */
25874 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_32)
25875 +#endif
25876 #else
25877 /* 64-bit pagetable entries */
25878 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_64)
25879 #endif
25880
25881 -struct pv_mmu_ops pv_mmu_ops = {
25882 +struct pv_mmu_ops pv_mmu_ops __read_only = {
25883
25884 .read_cr2 = native_read_cr2,
25885 .write_cr2 = native_write_cr2,
25886 @@ -453,6 +465,7 @@ struct pv_mmu_ops pv_mmu_ops = {
25887 .make_pud = PTE_IDENT,
25888
25889 .set_pgd = native_set_pgd,
25890 + .set_pgd_batched = native_set_pgd_batched,
25891 #endif
25892 #endif /* PAGETABLE_LEVELS >= 3 */
25893
25894 @@ -473,6 +486,12 @@ struct pv_mmu_ops pv_mmu_ops = {
25895 },
25896
25897 .set_fixmap = native_set_fixmap,
25898 +
25899 +#ifdef CONFIG_PAX_KERNEXEC
25900 + .pax_open_kernel = native_pax_open_kernel,
25901 + .pax_close_kernel = native_pax_close_kernel,
25902 +#endif
25903 +
25904 };
25905
25906 EXPORT_SYMBOL_GPL(pv_time_ops);
25907 diff --git a/arch/x86/kernel/pci-calgary_64.c b/arch/x86/kernel/pci-calgary_64.c
25908 index 299d493..2ccb0ee 100644
25909 --- a/arch/x86/kernel/pci-calgary_64.c
25910 +++ b/arch/x86/kernel/pci-calgary_64.c
25911 @@ -1339,7 +1339,7 @@ static void __init get_tce_space_from_tar(void)
25912 tce_space = be64_to_cpu(readq(target));
25913 tce_space = tce_space & TAR_SW_BITS;
25914
25915 - tce_space = tce_space & (~specified_table_size);
25916 + tce_space = tce_space & (~(unsigned long)specified_table_size);
25917 info->tce_space = (u64 *)__va(tce_space);
25918 }
25919 }
25920 diff --git a/arch/x86/kernel/pci-iommu_table.c b/arch/x86/kernel/pci-iommu_table.c
25921 index 35ccf75..7a15747 100644
25922 --- a/arch/x86/kernel/pci-iommu_table.c
25923 +++ b/arch/x86/kernel/pci-iommu_table.c
25924 @@ -2,7 +2,7 @@
25925 #include <asm/iommu_table.h>
25926 #include <linux/string.h>
25927 #include <linux/kallsyms.h>
25928 -
25929 +#include <linux/sched.h>
25930
25931 #define DEBUG 1
25932
25933 diff --git a/arch/x86/kernel/pci-swiotlb.c b/arch/x86/kernel/pci-swiotlb.c
25934 index 6c483ba..d10ce2f 100644
25935 --- a/arch/x86/kernel/pci-swiotlb.c
25936 +++ b/arch/x86/kernel/pci-swiotlb.c
25937 @@ -32,7 +32,7 @@ static void x86_swiotlb_free_coherent(struct device *dev, size_t size,
25938 void *vaddr, dma_addr_t dma_addr,
25939 struct dma_attrs *attrs)
25940 {
25941 - swiotlb_free_coherent(dev, size, vaddr, dma_addr);
25942 + swiotlb_free_coherent(dev, size, vaddr, dma_addr, attrs);
25943 }
25944
25945 static struct dma_map_ops swiotlb_dma_ops = {
25946 diff --git a/arch/x86/kernel/preempt.S b/arch/x86/kernel/preempt.S
25947 index ca7f0d5..8996469 100644
25948 --- a/arch/x86/kernel/preempt.S
25949 +++ b/arch/x86/kernel/preempt.S
25950 @@ -3,12 +3,14 @@
25951 #include <asm/dwarf2.h>
25952 #include <asm/asm.h>
25953 #include <asm/calling.h>
25954 +#include <asm/alternative-asm.h>
25955
25956 ENTRY(___preempt_schedule)
25957 CFI_STARTPROC
25958 SAVE_ALL
25959 call preempt_schedule
25960 RESTORE_ALL
25961 + pax_force_retaddr
25962 ret
25963 CFI_ENDPROC
25964
25965 @@ -19,6 +21,7 @@ ENTRY(___preempt_schedule_context)
25966 SAVE_ALL
25967 call preempt_schedule_context
25968 RESTORE_ALL
25969 + pax_force_retaddr
25970 ret
25971 CFI_ENDPROC
25972
25973 diff --git a/arch/x86/kernel/process.c b/arch/x86/kernel/process.c
25974 index 3fb8d95..254dc51 100644
25975 --- a/arch/x86/kernel/process.c
25976 +++ b/arch/x86/kernel/process.c
25977 @@ -36,7 +36,8 @@
25978 * section. Since TSS's are completely CPU-local, we want them
25979 * on exact cacheline boundaries, to eliminate cacheline ping-pong.
25980 */
25981 -__visible DEFINE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss) = INIT_TSS;
25982 +struct tss_struct init_tss[NR_CPUS] __visible ____cacheline_internodealigned_in_smp = { [0 ... NR_CPUS-1] = INIT_TSS };
25983 +EXPORT_SYMBOL(init_tss);
25984
25985 #ifdef CONFIG_X86_64
25986 static DEFINE_PER_CPU(unsigned char, is_idle);
25987 @@ -92,7 +93,7 @@ void arch_task_cache_init(void)
25988 task_xstate_cachep =
25989 kmem_cache_create("task_xstate", xstate_size,
25990 __alignof__(union thread_xstate),
25991 - SLAB_PANIC | SLAB_NOTRACK, NULL);
25992 + SLAB_PANIC | SLAB_NOTRACK | SLAB_USERCOPY, NULL);
25993 }
25994
25995 /*
25996 @@ -105,7 +106,7 @@ void exit_thread(void)
25997 unsigned long *bp = t->io_bitmap_ptr;
25998
25999 if (bp) {
26000 - struct tss_struct *tss = &per_cpu(init_tss, get_cpu());
26001 + struct tss_struct *tss = init_tss + get_cpu();
26002
26003 t->io_bitmap_ptr = NULL;
26004 clear_thread_flag(TIF_IO_BITMAP);
26005 @@ -125,6 +126,9 @@ void flush_thread(void)
26006 {
26007 struct task_struct *tsk = current;
26008
26009 +#if defined(CONFIG_X86_32) && !defined(CONFIG_CC_STACKPROTECTOR) && !defined(CONFIG_PAX_MEMORY_UDEREF)
26010 + loadsegment(gs, 0);
26011 +#endif
26012 flush_ptrace_hw_breakpoint(tsk);
26013 memset(tsk->thread.tls_array, 0, sizeof(tsk->thread.tls_array));
26014 drop_init_fpu(tsk);
26015 @@ -271,7 +275,7 @@ static void __exit_idle(void)
26016 void exit_idle(void)
26017 {
26018 /* idle loop has pid 0 */
26019 - if (current->pid)
26020 + if (task_pid_nr(current))
26021 return;
26022 __exit_idle();
26023 }
26024 @@ -327,7 +331,7 @@ bool xen_set_default_idle(void)
26025 return ret;
26026 }
26027 #endif
26028 -void stop_this_cpu(void *dummy)
26029 +__noreturn void stop_this_cpu(void *dummy)
26030 {
26031 local_irq_disable();
26032 /*
26033 @@ -456,16 +460,37 @@ static int __init idle_setup(char *str)
26034 }
26035 early_param("idle", idle_setup);
26036
26037 -unsigned long arch_align_stack(unsigned long sp)
26038 +#ifdef CONFIG_PAX_RANDKSTACK
26039 +void pax_randomize_kstack(struct pt_regs *regs)
26040 {
26041 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
26042 - sp -= get_random_int() % 8192;
26043 - return sp & ~0xf;
26044 -}
26045 + struct thread_struct *thread = &current->thread;
26046 + unsigned long time;
26047
26048 -unsigned long arch_randomize_brk(struct mm_struct *mm)
26049 -{
26050 - unsigned long range_end = mm->brk + 0x02000000;
26051 - return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
26052 -}
26053 + if (!randomize_va_space)
26054 + return;
26055 +
26056 + if (v8086_mode(regs))
26057 + return;
26058
26059 + rdtscl(time);
26060 +
26061 + /* P4 seems to return a 0 LSB, ignore it */
26062 +#ifdef CONFIG_MPENTIUM4
26063 + time &= 0x3EUL;
26064 + time <<= 2;
26065 +#elif defined(CONFIG_X86_64)
26066 + time &= 0xFUL;
26067 + time <<= 4;
26068 +#else
26069 + time &= 0x1FUL;
26070 + time <<= 3;
26071 +#endif
26072 +
26073 + thread->sp0 ^= time;
26074 + load_sp0(init_tss + smp_processor_id(), thread);
26075 +
26076 +#ifdef CONFIG_X86_64
26077 + this_cpu_write(kernel_stack, thread->sp0);
26078 +#endif
26079 +}
26080 +#endif
26081 diff --git a/arch/x86/kernel/process_32.c b/arch/x86/kernel/process_32.c
26082 index 6f1236c..fd448d4 100644
26083 --- a/arch/x86/kernel/process_32.c
26084 +++ b/arch/x86/kernel/process_32.c
26085 @@ -65,6 +65,7 @@ asmlinkage void ret_from_kernel_thread(void) __asm__("ret_from_kernel_thread");
26086 unsigned long thread_saved_pc(struct task_struct *tsk)
26087 {
26088 return ((unsigned long *)tsk->thread.sp)[3];
26089 +//XXX return tsk->thread.eip;
26090 }
26091
26092 void __show_regs(struct pt_regs *regs, int all)
26093 @@ -74,19 +75,18 @@ void __show_regs(struct pt_regs *regs, int all)
26094 unsigned long sp;
26095 unsigned short ss, gs;
26096
26097 - if (user_mode_vm(regs)) {
26098 + if (user_mode(regs)) {
26099 sp = regs->sp;
26100 ss = regs->ss & 0xffff;
26101 - gs = get_user_gs(regs);
26102 } else {
26103 sp = kernel_stack_pointer(regs);
26104 savesegment(ss, ss);
26105 - savesegment(gs, gs);
26106 }
26107 + gs = get_user_gs(regs);
26108
26109 printk(KERN_DEFAULT "EIP: %04x:[<%08lx>] EFLAGS: %08lx CPU: %d\n",
26110 (u16)regs->cs, regs->ip, regs->flags,
26111 - smp_processor_id());
26112 + raw_smp_processor_id());
26113 print_symbol("EIP is at %s\n", regs->ip);
26114
26115 printk(KERN_DEFAULT "EAX: %08lx EBX: %08lx ECX: %08lx EDX: %08lx\n",
26116 @@ -133,20 +133,21 @@ void release_thread(struct task_struct *dead_task)
26117 int copy_thread(unsigned long clone_flags, unsigned long sp,
26118 unsigned long arg, struct task_struct *p)
26119 {
26120 - struct pt_regs *childregs = task_pt_regs(p);
26121 + struct pt_regs *childregs = task_stack_page(p) + THREAD_SIZE - sizeof(struct pt_regs) - 8;
26122 struct task_struct *tsk;
26123 int err;
26124
26125 p->thread.sp = (unsigned long) childregs;
26126 p->thread.sp0 = (unsigned long) (childregs+1);
26127 + p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
26128
26129 if (unlikely(p->flags & PF_KTHREAD)) {
26130 /* kernel thread */
26131 memset(childregs, 0, sizeof(struct pt_regs));
26132 p->thread.ip = (unsigned long) ret_from_kernel_thread;
26133 - task_user_gs(p) = __KERNEL_STACK_CANARY;
26134 - childregs->ds = __USER_DS;
26135 - childregs->es = __USER_DS;
26136 + savesegment(gs, childregs->gs);
26137 + childregs->ds = __KERNEL_DS;
26138 + childregs->es = __KERNEL_DS;
26139 childregs->fs = __KERNEL_PERCPU;
26140 childregs->bx = sp; /* function */
26141 childregs->bp = arg;
26142 @@ -253,7 +254,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26143 struct thread_struct *prev = &prev_p->thread,
26144 *next = &next_p->thread;
26145 int cpu = smp_processor_id();
26146 - struct tss_struct *tss = &per_cpu(init_tss, cpu);
26147 + struct tss_struct *tss = init_tss + cpu;
26148 fpu_switch_t fpu;
26149
26150 /* never put a printk in __switch_to... printk() calls wake_up*() indirectly */
26151 @@ -277,6 +278,10 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26152 */
26153 lazy_save_gs(prev->gs);
26154
26155 +#ifdef CONFIG_PAX_MEMORY_UDEREF
26156 + __set_fs(task_thread_info(next_p)->addr_limit);
26157 +#endif
26158 +
26159 /*
26160 * Load the per-thread Thread-Local Storage descriptor.
26161 */
26162 @@ -315,6 +320,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26163 */
26164 arch_end_context_switch(next_p);
26165
26166 + this_cpu_write(current_task, next_p);
26167 + this_cpu_write(current_tinfo, &next_p->tinfo);
26168 +
26169 /*
26170 * Restore %gs if needed (which is common)
26171 */
26172 @@ -323,8 +331,6 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26173
26174 switch_fpu_finish(next_p, fpu);
26175
26176 - this_cpu_write(current_task, next_p);
26177 -
26178 return prev_p;
26179 }
26180
26181 @@ -354,4 +360,3 @@ unsigned long get_wchan(struct task_struct *p)
26182 } while (count++ < 16);
26183 return 0;
26184 }
26185 -
26186 diff --git a/arch/x86/kernel/process_64.c b/arch/x86/kernel/process_64.c
26187 index 9c0280f..5bbb1c0 100644
26188 --- a/arch/x86/kernel/process_64.c
26189 +++ b/arch/x86/kernel/process_64.c
26190 @@ -158,10 +158,11 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
26191 struct pt_regs *childregs;
26192 struct task_struct *me = current;
26193
26194 - p->thread.sp0 = (unsigned long)task_stack_page(p) + THREAD_SIZE;
26195 + p->thread.sp0 = (unsigned long)task_stack_page(p) + THREAD_SIZE - 16;
26196 childregs = task_pt_regs(p);
26197 p->thread.sp = (unsigned long) childregs;
26198 p->thread.usersp = me->thread.usersp;
26199 + p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
26200 set_tsk_thread_flag(p, TIF_FORK);
26201 p->thread.fpu_counter = 0;
26202 p->thread.io_bitmap_ptr = NULL;
26203 @@ -172,6 +173,8 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
26204 p->thread.fs = p->thread.fsindex ? 0 : me->thread.fs;
26205 savesegment(es, p->thread.es);
26206 savesegment(ds, p->thread.ds);
26207 + savesegment(ss, p->thread.ss);
26208 + BUG_ON(p->thread.ss == __UDEREF_KERNEL_DS);
26209 memset(p->thread.ptrace_bps, 0, sizeof(p->thread.ptrace_bps));
26210
26211 if (unlikely(p->flags & PF_KTHREAD)) {
26212 @@ -280,7 +283,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26213 struct thread_struct *prev = &prev_p->thread;
26214 struct thread_struct *next = &next_p->thread;
26215 int cpu = smp_processor_id();
26216 - struct tss_struct *tss = &per_cpu(init_tss, cpu);
26217 + struct tss_struct *tss = init_tss + cpu;
26218 unsigned fsindex, gsindex;
26219 fpu_switch_t fpu;
26220
26221 @@ -303,6 +306,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26222 if (unlikely(next->ds | prev->ds))
26223 loadsegment(ds, next->ds);
26224
26225 + savesegment(ss, prev->ss);
26226 + if (unlikely(next->ss != prev->ss))
26227 + loadsegment(ss, next->ss);
26228
26229 /* We must save %fs and %gs before load_TLS() because
26230 * %fs and %gs may be cleared by load_TLS().
26231 @@ -362,6 +368,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26232 prev->usersp = this_cpu_read(old_rsp);
26233 this_cpu_write(old_rsp, next->usersp);
26234 this_cpu_write(current_task, next_p);
26235 + this_cpu_write(current_tinfo, &next_p->tinfo);
26236
26237 /*
26238 * If it were not for PREEMPT_ACTIVE we could guarantee that the
26239 @@ -371,9 +378,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26240 task_thread_info(prev_p)->saved_preempt_count = this_cpu_read(__preempt_count);
26241 this_cpu_write(__preempt_count, task_thread_info(next_p)->saved_preempt_count);
26242
26243 - this_cpu_write(kernel_stack,
26244 - (unsigned long)task_stack_page(next_p) +
26245 - THREAD_SIZE - KERNEL_STACK_OFFSET);
26246 + this_cpu_write(kernel_stack, next->sp0);
26247
26248 /*
26249 * Now maybe reload the debug registers and handle I/O bitmaps
26250 @@ -442,12 +447,11 @@ unsigned long get_wchan(struct task_struct *p)
26251 if (!p || p == current || p->state == TASK_RUNNING)
26252 return 0;
26253 stack = (unsigned long)task_stack_page(p);
26254 - if (p->thread.sp < stack || p->thread.sp >= stack+THREAD_SIZE)
26255 + if (p->thread.sp < stack || p->thread.sp > stack+THREAD_SIZE-16-sizeof(u64))
26256 return 0;
26257 fp = *(u64 *)(p->thread.sp);
26258 do {
26259 - if (fp < (unsigned long)stack ||
26260 - fp >= (unsigned long)stack+THREAD_SIZE)
26261 + if (fp < stack || fp > stack+THREAD_SIZE-16-sizeof(u64))
26262 return 0;
26263 ip = *(u64 *)(fp+8);
26264 if (!in_sched_functions(ip))
26265 diff --git a/arch/x86/kernel/ptrace.c b/arch/x86/kernel/ptrace.c
26266 index 7461f50..1334029 100644
26267 --- a/arch/x86/kernel/ptrace.c
26268 +++ b/arch/x86/kernel/ptrace.c
26269 @@ -184,14 +184,13 @@ unsigned long kernel_stack_pointer(struct pt_regs *regs)
26270 {
26271 unsigned long context = (unsigned long)regs & ~(THREAD_SIZE - 1);
26272 unsigned long sp = (unsigned long)&regs->sp;
26273 - struct thread_info *tinfo;
26274
26275 - if (context == (sp & ~(THREAD_SIZE - 1)))
26276 + if (context == ((sp + 8) & ~(THREAD_SIZE - 1)))
26277 return sp;
26278
26279 - tinfo = (struct thread_info *)context;
26280 - if (tinfo->previous_esp)
26281 - return tinfo->previous_esp;
26282 + sp = *(unsigned long *)context;
26283 + if (sp)
26284 + return sp;
26285
26286 return (unsigned long)regs;
26287 }
26288 @@ -588,7 +587,7 @@ static void ptrace_triggered(struct perf_event *bp,
26289 static unsigned long ptrace_get_dr7(struct perf_event *bp[])
26290 {
26291 int i;
26292 - int dr7 = 0;
26293 + unsigned long dr7 = 0;
26294 struct arch_hw_breakpoint *info;
26295
26296 for (i = 0; i < HBP_NUM; i++) {
26297 @@ -822,7 +821,7 @@ long arch_ptrace(struct task_struct *child, long request,
26298 unsigned long addr, unsigned long data)
26299 {
26300 int ret;
26301 - unsigned long __user *datap = (unsigned long __user *)data;
26302 + unsigned long __user *datap = (__force unsigned long __user *)data;
26303
26304 switch (request) {
26305 /* read the word at location addr in the USER area. */
26306 @@ -907,14 +906,14 @@ long arch_ptrace(struct task_struct *child, long request,
26307 if ((int) addr < 0)
26308 return -EIO;
26309 ret = do_get_thread_area(child, addr,
26310 - (struct user_desc __user *)data);
26311 + (__force struct user_desc __user *) data);
26312 break;
26313
26314 case PTRACE_SET_THREAD_AREA:
26315 if ((int) addr < 0)
26316 return -EIO;
26317 ret = do_set_thread_area(child, addr,
26318 - (struct user_desc __user *)data, 0);
26319 + (__force struct user_desc __user *) data, 0);
26320 break;
26321 #endif
26322
26323 @@ -1292,7 +1291,7 @@ long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
26324
26325 #ifdef CONFIG_X86_64
26326
26327 -static struct user_regset x86_64_regsets[] __read_mostly = {
26328 +static user_regset_no_const x86_64_regsets[] __read_only = {
26329 [REGSET_GENERAL] = {
26330 .core_note_type = NT_PRSTATUS,
26331 .n = sizeof(struct user_regs_struct) / sizeof(long),
26332 @@ -1333,7 +1332,7 @@ static const struct user_regset_view user_x86_64_view = {
26333 #endif /* CONFIG_X86_64 */
26334
26335 #if defined CONFIG_X86_32 || defined CONFIG_IA32_EMULATION
26336 -static struct user_regset x86_32_regsets[] __read_mostly = {
26337 +static user_regset_no_const x86_32_regsets[] __read_only = {
26338 [REGSET_GENERAL] = {
26339 .core_note_type = NT_PRSTATUS,
26340 .n = sizeof(struct user_regs_struct32) / sizeof(u32),
26341 @@ -1386,7 +1385,7 @@ static const struct user_regset_view user_x86_32_view = {
26342 */
26343 u64 xstate_fx_sw_bytes[USER_XSTATE_FX_SW_WORDS];
26344
26345 -void update_regset_xstate_info(unsigned int size, u64 xstate_mask)
26346 +void __init update_regset_xstate_info(unsigned int size, u64 xstate_mask)
26347 {
26348 #ifdef CONFIG_X86_64
26349 x86_64_regsets[REGSET_XSTATE].n = size / sizeof(u64);
26350 @@ -1421,7 +1420,7 @@ static void fill_sigtrap_info(struct task_struct *tsk,
26351 memset(info, 0, sizeof(*info));
26352 info->si_signo = SIGTRAP;
26353 info->si_code = si_code;
26354 - info->si_addr = user_mode_vm(regs) ? (void __user *)regs->ip : NULL;
26355 + info->si_addr = user_mode(regs) ? (__force void __user *)regs->ip : NULL;
26356 }
26357
26358 void user_single_step_siginfo(struct task_struct *tsk,
26359 @@ -1450,6 +1449,10 @@ void send_sigtrap(struct task_struct *tsk, struct pt_regs *regs,
26360 # define IS_IA32 0
26361 #endif
26362
26363 +#ifdef CONFIG_GRKERNSEC_SETXID
26364 +extern void gr_delayed_cred_worker(void);
26365 +#endif
26366 +
26367 /*
26368 * We must return the syscall number to actually look up in the table.
26369 * This can be -1L to skip running any syscall at all.
26370 @@ -1460,6 +1463,11 @@ long syscall_trace_enter(struct pt_regs *regs)
26371
26372 user_exit();
26373
26374 +#ifdef CONFIG_GRKERNSEC_SETXID
26375 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
26376 + gr_delayed_cred_worker();
26377 +#endif
26378 +
26379 /*
26380 * If we stepped into a sysenter/syscall insn, it trapped in
26381 * kernel mode; do_debug() cleared TF and set TIF_SINGLESTEP.
26382 @@ -1515,6 +1523,11 @@ void syscall_trace_leave(struct pt_regs *regs)
26383 */
26384 user_exit();
26385
26386 +#ifdef CONFIG_GRKERNSEC_SETXID
26387 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
26388 + gr_delayed_cred_worker();
26389 +#endif
26390 +
26391 audit_syscall_exit(regs);
26392
26393 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
26394 diff --git a/arch/x86/kernel/pvclock.c b/arch/x86/kernel/pvclock.c
26395 index 2f355d2..e75ed0a 100644
26396 --- a/arch/x86/kernel/pvclock.c
26397 +++ b/arch/x86/kernel/pvclock.c
26398 @@ -51,11 +51,11 @@ void pvclock_touch_watchdogs(void)
26399 reset_hung_task_detector();
26400 }
26401
26402 -static atomic64_t last_value = ATOMIC64_INIT(0);
26403 +static atomic64_unchecked_t last_value = ATOMIC64_INIT(0);
26404
26405 void pvclock_resume(void)
26406 {
26407 - atomic64_set(&last_value, 0);
26408 + atomic64_set_unchecked(&last_value, 0);
26409 }
26410
26411 u8 pvclock_read_flags(struct pvclock_vcpu_time_info *src)
26412 @@ -105,11 +105,11 @@ cycle_t pvclock_clocksource_read(struct pvclock_vcpu_time_info *src)
26413 * updating at the same time, and one of them could be slightly behind,
26414 * making the assumption that last_value always go forward fail to hold.
26415 */
26416 - last = atomic64_read(&last_value);
26417 + last = atomic64_read_unchecked(&last_value);
26418 do {
26419 if (ret < last)
26420 return last;
26421 - last = atomic64_cmpxchg(&last_value, last, ret);
26422 + last = atomic64_cmpxchg_unchecked(&last_value, last, ret);
26423 } while (unlikely(last != ret));
26424
26425 return ret;
26426 diff --git a/arch/x86/kernel/reboot.c b/arch/x86/kernel/reboot.c
26427 index c752cb4..866c432 100644
26428 --- a/arch/x86/kernel/reboot.c
26429 +++ b/arch/x86/kernel/reboot.c
26430 @@ -68,6 +68,11 @@ static int __init set_bios_reboot(const struct dmi_system_id *d)
26431
26432 void __noreturn machine_real_restart(unsigned int type)
26433 {
26434 +
26435 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
26436 + struct desc_struct *gdt;
26437 +#endif
26438 +
26439 local_irq_disable();
26440
26441 /*
26442 @@ -95,7 +100,29 @@ void __noreturn machine_real_restart(unsigned int type)
26443
26444 /* Jump to the identity-mapped low memory code */
26445 #ifdef CONFIG_X86_32
26446 - asm volatile("jmpl *%0" : :
26447 +
26448 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
26449 + gdt = get_cpu_gdt_table(smp_processor_id());
26450 + pax_open_kernel();
26451 +#ifdef CONFIG_PAX_MEMORY_UDEREF
26452 + gdt[GDT_ENTRY_KERNEL_DS].type = 3;
26453 + gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
26454 + loadsegment(ds, __KERNEL_DS);
26455 + loadsegment(es, __KERNEL_DS);
26456 + loadsegment(ss, __KERNEL_DS);
26457 +#endif
26458 +#ifdef CONFIG_PAX_KERNEXEC
26459 + gdt[GDT_ENTRY_KERNEL_CS].base0 = 0;
26460 + gdt[GDT_ENTRY_KERNEL_CS].base1 = 0;
26461 + gdt[GDT_ENTRY_KERNEL_CS].base2 = 0;
26462 + gdt[GDT_ENTRY_KERNEL_CS].limit0 = 0xffff;
26463 + gdt[GDT_ENTRY_KERNEL_CS].limit = 0xf;
26464 + gdt[GDT_ENTRY_KERNEL_CS].g = 1;
26465 +#endif
26466 + pax_close_kernel();
26467 +#endif
26468 +
26469 + asm volatile("ljmpl *%0" : :
26470 "rm" (real_mode_header->machine_real_restart_asm),
26471 "a" (type));
26472 #else
26473 @@ -470,7 +497,7 @@ void __attribute__((weak)) mach_reboot_fixups(void)
26474 * try to force a triple fault and then cycle between hitting the keyboard
26475 * controller and doing that
26476 */
26477 -static void native_machine_emergency_restart(void)
26478 +static void __noreturn native_machine_emergency_restart(void)
26479 {
26480 int i;
26481 int attempt = 0;
26482 @@ -593,13 +620,13 @@ void native_machine_shutdown(void)
26483 #endif
26484 }
26485
26486 -static void __machine_emergency_restart(int emergency)
26487 +static void __noreturn __machine_emergency_restart(int emergency)
26488 {
26489 reboot_emergency = emergency;
26490 machine_ops.emergency_restart();
26491 }
26492
26493 -static void native_machine_restart(char *__unused)
26494 +static void __noreturn native_machine_restart(char *__unused)
26495 {
26496 pr_notice("machine restart\n");
26497
26498 @@ -608,7 +635,7 @@ static void native_machine_restart(char *__unused)
26499 __machine_emergency_restart(0);
26500 }
26501
26502 -static void native_machine_halt(void)
26503 +static void __noreturn native_machine_halt(void)
26504 {
26505 /* Stop other cpus and apics */
26506 machine_shutdown();
26507 @@ -618,7 +645,7 @@ static void native_machine_halt(void)
26508 stop_this_cpu(NULL);
26509 }
26510
26511 -static void native_machine_power_off(void)
26512 +static void __noreturn native_machine_power_off(void)
26513 {
26514 if (pm_power_off) {
26515 if (!reboot_force)
26516 @@ -627,9 +654,10 @@ static void native_machine_power_off(void)
26517 }
26518 /* A fallback in case there is no PM info available */
26519 tboot_shutdown(TB_SHUTDOWN_HALT);
26520 + unreachable();
26521 }
26522
26523 -struct machine_ops machine_ops = {
26524 +struct machine_ops machine_ops __read_only = {
26525 .power_off = native_machine_power_off,
26526 .shutdown = native_machine_shutdown,
26527 .emergency_restart = native_machine_emergency_restart,
26528 diff --git a/arch/x86/kernel/reboot_fixups_32.c b/arch/x86/kernel/reboot_fixups_32.c
26529 index c8e41e9..64049ef 100644
26530 --- a/arch/x86/kernel/reboot_fixups_32.c
26531 +++ b/arch/x86/kernel/reboot_fixups_32.c
26532 @@ -57,7 +57,7 @@ struct device_fixup {
26533 unsigned int vendor;
26534 unsigned int device;
26535 void (*reboot_fixup)(struct pci_dev *);
26536 -};
26537 +} __do_const;
26538
26539 /*
26540 * PCI ids solely used for fixups_table go here
26541 diff --git a/arch/x86/kernel/relocate_kernel_64.S b/arch/x86/kernel/relocate_kernel_64.S
26542 index 3fd2c69..a444264 100644
26543 --- a/arch/x86/kernel/relocate_kernel_64.S
26544 +++ b/arch/x86/kernel/relocate_kernel_64.S
26545 @@ -96,8 +96,7 @@ relocate_kernel:
26546
26547 /* jump to identity mapped page */
26548 addq $(identity_mapped - relocate_kernel), %r8
26549 - pushq %r8
26550 - ret
26551 + jmp *%r8
26552
26553 identity_mapped:
26554 /* set return address to 0 if not preserving context */
26555 diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
26556 index cb233bc..23b4879 100644
26557 --- a/arch/x86/kernel/setup.c
26558 +++ b/arch/x86/kernel/setup.c
26559 @@ -110,6 +110,7 @@
26560 #include <asm/mce.h>
26561 #include <asm/alternative.h>
26562 #include <asm/prom.h>
26563 +#include <asm/boot.h>
26564
26565 /*
26566 * max_low_pfn_mapped: highest direct mapped pfn under 4GB
26567 @@ -205,12 +206,50 @@ EXPORT_SYMBOL(boot_cpu_data);
26568 #endif
26569
26570
26571 -#if !defined(CONFIG_X86_PAE) || defined(CONFIG_X86_64)
26572 -__visible unsigned long mmu_cr4_features;
26573 +#ifdef CONFIG_X86_64
26574 +__visible unsigned long mmu_cr4_features __read_only = X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE;
26575 +#elif defined(CONFIG_X86_PAE)
26576 +__visible unsigned long mmu_cr4_features __read_only = X86_CR4_PAE;
26577 #else
26578 -__visible unsigned long mmu_cr4_features = X86_CR4_PAE;
26579 +__visible unsigned long mmu_cr4_features __read_only;
26580 #endif
26581
26582 +void set_in_cr4(unsigned long mask)
26583 +{
26584 + unsigned long cr4 = read_cr4();
26585 +
26586 + if ((cr4 & mask) == mask && cr4 == mmu_cr4_features)
26587 + return;
26588 +
26589 + pax_open_kernel();
26590 + mmu_cr4_features |= mask;
26591 + pax_close_kernel();
26592 +
26593 + if (trampoline_cr4_features)
26594 + *trampoline_cr4_features = mmu_cr4_features;
26595 + cr4 |= mask;
26596 + write_cr4(cr4);
26597 +}
26598 +EXPORT_SYMBOL(set_in_cr4);
26599 +
26600 +void clear_in_cr4(unsigned long mask)
26601 +{
26602 + unsigned long cr4 = read_cr4();
26603 +
26604 + if (!(cr4 & mask) && cr4 == mmu_cr4_features)
26605 + return;
26606 +
26607 + pax_open_kernel();
26608 + mmu_cr4_features &= ~mask;
26609 + pax_close_kernel();
26610 +
26611 + if (trampoline_cr4_features)
26612 + *trampoline_cr4_features = mmu_cr4_features;
26613 + cr4 &= ~mask;
26614 + write_cr4(cr4);
26615 +}
26616 +EXPORT_SYMBOL(clear_in_cr4);
26617 +
26618 /* Boot loader ID and version as integers, for the benefit of proc_dointvec */
26619 int bootloader_type, bootloader_version;
26620
26621 @@ -768,7 +807,7 @@ static void __init trim_bios_range(void)
26622 * area (640->1Mb) as ram even though it is not.
26623 * take them out.
26624 */
26625 - e820_remove_range(BIOS_BEGIN, BIOS_END - BIOS_BEGIN, E820_RAM, 1);
26626 + e820_remove_range(ISA_START_ADDRESS, ISA_END_ADDRESS - ISA_START_ADDRESS, E820_RAM, 1);
26627
26628 sanitize_e820_map(e820.map, ARRAY_SIZE(e820.map), &e820.nr_map);
26629 }
26630 @@ -776,7 +815,7 @@ static void __init trim_bios_range(void)
26631 /* called before trim_bios_range() to spare extra sanitize */
26632 static void __init e820_add_kernel_range(void)
26633 {
26634 - u64 start = __pa_symbol(_text);
26635 + u64 start = __pa_symbol(ktla_ktva(_text));
26636 u64 size = __pa_symbol(_end) - start;
26637
26638 /*
26639 @@ -838,8 +877,12 @@ static void __init trim_low_memory_range(void)
26640
26641 void __init setup_arch(char **cmdline_p)
26642 {
26643 +#ifdef CONFIG_X86_32
26644 + memblock_reserve(LOAD_PHYSICAL_ADDR, __pa_symbol(__bss_stop) - LOAD_PHYSICAL_ADDR);
26645 +#else
26646 memblock_reserve(__pa_symbol(_text),
26647 (unsigned long)__bss_stop - (unsigned long)_text);
26648 +#endif
26649
26650 early_reserve_initrd();
26651
26652 @@ -931,14 +974,14 @@ void __init setup_arch(char **cmdline_p)
26653
26654 if (!boot_params.hdr.root_flags)
26655 root_mountflags &= ~MS_RDONLY;
26656 - init_mm.start_code = (unsigned long) _text;
26657 - init_mm.end_code = (unsigned long) _etext;
26658 + init_mm.start_code = ktla_ktva((unsigned long) _text);
26659 + init_mm.end_code = ktla_ktva((unsigned long) _etext);
26660 init_mm.end_data = (unsigned long) _edata;
26661 init_mm.brk = _brk_end;
26662
26663 - code_resource.start = __pa_symbol(_text);
26664 - code_resource.end = __pa_symbol(_etext)-1;
26665 - data_resource.start = __pa_symbol(_etext);
26666 + code_resource.start = __pa_symbol(ktla_ktva(_text));
26667 + code_resource.end = __pa_symbol(ktla_ktva(_etext))-1;
26668 + data_resource.start = __pa_symbol(_sdata);
26669 data_resource.end = __pa_symbol(_edata)-1;
26670 bss_resource.start = __pa_symbol(__bss_start);
26671 bss_resource.end = __pa_symbol(__bss_stop)-1;
26672 diff --git a/arch/x86/kernel/setup_percpu.c b/arch/x86/kernel/setup_percpu.c
26673 index 5cdff03..80fa283 100644
26674 --- a/arch/x86/kernel/setup_percpu.c
26675 +++ b/arch/x86/kernel/setup_percpu.c
26676 @@ -21,19 +21,17 @@
26677 #include <asm/cpu.h>
26678 #include <asm/stackprotector.h>
26679
26680 -DEFINE_PER_CPU_READ_MOSTLY(int, cpu_number);
26681 +#ifdef CONFIG_SMP
26682 +DEFINE_PER_CPU_READ_MOSTLY(unsigned int, cpu_number);
26683 EXPORT_PER_CPU_SYMBOL(cpu_number);
26684 +#endif
26685
26686 -#ifdef CONFIG_X86_64
26687 #define BOOT_PERCPU_OFFSET ((unsigned long)__per_cpu_load)
26688 -#else
26689 -#define BOOT_PERCPU_OFFSET 0
26690 -#endif
26691
26692 DEFINE_PER_CPU(unsigned long, this_cpu_off) = BOOT_PERCPU_OFFSET;
26693 EXPORT_PER_CPU_SYMBOL(this_cpu_off);
26694
26695 -unsigned long __per_cpu_offset[NR_CPUS] __read_mostly = {
26696 +unsigned long __per_cpu_offset[NR_CPUS] __read_only = {
26697 [0 ... NR_CPUS-1] = BOOT_PERCPU_OFFSET,
26698 };
26699 EXPORT_SYMBOL(__per_cpu_offset);
26700 @@ -66,7 +64,7 @@ static bool __init pcpu_need_numa(void)
26701 {
26702 #ifdef CONFIG_NEED_MULTIPLE_NODES
26703 pg_data_t *last = NULL;
26704 - unsigned int cpu;
26705 + int cpu;
26706
26707 for_each_possible_cpu(cpu) {
26708 int node = early_cpu_to_node(cpu);
26709 @@ -155,10 +153,10 @@ static inline void setup_percpu_segment(int cpu)
26710 {
26711 #ifdef CONFIG_X86_32
26712 struct desc_struct gdt;
26713 + unsigned long base = per_cpu_offset(cpu);
26714
26715 - pack_descriptor(&gdt, per_cpu_offset(cpu), 0xFFFFF,
26716 - 0x2 | DESCTYPE_S, 0x8);
26717 - gdt.s = 1;
26718 + pack_descriptor(&gdt, base, (VMALLOC_END - base - 1) >> PAGE_SHIFT,
26719 + 0x83 | DESCTYPE_S, 0xC);
26720 write_gdt_entry(get_cpu_gdt_table(cpu),
26721 GDT_ENTRY_PERCPU, &gdt, DESCTYPE_S);
26722 #endif
26723 @@ -219,6 +217,11 @@ void __init setup_per_cpu_areas(void)
26724 /* alrighty, percpu areas up and running */
26725 delta = (unsigned long)pcpu_base_addr - (unsigned long)__per_cpu_start;
26726 for_each_possible_cpu(cpu) {
26727 +#ifdef CONFIG_CC_STACKPROTECTOR
26728 +#ifdef CONFIG_X86_32
26729 + unsigned long canary = per_cpu(stack_canary.canary, cpu);
26730 +#endif
26731 +#endif
26732 per_cpu_offset(cpu) = delta + pcpu_unit_offsets[cpu];
26733 per_cpu(this_cpu_off, cpu) = per_cpu_offset(cpu);
26734 per_cpu(cpu_number, cpu) = cpu;
26735 @@ -259,6 +262,12 @@ void __init setup_per_cpu_areas(void)
26736 */
26737 set_cpu_numa_node(cpu, early_cpu_to_node(cpu));
26738 #endif
26739 +#ifdef CONFIG_CC_STACKPROTECTOR
26740 +#ifdef CONFIG_X86_32
26741 + if (!cpu)
26742 + per_cpu(stack_canary.canary, cpu) = canary;
26743 +#endif
26744 +#endif
26745 /*
26746 * Up to this point, the boot CPU has been using .init.data
26747 * area. Reload any changed state for the boot CPU.
26748 diff --git a/arch/x86/kernel/signal.c b/arch/x86/kernel/signal.c
26749 index 9e5de68..16c53cb 100644
26750 --- a/arch/x86/kernel/signal.c
26751 +++ b/arch/x86/kernel/signal.c
26752 @@ -190,7 +190,7 @@ static unsigned long align_sigframe(unsigned long sp)
26753 * Align the stack pointer according to the i386 ABI,
26754 * i.e. so that on function entry ((sp + 4) & 15) == 0.
26755 */
26756 - sp = ((sp + 4) & -16ul) - 4;
26757 + sp = ((sp - 12) & -16ul) - 4;
26758 #else /* !CONFIG_X86_32 */
26759 sp = round_down(sp, 16) - 8;
26760 #endif
26761 @@ -298,9 +298,9 @@ __setup_frame(int sig, struct ksignal *ksig, sigset_t *set,
26762 }
26763
26764 if (current->mm->context.vdso)
26765 - restorer = VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
26766 + restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
26767 else
26768 - restorer = &frame->retcode;
26769 + restorer = (void __user *)&frame->retcode;
26770 if (ksig->ka.sa.sa_flags & SA_RESTORER)
26771 restorer = ksig->ka.sa.sa_restorer;
26772
26773 @@ -314,7 +314,7 @@ __setup_frame(int sig, struct ksignal *ksig, sigset_t *set,
26774 * reasons and because gdb uses it as a signature to notice
26775 * signal handler stack frames.
26776 */
26777 - err |= __put_user(*((u64 *)&retcode), (u64 *)frame->retcode);
26778 + err |= __put_user(*((u64 *)&retcode), (u64 __user *)frame->retcode);
26779
26780 if (err)
26781 return -EFAULT;
26782 @@ -361,7 +361,10 @@ static int __setup_rt_frame(int sig, struct ksignal *ksig,
26783 save_altstack_ex(&frame->uc.uc_stack, regs->sp);
26784
26785 /* Set up to return from userspace. */
26786 - restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
26787 + if (current->mm->context.vdso)
26788 + restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
26789 + else
26790 + restorer = (void __user *)&frame->retcode;
26791 if (ksig->ka.sa.sa_flags & SA_RESTORER)
26792 restorer = ksig->ka.sa.sa_restorer;
26793 put_user_ex(restorer, &frame->pretcode);
26794 @@ -373,7 +376,7 @@ static int __setup_rt_frame(int sig, struct ksignal *ksig,
26795 * reasons and because gdb uses it as a signature to notice
26796 * signal handler stack frames.
26797 */
26798 - put_user_ex(*((u64 *)&rt_retcode), (u64 *)frame->retcode);
26799 + put_user_ex(*((u64 *)&rt_retcode), (u64 __user *)frame->retcode);
26800 } put_user_catch(err);
26801
26802 err |= copy_siginfo_to_user(&frame->info, &ksig->info);
26803 @@ -609,7 +612,12 @@ setup_rt_frame(struct ksignal *ksig, struct pt_regs *regs)
26804 {
26805 int usig = signr_convert(ksig->sig);
26806 sigset_t *set = sigmask_to_save();
26807 - compat_sigset_t *cset = (compat_sigset_t *) set;
26808 + sigset_t sigcopy;
26809 + compat_sigset_t *cset;
26810 +
26811 + sigcopy = *set;
26812 +
26813 + cset = (compat_sigset_t *) &sigcopy;
26814
26815 /* Set up the stack frame */
26816 if (is_ia32_frame()) {
26817 @@ -620,7 +628,7 @@ setup_rt_frame(struct ksignal *ksig, struct pt_regs *regs)
26818 } else if (is_x32_frame()) {
26819 return x32_setup_rt_frame(ksig, cset, regs);
26820 } else {
26821 - return __setup_rt_frame(ksig->sig, ksig, set, regs);
26822 + return __setup_rt_frame(ksig->sig, ksig, &sigcopy, regs);
26823 }
26824 }
26825
26826 diff --git a/arch/x86/kernel/smp.c b/arch/x86/kernel/smp.c
26827 index 7c3a5a6..f0a8961 100644
26828 --- a/arch/x86/kernel/smp.c
26829 +++ b/arch/x86/kernel/smp.c
26830 @@ -341,7 +341,7 @@ static int __init nonmi_ipi_setup(char *str)
26831
26832 __setup("nonmi_ipi", nonmi_ipi_setup);
26833
26834 -struct smp_ops smp_ops = {
26835 +struct smp_ops smp_ops __read_only = {
26836 .smp_prepare_boot_cpu = native_smp_prepare_boot_cpu,
26837 .smp_prepare_cpus = native_smp_prepare_cpus,
26838 .smp_cpus_done = native_smp_cpus_done,
26839 diff --git a/arch/x86/kernel/smpboot.c b/arch/x86/kernel/smpboot.c
26840 index 85dc05a..f8c96f6 100644
26841 --- a/arch/x86/kernel/smpboot.c
26842 +++ b/arch/x86/kernel/smpboot.c
26843 @@ -229,14 +229,18 @@ static void notrace start_secondary(void *unused)
26844
26845 enable_start_cpu0 = 0;
26846
26847 -#ifdef CONFIG_X86_32
26848 - /* switch away from the initial page table */
26849 - load_cr3(swapper_pg_dir);
26850 - __flush_tlb_all();
26851 -#endif
26852 -
26853 /* otherwise gcc will move up smp_processor_id before the cpu_init */
26854 barrier();
26855 +
26856 + /* switch away from the initial page table */
26857 +#ifdef CONFIG_PAX_PER_CPU_PGD
26858 + load_cr3(get_cpu_pgd(smp_processor_id(), kernel));
26859 + __flush_tlb_all();
26860 +#elif defined(CONFIG_X86_32)
26861 + load_cr3(swapper_pg_dir);
26862 + __flush_tlb_all();
26863 +#endif
26864 +
26865 /*
26866 * Check TSC synchronization with the BP:
26867 */
26868 @@ -749,8 +753,9 @@ static int do_boot_cpu(int apicid, int cpu, struct task_struct *idle)
26869 alternatives_enable_smp();
26870
26871 idle->thread.sp = (unsigned long) (((struct pt_regs *)
26872 - (THREAD_SIZE + task_stack_page(idle))) - 1);
26873 + (THREAD_SIZE - 16 + task_stack_page(idle))) - 1);
26874 per_cpu(current_task, cpu) = idle;
26875 + per_cpu(current_tinfo, cpu) = &idle->tinfo;
26876
26877 #ifdef CONFIG_X86_32
26878 /* Stack for startup_32 can be just as for start_secondary onwards */
26879 @@ -758,11 +763,13 @@ static int do_boot_cpu(int apicid, int cpu, struct task_struct *idle)
26880 #else
26881 clear_tsk_thread_flag(idle, TIF_FORK);
26882 initial_gs = per_cpu_offset(cpu);
26883 - per_cpu(kernel_stack, cpu) =
26884 - (unsigned long)task_stack_page(idle) -
26885 - KERNEL_STACK_OFFSET + THREAD_SIZE;
26886 + per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
26887 #endif
26888 +
26889 + pax_open_kernel();
26890 early_gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
26891 + pax_close_kernel();
26892 +
26893 initial_code = (unsigned long)start_secondary;
26894 stack_start = idle->thread.sp;
26895
26896 @@ -911,6 +918,15 @@ int native_cpu_up(unsigned int cpu, struct task_struct *tidle)
26897 /* the FPU context is blank, nobody can own it */
26898 __cpu_disable_lazy_restore(cpu);
26899
26900 +#ifdef CONFIG_PAX_PER_CPU_PGD
26901 + clone_pgd_range(get_cpu_pgd(cpu, kernel) + KERNEL_PGD_BOUNDARY,
26902 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
26903 + KERNEL_PGD_PTRS);
26904 + clone_pgd_range(get_cpu_pgd(cpu, user) + KERNEL_PGD_BOUNDARY,
26905 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
26906 + KERNEL_PGD_PTRS);
26907 +#endif
26908 +
26909 err = do_boot_cpu(apicid, cpu, tidle);
26910 if (err) {
26911 pr_debug("do_boot_cpu failed %d\n", err);
26912 diff --git a/arch/x86/kernel/step.c b/arch/x86/kernel/step.c
26913 index 9b4d51d..5d28b58 100644
26914 --- a/arch/x86/kernel/step.c
26915 +++ b/arch/x86/kernel/step.c
26916 @@ -27,10 +27,10 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
26917 struct desc_struct *desc;
26918 unsigned long base;
26919
26920 - seg &= ~7UL;
26921 + seg >>= 3;
26922
26923 mutex_lock(&child->mm->context.lock);
26924 - if (unlikely((seg >> 3) >= child->mm->context.size))
26925 + if (unlikely(seg >= child->mm->context.size))
26926 addr = -1L; /* bogus selector, access would fault */
26927 else {
26928 desc = child->mm->context.ldt + seg;
26929 @@ -42,7 +42,8 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
26930 addr += base;
26931 }
26932 mutex_unlock(&child->mm->context.lock);
26933 - }
26934 + } else if (seg == __KERNEL_CS || seg == __KERNEXEC_KERNEL_CS)
26935 + addr = ktla_ktva(addr);
26936
26937 return addr;
26938 }
26939 @@ -53,6 +54,9 @@ static int is_setting_trap_flag(struct task_struct *child, struct pt_regs *regs)
26940 unsigned char opcode[15];
26941 unsigned long addr = convert_ip_to_linear(child, regs);
26942
26943 + if (addr == -EINVAL)
26944 + return 0;
26945 +
26946 copied = access_process_vm(child, addr, opcode, sizeof(opcode), 0);
26947 for (i = 0; i < copied; i++) {
26948 switch (opcode[i]) {
26949 diff --git a/arch/x86/kernel/sys_i386_32.c b/arch/x86/kernel/sys_i386_32.c
26950 new file mode 100644
26951 index 0000000..5877189
26952 --- /dev/null
26953 +++ b/arch/x86/kernel/sys_i386_32.c
26954 @@ -0,0 +1,189 @@
26955 +/*
26956 + * This file contains various random system calls that
26957 + * have a non-standard calling sequence on the Linux/i386
26958 + * platform.
26959 + */
26960 +
26961 +#include <linux/errno.h>
26962 +#include <linux/sched.h>
26963 +#include <linux/mm.h>
26964 +#include <linux/fs.h>
26965 +#include <linux/smp.h>
26966 +#include <linux/sem.h>
26967 +#include <linux/msg.h>
26968 +#include <linux/shm.h>
26969 +#include <linux/stat.h>
26970 +#include <linux/syscalls.h>
26971 +#include <linux/mman.h>
26972 +#include <linux/file.h>
26973 +#include <linux/utsname.h>
26974 +#include <linux/ipc.h>
26975 +#include <linux/elf.h>
26976 +
26977 +#include <linux/uaccess.h>
26978 +#include <linux/unistd.h>
26979 +
26980 +#include <asm/syscalls.h>
26981 +
26982 +int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags)
26983 +{
26984 + unsigned long pax_task_size = TASK_SIZE;
26985 +
26986 +#ifdef CONFIG_PAX_SEGMEXEC
26987 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
26988 + pax_task_size = SEGMEXEC_TASK_SIZE;
26989 +#endif
26990 +
26991 + if (flags & MAP_FIXED)
26992 + if (len > pax_task_size || addr > pax_task_size - len)
26993 + return -EINVAL;
26994 +
26995 + return 0;
26996 +}
26997 +
26998 +/*
26999 + * Align a virtual address to avoid aliasing in the I$ on AMD F15h.
27000 + */
27001 +static unsigned long get_align_mask(void)
27002 +{
27003 + if (va_align.flags < 0 || !(va_align.flags & ALIGN_VA_32))
27004 + return 0;
27005 +
27006 + if (!(current->flags & PF_RANDOMIZE))
27007 + return 0;
27008 +
27009 + return va_align.mask;
27010 +}
27011 +
27012 +unsigned long
27013 +arch_get_unmapped_area(struct file *filp, unsigned long addr,
27014 + unsigned long len, unsigned long pgoff, unsigned long flags)
27015 +{
27016 + struct mm_struct *mm = current->mm;
27017 + struct vm_area_struct *vma;
27018 + unsigned long pax_task_size = TASK_SIZE;
27019 + struct vm_unmapped_area_info info;
27020 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
27021 +
27022 +#ifdef CONFIG_PAX_SEGMEXEC
27023 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
27024 + pax_task_size = SEGMEXEC_TASK_SIZE;
27025 +#endif
27026 +
27027 + pax_task_size -= PAGE_SIZE;
27028 +
27029 + if (len > pax_task_size)
27030 + return -ENOMEM;
27031 +
27032 + if (flags & MAP_FIXED)
27033 + return addr;
27034 +
27035 +#ifdef CONFIG_PAX_RANDMMAP
27036 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
27037 +#endif
27038 +
27039 + if (addr) {
27040 + addr = PAGE_ALIGN(addr);
27041 + if (pax_task_size - len >= addr) {
27042 + vma = find_vma(mm, addr);
27043 + if (check_heap_stack_gap(vma, addr, len, offset))
27044 + return addr;
27045 + }
27046 + }
27047 +
27048 + info.flags = 0;
27049 + info.length = len;
27050 + info.align_mask = filp ? get_align_mask() : 0;
27051 + info.align_offset = pgoff << PAGE_SHIFT;
27052 + info.threadstack_offset = offset;
27053 +
27054 +#ifdef CONFIG_PAX_PAGEEXEC
27055 + if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE)) {
27056 + info.low_limit = 0x00110000UL;
27057 + info.high_limit = mm->start_code;
27058 +
27059 +#ifdef CONFIG_PAX_RANDMMAP
27060 + if (mm->pax_flags & MF_PAX_RANDMMAP)
27061 + info.low_limit += mm->delta_mmap & 0x03FFF000UL;
27062 +#endif
27063 +
27064 + if (info.low_limit < info.high_limit) {
27065 + addr = vm_unmapped_area(&info);
27066 + if (!IS_ERR_VALUE(addr))
27067 + return addr;
27068 + }
27069 + } else
27070 +#endif
27071 +
27072 + info.low_limit = mm->mmap_base;
27073 + info.high_limit = pax_task_size;
27074 +
27075 + return vm_unmapped_area(&info);
27076 +}
27077 +
27078 +unsigned long
27079 +arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
27080 + const unsigned long len, const unsigned long pgoff,
27081 + const unsigned long flags)
27082 +{
27083 + struct vm_area_struct *vma;
27084 + struct mm_struct *mm = current->mm;
27085 + unsigned long addr = addr0, pax_task_size = TASK_SIZE;
27086 + struct vm_unmapped_area_info info;
27087 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
27088 +
27089 +#ifdef CONFIG_PAX_SEGMEXEC
27090 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
27091 + pax_task_size = SEGMEXEC_TASK_SIZE;
27092 +#endif
27093 +
27094 + pax_task_size -= PAGE_SIZE;
27095 +
27096 + /* requested length too big for entire address space */
27097 + if (len > pax_task_size)
27098 + return -ENOMEM;
27099 +
27100 + if (flags & MAP_FIXED)
27101 + return addr;
27102 +
27103 +#ifdef CONFIG_PAX_PAGEEXEC
27104 + if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE))
27105 + goto bottomup;
27106 +#endif
27107 +
27108 +#ifdef CONFIG_PAX_RANDMMAP
27109 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
27110 +#endif
27111 +
27112 + /* requesting a specific address */
27113 + if (addr) {
27114 + addr = PAGE_ALIGN(addr);
27115 + if (pax_task_size - len >= addr) {
27116 + vma = find_vma(mm, addr);
27117 + if (check_heap_stack_gap(vma, addr, len, offset))
27118 + return addr;
27119 + }
27120 + }
27121 +
27122 + info.flags = VM_UNMAPPED_AREA_TOPDOWN;
27123 + info.length = len;
27124 + info.low_limit = PAGE_SIZE;
27125 + info.high_limit = mm->mmap_base;
27126 + info.align_mask = filp ? get_align_mask() : 0;
27127 + info.align_offset = pgoff << PAGE_SHIFT;
27128 + info.threadstack_offset = offset;
27129 +
27130 + addr = vm_unmapped_area(&info);
27131 + if (!(addr & ~PAGE_MASK))
27132 + return addr;
27133 + VM_BUG_ON(addr != -ENOMEM);
27134 +
27135 +bottomup:
27136 + /*
27137 + * A failed mmap() very likely causes application failure,
27138 + * so fall back to the bottom-up function here. This scenario
27139 + * can happen with large stack limits and large mmap()
27140 + * allocations.
27141 + */
27142 + return arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
27143 +}
27144 diff --git a/arch/x86/kernel/sys_x86_64.c b/arch/x86/kernel/sys_x86_64.c
27145 index 30277e2..5664a29 100644
27146 --- a/arch/x86/kernel/sys_x86_64.c
27147 +++ b/arch/x86/kernel/sys_x86_64.c
27148 @@ -81,8 +81,8 @@ out:
27149 return error;
27150 }
27151
27152 -static void find_start_end(unsigned long flags, unsigned long *begin,
27153 - unsigned long *end)
27154 +static void find_start_end(struct mm_struct *mm, unsigned long flags,
27155 + unsigned long *begin, unsigned long *end)
27156 {
27157 if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT)) {
27158 unsigned long new_begin;
27159 @@ -101,7 +101,7 @@ static void find_start_end(unsigned long flags, unsigned long *begin,
27160 *begin = new_begin;
27161 }
27162 } else {
27163 - *begin = current->mm->mmap_legacy_base;
27164 + *begin = mm->mmap_legacy_base;
27165 *end = TASK_SIZE;
27166 }
27167 }
27168 @@ -114,20 +114,24 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
27169 struct vm_area_struct *vma;
27170 struct vm_unmapped_area_info info;
27171 unsigned long begin, end;
27172 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
27173
27174 if (flags & MAP_FIXED)
27175 return addr;
27176
27177 - find_start_end(flags, &begin, &end);
27178 + find_start_end(mm, flags, &begin, &end);
27179
27180 if (len > end)
27181 return -ENOMEM;
27182
27183 +#ifdef CONFIG_PAX_RANDMMAP
27184 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
27185 +#endif
27186 +
27187 if (addr) {
27188 addr = PAGE_ALIGN(addr);
27189 vma = find_vma(mm, addr);
27190 - if (end - len >= addr &&
27191 - (!vma || addr + len <= vma->vm_start))
27192 + if (end - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
27193 return addr;
27194 }
27195
27196 @@ -137,6 +141,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
27197 info.high_limit = end;
27198 info.align_mask = filp ? get_align_mask() : 0;
27199 info.align_offset = pgoff << PAGE_SHIFT;
27200 + info.threadstack_offset = offset;
27201 return vm_unmapped_area(&info);
27202 }
27203
27204 @@ -149,6 +154,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
27205 struct mm_struct *mm = current->mm;
27206 unsigned long addr = addr0;
27207 struct vm_unmapped_area_info info;
27208 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
27209
27210 /* requested length too big for entire address space */
27211 if (len > TASK_SIZE)
27212 @@ -161,12 +167,15 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
27213 if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT))
27214 goto bottomup;
27215
27216 +#ifdef CONFIG_PAX_RANDMMAP
27217 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
27218 +#endif
27219 +
27220 /* requesting a specific address */
27221 if (addr) {
27222 addr = PAGE_ALIGN(addr);
27223 vma = find_vma(mm, addr);
27224 - if (TASK_SIZE - len >= addr &&
27225 - (!vma || addr + len <= vma->vm_start))
27226 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
27227 return addr;
27228 }
27229
27230 @@ -176,6 +185,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
27231 info.high_limit = mm->mmap_base;
27232 info.align_mask = filp ? get_align_mask() : 0;
27233 info.align_offset = pgoff << PAGE_SHIFT;
27234 + info.threadstack_offset = offset;
27235 addr = vm_unmapped_area(&info);
27236 if (!(addr & ~PAGE_MASK))
27237 return addr;
27238 diff --git a/arch/x86/kernel/tboot.c b/arch/x86/kernel/tboot.c
27239 index 91a4496..bb87552 100644
27240 --- a/arch/x86/kernel/tboot.c
27241 +++ b/arch/x86/kernel/tboot.c
27242 @@ -221,7 +221,7 @@ static int tboot_setup_sleep(void)
27243
27244 void tboot_shutdown(u32 shutdown_type)
27245 {
27246 - void (*shutdown)(void);
27247 + void (* __noreturn shutdown)(void);
27248
27249 if (!tboot_enabled())
27250 return;
27251 @@ -243,7 +243,7 @@ void tboot_shutdown(u32 shutdown_type)
27252
27253 switch_to_tboot_pt();
27254
27255 - shutdown = (void(*)(void))(unsigned long)tboot->shutdown_entry;
27256 + shutdown = (void *)(unsigned long)tboot->shutdown_entry;
27257 shutdown();
27258
27259 /* should not reach here */
27260 @@ -310,7 +310,7 @@ static int tboot_extended_sleep(u8 sleep_state, u32 val_a, u32 val_b)
27261 return -ENODEV;
27262 }
27263
27264 -static atomic_t ap_wfs_count;
27265 +static atomic_unchecked_t ap_wfs_count;
27266
27267 static int tboot_wait_for_aps(int num_aps)
27268 {
27269 @@ -334,9 +334,9 @@ static int tboot_cpu_callback(struct notifier_block *nfb, unsigned long action,
27270 {
27271 switch (action) {
27272 case CPU_DYING:
27273 - atomic_inc(&ap_wfs_count);
27274 + atomic_inc_unchecked(&ap_wfs_count);
27275 if (num_online_cpus() == 1)
27276 - if (tboot_wait_for_aps(atomic_read(&ap_wfs_count)))
27277 + if (tboot_wait_for_aps(atomic_read_unchecked(&ap_wfs_count)))
27278 return NOTIFY_BAD;
27279 break;
27280 }
27281 @@ -422,7 +422,7 @@ static __init int tboot_late_init(void)
27282
27283 tboot_create_trampoline();
27284
27285 - atomic_set(&ap_wfs_count, 0);
27286 + atomic_set_unchecked(&ap_wfs_count, 0);
27287 register_hotcpu_notifier(&tboot_cpu_notifier);
27288
27289 #ifdef CONFIG_DEBUG_FS
27290 diff --git a/arch/x86/kernel/time.c b/arch/x86/kernel/time.c
27291 index 24d3c91..d06b473 100644
27292 --- a/arch/x86/kernel/time.c
27293 +++ b/arch/x86/kernel/time.c
27294 @@ -30,9 +30,9 @@ unsigned long profile_pc(struct pt_regs *regs)
27295 {
27296 unsigned long pc = instruction_pointer(regs);
27297
27298 - if (!user_mode_vm(regs) && in_lock_functions(pc)) {
27299 + if (!user_mode(regs) && in_lock_functions(pc)) {
27300 #ifdef CONFIG_FRAME_POINTER
27301 - return *(unsigned long *)(regs->bp + sizeof(long));
27302 + return ktla_ktva(*(unsigned long *)(regs->bp + sizeof(long)));
27303 #else
27304 unsigned long *sp =
27305 (unsigned long *)kernel_stack_pointer(regs);
27306 @@ -41,11 +41,17 @@ unsigned long profile_pc(struct pt_regs *regs)
27307 * or above a saved flags. Eflags has bits 22-31 zero,
27308 * kernel addresses don't.
27309 */
27310 +
27311 +#ifdef CONFIG_PAX_KERNEXEC
27312 + return ktla_ktva(sp[0]);
27313 +#else
27314 if (sp[0] >> 22)
27315 return sp[0];
27316 if (sp[1] >> 22)
27317 return sp[1];
27318 #endif
27319 +
27320 +#endif
27321 }
27322 return pc;
27323 }
27324 diff --git a/arch/x86/kernel/tls.c b/arch/x86/kernel/tls.c
27325 index f7fec09..9991981 100644
27326 --- a/arch/x86/kernel/tls.c
27327 +++ b/arch/x86/kernel/tls.c
27328 @@ -84,6 +84,11 @@ int do_set_thread_area(struct task_struct *p, int idx,
27329 if (idx < GDT_ENTRY_TLS_MIN || idx > GDT_ENTRY_TLS_MAX)
27330 return -EINVAL;
27331
27332 +#ifdef CONFIG_PAX_SEGMEXEC
27333 + if ((p->mm->pax_flags & MF_PAX_SEGMEXEC) && (info.contents & MODIFY_LDT_CONTENTS_CODE))
27334 + return -EINVAL;
27335 +#endif
27336 +
27337 set_tls_desc(p, idx, &info, 1);
27338
27339 return 0;
27340 @@ -200,7 +205,7 @@ int regset_tls_set(struct task_struct *target, const struct user_regset *regset,
27341
27342 if (kbuf)
27343 info = kbuf;
27344 - else if (__copy_from_user(infobuf, ubuf, count))
27345 + else if (count > sizeof infobuf || __copy_from_user(infobuf, ubuf, count))
27346 return -EFAULT;
27347 else
27348 info = infobuf;
27349 diff --git a/arch/x86/kernel/tracepoint.c b/arch/x86/kernel/tracepoint.c
27350 index 1c113db..287b42e 100644
27351 --- a/arch/x86/kernel/tracepoint.c
27352 +++ b/arch/x86/kernel/tracepoint.c
27353 @@ -9,11 +9,11 @@
27354 #include <linux/atomic.h>
27355
27356 atomic_t trace_idt_ctr = ATOMIC_INIT(0);
27357 -struct desc_ptr trace_idt_descr = { NR_VECTORS * 16 - 1,
27358 +const struct desc_ptr trace_idt_descr = { NR_VECTORS * 16 - 1,
27359 (unsigned long) trace_idt_table };
27360
27361 /* No need to be aligned, but done to keep all IDTs defined the same way. */
27362 -gate_desc trace_idt_table[NR_VECTORS] __page_aligned_bss;
27363 +gate_desc trace_idt_table[NR_VECTORS] __page_aligned_rodata;
27364
27365 static int trace_irq_vector_refcount;
27366 static DEFINE_MUTEX(irq_vector_mutex);
27367 diff --git a/arch/x86/kernel/traps.c b/arch/x86/kernel/traps.c
27368 index b857ed8..51ae4cb 100644
27369 --- a/arch/x86/kernel/traps.c
27370 +++ b/arch/x86/kernel/traps.c
27371 @@ -66,7 +66,7 @@
27372 #include <asm/proto.h>
27373
27374 /* No need to be aligned, but done to keep all IDTs defined the same way. */
27375 -gate_desc debug_idt_table[NR_VECTORS] __page_aligned_bss;
27376 +gate_desc debug_idt_table[NR_VECTORS] __page_aligned_rodata;
27377 #else
27378 #include <asm/processor-flags.h>
27379 #include <asm/setup.h>
27380 @@ -75,7 +75,7 @@ asmlinkage int system_call(void);
27381 #endif
27382
27383 /* Must be page-aligned because the real IDT is used in a fixmap. */
27384 -gate_desc idt_table[NR_VECTORS] __page_aligned_bss;
27385 +gate_desc idt_table[NR_VECTORS] __page_aligned_rodata;
27386
27387 DECLARE_BITMAP(used_vectors, NR_VECTORS);
27388 EXPORT_SYMBOL_GPL(used_vectors);
27389 @@ -107,11 +107,11 @@ static inline void preempt_conditional_cli(struct pt_regs *regs)
27390 }
27391
27392 static int __kprobes
27393 -do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
27394 +do_trap_no_signal(struct task_struct *tsk, int trapnr, const char *str,
27395 struct pt_regs *regs, long error_code)
27396 {
27397 #ifdef CONFIG_X86_32
27398 - if (regs->flags & X86_VM_MASK) {
27399 + if (v8086_mode(regs)) {
27400 /*
27401 * Traps 0, 1, 3, 4, and 5 should be forwarded to vm86.
27402 * On nmi (interrupt 2), do_trap should not be called.
27403 @@ -124,12 +124,24 @@ do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
27404 return -1;
27405 }
27406 #endif
27407 - if (!user_mode(regs)) {
27408 + if (!user_mode_novm(regs)) {
27409 if (!fixup_exception(regs)) {
27410 tsk->thread.error_code = error_code;
27411 tsk->thread.trap_nr = trapnr;
27412 +
27413 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
27414 + if (trapnr == 12 && ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS))
27415 + str = "PAX: suspicious stack segment fault";
27416 +#endif
27417 +
27418 die(str, regs, error_code);
27419 }
27420 +
27421 +#ifdef CONFIG_PAX_REFCOUNT
27422 + if (trapnr == 4)
27423 + pax_report_refcount_overflow(regs);
27424 +#endif
27425 +
27426 return 0;
27427 }
27428
27429 @@ -137,7 +149,7 @@ do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
27430 }
27431
27432 static void __kprobes
27433 -do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
27434 +do_trap(int trapnr, int signr, const char *str, struct pt_regs *regs,
27435 long error_code, siginfo_t *info)
27436 {
27437 struct task_struct *tsk = current;
27438 @@ -161,7 +173,7 @@ do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
27439 if (show_unhandled_signals && unhandled_signal(tsk, signr) &&
27440 printk_ratelimit()) {
27441 pr_info("%s[%d] trap %s ip:%lx sp:%lx error:%lx",
27442 - tsk->comm, tsk->pid, str,
27443 + tsk->comm, task_pid_nr(tsk), str,
27444 regs->ip, regs->sp, error_code);
27445 print_vma_addr(" in ", regs->ip);
27446 pr_cont("\n");
27447 @@ -277,7 +289,7 @@ do_general_protection(struct pt_regs *regs, long error_code)
27448 conditional_sti(regs);
27449
27450 #ifdef CONFIG_X86_32
27451 - if (regs->flags & X86_VM_MASK) {
27452 + if (v8086_mode(regs)) {
27453 local_irq_enable();
27454 handle_vm86_fault((struct kernel_vm86_regs *) regs, error_code);
27455 goto exit;
27456 @@ -285,18 +297,42 @@ do_general_protection(struct pt_regs *regs, long error_code)
27457 #endif
27458
27459 tsk = current;
27460 - if (!user_mode(regs)) {
27461 + if (!user_mode_novm(regs)) {
27462 if (fixup_exception(regs))
27463 goto exit;
27464
27465 tsk->thread.error_code = error_code;
27466 tsk->thread.trap_nr = X86_TRAP_GP;
27467 if (notify_die(DIE_GPF, "general protection fault", regs, error_code,
27468 - X86_TRAP_GP, SIGSEGV) != NOTIFY_STOP)
27469 + X86_TRAP_GP, SIGSEGV) != NOTIFY_STOP) {
27470 +
27471 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
27472 + if ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS)
27473 + die("PAX: suspicious general protection fault", regs, error_code);
27474 + else
27475 +#endif
27476 +
27477 die("general protection fault", regs, error_code);
27478 + }
27479 goto exit;
27480 }
27481
27482 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
27483 + if (!(__supported_pte_mask & _PAGE_NX) && tsk->mm && (tsk->mm->pax_flags & MF_PAX_PAGEEXEC)) {
27484 + struct mm_struct *mm = tsk->mm;
27485 + unsigned long limit;
27486 +
27487 + down_write(&mm->mmap_sem);
27488 + limit = mm->context.user_cs_limit;
27489 + if (limit < TASK_SIZE) {
27490 + track_exec_limit(mm, limit, TASK_SIZE, VM_EXEC);
27491 + up_write(&mm->mmap_sem);
27492 + return;
27493 + }
27494 + up_write(&mm->mmap_sem);
27495 + }
27496 +#endif
27497 +
27498 tsk->thread.error_code = error_code;
27499 tsk->thread.trap_nr = X86_TRAP_GP;
27500
27501 @@ -457,7 +493,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
27502 /* It's safe to allow irq's after DR6 has been saved */
27503 preempt_conditional_sti(regs);
27504
27505 - if (regs->flags & X86_VM_MASK) {
27506 + if (v8086_mode(regs)) {
27507 handle_vm86_trap((struct kernel_vm86_regs *) regs, error_code,
27508 X86_TRAP_DB);
27509 preempt_conditional_cli(regs);
27510 @@ -472,7 +508,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
27511 * We already checked v86 mode above, so we can check for kernel mode
27512 * by just checking the CPL of CS.
27513 */
27514 - if ((dr6 & DR_STEP) && !user_mode(regs)) {
27515 + if ((dr6 & DR_STEP) && !user_mode_novm(regs)) {
27516 tsk->thread.debugreg6 &= ~DR_STEP;
27517 set_tsk_thread_flag(tsk, TIF_SINGLESTEP);
27518 regs->flags &= ~X86_EFLAGS_TF;
27519 @@ -504,7 +540,7 @@ void math_error(struct pt_regs *regs, int error_code, int trapnr)
27520 return;
27521 conditional_sti(regs);
27522
27523 - if (!user_mode_vm(regs))
27524 + if (!user_mode(regs))
27525 {
27526 if (!fixup_exception(regs)) {
27527 task->thread.error_code = error_code;
27528 diff --git a/arch/x86/kernel/uprobes.c b/arch/x86/kernel/uprobes.c
27529 index 2ed8459..7cf329f 100644
27530 --- a/arch/x86/kernel/uprobes.c
27531 +++ b/arch/x86/kernel/uprobes.c
27532 @@ -629,7 +629,7 @@ int arch_uprobe_exception_notify(struct notifier_block *self, unsigned long val,
27533 int ret = NOTIFY_DONE;
27534
27535 /* We are only interested in userspace traps */
27536 - if (regs && !user_mode_vm(regs))
27537 + if (regs && !user_mode(regs))
27538 return NOTIFY_DONE;
27539
27540 switch (val) {
27541 @@ -719,7 +719,7 @@ arch_uretprobe_hijack_return_addr(unsigned long trampoline_vaddr, struct pt_regs
27542
27543 if (ncopied != rasize) {
27544 pr_err("uprobe: return address clobbered: pid=%d, %%sp=%#lx, "
27545 - "%%ip=%#lx\n", current->pid, regs->sp, regs->ip);
27546 + "%%ip=%#lx\n", task_pid_nr(current), regs->sp, regs->ip);
27547
27548 force_sig_info(SIGSEGV, SEND_SIG_FORCED, current);
27549 }
27550 diff --git a/arch/x86/kernel/verify_cpu.S b/arch/x86/kernel/verify_cpu.S
27551 index b9242ba..50c5edd 100644
27552 --- a/arch/x86/kernel/verify_cpu.S
27553 +++ b/arch/x86/kernel/verify_cpu.S
27554 @@ -20,6 +20,7 @@
27555 * arch/x86/boot/compressed/head_64.S: Boot cpu verification
27556 * arch/x86/kernel/trampoline_64.S: secondary processor verification
27557 * arch/x86/kernel/head_32.S: processor startup
27558 + * arch/x86/kernel/acpi/realmode/wakeup.S: 32bit processor resume
27559 *
27560 * verify_cpu, returns the status of longmode and SSE in register %eax.
27561 * 0: Success 1: Failure
27562 diff --git a/arch/x86/kernel/vm86_32.c b/arch/x86/kernel/vm86_32.c
27563 index e8edcf5..27f9344 100644
27564 --- a/arch/x86/kernel/vm86_32.c
27565 +++ b/arch/x86/kernel/vm86_32.c
27566 @@ -44,6 +44,7 @@
27567 #include <linux/ptrace.h>
27568 #include <linux/audit.h>
27569 #include <linux/stddef.h>
27570 +#include <linux/grsecurity.h>
27571
27572 #include <asm/uaccess.h>
27573 #include <asm/io.h>
27574 @@ -150,7 +151,7 @@ struct pt_regs *save_v86_state(struct kernel_vm86_regs *regs)
27575 do_exit(SIGSEGV);
27576 }
27577
27578 - tss = &per_cpu(init_tss, get_cpu());
27579 + tss = init_tss + get_cpu();
27580 current->thread.sp0 = current->thread.saved_sp0;
27581 current->thread.sysenter_cs = __KERNEL_CS;
27582 load_sp0(tss, &current->thread);
27583 @@ -214,6 +215,14 @@ SYSCALL_DEFINE1(vm86old, struct vm86_struct __user *, v86)
27584
27585 if (tsk->thread.saved_sp0)
27586 return -EPERM;
27587 +
27588 +#ifdef CONFIG_GRKERNSEC_VM86
27589 + if (!capable(CAP_SYS_RAWIO)) {
27590 + gr_handle_vm86();
27591 + return -EPERM;
27592 + }
27593 +#endif
27594 +
27595 tmp = copy_vm86_regs_from_user(&info.regs, &v86->regs,
27596 offsetof(struct kernel_vm86_struct, vm86plus) -
27597 sizeof(info.regs));
27598 @@ -238,6 +247,13 @@ SYSCALL_DEFINE2(vm86, unsigned long, cmd, unsigned long, arg)
27599 int tmp;
27600 struct vm86plus_struct __user *v86;
27601
27602 +#ifdef CONFIG_GRKERNSEC_VM86
27603 + if (!capable(CAP_SYS_RAWIO)) {
27604 + gr_handle_vm86();
27605 + return -EPERM;
27606 + }
27607 +#endif
27608 +
27609 tsk = current;
27610 switch (cmd) {
27611 case VM86_REQUEST_IRQ:
27612 @@ -318,7 +334,7 @@ static void do_sys_vm86(struct kernel_vm86_struct *info, struct task_struct *tsk
27613 tsk->thread.saved_fs = info->regs32->fs;
27614 tsk->thread.saved_gs = get_user_gs(info->regs32);
27615
27616 - tss = &per_cpu(init_tss, get_cpu());
27617 + tss = init_tss + get_cpu();
27618 tsk->thread.sp0 = (unsigned long) &info->VM86_TSS_ESP0;
27619 if (cpu_has_sep)
27620 tsk->thread.sysenter_cs = 0;
27621 @@ -525,7 +541,7 @@ static void do_int(struct kernel_vm86_regs *regs, int i,
27622 goto cannot_handle;
27623 if (i == 0x21 && is_revectored(AH(regs), &KVM86->int21_revectored))
27624 goto cannot_handle;
27625 - intr_ptr = (unsigned long __user *) (i << 2);
27626 + intr_ptr = (__force unsigned long __user *) (i << 2);
27627 if (get_user(segoffs, intr_ptr))
27628 goto cannot_handle;
27629 if ((segoffs >> 16) == BIOSSEG)
27630 diff --git a/arch/x86/kernel/vmlinux.lds.S b/arch/x86/kernel/vmlinux.lds.S
27631 index da6b35a..977e9cf 100644
27632 --- a/arch/x86/kernel/vmlinux.lds.S
27633 +++ b/arch/x86/kernel/vmlinux.lds.S
27634 @@ -26,6 +26,13 @@
27635 #include <asm/page_types.h>
27636 #include <asm/cache.h>
27637 #include <asm/boot.h>
27638 +#include <asm/segment.h>
27639 +
27640 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
27641 +#define __KERNEL_TEXT_OFFSET (LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR)
27642 +#else
27643 +#define __KERNEL_TEXT_OFFSET 0
27644 +#endif
27645
27646 #undef i386 /* in case the preprocessor is a 32bit one */
27647
27648 @@ -69,30 +76,43 @@ jiffies_64 = jiffies;
27649
27650 PHDRS {
27651 text PT_LOAD FLAGS(5); /* R_E */
27652 +#ifdef CONFIG_X86_32
27653 + module PT_LOAD FLAGS(5); /* R_E */
27654 +#endif
27655 +#ifdef CONFIG_XEN
27656 + rodata PT_LOAD FLAGS(5); /* R_E */
27657 +#else
27658 + rodata PT_LOAD FLAGS(4); /* R__ */
27659 +#endif
27660 data PT_LOAD FLAGS(6); /* RW_ */
27661 -#ifdef CONFIG_X86_64
27662 + init.begin PT_LOAD FLAGS(6); /* RW_ */
27663 #ifdef CONFIG_SMP
27664 percpu PT_LOAD FLAGS(6); /* RW_ */
27665 #endif
27666 + text.init PT_LOAD FLAGS(5); /* R_E */
27667 + text.exit PT_LOAD FLAGS(5); /* R_E */
27668 init PT_LOAD FLAGS(7); /* RWE */
27669 -#endif
27670 note PT_NOTE FLAGS(0); /* ___ */
27671 }
27672
27673 SECTIONS
27674 {
27675 #ifdef CONFIG_X86_32
27676 - . = LOAD_OFFSET + LOAD_PHYSICAL_ADDR;
27677 - phys_startup_32 = startup_32 - LOAD_OFFSET;
27678 + . = LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR;
27679 #else
27680 - . = __START_KERNEL;
27681 - phys_startup_64 = startup_64 - LOAD_OFFSET;
27682 + . = __START_KERNEL;
27683 #endif
27684
27685 /* Text and read-only data */
27686 - .text : AT(ADDR(.text) - LOAD_OFFSET) {
27687 - _text = .;
27688 + .text (. - __KERNEL_TEXT_OFFSET): AT(ADDR(.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
27689 /* bootstrapping code */
27690 +#ifdef CONFIG_X86_32
27691 + phys_startup_32 = startup_32 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
27692 +#else
27693 + phys_startup_64 = startup_64 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
27694 +#endif
27695 + __LOAD_PHYSICAL_ADDR = . - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
27696 + _text = .;
27697 HEAD_TEXT
27698 . = ALIGN(8);
27699 _stext = .;
27700 @@ -104,13 +124,47 @@ SECTIONS
27701 IRQENTRY_TEXT
27702 *(.fixup)
27703 *(.gnu.warning)
27704 - /* End of text section */
27705 - _etext = .;
27706 } :text = 0x9090
27707
27708 - NOTES :text :note
27709 + . += __KERNEL_TEXT_OFFSET;
27710
27711 - EXCEPTION_TABLE(16) :text = 0x9090
27712 +#ifdef CONFIG_X86_32
27713 + . = ALIGN(PAGE_SIZE);
27714 + .module.text : AT(ADDR(.module.text) - LOAD_OFFSET) {
27715 +
27716 +#ifdef CONFIG_PAX_KERNEXEC
27717 + MODULES_EXEC_VADDR = .;
27718 + BYTE(0)
27719 + . += (CONFIG_PAX_KERNEXEC_MODULE_TEXT * 1024 * 1024);
27720 + . = ALIGN(HPAGE_SIZE) - 1;
27721 + MODULES_EXEC_END = .;
27722 +#endif
27723 +
27724 + } :module
27725 +#endif
27726 +
27727 + .text.end : AT(ADDR(.text.end) - LOAD_OFFSET) {
27728 + /* End of text section */
27729 + BYTE(0)
27730 + _etext = . - __KERNEL_TEXT_OFFSET;
27731 + }
27732 +
27733 +#ifdef CONFIG_X86_32
27734 + . = ALIGN(PAGE_SIZE);
27735 + .rodata.page_aligned : AT(ADDR(.rodata.page_aligned) - LOAD_OFFSET) {
27736 + . = ALIGN(PAGE_SIZE);
27737 + *(.empty_zero_page)
27738 + *(.initial_pg_fixmap)
27739 + *(.initial_pg_pmd)
27740 + *(.initial_page_table)
27741 + *(.swapper_pg_dir)
27742 + } :rodata
27743 +#endif
27744 +
27745 + . = ALIGN(PAGE_SIZE);
27746 + NOTES :rodata :note
27747 +
27748 + EXCEPTION_TABLE(16) :rodata
27749
27750 #if defined(CONFIG_DEBUG_RODATA)
27751 /* .text should occupy whole number of pages */
27752 @@ -122,16 +176,20 @@ SECTIONS
27753
27754 /* Data */
27755 .data : AT(ADDR(.data) - LOAD_OFFSET) {
27756 +
27757 +#ifdef CONFIG_PAX_KERNEXEC
27758 + . = ALIGN(HPAGE_SIZE);
27759 +#else
27760 + . = ALIGN(PAGE_SIZE);
27761 +#endif
27762 +
27763 /* Start of data section */
27764 _sdata = .;
27765
27766 /* init_task */
27767 INIT_TASK_DATA(THREAD_SIZE)
27768
27769 -#ifdef CONFIG_X86_32
27770 - /* 32 bit has nosave before _edata */
27771 NOSAVE_DATA
27772 -#endif
27773
27774 PAGE_ALIGNED_DATA(PAGE_SIZE)
27775
27776 @@ -172,12 +230,19 @@ SECTIONS
27777 #endif /* CONFIG_X86_64 */
27778
27779 /* Init code and data - will be freed after init */
27780 - . = ALIGN(PAGE_SIZE);
27781 .init.begin : AT(ADDR(.init.begin) - LOAD_OFFSET) {
27782 + BYTE(0)
27783 +
27784 +#ifdef CONFIG_PAX_KERNEXEC
27785 + . = ALIGN(HPAGE_SIZE);
27786 +#else
27787 + . = ALIGN(PAGE_SIZE);
27788 +#endif
27789 +
27790 __init_begin = .; /* paired with __init_end */
27791 - }
27792 + } :init.begin
27793
27794 -#if defined(CONFIG_X86_64) && defined(CONFIG_SMP)
27795 +#ifdef CONFIG_SMP
27796 /*
27797 * percpu offsets are zero-based on SMP. PERCPU_VADDR() changes the
27798 * output PHDR, so the next output section - .init.text - should
27799 @@ -186,12 +251,27 @@ SECTIONS
27800 PERCPU_VADDR(INTERNODE_CACHE_BYTES, 0, :percpu)
27801 #endif
27802
27803 - INIT_TEXT_SECTION(PAGE_SIZE)
27804 -#ifdef CONFIG_X86_64
27805 - :init
27806 -#endif
27807 + . = ALIGN(PAGE_SIZE);
27808 + init_begin = .;
27809 + .init.text (. - __KERNEL_TEXT_OFFSET): AT(init_begin - LOAD_OFFSET) {
27810 + VMLINUX_SYMBOL(_sinittext) = .;
27811 + INIT_TEXT
27812 + VMLINUX_SYMBOL(_einittext) = .;
27813 + . = ALIGN(PAGE_SIZE);
27814 + } :text.init
27815
27816 - INIT_DATA_SECTION(16)
27817 + /*
27818 + * .exit.text is discard at runtime, not link time, to deal with
27819 + * references from .altinstructions and .eh_frame
27820 + */
27821 + .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
27822 + EXIT_TEXT
27823 + . = ALIGN(16);
27824 + } :text.exit
27825 + . = init_begin + SIZEOF(.init.text) + SIZEOF(.exit.text);
27826 +
27827 + . = ALIGN(PAGE_SIZE);
27828 + INIT_DATA_SECTION(16) :init
27829
27830 .x86_cpu_dev.init : AT(ADDR(.x86_cpu_dev.init) - LOAD_OFFSET) {
27831 __x86_cpu_dev_start = .;
27832 @@ -262,19 +342,12 @@ SECTIONS
27833 }
27834
27835 . = ALIGN(8);
27836 - /*
27837 - * .exit.text is discard at runtime, not link time, to deal with
27838 - * references from .altinstructions and .eh_frame
27839 - */
27840 - .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET) {
27841 - EXIT_TEXT
27842 - }
27843
27844 .exit.data : AT(ADDR(.exit.data) - LOAD_OFFSET) {
27845 EXIT_DATA
27846 }
27847
27848 -#if !defined(CONFIG_X86_64) || !defined(CONFIG_SMP)
27849 +#ifndef CONFIG_SMP
27850 PERCPU_SECTION(INTERNODE_CACHE_BYTES)
27851 #endif
27852
27853 @@ -293,16 +366,10 @@ SECTIONS
27854 .smp_locks : AT(ADDR(.smp_locks) - LOAD_OFFSET) {
27855 __smp_locks = .;
27856 *(.smp_locks)
27857 - . = ALIGN(PAGE_SIZE);
27858 __smp_locks_end = .;
27859 + . = ALIGN(PAGE_SIZE);
27860 }
27861
27862 -#ifdef CONFIG_X86_64
27863 - .data_nosave : AT(ADDR(.data_nosave) - LOAD_OFFSET) {
27864 - NOSAVE_DATA
27865 - }
27866 -#endif
27867 -
27868 /* BSS */
27869 . = ALIGN(PAGE_SIZE);
27870 .bss : AT(ADDR(.bss) - LOAD_OFFSET) {
27871 @@ -318,6 +385,7 @@ SECTIONS
27872 __brk_base = .;
27873 . += 64 * 1024; /* 64k alignment slop space */
27874 *(.brk_reservation) /* areas brk users have reserved */
27875 + . = ALIGN(HPAGE_SIZE);
27876 __brk_limit = .;
27877 }
27878
27879 @@ -344,13 +412,12 @@ SECTIONS
27880 * for the boot processor.
27881 */
27882 #define INIT_PER_CPU(x) init_per_cpu__##x = x + __per_cpu_load
27883 -INIT_PER_CPU(gdt_page);
27884 INIT_PER_CPU(irq_stack_union);
27885
27886 /*
27887 * Build-time check on the image size:
27888 */
27889 -. = ASSERT((_end - _text <= KERNEL_IMAGE_SIZE),
27890 +. = ASSERT((_end - _text - __KERNEL_TEXT_OFFSET <= KERNEL_IMAGE_SIZE),
27891 "kernel image bigger than KERNEL_IMAGE_SIZE");
27892
27893 #ifdef CONFIG_SMP
27894 diff --git a/arch/x86/kernel/vsyscall_64.c b/arch/x86/kernel/vsyscall_64.c
27895 index 1f96f93..d5c8f7a 100644
27896 --- a/arch/x86/kernel/vsyscall_64.c
27897 +++ b/arch/x86/kernel/vsyscall_64.c
27898 @@ -56,15 +56,13 @@
27899 DEFINE_VVAR(int, vgetcpu_mode);
27900 DEFINE_VVAR(struct vsyscall_gtod_data, vsyscall_gtod_data);
27901
27902 -static enum { EMULATE, NATIVE, NONE } vsyscall_mode = EMULATE;
27903 +static enum { EMULATE, NONE } vsyscall_mode = EMULATE;
27904
27905 static int __init vsyscall_setup(char *str)
27906 {
27907 if (str) {
27908 if (!strcmp("emulate", str))
27909 vsyscall_mode = EMULATE;
27910 - else if (!strcmp("native", str))
27911 - vsyscall_mode = NATIVE;
27912 else if (!strcmp("none", str))
27913 vsyscall_mode = NONE;
27914 else
27915 @@ -323,8 +321,7 @@ do_ret:
27916 return true;
27917
27918 sigsegv:
27919 - force_sig(SIGSEGV, current);
27920 - return true;
27921 + do_group_exit(SIGKILL);
27922 }
27923
27924 /*
27925 @@ -377,10 +374,7 @@ void __init map_vsyscall(void)
27926 extern char __vvar_page;
27927 unsigned long physaddr_vvar_page = __pa_symbol(&__vvar_page);
27928
27929 - __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_vsyscall,
27930 - vsyscall_mode == NATIVE
27931 - ? PAGE_KERNEL_VSYSCALL
27932 - : PAGE_KERNEL_VVAR);
27933 + __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_vsyscall, PAGE_KERNEL_VVAR);
27934 BUILD_BUG_ON((unsigned long)__fix_to_virt(VSYSCALL_FIRST_PAGE) !=
27935 (unsigned long)VSYSCALL_START);
27936
27937 diff --git a/arch/x86/kernel/x8664_ksyms_64.c b/arch/x86/kernel/x8664_ksyms_64.c
27938 index 04068192..4d75aa6 100644
27939 --- a/arch/x86/kernel/x8664_ksyms_64.c
27940 +++ b/arch/x86/kernel/x8664_ksyms_64.c
27941 @@ -34,8 +34,6 @@ EXPORT_SYMBOL(copy_user_generic_string);
27942 EXPORT_SYMBOL(copy_user_generic_unrolled);
27943 EXPORT_SYMBOL(copy_user_enhanced_fast_string);
27944 EXPORT_SYMBOL(__copy_user_nocache);
27945 -EXPORT_SYMBOL(_copy_from_user);
27946 -EXPORT_SYMBOL(_copy_to_user);
27947
27948 EXPORT_SYMBOL(copy_page);
27949 EXPORT_SYMBOL(clear_page);
27950 @@ -73,3 +71,7 @@ EXPORT_SYMBOL(___preempt_schedule);
27951 EXPORT_SYMBOL(___preempt_schedule_context);
27952 #endif
27953 #endif
27954 +
27955 +#ifdef CONFIG_PAX_PER_CPU_PGD
27956 +EXPORT_SYMBOL(cpu_pgd);
27957 +#endif
27958 diff --git a/arch/x86/kernel/x86_init.c b/arch/x86/kernel/x86_init.c
27959 index 021783b..6511282 100644
27960 --- a/arch/x86/kernel/x86_init.c
27961 +++ b/arch/x86/kernel/x86_init.c
27962 @@ -93,7 +93,7 @@ struct x86_cpuinit_ops x86_cpuinit = {
27963 static void default_nmi_init(void) { };
27964 static int default_i8042_detect(void) { return 1; };
27965
27966 -struct x86_platform_ops x86_platform = {
27967 +struct x86_platform_ops x86_platform __read_only = {
27968 .calibrate_tsc = native_calibrate_tsc,
27969 .get_wallclock = mach_get_cmos_time,
27970 .set_wallclock = mach_set_rtc_mmss,
27971 @@ -109,7 +109,7 @@ struct x86_platform_ops x86_platform = {
27972 EXPORT_SYMBOL_GPL(x86_platform);
27973
27974 #if defined(CONFIG_PCI_MSI)
27975 -struct x86_msi_ops x86_msi = {
27976 +struct x86_msi_ops x86_msi __read_only = {
27977 .setup_msi_irqs = native_setup_msi_irqs,
27978 .compose_msi_msg = native_compose_msi_msg,
27979 .teardown_msi_irq = native_teardown_msi_irq,
27980 @@ -150,7 +150,7 @@ u32 arch_msix_mask_irq(struct msi_desc *desc, u32 flag)
27981 }
27982 #endif
27983
27984 -struct x86_io_apic_ops x86_io_apic_ops = {
27985 +struct x86_io_apic_ops x86_io_apic_ops __read_only = {
27986 .init = native_io_apic_init_mappings,
27987 .read = native_io_apic_read,
27988 .write = native_io_apic_write,
27989 diff --git a/arch/x86/kernel/xsave.c b/arch/x86/kernel/xsave.c
27990 index 422fd82..b2d262e 100644
27991 --- a/arch/x86/kernel/xsave.c
27992 +++ b/arch/x86/kernel/xsave.c
27993 @@ -164,18 +164,18 @@ static inline int save_xstate_epilog(void __user *buf, int ia32_frame)
27994
27995 /* Setup the bytes not touched by the [f]xsave and reserved for SW. */
27996 sw_bytes = ia32_frame ? &fx_sw_reserved_ia32 : &fx_sw_reserved;
27997 - err = __copy_to_user(&x->i387.sw_reserved, sw_bytes, sizeof(*sw_bytes));
27998 + err = __copy_to_user(x->i387.sw_reserved, sw_bytes, sizeof(*sw_bytes));
27999
28000 if (!use_xsave())
28001 return err;
28002
28003 - err |= __put_user(FP_XSTATE_MAGIC2, (__u32 *)(buf + xstate_size));
28004 + err |= __put_user(FP_XSTATE_MAGIC2, (__u32 __user *)(buf + xstate_size));
28005
28006 /*
28007 * Read the xstate_bv which we copied (directly from the cpu or
28008 * from the state in task struct) to the user buffers.
28009 */
28010 - err |= __get_user(xstate_bv, (__u32 *)&x->xsave_hdr.xstate_bv);
28011 + err |= __get_user(xstate_bv, (__u32 __user *)&x->xsave_hdr.xstate_bv);
28012
28013 /*
28014 * For legacy compatible, we always set FP/SSE bits in the bit
28015 @@ -190,7 +190,7 @@ static inline int save_xstate_epilog(void __user *buf, int ia32_frame)
28016 */
28017 xstate_bv |= XSTATE_FPSSE;
28018
28019 - err |= __put_user(xstate_bv, (__u32 *)&x->xsave_hdr.xstate_bv);
28020 + err |= __put_user(xstate_bv, (__u32 __user *)&x->xsave_hdr.xstate_bv);
28021
28022 return err;
28023 }
28024 @@ -199,6 +199,7 @@ static inline int save_user_xstate(struct xsave_struct __user *buf)
28025 {
28026 int err;
28027
28028 + buf = (struct xsave_struct __user *)____m(buf);
28029 if (use_xsave())
28030 err = xsave_user(buf);
28031 else if (use_fxsr())
28032 @@ -311,6 +312,7 @@ sanitize_restored_xstate(struct task_struct *tsk,
28033 */
28034 static inline int restore_user_xstate(void __user *buf, u64 xbv, int fx_only)
28035 {
28036 + buf = (void __user *)____m(buf);
28037 if (use_xsave()) {
28038 if ((unsigned long)buf % 64 || fx_only) {
28039 u64 init_bv = pcntxt_mask & ~XSTATE_FPSSE;
28040 diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c
28041 index c697625..a032162 100644
28042 --- a/arch/x86/kvm/cpuid.c
28043 +++ b/arch/x86/kvm/cpuid.c
28044 @@ -156,15 +156,20 @@ int kvm_vcpu_ioctl_set_cpuid2(struct kvm_vcpu *vcpu,
28045 struct kvm_cpuid2 *cpuid,
28046 struct kvm_cpuid_entry2 __user *entries)
28047 {
28048 - int r;
28049 + int r, i;
28050
28051 r = -E2BIG;
28052 if (cpuid->nent > KVM_MAX_CPUID_ENTRIES)
28053 goto out;
28054 r = -EFAULT;
28055 - if (copy_from_user(&vcpu->arch.cpuid_entries, entries,
28056 - cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
28057 + if (!access_ok(VERIFY_READ, entries, cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
28058 goto out;
28059 + for (i = 0; i < cpuid->nent; ++i) {
28060 + struct kvm_cpuid_entry2 cpuid_entry;
28061 + if (__copy_from_user(&cpuid_entry, entries + i, sizeof(cpuid_entry)))
28062 + goto out;
28063 + vcpu->arch.cpuid_entries[i] = cpuid_entry;
28064 + }
28065 vcpu->arch.cpuid_nent = cpuid->nent;
28066 kvm_apic_set_version(vcpu);
28067 kvm_x86_ops->cpuid_update(vcpu);
28068 @@ -179,15 +184,19 @@ int kvm_vcpu_ioctl_get_cpuid2(struct kvm_vcpu *vcpu,
28069 struct kvm_cpuid2 *cpuid,
28070 struct kvm_cpuid_entry2 __user *entries)
28071 {
28072 - int r;
28073 + int r, i;
28074
28075 r = -E2BIG;
28076 if (cpuid->nent < vcpu->arch.cpuid_nent)
28077 goto out;
28078 r = -EFAULT;
28079 - if (copy_to_user(entries, &vcpu->arch.cpuid_entries,
28080 - vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
28081 + if (!access_ok(VERIFY_WRITE, entries, vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
28082 goto out;
28083 + for (i = 0; i < vcpu->arch.cpuid_nent; ++i) {
28084 + struct kvm_cpuid_entry2 cpuid_entry = vcpu->arch.cpuid_entries[i];
28085 + if (__copy_to_user(entries + i, &cpuid_entry, sizeof(cpuid_entry)))
28086 + goto out;
28087 + }
28088 return 0;
28089
28090 out:
28091 diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c
28092 index d86ff15..e77b023 100644
28093 --- a/arch/x86/kvm/lapic.c
28094 +++ b/arch/x86/kvm/lapic.c
28095 @@ -55,7 +55,7 @@
28096 #define APIC_BUS_CYCLE_NS 1
28097
28098 /* #define apic_debug(fmt,arg...) printk(KERN_WARNING fmt,##arg) */
28099 -#define apic_debug(fmt, arg...)
28100 +#define apic_debug(fmt, arg...) do {} while (0)
28101
28102 #define APIC_LVT_NUM 6
28103 /* 14 is the version for Xeon and Pentium 8.4.8*/
28104 diff --git a/arch/x86/kvm/paging_tmpl.h b/arch/x86/kvm/paging_tmpl.h
28105 index cba218a..1cc1bed 100644
28106 --- a/arch/x86/kvm/paging_tmpl.h
28107 +++ b/arch/x86/kvm/paging_tmpl.h
28108 @@ -331,7 +331,7 @@ retry_walk:
28109 if (unlikely(kvm_is_error_hva(host_addr)))
28110 goto error;
28111
28112 - ptep_user = (pt_element_t __user *)((void *)host_addr + offset);
28113 + ptep_user = (pt_element_t __force_user *)((void *)host_addr + offset);
28114 if (unlikely(__copy_from_user(&pte, ptep_user, sizeof(pte))))
28115 goto error;
28116 walker->ptep_user[walker->level - 1] = ptep_user;
28117 diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
28118 index 532add1..59eb241 100644
28119 --- a/arch/x86/kvm/svm.c
28120 +++ b/arch/x86/kvm/svm.c
28121 @@ -3495,7 +3495,11 @@ static void reload_tss(struct kvm_vcpu *vcpu)
28122 int cpu = raw_smp_processor_id();
28123
28124 struct svm_cpu_data *sd = per_cpu(svm_data, cpu);
28125 +
28126 + pax_open_kernel();
28127 sd->tss_desc->type = 9; /* available 32/64-bit TSS */
28128 + pax_close_kernel();
28129 +
28130 load_TR_desc();
28131 }
28132
28133 @@ -3898,6 +3902,10 @@ static void svm_vcpu_run(struct kvm_vcpu *vcpu)
28134 #endif
28135 #endif
28136
28137 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
28138 + __set_fs(current_thread_info()->addr_limit);
28139 +#endif
28140 +
28141 reload_tss(vcpu);
28142
28143 local_irq_disable();
28144 diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
28145 index 31c3e8b..ca3acc6 100644
28146 --- a/arch/x86/kvm/vmx.c
28147 +++ b/arch/x86/kvm/vmx.c
28148 @@ -1316,12 +1316,12 @@ static void vmcs_write64(unsigned long field, u64 value)
28149 #endif
28150 }
28151
28152 -static void vmcs_clear_bits(unsigned long field, u32 mask)
28153 +static void vmcs_clear_bits(unsigned long field, unsigned long mask)
28154 {
28155 vmcs_writel(field, vmcs_readl(field) & ~mask);
28156 }
28157
28158 -static void vmcs_set_bits(unsigned long field, u32 mask)
28159 +static void vmcs_set_bits(unsigned long field, unsigned long mask)
28160 {
28161 vmcs_writel(field, vmcs_readl(field) | mask);
28162 }
28163 @@ -1522,7 +1522,11 @@ static void reload_tss(void)
28164 struct desc_struct *descs;
28165
28166 descs = (void *)gdt->address;
28167 +
28168 + pax_open_kernel();
28169 descs[GDT_ENTRY_TSS].type = 9; /* available TSS */
28170 + pax_close_kernel();
28171 +
28172 load_TR_desc();
28173 }
28174
28175 @@ -1746,6 +1750,10 @@ static void vmx_vcpu_load(struct kvm_vcpu *vcpu, int cpu)
28176 vmcs_writel(HOST_TR_BASE, kvm_read_tr_base()); /* 22.2.4 */
28177 vmcs_writel(HOST_GDTR_BASE, gdt->address); /* 22.2.4 */
28178
28179 +#ifdef CONFIG_PAX_PER_CPU_PGD
28180 + vmcs_writel(HOST_CR3, read_cr3()); /* 22.2.3 FIXME: shadow tables */
28181 +#endif
28182 +
28183 rdmsrl(MSR_IA32_SYSENTER_ESP, sysenter_esp);
28184 vmcs_writel(HOST_IA32_SYSENTER_ESP, sysenter_esp); /* 22.2.3 */
28185 vmx->loaded_vmcs->cpu = cpu;
28186 @@ -2033,7 +2041,7 @@ static void setup_msrs(struct vcpu_vmx *vmx)
28187 * reads and returns guest's timestamp counter "register"
28188 * guest_tsc = host_tsc + tsc_offset -- 21.3
28189 */
28190 -static u64 guest_read_tsc(void)
28191 +static u64 __intentional_overflow(-1) guest_read_tsc(void)
28192 {
28193 u64 host_tsc, tsc_offset;
28194
28195 @@ -2987,8 +2995,11 @@ static __init int hardware_setup(void)
28196 if (!cpu_has_vmx_flexpriority())
28197 flexpriority_enabled = 0;
28198
28199 - if (!cpu_has_vmx_tpr_shadow())
28200 - kvm_x86_ops->update_cr8_intercept = NULL;
28201 + if (!cpu_has_vmx_tpr_shadow()) {
28202 + pax_open_kernel();
28203 + *(void **)&kvm_x86_ops->update_cr8_intercept = NULL;
28204 + pax_close_kernel();
28205 + }
28206
28207 if (enable_ept && !cpu_has_vmx_ept_2m_page())
28208 kvm_disable_largepages();
28209 @@ -2999,13 +3010,15 @@ static __init int hardware_setup(void)
28210 if (!cpu_has_vmx_apicv())
28211 enable_apicv = 0;
28212
28213 + pax_open_kernel();
28214 if (enable_apicv)
28215 - kvm_x86_ops->update_cr8_intercept = NULL;
28216 + *(void **)&kvm_x86_ops->update_cr8_intercept = NULL;
28217 else {
28218 - kvm_x86_ops->hwapic_irr_update = NULL;
28219 - kvm_x86_ops->deliver_posted_interrupt = NULL;
28220 - kvm_x86_ops->sync_pir_to_irr = vmx_sync_pir_to_irr_dummy;
28221 + *(void **)&kvm_x86_ops->hwapic_irr_update = NULL;
28222 + *(void **)&kvm_x86_ops->deliver_posted_interrupt = NULL;
28223 + *(void **)&kvm_x86_ops->sync_pir_to_irr = vmx_sync_pir_to_irr_dummy;
28224 }
28225 + pax_close_kernel();
28226
28227 if (nested)
28228 nested_vmx_setup_ctls_msrs();
28229 @@ -4134,7 +4147,10 @@ static void vmx_set_constant_host_state(struct vcpu_vmx *vmx)
28230
28231 vmcs_writel(HOST_CR0, read_cr0() & ~X86_CR0_TS); /* 22.2.3 */
28232 vmcs_writel(HOST_CR4, read_cr4()); /* 22.2.3, 22.2.5 */
28233 +
28234 +#ifndef CONFIG_PAX_PER_CPU_PGD
28235 vmcs_writel(HOST_CR3, read_cr3()); /* 22.2.3 FIXME: shadow tables */
28236 +#endif
28237
28238 vmcs_write16(HOST_CS_SELECTOR, __KERNEL_CS); /* 22.2.4 */
28239 #ifdef CONFIG_X86_64
28240 @@ -4156,7 +4172,7 @@ static void vmx_set_constant_host_state(struct vcpu_vmx *vmx)
28241 vmcs_writel(HOST_IDTR_BASE, dt.address); /* 22.2.4 */
28242 vmx->host_idt_base = dt.address;
28243
28244 - vmcs_writel(HOST_RIP, vmx_return); /* 22.2.5 */
28245 + vmcs_writel(HOST_RIP, ktla_ktva(vmx_return)); /* 22.2.5 */
28246
28247 rdmsr(MSR_IA32_SYSENTER_CS, low32, high32);
28248 vmcs_write32(HOST_IA32_SYSENTER_CS, low32);
28249 @@ -7219,6 +7235,12 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
28250 "jmp 2f \n\t"
28251 "1: " __ex(ASM_VMX_VMRESUME) "\n\t"
28252 "2: "
28253 +
28254 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
28255 + "ljmp %[cs],$3f\n\t"
28256 + "3: "
28257 +#endif
28258 +
28259 /* Save guest registers, load host registers, keep flags */
28260 "mov %0, %c[wordsize](%%" _ASM_SP ") \n\t"
28261 "pop %0 \n\t"
28262 @@ -7271,6 +7293,11 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
28263 #endif
28264 [cr2]"i"(offsetof(struct vcpu_vmx, vcpu.arch.cr2)),
28265 [wordsize]"i"(sizeof(ulong))
28266 +
28267 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
28268 + ,[cs]"i"(__KERNEL_CS)
28269 +#endif
28270 +
28271 : "cc", "memory"
28272 #ifdef CONFIG_X86_64
28273 , "rax", "rbx", "rdi", "rsi"
28274 @@ -7284,7 +7311,7 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
28275 if (debugctlmsr)
28276 update_debugctlmsr(debugctlmsr);
28277
28278 -#ifndef CONFIG_X86_64
28279 +#ifdef CONFIG_X86_32
28280 /*
28281 * The sysexit path does not restore ds/es, so we must set them to
28282 * a reasonable value ourselves.
28283 @@ -7293,8 +7320,18 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
28284 * may be executed in interrupt context, which saves and restore segments
28285 * around it, nullifying its effect.
28286 */
28287 - loadsegment(ds, __USER_DS);
28288 - loadsegment(es, __USER_DS);
28289 + loadsegment(ds, __KERNEL_DS);
28290 + loadsegment(es, __KERNEL_DS);
28291 + loadsegment(ss, __KERNEL_DS);
28292 +
28293 +#ifdef CONFIG_PAX_KERNEXEC
28294 + loadsegment(fs, __KERNEL_PERCPU);
28295 +#endif
28296 +
28297 +#ifdef CONFIG_PAX_MEMORY_UDEREF
28298 + __set_fs(current_thread_info()->addr_limit);
28299 +#endif
28300 +
28301 #endif
28302
28303 vcpu->arch.regs_avail = ~((1 << VCPU_REGS_RIP) | (1 << VCPU_REGS_RSP)
28304 diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
28305 index 4e33b85..fa94855 100644
28306 --- a/arch/x86/kvm/x86.c
28307 +++ b/arch/x86/kvm/x86.c
28308 @@ -1791,8 +1791,8 @@ static int xen_hvm_config(struct kvm_vcpu *vcpu, u64 data)
28309 {
28310 struct kvm *kvm = vcpu->kvm;
28311 int lm = is_long_mode(vcpu);
28312 - u8 *blob_addr = lm ? (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_64
28313 - : (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
28314 + u8 __user *blob_addr = lm ? (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_64
28315 + : (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
28316 u8 blob_size = lm ? kvm->arch.xen_hvm_config.blob_size_64
28317 : kvm->arch.xen_hvm_config.blob_size_32;
28318 u32 page_num = data & ~PAGE_MASK;
28319 @@ -2676,6 +2676,8 @@ long kvm_arch_dev_ioctl(struct file *filp,
28320 if (n < msr_list.nmsrs)
28321 goto out;
28322 r = -EFAULT;
28323 + if (num_msrs_to_save > ARRAY_SIZE(msrs_to_save))
28324 + goto out;
28325 if (copy_to_user(user_msr_list->indices, &msrs_to_save,
28326 num_msrs_to_save * sizeof(u32)))
28327 goto out;
28328 @@ -5485,7 +5487,7 @@ static struct notifier_block pvclock_gtod_notifier = {
28329 };
28330 #endif
28331
28332 -int kvm_arch_init(void *opaque)
28333 +int kvm_arch_init(const void *opaque)
28334 {
28335 int r;
28336 struct kvm_x86_ops *ops = opaque;
28337 diff --git a/arch/x86/lguest/boot.c b/arch/x86/lguest/boot.c
28338 index bdf8532..f63c587 100644
28339 --- a/arch/x86/lguest/boot.c
28340 +++ b/arch/x86/lguest/boot.c
28341 @@ -1206,9 +1206,10 @@ static __init int early_put_chars(u32 vtermno, const char *buf, int count)
28342 * Rebooting also tells the Host we're finished, but the RESTART flag tells the
28343 * Launcher to reboot us.
28344 */
28345 -static void lguest_restart(char *reason)
28346 +static __noreturn void lguest_restart(char *reason)
28347 {
28348 hcall(LHCALL_SHUTDOWN, __pa(reason), LGUEST_SHUTDOWN_RESTART, 0, 0);
28349 + BUG();
28350 }
28351
28352 /*G:050
28353 diff --git a/arch/x86/lib/atomic64_386_32.S b/arch/x86/lib/atomic64_386_32.S
28354 index 00933d5..3a64af9 100644
28355 --- a/arch/x86/lib/atomic64_386_32.S
28356 +++ b/arch/x86/lib/atomic64_386_32.S
28357 @@ -48,6 +48,10 @@ BEGIN(read)
28358 movl (v), %eax
28359 movl 4(v), %edx
28360 RET_ENDP
28361 +BEGIN(read_unchecked)
28362 + movl (v), %eax
28363 + movl 4(v), %edx
28364 +RET_ENDP
28365 #undef v
28366
28367 #define v %esi
28368 @@ -55,6 +59,10 @@ BEGIN(set)
28369 movl %ebx, (v)
28370 movl %ecx, 4(v)
28371 RET_ENDP
28372 +BEGIN(set_unchecked)
28373 + movl %ebx, (v)
28374 + movl %ecx, 4(v)
28375 +RET_ENDP
28376 #undef v
28377
28378 #define v %esi
28379 @@ -70,6 +78,20 @@ RET_ENDP
28380 BEGIN(add)
28381 addl %eax, (v)
28382 adcl %edx, 4(v)
28383 +
28384 +#ifdef CONFIG_PAX_REFCOUNT
28385 + jno 0f
28386 + subl %eax, (v)
28387 + sbbl %edx, 4(v)
28388 + int $4
28389 +0:
28390 + _ASM_EXTABLE(0b, 0b)
28391 +#endif
28392 +
28393 +RET_ENDP
28394 +BEGIN(add_unchecked)
28395 + addl %eax, (v)
28396 + adcl %edx, 4(v)
28397 RET_ENDP
28398 #undef v
28399
28400 @@ -77,6 +99,24 @@ RET_ENDP
28401 BEGIN(add_return)
28402 addl (v), %eax
28403 adcl 4(v), %edx
28404 +
28405 +#ifdef CONFIG_PAX_REFCOUNT
28406 + into
28407 +1234:
28408 + _ASM_EXTABLE(1234b, 2f)
28409 +#endif
28410 +
28411 + movl %eax, (v)
28412 + movl %edx, 4(v)
28413 +
28414 +#ifdef CONFIG_PAX_REFCOUNT
28415 +2:
28416 +#endif
28417 +
28418 +RET_ENDP
28419 +BEGIN(add_return_unchecked)
28420 + addl (v), %eax
28421 + adcl 4(v), %edx
28422 movl %eax, (v)
28423 movl %edx, 4(v)
28424 RET_ENDP
28425 @@ -86,6 +126,20 @@ RET_ENDP
28426 BEGIN(sub)
28427 subl %eax, (v)
28428 sbbl %edx, 4(v)
28429 +
28430 +#ifdef CONFIG_PAX_REFCOUNT
28431 + jno 0f
28432 + addl %eax, (v)
28433 + adcl %edx, 4(v)
28434 + int $4
28435 +0:
28436 + _ASM_EXTABLE(0b, 0b)
28437 +#endif
28438 +
28439 +RET_ENDP
28440 +BEGIN(sub_unchecked)
28441 + subl %eax, (v)
28442 + sbbl %edx, 4(v)
28443 RET_ENDP
28444 #undef v
28445
28446 @@ -96,6 +150,27 @@ BEGIN(sub_return)
28447 sbbl $0, %edx
28448 addl (v), %eax
28449 adcl 4(v), %edx
28450 +
28451 +#ifdef CONFIG_PAX_REFCOUNT
28452 + into
28453 +1234:
28454 + _ASM_EXTABLE(1234b, 2f)
28455 +#endif
28456 +
28457 + movl %eax, (v)
28458 + movl %edx, 4(v)
28459 +
28460 +#ifdef CONFIG_PAX_REFCOUNT
28461 +2:
28462 +#endif
28463 +
28464 +RET_ENDP
28465 +BEGIN(sub_return_unchecked)
28466 + negl %edx
28467 + negl %eax
28468 + sbbl $0, %edx
28469 + addl (v), %eax
28470 + adcl 4(v), %edx
28471 movl %eax, (v)
28472 movl %edx, 4(v)
28473 RET_ENDP
28474 @@ -105,6 +180,20 @@ RET_ENDP
28475 BEGIN(inc)
28476 addl $1, (v)
28477 adcl $0, 4(v)
28478 +
28479 +#ifdef CONFIG_PAX_REFCOUNT
28480 + jno 0f
28481 + subl $1, (v)
28482 + sbbl $0, 4(v)
28483 + int $4
28484 +0:
28485 + _ASM_EXTABLE(0b, 0b)
28486 +#endif
28487 +
28488 +RET_ENDP
28489 +BEGIN(inc_unchecked)
28490 + addl $1, (v)
28491 + adcl $0, 4(v)
28492 RET_ENDP
28493 #undef v
28494
28495 @@ -114,6 +203,26 @@ BEGIN(inc_return)
28496 movl 4(v), %edx
28497 addl $1, %eax
28498 adcl $0, %edx
28499 +
28500 +#ifdef CONFIG_PAX_REFCOUNT
28501 + into
28502 +1234:
28503 + _ASM_EXTABLE(1234b, 2f)
28504 +#endif
28505 +
28506 + movl %eax, (v)
28507 + movl %edx, 4(v)
28508 +
28509 +#ifdef CONFIG_PAX_REFCOUNT
28510 +2:
28511 +#endif
28512 +
28513 +RET_ENDP
28514 +BEGIN(inc_return_unchecked)
28515 + movl (v), %eax
28516 + movl 4(v), %edx
28517 + addl $1, %eax
28518 + adcl $0, %edx
28519 movl %eax, (v)
28520 movl %edx, 4(v)
28521 RET_ENDP
28522 @@ -123,6 +232,20 @@ RET_ENDP
28523 BEGIN(dec)
28524 subl $1, (v)
28525 sbbl $0, 4(v)
28526 +
28527 +#ifdef CONFIG_PAX_REFCOUNT
28528 + jno 0f
28529 + addl $1, (v)
28530 + adcl $0, 4(v)
28531 + int $4
28532 +0:
28533 + _ASM_EXTABLE(0b, 0b)
28534 +#endif
28535 +
28536 +RET_ENDP
28537 +BEGIN(dec_unchecked)
28538 + subl $1, (v)
28539 + sbbl $0, 4(v)
28540 RET_ENDP
28541 #undef v
28542
28543 @@ -132,6 +255,26 @@ BEGIN(dec_return)
28544 movl 4(v), %edx
28545 subl $1, %eax
28546 sbbl $0, %edx
28547 +
28548 +#ifdef CONFIG_PAX_REFCOUNT
28549 + into
28550 +1234:
28551 + _ASM_EXTABLE(1234b, 2f)
28552 +#endif
28553 +
28554 + movl %eax, (v)
28555 + movl %edx, 4(v)
28556 +
28557 +#ifdef CONFIG_PAX_REFCOUNT
28558 +2:
28559 +#endif
28560 +
28561 +RET_ENDP
28562 +BEGIN(dec_return_unchecked)
28563 + movl (v), %eax
28564 + movl 4(v), %edx
28565 + subl $1, %eax
28566 + sbbl $0, %edx
28567 movl %eax, (v)
28568 movl %edx, 4(v)
28569 RET_ENDP
28570 @@ -143,6 +286,13 @@ BEGIN(add_unless)
28571 adcl %edx, %edi
28572 addl (v), %eax
28573 adcl 4(v), %edx
28574 +
28575 +#ifdef CONFIG_PAX_REFCOUNT
28576 + into
28577 +1234:
28578 + _ASM_EXTABLE(1234b, 2f)
28579 +#endif
28580 +
28581 cmpl %eax, %ecx
28582 je 3f
28583 1:
28584 @@ -168,6 +318,13 @@ BEGIN(inc_not_zero)
28585 1:
28586 addl $1, %eax
28587 adcl $0, %edx
28588 +
28589 +#ifdef CONFIG_PAX_REFCOUNT
28590 + into
28591 +1234:
28592 + _ASM_EXTABLE(1234b, 2f)
28593 +#endif
28594 +
28595 movl %eax, (v)
28596 movl %edx, 4(v)
28597 movl $1, %eax
28598 @@ -186,6 +343,13 @@ BEGIN(dec_if_positive)
28599 movl 4(v), %edx
28600 subl $1, %eax
28601 sbbl $0, %edx
28602 +
28603 +#ifdef CONFIG_PAX_REFCOUNT
28604 + into
28605 +1234:
28606 + _ASM_EXTABLE(1234b, 1f)
28607 +#endif
28608 +
28609 js 1f
28610 movl %eax, (v)
28611 movl %edx, 4(v)
28612 diff --git a/arch/x86/lib/atomic64_cx8_32.S b/arch/x86/lib/atomic64_cx8_32.S
28613 index f5cc9eb..51fa319 100644
28614 --- a/arch/x86/lib/atomic64_cx8_32.S
28615 +++ b/arch/x86/lib/atomic64_cx8_32.S
28616 @@ -35,10 +35,20 @@ ENTRY(atomic64_read_cx8)
28617 CFI_STARTPROC
28618
28619 read64 %ecx
28620 + pax_force_retaddr
28621 ret
28622 CFI_ENDPROC
28623 ENDPROC(atomic64_read_cx8)
28624
28625 +ENTRY(atomic64_read_unchecked_cx8)
28626 + CFI_STARTPROC
28627 +
28628 + read64 %ecx
28629 + pax_force_retaddr
28630 + ret
28631 + CFI_ENDPROC
28632 +ENDPROC(atomic64_read_unchecked_cx8)
28633 +
28634 ENTRY(atomic64_set_cx8)
28635 CFI_STARTPROC
28636
28637 @@ -48,10 +58,25 @@ ENTRY(atomic64_set_cx8)
28638 cmpxchg8b (%esi)
28639 jne 1b
28640
28641 + pax_force_retaddr
28642 ret
28643 CFI_ENDPROC
28644 ENDPROC(atomic64_set_cx8)
28645
28646 +ENTRY(atomic64_set_unchecked_cx8)
28647 + CFI_STARTPROC
28648 +
28649 +1:
28650 +/* we don't need LOCK_PREFIX since aligned 64-bit writes
28651 + * are atomic on 586 and newer */
28652 + cmpxchg8b (%esi)
28653 + jne 1b
28654 +
28655 + pax_force_retaddr
28656 + ret
28657 + CFI_ENDPROC
28658 +ENDPROC(atomic64_set_unchecked_cx8)
28659 +
28660 ENTRY(atomic64_xchg_cx8)
28661 CFI_STARTPROC
28662
28663 @@ -60,12 +85,13 @@ ENTRY(atomic64_xchg_cx8)
28664 cmpxchg8b (%esi)
28665 jne 1b
28666
28667 + pax_force_retaddr
28668 ret
28669 CFI_ENDPROC
28670 ENDPROC(atomic64_xchg_cx8)
28671
28672 -.macro addsub_return func ins insc
28673 -ENTRY(atomic64_\func\()_return_cx8)
28674 +.macro addsub_return func ins insc unchecked=""
28675 +ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
28676 CFI_STARTPROC
28677 SAVE ebp
28678 SAVE ebx
28679 @@ -82,27 +108,44 @@ ENTRY(atomic64_\func\()_return_cx8)
28680 movl %edx, %ecx
28681 \ins\()l %esi, %ebx
28682 \insc\()l %edi, %ecx
28683 +
28684 +.ifb \unchecked
28685 +#ifdef CONFIG_PAX_REFCOUNT
28686 + into
28687 +2:
28688 + _ASM_EXTABLE(2b, 3f)
28689 +#endif
28690 +.endif
28691 +
28692 LOCK_PREFIX
28693 cmpxchg8b (%ebp)
28694 jne 1b
28695 -
28696 -10:
28697 movl %ebx, %eax
28698 movl %ecx, %edx
28699 +
28700 +.ifb \unchecked
28701 +#ifdef CONFIG_PAX_REFCOUNT
28702 +3:
28703 +#endif
28704 +.endif
28705 +
28706 RESTORE edi
28707 RESTORE esi
28708 RESTORE ebx
28709 RESTORE ebp
28710 + pax_force_retaddr
28711 ret
28712 CFI_ENDPROC
28713 -ENDPROC(atomic64_\func\()_return_cx8)
28714 +ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
28715 .endm
28716
28717 addsub_return add add adc
28718 addsub_return sub sub sbb
28719 +addsub_return add add adc _unchecked
28720 +addsub_return sub sub sbb _unchecked
28721
28722 -.macro incdec_return func ins insc
28723 -ENTRY(atomic64_\func\()_return_cx8)
28724 +.macro incdec_return func ins insc unchecked=""
28725 +ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
28726 CFI_STARTPROC
28727 SAVE ebx
28728
28729 @@ -112,21 +155,39 @@ ENTRY(atomic64_\func\()_return_cx8)
28730 movl %edx, %ecx
28731 \ins\()l $1, %ebx
28732 \insc\()l $0, %ecx
28733 +
28734 +.ifb \unchecked
28735 +#ifdef CONFIG_PAX_REFCOUNT
28736 + into
28737 +2:
28738 + _ASM_EXTABLE(2b, 3f)
28739 +#endif
28740 +.endif
28741 +
28742 LOCK_PREFIX
28743 cmpxchg8b (%esi)
28744 jne 1b
28745
28746 -10:
28747 movl %ebx, %eax
28748 movl %ecx, %edx
28749 +
28750 +.ifb \unchecked
28751 +#ifdef CONFIG_PAX_REFCOUNT
28752 +3:
28753 +#endif
28754 +.endif
28755 +
28756 RESTORE ebx
28757 + pax_force_retaddr
28758 ret
28759 CFI_ENDPROC
28760 -ENDPROC(atomic64_\func\()_return_cx8)
28761 +ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
28762 .endm
28763
28764 incdec_return inc add adc
28765 incdec_return dec sub sbb
28766 +incdec_return inc add adc _unchecked
28767 +incdec_return dec sub sbb _unchecked
28768
28769 ENTRY(atomic64_dec_if_positive_cx8)
28770 CFI_STARTPROC
28771 @@ -138,6 +199,13 @@ ENTRY(atomic64_dec_if_positive_cx8)
28772 movl %edx, %ecx
28773 subl $1, %ebx
28774 sbb $0, %ecx
28775 +
28776 +#ifdef CONFIG_PAX_REFCOUNT
28777 + into
28778 +1234:
28779 + _ASM_EXTABLE(1234b, 2f)
28780 +#endif
28781 +
28782 js 2f
28783 LOCK_PREFIX
28784 cmpxchg8b (%esi)
28785 @@ -147,6 +215,7 @@ ENTRY(atomic64_dec_if_positive_cx8)
28786 movl %ebx, %eax
28787 movl %ecx, %edx
28788 RESTORE ebx
28789 + pax_force_retaddr
28790 ret
28791 CFI_ENDPROC
28792 ENDPROC(atomic64_dec_if_positive_cx8)
28793 @@ -171,6 +240,13 @@ ENTRY(atomic64_add_unless_cx8)
28794 movl %edx, %ecx
28795 addl %ebp, %ebx
28796 adcl %edi, %ecx
28797 +
28798 +#ifdef CONFIG_PAX_REFCOUNT
28799 + into
28800 +1234:
28801 + _ASM_EXTABLE(1234b, 3f)
28802 +#endif
28803 +
28804 LOCK_PREFIX
28805 cmpxchg8b (%esi)
28806 jne 1b
28807 @@ -181,6 +257,7 @@ ENTRY(atomic64_add_unless_cx8)
28808 CFI_ADJUST_CFA_OFFSET -8
28809 RESTORE ebx
28810 RESTORE ebp
28811 + pax_force_retaddr
28812 ret
28813 4:
28814 cmpl %edx, 4(%esp)
28815 @@ -203,6 +280,13 @@ ENTRY(atomic64_inc_not_zero_cx8)
28816 xorl %ecx, %ecx
28817 addl $1, %ebx
28818 adcl %edx, %ecx
28819 +
28820 +#ifdef CONFIG_PAX_REFCOUNT
28821 + into
28822 +1234:
28823 + _ASM_EXTABLE(1234b, 3f)
28824 +#endif
28825 +
28826 LOCK_PREFIX
28827 cmpxchg8b (%esi)
28828 jne 1b
28829 @@ -210,6 +294,7 @@ ENTRY(atomic64_inc_not_zero_cx8)
28830 movl $1, %eax
28831 3:
28832 RESTORE ebx
28833 + pax_force_retaddr
28834 ret
28835 CFI_ENDPROC
28836 ENDPROC(atomic64_inc_not_zero_cx8)
28837 diff --git a/arch/x86/lib/checksum_32.S b/arch/x86/lib/checksum_32.S
28838 index e78b8ee..7e173a8 100644
28839 --- a/arch/x86/lib/checksum_32.S
28840 +++ b/arch/x86/lib/checksum_32.S
28841 @@ -29,7 +29,8 @@
28842 #include <asm/dwarf2.h>
28843 #include <asm/errno.h>
28844 #include <asm/asm.h>
28845 -
28846 +#include <asm/segment.h>
28847 +
28848 /*
28849 * computes a partial checksum, e.g. for TCP/UDP fragments
28850 */
28851 @@ -293,9 +294,24 @@ unsigned int csum_partial_copy_generic (const char *src, char *dst,
28852
28853 #define ARGBASE 16
28854 #define FP 12
28855 -
28856 -ENTRY(csum_partial_copy_generic)
28857 +
28858 +ENTRY(csum_partial_copy_generic_to_user)
28859 CFI_STARTPROC
28860 +
28861 +#ifdef CONFIG_PAX_MEMORY_UDEREF
28862 + pushl_cfi %gs
28863 + popl_cfi %es
28864 + jmp csum_partial_copy_generic
28865 +#endif
28866 +
28867 +ENTRY(csum_partial_copy_generic_from_user)
28868 +
28869 +#ifdef CONFIG_PAX_MEMORY_UDEREF
28870 + pushl_cfi %gs
28871 + popl_cfi %ds
28872 +#endif
28873 +
28874 +ENTRY(csum_partial_copy_generic)
28875 subl $4,%esp
28876 CFI_ADJUST_CFA_OFFSET 4
28877 pushl_cfi %edi
28878 @@ -317,7 +333,7 @@ ENTRY(csum_partial_copy_generic)
28879 jmp 4f
28880 SRC(1: movw (%esi), %bx )
28881 addl $2, %esi
28882 -DST( movw %bx, (%edi) )
28883 +DST( movw %bx, %es:(%edi) )
28884 addl $2, %edi
28885 addw %bx, %ax
28886 adcl $0, %eax
28887 @@ -329,30 +345,30 @@ DST( movw %bx, (%edi) )
28888 SRC(1: movl (%esi), %ebx )
28889 SRC( movl 4(%esi), %edx )
28890 adcl %ebx, %eax
28891 -DST( movl %ebx, (%edi) )
28892 +DST( movl %ebx, %es:(%edi) )
28893 adcl %edx, %eax
28894 -DST( movl %edx, 4(%edi) )
28895 +DST( movl %edx, %es:4(%edi) )
28896
28897 SRC( movl 8(%esi), %ebx )
28898 SRC( movl 12(%esi), %edx )
28899 adcl %ebx, %eax
28900 -DST( movl %ebx, 8(%edi) )
28901 +DST( movl %ebx, %es:8(%edi) )
28902 adcl %edx, %eax
28903 -DST( movl %edx, 12(%edi) )
28904 +DST( movl %edx, %es:12(%edi) )
28905
28906 SRC( movl 16(%esi), %ebx )
28907 SRC( movl 20(%esi), %edx )
28908 adcl %ebx, %eax
28909 -DST( movl %ebx, 16(%edi) )
28910 +DST( movl %ebx, %es:16(%edi) )
28911 adcl %edx, %eax
28912 -DST( movl %edx, 20(%edi) )
28913 +DST( movl %edx, %es:20(%edi) )
28914
28915 SRC( movl 24(%esi), %ebx )
28916 SRC( movl 28(%esi), %edx )
28917 adcl %ebx, %eax
28918 -DST( movl %ebx, 24(%edi) )
28919 +DST( movl %ebx, %es:24(%edi) )
28920 adcl %edx, %eax
28921 -DST( movl %edx, 28(%edi) )
28922 +DST( movl %edx, %es:28(%edi) )
28923
28924 lea 32(%esi), %esi
28925 lea 32(%edi), %edi
28926 @@ -366,7 +382,7 @@ DST( movl %edx, 28(%edi) )
28927 shrl $2, %edx # This clears CF
28928 SRC(3: movl (%esi), %ebx )
28929 adcl %ebx, %eax
28930 -DST( movl %ebx, (%edi) )
28931 +DST( movl %ebx, %es:(%edi) )
28932 lea 4(%esi), %esi
28933 lea 4(%edi), %edi
28934 dec %edx
28935 @@ -378,12 +394,12 @@ DST( movl %ebx, (%edi) )
28936 jb 5f
28937 SRC( movw (%esi), %cx )
28938 leal 2(%esi), %esi
28939 -DST( movw %cx, (%edi) )
28940 +DST( movw %cx, %es:(%edi) )
28941 leal 2(%edi), %edi
28942 je 6f
28943 shll $16,%ecx
28944 SRC(5: movb (%esi), %cl )
28945 -DST( movb %cl, (%edi) )
28946 +DST( movb %cl, %es:(%edi) )
28947 6: addl %ecx, %eax
28948 adcl $0, %eax
28949 7:
28950 @@ -394,7 +410,7 @@ DST( movb %cl, (%edi) )
28951
28952 6001:
28953 movl ARGBASE+20(%esp), %ebx # src_err_ptr
28954 - movl $-EFAULT, (%ebx)
28955 + movl $-EFAULT, %ss:(%ebx)
28956
28957 # zero the complete destination - computing the rest
28958 # is too much work
28959 @@ -407,11 +423,15 @@ DST( movb %cl, (%edi) )
28960
28961 6002:
28962 movl ARGBASE+24(%esp), %ebx # dst_err_ptr
28963 - movl $-EFAULT,(%ebx)
28964 + movl $-EFAULT,%ss:(%ebx)
28965 jmp 5000b
28966
28967 .previous
28968
28969 + pushl_cfi %ss
28970 + popl_cfi %ds
28971 + pushl_cfi %ss
28972 + popl_cfi %es
28973 popl_cfi %ebx
28974 CFI_RESTORE ebx
28975 popl_cfi %esi
28976 @@ -421,26 +441,43 @@ DST( movb %cl, (%edi) )
28977 popl_cfi %ecx # equivalent to addl $4,%esp
28978 ret
28979 CFI_ENDPROC
28980 -ENDPROC(csum_partial_copy_generic)
28981 +ENDPROC(csum_partial_copy_generic_to_user)
28982
28983 #else
28984
28985 /* Version for PentiumII/PPro */
28986
28987 #define ROUND1(x) \
28988 + nop; nop; nop; \
28989 SRC(movl x(%esi), %ebx ) ; \
28990 addl %ebx, %eax ; \
28991 - DST(movl %ebx, x(%edi) ) ;
28992 + DST(movl %ebx, %es:x(%edi)) ;
28993
28994 #define ROUND(x) \
28995 + nop; nop; nop; \
28996 SRC(movl x(%esi), %ebx ) ; \
28997 adcl %ebx, %eax ; \
28998 - DST(movl %ebx, x(%edi) ) ;
28999 + DST(movl %ebx, %es:x(%edi)) ;
29000
29001 #define ARGBASE 12
29002 -
29003 -ENTRY(csum_partial_copy_generic)
29004 +
29005 +ENTRY(csum_partial_copy_generic_to_user)
29006 CFI_STARTPROC
29007 +
29008 +#ifdef CONFIG_PAX_MEMORY_UDEREF
29009 + pushl_cfi %gs
29010 + popl_cfi %es
29011 + jmp csum_partial_copy_generic
29012 +#endif
29013 +
29014 +ENTRY(csum_partial_copy_generic_from_user)
29015 +
29016 +#ifdef CONFIG_PAX_MEMORY_UDEREF
29017 + pushl_cfi %gs
29018 + popl_cfi %ds
29019 +#endif
29020 +
29021 +ENTRY(csum_partial_copy_generic)
29022 pushl_cfi %ebx
29023 CFI_REL_OFFSET ebx, 0
29024 pushl_cfi %edi
29025 @@ -461,7 +498,7 @@ ENTRY(csum_partial_copy_generic)
29026 subl %ebx, %edi
29027 lea -1(%esi),%edx
29028 andl $-32,%edx
29029 - lea 3f(%ebx,%ebx), %ebx
29030 + lea 3f(%ebx,%ebx,2), %ebx
29031 testl %esi, %esi
29032 jmp *%ebx
29033 1: addl $64,%esi
29034 @@ -482,19 +519,19 @@ ENTRY(csum_partial_copy_generic)
29035 jb 5f
29036 SRC( movw (%esi), %dx )
29037 leal 2(%esi), %esi
29038 -DST( movw %dx, (%edi) )
29039 +DST( movw %dx, %es:(%edi) )
29040 leal 2(%edi), %edi
29041 je 6f
29042 shll $16,%edx
29043 5:
29044 SRC( movb (%esi), %dl )
29045 -DST( movb %dl, (%edi) )
29046 +DST( movb %dl, %es:(%edi) )
29047 6: addl %edx, %eax
29048 adcl $0, %eax
29049 7:
29050 .section .fixup, "ax"
29051 6001: movl ARGBASE+20(%esp), %ebx # src_err_ptr
29052 - movl $-EFAULT, (%ebx)
29053 + movl $-EFAULT, %ss:(%ebx)
29054 # zero the complete destination (computing the rest is too much work)
29055 movl ARGBASE+8(%esp),%edi # dst
29056 movl ARGBASE+12(%esp),%ecx # len
29057 @@ -502,10 +539,17 @@ DST( movb %dl, (%edi) )
29058 rep; stosb
29059 jmp 7b
29060 6002: movl ARGBASE+24(%esp), %ebx # dst_err_ptr
29061 - movl $-EFAULT, (%ebx)
29062 + movl $-EFAULT, %ss:(%ebx)
29063 jmp 7b
29064 .previous
29065
29066 +#ifdef CONFIG_PAX_MEMORY_UDEREF
29067 + pushl_cfi %ss
29068 + popl_cfi %ds
29069 + pushl_cfi %ss
29070 + popl_cfi %es
29071 +#endif
29072 +
29073 popl_cfi %esi
29074 CFI_RESTORE esi
29075 popl_cfi %edi
29076 @@ -514,7 +558,7 @@ DST( movb %dl, (%edi) )
29077 CFI_RESTORE ebx
29078 ret
29079 CFI_ENDPROC
29080 -ENDPROC(csum_partial_copy_generic)
29081 +ENDPROC(csum_partial_copy_generic_to_user)
29082
29083 #undef ROUND
29084 #undef ROUND1
29085 diff --git a/arch/x86/lib/clear_page_64.S b/arch/x86/lib/clear_page_64.S
29086 index f2145cf..cea889d 100644
29087 --- a/arch/x86/lib/clear_page_64.S
29088 +++ b/arch/x86/lib/clear_page_64.S
29089 @@ -11,6 +11,7 @@ ENTRY(clear_page_c)
29090 movl $4096/8,%ecx
29091 xorl %eax,%eax
29092 rep stosq
29093 + pax_force_retaddr
29094 ret
29095 CFI_ENDPROC
29096 ENDPROC(clear_page_c)
29097 @@ -20,6 +21,7 @@ ENTRY(clear_page_c_e)
29098 movl $4096,%ecx
29099 xorl %eax,%eax
29100 rep stosb
29101 + pax_force_retaddr
29102 ret
29103 CFI_ENDPROC
29104 ENDPROC(clear_page_c_e)
29105 @@ -43,6 +45,7 @@ ENTRY(clear_page)
29106 leaq 64(%rdi),%rdi
29107 jnz .Lloop
29108 nop
29109 + pax_force_retaddr
29110 ret
29111 CFI_ENDPROC
29112 .Lclear_page_end:
29113 @@ -58,7 +61,7 @@ ENDPROC(clear_page)
29114
29115 #include <asm/cpufeature.h>
29116
29117 - .section .altinstr_replacement,"ax"
29118 + .section .altinstr_replacement,"a"
29119 1: .byte 0xeb /* jmp <disp8> */
29120 .byte (clear_page_c - clear_page) - (2f - 1b) /* offset */
29121 2: .byte 0xeb /* jmp <disp8> */
29122 diff --git a/arch/x86/lib/cmpxchg16b_emu.S b/arch/x86/lib/cmpxchg16b_emu.S
29123 index 1e572c5..2a162cd 100644
29124 --- a/arch/x86/lib/cmpxchg16b_emu.S
29125 +++ b/arch/x86/lib/cmpxchg16b_emu.S
29126 @@ -53,11 +53,13 @@ this_cpu_cmpxchg16b_emu:
29127
29128 popf
29129 mov $1, %al
29130 + pax_force_retaddr
29131 ret
29132
29133 not_same:
29134 popf
29135 xor %al,%al
29136 + pax_force_retaddr
29137 ret
29138
29139 CFI_ENDPROC
29140 diff --git a/arch/x86/lib/copy_page_64.S b/arch/x86/lib/copy_page_64.S
29141 index 176cca6..e0d658e 100644
29142 --- a/arch/x86/lib/copy_page_64.S
29143 +++ b/arch/x86/lib/copy_page_64.S
29144 @@ -9,6 +9,7 @@ copy_page_rep:
29145 CFI_STARTPROC
29146 movl $4096/8, %ecx
29147 rep movsq
29148 + pax_force_retaddr
29149 ret
29150 CFI_ENDPROC
29151 ENDPROC(copy_page_rep)
29152 @@ -24,8 +25,8 @@ ENTRY(copy_page)
29153 CFI_ADJUST_CFA_OFFSET 2*8
29154 movq %rbx, (%rsp)
29155 CFI_REL_OFFSET rbx, 0
29156 - movq %r12, 1*8(%rsp)
29157 - CFI_REL_OFFSET r12, 1*8
29158 + movq %r13, 1*8(%rsp)
29159 + CFI_REL_OFFSET r13, 1*8
29160
29161 movl $(4096/64)-5, %ecx
29162 .p2align 4
29163 @@ -38,7 +39,7 @@ ENTRY(copy_page)
29164 movq 0x8*4(%rsi), %r9
29165 movq 0x8*5(%rsi), %r10
29166 movq 0x8*6(%rsi), %r11
29167 - movq 0x8*7(%rsi), %r12
29168 + movq 0x8*7(%rsi), %r13
29169
29170 prefetcht0 5*64(%rsi)
29171
29172 @@ -49,7 +50,7 @@ ENTRY(copy_page)
29173 movq %r9, 0x8*4(%rdi)
29174 movq %r10, 0x8*5(%rdi)
29175 movq %r11, 0x8*6(%rdi)
29176 - movq %r12, 0x8*7(%rdi)
29177 + movq %r13, 0x8*7(%rdi)
29178
29179 leaq 64 (%rsi), %rsi
29180 leaq 64 (%rdi), %rdi
29181 @@ -68,7 +69,7 @@ ENTRY(copy_page)
29182 movq 0x8*4(%rsi), %r9
29183 movq 0x8*5(%rsi), %r10
29184 movq 0x8*6(%rsi), %r11
29185 - movq 0x8*7(%rsi), %r12
29186 + movq 0x8*7(%rsi), %r13
29187
29188 movq %rax, 0x8*0(%rdi)
29189 movq %rbx, 0x8*1(%rdi)
29190 @@ -77,7 +78,7 @@ ENTRY(copy_page)
29191 movq %r9, 0x8*4(%rdi)
29192 movq %r10, 0x8*5(%rdi)
29193 movq %r11, 0x8*6(%rdi)
29194 - movq %r12, 0x8*7(%rdi)
29195 + movq %r13, 0x8*7(%rdi)
29196
29197 leaq 64(%rdi), %rdi
29198 leaq 64(%rsi), %rsi
29199 @@ -85,10 +86,11 @@ ENTRY(copy_page)
29200
29201 movq (%rsp), %rbx
29202 CFI_RESTORE rbx
29203 - movq 1*8(%rsp), %r12
29204 - CFI_RESTORE r12
29205 + movq 1*8(%rsp), %r13
29206 + CFI_RESTORE r13
29207 addq $2*8, %rsp
29208 CFI_ADJUST_CFA_OFFSET -2*8
29209 + pax_force_retaddr
29210 ret
29211 .Lcopy_page_end:
29212 CFI_ENDPROC
29213 @@ -99,7 +101,7 @@ ENDPROC(copy_page)
29214
29215 #include <asm/cpufeature.h>
29216
29217 - .section .altinstr_replacement,"ax"
29218 + .section .altinstr_replacement,"a"
29219 1: .byte 0xeb /* jmp <disp8> */
29220 .byte (copy_page_rep - copy_page) - (2f - 1b) /* offset */
29221 2:
29222 diff --git a/arch/x86/lib/copy_user_64.S b/arch/x86/lib/copy_user_64.S
29223 index a30ca15..407412b 100644
29224 --- a/arch/x86/lib/copy_user_64.S
29225 +++ b/arch/x86/lib/copy_user_64.S
29226 @@ -18,31 +18,7 @@
29227 #include <asm/alternative-asm.h>
29228 #include <asm/asm.h>
29229 #include <asm/smap.h>
29230 -
29231 -/*
29232 - * By placing feature2 after feature1 in altinstructions section, we logically
29233 - * implement:
29234 - * If CPU has feature2, jmp to alt2 is used
29235 - * else if CPU has feature1, jmp to alt1 is used
29236 - * else jmp to orig is used.
29237 - */
29238 - .macro ALTERNATIVE_JUMP feature1,feature2,orig,alt1,alt2
29239 -0:
29240 - .byte 0xe9 /* 32bit jump */
29241 - .long \orig-1f /* by default jump to orig */
29242 -1:
29243 - .section .altinstr_replacement,"ax"
29244 -2: .byte 0xe9 /* near jump with 32bit immediate */
29245 - .long \alt1-1b /* offset */ /* or alternatively to alt1 */
29246 -3: .byte 0xe9 /* near jump with 32bit immediate */
29247 - .long \alt2-1b /* offset */ /* or alternatively to alt2 */
29248 - .previous
29249 -
29250 - .section .altinstructions,"a"
29251 - altinstruction_entry 0b,2b,\feature1,5,5
29252 - altinstruction_entry 0b,3b,\feature2,5,5
29253 - .previous
29254 - .endm
29255 +#include <asm/pgtable.h>
29256
29257 .macro ALIGN_DESTINATION
29258 #ifdef FIX_ALIGNMENT
29259 @@ -70,52 +46,6 @@
29260 #endif
29261 .endm
29262
29263 -/* Standard copy_to_user with segment limit checking */
29264 -ENTRY(_copy_to_user)
29265 - CFI_STARTPROC
29266 - GET_THREAD_INFO(%rax)
29267 - movq %rdi,%rcx
29268 - addq %rdx,%rcx
29269 - jc bad_to_user
29270 - cmpq TI_addr_limit(%rax),%rcx
29271 - ja bad_to_user
29272 - ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
29273 - copy_user_generic_unrolled,copy_user_generic_string, \
29274 - copy_user_enhanced_fast_string
29275 - CFI_ENDPROC
29276 -ENDPROC(_copy_to_user)
29277 -
29278 -/* Standard copy_from_user with segment limit checking */
29279 -ENTRY(_copy_from_user)
29280 - CFI_STARTPROC
29281 - GET_THREAD_INFO(%rax)
29282 - movq %rsi,%rcx
29283 - addq %rdx,%rcx
29284 - jc bad_from_user
29285 - cmpq TI_addr_limit(%rax),%rcx
29286 - ja bad_from_user
29287 - ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
29288 - copy_user_generic_unrolled,copy_user_generic_string, \
29289 - copy_user_enhanced_fast_string
29290 - CFI_ENDPROC
29291 -ENDPROC(_copy_from_user)
29292 -
29293 - .section .fixup,"ax"
29294 - /* must zero dest */
29295 -ENTRY(bad_from_user)
29296 -bad_from_user:
29297 - CFI_STARTPROC
29298 - movl %edx,%ecx
29299 - xorl %eax,%eax
29300 - rep
29301 - stosb
29302 -bad_to_user:
29303 - movl %edx,%eax
29304 - ret
29305 - CFI_ENDPROC
29306 -ENDPROC(bad_from_user)
29307 - .previous
29308 -
29309 /*
29310 * copy_user_generic_unrolled - memory copy with exception handling.
29311 * This version is for CPUs like P4 that don't have efficient micro
29312 @@ -131,6 +61,7 @@ ENDPROC(bad_from_user)
29313 */
29314 ENTRY(copy_user_generic_unrolled)
29315 CFI_STARTPROC
29316 + ASM_PAX_OPEN_USERLAND
29317 ASM_STAC
29318 cmpl $8,%edx
29319 jb 20f /* less then 8 bytes, go to byte copy loop */
29320 @@ -180,6 +111,8 @@ ENTRY(copy_user_generic_unrolled)
29321 jnz 21b
29322 23: xor %eax,%eax
29323 ASM_CLAC
29324 + ASM_PAX_CLOSE_USERLAND
29325 + pax_force_retaddr
29326 ret
29327
29328 .section .fixup,"ax"
29329 @@ -235,6 +168,7 @@ ENDPROC(copy_user_generic_unrolled)
29330 */
29331 ENTRY(copy_user_generic_string)
29332 CFI_STARTPROC
29333 + ASM_PAX_OPEN_USERLAND
29334 ASM_STAC
29335 andl %edx,%edx
29336 jz 4f
29337 @@ -251,6 +185,8 @@ ENTRY(copy_user_generic_string)
29338 movsb
29339 4: xorl %eax,%eax
29340 ASM_CLAC
29341 + ASM_PAX_CLOSE_USERLAND
29342 + pax_force_retaddr
29343 ret
29344
29345 .section .fixup,"ax"
29346 @@ -278,6 +214,7 @@ ENDPROC(copy_user_generic_string)
29347 */
29348 ENTRY(copy_user_enhanced_fast_string)
29349 CFI_STARTPROC
29350 + ASM_PAX_OPEN_USERLAND
29351 ASM_STAC
29352 andl %edx,%edx
29353 jz 2f
29354 @@ -286,6 +223,8 @@ ENTRY(copy_user_enhanced_fast_string)
29355 movsb
29356 2: xorl %eax,%eax
29357 ASM_CLAC
29358 + ASM_PAX_CLOSE_USERLAND
29359 + pax_force_retaddr
29360 ret
29361
29362 .section .fixup,"ax"
29363 diff --git a/arch/x86/lib/copy_user_nocache_64.S b/arch/x86/lib/copy_user_nocache_64.S
29364 index 6a4f43c..c70fb52 100644
29365 --- a/arch/x86/lib/copy_user_nocache_64.S
29366 +++ b/arch/x86/lib/copy_user_nocache_64.S
29367 @@ -8,6 +8,7 @@
29368
29369 #include <linux/linkage.h>
29370 #include <asm/dwarf2.h>
29371 +#include <asm/alternative-asm.h>
29372
29373 #define FIX_ALIGNMENT 1
29374
29375 @@ -16,6 +17,7 @@
29376 #include <asm/thread_info.h>
29377 #include <asm/asm.h>
29378 #include <asm/smap.h>
29379 +#include <asm/pgtable.h>
29380
29381 .macro ALIGN_DESTINATION
29382 #ifdef FIX_ALIGNMENT
29383 @@ -49,6 +51,16 @@
29384 */
29385 ENTRY(__copy_user_nocache)
29386 CFI_STARTPROC
29387 +
29388 +#ifdef CONFIG_PAX_MEMORY_UDEREF
29389 + mov pax_user_shadow_base,%rcx
29390 + cmp %rcx,%rsi
29391 + jae 1f
29392 + add %rcx,%rsi
29393 +1:
29394 +#endif
29395 +
29396 + ASM_PAX_OPEN_USERLAND
29397 ASM_STAC
29398 cmpl $8,%edx
29399 jb 20f /* less then 8 bytes, go to byte copy loop */
29400 @@ -98,7 +110,9 @@ ENTRY(__copy_user_nocache)
29401 jnz 21b
29402 23: xorl %eax,%eax
29403 ASM_CLAC
29404 + ASM_PAX_CLOSE_USERLAND
29405 sfence
29406 + pax_force_retaddr
29407 ret
29408
29409 .section .fixup,"ax"
29410 diff --git a/arch/x86/lib/csum-copy_64.S b/arch/x86/lib/csum-copy_64.S
29411 index 2419d5f..fe52d0e 100644
29412 --- a/arch/x86/lib/csum-copy_64.S
29413 +++ b/arch/x86/lib/csum-copy_64.S
29414 @@ -9,6 +9,7 @@
29415 #include <asm/dwarf2.h>
29416 #include <asm/errno.h>
29417 #include <asm/asm.h>
29418 +#include <asm/alternative-asm.h>
29419
29420 /*
29421 * Checksum copy with exception handling.
29422 @@ -56,8 +57,8 @@ ENTRY(csum_partial_copy_generic)
29423 CFI_ADJUST_CFA_OFFSET 7*8
29424 movq %rbx, 2*8(%rsp)
29425 CFI_REL_OFFSET rbx, 2*8
29426 - movq %r12, 3*8(%rsp)
29427 - CFI_REL_OFFSET r12, 3*8
29428 + movq %r15, 3*8(%rsp)
29429 + CFI_REL_OFFSET r15, 3*8
29430 movq %r14, 4*8(%rsp)
29431 CFI_REL_OFFSET r14, 4*8
29432 movq %r13, 5*8(%rsp)
29433 @@ -72,16 +73,16 @@ ENTRY(csum_partial_copy_generic)
29434 movl %edx, %ecx
29435
29436 xorl %r9d, %r9d
29437 - movq %rcx, %r12
29438 + movq %rcx, %r15
29439
29440 - shrq $6, %r12
29441 + shrq $6, %r15
29442 jz .Lhandle_tail /* < 64 */
29443
29444 clc
29445
29446 /* main loop. clear in 64 byte blocks */
29447 /* r9: zero, r8: temp2, rbx: temp1, rax: sum, rcx: saved length */
29448 - /* r11: temp3, rdx: temp4, r12 loopcnt */
29449 + /* r11: temp3, rdx: temp4, r15 loopcnt */
29450 /* r10: temp5, rbp: temp6, r14 temp7, r13 temp8 */
29451 .p2align 4
29452 .Lloop:
29453 @@ -115,7 +116,7 @@ ENTRY(csum_partial_copy_generic)
29454 adcq %r14, %rax
29455 adcq %r13, %rax
29456
29457 - decl %r12d
29458 + decl %r15d
29459
29460 dest
29461 movq %rbx, (%rsi)
29462 @@ -210,8 +211,8 @@ ENTRY(csum_partial_copy_generic)
29463 .Lende:
29464 movq 2*8(%rsp), %rbx
29465 CFI_RESTORE rbx
29466 - movq 3*8(%rsp), %r12
29467 - CFI_RESTORE r12
29468 + movq 3*8(%rsp), %r15
29469 + CFI_RESTORE r15
29470 movq 4*8(%rsp), %r14
29471 CFI_RESTORE r14
29472 movq 5*8(%rsp), %r13
29473 @@ -220,6 +221,7 @@ ENTRY(csum_partial_copy_generic)
29474 CFI_RESTORE rbp
29475 addq $7*8, %rsp
29476 CFI_ADJUST_CFA_OFFSET -7*8
29477 + pax_force_retaddr
29478 ret
29479 CFI_RESTORE_STATE
29480
29481 diff --git a/arch/x86/lib/csum-wrappers_64.c b/arch/x86/lib/csum-wrappers_64.c
29482 index 7609e0e..b449b98 100644
29483 --- a/arch/x86/lib/csum-wrappers_64.c
29484 +++ b/arch/x86/lib/csum-wrappers_64.c
29485 @@ -53,10 +53,12 @@ csum_partial_copy_from_user(const void __user *src, void *dst,
29486 len -= 2;
29487 }
29488 }
29489 + pax_open_userland();
29490 stac();
29491 - isum = csum_partial_copy_generic((__force const void *)src,
29492 + isum = csum_partial_copy_generic((const void __force_kernel *)____m(src),
29493 dst, len, isum, errp, NULL);
29494 clac();
29495 + pax_close_userland();
29496 if (unlikely(*errp))
29497 goto out_err;
29498
29499 @@ -110,10 +112,12 @@ csum_partial_copy_to_user(const void *src, void __user *dst,
29500 }
29501
29502 *errp = 0;
29503 + pax_open_userland();
29504 stac();
29505 - ret = csum_partial_copy_generic(src, (void __force *)dst,
29506 + ret = csum_partial_copy_generic(src, (void __force_kernel *)____m(dst),
29507 len, isum, NULL, errp);
29508 clac();
29509 + pax_close_userland();
29510 return ret;
29511 }
29512 EXPORT_SYMBOL(csum_partial_copy_to_user);
29513 diff --git a/arch/x86/lib/getuser.S b/arch/x86/lib/getuser.S
29514 index a451235..1daa956 100644
29515 --- a/arch/x86/lib/getuser.S
29516 +++ b/arch/x86/lib/getuser.S
29517 @@ -33,17 +33,40 @@
29518 #include <asm/thread_info.h>
29519 #include <asm/asm.h>
29520 #include <asm/smap.h>
29521 +#include <asm/segment.h>
29522 +#include <asm/pgtable.h>
29523 +#include <asm/alternative-asm.h>
29524 +
29525 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
29526 +#define __copyuser_seg gs;
29527 +#else
29528 +#define __copyuser_seg
29529 +#endif
29530
29531 .text
29532 ENTRY(__get_user_1)
29533 CFI_STARTPROC
29534 +
29535 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
29536 GET_THREAD_INFO(%_ASM_DX)
29537 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
29538 jae bad_get_user
29539 ASM_STAC
29540 -1: movzbl (%_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 +1: __copyuser_seg movzbl (%_ASM_AX),%edx
29553 xor %eax,%eax
29554 ASM_CLAC
29555 + pax_force_retaddr
29556 ret
29557 CFI_ENDPROC
29558 ENDPROC(__get_user_1)
29559 @@ -51,14 +74,28 @@ ENDPROC(__get_user_1)
29560 ENTRY(__get_user_2)
29561 CFI_STARTPROC
29562 add $1,%_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 -2: movzwl -1(%_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 +2: __copyuser_seg movzwl -1(%_ASM_AX),%edx
29583 xor %eax,%eax
29584 ASM_CLAC
29585 + pax_force_retaddr
29586 ret
29587 CFI_ENDPROC
29588 ENDPROC(__get_user_2)
29589 @@ -66,14 +103,28 @@ ENDPROC(__get_user_2)
29590 ENTRY(__get_user_4)
29591 CFI_STARTPROC
29592 add $3,%_ASM_AX
29593 +
29594 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
29595 jc bad_get_user
29596 GET_THREAD_INFO(%_ASM_DX)
29597 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
29598 jae bad_get_user
29599 ASM_STAC
29600 -3: movl -3(%_ASM_AX),%edx
29601 +
29602 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
29603 + mov pax_user_shadow_base,%_ASM_DX
29604 + cmp %_ASM_DX,%_ASM_AX
29605 + jae 1234f
29606 + add %_ASM_DX,%_ASM_AX
29607 +1234:
29608 +#endif
29609 +
29610 +#endif
29611 +
29612 +3: __copyuser_seg movl -3(%_ASM_AX),%edx
29613 xor %eax,%eax
29614 ASM_CLAC
29615 + pax_force_retaddr
29616 ret
29617 CFI_ENDPROC
29618 ENDPROC(__get_user_4)
29619 @@ -86,10 +137,20 @@ ENTRY(__get_user_8)
29620 GET_THREAD_INFO(%_ASM_DX)
29621 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
29622 jae bad_get_user
29623 +
29624 +#ifdef CONFIG_PAX_MEMORY_UDEREF
29625 + mov pax_user_shadow_base,%_ASM_DX
29626 + cmp %_ASM_DX,%_ASM_AX
29627 + jae 1234f
29628 + add %_ASM_DX,%_ASM_AX
29629 +1234:
29630 +#endif
29631 +
29632 ASM_STAC
29633 4: movq -7(%_ASM_AX),%rdx
29634 xor %eax,%eax
29635 ASM_CLAC
29636 + pax_force_retaddr
29637 ret
29638 #else
29639 add $7,%_ASM_AX
29640 @@ -98,10 +159,11 @@ ENTRY(__get_user_8)
29641 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
29642 jae bad_get_user_8
29643 ASM_STAC
29644 -4: movl -7(%_ASM_AX),%edx
29645 -5: movl -3(%_ASM_AX),%ecx
29646 +4: __copyuser_seg movl -7(%_ASM_AX),%edx
29647 +5: __copyuser_seg movl -3(%_ASM_AX),%ecx
29648 xor %eax,%eax
29649 ASM_CLAC
29650 + pax_force_retaddr
29651 ret
29652 #endif
29653 CFI_ENDPROC
29654 @@ -113,6 +175,7 @@ bad_get_user:
29655 xor %edx,%edx
29656 mov $(-EFAULT),%_ASM_AX
29657 ASM_CLAC
29658 + pax_force_retaddr
29659 ret
29660 CFI_ENDPROC
29661 END(bad_get_user)
29662 @@ -124,6 +187,7 @@ bad_get_user_8:
29663 xor %ecx,%ecx
29664 mov $(-EFAULT),%_ASM_AX
29665 ASM_CLAC
29666 + pax_force_retaddr
29667 ret
29668 CFI_ENDPROC
29669 END(bad_get_user_8)
29670 diff --git a/arch/x86/lib/insn.c b/arch/x86/lib/insn.c
29671 index 54fcffe..7be149e 100644
29672 --- a/arch/x86/lib/insn.c
29673 +++ b/arch/x86/lib/insn.c
29674 @@ -20,8 +20,10 @@
29675
29676 #ifdef __KERNEL__
29677 #include <linux/string.h>
29678 +#include <asm/pgtable_types.h>
29679 #else
29680 #include <string.h>
29681 +#define ktla_ktva(addr) addr
29682 #endif
29683 #include <asm/inat.h>
29684 #include <asm/insn.h>
29685 @@ -53,8 +55,8 @@
29686 void insn_init(struct insn *insn, const void *kaddr, int x86_64)
29687 {
29688 memset(insn, 0, sizeof(*insn));
29689 - insn->kaddr = kaddr;
29690 - insn->next_byte = kaddr;
29691 + insn->kaddr = ktla_ktva(kaddr);
29692 + insn->next_byte = ktla_ktva(kaddr);
29693 insn->x86_64 = x86_64 ? 1 : 0;
29694 insn->opnd_bytes = 4;
29695 if (x86_64)
29696 diff --git a/arch/x86/lib/iomap_copy_64.S b/arch/x86/lib/iomap_copy_64.S
29697 index 05a95e7..326f2fa 100644
29698 --- a/arch/x86/lib/iomap_copy_64.S
29699 +++ b/arch/x86/lib/iomap_copy_64.S
29700 @@ -17,6 +17,7 @@
29701
29702 #include <linux/linkage.h>
29703 #include <asm/dwarf2.h>
29704 +#include <asm/alternative-asm.h>
29705
29706 /*
29707 * override generic version in lib/iomap_copy.c
29708 @@ -25,6 +26,7 @@ ENTRY(__iowrite32_copy)
29709 CFI_STARTPROC
29710 movl %edx,%ecx
29711 rep movsd
29712 + pax_force_retaddr
29713 ret
29714 CFI_ENDPROC
29715 ENDPROC(__iowrite32_copy)
29716 diff --git a/arch/x86/lib/memcpy_64.S b/arch/x86/lib/memcpy_64.S
29717 index 56313a3..0db417e 100644
29718 --- a/arch/x86/lib/memcpy_64.S
29719 +++ b/arch/x86/lib/memcpy_64.S
29720 @@ -24,7 +24,7 @@
29721 * This gets patched over the unrolled variant (below) via the
29722 * alternative instructions framework:
29723 */
29724 - .section .altinstr_replacement, "ax", @progbits
29725 + .section .altinstr_replacement, "a", @progbits
29726 .Lmemcpy_c:
29727 movq %rdi, %rax
29728 movq %rdx, %rcx
29729 @@ -33,6 +33,7 @@
29730 rep movsq
29731 movl %edx, %ecx
29732 rep movsb
29733 + pax_force_retaddr
29734 ret
29735 .Lmemcpy_e:
29736 .previous
29737 @@ -44,11 +45,12 @@
29738 * This gets patched over the unrolled variant (below) via the
29739 * alternative instructions framework:
29740 */
29741 - .section .altinstr_replacement, "ax", @progbits
29742 + .section .altinstr_replacement, "a", @progbits
29743 .Lmemcpy_c_e:
29744 movq %rdi, %rax
29745 movq %rdx, %rcx
29746 rep movsb
29747 + pax_force_retaddr
29748 ret
29749 .Lmemcpy_e_e:
29750 .previous
29751 @@ -136,6 +138,7 @@ ENTRY(memcpy)
29752 movq %r9, 1*8(%rdi)
29753 movq %r10, -2*8(%rdi, %rdx)
29754 movq %r11, -1*8(%rdi, %rdx)
29755 + pax_force_retaddr
29756 retq
29757 .p2align 4
29758 .Lless_16bytes:
29759 @@ -148,6 +151,7 @@ ENTRY(memcpy)
29760 movq -1*8(%rsi, %rdx), %r9
29761 movq %r8, 0*8(%rdi)
29762 movq %r9, -1*8(%rdi, %rdx)
29763 + pax_force_retaddr
29764 retq
29765 .p2align 4
29766 .Lless_8bytes:
29767 @@ -161,6 +165,7 @@ ENTRY(memcpy)
29768 movl -4(%rsi, %rdx), %r8d
29769 movl %ecx, (%rdi)
29770 movl %r8d, -4(%rdi, %rdx)
29771 + pax_force_retaddr
29772 retq
29773 .p2align 4
29774 .Lless_3bytes:
29775 @@ -179,6 +184,7 @@ ENTRY(memcpy)
29776 movb %cl, (%rdi)
29777
29778 .Lend:
29779 + pax_force_retaddr
29780 retq
29781 CFI_ENDPROC
29782 ENDPROC(memcpy)
29783 diff --git a/arch/x86/lib/memmove_64.S b/arch/x86/lib/memmove_64.S
29784 index 65268a6..dd1de11 100644
29785 --- a/arch/x86/lib/memmove_64.S
29786 +++ b/arch/x86/lib/memmove_64.S
29787 @@ -202,14 +202,16 @@ ENTRY(memmove)
29788 movb (%rsi), %r11b
29789 movb %r11b, (%rdi)
29790 13:
29791 + pax_force_retaddr
29792 retq
29793 CFI_ENDPROC
29794
29795 - .section .altinstr_replacement,"ax"
29796 + .section .altinstr_replacement,"a"
29797 .Lmemmove_begin_forward_efs:
29798 /* Forward moving data. */
29799 movq %rdx, %rcx
29800 rep movsb
29801 + pax_force_retaddr
29802 retq
29803 .Lmemmove_end_forward_efs:
29804 .previous
29805 diff --git a/arch/x86/lib/memset_64.S b/arch/x86/lib/memset_64.S
29806 index 2dcb380..2eb79fe 100644
29807 --- a/arch/x86/lib/memset_64.S
29808 +++ b/arch/x86/lib/memset_64.S
29809 @@ -16,7 +16,7 @@
29810 *
29811 * rax original destination
29812 */
29813 - .section .altinstr_replacement, "ax", @progbits
29814 + .section .altinstr_replacement, "a", @progbits
29815 .Lmemset_c:
29816 movq %rdi,%r9
29817 movq %rdx,%rcx
29818 @@ -30,6 +30,7 @@
29819 movl %edx,%ecx
29820 rep stosb
29821 movq %r9,%rax
29822 + pax_force_retaddr
29823 ret
29824 .Lmemset_e:
29825 .previous
29826 @@ -45,13 +46,14 @@
29827 *
29828 * rax original destination
29829 */
29830 - .section .altinstr_replacement, "ax", @progbits
29831 + .section .altinstr_replacement, "a", @progbits
29832 .Lmemset_c_e:
29833 movq %rdi,%r9
29834 movb %sil,%al
29835 movq %rdx,%rcx
29836 rep stosb
29837 movq %r9,%rax
29838 + pax_force_retaddr
29839 ret
29840 .Lmemset_e_e:
29841 .previous
29842 @@ -118,6 +120,7 @@ ENTRY(__memset)
29843
29844 .Lende:
29845 movq %r10,%rax
29846 + pax_force_retaddr
29847 ret
29848
29849 CFI_RESTORE_STATE
29850 diff --git a/arch/x86/lib/mmx_32.c b/arch/x86/lib/mmx_32.c
29851 index c9f2d9b..e7fd2c0 100644
29852 --- a/arch/x86/lib/mmx_32.c
29853 +++ b/arch/x86/lib/mmx_32.c
29854 @@ -29,6 +29,7 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
29855 {
29856 void *p;
29857 int i;
29858 + unsigned long cr0;
29859
29860 if (unlikely(in_interrupt()))
29861 return __memcpy(to, from, len);
29862 @@ -39,44 +40,72 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
29863 kernel_fpu_begin();
29864
29865 __asm__ __volatile__ (
29866 - "1: prefetch (%0)\n" /* This set is 28 bytes */
29867 - " prefetch 64(%0)\n"
29868 - " prefetch 128(%0)\n"
29869 - " prefetch 192(%0)\n"
29870 - " prefetch 256(%0)\n"
29871 + "1: prefetch (%1)\n" /* This set is 28 bytes */
29872 + " prefetch 64(%1)\n"
29873 + " prefetch 128(%1)\n"
29874 + " prefetch 192(%1)\n"
29875 + " prefetch 256(%1)\n"
29876 "2: \n"
29877 ".section .fixup, \"ax\"\n"
29878 - "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
29879 + "3: \n"
29880 +
29881 +#ifdef CONFIG_PAX_KERNEXEC
29882 + " movl %%cr0, %0\n"
29883 + " movl %0, %%eax\n"
29884 + " andl $0xFFFEFFFF, %%eax\n"
29885 + " movl %%eax, %%cr0\n"
29886 +#endif
29887 +
29888 + " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
29889 +
29890 +#ifdef CONFIG_PAX_KERNEXEC
29891 + " movl %0, %%cr0\n"
29892 +#endif
29893 +
29894 " jmp 2b\n"
29895 ".previous\n"
29896 _ASM_EXTABLE(1b, 3b)
29897 - : : "r" (from));
29898 + : "=&r" (cr0) : "r" (from) : "ax");
29899
29900 for ( ; i > 5; i--) {
29901 __asm__ __volatile__ (
29902 - "1: prefetch 320(%0)\n"
29903 - "2: movq (%0), %%mm0\n"
29904 - " movq 8(%0), %%mm1\n"
29905 - " movq 16(%0), %%mm2\n"
29906 - " movq 24(%0), %%mm3\n"
29907 - " movq %%mm0, (%1)\n"
29908 - " movq %%mm1, 8(%1)\n"
29909 - " movq %%mm2, 16(%1)\n"
29910 - " movq %%mm3, 24(%1)\n"
29911 - " movq 32(%0), %%mm0\n"
29912 - " movq 40(%0), %%mm1\n"
29913 - " movq 48(%0), %%mm2\n"
29914 - " movq 56(%0), %%mm3\n"
29915 - " movq %%mm0, 32(%1)\n"
29916 - " movq %%mm1, 40(%1)\n"
29917 - " movq %%mm2, 48(%1)\n"
29918 - " movq %%mm3, 56(%1)\n"
29919 + "1: prefetch 320(%1)\n"
29920 + "2: movq (%1), %%mm0\n"
29921 + " movq 8(%1), %%mm1\n"
29922 + " movq 16(%1), %%mm2\n"
29923 + " movq 24(%1), %%mm3\n"
29924 + " movq %%mm0, (%2)\n"
29925 + " movq %%mm1, 8(%2)\n"
29926 + " movq %%mm2, 16(%2)\n"
29927 + " movq %%mm3, 24(%2)\n"
29928 + " movq 32(%1), %%mm0\n"
29929 + " movq 40(%1), %%mm1\n"
29930 + " movq 48(%1), %%mm2\n"
29931 + " movq 56(%1), %%mm3\n"
29932 + " movq %%mm0, 32(%2)\n"
29933 + " movq %%mm1, 40(%2)\n"
29934 + " movq %%mm2, 48(%2)\n"
29935 + " movq %%mm3, 56(%2)\n"
29936 ".section .fixup, \"ax\"\n"
29937 - "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
29938 + "3:\n"
29939 +
29940 +#ifdef CONFIG_PAX_KERNEXEC
29941 + " movl %%cr0, %0\n"
29942 + " movl %0, %%eax\n"
29943 + " andl $0xFFFEFFFF, %%eax\n"
29944 + " movl %%eax, %%cr0\n"
29945 +#endif
29946 +
29947 + " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
29948 +
29949 +#ifdef CONFIG_PAX_KERNEXEC
29950 + " movl %0, %%cr0\n"
29951 +#endif
29952 +
29953 " jmp 2b\n"
29954 ".previous\n"
29955 _ASM_EXTABLE(1b, 3b)
29956 - : : "r" (from), "r" (to) : "memory");
29957 + : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
29958
29959 from += 64;
29960 to += 64;
29961 @@ -158,6 +187,7 @@ static void fast_clear_page(void *page)
29962 static void fast_copy_page(void *to, void *from)
29963 {
29964 int i;
29965 + unsigned long cr0;
29966
29967 kernel_fpu_begin();
29968
29969 @@ -166,42 +196,70 @@ static void fast_copy_page(void *to, void *from)
29970 * but that is for later. -AV
29971 */
29972 __asm__ __volatile__(
29973 - "1: prefetch (%0)\n"
29974 - " prefetch 64(%0)\n"
29975 - " prefetch 128(%0)\n"
29976 - " prefetch 192(%0)\n"
29977 - " prefetch 256(%0)\n"
29978 + "1: prefetch (%1)\n"
29979 + " prefetch 64(%1)\n"
29980 + " prefetch 128(%1)\n"
29981 + " prefetch 192(%1)\n"
29982 + " prefetch 256(%1)\n"
29983 "2: \n"
29984 ".section .fixup, \"ax\"\n"
29985 - "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
29986 + "3: \n"
29987 +
29988 +#ifdef CONFIG_PAX_KERNEXEC
29989 + " movl %%cr0, %0\n"
29990 + " movl %0, %%eax\n"
29991 + " andl $0xFFFEFFFF, %%eax\n"
29992 + " movl %%eax, %%cr0\n"
29993 +#endif
29994 +
29995 + " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
29996 +
29997 +#ifdef CONFIG_PAX_KERNEXEC
29998 + " movl %0, %%cr0\n"
29999 +#endif
30000 +
30001 " jmp 2b\n"
30002 ".previous\n"
30003 - _ASM_EXTABLE(1b, 3b) : : "r" (from));
30004 + _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
30005
30006 for (i = 0; i < (4096-320)/64; i++) {
30007 __asm__ __volatile__ (
30008 - "1: prefetch 320(%0)\n"
30009 - "2: movq (%0), %%mm0\n"
30010 - " movntq %%mm0, (%1)\n"
30011 - " movq 8(%0), %%mm1\n"
30012 - " movntq %%mm1, 8(%1)\n"
30013 - " movq 16(%0), %%mm2\n"
30014 - " movntq %%mm2, 16(%1)\n"
30015 - " movq 24(%0), %%mm3\n"
30016 - " movntq %%mm3, 24(%1)\n"
30017 - " movq 32(%0), %%mm4\n"
30018 - " movntq %%mm4, 32(%1)\n"
30019 - " movq 40(%0), %%mm5\n"
30020 - " movntq %%mm5, 40(%1)\n"
30021 - " movq 48(%0), %%mm6\n"
30022 - " movntq %%mm6, 48(%1)\n"
30023 - " movq 56(%0), %%mm7\n"
30024 - " movntq %%mm7, 56(%1)\n"
30025 + "1: prefetch 320(%1)\n"
30026 + "2: movq (%1), %%mm0\n"
30027 + " movntq %%mm0, (%2)\n"
30028 + " movq 8(%1), %%mm1\n"
30029 + " movntq %%mm1, 8(%2)\n"
30030 + " movq 16(%1), %%mm2\n"
30031 + " movntq %%mm2, 16(%2)\n"
30032 + " movq 24(%1), %%mm3\n"
30033 + " movntq %%mm3, 24(%2)\n"
30034 + " movq 32(%1), %%mm4\n"
30035 + " movntq %%mm4, 32(%2)\n"
30036 + " movq 40(%1), %%mm5\n"
30037 + " movntq %%mm5, 40(%2)\n"
30038 + " movq 48(%1), %%mm6\n"
30039 + " movntq %%mm6, 48(%2)\n"
30040 + " movq 56(%1), %%mm7\n"
30041 + " movntq %%mm7, 56(%2)\n"
30042 ".section .fixup, \"ax\"\n"
30043 - "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
30044 + "3:\n"
30045 +
30046 +#ifdef CONFIG_PAX_KERNEXEC
30047 + " movl %%cr0, %0\n"
30048 + " movl %0, %%eax\n"
30049 + " andl $0xFFFEFFFF, %%eax\n"
30050 + " movl %%eax, %%cr0\n"
30051 +#endif
30052 +
30053 + " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
30054 +
30055 +#ifdef CONFIG_PAX_KERNEXEC
30056 + " movl %0, %%cr0\n"
30057 +#endif
30058 +
30059 " jmp 2b\n"
30060 ".previous\n"
30061 - _ASM_EXTABLE(1b, 3b) : : "r" (from), "r" (to) : "memory");
30062 + _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
30063
30064 from += 64;
30065 to += 64;
30066 @@ -280,47 +338,76 @@ static void fast_clear_page(void *page)
30067 static void fast_copy_page(void *to, void *from)
30068 {
30069 int i;
30070 + unsigned long cr0;
30071
30072 kernel_fpu_begin();
30073
30074 __asm__ __volatile__ (
30075 - "1: prefetch (%0)\n"
30076 - " prefetch 64(%0)\n"
30077 - " prefetch 128(%0)\n"
30078 - " prefetch 192(%0)\n"
30079 - " prefetch 256(%0)\n"
30080 + "1: prefetch (%1)\n"
30081 + " prefetch 64(%1)\n"
30082 + " prefetch 128(%1)\n"
30083 + " prefetch 192(%1)\n"
30084 + " prefetch 256(%1)\n"
30085 "2: \n"
30086 ".section .fixup, \"ax\"\n"
30087 - "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
30088 + "3: \n"
30089 +
30090 +#ifdef CONFIG_PAX_KERNEXEC
30091 + " movl %%cr0, %0\n"
30092 + " movl %0, %%eax\n"
30093 + " andl $0xFFFEFFFF, %%eax\n"
30094 + " movl %%eax, %%cr0\n"
30095 +#endif
30096 +
30097 + " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
30098 +
30099 +#ifdef CONFIG_PAX_KERNEXEC
30100 + " movl %0, %%cr0\n"
30101 +#endif
30102 +
30103 " jmp 2b\n"
30104 ".previous\n"
30105 - _ASM_EXTABLE(1b, 3b) : : "r" (from));
30106 + _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
30107
30108 for (i = 0; i < 4096/64; i++) {
30109 __asm__ __volatile__ (
30110 - "1: prefetch 320(%0)\n"
30111 - "2: movq (%0), %%mm0\n"
30112 - " movq 8(%0), %%mm1\n"
30113 - " movq 16(%0), %%mm2\n"
30114 - " movq 24(%0), %%mm3\n"
30115 - " movq %%mm0, (%1)\n"
30116 - " movq %%mm1, 8(%1)\n"
30117 - " movq %%mm2, 16(%1)\n"
30118 - " movq %%mm3, 24(%1)\n"
30119 - " movq 32(%0), %%mm0\n"
30120 - " movq 40(%0), %%mm1\n"
30121 - " movq 48(%0), %%mm2\n"
30122 - " movq 56(%0), %%mm3\n"
30123 - " movq %%mm0, 32(%1)\n"
30124 - " movq %%mm1, 40(%1)\n"
30125 - " movq %%mm2, 48(%1)\n"
30126 - " movq %%mm3, 56(%1)\n"
30127 + "1: prefetch 320(%1)\n"
30128 + "2: movq (%1), %%mm0\n"
30129 + " movq 8(%1), %%mm1\n"
30130 + " movq 16(%1), %%mm2\n"
30131 + " movq 24(%1), %%mm3\n"
30132 + " movq %%mm0, (%2)\n"
30133 + " movq %%mm1, 8(%2)\n"
30134 + " movq %%mm2, 16(%2)\n"
30135 + " movq %%mm3, 24(%2)\n"
30136 + " movq 32(%1), %%mm0\n"
30137 + " movq 40(%1), %%mm1\n"
30138 + " movq 48(%1), %%mm2\n"
30139 + " movq 56(%1), %%mm3\n"
30140 + " movq %%mm0, 32(%2)\n"
30141 + " movq %%mm1, 40(%2)\n"
30142 + " movq %%mm2, 48(%2)\n"
30143 + " movq %%mm3, 56(%2)\n"
30144 ".section .fixup, \"ax\"\n"
30145 - "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
30146 + "3:\n"
30147 +
30148 +#ifdef CONFIG_PAX_KERNEXEC
30149 + " movl %%cr0, %0\n"
30150 + " movl %0, %%eax\n"
30151 + " andl $0xFFFEFFFF, %%eax\n"
30152 + " movl %%eax, %%cr0\n"
30153 +#endif
30154 +
30155 + " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
30156 +
30157 +#ifdef CONFIG_PAX_KERNEXEC
30158 + " movl %0, %%cr0\n"
30159 +#endif
30160 +
30161 " jmp 2b\n"
30162 ".previous\n"
30163 _ASM_EXTABLE(1b, 3b)
30164 - : : "r" (from), "r" (to) : "memory");
30165 + : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
30166
30167 from += 64;
30168 to += 64;
30169 diff --git a/arch/x86/lib/msr-reg.S b/arch/x86/lib/msr-reg.S
30170 index f6d13ee..d789440 100644
30171 --- a/arch/x86/lib/msr-reg.S
30172 +++ b/arch/x86/lib/msr-reg.S
30173 @@ -3,6 +3,7 @@
30174 #include <asm/dwarf2.h>
30175 #include <asm/asm.h>
30176 #include <asm/msr.h>
30177 +#include <asm/alternative-asm.h>
30178
30179 #ifdef CONFIG_X86_64
30180 /*
30181 @@ -37,6 +38,7 @@ ENTRY(\op\()_safe_regs)
30182 movl %edi, 28(%r10)
30183 popq_cfi %rbp
30184 popq_cfi %rbx
30185 + pax_force_retaddr
30186 ret
30187 3:
30188 CFI_RESTORE_STATE
30189 diff --git a/arch/x86/lib/putuser.S b/arch/x86/lib/putuser.S
30190 index fc6ba17..d4d989d 100644
30191 --- a/arch/x86/lib/putuser.S
30192 +++ b/arch/x86/lib/putuser.S
30193 @@ -16,7 +16,9 @@
30194 #include <asm/errno.h>
30195 #include <asm/asm.h>
30196 #include <asm/smap.h>
30197 -
30198 +#include <asm/segment.h>
30199 +#include <asm/pgtable.h>
30200 +#include <asm/alternative-asm.h>
30201
30202 /*
30203 * __put_user_X
30204 @@ -30,57 +32,125 @@
30205 * as they get called from within inline assembly.
30206 */
30207
30208 -#define ENTER CFI_STARTPROC ; \
30209 - GET_THREAD_INFO(%_ASM_BX)
30210 -#define EXIT ASM_CLAC ; \
30211 - ret ; \
30212 +#define ENTER CFI_STARTPROC
30213 +#define EXIT ASM_CLAC ; \
30214 + pax_force_retaddr ; \
30215 + ret ; \
30216 CFI_ENDPROC
30217
30218 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
30219 +#define _DEST %_ASM_CX,%_ASM_BX
30220 +#else
30221 +#define _DEST %_ASM_CX
30222 +#endif
30223 +
30224 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
30225 +#define __copyuser_seg gs;
30226 +#else
30227 +#define __copyuser_seg
30228 +#endif
30229 +
30230 .text
30231 ENTRY(__put_user_1)
30232 ENTER
30233 +
30234 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
30235 + GET_THREAD_INFO(%_ASM_BX)
30236 cmp TI_addr_limit(%_ASM_BX),%_ASM_CX
30237 jae bad_put_user
30238 ASM_STAC
30239 -1: movb %al,(%_ASM_CX)
30240 +
30241 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
30242 + mov pax_user_shadow_base,%_ASM_BX
30243 + cmp %_ASM_BX,%_ASM_CX
30244 + jb 1234f
30245 + xor %ebx,%ebx
30246 +1234:
30247 +#endif
30248 +
30249 +#endif
30250 +
30251 +1: __copyuser_seg movb %al,(_DEST)
30252 xor %eax,%eax
30253 EXIT
30254 ENDPROC(__put_user_1)
30255
30256 ENTRY(__put_user_2)
30257 ENTER
30258 +
30259 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
30260 + GET_THREAD_INFO(%_ASM_BX)
30261 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
30262 sub $1,%_ASM_BX
30263 cmp %_ASM_BX,%_ASM_CX
30264 jae bad_put_user
30265 ASM_STAC
30266 -2: movw %ax,(%_ASM_CX)
30267 +
30268 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
30269 + mov pax_user_shadow_base,%_ASM_BX
30270 + cmp %_ASM_BX,%_ASM_CX
30271 + jb 1234f
30272 + xor %ebx,%ebx
30273 +1234:
30274 +#endif
30275 +
30276 +#endif
30277 +
30278 +2: __copyuser_seg movw %ax,(_DEST)
30279 xor %eax,%eax
30280 EXIT
30281 ENDPROC(__put_user_2)
30282
30283 ENTRY(__put_user_4)
30284 ENTER
30285 +
30286 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
30287 + GET_THREAD_INFO(%_ASM_BX)
30288 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
30289 sub $3,%_ASM_BX
30290 cmp %_ASM_BX,%_ASM_CX
30291 jae bad_put_user
30292 ASM_STAC
30293 -3: movl %eax,(%_ASM_CX)
30294 +
30295 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
30296 + mov pax_user_shadow_base,%_ASM_BX
30297 + cmp %_ASM_BX,%_ASM_CX
30298 + jb 1234f
30299 + xor %ebx,%ebx
30300 +1234:
30301 +#endif
30302 +
30303 +#endif
30304 +
30305 +3: __copyuser_seg movl %eax,(_DEST)
30306 xor %eax,%eax
30307 EXIT
30308 ENDPROC(__put_user_4)
30309
30310 ENTRY(__put_user_8)
30311 ENTER
30312 +
30313 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
30314 + GET_THREAD_INFO(%_ASM_BX)
30315 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
30316 sub $7,%_ASM_BX
30317 cmp %_ASM_BX,%_ASM_CX
30318 jae bad_put_user
30319 ASM_STAC
30320 -4: mov %_ASM_AX,(%_ASM_CX)
30321 +
30322 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
30323 + mov pax_user_shadow_base,%_ASM_BX
30324 + cmp %_ASM_BX,%_ASM_CX
30325 + jb 1234f
30326 + xor %ebx,%ebx
30327 +1234:
30328 +#endif
30329 +
30330 +#endif
30331 +
30332 +4: __copyuser_seg mov %_ASM_AX,(_DEST)
30333 #ifdef CONFIG_X86_32
30334 -5: movl %edx,4(%_ASM_CX)
30335 +5: __copyuser_seg movl %edx,4(_DEST)
30336 #endif
30337 xor %eax,%eax
30338 EXIT
30339 diff --git a/arch/x86/lib/rwlock.S b/arch/x86/lib/rwlock.S
30340 index 1cad221..de671ee 100644
30341 --- a/arch/x86/lib/rwlock.S
30342 +++ b/arch/x86/lib/rwlock.S
30343 @@ -16,13 +16,34 @@ ENTRY(__write_lock_failed)
30344 FRAME
30345 0: LOCK_PREFIX
30346 WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
30347 +
30348 +#ifdef CONFIG_PAX_REFCOUNT
30349 + jno 1234f
30350 + LOCK_PREFIX
30351 + WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
30352 + int $4
30353 +1234:
30354 + _ASM_EXTABLE(1234b, 1234b)
30355 +#endif
30356 +
30357 1: rep; nop
30358 cmpl $WRITE_LOCK_CMP, (%__lock_ptr)
30359 jne 1b
30360 LOCK_PREFIX
30361 WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
30362 +
30363 +#ifdef CONFIG_PAX_REFCOUNT
30364 + jno 1234f
30365 + LOCK_PREFIX
30366 + WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
30367 + int $4
30368 +1234:
30369 + _ASM_EXTABLE(1234b, 1234b)
30370 +#endif
30371 +
30372 jnz 0b
30373 ENDFRAME
30374 + pax_force_retaddr
30375 ret
30376 CFI_ENDPROC
30377 END(__write_lock_failed)
30378 @@ -32,13 +53,34 @@ ENTRY(__read_lock_failed)
30379 FRAME
30380 0: LOCK_PREFIX
30381 READ_LOCK_SIZE(inc) (%__lock_ptr)
30382 +
30383 +#ifdef CONFIG_PAX_REFCOUNT
30384 + jno 1234f
30385 + LOCK_PREFIX
30386 + READ_LOCK_SIZE(dec) (%__lock_ptr)
30387 + int $4
30388 +1234:
30389 + _ASM_EXTABLE(1234b, 1234b)
30390 +#endif
30391 +
30392 1: rep; nop
30393 READ_LOCK_SIZE(cmp) $1, (%__lock_ptr)
30394 js 1b
30395 LOCK_PREFIX
30396 READ_LOCK_SIZE(dec) (%__lock_ptr)
30397 +
30398 +#ifdef CONFIG_PAX_REFCOUNT
30399 + jno 1234f
30400 + LOCK_PREFIX
30401 + READ_LOCK_SIZE(inc) (%__lock_ptr)
30402 + int $4
30403 +1234:
30404 + _ASM_EXTABLE(1234b, 1234b)
30405 +#endif
30406 +
30407 js 0b
30408 ENDFRAME
30409 + pax_force_retaddr
30410 ret
30411 CFI_ENDPROC
30412 END(__read_lock_failed)
30413 diff --git a/arch/x86/lib/rwsem.S b/arch/x86/lib/rwsem.S
30414 index 5dff5f0..cadebf4 100644
30415 --- a/arch/x86/lib/rwsem.S
30416 +++ b/arch/x86/lib/rwsem.S
30417 @@ -94,6 +94,7 @@ ENTRY(call_rwsem_down_read_failed)
30418 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
30419 CFI_RESTORE __ASM_REG(dx)
30420 restore_common_regs
30421 + pax_force_retaddr
30422 ret
30423 CFI_ENDPROC
30424 ENDPROC(call_rwsem_down_read_failed)
30425 @@ -104,6 +105,7 @@ ENTRY(call_rwsem_down_write_failed)
30426 movq %rax,%rdi
30427 call rwsem_down_write_failed
30428 restore_common_regs
30429 + pax_force_retaddr
30430 ret
30431 CFI_ENDPROC
30432 ENDPROC(call_rwsem_down_write_failed)
30433 @@ -117,7 +119,8 @@ ENTRY(call_rwsem_wake)
30434 movq %rax,%rdi
30435 call rwsem_wake
30436 restore_common_regs
30437 -1: ret
30438 +1: pax_force_retaddr
30439 + ret
30440 CFI_ENDPROC
30441 ENDPROC(call_rwsem_wake)
30442
30443 @@ -131,6 +134,7 @@ ENTRY(call_rwsem_downgrade_wake)
30444 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
30445 CFI_RESTORE __ASM_REG(dx)
30446 restore_common_regs
30447 + pax_force_retaddr
30448 ret
30449 CFI_ENDPROC
30450 ENDPROC(call_rwsem_downgrade_wake)
30451 diff --git a/arch/x86/lib/thunk_64.S b/arch/x86/lib/thunk_64.S
30452 index a63efd6..8149fbe 100644
30453 --- a/arch/x86/lib/thunk_64.S
30454 +++ b/arch/x86/lib/thunk_64.S
30455 @@ -8,6 +8,7 @@
30456 #include <linux/linkage.h>
30457 #include <asm/dwarf2.h>
30458 #include <asm/calling.h>
30459 +#include <asm/alternative-asm.h>
30460
30461 /* rdi: arg1 ... normal C conventions. rax is saved/restored. */
30462 .macro THUNK name, func, put_ret_addr_in_rdi=0
30463 @@ -15,11 +16,11 @@
30464 \name:
30465 CFI_STARTPROC
30466
30467 - /* this one pushes 9 elems, the next one would be %rIP */
30468 - SAVE_ARGS
30469 + /* this one pushes 15+1 elems, the next one would be %rIP */
30470 + SAVE_ARGS 8
30471
30472 .if \put_ret_addr_in_rdi
30473 - movq_cfi_restore 9*8, rdi
30474 + movq_cfi_restore RIP, rdi
30475 .endif
30476
30477 call \func
30478 @@ -38,8 +39,9 @@
30479
30480 /* SAVE_ARGS below is used only for the .cfi directives it contains. */
30481 CFI_STARTPROC
30482 - SAVE_ARGS
30483 + SAVE_ARGS 8
30484 restore:
30485 - RESTORE_ARGS
30486 + RESTORE_ARGS 1,8
30487 + pax_force_retaddr
30488 ret
30489 CFI_ENDPROC
30490 diff --git a/arch/x86/lib/usercopy_32.c b/arch/x86/lib/usercopy_32.c
30491 index e2f5e21..4b22130 100644
30492 --- a/arch/x86/lib/usercopy_32.c
30493 +++ b/arch/x86/lib/usercopy_32.c
30494 @@ -42,11 +42,13 @@ do { \
30495 int __d0; \
30496 might_fault(); \
30497 __asm__ __volatile__( \
30498 + __COPYUSER_SET_ES \
30499 ASM_STAC "\n" \
30500 "0: rep; stosl\n" \
30501 " movl %2,%0\n" \
30502 "1: rep; stosb\n" \
30503 "2: " ASM_CLAC "\n" \
30504 + __COPYUSER_RESTORE_ES \
30505 ".section .fixup,\"ax\"\n" \
30506 "3: lea 0(%2,%0,4),%0\n" \
30507 " jmp 2b\n" \
30508 @@ -98,7 +100,7 @@ EXPORT_SYMBOL(__clear_user);
30509
30510 #ifdef CONFIG_X86_INTEL_USERCOPY
30511 static unsigned long
30512 -__copy_user_intel(void __user *to, const void *from, unsigned long size)
30513 +__generic_copy_to_user_intel(void __user *to, const void *from, unsigned long size)
30514 {
30515 int d0, d1;
30516 __asm__ __volatile__(
30517 @@ -110,36 +112,36 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
30518 " .align 2,0x90\n"
30519 "3: movl 0(%4), %%eax\n"
30520 "4: movl 4(%4), %%edx\n"
30521 - "5: movl %%eax, 0(%3)\n"
30522 - "6: movl %%edx, 4(%3)\n"
30523 + "5: "__copyuser_seg" movl %%eax, 0(%3)\n"
30524 + "6: "__copyuser_seg" movl %%edx, 4(%3)\n"
30525 "7: movl 8(%4), %%eax\n"
30526 "8: movl 12(%4),%%edx\n"
30527 - "9: movl %%eax, 8(%3)\n"
30528 - "10: movl %%edx, 12(%3)\n"
30529 + "9: "__copyuser_seg" movl %%eax, 8(%3)\n"
30530 + "10: "__copyuser_seg" movl %%edx, 12(%3)\n"
30531 "11: movl 16(%4), %%eax\n"
30532 "12: movl 20(%4), %%edx\n"
30533 - "13: movl %%eax, 16(%3)\n"
30534 - "14: movl %%edx, 20(%3)\n"
30535 + "13: "__copyuser_seg" movl %%eax, 16(%3)\n"
30536 + "14: "__copyuser_seg" movl %%edx, 20(%3)\n"
30537 "15: movl 24(%4), %%eax\n"
30538 "16: movl 28(%4), %%edx\n"
30539 - "17: movl %%eax, 24(%3)\n"
30540 - "18: movl %%edx, 28(%3)\n"
30541 + "17: "__copyuser_seg" movl %%eax, 24(%3)\n"
30542 + "18: "__copyuser_seg" movl %%edx, 28(%3)\n"
30543 "19: movl 32(%4), %%eax\n"
30544 "20: movl 36(%4), %%edx\n"
30545 - "21: movl %%eax, 32(%3)\n"
30546 - "22: movl %%edx, 36(%3)\n"
30547 + "21: "__copyuser_seg" movl %%eax, 32(%3)\n"
30548 + "22: "__copyuser_seg" movl %%edx, 36(%3)\n"
30549 "23: movl 40(%4), %%eax\n"
30550 "24: movl 44(%4), %%edx\n"
30551 - "25: movl %%eax, 40(%3)\n"
30552 - "26: movl %%edx, 44(%3)\n"
30553 + "25: "__copyuser_seg" movl %%eax, 40(%3)\n"
30554 + "26: "__copyuser_seg" movl %%edx, 44(%3)\n"
30555 "27: movl 48(%4), %%eax\n"
30556 "28: movl 52(%4), %%edx\n"
30557 - "29: movl %%eax, 48(%3)\n"
30558 - "30: movl %%edx, 52(%3)\n"
30559 + "29: "__copyuser_seg" movl %%eax, 48(%3)\n"
30560 + "30: "__copyuser_seg" movl %%edx, 52(%3)\n"
30561 "31: movl 56(%4), %%eax\n"
30562 "32: movl 60(%4), %%edx\n"
30563 - "33: movl %%eax, 56(%3)\n"
30564 - "34: movl %%edx, 60(%3)\n"
30565 + "33: "__copyuser_seg" movl %%eax, 56(%3)\n"
30566 + "34: "__copyuser_seg" movl %%edx, 60(%3)\n"
30567 " addl $-64, %0\n"
30568 " addl $64, %4\n"
30569 " addl $64, %3\n"
30570 @@ -149,10 +151,116 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
30571 " shrl $2, %0\n"
30572 " andl $3, %%eax\n"
30573 " cld\n"
30574 + __COPYUSER_SET_ES
30575 "99: rep; movsl\n"
30576 "36: movl %%eax, %0\n"
30577 "37: rep; movsb\n"
30578 "100:\n"
30579 + __COPYUSER_RESTORE_ES
30580 + ".section .fixup,\"ax\"\n"
30581 + "101: lea 0(%%eax,%0,4),%0\n"
30582 + " jmp 100b\n"
30583 + ".previous\n"
30584 + _ASM_EXTABLE(1b,100b)
30585 + _ASM_EXTABLE(2b,100b)
30586 + _ASM_EXTABLE(3b,100b)
30587 + _ASM_EXTABLE(4b,100b)
30588 + _ASM_EXTABLE(5b,100b)
30589 + _ASM_EXTABLE(6b,100b)
30590 + _ASM_EXTABLE(7b,100b)
30591 + _ASM_EXTABLE(8b,100b)
30592 + _ASM_EXTABLE(9b,100b)
30593 + _ASM_EXTABLE(10b,100b)
30594 + _ASM_EXTABLE(11b,100b)
30595 + _ASM_EXTABLE(12b,100b)
30596 + _ASM_EXTABLE(13b,100b)
30597 + _ASM_EXTABLE(14b,100b)
30598 + _ASM_EXTABLE(15b,100b)
30599 + _ASM_EXTABLE(16b,100b)
30600 + _ASM_EXTABLE(17b,100b)
30601 + _ASM_EXTABLE(18b,100b)
30602 + _ASM_EXTABLE(19b,100b)
30603 + _ASM_EXTABLE(20b,100b)
30604 + _ASM_EXTABLE(21b,100b)
30605 + _ASM_EXTABLE(22b,100b)
30606 + _ASM_EXTABLE(23b,100b)
30607 + _ASM_EXTABLE(24b,100b)
30608 + _ASM_EXTABLE(25b,100b)
30609 + _ASM_EXTABLE(26b,100b)
30610 + _ASM_EXTABLE(27b,100b)
30611 + _ASM_EXTABLE(28b,100b)
30612 + _ASM_EXTABLE(29b,100b)
30613 + _ASM_EXTABLE(30b,100b)
30614 + _ASM_EXTABLE(31b,100b)
30615 + _ASM_EXTABLE(32b,100b)
30616 + _ASM_EXTABLE(33b,100b)
30617 + _ASM_EXTABLE(34b,100b)
30618 + _ASM_EXTABLE(35b,100b)
30619 + _ASM_EXTABLE(36b,100b)
30620 + _ASM_EXTABLE(37b,100b)
30621 + _ASM_EXTABLE(99b,101b)
30622 + : "=&c"(size), "=&D" (d0), "=&S" (d1)
30623 + : "1"(to), "2"(from), "0"(size)
30624 + : "eax", "edx", "memory");
30625 + return size;
30626 +}
30627 +
30628 +static unsigned long
30629 +__generic_copy_from_user_intel(void *to, const void __user *from, unsigned long size)
30630 +{
30631 + int d0, d1;
30632 + __asm__ __volatile__(
30633 + " .align 2,0x90\n"
30634 + "1: "__copyuser_seg" movl 32(%4), %%eax\n"
30635 + " cmpl $67, %0\n"
30636 + " jbe 3f\n"
30637 + "2: "__copyuser_seg" movl 64(%4), %%eax\n"
30638 + " .align 2,0x90\n"
30639 + "3: "__copyuser_seg" movl 0(%4), %%eax\n"
30640 + "4: "__copyuser_seg" movl 4(%4), %%edx\n"
30641 + "5: movl %%eax, 0(%3)\n"
30642 + "6: movl %%edx, 4(%3)\n"
30643 + "7: "__copyuser_seg" movl 8(%4), %%eax\n"
30644 + "8: "__copyuser_seg" movl 12(%4),%%edx\n"
30645 + "9: movl %%eax, 8(%3)\n"
30646 + "10: movl %%edx, 12(%3)\n"
30647 + "11: "__copyuser_seg" movl 16(%4), %%eax\n"
30648 + "12: "__copyuser_seg" movl 20(%4), %%edx\n"
30649 + "13: movl %%eax, 16(%3)\n"
30650 + "14: movl %%edx, 20(%3)\n"
30651 + "15: "__copyuser_seg" movl 24(%4), %%eax\n"
30652 + "16: "__copyuser_seg" movl 28(%4), %%edx\n"
30653 + "17: movl %%eax, 24(%3)\n"
30654 + "18: movl %%edx, 28(%3)\n"
30655 + "19: "__copyuser_seg" movl 32(%4), %%eax\n"
30656 + "20: "__copyuser_seg" movl 36(%4), %%edx\n"
30657 + "21: movl %%eax, 32(%3)\n"
30658 + "22: movl %%edx, 36(%3)\n"
30659 + "23: "__copyuser_seg" movl 40(%4), %%eax\n"
30660 + "24: "__copyuser_seg" movl 44(%4), %%edx\n"
30661 + "25: movl %%eax, 40(%3)\n"
30662 + "26: movl %%edx, 44(%3)\n"
30663 + "27: "__copyuser_seg" movl 48(%4), %%eax\n"
30664 + "28: "__copyuser_seg" movl 52(%4), %%edx\n"
30665 + "29: movl %%eax, 48(%3)\n"
30666 + "30: movl %%edx, 52(%3)\n"
30667 + "31: "__copyuser_seg" movl 56(%4), %%eax\n"
30668 + "32: "__copyuser_seg" movl 60(%4), %%edx\n"
30669 + "33: movl %%eax, 56(%3)\n"
30670 + "34: movl %%edx, 60(%3)\n"
30671 + " addl $-64, %0\n"
30672 + " addl $64, %4\n"
30673 + " addl $64, %3\n"
30674 + " cmpl $63, %0\n"
30675 + " ja 1b\n"
30676 + "35: movl %0, %%eax\n"
30677 + " shrl $2, %0\n"
30678 + " andl $3, %%eax\n"
30679 + " cld\n"
30680 + "99: rep; "__copyuser_seg" movsl\n"
30681 + "36: movl %%eax, %0\n"
30682 + "37: rep; "__copyuser_seg" movsb\n"
30683 + "100:\n"
30684 ".section .fixup,\"ax\"\n"
30685 "101: lea 0(%%eax,%0,4),%0\n"
30686 " jmp 100b\n"
30687 @@ -207,41 +315,41 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
30688 int d0, d1;
30689 __asm__ __volatile__(
30690 " .align 2,0x90\n"
30691 - "0: movl 32(%4), %%eax\n"
30692 + "0: "__copyuser_seg" movl 32(%4), %%eax\n"
30693 " cmpl $67, %0\n"
30694 " jbe 2f\n"
30695 - "1: movl 64(%4), %%eax\n"
30696 + "1: "__copyuser_seg" movl 64(%4), %%eax\n"
30697 " .align 2,0x90\n"
30698 - "2: movl 0(%4), %%eax\n"
30699 - "21: movl 4(%4), %%edx\n"
30700 + "2: "__copyuser_seg" movl 0(%4), %%eax\n"
30701 + "21: "__copyuser_seg" movl 4(%4), %%edx\n"
30702 " movl %%eax, 0(%3)\n"
30703 " movl %%edx, 4(%3)\n"
30704 - "3: movl 8(%4), %%eax\n"
30705 - "31: movl 12(%4),%%edx\n"
30706 + "3: "__copyuser_seg" movl 8(%4), %%eax\n"
30707 + "31: "__copyuser_seg" movl 12(%4),%%edx\n"
30708 " movl %%eax, 8(%3)\n"
30709 " movl %%edx, 12(%3)\n"
30710 - "4: movl 16(%4), %%eax\n"
30711 - "41: movl 20(%4), %%edx\n"
30712 + "4: "__copyuser_seg" movl 16(%4), %%eax\n"
30713 + "41: "__copyuser_seg" movl 20(%4), %%edx\n"
30714 " movl %%eax, 16(%3)\n"
30715 " movl %%edx, 20(%3)\n"
30716 - "10: movl 24(%4), %%eax\n"
30717 - "51: movl 28(%4), %%edx\n"
30718 + "10: "__copyuser_seg" movl 24(%4), %%eax\n"
30719 + "51: "__copyuser_seg" movl 28(%4), %%edx\n"
30720 " movl %%eax, 24(%3)\n"
30721 " movl %%edx, 28(%3)\n"
30722 - "11: movl 32(%4), %%eax\n"
30723 - "61: movl 36(%4), %%edx\n"
30724 + "11: "__copyuser_seg" movl 32(%4), %%eax\n"
30725 + "61: "__copyuser_seg" movl 36(%4), %%edx\n"
30726 " movl %%eax, 32(%3)\n"
30727 " movl %%edx, 36(%3)\n"
30728 - "12: movl 40(%4), %%eax\n"
30729 - "71: movl 44(%4), %%edx\n"
30730 + "12: "__copyuser_seg" movl 40(%4), %%eax\n"
30731 + "71: "__copyuser_seg" movl 44(%4), %%edx\n"
30732 " movl %%eax, 40(%3)\n"
30733 " movl %%edx, 44(%3)\n"
30734 - "13: movl 48(%4), %%eax\n"
30735 - "81: movl 52(%4), %%edx\n"
30736 + "13: "__copyuser_seg" movl 48(%4), %%eax\n"
30737 + "81: "__copyuser_seg" movl 52(%4), %%edx\n"
30738 " movl %%eax, 48(%3)\n"
30739 " movl %%edx, 52(%3)\n"
30740 - "14: movl 56(%4), %%eax\n"
30741 - "91: movl 60(%4), %%edx\n"
30742 + "14: "__copyuser_seg" movl 56(%4), %%eax\n"
30743 + "91: "__copyuser_seg" movl 60(%4), %%edx\n"
30744 " movl %%eax, 56(%3)\n"
30745 " movl %%edx, 60(%3)\n"
30746 " addl $-64, %0\n"
30747 @@ -253,9 +361,9 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
30748 " shrl $2, %0\n"
30749 " andl $3, %%eax\n"
30750 " cld\n"
30751 - "6: rep; movsl\n"
30752 + "6: rep; "__copyuser_seg" movsl\n"
30753 " movl %%eax,%0\n"
30754 - "7: rep; movsb\n"
30755 + "7: rep; "__copyuser_seg" movsb\n"
30756 "8:\n"
30757 ".section .fixup,\"ax\"\n"
30758 "9: lea 0(%%eax,%0,4),%0\n"
30759 @@ -305,41 +413,41 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
30760
30761 __asm__ __volatile__(
30762 " .align 2,0x90\n"
30763 - "0: movl 32(%4), %%eax\n"
30764 + "0: "__copyuser_seg" movl 32(%4), %%eax\n"
30765 " cmpl $67, %0\n"
30766 " jbe 2f\n"
30767 - "1: movl 64(%4), %%eax\n"
30768 + "1: "__copyuser_seg" movl 64(%4), %%eax\n"
30769 " .align 2,0x90\n"
30770 - "2: movl 0(%4), %%eax\n"
30771 - "21: movl 4(%4), %%edx\n"
30772 + "2: "__copyuser_seg" movl 0(%4), %%eax\n"
30773 + "21: "__copyuser_seg" movl 4(%4), %%edx\n"
30774 " movnti %%eax, 0(%3)\n"
30775 " movnti %%edx, 4(%3)\n"
30776 - "3: movl 8(%4), %%eax\n"
30777 - "31: movl 12(%4),%%edx\n"
30778 + "3: "__copyuser_seg" movl 8(%4), %%eax\n"
30779 + "31: "__copyuser_seg" movl 12(%4),%%edx\n"
30780 " movnti %%eax, 8(%3)\n"
30781 " movnti %%edx, 12(%3)\n"
30782 - "4: movl 16(%4), %%eax\n"
30783 - "41: movl 20(%4), %%edx\n"
30784 + "4: "__copyuser_seg" movl 16(%4), %%eax\n"
30785 + "41: "__copyuser_seg" movl 20(%4), %%edx\n"
30786 " movnti %%eax, 16(%3)\n"
30787 " movnti %%edx, 20(%3)\n"
30788 - "10: movl 24(%4), %%eax\n"
30789 - "51: movl 28(%4), %%edx\n"
30790 + "10: "__copyuser_seg" movl 24(%4), %%eax\n"
30791 + "51: "__copyuser_seg" movl 28(%4), %%edx\n"
30792 " movnti %%eax, 24(%3)\n"
30793 " movnti %%edx, 28(%3)\n"
30794 - "11: movl 32(%4), %%eax\n"
30795 - "61: movl 36(%4), %%edx\n"
30796 + "11: "__copyuser_seg" movl 32(%4), %%eax\n"
30797 + "61: "__copyuser_seg" movl 36(%4), %%edx\n"
30798 " movnti %%eax, 32(%3)\n"
30799 " movnti %%edx, 36(%3)\n"
30800 - "12: movl 40(%4), %%eax\n"
30801 - "71: movl 44(%4), %%edx\n"
30802 + "12: "__copyuser_seg" movl 40(%4), %%eax\n"
30803 + "71: "__copyuser_seg" movl 44(%4), %%edx\n"
30804 " movnti %%eax, 40(%3)\n"
30805 " movnti %%edx, 44(%3)\n"
30806 - "13: movl 48(%4), %%eax\n"
30807 - "81: movl 52(%4), %%edx\n"
30808 + "13: "__copyuser_seg" movl 48(%4), %%eax\n"
30809 + "81: "__copyuser_seg" movl 52(%4), %%edx\n"
30810 " movnti %%eax, 48(%3)\n"
30811 " movnti %%edx, 52(%3)\n"
30812 - "14: movl 56(%4), %%eax\n"
30813 - "91: movl 60(%4), %%edx\n"
30814 + "14: "__copyuser_seg" movl 56(%4), %%eax\n"
30815 + "91: "__copyuser_seg" movl 60(%4), %%edx\n"
30816 " movnti %%eax, 56(%3)\n"
30817 " movnti %%edx, 60(%3)\n"
30818 " addl $-64, %0\n"
30819 @@ -352,9 +460,9 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
30820 " shrl $2, %0\n"
30821 " andl $3, %%eax\n"
30822 " cld\n"
30823 - "6: rep; movsl\n"
30824 + "6: rep; "__copyuser_seg" movsl\n"
30825 " movl %%eax,%0\n"
30826 - "7: rep; movsb\n"
30827 + "7: rep; "__copyuser_seg" movsb\n"
30828 "8:\n"
30829 ".section .fixup,\"ax\"\n"
30830 "9: lea 0(%%eax,%0,4),%0\n"
30831 @@ -399,41 +507,41 @@ static unsigned long __copy_user_intel_nocache(void *to,
30832
30833 __asm__ __volatile__(
30834 " .align 2,0x90\n"
30835 - "0: movl 32(%4), %%eax\n"
30836 + "0: "__copyuser_seg" movl 32(%4), %%eax\n"
30837 " cmpl $67, %0\n"
30838 " jbe 2f\n"
30839 - "1: movl 64(%4), %%eax\n"
30840 + "1: "__copyuser_seg" movl 64(%4), %%eax\n"
30841 " .align 2,0x90\n"
30842 - "2: movl 0(%4), %%eax\n"
30843 - "21: movl 4(%4), %%edx\n"
30844 + "2: "__copyuser_seg" movl 0(%4), %%eax\n"
30845 + "21: "__copyuser_seg" movl 4(%4), %%edx\n"
30846 " movnti %%eax, 0(%3)\n"
30847 " movnti %%edx, 4(%3)\n"
30848 - "3: movl 8(%4), %%eax\n"
30849 - "31: movl 12(%4),%%edx\n"
30850 + "3: "__copyuser_seg" movl 8(%4), %%eax\n"
30851 + "31: "__copyuser_seg" movl 12(%4),%%edx\n"
30852 " movnti %%eax, 8(%3)\n"
30853 " movnti %%edx, 12(%3)\n"
30854 - "4: movl 16(%4), %%eax\n"
30855 - "41: movl 20(%4), %%edx\n"
30856 + "4: "__copyuser_seg" movl 16(%4), %%eax\n"
30857 + "41: "__copyuser_seg" movl 20(%4), %%edx\n"
30858 " movnti %%eax, 16(%3)\n"
30859 " movnti %%edx, 20(%3)\n"
30860 - "10: movl 24(%4), %%eax\n"
30861 - "51: movl 28(%4), %%edx\n"
30862 + "10: "__copyuser_seg" movl 24(%4), %%eax\n"
30863 + "51: "__copyuser_seg" movl 28(%4), %%edx\n"
30864 " movnti %%eax, 24(%3)\n"
30865 " movnti %%edx, 28(%3)\n"
30866 - "11: movl 32(%4), %%eax\n"
30867 - "61: movl 36(%4), %%edx\n"
30868 + "11: "__copyuser_seg" movl 32(%4), %%eax\n"
30869 + "61: "__copyuser_seg" movl 36(%4), %%edx\n"
30870 " movnti %%eax, 32(%3)\n"
30871 " movnti %%edx, 36(%3)\n"
30872 - "12: movl 40(%4), %%eax\n"
30873 - "71: movl 44(%4), %%edx\n"
30874 + "12: "__copyuser_seg" movl 40(%4), %%eax\n"
30875 + "71: "__copyuser_seg" movl 44(%4), %%edx\n"
30876 " movnti %%eax, 40(%3)\n"
30877 " movnti %%edx, 44(%3)\n"
30878 - "13: movl 48(%4), %%eax\n"
30879 - "81: movl 52(%4), %%edx\n"
30880 + "13: "__copyuser_seg" movl 48(%4), %%eax\n"
30881 + "81: "__copyuser_seg" movl 52(%4), %%edx\n"
30882 " movnti %%eax, 48(%3)\n"
30883 " movnti %%edx, 52(%3)\n"
30884 - "14: movl 56(%4), %%eax\n"
30885 - "91: movl 60(%4), %%edx\n"
30886 + "14: "__copyuser_seg" movl 56(%4), %%eax\n"
30887 + "91: "__copyuser_seg" movl 60(%4), %%edx\n"
30888 " movnti %%eax, 56(%3)\n"
30889 " movnti %%edx, 60(%3)\n"
30890 " addl $-64, %0\n"
30891 @@ -446,9 +554,9 @@ static unsigned long __copy_user_intel_nocache(void *to,
30892 " shrl $2, %0\n"
30893 " andl $3, %%eax\n"
30894 " cld\n"
30895 - "6: rep; movsl\n"
30896 + "6: rep; "__copyuser_seg" movsl\n"
30897 " movl %%eax,%0\n"
30898 - "7: rep; movsb\n"
30899 + "7: rep; "__copyuser_seg" movsb\n"
30900 "8:\n"
30901 ".section .fixup,\"ax\"\n"
30902 "9: lea 0(%%eax,%0,4),%0\n"
30903 @@ -488,32 +596,36 @@ static unsigned long __copy_user_intel_nocache(void *to,
30904 */
30905 unsigned long __copy_user_zeroing_intel(void *to, const void __user *from,
30906 unsigned long size);
30907 -unsigned long __copy_user_intel(void __user *to, const void *from,
30908 +unsigned long __generic_copy_to_user_intel(void __user *to, const void *from,
30909 + unsigned long size);
30910 +unsigned long __generic_copy_from_user_intel(void *to, const void __user *from,
30911 unsigned long size);
30912 unsigned long __copy_user_zeroing_intel_nocache(void *to,
30913 const void __user *from, unsigned long size);
30914 #endif /* CONFIG_X86_INTEL_USERCOPY */
30915
30916 /* Generic arbitrary sized copy. */
30917 -#define __copy_user(to, from, size) \
30918 +#define __copy_user(to, from, size, prefix, set, restore) \
30919 do { \
30920 int __d0, __d1, __d2; \
30921 __asm__ __volatile__( \
30922 + set \
30923 " cmp $7,%0\n" \
30924 " jbe 1f\n" \
30925 " movl %1,%0\n" \
30926 " negl %0\n" \
30927 " andl $7,%0\n" \
30928 " subl %0,%3\n" \
30929 - "4: rep; movsb\n" \
30930 + "4: rep; "prefix"movsb\n" \
30931 " movl %3,%0\n" \
30932 " shrl $2,%0\n" \
30933 " andl $3,%3\n" \
30934 " .align 2,0x90\n" \
30935 - "0: rep; movsl\n" \
30936 + "0: rep; "prefix"movsl\n" \
30937 " movl %3,%0\n" \
30938 - "1: rep; movsb\n" \
30939 + "1: rep; "prefix"movsb\n" \
30940 "2:\n" \
30941 + restore \
30942 ".section .fixup,\"ax\"\n" \
30943 "5: addl %3,%0\n" \
30944 " jmp 2b\n" \
30945 @@ -538,14 +650,14 @@ do { \
30946 " negl %0\n" \
30947 " andl $7,%0\n" \
30948 " subl %0,%3\n" \
30949 - "4: rep; movsb\n" \
30950 + "4: rep; "__copyuser_seg"movsb\n" \
30951 " movl %3,%0\n" \
30952 " shrl $2,%0\n" \
30953 " andl $3,%3\n" \
30954 " .align 2,0x90\n" \
30955 - "0: rep; movsl\n" \
30956 + "0: rep; "__copyuser_seg"movsl\n" \
30957 " movl %3,%0\n" \
30958 - "1: rep; movsb\n" \
30959 + "1: rep; "__copyuser_seg"movsb\n" \
30960 "2:\n" \
30961 ".section .fixup,\"ax\"\n" \
30962 "5: addl %3,%0\n" \
30963 @@ -572,9 +684,9 @@ unsigned long __copy_to_user_ll(void __user *to, const void *from,
30964 {
30965 stac();
30966 if (movsl_is_ok(to, from, n))
30967 - __copy_user(to, from, n);
30968 + __copy_user(to, from, n, "", __COPYUSER_SET_ES, __COPYUSER_RESTORE_ES);
30969 else
30970 - n = __copy_user_intel(to, from, n);
30971 + n = __generic_copy_to_user_intel(to, from, n);
30972 clac();
30973 return n;
30974 }
30975 @@ -598,10 +710,9 @@ unsigned long __copy_from_user_ll_nozero(void *to, const void __user *from,
30976 {
30977 stac();
30978 if (movsl_is_ok(to, from, n))
30979 - __copy_user(to, from, n);
30980 + __copy_user(to, from, n, __copyuser_seg, "", "");
30981 else
30982 - n = __copy_user_intel((void __user *)to,
30983 - (const void *)from, n);
30984 + n = __generic_copy_from_user_intel(to, from, n);
30985 clac();
30986 return n;
30987 }
30988 @@ -632,58 +743,38 @@ unsigned long __copy_from_user_ll_nocache_nozero(void *to, const void __user *fr
30989 if (n > 64 && cpu_has_xmm2)
30990 n = __copy_user_intel_nocache(to, from, n);
30991 else
30992 - __copy_user(to, from, n);
30993 + __copy_user(to, from, n, __copyuser_seg, "", "");
30994 #else
30995 - __copy_user(to, from, n);
30996 + __copy_user(to, from, n, __copyuser_seg, "", "");
30997 #endif
30998 clac();
30999 return n;
31000 }
31001 EXPORT_SYMBOL(__copy_from_user_ll_nocache_nozero);
31002
31003 -/**
31004 - * copy_to_user: - Copy a block of data into user space.
31005 - * @to: Destination address, in user space.
31006 - * @from: Source address, in kernel space.
31007 - * @n: Number of bytes to copy.
31008 - *
31009 - * Context: User context only. This function may sleep.
31010 - *
31011 - * Copy data from kernel space to user space.
31012 - *
31013 - * Returns number of bytes that could not be copied.
31014 - * On success, this will be zero.
31015 - */
31016 -unsigned long _copy_to_user(void __user *to, const void *from, unsigned n)
31017 +#ifdef CONFIG_PAX_MEMORY_UDEREF
31018 +void __set_fs(mm_segment_t x)
31019 {
31020 - if (access_ok(VERIFY_WRITE, to, n))
31021 - n = __copy_to_user(to, from, n);
31022 - return n;
31023 + switch (x.seg) {
31024 + case 0:
31025 + loadsegment(gs, 0);
31026 + break;
31027 + case TASK_SIZE_MAX:
31028 + loadsegment(gs, __USER_DS);
31029 + break;
31030 + case -1UL:
31031 + loadsegment(gs, __KERNEL_DS);
31032 + break;
31033 + default:
31034 + BUG();
31035 + }
31036 }
31037 -EXPORT_SYMBOL(_copy_to_user);
31038 +EXPORT_SYMBOL(__set_fs);
31039
31040 -/**
31041 - * copy_from_user: - Copy a block of data from user space.
31042 - * @to: Destination address, in kernel space.
31043 - * @from: Source address, in user space.
31044 - * @n: Number of bytes to copy.
31045 - *
31046 - * Context: User context only. This function may sleep.
31047 - *
31048 - * Copy data from user space to kernel space.
31049 - *
31050 - * Returns number of bytes that could not be copied.
31051 - * On success, this will be zero.
31052 - *
31053 - * If some data could not be copied, this function will pad the copied
31054 - * data to the requested size using zero bytes.
31055 - */
31056 -unsigned long _copy_from_user(void *to, const void __user *from, unsigned n)
31057 +void set_fs(mm_segment_t x)
31058 {
31059 - if (access_ok(VERIFY_READ, from, n))
31060 - n = __copy_from_user(to, from, n);
31061 - else
31062 - memset(to, 0, n);
31063 - return n;
31064 + current_thread_info()->addr_limit = x;
31065 + __set_fs(x);
31066 }
31067 -EXPORT_SYMBOL(_copy_from_user);
31068 +EXPORT_SYMBOL(set_fs);
31069 +#endif
31070 diff --git a/arch/x86/lib/usercopy_64.c b/arch/x86/lib/usercopy_64.c
31071 index c905e89..01ab928 100644
31072 --- a/arch/x86/lib/usercopy_64.c
31073 +++ b/arch/x86/lib/usercopy_64.c
31074 @@ -18,6 +18,7 @@ unsigned long __clear_user(void __user *addr, unsigned long size)
31075 might_fault();
31076 /* no memory constraint because it doesn't change any memory gcc knows
31077 about */
31078 + pax_open_userland();
31079 stac();
31080 asm volatile(
31081 " testq %[size8],%[size8]\n"
31082 @@ -39,9 +40,10 @@ unsigned long __clear_user(void __user *addr, unsigned long size)
31083 _ASM_EXTABLE(0b,3b)
31084 _ASM_EXTABLE(1b,2b)
31085 : [size8] "=&c"(size), [dst] "=&D" (__d0)
31086 - : [size1] "r"(size & 7), "[size8]" (size / 8), "[dst]"(addr),
31087 + : [size1] "r"(size & 7), "[size8]" (size / 8), "[dst]"(____m(addr)),
31088 [zero] "r" (0UL), [eight] "r" (8UL));
31089 clac();
31090 + pax_close_userland();
31091 return size;
31092 }
31093 EXPORT_SYMBOL(__clear_user);
31094 @@ -54,12 +56,11 @@ unsigned long clear_user(void __user *to, unsigned long n)
31095 }
31096 EXPORT_SYMBOL(clear_user);
31097
31098 -unsigned long copy_in_user(void __user *to, const void __user *from, unsigned len)
31099 +unsigned long copy_in_user(void __user *to, const void __user *from, unsigned long len)
31100 {
31101 - if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len)) {
31102 - return copy_user_generic((__force void *)to, (__force void *)from, len);
31103 - }
31104 - return len;
31105 + if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len))
31106 + return copy_user_generic((void __force_kernel *)____m(to), (void __force_kernel *)____m(from), len);
31107 + return len;
31108 }
31109 EXPORT_SYMBOL(copy_in_user);
31110
31111 @@ -69,11 +70,13 @@ EXPORT_SYMBOL(copy_in_user);
31112 * it is not necessary to optimize tail handling.
31113 */
31114 __visible unsigned long
31115 -copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
31116 +copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest)
31117 {
31118 char c;
31119 unsigned zero_len;
31120
31121 + clac();
31122 + pax_close_userland();
31123 for (; len; --len, to++) {
31124 if (__get_user_nocheck(c, from++, sizeof(char)))
31125 break;
31126 @@ -84,6 +87,5 @@ copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
31127 for (c = 0, zero_len = len; zerorest && zero_len; --zero_len)
31128 if (__put_user_nocheck(c, to++, sizeof(char)))
31129 break;
31130 - clac();
31131 return len;
31132 }
31133 diff --git a/arch/x86/mm/Makefile b/arch/x86/mm/Makefile
31134 index 6a19ad9..1c48f9a 100644
31135 --- a/arch/x86/mm/Makefile
31136 +++ b/arch/x86/mm/Makefile
31137 @@ -30,3 +30,7 @@ obj-$(CONFIG_ACPI_NUMA) += srat.o
31138 obj-$(CONFIG_NUMA_EMU) += numa_emulation.o
31139
31140 obj-$(CONFIG_MEMTEST) += memtest.o
31141 +
31142 +quote:="
31143 +obj-$(CONFIG_X86_64) += uderef_64.o
31144 +CFLAGS_uderef_64.o := $(subst $(quote),,$(CONFIG_ARCH_HWEIGHT_CFLAGS))
31145 diff --git a/arch/x86/mm/extable.c b/arch/x86/mm/extable.c
31146 index 903ec1e..c4166b2 100644
31147 --- a/arch/x86/mm/extable.c
31148 +++ b/arch/x86/mm/extable.c
31149 @@ -6,12 +6,24 @@
31150 static inline unsigned long
31151 ex_insn_addr(const struct exception_table_entry *x)
31152 {
31153 - return (unsigned long)&x->insn + x->insn;
31154 + unsigned long reloc = 0;
31155 +
31156 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
31157 + reloc = ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
31158 +#endif
31159 +
31160 + return (unsigned long)&x->insn + x->insn + reloc;
31161 }
31162 static inline unsigned long
31163 ex_fixup_addr(const struct exception_table_entry *x)
31164 {
31165 - return (unsigned long)&x->fixup + x->fixup;
31166 + unsigned long reloc = 0;
31167 +
31168 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
31169 + reloc = ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
31170 +#endif
31171 +
31172 + return (unsigned long)&x->fixup + x->fixup + reloc;
31173 }
31174
31175 int fixup_exception(struct pt_regs *regs)
31176 @@ -20,7 +32,7 @@ int fixup_exception(struct pt_regs *regs)
31177 unsigned long new_ip;
31178
31179 #ifdef CONFIG_PNPBIOS
31180 - if (unlikely(SEGMENT_IS_PNP_CODE(regs->cs))) {
31181 + if (unlikely(!v8086_mode(regs) && SEGMENT_IS_PNP_CODE(regs->cs))) {
31182 extern u32 pnp_bios_fault_eip, pnp_bios_fault_esp;
31183 extern u32 pnp_bios_is_utter_crap;
31184 pnp_bios_is_utter_crap = 1;
31185 @@ -145,6 +157,13 @@ void sort_extable(struct exception_table_entry *start,
31186 i += 4;
31187 p->fixup -= i;
31188 i += 4;
31189 +
31190 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
31191 + BUILD_BUG_ON(!IS_ENABLED(CONFIG_BUILDTIME_EXTABLE_SORT));
31192 + p->insn -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
31193 + p->fixup -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
31194 +#endif
31195 +
31196 }
31197 }
31198
31199 diff --git a/arch/x86/mm/fault.c b/arch/x86/mm/fault.c
31200 index 6dea040..31e52ff 100644
31201 --- a/arch/x86/mm/fault.c
31202 +++ b/arch/x86/mm/fault.c
31203 @@ -14,11 +14,18 @@
31204 #include <linux/hugetlb.h> /* hstate_index_to_shift */
31205 #include <linux/prefetch.h> /* prefetchw */
31206 #include <linux/context_tracking.h> /* exception_enter(), ... */
31207 +#include <linux/unistd.h>
31208 +#include <linux/compiler.h>
31209
31210 #include <asm/traps.h> /* dotraplinkage, ... */
31211 #include <asm/pgalloc.h> /* pgd_*(), ... */
31212 #include <asm/kmemcheck.h> /* kmemcheck_*(), ... */
31213 #include <asm/fixmap.h> /* VSYSCALL_START */
31214 +#include <asm/tlbflush.h>
31215 +
31216 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
31217 +#include <asm/stacktrace.h>
31218 +#endif
31219
31220 #define CREATE_TRACE_POINTS
31221 #include <asm/trace/exceptions.h>
31222 @@ -59,7 +66,7 @@ static inline int __kprobes kprobes_fault(struct pt_regs *regs)
31223 int ret = 0;
31224
31225 /* kprobe_running() needs smp_processor_id() */
31226 - if (kprobes_built_in() && !user_mode_vm(regs)) {
31227 + if (kprobes_built_in() && !user_mode(regs)) {
31228 preempt_disable();
31229 if (kprobe_running() && kprobe_fault_handler(regs, 14))
31230 ret = 1;
31231 @@ -120,7 +127,10 @@ check_prefetch_opcode(struct pt_regs *regs, unsigned char *instr,
31232 return !instr_lo || (instr_lo>>1) == 1;
31233 case 0x00:
31234 /* Prefetch instruction is 0x0F0D or 0x0F18 */
31235 - if (probe_kernel_address(instr, opcode))
31236 + if (user_mode(regs)) {
31237 + if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
31238 + return 0;
31239 + } else if (probe_kernel_address(instr, opcode))
31240 return 0;
31241
31242 *prefetch = (instr_lo == 0xF) &&
31243 @@ -154,7 +164,10 @@ is_prefetch(struct pt_regs *regs, unsigned long error_code, unsigned long addr)
31244 while (instr < max_instr) {
31245 unsigned char opcode;
31246
31247 - if (probe_kernel_address(instr, opcode))
31248 + if (user_mode(regs)) {
31249 + if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
31250 + break;
31251 + } else if (probe_kernel_address(instr, opcode))
31252 break;
31253
31254 instr++;
31255 @@ -185,6 +198,34 @@ force_sig_info_fault(int si_signo, int si_code, unsigned long address,
31256 force_sig_info(si_signo, &info, tsk);
31257 }
31258
31259 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
31260 +static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address);
31261 +#endif
31262 +
31263 +#ifdef CONFIG_PAX_EMUTRAMP
31264 +static int pax_handle_fetch_fault(struct pt_regs *regs);
31265 +#endif
31266 +
31267 +#ifdef CONFIG_PAX_PAGEEXEC
31268 +static inline pmd_t * pax_get_pmd(struct mm_struct *mm, unsigned long address)
31269 +{
31270 + pgd_t *pgd;
31271 + pud_t *pud;
31272 + pmd_t *pmd;
31273 +
31274 + pgd = pgd_offset(mm, address);
31275 + if (!pgd_present(*pgd))
31276 + return NULL;
31277 + pud = pud_offset(pgd, address);
31278 + if (!pud_present(*pud))
31279 + return NULL;
31280 + pmd = pmd_offset(pud, address);
31281 + if (!pmd_present(*pmd))
31282 + return NULL;
31283 + return pmd;
31284 +}
31285 +#endif
31286 +
31287 DEFINE_SPINLOCK(pgd_lock);
31288 LIST_HEAD(pgd_list);
31289
31290 @@ -235,10 +276,27 @@ void vmalloc_sync_all(void)
31291 for (address = VMALLOC_START & PMD_MASK;
31292 address >= TASK_SIZE && address < FIXADDR_TOP;
31293 address += PMD_SIZE) {
31294 +
31295 +#ifdef CONFIG_PAX_PER_CPU_PGD
31296 + unsigned long cpu;
31297 +#else
31298 struct page *page;
31299 +#endif
31300
31301 spin_lock(&pgd_lock);
31302 +
31303 +#ifdef CONFIG_PAX_PER_CPU_PGD
31304 + for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
31305 + pgd_t *pgd = get_cpu_pgd(cpu, user);
31306 + pmd_t *ret;
31307 +
31308 + ret = vmalloc_sync_one(pgd, address);
31309 + if (!ret)
31310 + break;
31311 + pgd = get_cpu_pgd(cpu, kernel);
31312 +#else
31313 list_for_each_entry(page, &pgd_list, lru) {
31314 + pgd_t *pgd;
31315 spinlock_t *pgt_lock;
31316 pmd_t *ret;
31317
31318 @@ -246,8 +304,14 @@ void vmalloc_sync_all(void)
31319 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
31320
31321 spin_lock(pgt_lock);
31322 - ret = vmalloc_sync_one(page_address(page), address);
31323 + pgd = page_address(page);
31324 +#endif
31325 +
31326 + ret = vmalloc_sync_one(pgd, address);
31327 +
31328 +#ifndef CONFIG_PAX_PER_CPU_PGD
31329 spin_unlock(pgt_lock);
31330 +#endif
31331
31332 if (!ret)
31333 break;
31334 @@ -281,6 +345,12 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
31335 * an interrupt in the middle of a task switch..
31336 */
31337 pgd_paddr = read_cr3();
31338 +
31339 +#ifdef CONFIG_PAX_PER_CPU_PGD
31340 + BUG_ON(__pa(get_cpu_pgd(smp_processor_id(), kernel)) != (pgd_paddr & __PHYSICAL_MASK));
31341 + vmalloc_sync_one(__va(pgd_paddr + PAGE_SIZE), address);
31342 +#endif
31343 +
31344 pmd_k = vmalloc_sync_one(__va(pgd_paddr), address);
31345 if (!pmd_k)
31346 return -1;
31347 @@ -376,11 +446,25 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
31348 * happen within a race in page table update. In the later
31349 * case just flush:
31350 */
31351 - pgd = pgd_offset(current->active_mm, address);
31352 +
31353 pgd_ref = pgd_offset_k(address);
31354 if (pgd_none(*pgd_ref))
31355 return -1;
31356
31357 +#ifdef CONFIG_PAX_PER_CPU_PGD
31358 + BUG_ON(__pa(get_cpu_pgd(smp_processor_id(), kernel)) != (read_cr3() & __PHYSICAL_MASK));
31359 + pgd = pgd_offset_cpu(smp_processor_id(), user, address);
31360 + if (pgd_none(*pgd)) {
31361 + set_pgd(pgd, *pgd_ref);
31362 + arch_flush_lazy_mmu_mode();
31363 + } else {
31364 + BUG_ON(pgd_page_vaddr(*pgd) != pgd_page_vaddr(*pgd_ref));
31365 + }
31366 + pgd = pgd_offset_cpu(smp_processor_id(), kernel, address);
31367 +#else
31368 + pgd = pgd_offset(current->active_mm, address);
31369 +#endif
31370 +
31371 if (pgd_none(*pgd)) {
31372 set_pgd(pgd, *pgd_ref);
31373 arch_flush_lazy_mmu_mode();
31374 @@ -546,7 +630,7 @@ static int is_errata93(struct pt_regs *regs, unsigned long address)
31375 static int is_errata100(struct pt_regs *regs, unsigned long address)
31376 {
31377 #ifdef CONFIG_X86_64
31378 - if ((regs->cs == __USER32_CS || (regs->cs & (1<<2))) && (address >> 32))
31379 + if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)) && (address >> 32))
31380 return 1;
31381 #endif
31382 return 0;
31383 @@ -573,7 +657,7 @@ static int is_f00f_bug(struct pt_regs *regs, unsigned long address)
31384 }
31385
31386 static const char nx_warning[] = KERN_CRIT
31387 -"kernel tried to execute NX-protected page - exploit attempt? (uid: %d)\n";
31388 +"kernel tried to execute NX-protected page - exploit attempt? (uid: %d, task: %s, pid: %d)\n";
31389
31390 static void
31391 show_fault_oops(struct pt_regs *regs, unsigned long error_code,
31392 @@ -582,15 +666,27 @@ show_fault_oops(struct pt_regs *regs, unsigned long error_code,
31393 if (!oops_may_print())
31394 return;
31395
31396 - if (error_code & PF_INSTR) {
31397 + if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR)) {
31398 unsigned int level;
31399
31400 pte_t *pte = lookup_address(address, &level);
31401
31402 if (pte && pte_present(*pte) && !pte_exec(*pte))
31403 - printk(nx_warning, from_kuid(&init_user_ns, current_uid()));
31404 + printk(nx_warning, from_kuid_munged(&init_user_ns, current_uid()), current->comm, task_pid_nr(current));
31405 }
31406
31407 +#ifdef CONFIG_PAX_KERNEXEC
31408 + if (init_mm.start_code <= address && address < init_mm.end_code) {
31409 + if (current->signal->curr_ip)
31410 + printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
31411 + &current->signal->curr_ip, current->comm, task_pid_nr(current),
31412 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
31413 + else
31414 + printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n", current->comm, task_pid_nr(current),
31415 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
31416 + }
31417 +#endif
31418 +
31419 printk(KERN_ALERT "BUG: unable to handle kernel ");
31420 if (address < PAGE_SIZE)
31421 printk(KERN_CONT "NULL pointer dereference");
31422 @@ -771,6 +867,22 @@ __bad_area_nosemaphore(struct pt_regs *regs, unsigned long error_code,
31423 return;
31424 }
31425 #endif
31426 +
31427 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
31428 + if (pax_is_fetch_fault(regs, error_code, address)) {
31429 +
31430 +#ifdef CONFIG_PAX_EMUTRAMP
31431 + switch (pax_handle_fetch_fault(regs)) {
31432 + case 2:
31433 + return;
31434 + }
31435 +#endif
31436 +
31437 + pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
31438 + do_group_exit(SIGKILL);
31439 + }
31440 +#endif
31441 +
31442 /* Kernel addresses are always protection faults: */
31443 if (address >= TASK_SIZE)
31444 error_code |= PF_PROT;
31445 @@ -856,7 +968,7 @@ do_sigbus(struct pt_regs *regs, unsigned long error_code, unsigned long address,
31446 if (fault & (VM_FAULT_HWPOISON|VM_FAULT_HWPOISON_LARGE)) {
31447 printk(KERN_ERR
31448 "MCE: Killing %s:%d due to hardware memory corruption fault at %lx\n",
31449 - tsk->comm, tsk->pid, address);
31450 + tsk->comm, task_pid_nr(tsk), address);
31451 code = BUS_MCEERR_AR;
31452 }
31453 #endif
31454 @@ -910,6 +1022,99 @@ static int spurious_fault_check(unsigned long error_code, pte_t *pte)
31455 return 1;
31456 }
31457
31458 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
31459 +static int pax_handle_pageexec_fault(struct pt_regs *regs, struct mm_struct *mm, unsigned long address, unsigned long error_code)
31460 +{
31461 + pte_t *pte;
31462 + pmd_t *pmd;
31463 + spinlock_t *ptl;
31464 + unsigned char pte_mask;
31465 +
31466 + if ((__supported_pte_mask & _PAGE_NX) || (error_code & (PF_PROT|PF_USER)) != (PF_PROT|PF_USER) || v8086_mode(regs) ||
31467 + !(mm->pax_flags & MF_PAX_PAGEEXEC))
31468 + return 0;
31469 +
31470 + /* PaX: it's our fault, let's handle it if we can */
31471 +
31472 + /* PaX: take a look at read faults before acquiring any locks */
31473 + if (unlikely(!(error_code & PF_WRITE) && (regs->ip == address))) {
31474 + /* instruction fetch attempt from a protected page in user mode */
31475 + up_read(&mm->mmap_sem);
31476 +
31477 +#ifdef CONFIG_PAX_EMUTRAMP
31478 + switch (pax_handle_fetch_fault(regs)) {
31479 + case 2:
31480 + return 1;
31481 + }
31482 +#endif
31483 +
31484 + pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
31485 + do_group_exit(SIGKILL);
31486 + }
31487 +
31488 + pmd = pax_get_pmd(mm, address);
31489 + if (unlikely(!pmd))
31490 + return 0;
31491 +
31492 + pte = pte_offset_map_lock(mm, pmd, address, &ptl);
31493 + if (unlikely(!(pte_val(*pte) & _PAGE_PRESENT) || pte_user(*pte))) {
31494 + pte_unmap_unlock(pte, ptl);
31495 + return 0;
31496 + }
31497 +
31498 + if (unlikely((error_code & PF_WRITE) && !pte_write(*pte))) {
31499 + /* write attempt to a protected page in user mode */
31500 + pte_unmap_unlock(pte, ptl);
31501 + return 0;
31502 + }
31503 +
31504 +#ifdef CONFIG_SMP
31505 + if (likely(address > get_limit(regs->cs) && cpu_isset(smp_processor_id(), mm->context.cpu_user_cs_mask)))
31506 +#else
31507 + if (likely(address > get_limit(regs->cs)))
31508 +#endif
31509 + {
31510 + set_pte(pte, pte_mkread(*pte));
31511 + __flush_tlb_one(address);
31512 + pte_unmap_unlock(pte, ptl);
31513 + up_read(&mm->mmap_sem);
31514 + return 1;
31515 + }
31516 +
31517 + pte_mask = _PAGE_ACCESSED | _PAGE_USER | ((error_code & PF_WRITE) << (_PAGE_BIT_DIRTY-1));
31518 +
31519 + /*
31520 + * PaX: fill DTLB with user rights and retry
31521 + */
31522 + __asm__ __volatile__ (
31523 + "orb %2,(%1)\n"
31524 +#if defined(CONFIG_M586) || defined(CONFIG_M586TSC)
31525 +/*
31526 + * PaX: let this uncommented 'invlpg' remind us on the behaviour of Intel's
31527 + * (and AMD's) TLBs. namely, they do not cache PTEs that would raise *any*
31528 + * page fault when examined during a TLB load attempt. this is true not only
31529 + * for PTEs holding a non-present entry but also present entries that will
31530 + * raise a page fault (such as those set up by PaX, or the copy-on-write
31531 + * mechanism). in effect it means that we do *not* need to flush the TLBs
31532 + * for our target pages since their PTEs are simply not in the TLBs at all.
31533 +
31534 + * the best thing in omitting it is that we gain around 15-20% speed in the
31535 + * fast path of the page fault handler and can get rid of tracing since we
31536 + * can no longer flush unintended entries.
31537 + */
31538 + "invlpg (%0)\n"
31539 +#endif
31540 + __copyuser_seg"testb $0,(%0)\n"
31541 + "xorb %3,(%1)\n"
31542 + :
31543 + : "r" (address), "r" (pte), "q" (pte_mask), "i" (_PAGE_USER)
31544 + : "memory", "cc");
31545 + pte_unmap_unlock(pte, ptl);
31546 + up_read(&mm->mmap_sem);
31547 + return 1;
31548 +}
31549 +#endif
31550 +
31551 /*
31552 * Handle a spurious fault caused by a stale TLB entry.
31553 *
31554 @@ -976,6 +1181,9 @@ int show_unhandled_signals = 1;
31555 static inline int
31556 access_error(unsigned long error_code, struct vm_area_struct *vma)
31557 {
31558 + if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR) && !(vma->vm_flags & VM_EXEC))
31559 + return 1;
31560 +
31561 if (error_code & PF_WRITE) {
31562 /* write, present and write, not present: */
31563 if (unlikely(!(vma->vm_flags & VM_WRITE)))
31564 @@ -1010,7 +1218,7 @@ static inline bool smap_violation(int error_code, struct pt_regs *regs)
31565 if (error_code & PF_USER)
31566 return false;
31567
31568 - if (!user_mode_vm(regs) && (regs->flags & X86_EFLAGS_AC))
31569 + if (!user_mode(regs) && (regs->flags & X86_EFLAGS_AC))
31570 return false;
31571
31572 return true;
31573 @@ -1037,6 +1245,22 @@ __do_page_fault(struct pt_regs *regs, unsigned long error_code)
31574 /* Get the faulting address: */
31575 address = read_cr2();
31576
31577 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
31578 + if (!user_mode(regs) && address < 2 * pax_user_shadow_base) {
31579 + if (!search_exception_tables(regs->ip)) {
31580 + printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
31581 + bad_area_nosemaphore(regs, error_code, address);
31582 + return;
31583 + }
31584 + if (address < pax_user_shadow_base) {
31585 + printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
31586 + printk(KERN_ERR "PAX: faulting IP: %pS\n", (void *)regs->ip);
31587 + show_trace_log_lvl(NULL, NULL, (void *)regs->sp, regs->bp, KERN_ERR);
31588 + } else
31589 + address -= pax_user_shadow_base;
31590 + }
31591 +#endif
31592 +
31593 /*
31594 * Detect and handle instructions that would cause a page fault for
31595 * both a tracked kernel page and a userspace page.
31596 @@ -1114,7 +1338,7 @@ __do_page_fault(struct pt_regs *regs, unsigned long error_code)
31597 * User-mode registers count as a user access even for any
31598 * potential system fault or CPU buglet:
31599 */
31600 - if (user_mode_vm(regs)) {
31601 + if (user_mode(regs)) {
31602 local_irq_enable();
31603 error_code |= PF_USER;
31604 flags |= FAULT_FLAG_USER;
31605 @@ -1161,6 +1385,11 @@ retry:
31606 might_sleep();
31607 }
31608
31609 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
31610 + if (pax_handle_pageexec_fault(regs, mm, address, error_code))
31611 + return;
31612 +#endif
31613 +
31614 vma = find_vma(mm, address);
31615 if (unlikely(!vma)) {
31616 bad_area(regs, error_code, address);
31617 @@ -1172,18 +1401,24 @@ retry:
31618 bad_area(regs, error_code, address);
31619 return;
31620 }
31621 - if (error_code & PF_USER) {
31622 - /*
31623 - * Accessing the stack below %sp is always a bug.
31624 - * The large cushion allows instructions like enter
31625 - * and pusha to work. ("enter $65535, $31" pushes
31626 - * 32 pointers and then decrements %sp by 65535.)
31627 - */
31628 - if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < regs->sp)) {
31629 - bad_area(regs, error_code, address);
31630 - return;
31631 - }
31632 + /*
31633 + * Accessing the stack below %sp is always a bug.
31634 + * The large cushion allows instructions like enter
31635 + * and pusha to work. ("enter $65535, $31" pushes
31636 + * 32 pointers and then decrements %sp by 65535.)
31637 + */
31638 + if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < task_pt_regs(tsk)->sp)) {
31639 + bad_area(regs, error_code, address);
31640 + return;
31641 }
31642 +
31643 +#ifdef CONFIG_PAX_SEGMEXEC
31644 + if (unlikely((mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end - SEGMEXEC_TASK_SIZE - 1 < address - SEGMEXEC_TASK_SIZE - 1)) {
31645 + bad_area(regs, error_code, address);
31646 + return;
31647 + }
31648 +#endif
31649 +
31650 if (unlikely(expand_stack(vma, address))) {
31651 bad_area(regs, error_code, address);
31652 return;
31653 @@ -1277,3 +1512,292 @@ trace_do_page_fault(struct pt_regs *regs, unsigned long error_code)
31654 __do_page_fault(regs, error_code);
31655 exception_exit(prev_state);
31656 }
31657 +
31658 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
31659 +static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address)
31660 +{
31661 + struct mm_struct *mm = current->mm;
31662 + unsigned long ip = regs->ip;
31663 +
31664 + if (v8086_mode(regs))
31665 + ip = ((regs->cs & 0xffff) << 4) + (ip & 0xffff);
31666 +
31667 +#ifdef CONFIG_PAX_PAGEEXEC
31668 + if (mm->pax_flags & MF_PAX_PAGEEXEC) {
31669 + if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR))
31670 + return true;
31671 + if (!(error_code & (PF_PROT | PF_WRITE)) && ip == address)
31672 + return true;
31673 + return false;
31674 + }
31675 +#endif
31676 +
31677 +#ifdef CONFIG_PAX_SEGMEXEC
31678 + if (mm->pax_flags & MF_PAX_SEGMEXEC) {
31679 + if (!(error_code & (PF_PROT | PF_WRITE)) && (ip + SEGMEXEC_TASK_SIZE == address))
31680 + return true;
31681 + return false;
31682 + }
31683 +#endif
31684 +
31685 + return false;
31686 +}
31687 +#endif
31688 +
31689 +#ifdef CONFIG_PAX_EMUTRAMP
31690 +static int pax_handle_fetch_fault_32(struct pt_regs *regs)
31691 +{
31692 + int err;
31693 +
31694 + do { /* PaX: libffi trampoline emulation */
31695 + unsigned char mov, jmp;
31696 + unsigned int addr1, addr2;
31697 +
31698 +#ifdef CONFIG_X86_64
31699 + if ((regs->ip + 9) >> 32)
31700 + break;
31701 +#endif
31702 +
31703 + err = get_user(mov, (unsigned char __user *)regs->ip);
31704 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
31705 + err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
31706 + err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
31707 +
31708 + if (err)
31709 + break;
31710 +
31711 + if (mov == 0xB8 && jmp == 0xE9) {
31712 + regs->ax = addr1;
31713 + regs->ip = (unsigned int)(regs->ip + addr2 + 10);
31714 + return 2;
31715 + }
31716 + } while (0);
31717 +
31718 + do { /* PaX: gcc trampoline emulation #1 */
31719 + unsigned char mov1, mov2;
31720 + unsigned short jmp;
31721 + unsigned int addr1, addr2;
31722 +
31723 +#ifdef CONFIG_X86_64
31724 + if ((regs->ip + 11) >> 32)
31725 + break;
31726 +#endif
31727 +
31728 + err = get_user(mov1, (unsigned char __user *)regs->ip);
31729 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
31730 + err |= get_user(mov2, (unsigned char __user *)(regs->ip + 5));
31731 + err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
31732 + err |= get_user(jmp, (unsigned short __user *)(regs->ip + 10));
31733 +
31734 + if (err)
31735 + break;
31736 +
31737 + if (mov1 == 0xB9 && mov2 == 0xB8 && jmp == 0xE0FF) {
31738 + regs->cx = addr1;
31739 + regs->ax = addr2;
31740 + regs->ip = addr2;
31741 + return 2;
31742 + }
31743 + } while (0);
31744 +
31745 + do { /* PaX: gcc trampoline emulation #2 */
31746 + unsigned char mov, jmp;
31747 + unsigned int addr1, addr2;
31748 +
31749 +#ifdef CONFIG_X86_64
31750 + if ((regs->ip + 9) >> 32)
31751 + break;
31752 +#endif
31753 +
31754 + err = get_user(mov, (unsigned char __user *)regs->ip);
31755 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
31756 + err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
31757 + err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
31758 +
31759 + if (err)
31760 + break;
31761 +
31762 + if (mov == 0xB9 && jmp == 0xE9) {
31763 + regs->cx = addr1;
31764 + regs->ip = (unsigned int)(regs->ip + addr2 + 10);
31765 + return 2;
31766 + }
31767 + } while (0);
31768 +
31769 + return 1; /* PaX in action */
31770 +}
31771 +
31772 +#ifdef CONFIG_X86_64
31773 +static int pax_handle_fetch_fault_64(struct pt_regs *regs)
31774 +{
31775 + int err;
31776 +
31777 + do { /* PaX: libffi trampoline emulation */
31778 + unsigned short mov1, mov2, jmp1;
31779 + unsigned char stcclc, jmp2;
31780 + unsigned long addr1, addr2;
31781 +
31782 + err = get_user(mov1, (unsigned short __user *)regs->ip);
31783 + err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
31784 + err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
31785 + err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
31786 + err |= get_user(stcclc, (unsigned char __user *)(regs->ip + 20));
31787 + err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 21));
31788 + err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 23));
31789 +
31790 + if (err)
31791 + break;
31792 +
31793 + if (mov1 == 0xBB49 && mov2 == 0xBA49 && (stcclc == 0xF8 || stcclc == 0xF9) && jmp1 == 0xFF49 && jmp2 == 0xE3) {
31794 + regs->r11 = addr1;
31795 + regs->r10 = addr2;
31796 + if (stcclc == 0xF8)
31797 + regs->flags &= ~X86_EFLAGS_CF;
31798 + else
31799 + regs->flags |= X86_EFLAGS_CF;
31800 + regs->ip = addr1;
31801 + return 2;
31802 + }
31803 + } while (0);
31804 +
31805 + do { /* PaX: gcc trampoline emulation #1 */
31806 + unsigned short mov1, mov2, jmp1;
31807 + unsigned char jmp2;
31808 + unsigned int addr1;
31809 + unsigned long addr2;
31810 +
31811 + err = get_user(mov1, (unsigned short __user *)regs->ip);
31812 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 2));
31813 + err |= get_user(mov2, (unsigned short __user *)(regs->ip + 6));
31814 + err |= get_user(addr2, (unsigned long __user *)(regs->ip + 8));
31815 + err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 16));
31816 + err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 18));
31817 +
31818 + if (err)
31819 + break;
31820 +
31821 + if (mov1 == 0xBB41 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
31822 + regs->r11 = addr1;
31823 + regs->r10 = addr2;
31824 + regs->ip = addr1;
31825 + return 2;
31826 + }
31827 + } while (0);
31828 +
31829 + do { /* PaX: gcc trampoline emulation #2 */
31830 + unsigned short mov1, mov2, jmp1;
31831 + unsigned char jmp2;
31832 + unsigned long addr1, addr2;
31833 +
31834 + err = get_user(mov1, (unsigned short __user *)regs->ip);
31835 + err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
31836 + err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
31837 + err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
31838 + err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 20));
31839 + err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 22));
31840 +
31841 + if (err)
31842 + break;
31843 +
31844 + if (mov1 == 0xBB49 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
31845 + regs->r11 = addr1;
31846 + regs->r10 = addr2;
31847 + regs->ip = addr1;
31848 + return 2;
31849 + }
31850 + } while (0);
31851 +
31852 + return 1; /* PaX in action */
31853 +}
31854 +#endif
31855 +
31856 +/*
31857 + * PaX: decide what to do with offenders (regs->ip = fault address)
31858 + *
31859 + * returns 1 when task should be killed
31860 + * 2 when gcc trampoline was detected
31861 + */
31862 +static int pax_handle_fetch_fault(struct pt_regs *regs)
31863 +{
31864 + if (v8086_mode(regs))
31865 + return 1;
31866 +
31867 + if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
31868 + return 1;
31869 +
31870 +#ifdef CONFIG_X86_32
31871 + return pax_handle_fetch_fault_32(regs);
31872 +#else
31873 + if (regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))
31874 + return pax_handle_fetch_fault_32(regs);
31875 + else
31876 + return pax_handle_fetch_fault_64(regs);
31877 +#endif
31878 +}
31879 +#endif
31880 +
31881 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
31882 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
31883 +{
31884 + long i;
31885 +
31886 + printk(KERN_ERR "PAX: bytes at PC: ");
31887 + for (i = 0; i < 20; i++) {
31888 + unsigned char c;
31889 + if (get_user(c, (unsigned char __force_user *)pc+i))
31890 + printk(KERN_CONT "?? ");
31891 + else
31892 + printk(KERN_CONT "%02x ", c);
31893 + }
31894 + printk("\n");
31895 +
31896 + printk(KERN_ERR "PAX: bytes at SP-%lu: ", (unsigned long)sizeof(long));
31897 + for (i = -1; i < 80 / (long)sizeof(long); i++) {
31898 + unsigned long c;
31899 + if (get_user(c, (unsigned long __force_user *)sp+i)) {
31900 +#ifdef CONFIG_X86_32
31901 + printk(KERN_CONT "???????? ");
31902 +#else
31903 + if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)))
31904 + printk(KERN_CONT "???????? ???????? ");
31905 + else
31906 + printk(KERN_CONT "???????????????? ");
31907 +#endif
31908 + } else {
31909 +#ifdef CONFIG_X86_64
31910 + if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))) {
31911 + printk(KERN_CONT "%08x ", (unsigned int)c);
31912 + printk(KERN_CONT "%08x ", (unsigned int)(c >> 32));
31913 + } else
31914 +#endif
31915 + printk(KERN_CONT "%0*lx ", 2 * (int)sizeof(long), c);
31916 + }
31917 + }
31918 + printk("\n");
31919 +}
31920 +#endif
31921 +
31922 +/**
31923 + * probe_kernel_write(): safely attempt to write to a location
31924 + * @dst: address to write to
31925 + * @src: pointer to the data that shall be written
31926 + * @size: size of the data chunk
31927 + *
31928 + * Safely write to address @dst from the buffer at @src. If a kernel fault
31929 + * happens, handle that and return -EFAULT.
31930 + */
31931 +long notrace probe_kernel_write(void *dst, const void *src, size_t size)
31932 +{
31933 + long ret;
31934 + mm_segment_t old_fs = get_fs();
31935 +
31936 + set_fs(KERNEL_DS);
31937 + pagefault_disable();
31938 + pax_open_kernel();
31939 + ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
31940 + pax_close_kernel();
31941 + pagefault_enable();
31942 + set_fs(old_fs);
31943 +
31944 + return ret ? -EFAULT : 0;
31945 +}
31946 diff --git a/arch/x86/mm/gup.c b/arch/x86/mm/gup.c
31947 index 0596e8e..5626789 100644
31948 --- a/arch/x86/mm/gup.c
31949 +++ b/arch/x86/mm/gup.c
31950 @@ -268,7 +268,7 @@ int __get_user_pages_fast(unsigned long start, int nr_pages, int write,
31951 addr = start;
31952 len = (unsigned long) nr_pages << PAGE_SHIFT;
31953 end = start + len;
31954 - if (unlikely(!access_ok(write ? VERIFY_WRITE : VERIFY_READ,
31955 + if (unlikely(!access_ok_noprefault(write ? VERIFY_WRITE : VERIFY_READ,
31956 (void __user *)start, len)))
31957 return 0;
31958
31959 @@ -344,6 +344,10 @@ int get_user_pages_fast(unsigned long start, int nr_pages, int write,
31960 goto slow_irqon;
31961 #endif
31962
31963 + if (unlikely(!access_ok_noprefault(write ? VERIFY_WRITE : VERIFY_READ,
31964 + (void __user *)start, len)))
31965 + return 0;
31966 +
31967 /*
31968 * XXX: batch / limit 'nr', to avoid large irq off latency
31969 * needs some instrumenting to determine the common sizes used by
31970 diff --git a/arch/x86/mm/highmem_32.c b/arch/x86/mm/highmem_32.c
31971 index 4500142..53a363c 100644
31972 --- a/arch/x86/mm/highmem_32.c
31973 +++ b/arch/x86/mm/highmem_32.c
31974 @@ -45,7 +45,11 @@ void *kmap_atomic_prot(struct page *page, pgprot_t prot)
31975 idx = type + KM_TYPE_NR*smp_processor_id();
31976 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
31977 BUG_ON(!pte_none(*(kmap_pte-idx)));
31978 +
31979 + pax_open_kernel();
31980 set_pte(kmap_pte-idx, mk_pte(page, prot));
31981 + pax_close_kernel();
31982 +
31983 arch_flush_lazy_mmu_mode();
31984
31985 return (void *)vaddr;
31986 diff --git a/arch/x86/mm/hugetlbpage.c b/arch/x86/mm/hugetlbpage.c
31987 index 9d980d8..6bbfacb 100644
31988 --- a/arch/x86/mm/hugetlbpage.c
31989 +++ b/arch/x86/mm/hugetlbpage.c
31990 @@ -92,23 +92,30 @@ int pmd_huge_support(void)
31991 #ifdef HAVE_ARCH_HUGETLB_UNMAPPED_AREA
31992 static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *file,
31993 unsigned long addr, unsigned long len,
31994 - unsigned long pgoff, unsigned long flags)
31995 + unsigned long pgoff, unsigned long flags, unsigned long offset)
31996 {
31997 struct hstate *h = hstate_file(file);
31998 struct vm_unmapped_area_info info;
31999 -
32000 +
32001 info.flags = 0;
32002 info.length = len;
32003 info.low_limit = TASK_UNMAPPED_BASE;
32004 +
32005 +#ifdef CONFIG_PAX_RANDMMAP
32006 + if (current->mm->pax_flags & MF_PAX_RANDMMAP)
32007 + info.low_limit += current->mm->delta_mmap;
32008 +#endif
32009 +
32010 info.high_limit = TASK_SIZE;
32011 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
32012 info.align_offset = 0;
32013 + info.threadstack_offset = offset;
32014 return vm_unmapped_area(&info);
32015 }
32016
32017 static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
32018 unsigned long addr0, unsigned long len,
32019 - unsigned long pgoff, unsigned long flags)
32020 + unsigned long pgoff, unsigned long flags, unsigned long offset)
32021 {
32022 struct hstate *h = hstate_file(file);
32023 struct vm_unmapped_area_info info;
32024 @@ -120,6 +127,7 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
32025 info.high_limit = current->mm->mmap_base;
32026 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
32027 info.align_offset = 0;
32028 + info.threadstack_offset = offset;
32029 addr = vm_unmapped_area(&info);
32030
32031 /*
32032 @@ -132,6 +140,12 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
32033 VM_BUG_ON(addr != -ENOMEM);
32034 info.flags = 0;
32035 info.low_limit = TASK_UNMAPPED_BASE;
32036 +
32037 +#ifdef CONFIG_PAX_RANDMMAP
32038 + if (current->mm->pax_flags & MF_PAX_RANDMMAP)
32039 + info.low_limit += current->mm->delta_mmap;
32040 +#endif
32041 +
32042 info.high_limit = TASK_SIZE;
32043 addr = vm_unmapped_area(&info);
32044 }
32045 @@ -146,10 +160,20 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
32046 struct hstate *h = hstate_file(file);
32047 struct mm_struct *mm = current->mm;
32048 struct vm_area_struct *vma;
32049 + unsigned long pax_task_size = TASK_SIZE;
32050 + unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
32051
32052 if (len & ~huge_page_mask(h))
32053 return -EINVAL;
32054 - if (len > TASK_SIZE)
32055 +
32056 +#ifdef CONFIG_PAX_SEGMEXEC
32057 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
32058 + pax_task_size = SEGMEXEC_TASK_SIZE;
32059 +#endif
32060 +
32061 + pax_task_size -= PAGE_SIZE;
32062 +
32063 + if (len > pax_task_size)
32064 return -ENOMEM;
32065
32066 if (flags & MAP_FIXED) {
32067 @@ -158,19 +182,22 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
32068 return addr;
32069 }
32070
32071 +#ifdef CONFIG_PAX_RANDMMAP
32072 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
32073 +#endif
32074 +
32075 if (addr) {
32076 addr = ALIGN(addr, huge_page_size(h));
32077 vma = find_vma(mm, addr);
32078 - if (TASK_SIZE - len >= addr &&
32079 - (!vma || addr + len <= vma->vm_start))
32080 + if (pax_task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
32081 return addr;
32082 }
32083 if (mm->get_unmapped_area == arch_get_unmapped_area)
32084 return hugetlb_get_unmapped_area_bottomup(file, addr, len,
32085 - pgoff, flags);
32086 + pgoff, flags, offset);
32087 else
32088 return hugetlb_get_unmapped_area_topdown(file, addr, len,
32089 - pgoff, flags);
32090 + pgoff, flags, offset);
32091 }
32092
32093 #endif /*HAVE_ARCH_HUGETLB_UNMAPPED_AREA*/
32094 diff --git a/arch/x86/mm/init.c b/arch/x86/mm/init.c
32095 index f971306..e83e0f6 100644
32096 --- a/arch/x86/mm/init.c
32097 +++ b/arch/x86/mm/init.c
32098 @@ -4,6 +4,7 @@
32099 #include <linux/swap.h>
32100 #include <linux/memblock.h>
32101 #include <linux/bootmem.h> /* for max_low_pfn */
32102 +#include <linux/tboot.h>
32103
32104 #include <asm/cacheflush.h>
32105 #include <asm/e820.h>
32106 @@ -17,6 +18,8 @@
32107 #include <asm/proto.h>
32108 #include <asm/dma.h> /* for MAX_DMA_PFN */
32109 #include <asm/microcode.h>
32110 +#include <asm/desc.h>
32111 +#include <asm/bios_ebda.h>
32112
32113 #include "mm_internal.h"
32114
32115 @@ -563,7 +566,18 @@ void __init init_mem_mapping(void)
32116 early_ioremap_page_table_range_init();
32117 #endif
32118
32119 +#ifdef CONFIG_PAX_PER_CPU_PGD
32120 + clone_pgd_range(get_cpu_pgd(0, kernel) + KERNEL_PGD_BOUNDARY,
32121 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
32122 + KERNEL_PGD_PTRS);
32123 + clone_pgd_range(get_cpu_pgd(0, user) + KERNEL_PGD_BOUNDARY,
32124 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
32125 + KERNEL_PGD_PTRS);
32126 + load_cr3(get_cpu_pgd(0, kernel));
32127 +#else
32128 load_cr3(swapper_pg_dir);
32129 +#endif
32130 +
32131 __flush_tlb_all();
32132
32133 early_memtest(0, max_pfn_mapped << PAGE_SHIFT);
32134 @@ -579,10 +593,40 @@ void __init init_mem_mapping(void)
32135 * Access has to be given to non-kernel-ram areas as well, these contain the PCI
32136 * mmio resources as well as potential bios/acpi data regions.
32137 */
32138 +
32139 +#ifdef CONFIG_GRKERNSEC_KMEM
32140 +static unsigned int ebda_start __read_only;
32141 +static unsigned int ebda_end __read_only;
32142 +#endif
32143 +
32144 int devmem_is_allowed(unsigned long pagenr)
32145 {
32146 - if (pagenr < 256)
32147 +#ifdef CONFIG_GRKERNSEC_KMEM
32148 + /* allow BDA */
32149 + if (!pagenr)
32150 return 1;
32151 + /* allow EBDA */
32152 + if (pagenr >= ebda_start && pagenr < ebda_end)
32153 + return 1;
32154 + /* if tboot is in use, allow access to its hardcoded serial log range */
32155 + if (tboot_enabled() && ((0x60000 >> PAGE_SHIFT) <= pagenr) && (pagenr < (0x68000 >> PAGE_SHIFT)))
32156 + return 1;
32157 +#else
32158 + if (!pagenr)
32159 + return 1;
32160 +#ifdef CONFIG_VM86
32161 + if (pagenr < (ISA_START_ADDRESS >> PAGE_SHIFT))
32162 + return 1;
32163 +#endif
32164 +#endif
32165 +
32166 + if ((ISA_START_ADDRESS >> PAGE_SHIFT) <= pagenr && pagenr < (ISA_END_ADDRESS >> PAGE_SHIFT))
32167 + return 1;
32168 +#ifdef CONFIG_GRKERNSEC_KMEM
32169 + /* throw out everything else below 1MB */
32170 + if (pagenr <= 256)
32171 + return 0;
32172 +#endif
32173 if (iomem_is_exclusive(pagenr << PAGE_SHIFT))
32174 return 0;
32175 if (!page_is_ram(pagenr))
32176 @@ -628,8 +672,117 @@ void free_init_pages(char *what, unsigned long begin, unsigned long end)
32177 #endif
32178 }
32179
32180 +#ifdef CONFIG_GRKERNSEC_KMEM
32181 +static inline void gr_init_ebda(void)
32182 +{
32183 + unsigned int ebda_addr;
32184 + unsigned int ebda_size = 0;
32185 +
32186 + ebda_addr = get_bios_ebda();
32187 + if (ebda_addr) {
32188 + ebda_size = *(unsigned char *)phys_to_virt(ebda_addr);
32189 + ebda_size <<= 10;
32190 + }
32191 + if (ebda_addr && ebda_size) {
32192 + ebda_start = ebda_addr >> PAGE_SHIFT;
32193 + ebda_end = min((unsigned int)PAGE_ALIGN(ebda_addr + ebda_size), (unsigned int)0xa0000) >> PAGE_SHIFT;
32194 + } else {
32195 + ebda_start = 0x9f000 >> PAGE_SHIFT;
32196 + ebda_end = 0xa0000 >> PAGE_SHIFT;
32197 + }
32198 +}
32199 +#else
32200 +static inline void gr_init_ebda(void) { }
32201 +#endif
32202 +
32203 void free_initmem(void)
32204 {
32205 +#ifdef CONFIG_PAX_KERNEXEC
32206 +#ifdef CONFIG_X86_32
32207 + /* PaX: limit KERNEL_CS to actual size */
32208 + unsigned long addr, limit;
32209 + struct desc_struct d;
32210 + int cpu;
32211 +#else
32212 + pgd_t *pgd;
32213 + pud_t *pud;
32214 + pmd_t *pmd;
32215 + unsigned long addr, end;
32216 +#endif
32217 +#endif
32218 +
32219 + gr_init_ebda();
32220 +
32221 +#ifdef CONFIG_PAX_KERNEXEC
32222 +#ifdef CONFIG_X86_32
32223 + limit = paravirt_enabled() ? ktva_ktla(0xffffffff) : (unsigned long)&_etext;
32224 + limit = (limit - 1UL) >> PAGE_SHIFT;
32225 +
32226 + memset(__LOAD_PHYSICAL_ADDR + PAGE_OFFSET, POISON_FREE_INITMEM, PAGE_SIZE);
32227 + for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
32228 + pack_descriptor(&d, get_desc_base(&get_cpu_gdt_table(cpu)[GDT_ENTRY_KERNEL_CS]), limit, 0x9B, 0xC);
32229 + write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEL_CS, &d, DESCTYPE_S);
32230 + write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEXEC_KERNEL_CS, &d, DESCTYPE_S);
32231 + }
32232 +
32233 + /* PaX: make KERNEL_CS read-only */
32234 + addr = PFN_ALIGN(ktla_ktva((unsigned long)&_text));
32235 + if (!paravirt_enabled())
32236 + set_memory_ro(addr, (PFN_ALIGN(_sdata) - addr) >> PAGE_SHIFT);
32237 +/*
32238 + for (addr = ktla_ktva((unsigned long)&_text); addr < (unsigned long)&_sdata; addr += PMD_SIZE) {
32239 + pgd = pgd_offset_k(addr);
32240 + pud = pud_offset(pgd, addr);
32241 + pmd = pmd_offset(pud, addr);
32242 + set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
32243 + }
32244 +*/
32245 +#ifdef CONFIG_X86_PAE
32246 + set_memory_nx(PFN_ALIGN(__init_begin), (PFN_ALIGN(__init_end) - PFN_ALIGN(__init_begin)) >> PAGE_SHIFT);
32247 +/*
32248 + for (addr = (unsigned long)&__init_begin; addr < (unsigned long)&__init_end; addr += PMD_SIZE) {
32249 + pgd = pgd_offset_k(addr);
32250 + pud = pud_offset(pgd, addr);
32251 + pmd = pmd_offset(pud, addr);
32252 + set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
32253 + }
32254 +*/
32255 +#endif
32256 +
32257 +#ifdef CONFIG_MODULES
32258 + set_memory_4k((unsigned long)MODULES_EXEC_VADDR, (MODULES_EXEC_END - MODULES_EXEC_VADDR) >> PAGE_SHIFT);
32259 +#endif
32260 +
32261 +#else
32262 + /* PaX: make kernel code/rodata read-only, rest non-executable */
32263 + for (addr = __START_KERNEL_map; addr < __START_KERNEL_map + KERNEL_IMAGE_SIZE; addr += PMD_SIZE) {
32264 + pgd = pgd_offset_k(addr);
32265 + pud = pud_offset(pgd, addr);
32266 + pmd = pmd_offset(pud, addr);
32267 + if (!pmd_present(*pmd))
32268 + continue;
32269 + if ((unsigned long)_text <= addr && addr < (unsigned long)_sdata)
32270 + set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
32271 + else
32272 + set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
32273 + }
32274 +
32275 + addr = (unsigned long)__va(__pa(__START_KERNEL_map));
32276 + end = addr + KERNEL_IMAGE_SIZE;
32277 + for (; addr < end; addr += PMD_SIZE) {
32278 + pgd = pgd_offset_k(addr);
32279 + pud = pud_offset(pgd, addr);
32280 + pmd = pmd_offset(pud, addr);
32281 + if (!pmd_present(*pmd))
32282 + continue;
32283 + if ((unsigned long)__va(__pa(_text)) <= addr && addr < (unsigned long)__va(__pa(_sdata)))
32284 + set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
32285 + }
32286 +#endif
32287 +
32288 + flush_tlb_all();
32289 +#endif
32290 +
32291 free_init_pages("unused kernel",
32292 (unsigned long)(&__init_begin),
32293 (unsigned long)(&__init_end));
32294 diff --git a/arch/x86/mm/init_32.c b/arch/x86/mm/init_32.c
32295 index 4287f1f..1a4e8e9 100644
32296 --- a/arch/x86/mm/init_32.c
32297 +++ b/arch/x86/mm/init_32.c
32298 @@ -62,33 +62,6 @@ static noinline int do_test_wp_bit(void);
32299 bool __read_mostly __vmalloc_start_set = false;
32300
32301 /*
32302 - * Creates a middle page table and puts a pointer to it in the
32303 - * given global directory entry. This only returns the gd entry
32304 - * in non-PAE compilation mode, since the middle layer is folded.
32305 - */
32306 -static pmd_t * __init one_md_table_init(pgd_t *pgd)
32307 -{
32308 - pud_t *pud;
32309 - pmd_t *pmd_table;
32310 -
32311 -#ifdef CONFIG_X86_PAE
32312 - if (!(pgd_val(*pgd) & _PAGE_PRESENT)) {
32313 - pmd_table = (pmd_t *)alloc_low_page();
32314 - paravirt_alloc_pmd(&init_mm, __pa(pmd_table) >> PAGE_SHIFT);
32315 - set_pgd(pgd, __pgd(__pa(pmd_table) | _PAGE_PRESENT));
32316 - pud = pud_offset(pgd, 0);
32317 - BUG_ON(pmd_table != pmd_offset(pud, 0));
32318 -
32319 - return pmd_table;
32320 - }
32321 -#endif
32322 - pud = pud_offset(pgd, 0);
32323 - pmd_table = pmd_offset(pud, 0);
32324 -
32325 - return pmd_table;
32326 -}
32327 -
32328 -/*
32329 * Create a page table and place a pointer to it in a middle page
32330 * directory entry:
32331 */
32332 @@ -98,13 +71,28 @@ static pte_t * __init one_page_table_init(pmd_t *pmd)
32333 pte_t *page_table = (pte_t *)alloc_low_page();
32334
32335 paravirt_alloc_pte(&init_mm, __pa(page_table) >> PAGE_SHIFT);
32336 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
32337 + set_pmd(pmd, __pmd(__pa(page_table) | _KERNPG_TABLE));
32338 +#else
32339 set_pmd(pmd, __pmd(__pa(page_table) | _PAGE_TABLE));
32340 +#endif
32341 BUG_ON(page_table != pte_offset_kernel(pmd, 0));
32342 }
32343
32344 return pte_offset_kernel(pmd, 0);
32345 }
32346
32347 +static pmd_t * __init one_md_table_init(pgd_t *pgd)
32348 +{
32349 + pud_t *pud;
32350 + pmd_t *pmd_table;
32351 +
32352 + pud = pud_offset(pgd, 0);
32353 + pmd_table = pmd_offset(pud, 0);
32354 +
32355 + return pmd_table;
32356 +}
32357 +
32358 pmd_t * __init populate_extra_pmd(unsigned long vaddr)
32359 {
32360 int pgd_idx = pgd_index(vaddr);
32361 @@ -208,6 +196,7 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
32362 int pgd_idx, pmd_idx;
32363 unsigned long vaddr;
32364 pgd_t *pgd;
32365 + pud_t *pud;
32366 pmd_t *pmd;
32367 pte_t *pte = NULL;
32368 unsigned long count = page_table_range_init_count(start, end);
32369 @@ -222,8 +211,13 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
32370 pgd = pgd_base + pgd_idx;
32371
32372 for ( ; (pgd_idx < PTRS_PER_PGD) && (vaddr != end); pgd++, pgd_idx++) {
32373 - pmd = one_md_table_init(pgd);
32374 - pmd = pmd + pmd_index(vaddr);
32375 + pud = pud_offset(pgd, vaddr);
32376 + pmd = pmd_offset(pud, vaddr);
32377 +
32378 +#ifdef CONFIG_X86_PAE
32379 + paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
32380 +#endif
32381 +
32382 for (; (pmd_idx < PTRS_PER_PMD) && (vaddr != end);
32383 pmd++, pmd_idx++) {
32384 pte = page_table_kmap_check(one_page_table_init(pmd),
32385 @@ -235,11 +229,20 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
32386 }
32387 }
32388
32389 -static inline int is_kernel_text(unsigned long addr)
32390 +static inline int is_kernel_text(unsigned long start, unsigned long end)
32391 {
32392 - if (addr >= (unsigned long)_text && addr <= (unsigned long)__init_end)
32393 - return 1;
32394 - return 0;
32395 + if ((start >= ktla_ktva((unsigned long)_etext) ||
32396 + end <= ktla_ktva((unsigned long)_stext)) &&
32397 + (start >= ktla_ktva((unsigned long)_einittext) ||
32398 + end <= ktla_ktva((unsigned long)_sinittext)) &&
32399 +
32400 +#ifdef CONFIG_ACPI_SLEEP
32401 + (start >= (unsigned long)__va(acpi_wakeup_address) + 0x4000 || end <= (unsigned long)__va(acpi_wakeup_address)) &&
32402 +#endif
32403 +
32404 + (start > (unsigned long)__va(0xfffff) || end <= (unsigned long)__va(0xc0000)))
32405 + return 0;
32406 + return 1;
32407 }
32408
32409 /*
32410 @@ -256,9 +259,10 @@ kernel_physical_mapping_init(unsigned long start,
32411 unsigned long last_map_addr = end;
32412 unsigned long start_pfn, end_pfn;
32413 pgd_t *pgd_base = swapper_pg_dir;
32414 - int pgd_idx, pmd_idx, pte_ofs;
32415 + unsigned int pgd_idx, pmd_idx, pte_ofs;
32416 unsigned long pfn;
32417 pgd_t *pgd;
32418 + pud_t *pud;
32419 pmd_t *pmd;
32420 pte_t *pte;
32421 unsigned pages_2m, pages_4k;
32422 @@ -291,8 +295,13 @@ repeat:
32423 pfn = start_pfn;
32424 pgd_idx = pgd_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
32425 pgd = pgd_base + pgd_idx;
32426 - for (; pgd_idx < PTRS_PER_PGD; pgd++, pgd_idx++) {
32427 - pmd = one_md_table_init(pgd);
32428 + for (; pgd_idx < PTRS_PER_PGD && pfn < max_low_pfn; pgd++, pgd_idx++) {
32429 + pud = pud_offset(pgd, 0);
32430 + pmd = pmd_offset(pud, 0);
32431 +
32432 +#ifdef CONFIG_X86_PAE
32433 + paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
32434 +#endif
32435
32436 if (pfn >= end_pfn)
32437 continue;
32438 @@ -304,14 +313,13 @@ repeat:
32439 #endif
32440 for (; pmd_idx < PTRS_PER_PMD && pfn < end_pfn;
32441 pmd++, pmd_idx++) {
32442 - unsigned int addr = pfn * PAGE_SIZE + PAGE_OFFSET;
32443 + unsigned long address = pfn * PAGE_SIZE + PAGE_OFFSET;
32444
32445 /*
32446 * Map with big pages if possible, otherwise
32447 * create normal page tables:
32448 */
32449 if (use_pse) {
32450 - unsigned int addr2;
32451 pgprot_t prot = PAGE_KERNEL_LARGE;
32452 /*
32453 * first pass will use the same initial
32454 @@ -322,11 +330,7 @@ repeat:
32455 _PAGE_PSE);
32456
32457 pfn &= PMD_MASK >> PAGE_SHIFT;
32458 - addr2 = (pfn + PTRS_PER_PTE-1) * PAGE_SIZE +
32459 - PAGE_OFFSET + PAGE_SIZE-1;
32460 -
32461 - if (is_kernel_text(addr) ||
32462 - is_kernel_text(addr2))
32463 + if (is_kernel_text(address, address + PMD_SIZE))
32464 prot = PAGE_KERNEL_LARGE_EXEC;
32465
32466 pages_2m++;
32467 @@ -343,7 +347,7 @@ repeat:
32468 pte_ofs = pte_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
32469 pte += pte_ofs;
32470 for (; pte_ofs < PTRS_PER_PTE && pfn < end_pfn;
32471 - pte++, pfn++, pte_ofs++, addr += PAGE_SIZE) {
32472 + pte++, pfn++, pte_ofs++, address += PAGE_SIZE) {
32473 pgprot_t prot = PAGE_KERNEL;
32474 /*
32475 * first pass will use the same initial
32476 @@ -351,7 +355,7 @@ repeat:
32477 */
32478 pgprot_t init_prot = __pgprot(PTE_IDENT_ATTR);
32479
32480 - if (is_kernel_text(addr))
32481 + if (is_kernel_text(address, address + PAGE_SIZE))
32482 prot = PAGE_KERNEL_EXEC;
32483
32484 pages_4k++;
32485 @@ -474,7 +478,7 @@ void __init native_pagetable_init(void)
32486
32487 pud = pud_offset(pgd, va);
32488 pmd = pmd_offset(pud, va);
32489 - if (!pmd_present(*pmd))
32490 + if (!pmd_present(*pmd)) // PAX TODO || pmd_large(*pmd))
32491 break;
32492
32493 /* should not be large page here */
32494 @@ -532,12 +536,10 @@ void __init early_ioremap_page_table_range_init(void)
32495
32496 static void __init pagetable_init(void)
32497 {
32498 - pgd_t *pgd_base = swapper_pg_dir;
32499 -
32500 - permanent_kmaps_init(pgd_base);
32501 + permanent_kmaps_init(swapper_pg_dir);
32502 }
32503
32504 -pteval_t __supported_pte_mask __read_mostly = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
32505 +pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
32506 EXPORT_SYMBOL_GPL(__supported_pte_mask);
32507
32508 /* user-defined highmem size */
32509 @@ -787,10 +789,10 @@ void __init mem_init(void)
32510 ((unsigned long)&__init_end -
32511 (unsigned long)&__init_begin) >> 10,
32512
32513 - (unsigned long)&_etext, (unsigned long)&_edata,
32514 - ((unsigned long)&_edata - (unsigned long)&_etext) >> 10,
32515 + (unsigned long)&_sdata, (unsigned long)&_edata,
32516 + ((unsigned long)&_edata - (unsigned long)&_sdata) >> 10,
32517
32518 - (unsigned long)&_text, (unsigned long)&_etext,
32519 + ktla_ktva((unsigned long)&_text), ktla_ktva((unsigned long)&_etext),
32520 ((unsigned long)&_etext - (unsigned long)&_text) >> 10);
32521
32522 /*
32523 @@ -880,6 +882,7 @@ void set_kernel_text_rw(void)
32524 if (!kernel_set_to_readonly)
32525 return;
32526
32527 + start = ktla_ktva(start);
32528 pr_debug("Set kernel text: %lx - %lx for read write\n",
32529 start, start+size);
32530
32531 @@ -894,6 +897,7 @@ void set_kernel_text_ro(void)
32532 if (!kernel_set_to_readonly)
32533 return;
32534
32535 + start = ktla_ktva(start);
32536 pr_debug("Set kernel text: %lx - %lx for read only\n",
32537 start, start+size);
32538
32539 @@ -922,6 +926,7 @@ void mark_rodata_ro(void)
32540 unsigned long start = PFN_ALIGN(_text);
32541 unsigned long size = PFN_ALIGN(_etext) - start;
32542
32543 + start = ktla_ktva(start);
32544 set_pages_ro(virt_to_page(start), size >> PAGE_SHIFT);
32545 printk(KERN_INFO "Write protecting the kernel text: %luk\n",
32546 size >> 10);
32547 diff --git a/arch/x86/mm/init_64.c b/arch/x86/mm/init_64.c
32548 index 104d56a..62ba13f1 100644
32549 --- a/arch/x86/mm/init_64.c
32550 +++ b/arch/x86/mm/init_64.c
32551 @@ -151,7 +151,7 @@ early_param("gbpages", parse_direct_gbpages_on);
32552 * around without checking the pgd every time.
32553 */
32554
32555 -pteval_t __supported_pte_mask __read_mostly = ~_PAGE_IOMAP;
32556 +pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_IOMAP);
32557 EXPORT_SYMBOL_GPL(__supported_pte_mask);
32558
32559 int force_personality32;
32560 @@ -184,12 +184,29 @@ void sync_global_pgds(unsigned long start, unsigned long end)
32561
32562 for (address = start; address <= end; address += PGDIR_SIZE) {
32563 const pgd_t *pgd_ref = pgd_offset_k(address);
32564 +
32565 +#ifdef CONFIG_PAX_PER_CPU_PGD
32566 + unsigned long cpu;
32567 +#else
32568 struct page *page;
32569 +#endif
32570
32571 if (pgd_none(*pgd_ref))
32572 continue;
32573
32574 spin_lock(&pgd_lock);
32575 +
32576 +#ifdef CONFIG_PAX_PER_CPU_PGD
32577 + for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
32578 + pgd_t *pgd = pgd_offset_cpu(cpu, user, address);
32579 +
32580 + if (pgd_none(*pgd))
32581 + set_pgd(pgd, *pgd_ref);
32582 + else
32583 + BUG_ON(pgd_page_vaddr(*pgd)
32584 + != pgd_page_vaddr(*pgd_ref));
32585 + pgd = pgd_offset_cpu(cpu, kernel, address);
32586 +#else
32587 list_for_each_entry(page, &pgd_list, lru) {
32588 pgd_t *pgd;
32589 spinlock_t *pgt_lock;
32590 @@ -198,6 +215,7 @@ void sync_global_pgds(unsigned long start, unsigned long end)
32591 /* the pgt_lock only for Xen */
32592 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
32593 spin_lock(pgt_lock);
32594 +#endif
32595
32596 if (pgd_none(*pgd))
32597 set_pgd(pgd, *pgd_ref);
32598 @@ -205,7 +223,10 @@ void sync_global_pgds(unsigned long start, unsigned long end)
32599 BUG_ON(pgd_page_vaddr(*pgd)
32600 != pgd_page_vaddr(*pgd_ref));
32601
32602 +#ifndef CONFIG_PAX_PER_CPU_PGD
32603 spin_unlock(pgt_lock);
32604 +#endif
32605 +
32606 }
32607 spin_unlock(&pgd_lock);
32608 }
32609 @@ -238,7 +259,7 @@ static pud_t *fill_pud(pgd_t *pgd, unsigned long vaddr)
32610 {
32611 if (pgd_none(*pgd)) {
32612 pud_t *pud = (pud_t *)spp_getpage();
32613 - pgd_populate(&init_mm, pgd, pud);
32614 + pgd_populate_kernel(&init_mm, pgd, pud);
32615 if (pud != pud_offset(pgd, 0))
32616 printk(KERN_ERR "PAGETABLE BUG #00! %p <-> %p\n",
32617 pud, pud_offset(pgd, 0));
32618 @@ -250,7 +271,7 @@ static pmd_t *fill_pmd(pud_t *pud, unsigned long vaddr)
32619 {
32620 if (pud_none(*pud)) {
32621 pmd_t *pmd = (pmd_t *) spp_getpage();
32622 - pud_populate(&init_mm, pud, pmd);
32623 + pud_populate_kernel(&init_mm, pud, pmd);
32624 if (pmd != pmd_offset(pud, 0))
32625 printk(KERN_ERR "PAGETABLE BUG #01! %p <-> %p\n",
32626 pmd, pmd_offset(pud, 0));
32627 @@ -279,7 +300,9 @@ void set_pte_vaddr_pud(pud_t *pud_page, unsigned long vaddr, pte_t new_pte)
32628 pmd = fill_pmd(pud, vaddr);
32629 pte = fill_pte(pmd, vaddr);
32630
32631 + pax_open_kernel();
32632 set_pte(pte, new_pte);
32633 + pax_close_kernel();
32634
32635 /*
32636 * It's enough to flush this one mapping.
32637 @@ -338,14 +361,12 @@ static void __init __init_extra_mapping(unsigned long phys, unsigned long size,
32638 pgd = pgd_offset_k((unsigned long)__va(phys));
32639 if (pgd_none(*pgd)) {
32640 pud = (pud_t *) spp_getpage();
32641 - set_pgd(pgd, __pgd(__pa(pud) | _KERNPG_TABLE |
32642 - _PAGE_USER));
32643 + set_pgd(pgd, __pgd(__pa(pud) | _PAGE_TABLE));
32644 }
32645 pud = pud_offset(pgd, (unsigned long)__va(phys));
32646 if (pud_none(*pud)) {
32647 pmd = (pmd_t *) spp_getpage();
32648 - set_pud(pud, __pud(__pa(pmd) | _KERNPG_TABLE |
32649 - _PAGE_USER));
32650 + set_pud(pud, __pud(__pa(pmd) | _PAGE_TABLE));
32651 }
32652 pmd = pmd_offset(pud, phys);
32653 BUG_ON(!pmd_none(*pmd));
32654 @@ -586,7 +607,7 @@ phys_pud_init(pud_t *pud_page, unsigned long addr, unsigned long end,
32655 prot);
32656
32657 spin_lock(&init_mm.page_table_lock);
32658 - pud_populate(&init_mm, pud, pmd);
32659 + pud_populate_kernel(&init_mm, pud, pmd);
32660 spin_unlock(&init_mm.page_table_lock);
32661 }
32662 __flush_tlb_all();
32663 @@ -627,7 +648,7 @@ kernel_physical_mapping_init(unsigned long start,
32664 page_size_mask);
32665
32666 spin_lock(&init_mm.page_table_lock);
32667 - pgd_populate(&init_mm, pgd, pud);
32668 + pgd_populate_kernel(&init_mm, pgd, pud);
32669 spin_unlock(&init_mm.page_table_lock);
32670 pgd_changed = true;
32671 }
32672 @@ -1188,8 +1209,8 @@ int kern_addr_valid(unsigned long addr)
32673 static struct vm_area_struct gate_vma = {
32674 .vm_start = VSYSCALL_START,
32675 .vm_end = VSYSCALL_START + (VSYSCALL_MAPPED_PAGES * PAGE_SIZE),
32676 - .vm_page_prot = PAGE_READONLY_EXEC,
32677 - .vm_flags = VM_READ | VM_EXEC
32678 + .vm_page_prot = PAGE_READONLY,
32679 + .vm_flags = VM_READ
32680 };
32681
32682 struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
32683 @@ -1223,7 +1244,7 @@ int in_gate_area_no_mm(unsigned long addr)
32684
32685 const char *arch_vma_name(struct vm_area_struct *vma)
32686 {
32687 - if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
32688 + if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
32689 return "[vdso]";
32690 if (vma == &gate_vma)
32691 return "[vsyscall]";
32692 diff --git a/arch/x86/mm/iomap_32.c b/arch/x86/mm/iomap_32.c
32693 index 7b179b4..6bd17777 100644
32694 --- a/arch/x86/mm/iomap_32.c
32695 +++ b/arch/x86/mm/iomap_32.c
32696 @@ -64,7 +64,11 @@ void *kmap_atomic_prot_pfn(unsigned long pfn, pgprot_t prot)
32697 type = kmap_atomic_idx_push();
32698 idx = type + KM_TYPE_NR * smp_processor_id();
32699 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
32700 +
32701 + pax_open_kernel();
32702 set_pte(kmap_pte - idx, pfn_pte(pfn, prot));
32703 + pax_close_kernel();
32704 +
32705 arch_flush_lazy_mmu_mode();
32706
32707 return (void *)vaddr;
32708 diff --git a/arch/x86/mm/ioremap.c b/arch/x86/mm/ioremap.c
32709 index 799580c..72f9fe0 100644
32710 --- a/arch/x86/mm/ioremap.c
32711 +++ b/arch/x86/mm/ioremap.c
32712 @@ -97,7 +97,7 @@ static void __iomem *__ioremap_caller(resource_size_t phys_addr,
32713 for (pfn = phys_addr >> PAGE_SHIFT; pfn <= last_pfn; pfn++) {
32714 int is_ram = page_is_ram(pfn);
32715
32716 - if (is_ram && pfn_valid(pfn) && !PageReserved(pfn_to_page(pfn)))
32717 + if (is_ram && pfn_valid(pfn) && (pfn >= 0x100 || !PageReserved(pfn_to_page(pfn))))
32718 return NULL;
32719 WARN_ON_ONCE(is_ram);
32720 }
32721 @@ -256,7 +256,7 @@ EXPORT_SYMBOL(ioremap_prot);
32722 *
32723 * Caller must ensure there is only one unmapping for the same pointer.
32724 */
32725 -void iounmap(volatile void __iomem *addr)
32726 +void iounmap(const volatile void __iomem *addr)
32727 {
32728 struct vm_struct *p, *o;
32729
32730 @@ -310,6 +310,9 @@ void *xlate_dev_mem_ptr(unsigned long phys)
32731
32732 /* If page is RAM, we can use __va. Otherwise ioremap and unmap. */
32733 if (page_is_ram(start >> PAGE_SHIFT))
32734 +#ifdef CONFIG_HIGHMEM
32735 + if ((start >> PAGE_SHIFT) < max_low_pfn)
32736 +#endif
32737 return __va(phys);
32738
32739 addr = (void __force *)ioremap_cache(start, PAGE_SIZE);
32740 @@ -322,6 +325,9 @@ void *xlate_dev_mem_ptr(unsigned long phys)
32741 void unxlate_dev_mem_ptr(unsigned long phys, void *addr)
32742 {
32743 if (page_is_ram(phys >> PAGE_SHIFT))
32744 +#ifdef CONFIG_HIGHMEM
32745 + if ((phys >> PAGE_SHIFT) < max_low_pfn)
32746 +#endif
32747 return;
32748
32749 iounmap((void __iomem *)((unsigned long)addr & PAGE_MASK));
32750 @@ -339,7 +345,7 @@ static int __init early_ioremap_debug_setup(char *str)
32751 early_param("early_ioremap_debug", early_ioremap_debug_setup);
32752
32753 static __initdata int after_paging_init;
32754 -static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __page_aligned_bss;
32755 +static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __read_only __aligned(PAGE_SIZE);
32756
32757 static inline pmd_t * __init early_ioremap_pmd(unsigned long addr)
32758 {
32759 @@ -376,8 +382,7 @@ void __init early_ioremap_init(void)
32760 slot_virt[i] = __fix_to_virt(FIX_BTMAP_BEGIN - NR_FIX_BTMAPS*i);
32761
32762 pmd = early_ioremap_pmd(fix_to_virt(FIX_BTMAP_BEGIN));
32763 - memset(bm_pte, 0, sizeof(bm_pte));
32764 - pmd_populate_kernel(&init_mm, pmd, bm_pte);
32765 + pmd_populate_user(&init_mm, pmd, bm_pte);
32766
32767 /*
32768 * The boot-ioremap range spans multiple pmds, for which
32769 diff --git a/arch/x86/mm/kmemcheck/kmemcheck.c b/arch/x86/mm/kmemcheck/kmemcheck.c
32770 index d87dd6d..bf3fa66 100644
32771 --- a/arch/x86/mm/kmemcheck/kmemcheck.c
32772 +++ b/arch/x86/mm/kmemcheck/kmemcheck.c
32773 @@ -622,9 +622,9 @@ bool kmemcheck_fault(struct pt_regs *regs, unsigned long address,
32774 * memory (e.g. tracked pages)? For now, we need this to avoid
32775 * invoking kmemcheck for PnP BIOS calls.
32776 */
32777 - if (regs->flags & X86_VM_MASK)
32778 + if (v8086_mode(regs))
32779 return false;
32780 - if (regs->cs != __KERNEL_CS)
32781 + if (regs->cs != __KERNEL_CS && regs->cs != __KERNEXEC_KERNEL_CS)
32782 return false;
32783
32784 pte = kmemcheck_pte_lookup(address);
32785 diff --git a/arch/x86/mm/mmap.c b/arch/x86/mm/mmap.c
32786 index 25e7e13..1964579 100644
32787 --- a/arch/x86/mm/mmap.c
32788 +++ b/arch/x86/mm/mmap.c
32789 @@ -52,7 +52,7 @@ static unsigned int stack_maxrandom_size(void)
32790 * Leave an at least ~128 MB hole with possible stack randomization.
32791 */
32792 #define MIN_GAP (128*1024*1024UL + stack_maxrandom_size())
32793 -#define MAX_GAP (TASK_SIZE/6*5)
32794 +#define MAX_GAP (pax_task_size/6*5)
32795
32796 static int mmap_is_legacy(void)
32797 {
32798 @@ -82,27 +82,40 @@ static unsigned long mmap_rnd(void)
32799 return rnd << PAGE_SHIFT;
32800 }
32801
32802 -static unsigned long mmap_base(void)
32803 +static unsigned long mmap_base(struct mm_struct *mm)
32804 {
32805 unsigned long gap = rlimit(RLIMIT_STACK);
32806 + unsigned long pax_task_size = TASK_SIZE;
32807 +
32808 +#ifdef CONFIG_PAX_SEGMEXEC
32809 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
32810 + pax_task_size = SEGMEXEC_TASK_SIZE;
32811 +#endif
32812
32813 if (gap < MIN_GAP)
32814 gap = MIN_GAP;
32815 else if (gap > MAX_GAP)
32816 gap = MAX_GAP;
32817
32818 - return PAGE_ALIGN(TASK_SIZE - gap - mmap_rnd());
32819 + return PAGE_ALIGN(pax_task_size - gap - mmap_rnd());
32820 }
32821
32822 /*
32823 * Bottom-up (legacy) layout on X86_32 did not support randomization, X86_64
32824 * does, but not when emulating X86_32
32825 */
32826 -static unsigned long mmap_legacy_base(void)
32827 +static unsigned long mmap_legacy_base(struct mm_struct *mm)
32828 {
32829 - if (mmap_is_ia32())
32830 + if (mmap_is_ia32()) {
32831 +
32832 +#ifdef CONFIG_PAX_SEGMEXEC
32833 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
32834 + return SEGMEXEC_TASK_UNMAPPED_BASE;
32835 + else
32836 +#endif
32837 +
32838 return TASK_UNMAPPED_BASE;
32839 - else
32840 + } else
32841 return TASK_UNMAPPED_BASE + mmap_rnd();
32842 }
32843
32844 @@ -112,8 +125,15 @@ static unsigned long mmap_legacy_base(void)
32845 */
32846 void arch_pick_mmap_layout(struct mm_struct *mm)
32847 {
32848 - mm->mmap_legacy_base = mmap_legacy_base();
32849 - mm->mmap_base = mmap_base();
32850 + mm->mmap_legacy_base = mmap_legacy_base(mm);
32851 + mm->mmap_base = mmap_base(mm);
32852 +
32853 +#ifdef CONFIG_PAX_RANDMMAP
32854 + if (mm->pax_flags & MF_PAX_RANDMMAP) {
32855 + mm->mmap_legacy_base += mm->delta_mmap;
32856 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
32857 + }
32858 +#endif
32859
32860 if (mmap_is_legacy()) {
32861 mm->mmap_base = mm->mmap_legacy_base;
32862 diff --git a/arch/x86/mm/mmio-mod.c b/arch/x86/mm/mmio-mod.c
32863 index 0057a7a..95c7edd 100644
32864 --- a/arch/x86/mm/mmio-mod.c
32865 +++ b/arch/x86/mm/mmio-mod.c
32866 @@ -194,7 +194,7 @@ static void pre(struct kmmio_probe *p, struct pt_regs *regs,
32867 break;
32868 default:
32869 {
32870 - unsigned char *ip = (unsigned char *)instptr;
32871 + unsigned char *ip = (unsigned char *)ktla_ktva(instptr);
32872 my_trace->opcode = MMIO_UNKNOWN_OP;
32873 my_trace->width = 0;
32874 my_trace->value = (*ip) << 16 | *(ip + 1) << 8 |
32875 @@ -234,7 +234,7 @@ static void post(struct kmmio_probe *p, unsigned long condition,
32876 static void ioremap_trace_core(resource_size_t offset, unsigned long size,
32877 void __iomem *addr)
32878 {
32879 - static atomic_t next_id;
32880 + static atomic_unchecked_t next_id;
32881 struct remap_trace *trace = kmalloc(sizeof(*trace), GFP_KERNEL);
32882 /* These are page-unaligned. */
32883 struct mmiotrace_map map = {
32884 @@ -258,7 +258,7 @@ static void ioremap_trace_core(resource_size_t offset, unsigned long size,
32885 .private = trace
32886 },
32887 .phys = offset,
32888 - .id = atomic_inc_return(&next_id)
32889 + .id = atomic_inc_return_unchecked(&next_id)
32890 };
32891 map.map_id = trace->id;
32892
32893 @@ -290,7 +290,7 @@ void mmiotrace_ioremap(resource_size_t offset, unsigned long size,
32894 ioremap_trace_core(offset, size, addr);
32895 }
32896
32897 -static void iounmap_trace_core(volatile void __iomem *addr)
32898 +static void iounmap_trace_core(const volatile void __iomem *addr)
32899 {
32900 struct mmiotrace_map map = {
32901 .phys = 0,
32902 @@ -328,7 +328,7 @@ not_enabled:
32903 }
32904 }
32905
32906 -void mmiotrace_iounmap(volatile void __iomem *addr)
32907 +void mmiotrace_iounmap(const volatile void __iomem *addr)
32908 {
32909 might_sleep();
32910 if (is_enabled()) /* recheck and proper locking in *_core() */
32911 diff --git a/arch/x86/mm/numa.c b/arch/x86/mm/numa.c
32912 index 24aec58..c39fe8b 100644
32913 --- a/arch/x86/mm/numa.c
32914 +++ b/arch/x86/mm/numa.c
32915 @@ -474,7 +474,7 @@ static bool __init numa_meminfo_cover_memory(const struct numa_meminfo *mi)
32916 return true;
32917 }
32918
32919 -static int __init numa_register_memblks(struct numa_meminfo *mi)
32920 +static int __init __intentional_overflow(-1) numa_register_memblks(struct numa_meminfo *mi)
32921 {
32922 unsigned long uninitialized_var(pfn_align);
32923 int i, nid;
32924 diff --git a/arch/x86/mm/pageattr-test.c b/arch/x86/mm/pageattr-test.c
32925 index d0b1773..4c3327c 100644
32926 --- a/arch/x86/mm/pageattr-test.c
32927 +++ b/arch/x86/mm/pageattr-test.c
32928 @@ -36,7 +36,7 @@ enum {
32929
32930 static int pte_testbit(pte_t pte)
32931 {
32932 - return pte_flags(pte) & _PAGE_UNUSED1;
32933 + return pte_flags(pte) & _PAGE_CPA_TEST;
32934 }
32935
32936 struct split_state {
32937 diff --git a/arch/x86/mm/pageattr.c b/arch/x86/mm/pageattr.c
32938 index bb32480..75f2f5e 100644
32939 --- a/arch/x86/mm/pageattr.c
32940 +++ b/arch/x86/mm/pageattr.c
32941 @@ -261,7 +261,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
32942 */
32943 #ifdef CONFIG_PCI_BIOS
32944 if (pcibios_enabled && within(pfn, BIOS_BEGIN >> PAGE_SHIFT, BIOS_END >> PAGE_SHIFT))
32945 - pgprot_val(forbidden) |= _PAGE_NX;
32946 + pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
32947 #endif
32948
32949 /*
32950 @@ -269,9 +269,10 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
32951 * Does not cover __inittext since that is gone later on. On
32952 * 64bit we do not enforce !NX on the low mapping
32953 */
32954 - if (within(address, (unsigned long)_text, (unsigned long)_etext))
32955 - pgprot_val(forbidden) |= _PAGE_NX;
32956 + if (within(address, ktla_ktva((unsigned long)_text), ktla_ktva((unsigned long)_etext)))
32957 + pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
32958
32959 +#ifdef CONFIG_DEBUG_RODATA
32960 /*
32961 * The .rodata section needs to be read-only. Using the pfn
32962 * catches all aliases.
32963 @@ -279,6 +280,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
32964 if (within(pfn, __pa_symbol(__start_rodata) >> PAGE_SHIFT,
32965 __pa_symbol(__end_rodata) >> PAGE_SHIFT))
32966 pgprot_val(forbidden) |= _PAGE_RW;
32967 +#endif
32968
32969 #if defined(CONFIG_X86_64) && defined(CONFIG_DEBUG_RODATA)
32970 /*
32971 @@ -317,6 +319,13 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
32972 }
32973 #endif
32974
32975 +#ifdef CONFIG_PAX_KERNEXEC
32976 + if (within(pfn, __pa(ktla_ktva((unsigned long)&_text)), __pa((unsigned long)&_sdata))) {
32977 + pgprot_val(forbidden) |= _PAGE_RW;
32978 + pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
32979 + }
32980 +#endif
32981 +
32982 prot = __pgprot(pgprot_val(prot) & ~pgprot_val(forbidden));
32983
32984 return prot;
32985 @@ -400,23 +409,37 @@ EXPORT_SYMBOL_GPL(slow_virt_to_phys);
32986 static void __set_pmd_pte(pte_t *kpte, unsigned long address, pte_t pte)
32987 {
32988 /* change init_mm */
32989 + pax_open_kernel();
32990 set_pte_atomic(kpte, pte);
32991 +
32992 #ifdef CONFIG_X86_32
32993 if (!SHARED_KERNEL_PMD) {
32994 +
32995 +#ifdef CONFIG_PAX_PER_CPU_PGD
32996 + unsigned long cpu;
32997 +#else
32998 struct page *page;
32999 +#endif
33000
33001 +#ifdef CONFIG_PAX_PER_CPU_PGD
33002 + for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
33003 + pgd_t *pgd = get_cpu_pgd(cpu, kernel);
33004 +#else
33005 list_for_each_entry(page, &pgd_list, lru) {
33006 - pgd_t *pgd;
33007 + pgd_t *pgd = (pgd_t *)page_address(page);
33008 +#endif
33009 +
33010 pud_t *pud;
33011 pmd_t *pmd;
33012
33013 - pgd = (pgd_t *)page_address(page) + pgd_index(address);
33014 + pgd += pgd_index(address);
33015 pud = pud_offset(pgd, address);
33016 pmd = pmd_offset(pud, address);
33017 set_pte_atomic((pte_t *)pmd, pte);
33018 }
33019 }
33020 #endif
33021 + pax_close_kernel();
33022 }
33023
33024 static int
33025 diff --git a/arch/x86/mm/pat.c b/arch/x86/mm/pat.c
33026 index 6574388..87e9bef 100644
33027 --- a/arch/x86/mm/pat.c
33028 +++ b/arch/x86/mm/pat.c
33029 @@ -376,7 +376,7 @@ int free_memtype(u64 start, u64 end)
33030
33031 if (!entry) {
33032 printk(KERN_INFO "%s:%d freeing invalid memtype [mem %#010Lx-%#010Lx]\n",
33033 - current->comm, current->pid, start, end - 1);
33034 + current->comm, task_pid_nr(current), start, end - 1);
33035 return -EINVAL;
33036 }
33037
33038 @@ -506,8 +506,8 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
33039
33040 while (cursor < to) {
33041 if (!devmem_is_allowed(pfn)) {
33042 - printk(KERN_INFO "Program %s tried to access /dev/mem between [mem %#010Lx-%#010Lx]\n",
33043 - current->comm, from, to - 1);
33044 + printk(KERN_INFO "Program %s tried to access /dev/mem between [mem %#010Lx-%#010Lx] (%#010Lx)\n",
33045 + current->comm, from, to - 1, cursor);
33046 return 0;
33047 }
33048 cursor += PAGE_SIZE;
33049 @@ -577,7 +577,7 @@ int kernel_map_sync_memtype(u64 base, unsigned long size, unsigned long flags)
33050 if (ioremap_change_attr((unsigned long)__va(base), id_sz, flags) < 0) {
33051 printk(KERN_INFO "%s:%d ioremap_change_attr failed %s "
33052 "for [mem %#010Lx-%#010Lx]\n",
33053 - current->comm, current->pid,
33054 + current->comm, task_pid_nr(current),
33055 cattr_name(flags),
33056 base, (unsigned long long)(base + size-1));
33057 return -EINVAL;
33058 @@ -612,7 +612,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
33059 flags = lookup_memtype(paddr);
33060 if (want_flags != flags) {
33061 printk(KERN_WARNING "%s:%d map pfn RAM range req %s for [mem %#010Lx-%#010Lx], got %s\n",
33062 - current->comm, current->pid,
33063 + current->comm, task_pid_nr(current),
33064 cattr_name(want_flags),
33065 (unsigned long long)paddr,
33066 (unsigned long long)(paddr + size - 1),
33067 @@ -634,7 +634,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
33068 free_memtype(paddr, paddr + size);
33069 printk(KERN_ERR "%s:%d map pfn expected mapping type %s"
33070 " for [mem %#010Lx-%#010Lx], got %s\n",
33071 - current->comm, current->pid,
33072 + current->comm, task_pid_nr(current),
33073 cattr_name(want_flags),
33074 (unsigned long long)paddr,
33075 (unsigned long long)(paddr + size - 1),
33076 diff --git a/arch/x86/mm/pat_rbtree.c b/arch/x86/mm/pat_rbtree.c
33077 index 415f6c4..d319983 100644
33078 --- a/arch/x86/mm/pat_rbtree.c
33079 +++ b/arch/x86/mm/pat_rbtree.c
33080 @@ -160,7 +160,7 @@ success:
33081
33082 failure:
33083 printk(KERN_INFO "%s:%d conflicting memory types "
33084 - "%Lx-%Lx %s<->%s\n", current->comm, current->pid, start,
33085 + "%Lx-%Lx %s<->%s\n", current->comm, task_pid_nr(current), start,
33086 end, cattr_name(found_type), cattr_name(match->type));
33087 return -EBUSY;
33088 }
33089 diff --git a/arch/x86/mm/pf_in.c b/arch/x86/mm/pf_in.c
33090 index 9f0614d..92ae64a 100644
33091 --- a/arch/x86/mm/pf_in.c
33092 +++ b/arch/x86/mm/pf_in.c
33093 @@ -148,7 +148,7 @@ enum reason_type get_ins_type(unsigned long ins_addr)
33094 int i;
33095 enum reason_type rv = OTHERS;
33096
33097 - p = (unsigned char *)ins_addr;
33098 + p = (unsigned char *)ktla_ktva(ins_addr);
33099 p += skip_prefix(p, &prf);
33100 p += get_opcode(p, &opcode);
33101
33102 @@ -168,7 +168,7 @@ static unsigned int get_ins_reg_width(unsigned long ins_addr)
33103 struct prefix_bits prf;
33104 int i;
33105
33106 - p = (unsigned char *)ins_addr;
33107 + p = (unsigned char *)ktla_ktva(ins_addr);
33108 p += skip_prefix(p, &prf);
33109 p += get_opcode(p, &opcode);
33110
33111 @@ -191,7 +191,7 @@ unsigned int get_ins_mem_width(unsigned long ins_addr)
33112 struct prefix_bits prf;
33113 int i;
33114
33115 - p = (unsigned char *)ins_addr;
33116 + p = (unsigned char *)ktla_ktva(ins_addr);
33117 p += skip_prefix(p, &prf);
33118 p += get_opcode(p, &opcode);
33119
33120 @@ -415,7 +415,7 @@ unsigned long get_ins_reg_val(unsigned long ins_addr, struct pt_regs *regs)
33121 struct prefix_bits prf;
33122 int i;
33123
33124 - p = (unsigned char *)ins_addr;
33125 + p = (unsigned char *)ktla_ktva(ins_addr);
33126 p += skip_prefix(p, &prf);
33127 p += get_opcode(p, &opcode);
33128 for (i = 0; i < ARRAY_SIZE(reg_rop); i++)
33129 @@ -470,7 +470,7 @@ unsigned long get_ins_imm_val(unsigned long ins_addr)
33130 struct prefix_bits prf;
33131 int i;
33132
33133 - p = (unsigned char *)ins_addr;
33134 + p = (unsigned char *)ktla_ktva(ins_addr);
33135 p += skip_prefix(p, &prf);
33136 p += get_opcode(p, &opcode);
33137 for (i = 0; i < ARRAY_SIZE(imm_wop); i++)
33138 diff --git a/arch/x86/mm/pgtable.c b/arch/x86/mm/pgtable.c
33139 index c96314a..433b127 100644
33140 --- a/arch/x86/mm/pgtable.c
33141 +++ b/arch/x86/mm/pgtable.c
33142 @@ -97,10 +97,71 @@ static inline void pgd_list_del(pgd_t *pgd)
33143 list_del(&page->lru);
33144 }
33145
33146 -#define UNSHARED_PTRS_PER_PGD \
33147 - (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
33148 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
33149 +pgdval_t clone_pgd_mask __read_only = ~_PAGE_PRESENT;
33150
33151 +void __shadow_user_pgds(pgd_t *dst, const pgd_t *src)
33152 +{
33153 + unsigned int count = USER_PGD_PTRS;
33154
33155 + if (!pax_user_shadow_base)
33156 + return;
33157 +
33158 + while (count--)
33159 + *dst++ = __pgd((pgd_val(*src++) | (_PAGE_NX & __supported_pte_mask)) & ~_PAGE_USER);
33160 +}
33161 +#endif
33162 +
33163 +#ifdef CONFIG_PAX_PER_CPU_PGD
33164 +void __clone_user_pgds(pgd_t *dst, const pgd_t *src)
33165 +{
33166 + unsigned int count = USER_PGD_PTRS;
33167 +
33168 + while (count--) {
33169 + pgd_t pgd;
33170 +
33171 +#ifdef CONFIG_X86_64
33172 + pgd = __pgd(pgd_val(*src++) | _PAGE_USER);
33173 +#else
33174 + pgd = *src++;
33175 +#endif
33176 +
33177 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
33178 + pgd = __pgd(pgd_val(pgd) & clone_pgd_mask);
33179 +#endif
33180 +
33181 + *dst++ = pgd;
33182 + }
33183 +
33184 +}
33185 +#endif
33186 +
33187 +#ifdef CONFIG_X86_64
33188 +#define pxd_t pud_t
33189 +#define pyd_t pgd_t
33190 +#define paravirt_release_pxd(pfn) paravirt_release_pud(pfn)
33191 +#define pgtable_pxd_page_ctor(page) true
33192 +#define pgtable_pxd_page_dtor(page)
33193 +#define pxd_free(mm, pud) pud_free((mm), (pud))
33194 +#define pyd_populate(mm, pgd, pud) pgd_populate((mm), (pgd), (pud))
33195 +#define pyd_offset(mm, address) pgd_offset((mm), (address))
33196 +#define PYD_SIZE PGDIR_SIZE
33197 +#else
33198 +#define pxd_t pmd_t
33199 +#define pyd_t pud_t
33200 +#define paravirt_release_pxd(pfn) paravirt_release_pmd(pfn)
33201 +#define pgtable_pxd_page_ctor(page) pgtable_pmd_page_ctor(page)
33202 +#define pgtable_pxd_page_dtor(page) pgtable_pmd_page_dtor(page)
33203 +#define pxd_free(mm, pud) pmd_free((mm), (pud))
33204 +#define pyd_populate(mm, pgd, pud) pud_populate((mm), (pgd), (pud))
33205 +#define pyd_offset(mm, address) pud_offset((mm), (address))
33206 +#define PYD_SIZE PUD_SIZE
33207 +#endif
33208 +
33209 +#ifdef CONFIG_PAX_PER_CPU_PGD
33210 +static inline void pgd_ctor(struct mm_struct *mm, pgd_t *pgd) {}
33211 +static inline void pgd_dtor(pgd_t *pgd) {}
33212 +#else
33213 static void pgd_set_mm(pgd_t *pgd, struct mm_struct *mm)
33214 {
33215 BUILD_BUG_ON(sizeof(virt_to_page(pgd)->index) < sizeof(mm));
33216 @@ -141,6 +202,7 @@ static void pgd_dtor(pgd_t *pgd)
33217 pgd_list_del(pgd);
33218 spin_unlock(&pgd_lock);
33219 }
33220 +#endif
33221
33222 /*
33223 * List of all pgd's needed for non-PAE so it can invalidate entries
33224 @@ -153,7 +215,7 @@ static void pgd_dtor(pgd_t *pgd)
33225 * -- nyc
33226 */
33227
33228 -#ifdef CONFIG_X86_PAE
33229 +#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
33230 /*
33231 * In PAE mode, we need to do a cr3 reload (=tlb flush) when
33232 * updating the top-level pagetable entries to guarantee the
33233 @@ -165,7 +227,7 @@ static void pgd_dtor(pgd_t *pgd)
33234 * not shared between pagetables (!SHARED_KERNEL_PMDS), we allocate
33235 * and initialize the kernel pmds here.
33236 */
33237 -#define PREALLOCATED_PMDS UNSHARED_PTRS_PER_PGD
33238 +#define PREALLOCATED_PXDS (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
33239
33240 void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
33241 {
33242 @@ -183,43 +245,45 @@ void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
33243 */
33244 flush_tlb_mm(mm);
33245 }
33246 +#elif defined(CONFIG_X86_64) && defined(CONFIG_PAX_PER_CPU_PGD)
33247 +#define PREALLOCATED_PXDS USER_PGD_PTRS
33248 #else /* !CONFIG_X86_PAE */
33249
33250 /* No need to prepopulate any pagetable entries in non-PAE modes. */
33251 -#define PREALLOCATED_PMDS 0
33252 +#define PREALLOCATED_PXDS 0
33253
33254 #endif /* CONFIG_X86_PAE */
33255
33256 -static void free_pmds(pmd_t *pmds[])
33257 +static void free_pxds(pxd_t *pxds[])
33258 {
33259 int i;
33260
33261 - for(i = 0; i < PREALLOCATED_PMDS; i++)
33262 - if (pmds[i]) {
33263 - pgtable_pmd_page_dtor(virt_to_page(pmds[i]));
33264 - free_page((unsigned long)pmds[i]);
33265 + for(i = 0; i < PREALLOCATED_PXDS; i++)
33266 + if (pxds[i]) {
33267 + pgtable_pxd_page_dtor(virt_to_page(pxds[i]));
33268 + free_page((unsigned long)pxds[i]);
33269 }
33270 }
33271
33272 -static int preallocate_pmds(pmd_t *pmds[])
33273 +static int preallocate_pxds(pxd_t *pxds[])
33274 {
33275 int i;
33276 bool failed = false;
33277
33278 - for(i = 0; i < PREALLOCATED_PMDS; i++) {
33279 - pmd_t *pmd = (pmd_t *)__get_free_page(PGALLOC_GFP);
33280 - if (!pmd)
33281 + for(i = 0; i < PREALLOCATED_PXDS; i++) {
33282 + pxd_t *pxd = (pxd_t *)__get_free_page(PGALLOC_GFP);
33283 + if (!pxd)
33284 failed = true;
33285 - if (pmd && !pgtable_pmd_page_ctor(virt_to_page(pmd))) {
33286 - free_page((unsigned long)pmd);
33287 - pmd = NULL;
33288 + if (pxd && !pgtable_pxd_page_ctor(virt_to_page(pxd))) {
33289 + free_page((unsigned long)pxd);
33290 + pxd = NULL;
33291 failed = true;
33292 }
33293 - pmds[i] = pmd;
33294 + pxds[i] = pxd;
33295 }
33296
33297 if (failed) {
33298 - free_pmds(pmds);
33299 + free_pxds(pxds);
33300 return -ENOMEM;
33301 }
33302
33303 @@ -232,49 +296,52 @@ static int preallocate_pmds(pmd_t *pmds[])
33304 * preallocate which never got a corresponding vma will need to be
33305 * freed manually.
33306 */
33307 -static void pgd_mop_up_pmds(struct mm_struct *mm, pgd_t *pgdp)
33308 +static void pgd_mop_up_pxds(struct mm_struct *mm, pgd_t *pgdp)
33309 {
33310 int i;
33311
33312 - for(i = 0; i < PREALLOCATED_PMDS; i++) {
33313 + for(i = 0; i < PREALLOCATED_PXDS; i++) {
33314 pgd_t pgd = pgdp[i];
33315
33316 if (pgd_val(pgd) != 0) {
33317 - pmd_t *pmd = (pmd_t *)pgd_page_vaddr(pgd);
33318 + pxd_t *pxd = (pxd_t *)pgd_page_vaddr(pgd);
33319
33320 - pgdp[i] = native_make_pgd(0);
33321 + set_pgd(pgdp + i, native_make_pgd(0));
33322
33323 - paravirt_release_pmd(pgd_val(pgd) >> PAGE_SHIFT);
33324 - pmd_free(mm, pmd);
33325 + paravirt_release_pxd(pgd_val(pgd) >> PAGE_SHIFT);
33326 + pxd_free(mm, pxd);
33327 }
33328 }
33329 }
33330
33331 -static void pgd_prepopulate_pmd(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmds[])
33332 +static void pgd_prepopulate_pxd(struct mm_struct *mm, pgd_t *pgd, pxd_t *pxds[])
33333 {
33334 - pud_t *pud;
33335 + pyd_t *pyd;
33336 int i;
33337
33338 - if (PREALLOCATED_PMDS == 0) /* Work around gcc-3.4.x bug */
33339 + if (PREALLOCATED_PXDS == 0) /* Work around gcc-3.4.x bug */
33340 return;
33341
33342 - pud = pud_offset(pgd, 0);
33343 -
33344 - for (i = 0; i < PREALLOCATED_PMDS; i++, pud++) {
33345 - pmd_t *pmd = pmds[i];
33346 +#ifdef CONFIG_X86_64
33347 + pyd = pyd_offset(mm, 0L);
33348 +#else
33349 + pyd = pyd_offset(pgd, 0L);
33350 +#endif
33351
33352 + for (i = 0; i < PREALLOCATED_PXDS; i++, pyd++) {
33353 + pxd_t *pxd = pxds[i];
33354 if (i >= KERNEL_PGD_BOUNDARY)
33355 - memcpy(pmd, (pmd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
33356 - sizeof(pmd_t) * PTRS_PER_PMD);
33357 + memcpy(pxd, (pxd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
33358 + sizeof(pxd_t) * PTRS_PER_PMD);
33359
33360 - pud_populate(mm, pud, pmd);
33361 + pyd_populate(mm, pyd, pxd);
33362 }
33363 }
33364
33365 pgd_t *pgd_alloc(struct mm_struct *mm)
33366 {
33367 pgd_t *pgd;
33368 - pmd_t *pmds[PREALLOCATED_PMDS];
33369 + pxd_t *pxds[PREALLOCATED_PXDS];
33370
33371 pgd = (pgd_t *)__get_free_page(PGALLOC_GFP);
33372
33373 @@ -283,11 +350,11 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
33374
33375 mm->pgd = pgd;
33376
33377 - if (preallocate_pmds(pmds) != 0)
33378 + if (preallocate_pxds(pxds) != 0)
33379 goto out_free_pgd;
33380
33381 if (paravirt_pgd_alloc(mm) != 0)
33382 - goto out_free_pmds;
33383 + goto out_free_pxds;
33384
33385 /*
33386 * Make sure that pre-populating the pmds is atomic with
33387 @@ -297,14 +364,14 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
33388 spin_lock(&pgd_lock);
33389
33390 pgd_ctor(mm, pgd);
33391 - pgd_prepopulate_pmd(mm, pgd, pmds);
33392 + pgd_prepopulate_pxd(mm, pgd, pxds);
33393
33394 spin_unlock(&pgd_lock);
33395
33396 return pgd;
33397
33398 -out_free_pmds:
33399 - free_pmds(pmds);
33400 +out_free_pxds:
33401 + free_pxds(pxds);
33402 out_free_pgd:
33403 free_page((unsigned long)pgd);
33404 out:
33405 @@ -313,7 +380,7 @@ out:
33406
33407 void pgd_free(struct mm_struct *mm, pgd_t *pgd)
33408 {
33409 - pgd_mop_up_pmds(mm, pgd);
33410 + pgd_mop_up_pxds(mm, pgd);
33411 pgd_dtor(pgd);
33412 paravirt_pgd_free(mm, pgd);
33413 free_page((unsigned long)pgd);
33414 diff --git a/arch/x86/mm/pgtable_32.c b/arch/x86/mm/pgtable_32.c
33415 index a69bcb8..19068ab 100644
33416 --- a/arch/x86/mm/pgtable_32.c
33417 +++ b/arch/x86/mm/pgtable_32.c
33418 @@ -47,10 +47,13 @@ void set_pte_vaddr(unsigned long vaddr, pte_t pteval)
33419 return;
33420 }
33421 pte = pte_offset_kernel(pmd, vaddr);
33422 +
33423 + pax_open_kernel();
33424 if (pte_val(pteval))
33425 set_pte_at(&init_mm, vaddr, pte, pteval);
33426 else
33427 pte_clear(&init_mm, vaddr, pte);
33428 + pax_close_kernel();
33429
33430 /*
33431 * It's enough to flush this one mapping.
33432 diff --git a/arch/x86/mm/physaddr.c b/arch/x86/mm/physaddr.c
33433 index e666cbb..61788c45 100644
33434 --- a/arch/x86/mm/physaddr.c
33435 +++ b/arch/x86/mm/physaddr.c
33436 @@ -10,7 +10,7 @@
33437 #ifdef CONFIG_X86_64
33438
33439 #ifdef CONFIG_DEBUG_VIRTUAL
33440 -unsigned long __phys_addr(unsigned long x)
33441 +unsigned long __intentional_overflow(-1) __phys_addr(unsigned long x)
33442 {
33443 unsigned long y = x - __START_KERNEL_map;
33444
33445 @@ -67,7 +67,7 @@ EXPORT_SYMBOL(__virt_addr_valid);
33446 #else
33447
33448 #ifdef CONFIG_DEBUG_VIRTUAL
33449 -unsigned long __phys_addr(unsigned long x)
33450 +unsigned long __intentional_overflow(-1) __phys_addr(unsigned long x)
33451 {
33452 unsigned long phys_addr = x - PAGE_OFFSET;
33453 /* VMALLOC_* aren't constants */
33454 diff --git a/arch/x86/mm/setup_nx.c b/arch/x86/mm/setup_nx.c
33455 index 90555bf..f5f1828 100644
33456 --- a/arch/x86/mm/setup_nx.c
33457 +++ b/arch/x86/mm/setup_nx.c
33458 @@ -5,8 +5,10 @@
33459 #include <asm/pgtable.h>
33460 #include <asm/proto.h>
33461
33462 +#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
33463 static int disable_nx;
33464
33465 +#ifndef CONFIG_PAX_PAGEEXEC
33466 /*
33467 * noexec = on|off
33468 *
33469 @@ -28,12 +30,17 @@ static int __init noexec_setup(char *str)
33470 return 0;
33471 }
33472 early_param("noexec", noexec_setup);
33473 +#endif
33474 +
33475 +#endif
33476
33477 void x86_configure_nx(void)
33478 {
33479 +#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
33480 if (cpu_has_nx && !disable_nx)
33481 __supported_pte_mask |= _PAGE_NX;
33482 else
33483 +#endif
33484 __supported_pte_mask &= ~_PAGE_NX;
33485 }
33486
33487 diff --git a/arch/x86/mm/tlb.c b/arch/x86/mm/tlb.c
33488 index ae699b3..f1b2ad2 100644
33489 --- a/arch/x86/mm/tlb.c
33490 +++ b/arch/x86/mm/tlb.c
33491 @@ -48,7 +48,11 @@ void leave_mm(int cpu)
33492 BUG();
33493 if (cpumask_test_cpu(cpu, mm_cpumask(active_mm))) {
33494 cpumask_clear_cpu(cpu, mm_cpumask(active_mm));
33495 +
33496 +#ifndef CONFIG_PAX_PER_CPU_PGD
33497 load_cr3(swapper_pg_dir);
33498 +#endif
33499 +
33500 }
33501 }
33502 EXPORT_SYMBOL_GPL(leave_mm);
33503 diff --git a/arch/x86/mm/uderef_64.c b/arch/x86/mm/uderef_64.c
33504 new file mode 100644
33505 index 0000000..dace51c
33506 --- /dev/null
33507 +++ b/arch/x86/mm/uderef_64.c
33508 @@ -0,0 +1,37 @@
33509 +#include <linux/mm.h>
33510 +#include <asm/pgtable.h>
33511 +#include <asm/uaccess.h>
33512 +
33513 +#ifdef CONFIG_PAX_MEMORY_UDEREF
33514 +/* PaX: due to the special call convention these functions must
33515 + * - remain leaf functions under all configurations,
33516 + * - never be called directly, only dereferenced from the wrappers.
33517 + */
33518 +void __pax_open_userland(void)
33519 +{
33520 + unsigned int cpu;
33521 +
33522 + if (unlikely(!segment_eq(get_fs(), USER_DS)))
33523 + return;
33524 +
33525 + cpu = raw_get_cpu();
33526 + BUG_ON((read_cr3() & ~PAGE_MASK) != PCID_KERNEL);
33527 + write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER | PCID_NOFLUSH);
33528 + raw_put_cpu_no_resched();
33529 +}
33530 +EXPORT_SYMBOL(__pax_open_userland);
33531 +
33532 +void __pax_close_userland(void)
33533 +{
33534 + unsigned int cpu;
33535 +
33536 + if (unlikely(!segment_eq(get_fs(), USER_DS)))
33537 + return;
33538 +
33539 + cpu = raw_get_cpu();
33540 + BUG_ON((read_cr3() & ~PAGE_MASK) != PCID_USER);
33541 + write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL | PCID_NOFLUSH);
33542 + raw_put_cpu_no_resched();
33543 +}
33544 +EXPORT_SYMBOL(__pax_close_userland);
33545 +#endif
33546 diff --git a/arch/x86/net/bpf_jit.S b/arch/x86/net/bpf_jit.S
33547 index 0149575..f746de8 100644
33548 --- a/arch/x86/net/bpf_jit.S
33549 +++ b/arch/x86/net/bpf_jit.S
33550 @@ -9,6 +9,7 @@
33551 */
33552 #include <linux/linkage.h>
33553 #include <asm/dwarf2.h>
33554 +#include <asm/alternative-asm.h>
33555
33556 /*
33557 * Calling convention :
33558 @@ -35,6 +36,7 @@ sk_load_word_positive_offset:
33559 jle bpf_slow_path_word
33560 mov (SKBDATA,%rsi),%eax
33561 bswap %eax /* ntohl() */
33562 + pax_force_retaddr
33563 ret
33564
33565 sk_load_half:
33566 @@ -52,6 +54,7 @@ sk_load_half_positive_offset:
33567 jle bpf_slow_path_half
33568 movzwl (SKBDATA,%rsi),%eax
33569 rol $8,%ax # ntohs()
33570 + pax_force_retaddr
33571 ret
33572
33573 sk_load_byte:
33574 @@ -66,6 +69,7 @@ sk_load_byte_positive_offset:
33575 cmp %esi,%r9d /* if (offset >= hlen) goto bpf_slow_path_byte */
33576 jle bpf_slow_path_byte
33577 movzbl (SKBDATA,%rsi),%eax
33578 + pax_force_retaddr
33579 ret
33580
33581 /**
33582 @@ -87,6 +91,7 @@ sk_load_byte_msh_positive_offset:
33583 movzbl (SKBDATA,%rsi),%ebx
33584 and $15,%bl
33585 shl $2,%bl
33586 + pax_force_retaddr
33587 ret
33588
33589 /* rsi contains offset and can be scratched */
33590 @@ -109,6 +114,7 @@ bpf_slow_path_word:
33591 js bpf_error
33592 mov -12(%rbp),%eax
33593 bswap %eax
33594 + pax_force_retaddr
33595 ret
33596
33597 bpf_slow_path_half:
33598 @@ -117,12 +123,14 @@ bpf_slow_path_half:
33599 mov -12(%rbp),%ax
33600 rol $8,%ax
33601 movzwl %ax,%eax
33602 + pax_force_retaddr
33603 ret
33604
33605 bpf_slow_path_byte:
33606 bpf_slow_path_common(1)
33607 js bpf_error
33608 movzbl -12(%rbp),%eax
33609 + pax_force_retaddr
33610 ret
33611
33612 bpf_slow_path_byte_msh:
33613 @@ -133,6 +141,7 @@ bpf_slow_path_byte_msh:
33614 and $15,%al
33615 shl $2,%al
33616 xchg %eax,%ebx
33617 + pax_force_retaddr
33618 ret
33619
33620 #define sk_negative_common(SIZE) \
33621 @@ -157,6 +166,7 @@ sk_load_word_negative_offset:
33622 sk_negative_common(4)
33623 mov (%rax), %eax
33624 bswap %eax
33625 + pax_force_retaddr
33626 ret
33627
33628 bpf_slow_path_half_neg:
33629 @@ -168,6 +178,7 @@ sk_load_half_negative_offset:
33630 mov (%rax),%ax
33631 rol $8,%ax
33632 movzwl %ax,%eax
33633 + pax_force_retaddr
33634 ret
33635
33636 bpf_slow_path_byte_neg:
33637 @@ -177,6 +188,7 @@ sk_load_byte_negative_offset:
33638 .globl sk_load_byte_negative_offset
33639 sk_negative_common(1)
33640 movzbl (%rax), %eax
33641 + pax_force_retaddr
33642 ret
33643
33644 bpf_slow_path_byte_msh_neg:
33645 @@ -190,6 +202,7 @@ sk_load_byte_msh_negative_offset:
33646 and $15,%al
33647 shl $2,%al
33648 xchg %eax,%ebx
33649 + pax_force_retaddr
33650 ret
33651
33652 bpf_error:
33653 @@ -197,4 +210,5 @@ bpf_error:
33654 xor %eax,%eax
33655 mov -8(%rbp),%rbx
33656 leaveq
33657 + pax_force_retaddr
33658 ret
33659 diff --git a/arch/x86/net/bpf_jit_comp.c b/arch/x86/net/bpf_jit_comp.c
33660 index 4ed75dd..3cf24f0b 100644
33661 --- a/arch/x86/net/bpf_jit_comp.c
33662 +++ b/arch/x86/net/bpf_jit_comp.c
33663 @@ -50,13 +50,90 @@ static inline u8 *emit_code(u8 *ptr, u32 bytes, unsigned int len)
33664 return ptr + len;
33665 }
33666
33667 +#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
33668 +#define MAX_INSTR_CODE_SIZE 96
33669 +#else
33670 +#define MAX_INSTR_CODE_SIZE 64
33671 +#endif
33672 +
33673 #define EMIT(bytes, len) do { prog = emit_code(prog, bytes, len); } while (0)
33674
33675 #define EMIT1(b1) EMIT(b1, 1)
33676 #define EMIT2(b1, b2) EMIT((b1) + ((b2) << 8), 2)
33677 #define EMIT3(b1, b2, b3) EMIT((b1) + ((b2) << 8) + ((b3) << 16), 3)
33678 #define EMIT4(b1, b2, b3, b4) EMIT((b1) + ((b2) << 8) + ((b3) << 16) + ((b4) << 24), 4)
33679 +
33680 +#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
33681 +/* original constant will appear in ecx */
33682 +#define DILUTE_CONST_SEQUENCE(_off, _key) \
33683 +do { \
33684 + /* mov ecx, randkey */ \
33685 + EMIT1(0xb9); \
33686 + EMIT(_key, 4); \
33687 + /* xor ecx, randkey ^ off */ \
33688 + EMIT2(0x81, 0xf1); \
33689 + EMIT((_key) ^ (_off), 4); \
33690 +} while (0)
33691 +
33692 +#define EMIT1_off32(b1, _off) \
33693 +do { \
33694 + switch (b1) { \
33695 + case 0x05: /* add eax, imm32 */ \
33696 + case 0x2d: /* sub eax, imm32 */ \
33697 + case 0x25: /* and eax, imm32 */ \
33698 + case 0x0d: /* or eax, imm32 */ \
33699 + case 0xb8: /* mov eax, imm32 */ \
33700 + case 0x35: /* xor eax, imm32 */ \
33701 + case 0x3d: /* cmp eax, imm32 */ \
33702 + case 0xa9: /* test eax, imm32 */ \
33703 + DILUTE_CONST_SEQUENCE(_off, randkey); \
33704 + EMIT2((b1) - 4, 0xc8); /* convert imm instruction to eax, ecx */\
33705 + break; \
33706 + case 0xbb: /* mov ebx, imm32 */ \
33707 + DILUTE_CONST_SEQUENCE(_off, randkey); \
33708 + /* mov ebx, ecx */ \
33709 + EMIT2(0x89, 0xcb); \
33710 + break; \
33711 + case 0xbe: /* mov esi, imm32 */ \
33712 + DILUTE_CONST_SEQUENCE(_off, randkey); \
33713 + /* mov esi, ecx */ \
33714 + EMIT2(0x89, 0xce); \
33715 + break; \
33716 + case 0xe8: /* call rel imm32, always to known funcs */ \
33717 + EMIT1(b1); \
33718 + EMIT(_off, 4); \
33719 + break; \
33720 + case 0xe9: /* jmp rel imm32 */ \
33721 + EMIT1(b1); \
33722 + EMIT(_off, 4); \
33723 + /* prevent fall-through, we're not called if off = 0 */ \
33724 + EMIT(0xcccccccc, 4); \
33725 + EMIT(0xcccccccc, 4); \
33726 + break; \
33727 + default: \
33728 + BUILD_BUG(); \
33729 + } \
33730 +} while (0)
33731 +
33732 +#define EMIT2_off32(b1, b2, _off) \
33733 +do { \
33734 + if ((b1) == 0x8d && (b2) == 0xb3) { /* lea esi, [rbx+imm32] */ \
33735 + EMIT2(0x8d, 0xb3); /* lea esi, [rbx+randkey] */ \
33736 + EMIT(randkey, 4); \
33737 + EMIT2(0x8d, 0xb6); /* lea esi, [esi+off-randkey] */ \
33738 + EMIT((_off) - randkey, 4); \
33739 + } else if ((b1) == 0x69 && (b2) == 0xc0) { /* imul eax, imm32 */\
33740 + DILUTE_CONST_SEQUENCE(_off, randkey); \
33741 + /* imul eax, ecx */ \
33742 + EMIT3(0x0f, 0xaf, 0xc1); \
33743 + } else { \
33744 + BUILD_BUG(); \
33745 + } \
33746 +} while (0)
33747 +#else
33748 #define EMIT1_off32(b1, off) do { EMIT1(b1); EMIT(off, 4);} while (0)
33749 +#define EMIT2_off32(b1, b2, off) do { EMIT2(b1, b2); EMIT(off, 4);} while (0)
33750 +#endif
33751
33752 #define CLEAR_A() EMIT2(0x31, 0xc0) /* xor %eax,%eax */
33753 #define CLEAR_X() EMIT2(0x31, 0xdb) /* xor %ebx,%ebx */
33754 @@ -91,6 +168,24 @@ do { \
33755 #define X86_JBE 0x76
33756 #define X86_JA 0x77
33757
33758 +#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
33759 +#define APPEND_FLOW_VERIFY() \
33760 +do { \
33761 + /* mov ecx, randkey */ \
33762 + EMIT1(0xb9); \
33763 + EMIT(randkey, 4); \
33764 + /* cmp ecx, randkey */ \
33765 + EMIT2(0x81, 0xf9); \
33766 + EMIT(randkey, 4); \
33767 + /* jz after 8 int 3s */ \
33768 + EMIT2(0x74, 0x08); \
33769 + EMIT(0xcccccccc, 4); \
33770 + EMIT(0xcccccccc, 4); \
33771 +} while (0)
33772 +#else
33773 +#define APPEND_FLOW_VERIFY() do { } while (0)
33774 +#endif
33775 +
33776 #define EMIT_COND_JMP(op, offset) \
33777 do { \
33778 if (is_near(offset)) \
33779 @@ -98,6 +193,7 @@ do { \
33780 else { \
33781 EMIT2(0x0f, op + 0x10); \
33782 EMIT(offset, 4); /* jxx .+off32 */ \
33783 + APPEND_FLOW_VERIFY(); \
33784 } \
33785 } while (0)
33786
33787 @@ -145,55 +241,54 @@ static int pkt_type_offset(void)
33788 return -1;
33789 }
33790
33791 -struct bpf_binary_header {
33792 - unsigned int pages;
33793 - /* Note : for security reasons, bpf code will follow a randomly
33794 - * sized amount of int3 instructions
33795 - */
33796 - u8 image[];
33797 -};
33798 -
33799 -static struct bpf_binary_header *bpf_alloc_binary(unsigned int proglen,
33800 +/* Note : for security reasons, bpf code will follow a randomly
33801 + * sized amount of int3 instructions
33802 + */
33803 +static u8 *bpf_alloc_binary(unsigned int proglen,
33804 u8 **image_ptr)
33805 {
33806 unsigned int sz, hole;
33807 - struct bpf_binary_header *header;
33808 + u8 *header;
33809
33810 /* Most of BPF filters are really small,
33811 * but if some of them fill a page, allow at least
33812 * 128 extra bytes to insert a random section of int3
33813 */
33814 - sz = round_up(proglen + sizeof(*header) + 128, PAGE_SIZE);
33815 - header = module_alloc(sz);
33816 + sz = round_up(proglen + 128, PAGE_SIZE);
33817 + header = module_alloc_exec(sz);
33818 if (!header)
33819 return NULL;
33820
33821 + pax_open_kernel();
33822 memset(header, 0xcc, sz); /* fill whole space with int3 instructions */
33823 + pax_close_kernel();
33824
33825 - header->pages = sz / PAGE_SIZE;
33826 - hole = sz - (proglen + sizeof(*header));
33827 + hole = PAGE_SIZE - (proglen & ~PAGE_MASK);
33828
33829 /* insert a random number of int3 instructions before BPF code */
33830 - *image_ptr = &header->image[prandom_u32() % hole];
33831 + *image_ptr = &header[prandom_u32() % hole];
33832 return header;
33833 }
33834
33835 void bpf_jit_compile(struct sk_filter *fp)
33836 {
33837 - u8 temp[64];
33838 + u8 temp[MAX_INSTR_CODE_SIZE];
33839 u8 *prog;
33840 unsigned int proglen, oldproglen = 0;
33841 int ilen, i;
33842 int t_offset, f_offset;
33843 u8 t_op, f_op, seen = 0, pass;
33844 u8 *image = NULL;
33845 - struct bpf_binary_header *header = NULL;
33846 + u8 *header = NULL;
33847 u8 *func;
33848 int pc_ret0 = -1; /* bpf index of first RET #0 instruction (if any) */
33849 unsigned int cleanup_addr; /* epilogue code offset */
33850 unsigned int *addrs;
33851 const struct sock_filter *filter = fp->insns;
33852 int flen = fp->len;
33853 +#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
33854 + unsigned int randkey;
33855 +#endif
33856
33857 if (!bpf_jit_enable)
33858 return;
33859 @@ -203,10 +298,10 @@ void bpf_jit_compile(struct sk_filter *fp)
33860 return;
33861
33862 /* Before first pass, make a rough estimation of addrs[]
33863 - * each bpf instruction is translated to less than 64 bytes
33864 + * each bpf instruction is translated to less than MAX_INSTR_CODE_SIZE bytes
33865 */
33866 for (proglen = 0, i = 0; i < flen; i++) {
33867 - proglen += 64;
33868 + proglen += MAX_INSTR_CODE_SIZE;
33869 addrs[i] = proglen;
33870 }
33871 cleanup_addr = proglen; /* epilogue address */
33872 @@ -285,6 +380,10 @@ void bpf_jit_compile(struct sk_filter *fp)
33873 for (i = 0; i < flen; i++) {
33874 unsigned int K = filter[i].k;
33875
33876 +#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
33877 + randkey = prandom_u32();
33878 +#endif
33879 +
33880 switch (filter[i].code) {
33881 case BPF_S_ALU_ADD_X: /* A += X; */
33882 seen |= SEEN_XREG;
33883 @@ -317,10 +416,8 @@ void bpf_jit_compile(struct sk_filter *fp)
33884 case BPF_S_ALU_MUL_K: /* A *= K */
33885 if (is_imm8(K))
33886 EMIT3(0x6b, 0xc0, K); /* imul imm8,%eax,%eax */
33887 - else {
33888 - EMIT2(0x69, 0xc0); /* imul imm32,%eax */
33889 - EMIT(K, 4);
33890 - }
33891 + else
33892 + EMIT2_off32(0x69, 0xc0, K); /* imul imm32,%eax */
33893 break;
33894 case BPF_S_ALU_DIV_X: /* A /= X; */
33895 seen |= SEEN_XREG;
33896 @@ -364,7 +461,11 @@ void bpf_jit_compile(struct sk_filter *fp)
33897 break;
33898 }
33899 EMIT2(0x31, 0xd2); /* xor %edx,%edx */
33900 +#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
33901 + DILUTE_CONST_SEQUENCE(K, randkey);
33902 +#else
33903 EMIT1(0xb9);EMIT(K, 4); /* mov imm32,%ecx */
33904 +#endif
33905 EMIT2(0xf7, 0xf1); /* div %ecx */
33906 EMIT2(0x89, 0xd0); /* mov %edx,%eax */
33907 break;
33908 @@ -372,7 +473,11 @@ void bpf_jit_compile(struct sk_filter *fp)
33909 if (K == 1)
33910 break;
33911 EMIT2(0x31, 0xd2); /* xor %edx,%edx */
33912 +#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
33913 + DILUTE_CONST_SEQUENCE(K, randkey);
33914 +#else
33915 EMIT1(0xb9);EMIT(K, 4); /* mov imm32,%ecx */
33916 +#endif
33917 EMIT2(0xf7, 0xf1); /* div %ecx */
33918 break;
33919 case BPF_S_ALU_AND_X:
33920 @@ -643,8 +748,7 @@ common_load_ind: seen |= SEEN_DATAREF | SEEN_XREG;
33921 if (is_imm8(K)) {
33922 EMIT3(0x8d, 0x73, K); /* lea imm8(%rbx), %esi */
33923 } else {
33924 - EMIT2(0x8d, 0xb3); /* lea imm32(%rbx),%esi */
33925 - EMIT(K, 4);
33926 + EMIT2_off32(0x8d, 0xb3, K); /* lea imm32(%rbx),%esi */
33927 }
33928 } else {
33929 EMIT2(0x89,0xde); /* mov %ebx,%esi */
33930 @@ -734,10 +838,12 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
33931 if (unlikely(proglen + ilen > oldproglen)) {
33932 pr_err("bpb_jit_compile fatal error\n");
33933 kfree(addrs);
33934 - module_free(NULL, header);
33935 + module_free_exec(NULL, image);
33936 return;
33937 }
33938 + pax_open_kernel();
33939 memcpy(image + proglen, temp, ilen);
33940 + pax_close_kernel();
33941 }
33942 proglen += ilen;
33943 addrs[i] = proglen;
33944 @@ -770,7 +876,6 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
33945
33946 if (image) {
33947 bpf_flush_icache(header, image + proglen);
33948 - set_memory_ro((unsigned long)header, header->pages);
33949 fp->bpf_func = (void *)image;
33950 }
33951 out:
33952 @@ -782,10 +887,9 @@ static void bpf_jit_free_deferred(struct work_struct *work)
33953 {
33954 struct sk_filter *fp = container_of(work, struct sk_filter, work);
33955 unsigned long addr = (unsigned long)fp->bpf_func & PAGE_MASK;
33956 - struct bpf_binary_header *header = (void *)addr;
33957
33958 - set_memory_rw(addr, header->pages);
33959 - module_free(NULL, header);
33960 + set_memory_rw(addr, 1);
33961 + module_free_exec(NULL, (void *)addr);
33962 kfree(fp);
33963 }
33964
33965 diff --git a/arch/x86/oprofile/backtrace.c b/arch/x86/oprofile/backtrace.c
33966 index 5d04be5..2beeaa2 100644
33967 --- a/arch/x86/oprofile/backtrace.c
33968 +++ b/arch/x86/oprofile/backtrace.c
33969 @@ -46,11 +46,11 @@ dump_user_backtrace_32(struct stack_frame_ia32 *head)
33970 struct stack_frame_ia32 *fp;
33971 unsigned long bytes;
33972
33973 - bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
33974 + bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
33975 if (bytes != 0)
33976 return NULL;
33977
33978 - fp = (struct stack_frame_ia32 *) compat_ptr(bufhead[0].next_frame);
33979 + fp = (struct stack_frame_ia32 __force_kernel *) compat_ptr(bufhead[0].next_frame);
33980
33981 oprofile_add_trace(bufhead[0].return_address);
33982
33983 @@ -92,7 +92,7 @@ static struct stack_frame *dump_user_backtrace(struct stack_frame *head)
33984 struct stack_frame bufhead[2];
33985 unsigned long bytes;
33986
33987 - bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
33988 + bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
33989 if (bytes != 0)
33990 return NULL;
33991
33992 @@ -111,7 +111,7 @@ x86_backtrace(struct pt_regs * const regs, unsigned int depth)
33993 {
33994 struct stack_frame *head = (struct stack_frame *)frame_pointer(regs);
33995
33996 - if (!user_mode_vm(regs)) {
33997 + if (!user_mode(regs)) {
33998 unsigned long stack = kernel_stack_pointer(regs);
33999 if (depth)
34000 dump_trace(NULL, regs, (unsigned long *)stack, 0,
34001 diff --git a/arch/x86/oprofile/nmi_int.c b/arch/x86/oprofile/nmi_int.c
34002 index 6890d84..1dad1f1 100644
34003 --- a/arch/x86/oprofile/nmi_int.c
34004 +++ b/arch/x86/oprofile/nmi_int.c
34005 @@ -23,6 +23,7 @@
34006 #include <asm/nmi.h>
34007 #include <asm/msr.h>
34008 #include <asm/apic.h>
34009 +#include <asm/pgtable.h>
34010
34011 #include "op_counter.h"
34012 #include "op_x86_model.h"
34013 @@ -774,8 +775,11 @@ int __init op_nmi_init(struct oprofile_operations *ops)
34014 if (ret)
34015 return ret;
34016
34017 - if (!model->num_virt_counters)
34018 - model->num_virt_counters = model->num_counters;
34019 + if (!model->num_virt_counters) {
34020 + pax_open_kernel();
34021 + *(unsigned int *)&model->num_virt_counters = model->num_counters;
34022 + pax_close_kernel();
34023 + }
34024
34025 mux_init(ops);
34026
34027 diff --git a/arch/x86/oprofile/op_model_amd.c b/arch/x86/oprofile/op_model_amd.c
34028 index 50d86c0..7985318 100644
34029 --- a/arch/x86/oprofile/op_model_amd.c
34030 +++ b/arch/x86/oprofile/op_model_amd.c
34031 @@ -519,9 +519,11 @@ static int op_amd_init(struct oprofile_operations *ops)
34032 num_counters = AMD64_NUM_COUNTERS;
34033 }
34034
34035 - op_amd_spec.num_counters = num_counters;
34036 - op_amd_spec.num_controls = num_counters;
34037 - op_amd_spec.num_virt_counters = max(num_counters, NUM_VIRT_COUNTERS);
34038 + pax_open_kernel();
34039 + *(unsigned int *)&op_amd_spec.num_counters = num_counters;
34040 + *(unsigned int *)&op_amd_spec.num_controls = num_counters;
34041 + *(unsigned int *)&op_amd_spec.num_virt_counters = max(num_counters, NUM_VIRT_COUNTERS);
34042 + pax_close_kernel();
34043
34044 return 0;
34045 }
34046 diff --git a/arch/x86/oprofile/op_model_ppro.c b/arch/x86/oprofile/op_model_ppro.c
34047 index d90528e..0127e2b 100644
34048 --- a/arch/x86/oprofile/op_model_ppro.c
34049 +++ b/arch/x86/oprofile/op_model_ppro.c
34050 @@ -19,6 +19,7 @@
34051 #include <asm/msr.h>
34052 #include <asm/apic.h>
34053 #include <asm/nmi.h>
34054 +#include <asm/pgtable.h>
34055
34056 #include "op_x86_model.h"
34057 #include "op_counter.h"
34058 @@ -221,8 +222,10 @@ static void arch_perfmon_setup_counters(void)
34059
34060 num_counters = min((int)eax.split.num_counters, OP_MAX_COUNTER);
34061
34062 - op_arch_perfmon_spec.num_counters = num_counters;
34063 - op_arch_perfmon_spec.num_controls = num_counters;
34064 + pax_open_kernel();
34065 + *(unsigned int *)&op_arch_perfmon_spec.num_counters = num_counters;
34066 + *(unsigned int *)&op_arch_perfmon_spec.num_controls = num_counters;
34067 + pax_close_kernel();
34068 }
34069
34070 static int arch_perfmon_init(struct oprofile_operations *ignore)
34071 diff --git a/arch/x86/oprofile/op_x86_model.h b/arch/x86/oprofile/op_x86_model.h
34072 index 71e8a67..6a313bb 100644
34073 --- a/arch/x86/oprofile/op_x86_model.h
34074 +++ b/arch/x86/oprofile/op_x86_model.h
34075 @@ -52,7 +52,7 @@ struct op_x86_model_spec {
34076 void (*switch_ctrl)(struct op_x86_model_spec const *model,
34077 struct op_msrs const * const msrs);
34078 #endif
34079 -};
34080 +} __do_const;
34081
34082 struct op_counter_config;
34083
34084 diff --git a/arch/x86/pci/intel_mid_pci.c b/arch/x86/pci/intel_mid_pci.c
34085 index 51384ca..a25f51e 100644
34086 --- a/arch/x86/pci/intel_mid_pci.c
34087 +++ b/arch/x86/pci/intel_mid_pci.c
34088 @@ -241,7 +241,7 @@ int __init intel_mid_pci_init(void)
34089 pr_info("Intel MID platform detected, using MID PCI ops\n");
34090 pci_mmcfg_late_init();
34091 pcibios_enable_irq = intel_mid_pci_irq_enable;
34092 - pci_root_ops = intel_mid_pci_ops;
34093 + memcpy((void *)&pci_root_ops, &intel_mid_pci_ops, sizeof pci_root_ops);
34094 pci_soc_mode = 1;
34095 /* Continue with standard init */
34096 return 1;
34097 diff --git a/arch/x86/pci/irq.c b/arch/x86/pci/irq.c
34098 index 372e9b8..e775a6c 100644
34099 --- a/arch/x86/pci/irq.c
34100 +++ b/arch/x86/pci/irq.c
34101 @@ -50,7 +50,7 @@ struct irq_router {
34102 struct irq_router_handler {
34103 u16 vendor;
34104 int (*probe)(struct irq_router *r, struct pci_dev *router, u16 device);
34105 -};
34106 +} __do_const;
34107
34108 int (*pcibios_enable_irq)(struct pci_dev *dev) = pirq_enable_irq;
34109 void (*pcibios_disable_irq)(struct pci_dev *dev) = NULL;
34110 @@ -794,7 +794,7 @@ static __init int pico_router_probe(struct irq_router *r, struct pci_dev *router
34111 return 0;
34112 }
34113
34114 -static __initdata struct irq_router_handler pirq_routers[] = {
34115 +static __initconst const struct irq_router_handler pirq_routers[] = {
34116 { PCI_VENDOR_ID_INTEL, intel_router_probe },
34117 { PCI_VENDOR_ID_AL, ali_router_probe },
34118 { PCI_VENDOR_ID_ITE, ite_router_probe },
34119 @@ -821,7 +821,7 @@ static struct pci_dev *pirq_router_dev;
34120 static void __init pirq_find_router(struct irq_router *r)
34121 {
34122 struct irq_routing_table *rt = pirq_table;
34123 - struct irq_router_handler *h;
34124 + const struct irq_router_handler *h;
34125
34126 #ifdef CONFIG_PCI_BIOS
34127 if (!rt->signature) {
34128 @@ -1094,7 +1094,7 @@ static int __init fix_acer_tm360_irqrouting(const struct dmi_system_id *d)
34129 return 0;
34130 }
34131
34132 -static struct dmi_system_id __initdata pciirq_dmi_table[] = {
34133 +static const struct dmi_system_id __initconst pciirq_dmi_table[] = {
34134 {
34135 .callback = fix_broken_hp_bios_irq9,
34136 .ident = "HP Pavilion N5400 Series Laptop",
34137 diff --git a/arch/x86/pci/pcbios.c b/arch/x86/pci/pcbios.c
34138 index c77b24a..c979855 100644
34139 --- a/arch/x86/pci/pcbios.c
34140 +++ b/arch/x86/pci/pcbios.c
34141 @@ -79,7 +79,7 @@ union bios32 {
34142 static struct {
34143 unsigned long address;
34144 unsigned short segment;
34145 -} bios32_indirect = { 0, __KERNEL_CS };
34146 +} bios32_indirect __read_only = { 0, __PCIBIOS_CS };
34147
34148 /*
34149 * Returns the entry point for the given service, NULL on error
34150 @@ -92,37 +92,80 @@ static unsigned long bios32_service(unsigned long service)
34151 unsigned long length; /* %ecx */
34152 unsigned long entry; /* %edx */
34153 unsigned long flags;
34154 + struct desc_struct d, *gdt;
34155
34156 local_irq_save(flags);
34157 - __asm__("lcall *(%%edi); cld"
34158 +
34159 + gdt = get_cpu_gdt_table(smp_processor_id());
34160 +
34161 + pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x9B, 0xC);
34162 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
34163 + pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x93, 0xC);
34164 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
34165 +
34166 + __asm__("movw %w7, %%ds; lcall *(%%edi); push %%ss; pop %%ds; cld"
34167 : "=a" (return_code),
34168 "=b" (address),
34169 "=c" (length),
34170 "=d" (entry)
34171 : "0" (service),
34172 "1" (0),
34173 - "D" (&bios32_indirect));
34174 + "D" (&bios32_indirect),
34175 + "r"(__PCIBIOS_DS)
34176 + : "memory");
34177 +
34178 + pax_open_kernel();
34179 + gdt[GDT_ENTRY_PCIBIOS_CS].a = 0;
34180 + gdt[GDT_ENTRY_PCIBIOS_CS].b = 0;
34181 + gdt[GDT_ENTRY_PCIBIOS_DS].a = 0;
34182 + gdt[GDT_ENTRY_PCIBIOS_DS].b = 0;
34183 + pax_close_kernel();
34184 +
34185 local_irq_restore(flags);
34186
34187 switch (return_code) {
34188 - case 0:
34189 - return address + entry;
34190 - case 0x80: /* Not present */
34191 - printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
34192 - return 0;
34193 - default: /* Shouldn't happen */
34194 - printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
34195 - service, return_code);
34196 + case 0: {
34197 + int cpu;
34198 + unsigned char flags;
34199 +
34200 + printk(KERN_INFO "bios32_service: base:%08lx length:%08lx entry:%08lx\n", address, length, entry);
34201 + if (address >= 0xFFFF0 || length > 0x100000 - address || length <= entry) {
34202 + printk(KERN_WARNING "bios32_service: not valid\n");
34203 return 0;
34204 + }
34205 + address = address + PAGE_OFFSET;
34206 + length += 16UL; /* some BIOSs underreport this... */
34207 + flags = 4;
34208 + if (length >= 64*1024*1024) {
34209 + length >>= PAGE_SHIFT;
34210 + flags |= 8;
34211 + }
34212 +
34213 + for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
34214 + gdt = get_cpu_gdt_table(cpu);
34215 + pack_descriptor(&d, address, length, 0x9b, flags);
34216 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
34217 + pack_descriptor(&d, address, length, 0x93, flags);
34218 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
34219 + }
34220 + return entry;
34221 + }
34222 + case 0x80: /* Not present */
34223 + printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
34224 + return 0;
34225 + default: /* Shouldn't happen */
34226 + printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
34227 + service, return_code);
34228 + return 0;
34229 }
34230 }
34231
34232 static struct {
34233 unsigned long address;
34234 unsigned short segment;
34235 -} pci_indirect = { 0, __KERNEL_CS };
34236 +} pci_indirect __read_only = { 0, __PCIBIOS_CS };
34237
34238 -static int pci_bios_present;
34239 +static int pci_bios_present __read_only;
34240
34241 static int check_pcibios(void)
34242 {
34243 @@ -131,11 +174,13 @@ static int check_pcibios(void)
34244 unsigned long flags, pcibios_entry;
34245
34246 if ((pcibios_entry = bios32_service(PCI_SERVICE))) {
34247 - pci_indirect.address = pcibios_entry + PAGE_OFFSET;
34248 + pci_indirect.address = pcibios_entry;
34249
34250 local_irq_save(flags);
34251 - __asm__(
34252 - "lcall *(%%edi); cld\n\t"
34253 + __asm__("movw %w6, %%ds\n\t"
34254 + "lcall *%%ss:(%%edi); cld\n\t"
34255 + "push %%ss\n\t"
34256 + "pop %%ds\n\t"
34257 "jc 1f\n\t"
34258 "xor %%ah, %%ah\n"
34259 "1:"
34260 @@ -144,7 +189,8 @@ static int check_pcibios(void)
34261 "=b" (ebx),
34262 "=c" (ecx)
34263 : "1" (PCIBIOS_PCI_BIOS_PRESENT),
34264 - "D" (&pci_indirect)
34265 + "D" (&pci_indirect),
34266 + "r" (__PCIBIOS_DS)
34267 : "memory");
34268 local_irq_restore(flags);
34269
34270 @@ -189,7 +235,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
34271
34272 switch (len) {
34273 case 1:
34274 - __asm__("lcall *(%%esi); cld\n\t"
34275 + __asm__("movw %w6, %%ds\n\t"
34276 + "lcall *%%ss:(%%esi); cld\n\t"
34277 + "push %%ss\n\t"
34278 + "pop %%ds\n\t"
34279 "jc 1f\n\t"
34280 "xor %%ah, %%ah\n"
34281 "1:"
34282 @@ -198,7 +247,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
34283 : "1" (PCIBIOS_READ_CONFIG_BYTE),
34284 "b" (bx),
34285 "D" ((long)reg),
34286 - "S" (&pci_indirect));
34287 + "S" (&pci_indirect),
34288 + "r" (__PCIBIOS_DS));
34289 /*
34290 * Zero-extend the result beyond 8 bits, do not trust the
34291 * BIOS having done it:
34292 @@ -206,7 +256,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
34293 *value &= 0xff;
34294 break;
34295 case 2:
34296 - __asm__("lcall *(%%esi); cld\n\t"
34297 + __asm__("movw %w6, %%ds\n\t"
34298 + "lcall *%%ss:(%%esi); cld\n\t"
34299 + "push %%ss\n\t"
34300 + "pop %%ds\n\t"
34301 "jc 1f\n\t"
34302 "xor %%ah, %%ah\n"
34303 "1:"
34304 @@ -215,7 +268,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
34305 : "1" (PCIBIOS_READ_CONFIG_WORD),
34306 "b" (bx),
34307 "D" ((long)reg),
34308 - "S" (&pci_indirect));
34309 + "S" (&pci_indirect),
34310 + "r" (__PCIBIOS_DS));
34311 /*
34312 * Zero-extend the result beyond 16 bits, do not trust the
34313 * BIOS having done it:
34314 @@ -223,7 +277,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
34315 *value &= 0xffff;
34316 break;
34317 case 4:
34318 - __asm__("lcall *(%%esi); cld\n\t"
34319 + __asm__("movw %w6, %%ds\n\t"
34320 + "lcall *%%ss:(%%esi); cld\n\t"
34321 + "push %%ss\n\t"
34322 + "pop %%ds\n\t"
34323 "jc 1f\n\t"
34324 "xor %%ah, %%ah\n"
34325 "1:"
34326 @@ -232,7 +289,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
34327 : "1" (PCIBIOS_READ_CONFIG_DWORD),
34328 "b" (bx),
34329 "D" ((long)reg),
34330 - "S" (&pci_indirect));
34331 + "S" (&pci_indirect),
34332 + "r" (__PCIBIOS_DS));
34333 break;
34334 }
34335
34336 @@ -256,7 +314,10 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
34337
34338 switch (len) {
34339 case 1:
34340 - __asm__("lcall *(%%esi); cld\n\t"
34341 + __asm__("movw %w6, %%ds\n\t"
34342 + "lcall *%%ss:(%%esi); cld\n\t"
34343 + "push %%ss\n\t"
34344 + "pop %%ds\n\t"
34345 "jc 1f\n\t"
34346 "xor %%ah, %%ah\n"
34347 "1:"
34348 @@ -265,10 +326,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
34349 "c" (value),
34350 "b" (bx),
34351 "D" ((long)reg),
34352 - "S" (&pci_indirect));
34353 + "S" (&pci_indirect),
34354 + "r" (__PCIBIOS_DS));
34355 break;
34356 case 2:
34357 - __asm__("lcall *(%%esi); cld\n\t"
34358 + __asm__("movw %w6, %%ds\n\t"
34359 + "lcall *%%ss:(%%esi); cld\n\t"
34360 + "push %%ss\n\t"
34361 + "pop %%ds\n\t"
34362 "jc 1f\n\t"
34363 "xor %%ah, %%ah\n"
34364 "1:"
34365 @@ -277,10 +342,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
34366 "c" (value),
34367 "b" (bx),
34368 "D" ((long)reg),
34369 - "S" (&pci_indirect));
34370 + "S" (&pci_indirect),
34371 + "r" (__PCIBIOS_DS));
34372 break;
34373 case 4:
34374 - __asm__("lcall *(%%esi); cld\n\t"
34375 + __asm__("movw %w6, %%ds\n\t"
34376 + "lcall *%%ss:(%%esi); cld\n\t"
34377 + "push %%ss\n\t"
34378 + "pop %%ds\n\t"
34379 "jc 1f\n\t"
34380 "xor %%ah, %%ah\n"
34381 "1:"
34382 @@ -289,7 +358,8 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
34383 "c" (value),
34384 "b" (bx),
34385 "D" ((long)reg),
34386 - "S" (&pci_indirect));
34387 + "S" (&pci_indirect),
34388 + "r" (__PCIBIOS_DS));
34389 break;
34390 }
34391
34392 @@ -394,10 +464,13 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
34393
34394 DBG("PCI: Fetching IRQ routing table... ");
34395 __asm__("push %%es\n\t"
34396 + "movw %w8, %%ds\n\t"
34397 "push %%ds\n\t"
34398 "pop %%es\n\t"
34399 - "lcall *(%%esi); cld\n\t"
34400 + "lcall *%%ss:(%%esi); cld\n\t"
34401 "pop %%es\n\t"
34402 + "push %%ss\n\t"
34403 + "pop %%ds\n"
34404 "jc 1f\n\t"
34405 "xor %%ah, %%ah\n"
34406 "1:"
34407 @@ -408,7 +481,8 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
34408 "1" (0),
34409 "D" ((long) &opt),
34410 "S" (&pci_indirect),
34411 - "m" (opt)
34412 + "m" (opt),
34413 + "r" (__PCIBIOS_DS)
34414 : "memory");
34415 DBG("OK ret=%d, size=%d, map=%x\n", ret, opt.size, map);
34416 if (ret & 0xff00)
34417 @@ -432,7 +506,10 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
34418 {
34419 int ret;
34420
34421 - __asm__("lcall *(%%esi); cld\n\t"
34422 + __asm__("movw %w5, %%ds\n\t"
34423 + "lcall *%%ss:(%%esi); cld\n\t"
34424 + "push %%ss\n\t"
34425 + "pop %%ds\n"
34426 "jc 1f\n\t"
34427 "xor %%ah, %%ah\n"
34428 "1:"
34429 @@ -440,7 +517,8 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
34430 : "0" (PCIBIOS_SET_PCI_HW_INT),
34431 "b" ((dev->bus->number << 8) | dev->devfn),
34432 "c" ((irq << 8) | (pin + 10)),
34433 - "S" (&pci_indirect));
34434 + "S" (&pci_indirect),
34435 + "r" (__PCIBIOS_DS));
34436 return !(ret & 0xff00);
34437 }
34438 EXPORT_SYMBOL(pcibios_set_irq_routing);
34439 diff --git a/arch/x86/platform/efi/efi_32.c b/arch/x86/platform/efi/efi_32.c
34440 index 40e4469..d915bf9 100644
34441 --- a/arch/x86/platform/efi/efi_32.c
34442 +++ b/arch/x86/platform/efi/efi_32.c
34443 @@ -44,11 +44,22 @@ void efi_call_phys_prelog(void)
34444 {
34445 struct desc_ptr gdt_descr;
34446
34447 +#ifdef CONFIG_PAX_KERNEXEC
34448 + struct desc_struct d;
34449 +#endif
34450 +
34451 local_irq_save(efi_rt_eflags);
34452
34453 load_cr3(initial_page_table);
34454 __flush_tlb_all();
34455
34456 +#ifdef CONFIG_PAX_KERNEXEC
34457 + pack_descriptor(&d, 0, 0xFFFFF, 0x9B, 0xC);
34458 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
34459 + pack_descriptor(&d, 0, 0xFFFFF, 0x93, 0xC);
34460 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
34461 +#endif
34462 +
34463 gdt_descr.address = __pa(get_cpu_gdt_table(0));
34464 gdt_descr.size = GDT_SIZE - 1;
34465 load_gdt(&gdt_descr);
34466 @@ -58,11 +69,24 @@ void efi_call_phys_epilog(void)
34467 {
34468 struct desc_ptr gdt_descr;
34469
34470 +#ifdef CONFIG_PAX_KERNEXEC
34471 + struct desc_struct d;
34472 +
34473 + memset(&d, 0, sizeof d);
34474 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
34475 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
34476 +#endif
34477 +
34478 gdt_descr.address = (unsigned long)get_cpu_gdt_table(0);
34479 gdt_descr.size = GDT_SIZE - 1;
34480 load_gdt(&gdt_descr);
34481
34482 +#ifdef CONFIG_PAX_PER_CPU_PGD
34483 + load_cr3(get_cpu_pgd(smp_processor_id(), kernel));
34484 +#else
34485 load_cr3(swapper_pg_dir);
34486 +#endif
34487 +
34488 __flush_tlb_all();
34489
34490 local_irq_restore(efi_rt_eflags);
34491 diff --git a/arch/x86/platform/efi/efi_64.c b/arch/x86/platform/efi/efi_64.c
34492 index 39a0e7f1..872396e 100644
34493 --- a/arch/x86/platform/efi/efi_64.c
34494 +++ b/arch/x86/platform/efi/efi_64.c
34495 @@ -76,6 +76,11 @@ void __init efi_call_phys_prelog(void)
34496 vaddress = (unsigned long)__va(pgd * PGDIR_SIZE);
34497 set_pgd(pgd_offset_k(pgd * PGDIR_SIZE), *pgd_offset_k(vaddress));
34498 }
34499 +
34500 +#ifdef CONFIG_PAX_PER_CPU_PGD
34501 + load_cr3(swapper_pg_dir);
34502 +#endif
34503 +
34504 __flush_tlb_all();
34505 }
34506
34507 @@ -89,6 +94,11 @@ void __init efi_call_phys_epilog(void)
34508 for (pgd = 0; pgd < n_pgds; pgd++)
34509 set_pgd(pgd_offset_k(pgd * PGDIR_SIZE), save_pgd[pgd]);
34510 kfree(save_pgd);
34511 +
34512 +#ifdef CONFIG_PAX_PER_CPU_PGD
34513 + load_cr3(get_cpu_pgd(smp_processor_id(), kernel));
34514 +#endif
34515 +
34516 __flush_tlb_all();
34517 local_irq_restore(efi_flags);
34518 early_code_mapping_set_exec(0);
34519 diff --git a/arch/x86/platform/efi/efi_stub_32.S b/arch/x86/platform/efi/efi_stub_32.S
34520 index fbe66e6..eae5e38 100644
34521 --- a/arch/x86/platform/efi/efi_stub_32.S
34522 +++ b/arch/x86/platform/efi/efi_stub_32.S
34523 @@ -6,7 +6,9 @@
34524 */
34525
34526 #include <linux/linkage.h>
34527 +#include <linux/init.h>
34528 #include <asm/page_types.h>
34529 +#include <asm/segment.h>
34530
34531 /*
34532 * efi_call_phys(void *, ...) is a function with variable parameters.
34533 @@ -20,7 +22,7 @@
34534 * service functions will comply with gcc calling convention, too.
34535 */
34536
34537 -.text
34538 +__INIT
34539 ENTRY(efi_call_phys)
34540 /*
34541 * 0. The function can only be called in Linux kernel. So CS has been
34542 @@ -36,10 +38,24 @@ ENTRY(efi_call_phys)
34543 * The mapping of lower virtual memory has been created in prelog and
34544 * epilog.
34545 */
34546 - movl $1f, %edx
34547 - subl $__PAGE_OFFSET, %edx
34548 - jmp *%edx
34549 +#ifdef CONFIG_PAX_KERNEXEC
34550 + movl $(__KERNEXEC_EFI_DS), %edx
34551 + mov %edx, %ds
34552 + mov %edx, %es
34553 + mov %edx, %ss
34554 + addl $2f,(1f)
34555 + ljmp *(1f)
34556 +
34557 +__INITDATA
34558 +1: .long __LOAD_PHYSICAL_ADDR, __KERNEXEC_EFI_CS
34559 +.previous
34560 +
34561 +2:
34562 + subl $2b,(1b)
34563 +#else
34564 + jmp 1f-__PAGE_OFFSET
34565 1:
34566 +#endif
34567
34568 /*
34569 * 2. Now on the top of stack is the return
34570 @@ -47,14 +63,8 @@ ENTRY(efi_call_phys)
34571 * parameter 2, ..., param n. To make things easy, we save the return
34572 * address of efi_call_phys in a global variable.
34573 */
34574 - popl %edx
34575 - movl %edx, saved_return_addr
34576 - /* get the function pointer into ECX*/
34577 - popl %ecx
34578 - movl %ecx, efi_rt_function_ptr
34579 - movl $2f, %edx
34580 - subl $__PAGE_OFFSET, %edx
34581 - pushl %edx
34582 + popl (saved_return_addr)
34583 + popl (efi_rt_function_ptr)
34584
34585 /*
34586 * 3. Clear PG bit in %CR0.
34587 @@ -73,9 +83,8 @@ ENTRY(efi_call_phys)
34588 /*
34589 * 5. Call the physical function.
34590 */
34591 - jmp *%ecx
34592 + call *(efi_rt_function_ptr-__PAGE_OFFSET)
34593
34594 -2:
34595 /*
34596 * 6. After EFI runtime service returns, control will return to
34597 * following instruction. We'd better readjust stack pointer first.
34598 @@ -88,35 +97,36 @@ ENTRY(efi_call_phys)
34599 movl %cr0, %edx
34600 orl $0x80000000, %edx
34601 movl %edx, %cr0
34602 - jmp 1f
34603 -1:
34604 +
34605 /*
34606 * 8. Now restore the virtual mode from flat mode by
34607 * adding EIP with PAGE_OFFSET.
34608 */
34609 - movl $1f, %edx
34610 - jmp *%edx
34611 +#ifdef CONFIG_PAX_KERNEXEC
34612 + movl $(__KERNEL_DS), %edx
34613 + mov %edx, %ds
34614 + mov %edx, %es
34615 + mov %edx, %ss
34616 + ljmp $(__KERNEL_CS),$1f
34617 +#else
34618 + jmp 1f+__PAGE_OFFSET
34619 +#endif
34620 1:
34621
34622 /*
34623 * 9. Balance the stack. And because EAX contain the return value,
34624 * we'd better not clobber it.
34625 */
34626 - leal efi_rt_function_ptr, %edx
34627 - movl (%edx), %ecx
34628 - pushl %ecx
34629 + pushl (efi_rt_function_ptr)
34630
34631 /*
34632 - * 10. Push the saved return address onto the stack and return.
34633 + * 10. Return to the saved return address.
34634 */
34635 - leal saved_return_addr, %edx
34636 - movl (%edx), %ecx
34637 - pushl %ecx
34638 - ret
34639 + jmpl *(saved_return_addr)
34640 ENDPROC(efi_call_phys)
34641 .previous
34642
34643 -.data
34644 +__INITDATA
34645 saved_return_addr:
34646 .long 0
34647 efi_rt_function_ptr:
34648 diff --git a/arch/x86/platform/efi/efi_stub_64.S b/arch/x86/platform/efi/efi_stub_64.S
34649 index 4c07cca..2c8427d 100644
34650 --- a/arch/x86/platform/efi/efi_stub_64.S
34651 +++ b/arch/x86/platform/efi/efi_stub_64.S
34652 @@ -7,6 +7,7 @@
34653 */
34654
34655 #include <linux/linkage.h>
34656 +#include <asm/alternative-asm.h>
34657
34658 #define SAVE_XMM \
34659 mov %rsp, %rax; \
34660 @@ -40,6 +41,7 @@ ENTRY(efi_call0)
34661 call *%rdi
34662 addq $32, %rsp
34663 RESTORE_XMM
34664 + pax_force_retaddr 0, 1
34665 ret
34666 ENDPROC(efi_call0)
34667
34668 @@ -50,6 +52,7 @@ ENTRY(efi_call1)
34669 call *%rdi
34670 addq $32, %rsp
34671 RESTORE_XMM
34672 + pax_force_retaddr 0, 1
34673 ret
34674 ENDPROC(efi_call1)
34675
34676 @@ -60,6 +63,7 @@ ENTRY(efi_call2)
34677 call *%rdi
34678 addq $32, %rsp
34679 RESTORE_XMM
34680 + pax_force_retaddr 0, 1
34681 ret
34682 ENDPROC(efi_call2)
34683
34684 @@ -71,6 +75,7 @@ ENTRY(efi_call3)
34685 call *%rdi
34686 addq $32, %rsp
34687 RESTORE_XMM
34688 + pax_force_retaddr 0, 1
34689 ret
34690 ENDPROC(efi_call3)
34691
34692 @@ -83,6 +88,7 @@ ENTRY(efi_call4)
34693 call *%rdi
34694 addq $32, %rsp
34695 RESTORE_XMM
34696 + pax_force_retaddr 0, 1
34697 ret
34698 ENDPROC(efi_call4)
34699
34700 @@ -96,6 +102,7 @@ ENTRY(efi_call5)
34701 call *%rdi
34702 addq $48, %rsp
34703 RESTORE_XMM
34704 + pax_force_retaddr 0, 1
34705 ret
34706 ENDPROC(efi_call5)
34707
34708 @@ -112,5 +119,6 @@ ENTRY(efi_call6)
34709 call *%rdi
34710 addq $48, %rsp
34711 RESTORE_XMM
34712 + pax_force_retaddr 0, 1
34713 ret
34714 ENDPROC(efi_call6)
34715 diff --git a/arch/x86/platform/intel-mid/intel-mid.c b/arch/x86/platform/intel-mid/intel-mid.c
34716 index f90e290..435f0dd 100644
34717 --- a/arch/x86/platform/intel-mid/intel-mid.c
34718 +++ b/arch/x86/platform/intel-mid/intel-mid.c
34719 @@ -65,9 +65,10 @@ static void intel_mid_power_off(void)
34720 {
34721 }
34722
34723 -static void intel_mid_reboot(void)
34724 +static void __noreturn intel_mid_reboot(void)
34725 {
34726 intel_scu_ipc_simple_command(IPCMSG_COLD_BOOT, 0);
34727 + BUG();
34728 }
34729
34730 static unsigned long __init intel_mid_calibrate_tsc(void)
34731 diff --git a/arch/x86/platform/olpc/olpc_dt.c b/arch/x86/platform/olpc/olpc_dt.c
34732 index d6ee929..3637cb5 100644
34733 --- a/arch/x86/platform/olpc/olpc_dt.c
34734 +++ b/arch/x86/platform/olpc/olpc_dt.c
34735 @@ -156,7 +156,7 @@ void * __init prom_early_alloc(unsigned long size)
34736 return res;
34737 }
34738
34739 -static struct of_pdt_ops prom_olpc_ops __initdata = {
34740 +static struct of_pdt_ops prom_olpc_ops __initconst = {
34741 .nextprop = olpc_dt_nextprop,
34742 .getproplen = olpc_dt_getproplen,
34743 .getproperty = olpc_dt_getproperty,
34744 diff --git a/arch/x86/power/cpu.c b/arch/x86/power/cpu.c
34745 index 424f4c9..f2a2988 100644
34746 --- a/arch/x86/power/cpu.c
34747 +++ b/arch/x86/power/cpu.c
34748 @@ -137,11 +137,8 @@ static void do_fpu_end(void)
34749 static void fix_processor_context(void)
34750 {
34751 int cpu = smp_processor_id();
34752 - struct tss_struct *t = &per_cpu(init_tss, cpu);
34753 -#ifdef CONFIG_X86_64
34754 - struct desc_struct *desc = get_cpu_gdt_table(cpu);
34755 - tss_desc tss;
34756 -#endif
34757 + struct tss_struct *t = init_tss + cpu;
34758 +
34759 set_tss_desc(cpu, t); /*
34760 * This just modifies memory; should not be
34761 * necessary. But... This is necessary, because
34762 @@ -150,10 +147,6 @@ static void fix_processor_context(void)
34763 */
34764
34765 #ifdef CONFIG_X86_64
34766 - memcpy(&tss, &desc[GDT_ENTRY_TSS], sizeof(tss_desc));
34767 - tss.type = 0x9; /* The available 64-bit TSS (see AMD vol 2, pg 91 */
34768 - write_gdt_entry(desc, GDT_ENTRY_TSS, &tss, DESC_TSS);
34769 -
34770 syscall_init(); /* This sets MSR_*STAR and related */
34771 #endif
34772 load_TR_desc(); /* This does ltr */
34773 diff --git a/arch/x86/realmode/init.c b/arch/x86/realmode/init.c
34774 index a44f457..9140171 100644
34775 --- a/arch/x86/realmode/init.c
34776 +++ b/arch/x86/realmode/init.c
34777 @@ -70,7 +70,13 @@ void __init setup_real_mode(void)
34778 __va(real_mode_header->trampoline_header);
34779
34780 #ifdef CONFIG_X86_32
34781 - trampoline_header->start = __pa_symbol(startup_32_smp);
34782 + trampoline_header->start = __pa_symbol(ktla_ktva(startup_32_smp));
34783 +
34784 +#ifdef CONFIG_PAX_KERNEXEC
34785 + trampoline_header->start -= LOAD_PHYSICAL_ADDR;
34786 +#endif
34787 +
34788 + trampoline_header->boot_cs = __BOOT_CS;
34789 trampoline_header->gdt_limit = __BOOT_DS + 7;
34790 trampoline_header->gdt_base = __pa_symbol(boot_gdt);
34791 #else
34792 @@ -86,7 +92,7 @@ void __init setup_real_mode(void)
34793 *trampoline_cr4_features = read_cr4();
34794
34795 trampoline_pgd = (u64 *) __va(real_mode_header->trampoline_pgd);
34796 - trampoline_pgd[0] = init_level4_pgt[pgd_index(__PAGE_OFFSET)].pgd;
34797 + trampoline_pgd[0] = init_level4_pgt[pgd_index(__PAGE_OFFSET)].pgd & ~_PAGE_NX;
34798 trampoline_pgd[511] = init_level4_pgt[511].pgd;
34799 #endif
34800 }
34801 diff --git a/arch/x86/realmode/rm/Makefile b/arch/x86/realmode/rm/Makefile
34802 index 9cac825..4890b25 100644
34803 --- a/arch/x86/realmode/rm/Makefile
34804 +++ b/arch/x86/realmode/rm/Makefile
34805 @@ -79,5 +79,8 @@ KBUILD_CFLAGS := $(LINUXINCLUDE) -m32 -g -Os -D_SETUP -D__KERNEL__ -D_WAKEUP \
34806 $(call cc-option, -fno-unit-at-a-time)) \
34807 $(call cc-option, -fno-stack-protector) \
34808 $(call cc-option, -mpreferred-stack-boundary=2)
34809 +ifdef CONSTIFY_PLUGIN
34810 +KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
34811 +endif
34812 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
34813 GCOV_PROFILE := n
34814 diff --git a/arch/x86/realmode/rm/header.S b/arch/x86/realmode/rm/header.S
34815 index a28221d..93c40f1 100644
34816 --- a/arch/x86/realmode/rm/header.S
34817 +++ b/arch/x86/realmode/rm/header.S
34818 @@ -30,7 +30,9 @@ GLOBAL(real_mode_header)
34819 #endif
34820 /* APM/BIOS reboot */
34821 .long pa_machine_real_restart_asm
34822 -#ifdef CONFIG_X86_64
34823 +#ifdef CONFIG_X86_32
34824 + .long __KERNEL_CS
34825 +#else
34826 .long __KERNEL32_CS
34827 #endif
34828 END(real_mode_header)
34829 diff --git a/arch/x86/realmode/rm/trampoline_32.S b/arch/x86/realmode/rm/trampoline_32.S
34830 index c1b2791..f9e31c7 100644
34831 --- a/arch/x86/realmode/rm/trampoline_32.S
34832 +++ b/arch/x86/realmode/rm/trampoline_32.S
34833 @@ -25,6 +25,12 @@
34834 #include <asm/page_types.h>
34835 #include "realmode.h"
34836
34837 +#ifdef CONFIG_PAX_KERNEXEC
34838 +#define ta(X) (X)
34839 +#else
34840 +#define ta(X) (pa_ ## X)
34841 +#endif
34842 +
34843 .text
34844 .code16
34845
34846 @@ -39,8 +45,6 @@ ENTRY(trampoline_start)
34847
34848 cli # We should be safe anyway
34849
34850 - movl tr_start, %eax # where we need to go
34851 -
34852 movl $0xA5A5A5A5, trampoline_status
34853 # write marker for master knows we're running
34854
34855 @@ -56,7 +60,7 @@ ENTRY(trampoline_start)
34856 movw $1, %dx # protected mode (PE) bit
34857 lmsw %dx # into protected mode
34858
34859 - ljmpl $__BOOT_CS, $pa_startup_32
34860 + ljmpl *(trampoline_header)
34861
34862 .section ".text32","ax"
34863 .code32
34864 @@ -67,7 +71,7 @@ ENTRY(startup_32) # note: also used from wakeup_asm.S
34865 .balign 8
34866 GLOBAL(trampoline_header)
34867 tr_start: .space 4
34868 - tr_gdt_pad: .space 2
34869 + tr_boot_cs: .space 2
34870 tr_gdt: .space 6
34871 END(trampoline_header)
34872
34873 diff --git a/arch/x86/realmode/rm/trampoline_64.S b/arch/x86/realmode/rm/trampoline_64.S
34874 index bb360dc..d0fd8f8 100644
34875 --- a/arch/x86/realmode/rm/trampoline_64.S
34876 +++ b/arch/x86/realmode/rm/trampoline_64.S
34877 @@ -94,6 +94,7 @@ ENTRY(startup_32)
34878 movl %edx, %gs
34879
34880 movl pa_tr_cr4, %eax
34881 + andl $~X86_CR4_PCIDE, %eax
34882 movl %eax, %cr4 # Enable PAE mode
34883
34884 # Setup trampoline 4 level pagetables
34885 @@ -107,7 +108,7 @@ ENTRY(startup_32)
34886 wrmsr
34887
34888 # Enable paging and in turn activate Long Mode
34889 - movl $(X86_CR0_PG | X86_CR0_WP | X86_CR0_PE), %eax
34890 + movl $(X86_CR0_PG | X86_CR0_PE), %eax
34891 movl %eax, %cr0
34892
34893 /*
34894 diff --git a/arch/x86/tools/Makefile b/arch/x86/tools/Makefile
34895 index e812034..c747134 100644
34896 --- a/arch/x86/tools/Makefile
34897 +++ b/arch/x86/tools/Makefile
34898 @@ -37,7 +37,7 @@ $(obj)/test_get_len.o: $(srctree)/arch/x86/lib/insn.c $(srctree)/arch/x86/lib/in
34899
34900 $(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
34901
34902 -HOST_EXTRACFLAGS += -I$(srctree)/tools/include
34903 +HOST_EXTRACFLAGS += -I$(srctree)/tools/include -ggdb
34904 hostprogs-y += relocs
34905 relocs-objs := relocs_32.o relocs_64.o relocs_common.o
34906 relocs: $(obj)/relocs
34907 diff --git a/arch/x86/tools/relocs.c b/arch/x86/tools/relocs.c
34908 index f7bab68..b6d9886 100644
34909 --- a/arch/x86/tools/relocs.c
34910 +++ b/arch/x86/tools/relocs.c
34911 @@ -1,5 +1,7 @@
34912 /* This is included from relocs_32/64.c */
34913
34914 +#include "../../../include/generated/autoconf.h"
34915 +
34916 #define ElfW(type) _ElfW(ELF_BITS, type)
34917 #define _ElfW(bits, type) __ElfW(bits, type)
34918 #define __ElfW(bits, type) Elf##bits##_##type
34919 @@ -11,6 +13,7 @@
34920 #define Elf_Sym ElfW(Sym)
34921
34922 static Elf_Ehdr ehdr;
34923 +static Elf_Phdr *phdr;
34924
34925 struct relocs {
34926 uint32_t *offset;
34927 @@ -383,9 +386,39 @@ static void read_ehdr(FILE *fp)
34928 }
34929 }
34930
34931 +static void read_phdrs(FILE *fp)
34932 +{
34933 + unsigned int i;
34934 +
34935 + phdr = calloc(ehdr.e_phnum, sizeof(Elf_Phdr));
34936 + if (!phdr) {
34937 + die("Unable to allocate %d program headers\n",
34938 + ehdr.e_phnum);
34939 + }
34940 + if (fseek(fp, ehdr.e_phoff, SEEK_SET) < 0) {
34941 + die("Seek to %d failed: %s\n",
34942 + ehdr.e_phoff, strerror(errno));
34943 + }
34944 + if (fread(phdr, sizeof(*phdr), ehdr.e_phnum, fp) != ehdr.e_phnum) {
34945 + die("Cannot read ELF program headers: %s\n",
34946 + strerror(errno));
34947 + }
34948 + for(i = 0; i < ehdr.e_phnum; i++) {
34949 + phdr[i].p_type = elf_word_to_cpu(phdr[i].p_type);
34950 + phdr[i].p_offset = elf_off_to_cpu(phdr[i].p_offset);
34951 + phdr[i].p_vaddr = elf_addr_to_cpu(phdr[i].p_vaddr);
34952 + phdr[i].p_paddr = elf_addr_to_cpu(phdr[i].p_paddr);
34953 + phdr[i].p_filesz = elf_word_to_cpu(phdr[i].p_filesz);
34954 + phdr[i].p_memsz = elf_word_to_cpu(phdr[i].p_memsz);
34955 + phdr[i].p_flags = elf_word_to_cpu(phdr[i].p_flags);
34956 + phdr[i].p_align = elf_word_to_cpu(phdr[i].p_align);
34957 + }
34958 +
34959 +}
34960 +
34961 static void read_shdrs(FILE *fp)
34962 {
34963 - int i;
34964 + unsigned int i;
34965 Elf_Shdr shdr;
34966
34967 secs = calloc(ehdr.e_shnum, sizeof(struct section));
34968 @@ -420,7 +453,7 @@ static void read_shdrs(FILE *fp)
34969
34970 static void read_strtabs(FILE *fp)
34971 {
34972 - int i;
34973 + unsigned int i;
34974 for (i = 0; i < ehdr.e_shnum; i++) {
34975 struct section *sec = &secs[i];
34976 if (sec->shdr.sh_type != SHT_STRTAB) {
34977 @@ -445,7 +478,7 @@ static void read_strtabs(FILE *fp)
34978
34979 static void read_symtabs(FILE *fp)
34980 {
34981 - int i,j;
34982 + unsigned int i,j;
34983 for (i = 0; i < ehdr.e_shnum; i++) {
34984 struct section *sec = &secs[i];
34985 if (sec->shdr.sh_type != SHT_SYMTAB) {
34986 @@ -476,9 +509,11 @@ static void read_symtabs(FILE *fp)
34987 }
34988
34989
34990 -static void read_relocs(FILE *fp)
34991 +static void read_relocs(FILE *fp, int use_real_mode)
34992 {
34993 - int i,j;
34994 + unsigned int i,j;
34995 + uint32_t base;
34996 +
34997 for (i = 0; i < ehdr.e_shnum; i++) {
34998 struct section *sec = &secs[i];
34999 if (sec->shdr.sh_type != SHT_REL_TYPE) {
35000 @@ -498,9 +533,22 @@ static void read_relocs(FILE *fp)
35001 die("Cannot read symbol table: %s\n",
35002 strerror(errno));
35003 }
35004 + base = 0;
35005 +
35006 +#ifdef CONFIG_X86_32
35007 + for (j = 0; !use_real_mode && j < ehdr.e_phnum; j++) {
35008 + if (phdr[j].p_type != PT_LOAD )
35009 + continue;
35010 + 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)
35011 + continue;
35012 + base = CONFIG_PAGE_OFFSET + phdr[j].p_paddr - phdr[j].p_vaddr;
35013 + break;
35014 + }
35015 +#endif
35016 +
35017 for (j = 0; j < sec->shdr.sh_size/sizeof(Elf_Rel); j++) {
35018 Elf_Rel *rel = &sec->reltab[j];
35019 - rel->r_offset = elf_addr_to_cpu(rel->r_offset);
35020 + rel->r_offset = elf_addr_to_cpu(rel->r_offset) + base;
35021 rel->r_info = elf_xword_to_cpu(rel->r_info);
35022 #if (SHT_REL_TYPE == SHT_RELA)
35023 rel->r_addend = elf_xword_to_cpu(rel->r_addend);
35024 @@ -512,7 +560,7 @@ static void read_relocs(FILE *fp)
35025
35026 static void print_absolute_symbols(void)
35027 {
35028 - int i;
35029 + unsigned int i;
35030 const char *format;
35031
35032 if (ELF_BITS == 64)
35033 @@ -525,7 +573,7 @@ static void print_absolute_symbols(void)
35034 for (i = 0; i < ehdr.e_shnum; i++) {
35035 struct section *sec = &secs[i];
35036 char *sym_strtab;
35037 - int j;
35038 + unsigned int j;
35039
35040 if (sec->shdr.sh_type != SHT_SYMTAB) {
35041 continue;
35042 @@ -552,7 +600,7 @@ static void print_absolute_symbols(void)
35043
35044 static void print_absolute_relocs(void)
35045 {
35046 - int i, printed = 0;
35047 + unsigned int i, printed = 0;
35048 const char *format;
35049
35050 if (ELF_BITS == 64)
35051 @@ -565,7 +613,7 @@ static void print_absolute_relocs(void)
35052 struct section *sec_applies, *sec_symtab;
35053 char *sym_strtab;
35054 Elf_Sym *sh_symtab;
35055 - int j;
35056 + unsigned int j;
35057 if (sec->shdr.sh_type != SHT_REL_TYPE) {
35058 continue;
35059 }
35060 @@ -642,13 +690,13 @@ static void add_reloc(struct relocs *r, uint32_t offset)
35061 static void walk_relocs(int (*process)(struct section *sec, Elf_Rel *rel,
35062 Elf_Sym *sym, const char *symname))
35063 {
35064 - int i;
35065 + unsigned int i;
35066 /* Walk through the relocations */
35067 for (i = 0; i < ehdr.e_shnum; i++) {
35068 char *sym_strtab;
35069 Elf_Sym *sh_symtab;
35070 struct section *sec_applies, *sec_symtab;
35071 - int j;
35072 + unsigned int j;
35073 struct section *sec = &secs[i];
35074
35075 if (sec->shdr.sh_type != SHT_REL_TYPE) {
35076 @@ -812,6 +860,23 @@ static int do_reloc32(struct section *sec, Elf_Rel *rel, Elf_Sym *sym,
35077 {
35078 unsigned r_type = ELF32_R_TYPE(rel->r_info);
35079 int shn_abs = (sym->st_shndx == SHN_ABS) && !is_reloc(S_REL, symname);
35080 + char *sym_strtab = sec->link->link->strtab;
35081 +
35082 + /* Don't relocate actual per-cpu variables, they are absolute indices, not addresses */
35083 + if (!strcmp(sec_name(sym->st_shndx), ".data..percpu") && strcmp(sym_name(sym_strtab, sym), "__per_cpu_load"))
35084 + return 0;
35085 +
35086 +#ifdef CONFIG_PAX_KERNEXEC
35087 + /* Don't relocate actual code, they are relocated implicitly by the base address of KERNEL_CS */
35088 + if (!strcmp(sec_name(sym->st_shndx), ".text.end") && !strcmp(sym_name(sym_strtab, sym), "_etext"))
35089 + return 0;
35090 + if (!strcmp(sec_name(sym->st_shndx), ".init.text"))
35091 + return 0;
35092 + if (!strcmp(sec_name(sym->st_shndx), ".exit.text"))
35093 + return 0;
35094 + if (!strcmp(sec_name(sym->st_shndx), ".text") && strcmp(sym_name(sym_strtab, sym), "__LOAD_PHYSICAL_ADDR"))
35095 + return 0;
35096 +#endif
35097
35098 switch (r_type) {
35099 case R_386_NONE:
35100 @@ -950,7 +1015,7 @@ static int write32_as_text(uint32_t v, FILE *f)
35101
35102 static void emit_relocs(int as_text, int use_real_mode)
35103 {
35104 - int i;
35105 + unsigned int i;
35106 int (*write_reloc)(uint32_t, FILE *) = write32;
35107 int (*do_reloc)(struct section *sec, Elf_Rel *rel, Elf_Sym *sym,
35108 const char *symname);
35109 @@ -1026,10 +1091,11 @@ void process(FILE *fp, int use_real_mode, int as_text,
35110 {
35111 regex_init(use_real_mode);
35112 read_ehdr(fp);
35113 + read_phdrs(fp);
35114 read_shdrs(fp);
35115 read_strtabs(fp);
35116 read_symtabs(fp);
35117 - read_relocs(fp);
35118 + read_relocs(fp, use_real_mode);
35119 if (ELF_BITS == 64)
35120 percpu_init();
35121 if (show_absolute_syms) {
35122 diff --git a/arch/x86/um/tls_32.c b/arch/x86/um/tls_32.c
35123 index 80ffa5b..a33bd15 100644
35124 --- a/arch/x86/um/tls_32.c
35125 +++ b/arch/x86/um/tls_32.c
35126 @@ -260,7 +260,7 @@ out:
35127 if (unlikely(task == current &&
35128 !t->arch.tls_array[idx - GDT_ENTRY_TLS_MIN].flushed)) {
35129 printk(KERN_ERR "get_tls_entry: task with pid %d got here "
35130 - "without flushed TLS.", current->pid);
35131 + "without flushed TLS.", task_pid_nr(current));
35132 }
35133
35134 return 0;
35135 diff --git a/arch/x86/vdso/Makefile b/arch/x86/vdso/Makefile
35136 index fd14be1..e3c79c0 100644
35137 --- a/arch/x86/vdso/Makefile
35138 +++ b/arch/x86/vdso/Makefile
35139 @@ -181,7 +181,7 @@ quiet_cmd_vdso = VDSO $@
35140 -Wl,-T,$(filter %.lds,$^) $(filter %.o,$^) && \
35141 sh $(srctree)/$(src)/checkundef.sh '$(NM)' '$@'
35142
35143 -VDSO_LDFLAGS = -fPIC -shared $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
35144 +VDSO_LDFLAGS = -fPIC -shared -Wl,--no-undefined $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
35145 GCOV_PROFILE := n
35146
35147 #
35148 diff --git a/arch/x86/vdso/vdso32-setup.c b/arch/x86/vdso/vdso32-setup.c
35149 index d6bfb87..876ee18 100644
35150 --- a/arch/x86/vdso/vdso32-setup.c
35151 +++ b/arch/x86/vdso/vdso32-setup.c
35152 @@ -25,6 +25,7 @@
35153 #include <asm/tlbflush.h>
35154 #include <asm/vdso.h>
35155 #include <asm/proto.h>
35156 +#include <asm/mman.h>
35157
35158 enum {
35159 VDSO_DISABLED = 0,
35160 @@ -226,7 +227,7 @@ static inline void map_compat_vdso(int map)
35161 void enable_sep_cpu(void)
35162 {
35163 int cpu = get_cpu();
35164 - struct tss_struct *tss = &per_cpu(init_tss, cpu);
35165 + struct tss_struct *tss = init_tss + cpu;
35166
35167 if (!boot_cpu_has(X86_FEATURE_SEP)) {
35168 put_cpu();
35169 @@ -249,7 +250,7 @@ static int __init gate_vma_init(void)
35170 gate_vma.vm_start = FIXADDR_USER_START;
35171 gate_vma.vm_end = FIXADDR_USER_END;
35172 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
35173 - gate_vma.vm_page_prot = __P101;
35174 + gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
35175
35176 return 0;
35177 }
35178 @@ -330,14 +331,14 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
35179 if (compat)
35180 addr = VDSO_HIGH_BASE;
35181 else {
35182 - addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, 0);
35183 + addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, MAP_EXECUTABLE);
35184 if (IS_ERR_VALUE(addr)) {
35185 ret = addr;
35186 goto up_fail;
35187 }
35188 }
35189
35190 - current->mm->context.vdso = (void *)addr;
35191 + current->mm->context.vdso = addr;
35192
35193 if (compat_uses_vma || !compat) {
35194 /*
35195 @@ -353,11 +354,11 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
35196 }
35197
35198 current_thread_info()->sysenter_return =
35199 - VDSO32_SYMBOL(addr, SYSENTER_RETURN);
35200 + (__force void __user *)VDSO32_SYMBOL(addr, SYSENTER_RETURN);
35201
35202 up_fail:
35203 if (ret)
35204 - current->mm->context.vdso = NULL;
35205 + current->mm->context.vdso = 0;
35206
35207 up_write(&mm->mmap_sem);
35208
35209 @@ -404,8 +405,14 @@ __initcall(ia32_binfmt_init);
35210
35211 const char *arch_vma_name(struct vm_area_struct *vma)
35212 {
35213 - if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
35214 + if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
35215 return "[vdso]";
35216 +
35217 +#ifdef CONFIG_PAX_SEGMEXEC
35218 + if (vma->vm_mm && vma->vm_mirror && vma->vm_mirror->vm_start == vma->vm_mm->context.vdso)
35219 + return "[vdso]";
35220 +#endif
35221 +
35222 return NULL;
35223 }
35224
35225 @@ -415,7 +422,7 @@ struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
35226 * Check to see if the corresponding task was created in compat vdso
35227 * mode.
35228 */
35229 - if (mm && mm->context.vdso == (void *)VDSO_HIGH_BASE)
35230 + if (mm && mm->context.vdso == VDSO_HIGH_BASE)
35231 return &gate_vma;
35232 return NULL;
35233 }
35234 diff --git a/arch/x86/vdso/vma.c b/arch/x86/vdso/vma.c
35235 index 431e875..cbb23f3 100644
35236 --- a/arch/x86/vdso/vma.c
35237 +++ b/arch/x86/vdso/vma.c
35238 @@ -16,8 +16,6 @@
35239 #include <asm/vdso.h>
35240 #include <asm/page.h>
35241
35242 -unsigned int __read_mostly vdso_enabled = 1;
35243 -
35244 extern char vdso_start[], vdso_end[];
35245 extern unsigned short vdso_sync_cpuid;
35246
35247 @@ -141,7 +139,6 @@ static unsigned long vdso_addr(unsigned long start, unsigned len)
35248 * unaligned here as a result of stack start randomization.
35249 */
35250 addr = PAGE_ALIGN(addr);
35251 - addr = align_vdso_addr(addr);
35252
35253 return addr;
35254 }
35255 @@ -154,30 +151,31 @@ static int setup_additional_pages(struct linux_binprm *bprm,
35256 unsigned size)
35257 {
35258 struct mm_struct *mm = current->mm;
35259 - unsigned long addr;
35260 + unsigned long addr = 0;
35261 int ret;
35262
35263 - if (!vdso_enabled)
35264 - return 0;
35265 -
35266 down_write(&mm->mmap_sem);
35267 +
35268 +#ifdef CONFIG_PAX_RANDMMAP
35269 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
35270 +#endif
35271 +
35272 addr = vdso_addr(mm->start_stack, size);
35273 + addr = align_vdso_addr(addr);
35274 addr = get_unmapped_area(NULL, addr, size, 0, 0);
35275 if (IS_ERR_VALUE(addr)) {
35276 ret = addr;
35277 goto up_fail;
35278 }
35279
35280 - current->mm->context.vdso = (void *)addr;
35281 + mm->context.vdso = addr;
35282
35283 ret = install_special_mapping(mm, addr, size,
35284 VM_READ|VM_EXEC|
35285 VM_MAYREAD|VM_MAYWRITE|VM_MAYEXEC,
35286 pages);
35287 - if (ret) {
35288 - current->mm->context.vdso = NULL;
35289 - goto up_fail;
35290 - }
35291 + if (ret)
35292 + mm->context.vdso = 0;
35293
35294 up_fail:
35295 up_write(&mm->mmap_sem);
35296 @@ -197,10 +195,3 @@ int x32_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
35297 vdsox32_size);
35298 }
35299 #endif
35300 -
35301 -static __init int vdso_setup(char *s)
35302 -{
35303 - vdso_enabled = simple_strtoul(s, NULL, 0);
35304 - return 0;
35305 -}
35306 -__setup("vdso=", vdso_setup);
35307 diff --git a/arch/x86/xen/Kconfig b/arch/x86/xen/Kconfig
35308 index 1a3c765..3d2e8d1 100644
35309 --- a/arch/x86/xen/Kconfig
35310 +++ b/arch/x86/xen/Kconfig
35311 @@ -9,6 +9,7 @@ config XEN
35312 select XEN_HAVE_PVMMU
35313 depends on X86_64 || (X86_32 && X86_PAE && !X86_VISWS)
35314 depends on X86_TSC
35315 + depends on !GRKERNSEC_CONFIG_AUTO || GRKERNSEC_CONFIG_VIRT_XEN
35316 help
35317 This is the Linux Xen port. Enabling this will allow the
35318 kernel to boot in a paravirtualized environment under the
35319 diff --git a/arch/x86/xen/enlighten.c b/arch/x86/xen/enlighten.c
35320 index fa6ade7..73da73a5 100644
35321 --- a/arch/x86/xen/enlighten.c
35322 +++ b/arch/x86/xen/enlighten.c
35323 @@ -123,8 +123,6 @@ EXPORT_SYMBOL_GPL(xen_start_info);
35324
35325 struct shared_info xen_dummy_shared_info;
35326
35327 -void *xen_initial_gdt;
35328 -
35329 RESERVE_BRK(shared_info_page_brk, PAGE_SIZE);
35330 __read_mostly int xen_have_vector_callback;
35331 EXPORT_SYMBOL_GPL(xen_have_vector_callback);
35332 @@ -541,8 +539,7 @@ static void xen_load_gdt(const struct desc_ptr *dtr)
35333 {
35334 unsigned long va = dtr->address;
35335 unsigned int size = dtr->size + 1;
35336 - unsigned pages = (size + PAGE_SIZE - 1) / PAGE_SIZE;
35337 - unsigned long frames[pages];
35338 + unsigned long frames[65536 / PAGE_SIZE];
35339 int f;
35340
35341 /*
35342 @@ -590,8 +587,7 @@ static void __init xen_load_gdt_boot(const struct desc_ptr *dtr)
35343 {
35344 unsigned long va = dtr->address;
35345 unsigned int size = dtr->size + 1;
35346 - unsigned pages = (size + PAGE_SIZE - 1) / PAGE_SIZE;
35347 - unsigned long frames[pages];
35348 + unsigned long frames[(GDT_SIZE + PAGE_SIZE - 1) / PAGE_SIZE];
35349 int f;
35350
35351 /*
35352 @@ -599,7 +595,7 @@ static void __init xen_load_gdt_boot(const struct desc_ptr *dtr)
35353 * 8-byte entries, or 16 4k pages..
35354 */
35355
35356 - BUG_ON(size > 65536);
35357 + BUG_ON(size > GDT_SIZE);
35358 BUG_ON(va & ~PAGE_MASK);
35359
35360 for (f = 0; va < dtr->address + size; va += PAGE_SIZE, f++) {
35361 @@ -988,7 +984,7 @@ static u32 xen_safe_apic_wait_icr_idle(void)
35362 return 0;
35363 }
35364
35365 -static void set_xen_basic_apic_ops(void)
35366 +static void __init set_xen_basic_apic_ops(void)
35367 {
35368 apic->read = xen_apic_read;
35369 apic->write = xen_apic_write;
35370 @@ -1293,30 +1289,30 @@ static const struct pv_apic_ops xen_apic_ops __initconst = {
35371 #endif
35372 };
35373
35374 -static void xen_reboot(int reason)
35375 +static __noreturn void xen_reboot(int reason)
35376 {
35377 struct sched_shutdown r = { .reason = reason };
35378
35379 - if (HYPERVISOR_sched_op(SCHEDOP_shutdown, &r))
35380 - BUG();
35381 + HYPERVISOR_sched_op(SCHEDOP_shutdown, &r);
35382 + BUG();
35383 }
35384
35385 -static void xen_restart(char *msg)
35386 +static __noreturn void xen_restart(char *msg)
35387 {
35388 xen_reboot(SHUTDOWN_reboot);
35389 }
35390
35391 -static void xen_emergency_restart(void)
35392 +static __noreturn void xen_emergency_restart(void)
35393 {
35394 xen_reboot(SHUTDOWN_reboot);
35395 }
35396
35397 -static void xen_machine_halt(void)
35398 +static __noreturn void xen_machine_halt(void)
35399 {
35400 xen_reboot(SHUTDOWN_poweroff);
35401 }
35402
35403 -static void xen_machine_power_off(void)
35404 +static __noreturn void xen_machine_power_off(void)
35405 {
35406 if (pm_power_off)
35407 pm_power_off();
35408 @@ -1467,7 +1463,17 @@ asmlinkage void __init xen_start_kernel(void)
35409 __userpte_alloc_gfp &= ~__GFP_HIGHMEM;
35410
35411 /* Work out if we support NX */
35412 - x86_configure_nx();
35413 +#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
35414 + if ((cpuid_eax(0x80000000) & 0xffff0000) == 0x80000000 &&
35415 + (cpuid_edx(0x80000001) & (1U << (X86_FEATURE_NX & 31)))) {
35416 + unsigned l, h;
35417 +
35418 + __supported_pte_mask |= _PAGE_NX;
35419 + rdmsr(MSR_EFER, l, h);
35420 + l |= EFER_NX;
35421 + wrmsr(MSR_EFER, l, h);
35422 + }
35423 +#endif
35424
35425 xen_setup_features();
35426
35427 @@ -1498,13 +1504,6 @@ asmlinkage void __init xen_start_kernel(void)
35428
35429 machine_ops = xen_machine_ops;
35430
35431 - /*
35432 - * The only reliable way to retain the initial address of the
35433 - * percpu gdt_page is to remember it here, so we can go and
35434 - * mark it RW later, when the initial percpu area is freed.
35435 - */
35436 - xen_initial_gdt = &per_cpu(gdt_page, 0);
35437 -
35438 xen_smp_init();
35439
35440 #ifdef CONFIG_ACPI_NUMA
35441 diff --git a/arch/x86/xen/mmu.c b/arch/x86/xen/mmu.c
35442 index ce563be..7327d91 100644
35443 --- a/arch/x86/xen/mmu.c
35444 +++ b/arch/x86/xen/mmu.c
35445 @@ -379,7 +379,7 @@ static pteval_t pte_mfn_to_pfn(pteval_t val)
35446 return val;
35447 }
35448
35449 -static pteval_t pte_pfn_to_mfn(pteval_t val)
35450 +static pteval_t __intentional_overflow(-1) pte_pfn_to_mfn(pteval_t val)
35451 {
35452 if (val & _PAGE_PRESENT) {
35453 unsigned long pfn = (val & PTE_PFN_MASK) >> PAGE_SHIFT;
35454 @@ -1894,6 +1894,9 @@ void __init xen_setup_kernel_pagetable(pgd_t *pgd, unsigned long max_pfn)
35455 /* L3_k[510] -> level2_kernel_pgt
35456 * L3_i[511] -> level2_fixmap_pgt */
35457 convert_pfn_mfn(level3_kernel_pgt);
35458 + convert_pfn_mfn(level3_vmalloc_start_pgt);
35459 + convert_pfn_mfn(level3_vmalloc_end_pgt);
35460 + convert_pfn_mfn(level3_vmemmap_pgt);
35461
35462 /* We get [511][511] and have Xen's version of level2_kernel_pgt */
35463 l3 = m2v(pgd[pgd_index(__START_KERNEL_map)].pgd);
35464 @@ -1923,8 +1926,12 @@ void __init xen_setup_kernel_pagetable(pgd_t *pgd, unsigned long max_pfn)
35465 set_page_prot(init_level4_pgt, PAGE_KERNEL_RO);
35466 set_page_prot(level3_ident_pgt, PAGE_KERNEL_RO);
35467 set_page_prot(level3_kernel_pgt, PAGE_KERNEL_RO);
35468 + set_page_prot(level3_vmalloc_start_pgt, PAGE_KERNEL_RO);
35469 + set_page_prot(level3_vmalloc_end_pgt, PAGE_KERNEL_RO);
35470 + set_page_prot(level3_vmemmap_pgt, PAGE_KERNEL_RO);
35471 set_page_prot(level3_user_vsyscall, PAGE_KERNEL_RO);
35472 set_page_prot(level2_ident_pgt, PAGE_KERNEL_RO);
35473 + set_page_prot(level2_vmemmap_pgt, PAGE_KERNEL_RO);
35474 set_page_prot(level2_kernel_pgt, PAGE_KERNEL_RO);
35475 set_page_prot(level2_fixmap_pgt, PAGE_KERNEL_RO);
35476
35477 @@ -2108,6 +2115,7 @@ static void __init xen_post_allocator_init(void)
35478 pv_mmu_ops.set_pud = xen_set_pud;
35479 #if PAGETABLE_LEVELS == 4
35480 pv_mmu_ops.set_pgd = xen_set_pgd;
35481 + pv_mmu_ops.set_pgd_batched = xen_set_pgd;
35482 #endif
35483
35484 /* This will work as long as patching hasn't happened yet
35485 @@ -2186,6 +2194,7 @@ static const struct pv_mmu_ops xen_mmu_ops __initconst = {
35486 .pud_val = PV_CALLEE_SAVE(xen_pud_val),
35487 .make_pud = PV_CALLEE_SAVE(xen_make_pud),
35488 .set_pgd = xen_set_pgd_hyper,
35489 + .set_pgd_batched = xen_set_pgd_hyper,
35490
35491 .alloc_pud = xen_alloc_pmd_init,
35492 .release_pud = xen_release_pmd_init,
35493 diff --git a/arch/x86/xen/smp.c b/arch/x86/xen/smp.c
35494 index c36b325..b0f1518 100644
35495 --- a/arch/x86/xen/smp.c
35496 +++ b/arch/x86/xen/smp.c
35497 @@ -274,17 +274,13 @@ static void __init xen_smp_prepare_boot_cpu(void)
35498 native_smp_prepare_boot_cpu();
35499
35500 if (xen_pv_domain()) {
35501 - /* We've switched to the "real" per-cpu gdt, so make sure the
35502 - old memory can be recycled */
35503 - make_lowmem_page_readwrite(xen_initial_gdt);
35504 -
35505 #ifdef CONFIG_X86_32
35506 /*
35507 * Xen starts us with XEN_FLAT_RING1_DS, but linux code
35508 * expects __USER_DS
35509 */
35510 - loadsegment(ds, __USER_DS);
35511 - loadsegment(es, __USER_DS);
35512 + loadsegment(ds, __KERNEL_DS);
35513 + loadsegment(es, __KERNEL_DS);
35514 #endif
35515
35516 xen_filter_cpu_maps();
35517 @@ -364,7 +360,7 @@ cpu_initialize_context(unsigned int cpu, struct task_struct *idle)
35518 ctxt->user_regs.ss = __KERNEL_DS;
35519 #ifdef CONFIG_X86_32
35520 ctxt->user_regs.fs = __KERNEL_PERCPU;
35521 - ctxt->user_regs.gs = __KERNEL_STACK_CANARY;
35522 + savesegment(gs, ctxt->user_regs.gs);
35523 #else
35524 ctxt->gs_base_kernel = per_cpu_offset(cpu);
35525 #endif
35526 @@ -374,8 +370,8 @@ cpu_initialize_context(unsigned int cpu, struct task_struct *idle)
35527
35528 {
35529 ctxt->user_regs.eflags = 0x1000; /* IOPL_RING1 */
35530 - ctxt->user_regs.ds = __USER_DS;
35531 - ctxt->user_regs.es = __USER_DS;
35532 + ctxt->user_regs.ds = __KERNEL_DS;
35533 + ctxt->user_regs.es = __KERNEL_DS;
35534
35535 xen_copy_trap_info(ctxt->trap_ctxt);
35536
35537 @@ -420,13 +416,12 @@ static int xen_cpu_up(unsigned int cpu, struct task_struct *idle)
35538 int rc;
35539
35540 per_cpu(current_task, cpu) = idle;
35541 + per_cpu(current_tinfo, cpu) = &idle->tinfo;
35542 #ifdef CONFIG_X86_32
35543 irq_ctx_init(cpu);
35544 #else
35545 clear_tsk_thread_flag(idle, TIF_FORK);
35546 - per_cpu(kernel_stack, cpu) =
35547 - (unsigned long)task_stack_page(idle) -
35548 - KERNEL_STACK_OFFSET + THREAD_SIZE;
35549 + per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
35550 #endif
35551 xen_setup_runstate_info(cpu);
35552 xen_setup_timer(cpu);
35553 @@ -702,7 +697,7 @@ static const struct smp_ops xen_smp_ops __initconst = {
35554
35555 void __init xen_smp_init(void)
35556 {
35557 - smp_ops = xen_smp_ops;
35558 + memcpy((void *)&smp_ops, &xen_smp_ops, sizeof smp_ops);
35559 xen_fill_possible_map();
35560 }
35561
35562 diff --git a/arch/x86/xen/xen-asm_32.S b/arch/x86/xen/xen-asm_32.S
35563 index 33ca6e4..0ded929 100644
35564 --- a/arch/x86/xen/xen-asm_32.S
35565 +++ b/arch/x86/xen/xen-asm_32.S
35566 @@ -84,14 +84,14 @@ ENTRY(xen_iret)
35567 ESP_OFFSET=4 # bytes pushed onto stack
35568
35569 /*
35570 - * Store vcpu_info pointer for easy access. Do it this way to
35571 - * avoid having to reload %fs
35572 + * Store vcpu_info pointer for easy access.
35573 */
35574 #ifdef CONFIG_SMP
35575 - GET_THREAD_INFO(%eax)
35576 - movl %ss:TI_cpu(%eax), %eax
35577 - movl %ss:__per_cpu_offset(,%eax,4), %eax
35578 - mov %ss:xen_vcpu(%eax), %eax
35579 + push %fs
35580 + mov $(__KERNEL_PERCPU), %eax
35581 + mov %eax, %fs
35582 + mov PER_CPU_VAR(xen_vcpu), %eax
35583 + pop %fs
35584 #else
35585 movl %ss:xen_vcpu, %eax
35586 #endif
35587 diff --git a/arch/x86/xen/xen-head.S b/arch/x86/xen/xen-head.S
35588 index 7faed58..ba4427c 100644
35589 --- a/arch/x86/xen/xen-head.S
35590 +++ b/arch/x86/xen/xen-head.S
35591 @@ -19,6 +19,17 @@ ENTRY(startup_xen)
35592 #ifdef CONFIG_X86_32
35593 mov %esi,xen_start_info
35594 mov $init_thread_union+THREAD_SIZE,%esp
35595 +#ifdef CONFIG_SMP
35596 + movl $cpu_gdt_table,%edi
35597 + movl $__per_cpu_load,%eax
35598 + movw %ax,__KERNEL_PERCPU + 2(%edi)
35599 + rorl $16,%eax
35600 + movb %al,__KERNEL_PERCPU + 4(%edi)
35601 + movb %ah,__KERNEL_PERCPU + 7(%edi)
35602 + movl $__per_cpu_end - 1,%eax
35603 + subl $__per_cpu_start,%eax
35604 + movw %ax,__KERNEL_PERCPU + 0(%edi)
35605 +#endif
35606 #else
35607 mov %rsi,xen_start_info
35608 mov $init_thread_union+THREAD_SIZE,%rsp
35609 diff --git a/arch/x86/xen/xen-ops.h b/arch/x86/xen/xen-ops.h
35610 index 95f8c61..611d6e8 100644
35611 --- a/arch/x86/xen/xen-ops.h
35612 +++ b/arch/x86/xen/xen-ops.h
35613 @@ -10,8 +10,6 @@
35614 extern const char xen_hypervisor_callback[];
35615 extern const char xen_failsafe_callback[];
35616
35617 -extern void *xen_initial_gdt;
35618 -
35619 struct trap_info;
35620 void xen_copy_trap_info(struct trap_info *traps);
35621
35622 diff --git a/arch/xtensa/variants/dc232b/include/variant/core.h b/arch/xtensa/variants/dc232b/include/variant/core.h
35623 index 525bd3d..ef888b1 100644
35624 --- a/arch/xtensa/variants/dc232b/include/variant/core.h
35625 +++ b/arch/xtensa/variants/dc232b/include/variant/core.h
35626 @@ -119,9 +119,9 @@
35627 ----------------------------------------------------------------------*/
35628
35629 #define XCHAL_ICACHE_LINESIZE 32 /* I-cache line size in bytes */
35630 -#define XCHAL_DCACHE_LINESIZE 32 /* D-cache line size in bytes */
35631 #define XCHAL_ICACHE_LINEWIDTH 5 /* log2(I line size in bytes) */
35632 #define XCHAL_DCACHE_LINEWIDTH 5 /* log2(D line size in bytes) */
35633 +#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
35634
35635 #define XCHAL_ICACHE_SIZE 16384 /* I-cache size in bytes or 0 */
35636 #define XCHAL_DCACHE_SIZE 16384 /* D-cache size in bytes or 0 */
35637 diff --git a/arch/xtensa/variants/fsf/include/variant/core.h b/arch/xtensa/variants/fsf/include/variant/core.h
35638 index 2f33760..835e50a 100644
35639 --- a/arch/xtensa/variants/fsf/include/variant/core.h
35640 +++ b/arch/xtensa/variants/fsf/include/variant/core.h
35641 @@ -11,6 +11,7 @@
35642 #ifndef _XTENSA_CORE_H
35643 #define _XTENSA_CORE_H
35644
35645 +#include <linux/const.h>
35646
35647 /****************************************************************************
35648 Parameters Useful for Any Code, USER or PRIVILEGED
35649 @@ -112,9 +113,9 @@
35650 ----------------------------------------------------------------------*/
35651
35652 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
35653 -#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
35654 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
35655 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
35656 +#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
35657
35658 #define XCHAL_ICACHE_SIZE 8192 /* I-cache size in bytes or 0 */
35659 #define XCHAL_DCACHE_SIZE 8192 /* D-cache size in bytes or 0 */
35660 diff --git a/arch/xtensa/variants/s6000/include/variant/core.h b/arch/xtensa/variants/s6000/include/variant/core.h
35661 index af00795..2bb8105 100644
35662 --- a/arch/xtensa/variants/s6000/include/variant/core.h
35663 +++ b/arch/xtensa/variants/s6000/include/variant/core.h
35664 @@ -11,6 +11,7 @@
35665 #ifndef _XTENSA_CORE_CONFIGURATION_H
35666 #define _XTENSA_CORE_CONFIGURATION_H
35667
35668 +#include <linux/const.h>
35669
35670 /****************************************************************************
35671 Parameters Useful for Any Code, USER or PRIVILEGED
35672 @@ -118,9 +119,9 @@
35673 ----------------------------------------------------------------------*/
35674
35675 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
35676 -#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
35677 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
35678 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
35679 +#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
35680
35681 #define XCHAL_ICACHE_SIZE 32768 /* I-cache size in bytes or 0 */
35682 #define XCHAL_DCACHE_SIZE 32768 /* D-cache size in bytes or 0 */
35683 diff --git a/block/blk-cgroup.c b/block/blk-cgroup.c
35684 index 4e491d9..c8e18e4 100644
35685 --- a/block/blk-cgroup.c
35686 +++ b/block/blk-cgroup.c
35687 @@ -812,7 +812,7 @@ static void blkcg_css_free(struct cgroup_subsys_state *css)
35688 static struct cgroup_subsys_state *
35689 blkcg_css_alloc(struct cgroup_subsys_state *parent_css)
35690 {
35691 - static atomic64_t id_seq = ATOMIC64_INIT(0);
35692 + static atomic64_unchecked_t id_seq = ATOMIC64_INIT(0);
35693 struct blkcg *blkcg;
35694
35695 if (!parent_css) {
35696 @@ -826,7 +826,7 @@ blkcg_css_alloc(struct cgroup_subsys_state *parent_css)
35697
35698 blkcg->cfq_weight = CFQ_WEIGHT_DEFAULT;
35699 blkcg->cfq_leaf_weight = CFQ_WEIGHT_DEFAULT;
35700 - blkcg->id = atomic64_inc_return(&id_seq); /* root is 0, start from 1 */
35701 + blkcg->id = atomic64_inc_return_unchecked(&id_seq); /* root is 0, start from 1 */
35702 done:
35703 spin_lock_init(&blkcg->lock);
35704 INIT_RADIX_TREE(&blkcg->blkg_tree, GFP_ATOMIC);
35705 diff --git a/block/blk-iopoll.c b/block/blk-iopoll.c
35706 index 1855bf5..af12b06 100644
35707 --- a/block/blk-iopoll.c
35708 +++ b/block/blk-iopoll.c
35709 @@ -77,7 +77,7 @@ void blk_iopoll_complete(struct blk_iopoll *iopoll)
35710 }
35711 EXPORT_SYMBOL(blk_iopoll_complete);
35712
35713 -static void blk_iopoll_softirq(struct softirq_action *h)
35714 +static __latent_entropy void blk_iopoll_softirq(void)
35715 {
35716 struct list_head *list = this_cpu_ptr(&blk_cpu_iopoll);
35717 int rearm = 0, budget = blk_iopoll_budget;
35718 diff --git a/block/blk-map.c b/block/blk-map.c
35719 index 623e1cd..ca1e109 100644
35720 --- a/block/blk-map.c
35721 +++ b/block/blk-map.c
35722 @@ -302,7 +302,7 @@ int blk_rq_map_kern(struct request_queue *q, struct request *rq, void *kbuf,
35723 if (!len || !kbuf)
35724 return -EINVAL;
35725
35726 - do_copy = !blk_rq_aligned(q, addr, len) || object_is_on_stack(kbuf);
35727 + do_copy = !blk_rq_aligned(q, addr, len) || object_starts_on_stack(kbuf);
35728 if (do_copy)
35729 bio = bio_copy_kern(q, kbuf, len, gfp_mask, reading);
35730 else
35731 diff --git a/block/blk-softirq.c b/block/blk-softirq.c
35732 index 57790c1..5e988dd 100644
35733 --- a/block/blk-softirq.c
35734 +++ b/block/blk-softirq.c
35735 @@ -18,7 +18,7 @@ static DEFINE_PER_CPU(struct list_head, blk_cpu_done);
35736 * Softirq action handler - move entries to local list and loop over them
35737 * while passing them to the queue registered handler.
35738 */
35739 -static void blk_done_softirq(struct softirq_action *h)
35740 +static __latent_entropy void blk_done_softirq(void)
35741 {
35742 struct list_head *cpu_list, local_list;
35743
35744 diff --git a/block/bsg.c b/block/bsg.c
35745 index 420a5a9..23834aa 100644
35746 --- a/block/bsg.c
35747 +++ b/block/bsg.c
35748 @@ -176,16 +176,24 @@ static int blk_fill_sgv4_hdr_rq(struct request_queue *q, struct request *rq,
35749 struct sg_io_v4 *hdr, struct bsg_device *bd,
35750 fmode_t has_write_perm)
35751 {
35752 + unsigned char tmpcmd[sizeof(rq->__cmd)];
35753 + unsigned char *cmdptr;
35754 +
35755 if (hdr->request_len > BLK_MAX_CDB) {
35756 rq->cmd = kzalloc(hdr->request_len, GFP_KERNEL);
35757 if (!rq->cmd)
35758 return -ENOMEM;
35759 - }
35760 + cmdptr = rq->cmd;
35761 + } else
35762 + cmdptr = tmpcmd;
35763
35764 - if (copy_from_user(rq->cmd, (void __user *)(unsigned long)hdr->request,
35765 + if (copy_from_user(cmdptr, (void __user *)(unsigned long)hdr->request,
35766 hdr->request_len))
35767 return -EFAULT;
35768
35769 + if (cmdptr != rq->cmd)
35770 + memcpy(rq->cmd, cmdptr, hdr->request_len);
35771 +
35772 if (hdr->subprotocol == BSG_SUB_PROTOCOL_SCSI_CMD) {
35773 if (blk_verify_command(rq->cmd, has_write_perm))
35774 return -EPERM;
35775 diff --git a/block/compat_ioctl.c b/block/compat_ioctl.c
35776 index fbd5a67..f24fd95 100644
35777 --- a/block/compat_ioctl.c
35778 +++ b/block/compat_ioctl.c
35779 @@ -156,7 +156,7 @@ static int compat_cdrom_generic_command(struct block_device *bdev, fmode_t mode,
35780 cgc = compat_alloc_user_space(sizeof(*cgc));
35781 cgc32 = compat_ptr(arg);
35782
35783 - if (copy_in_user(&cgc->cmd, &cgc32->cmd, sizeof(cgc->cmd)) ||
35784 + if (copy_in_user(cgc->cmd, cgc32->cmd, sizeof(cgc->cmd)) ||
35785 get_user(data, &cgc32->buffer) ||
35786 put_user(compat_ptr(data), &cgc->buffer) ||
35787 copy_in_user(&cgc->buflen, &cgc32->buflen,
35788 @@ -341,7 +341,7 @@ static int compat_fd_ioctl(struct block_device *bdev, fmode_t mode,
35789 err |= __get_user(f->spec1, &uf->spec1);
35790 err |= __get_user(f->fmt_gap, &uf->fmt_gap);
35791 err |= __get_user(name, &uf->name);
35792 - f->name = compat_ptr(name);
35793 + f->name = (void __force_kernel *)compat_ptr(name);
35794 if (err) {
35795 err = -EFAULT;
35796 goto out;
35797 diff --git a/block/genhd.c b/block/genhd.c
35798 index 791f419..89f21c4 100644
35799 --- a/block/genhd.c
35800 +++ b/block/genhd.c
35801 @@ -467,21 +467,24 @@ static char *bdevt_str(dev_t devt, char *buf)
35802
35803 /*
35804 * Register device numbers dev..(dev+range-1)
35805 - * range must be nonzero
35806 + * Noop if @range is zero.
35807 * The hash chain is sorted on range, so that subranges can override.
35808 */
35809 void blk_register_region(dev_t devt, unsigned long range, struct module *module,
35810 struct kobject *(*probe)(dev_t, int *, void *),
35811 int (*lock)(dev_t, void *), void *data)
35812 {
35813 - kobj_map(bdev_map, devt, range, module, probe, lock, data);
35814 + if (range)
35815 + kobj_map(bdev_map, devt, range, module, probe, lock, data);
35816 }
35817
35818 EXPORT_SYMBOL(blk_register_region);
35819
35820 +/* undo blk_register_region(), noop if @range is zero */
35821 void blk_unregister_region(dev_t devt, unsigned long range)
35822 {
35823 - kobj_unmap(bdev_map, devt, range);
35824 + if (range)
35825 + kobj_unmap(bdev_map, devt, range);
35826 }
35827
35828 EXPORT_SYMBOL(blk_unregister_region);
35829 diff --git a/block/partitions/efi.c b/block/partitions/efi.c
35830 index dc51f46..d5446a8 100644
35831 --- a/block/partitions/efi.c
35832 +++ b/block/partitions/efi.c
35833 @@ -293,14 +293,14 @@ static gpt_entry *alloc_read_gpt_entries(struct parsed_partitions *state,
35834 if (!gpt)
35835 return NULL;
35836
35837 + if (!le32_to_cpu(gpt->num_partition_entries))
35838 + return NULL;
35839 + pte = kcalloc(le32_to_cpu(gpt->num_partition_entries), le32_to_cpu(gpt->sizeof_partition_entry), GFP_KERNEL);
35840 + if (!pte)
35841 + return NULL;
35842 +
35843 count = le32_to_cpu(gpt->num_partition_entries) *
35844 le32_to_cpu(gpt->sizeof_partition_entry);
35845 - if (!count)
35846 - return NULL;
35847 - pte = kmalloc(count, GFP_KERNEL);
35848 - if (!pte)
35849 - return NULL;
35850 -
35851 if (read_lba(state, le64_to_cpu(gpt->partition_entry_lba),
35852 (u8 *) pte, count) < count) {
35853 kfree(pte);
35854 diff --git a/block/scsi_ioctl.c b/block/scsi_ioctl.c
35855 index 625e3e4..b5339f9 100644
35856 --- a/block/scsi_ioctl.c
35857 +++ b/block/scsi_ioctl.c
35858 @@ -67,7 +67,7 @@ static int scsi_get_bus(struct request_queue *q, int __user *p)
35859 return put_user(0, p);
35860 }
35861
35862 -static int sg_get_timeout(struct request_queue *q)
35863 +static int __intentional_overflow(-1) sg_get_timeout(struct request_queue *q)
35864 {
35865 return jiffies_to_clock_t(q->sg_timeout);
35866 }
35867 @@ -224,8 +224,20 @@ EXPORT_SYMBOL(blk_verify_command);
35868 static int blk_fill_sghdr_rq(struct request_queue *q, struct request *rq,
35869 struct sg_io_hdr *hdr, fmode_t mode)
35870 {
35871 - if (copy_from_user(rq->cmd, hdr->cmdp, hdr->cmd_len))
35872 + unsigned char tmpcmd[sizeof(rq->__cmd)];
35873 + unsigned char *cmdptr;
35874 +
35875 + if (rq->cmd != rq->__cmd)
35876 + cmdptr = rq->cmd;
35877 + else
35878 + cmdptr = tmpcmd;
35879 +
35880 + if (copy_from_user(cmdptr, hdr->cmdp, hdr->cmd_len))
35881 return -EFAULT;
35882 +
35883 + if (cmdptr != rq->cmd)
35884 + memcpy(rq->cmd, cmdptr, hdr->cmd_len);
35885 +
35886 if (blk_verify_command(rq->cmd, mode & FMODE_WRITE))
35887 return -EPERM;
35888
35889 @@ -415,6 +427,8 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
35890 int err;
35891 unsigned int in_len, out_len, bytes, opcode, cmdlen;
35892 char *buffer = NULL, sense[SCSI_SENSE_BUFFERSIZE];
35893 + unsigned char tmpcmd[sizeof(rq->__cmd)];
35894 + unsigned char *cmdptr;
35895
35896 if (!sic)
35897 return -EINVAL;
35898 @@ -448,9 +462,18 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
35899 */
35900 err = -EFAULT;
35901 rq->cmd_len = cmdlen;
35902 - if (copy_from_user(rq->cmd, sic->data, cmdlen))
35903 +
35904 + if (rq->cmd != rq->__cmd)
35905 + cmdptr = rq->cmd;
35906 + else
35907 + cmdptr = tmpcmd;
35908 +
35909 + if (copy_from_user(cmdptr, sic->data, cmdlen))
35910 goto error;
35911
35912 + if (rq->cmd != cmdptr)
35913 + memcpy(rq->cmd, cmdptr, cmdlen);
35914 +
35915 if (in_len && copy_from_user(buffer, sic->data + cmdlen, in_len))
35916 goto error;
35917
35918 diff --git a/crypto/cryptd.c b/crypto/cryptd.c
35919 index 7bdd61b..afec999 100644
35920 --- a/crypto/cryptd.c
35921 +++ b/crypto/cryptd.c
35922 @@ -63,7 +63,7 @@ struct cryptd_blkcipher_ctx {
35923
35924 struct cryptd_blkcipher_request_ctx {
35925 crypto_completion_t complete;
35926 -};
35927 +} __no_const;
35928
35929 struct cryptd_hash_ctx {
35930 struct crypto_shash *child;
35931 @@ -80,7 +80,7 @@ struct cryptd_aead_ctx {
35932
35933 struct cryptd_aead_request_ctx {
35934 crypto_completion_t complete;
35935 -};
35936 +} __no_const;
35937
35938 static void cryptd_queue_worker(struct work_struct *work);
35939
35940 diff --git a/crypto/pcrypt.c b/crypto/pcrypt.c
35941 index f8c920c..ab2cb5a 100644
35942 --- a/crypto/pcrypt.c
35943 +++ b/crypto/pcrypt.c
35944 @@ -440,7 +440,7 @@ static int pcrypt_sysfs_add(struct padata_instance *pinst, const char *name)
35945 int ret;
35946
35947 pinst->kobj.kset = pcrypt_kset;
35948 - ret = kobject_add(&pinst->kobj, NULL, name);
35949 + ret = kobject_add(&pinst->kobj, NULL, "%s", name);
35950 if (!ret)
35951 kobject_uevent(&pinst->kobj, KOBJ_ADD);
35952
35953 diff --git a/drivers/acpi/acpica/hwxfsleep.c b/drivers/acpi/acpica/hwxfsleep.c
35954 index 15dddc1..b61cf0c 100644
35955 --- a/drivers/acpi/acpica/hwxfsleep.c
35956 +++ b/drivers/acpi/acpica/hwxfsleep.c
35957 @@ -63,11 +63,12 @@ static acpi_status acpi_hw_sleep_dispatch(u8 sleep_state, u32 function_id);
35958 /* Legacy functions are optional, based upon ACPI_REDUCED_HARDWARE */
35959
35960 static struct acpi_sleep_functions acpi_sleep_dispatch[] = {
35961 - {ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_sleep),
35962 - acpi_hw_extended_sleep},
35963 - {ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_wake_prep),
35964 - acpi_hw_extended_wake_prep},
35965 - {ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_wake), acpi_hw_extended_wake}
35966 + {.legacy_function = ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_sleep),
35967 + .extended_function = acpi_hw_extended_sleep},
35968 + {.legacy_function = ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_wake_prep),
35969 + .extended_function = acpi_hw_extended_wake_prep},
35970 + {.legacy_function = ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_wake),
35971 + .extended_function = acpi_hw_extended_wake}
35972 };
35973
35974 /*
35975 diff --git a/drivers/acpi/apei/apei-internal.h b/drivers/acpi/apei/apei-internal.h
35976 index 21ba34a..cb05966 100644
35977 --- a/drivers/acpi/apei/apei-internal.h
35978 +++ b/drivers/acpi/apei/apei-internal.h
35979 @@ -20,7 +20,7 @@ typedef int (*apei_exec_ins_func_t)(struct apei_exec_context *ctx,
35980 struct apei_exec_ins_type {
35981 u32 flags;
35982 apei_exec_ins_func_t run;
35983 -};
35984 +} __do_const;
35985
35986 struct apei_exec_context {
35987 u32 ip;
35988 diff --git a/drivers/acpi/apei/ghes.c b/drivers/acpi/apei/ghes.c
35989 index a30bc31..b91c4d5 100644
35990 --- a/drivers/acpi/apei/ghes.c
35991 +++ b/drivers/acpi/apei/ghes.c
35992 @@ -498,7 +498,7 @@ static void __ghes_print_estatus(const char *pfx,
35993 const struct acpi_hest_generic *generic,
35994 const struct acpi_generic_status *estatus)
35995 {
35996 - static atomic_t seqno;
35997 + static atomic_unchecked_t seqno;
35998 unsigned int curr_seqno;
35999 char pfx_seq[64];
36000
36001 @@ -509,7 +509,7 @@ static void __ghes_print_estatus(const char *pfx,
36002 else
36003 pfx = KERN_ERR;
36004 }
36005 - curr_seqno = atomic_inc_return(&seqno);
36006 + curr_seqno = atomic_inc_return_unchecked(&seqno);
36007 snprintf(pfx_seq, sizeof(pfx_seq), "%s{%u}" HW_ERR, pfx, curr_seqno);
36008 printk("%s""Hardware error from APEI Generic Hardware Error Source: %d\n",
36009 pfx_seq, generic->header.source_id);
36010 diff --git a/drivers/acpi/bgrt.c b/drivers/acpi/bgrt.c
36011 index a83e3c6..c3d617f 100644
36012 --- a/drivers/acpi/bgrt.c
36013 +++ b/drivers/acpi/bgrt.c
36014 @@ -86,8 +86,10 @@ static int __init bgrt_init(void)
36015 if (!bgrt_image)
36016 return -ENODEV;
36017
36018 - bin_attr_image.private = bgrt_image;
36019 - bin_attr_image.size = bgrt_image_size;
36020 + pax_open_kernel();
36021 + *(void **)&bin_attr_image.private = bgrt_image;
36022 + *(size_t *)&bin_attr_image.size = bgrt_image_size;
36023 + pax_close_kernel();
36024
36025 bgrt_kobj = kobject_create_and_add("bgrt", acpi_kobj);
36026 if (!bgrt_kobj)
36027 diff --git a/drivers/acpi/blacklist.c b/drivers/acpi/blacklist.c
36028 index 078c4f7..410e272 100644
36029 --- a/drivers/acpi/blacklist.c
36030 +++ b/drivers/acpi/blacklist.c
36031 @@ -52,7 +52,7 @@ struct acpi_blacklist_item {
36032 u32 is_critical_error;
36033 };
36034
36035 -static struct dmi_system_id acpi_osi_dmi_table[] __initdata;
36036 +static const struct dmi_system_id acpi_osi_dmi_table[] __initconst;
36037
36038 /*
36039 * POLICY: If *anything* doesn't work, put it on the blacklist.
36040 @@ -164,7 +164,7 @@ static int __init dmi_disable_osi_win8(const struct dmi_system_id *d)
36041 return 0;
36042 }
36043
36044 -static struct dmi_system_id acpi_osi_dmi_table[] __initdata = {
36045 +static const struct dmi_system_id acpi_osi_dmi_table[] __initconst = {
36046 {
36047 .callback = dmi_disable_osi_vista,
36048 .ident = "Fujitsu Siemens",
36049 diff --git a/drivers/acpi/custom_method.c b/drivers/acpi/custom_method.c
36050 index 12b62f2..dc2aac8 100644
36051 --- a/drivers/acpi/custom_method.c
36052 +++ b/drivers/acpi/custom_method.c
36053 @@ -29,6 +29,10 @@ static ssize_t cm_write(struct file *file, const char __user * user_buf,
36054 struct acpi_table_header table;
36055 acpi_status status;
36056
36057 +#ifdef CONFIG_GRKERNSEC_KMEM
36058 + return -EPERM;
36059 +#endif
36060 +
36061 if (!(*ppos)) {
36062 /* parse the table header to get the table length */
36063 if (count <= sizeof(struct acpi_table_header))
36064 diff --git a/drivers/acpi/processor_idle.c b/drivers/acpi/processor_idle.c
36065 index 644516d..643937e 100644
36066 --- a/drivers/acpi/processor_idle.c
36067 +++ b/drivers/acpi/processor_idle.c
36068 @@ -963,7 +963,7 @@ static int acpi_processor_setup_cpuidle_states(struct acpi_processor *pr)
36069 {
36070 int i, count = CPUIDLE_DRIVER_STATE_START;
36071 struct acpi_processor_cx *cx;
36072 - struct cpuidle_state *state;
36073 + cpuidle_state_no_const *state;
36074 struct cpuidle_driver *drv = &acpi_idle_driver;
36075
36076 if (!pr->flags.power_setup_done)
36077 diff --git a/drivers/acpi/sysfs.c b/drivers/acpi/sysfs.c
36078 index 6dbc3ca..b8b59a0 100644
36079 --- a/drivers/acpi/sysfs.c
36080 +++ b/drivers/acpi/sysfs.c
36081 @@ -425,11 +425,11 @@ static u32 num_counters;
36082 static struct attribute **all_attrs;
36083 static u32 acpi_gpe_count;
36084
36085 -static struct attribute_group interrupt_stats_attr_group = {
36086 +static attribute_group_no_const interrupt_stats_attr_group = {
36087 .name = "interrupts",
36088 };
36089
36090 -static struct kobj_attribute *counter_attrs;
36091 +static kobj_attribute_no_const *counter_attrs;
36092
36093 static void delete_gpe_attr_array(void)
36094 {
36095 diff --git a/drivers/ata/libahci.c b/drivers/ata/libahci.c
36096 index c482f8c..c832240 100644
36097 --- a/drivers/ata/libahci.c
36098 +++ b/drivers/ata/libahci.c
36099 @@ -1239,7 +1239,7 @@ int ahci_kick_engine(struct ata_port *ap)
36100 }
36101 EXPORT_SYMBOL_GPL(ahci_kick_engine);
36102
36103 -static int ahci_exec_polled_cmd(struct ata_port *ap, int pmp,
36104 +static int __intentional_overflow(-1) ahci_exec_polled_cmd(struct ata_port *ap, int pmp,
36105 struct ata_taskfile *tf, int is_cmd, u16 flags,
36106 unsigned long timeout_msec)
36107 {
36108 diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c
36109 index 8cb2522..a815e54 100644
36110 --- a/drivers/ata/libata-core.c
36111 +++ b/drivers/ata/libata-core.c
36112 @@ -98,7 +98,7 @@ static unsigned int ata_dev_set_xfermode(struct ata_device *dev);
36113 static void ata_dev_xfermask(struct ata_device *dev);
36114 static unsigned long ata_dev_blacklisted(const struct ata_device *dev);
36115
36116 -atomic_t ata_print_id = ATOMIC_INIT(0);
36117 +atomic_unchecked_t ata_print_id = ATOMIC_INIT(0);
36118
36119 struct ata_force_param {
36120 const char *name;
36121 @@ -4851,7 +4851,7 @@ void ata_qc_free(struct ata_queued_cmd *qc)
36122 struct ata_port *ap;
36123 unsigned int tag;
36124
36125 - WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
36126 + BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
36127 ap = qc->ap;
36128
36129 qc->flags = 0;
36130 @@ -4867,7 +4867,7 @@ void __ata_qc_complete(struct ata_queued_cmd *qc)
36131 struct ata_port *ap;
36132 struct ata_link *link;
36133
36134 - WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
36135 + BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
36136 WARN_ON_ONCE(!(qc->flags & ATA_QCFLAG_ACTIVE));
36137 ap = qc->ap;
36138 link = qc->dev->link;
36139 @@ -5986,6 +5986,7 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
36140 return;
36141
36142 spin_lock(&lock);
36143 + pax_open_kernel();
36144
36145 for (cur = ops->inherits; cur; cur = cur->inherits) {
36146 void **inherit = (void **)cur;
36147 @@ -5999,8 +6000,9 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
36148 if (IS_ERR(*pp))
36149 *pp = NULL;
36150
36151 - ops->inherits = NULL;
36152 + *(struct ata_port_operations **)&ops->inherits = NULL;
36153
36154 + pax_close_kernel();
36155 spin_unlock(&lock);
36156 }
36157
36158 @@ -6193,7 +6195,7 @@ int ata_host_register(struct ata_host *host, struct scsi_host_template *sht)
36159
36160 /* give ports names and add SCSI hosts */
36161 for (i = 0; i < host->n_ports; i++) {
36162 - host->ports[i]->print_id = atomic_inc_return(&ata_print_id);
36163 + host->ports[i]->print_id = atomic_inc_return_unchecked(&ata_print_id);
36164 host->ports[i]->local_port_no = i + 1;
36165 }
36166
36167 diff --git a/drivers/ata/libata-scsi.c b/drivers/ata/libata-scsi.c
36168 index ef8567d..8bdbd03 100644
36169 --- a/drivers/ata/libata-scsi.c
36170 +++ b/drivers/ata/libata-scsi.c
36171 @@ -4147,7 +4147,7 @@ int ata_sas_port_init(struct ata_port *ap)
36172
36173 if (rc)
36174 return rc;
36175 - ap->print_id = atomic_inc_return(&ata_print_id);
36176 + ap->print_id = atomic_inc_return_unchecked(&ata_print_id);
36177 return 0;
36178 }
36179 EXPORT_SYMBOL_GPL(ata_sas_port_init);
36180 diff --git a/drivers/ata/libata.h b/drivers/ata/libata.h
36181 index 45b5ab3..98446b8 100644
36182 --- a/drivers/ata/libata.h
36183 +++ b/drivers/ata/libata.h
36184 @@ -53,7 +53,7 @@ enum {
36185 ATA_DNXFER_QUIET = (1 << 31),
36186 };
36187
36188 -extern atomic_t ata_print_id;
36189 +extern atomic_unchecked_t ata_print_id;
36190 extern int atapi_passthru16;
36191 extern int libata_fua;
36192 extern int libata_noacpi;
36193 diff --git a/drivers/ata/pata_arasan_cf.c b/drivers/ata/pata_arasan_cf.c
36194 index 73492dd..ca2bff5 100644
36195 --- a/drivers/ata/pata_arasan_cf.c
36196 +++ b/drivers/ata/pata_arasan_cf.c
36197 @@ -865,7 +865,9 @@ static int arasan_cf_probe(struct platform_device *pdev)
36198 /* Handle platform specific quirks */
36199 if (quirk) {
36200 if (quirk & CF_BROKEN_PIO) {
36201 - ap->ops->set_piomode = NULL;
36202 + pax_open_kernel();
36203 + *(void **)&ap->ops->set_piomode = NULL;
36204 + pax_close_kernel();
36205 ap->pio_mask = 0;
36206 }
36207 if (quirk & CF_BROKEN_MWDMA)
36208 diff --git a/drivers/atm/adummy.c b/drivers/atm/adummy.c
36209 index f9b983a..887b9d8 100644
36210 --- a/drivers/atm/adummy.c
36211 +++ b/drivers/atm/adummy.c
36212 @@ -114,7 +114,7 @@ adummy_send(struct atm_vcc *vcc, struct sk_buff *skb)
36213 vcc->pop(vcc, skb);
36214 else
36215 dev_kfree_skb_any(skb);
36216 - atomic_inc(&vcc->stats->tx);
36217 + atomic_inc_unchecked(&vcc->stats->tx);
36218
36219 return 0;
36220 }
36221 diff --git a/drivers/atm/ambassador.c b/drivers/atm/ambassador.c
36222 index 62a7607..cc4be104 100644
36223 --- a/drivers/atm/ambassador.c
36224 +++ b/drivers/atm/ambassador.c
36225 @@ -454,7 +454,7 @@ static void tx_complete (amb_dev * dev, tx_out * tx) {
36226 PRINTD (DBG_FLOW|DBG_TX, "tx_complete %p %p", dev, tx);
36227
36228 // VC layer stats
36229 - atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
36230 + atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
36231
36232 // free the descriptor
36233 kfree (tx_descr);
36234 @@ -495,7 +495,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
36235 dump_skb ("<<<", vc, skb);
36236
36237 // VC layer stats
36238 - atomic_inc(&atm_vcc->stats->rx);
36239 + atomic_inc_unchecked(&atm_vcc->stats->rx);
36240 __net_timestamp(skb);
36241 // end of our responsibility
36242 atm_vcc->push (atm_vcc, skb);
36243 @@ -510,7 +510,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
36244 } else {
36245 PRINTK (KERN_INFO, "dropped over-size frame");
36246 // should we count this?
36247 - atomic_inc(&atm_vcc->stats->rx_drop);
36248 + atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
36249 }
36250
36251 } else {
36252 @@ -1338,7 +1338,7 @@ static int amb_send (struct atm_vcc * atm_vcc, struct sk_buff * skb) {
36253 }
36254
36255 if (check_area (skb->data, skb->len)) {
36256 - atomic_inc(&atm_vcc->stats->tx_err);
36257 + atomic_inc_unchecked(&atm_vcc->stats->tx_err);
36258 return -ENOMEM; // ?
36259 }
36260
36261 diff --git a/drivers/atm/atmtcp.c b/drivers/atm/atmtcp.c
36262 index 0e3f8f9..765a7a5 100644
36263 --- a/drivers/atm/atmtcp.c
36264 +++ b/drivers/atm/atmtcp.c
36265 @@ -206,7 +206,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
36266 if (vcc->pop) vcc->pop(vcc,skb);
36267 else dev_kfree_skb(skb);
36268 if (dev_data) return 0;
36269 - atomic_inc(&vcc->stats->tx_err);
36270 + atomic_inc_unchecked(&vcc->stats->tx_err);
36271 return -ENOLINK;
36272 }
36273 size = skb->len+sizeof(struct atmtcp_hdr);
36274 @@ -214,7 +214,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
36275 if (!new_skb) {
36276 if (vcc->pop) vcc->pop(vcc,skb);
36277 else dev_kfree_skb(skb);
36278 - atomic_inc(&vcc->stats->tx_err);
36279 + atomic_inc_unchecked(&vcc->stats->tx_err);
36280 return -ENOBUFS;
36281 }
36282 hdr = (void *) skb_put(new_skb,sizeof(struct atmtcp_hdr));
36283 @@ -225,8 +225,8 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
36284 if (vcc->pop) vcc->pop(vcc,skb);
36285 else dev_kfree_skb(skb);
36286 out_vcc->push(out_vcc,new_skb);
36287 - atomic_inc(&vcc->stats->tx);
36288 - atomic_inc(&out_vcc->stats->rx);
36289 + atomic_inc_unchecked(&vcc->stats->tx);
36290 + atomic_inc_unchecked(&out_vcc->stats->rx);
36291 return 0;
36292 }
36293
36294 @@ -299,7 +299,7 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
36295 out_vcc = find_vcc(dev, ntohs(hdr->vpi), ntohs(hdr->vci));
36296 read_unlock(&vcc_sklist_lock);
36297 if (!out_vcc) {
36298 - atomic_inc(&vcc->stats->tx_err);
36299 + atomic_inc_unchecked(&vcc->stats->tx_err);
36300 goto done;
36301 }
36302 skb_pull(skb,sizeof(struct atmtcp_hdr));
36303 @@ -311,8 +311,8 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
36304 __net_timestamp(new_skb);
36305 skb_copy_from_linear_data(skb, skb_put(new_skb, skb->len), skb->len);
36306 out_vcc->push(out_vcc,new_skb);
36307 - atomic_inc(&vcc->stats->tx);
36308 - atomic_inc(&out_vcc->stats->rx);
36309 + atomic_inc_unchecked(&vcc->stats->tx);
36310 + atomic_inc_unchecked(&out_vcc->stats->rx);
36311 done:
36312 if (vcc->pop) vcc->pop(vcc,skb);
36313 else dev_kfree_skb(skb);
36314 diff --git a/drivers/atm/eni.c b/drivers/atm/eni.c
36315 index b1955ba..b179940 100644
36316 --- a/drivers/atm/eni.c
36317 +++ b/drivers/atm/eni.c
36318 @@ -522,7 +522,7 @@ static int rx_aal0(struct atm_vcc *vcc)
36319 DPRINTK(DEV_LABEL "(itf %d): trashing empty cell\n",
36320 vcc->dev->number);
36321 length = 0;
36322 - atomic_inc(&vcc->stats->rx_err);
36323 + atomic_inc_unchecked(&vcc->stats->rx_err);
36324 }
36325 else {
36326 length = ATM_CELL_SIZE-1; /* no HEC */
36327 @@ -577,7 +577,7 @@ static int rx_aal5(struct atm_vcc *vcc)
36328 size);
36329 }
36330 eff = length = 0;
36331 - atomic_inc(&vcc->stats->rx_err);
36332 + atomic_inc_unchecked(&vcc->stats->rx_err);
36333 }
36334 else {
36335 size = (descr & MID_RED_COUNT)*(ATM_CELL_PAYLOAD >> 2);
36336 @@ -594,7 +594,7 @@ static int rx_aal5(struct atm_vcc *vcc)
36337 "(VCI=%d,length=%ld,size=%ld (descr 0x%lx))\n",
36338 vcc->dev->number,vcc->vci,length,size << 2,descr);
36339 length = eff = 0;
36340 - atomic_inc(&vcc->stats->rx_err);
36341 + atomic_inc_unchecked(&vcc->stats->rx_err);
36342 }
36343 }
36344 skb = eff ? atm_alloc_charge(vcc,eff << 2,GFP_ATOMIC) : NULL;
36345 @@ -767,7 +767,7 @@ rx_dequeued++;
36346 vcc->push(vcc,skb);
36347 pushed++;
36348 }
36349 - atomic_inc(&vcc->stats->rx);
36350 + atomic_inc_unchecked(&vcc->stats->rx);
36351 }
36352 wake_up(&eni_dev->rx_wait);
36353 }
36354 @@ -1227,7 +1227,7 @@ static void dequeue_tx(struct atm_dev *dev)
36355 PCI_DMA_TODEVICE);
36356 if (vcc->pop) vcc->pop(vcc,skb);
36357 else dev_kfree_skb_irq(skb);
36358 - atomic_inc(&vcc->stats->tx);
36359 + atomic_inc_unchecked(&vcc->stats->tx);
36360 wake_up(&eni_dev->tx_wait);
36361 dma_complete++;
36362 }
36363 diff --git a/drivers/atm/firestream.c b/drivers/atm/firestream.c
36364 index b41c948..a002b17 100644
36365 --- a/drivers/atm/firestream.c
36366 +++ b/drivers/atm/firestream.c
36367 @@ -749,7 +749,7 @@ static void process_txdone_queue (struct fs_dev *dev, struct queue *q)
36368 }
36369 }
36370
36371 - atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
36372 + atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
36373
36374 fs_dprintk (FS_DEBUG_TXMEM, "i");
36375 fs_dprintk (FS_DEBUG_ALLOC, "Free t-skb: %p\n", skb);
36376 @@ -816,7 +816,7 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
36377 #endif
36378 skb_put (skb, qe->p1 & 0xffff);
36379 ATM_SKB(skb)->vcc = atm_vcc;
36380 - atomic_inc(&atm_vcc->stats->rx);
36381 + atomic_inc_unchecked(&atm_vcc->stats->rx);
36382 __net_timestamp(skb);
36383 fs_dprintk (FS_DEBUG_ALLOC, "Free rec-skb: %p (pushed)\n", skb);
36384 atm_vcc->push (atm_vcc, skb);
36385 @@ -837,12 +837,12 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
36386 kfree (pe);
36387 }
36388 if (atm_vcc)
36389 - atomic_inc(&atm_vcc->stats->rx_drop);
36390 + atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
36391 break;
36392 case 0x1f: /* Reassembly abort: no buffers. */
36393 /* Silently increment error counter. */
36394 if (atm_vcc)
36395 - atomic_inc(&atm_vcc->stats->rx_drop);
36396 + atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
36397 break;
36398 default: /* Hmm. Haven't written the code to handle the others yet... -- REW */
36399 printk (KERN_WARNING "Don't know what to do with RX status %x: %s.\n",
36400 diff --git a/drivers/atm/fore200e.c b/drivers/atm/fore200e.c
36401 index 204814e..cede831 100644
36402 --- a/drivers/atm/fore200e.c
36403 +++ b/drivers/atm/fore200e.c
36404 @@ -931,9 +931,9 @@ fore200e_tx_irq(struct fore200e* fore200e)
36405 #endif
36406 /* check error condition */
36407 if (*entry->status & STATUS_ERROR)
36408 - atomic_inc(&vcc->stats->tx_err);
36409 + atomic_inc_unchecked(&vcc->stats->tx_err);
36410 else
36411 - atomic_inc(&vcc->stats->tx);
36412 + atomic_inc_unchecked(&vcc->stats->tx);
36413 }
36414 }
36415
36416 @@ -1082,7 +1082,7 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
36417 if (skb == NULL) {
36418 DPRINTK(2, "unable to alloc new skb, rx PDU length = %d\n", pdu_len);
36419
36420 - atomic_inc(&vcc->stats->rx_drop);
36421 + atomic_inc_unchecked(&vcc->stats->rx_drop);
36422 return -ENOMEM;
36423 }
36424
36425 @@ -1125,14 +1125,14 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
36426
36427 dev_kfree_skb_any(skb);
36428
36429 - atomic_inc(&vcc->stats->rx_drop);
36430 + atomic_inc_unchecked(&vcc->stats->rx_drop);
36431 return -ENOMEM;
36432 }
36433
36434 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
36435
36436 vcc->push(vcc, skb);
36437 - atomic_inc(&vcc->stats->rx);
36438 + atomic_inc_unchecked(&vcc->stats->rx);
36439
36440 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
36441
36442 @@ -1210,7 +1210,7 @@ fore200e_rx_irq(struct fore200e* fore200e)
36443 DPRINTK(2, "damaged PDU on %d.%d.%d\n",
36444 fore200e->atm_dev->number,
36445 entry->rpd->atm_header.vpi, entry->rpd->atm_header.vci);
36446 - atomic_inc(&vcc->stats->rx_err);
36447 + atomic_inc_unchecked(&vcc->stats->rx_err);
36448 }
36449 }
36450
36451 @@ -1655,7 +1655,7 @@ fore200e_send(struct atm_vcc *vcc, struct sk_buff *skb)
36452 goto retry_here;
36453 }
36454
36455 - atomic_inc(&vcc->stats->tx_err);
36456 + atomic_inc_unchecked(&vcc->stats->tx_err);
36457
36458 fore200e->tx_sat++;
36459 DPRINTK(2, "tx queue of device %s is saturated, PDU dropped - heartbeat is %08x\n",
36460 diff --git a/drivers/atm/he.c b/drivers/atm/he.c
36461 index 8557adc..3fb5d55 100644
36462 --- a/drivers/atm/he.c
36463 +++ b/drivers/atm/he.c
36464 @@ -1691,7 +1691,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
36465
36466 if (RBRQ_HBUF_ERR(he_dev->rbrq_head)) {
36467 hprintk("HBUF_ERR! (cid 0x%x)\n", cid);
36468 - atomic_inc(&vcc->stats->rx_drop);
36469 + atomic_inc_unchecked(&vcc->stats->rx_drop);
36470 goto return_host_buffers;
36471 }
36472
36473 @@ -1718,7 +1718,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
36474 RBRQ_LEN_ERR(he_dev->rbrq_head)
36475 ? "LEN_ERR" : "",
36476 vcc->vpi, vcc->vci);
36477 - atomic_inc(&vcc->stats->rx_err);
36478 + atomic_inc_unchecked(&vcc->stats->rx_err);
36479 goto return_host_buffers;
36480 }
36481
36482 @@ -1770,7 +1770,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
36483 vcc->push(vcc, skb);
36484 spin_lock(&he_dev->global_lock);
36485
36486 - atomic_inc(&vcc->stats->rx);
36487 + atomic_inc_unchecked(&vcc->stats->rx);
36488
36489 return_host_buffers:
36490 ++pdus_assembled;
36491 @@ -2096,7 +2096,7 @@ __enqueue_tpd(struct he_dev *he_dev, struct he_tpd *tpd, unsigned cid)
36492 tpd->vcc->pop(tpd->vcc, tpd->skb);
36493 else
36494 dev_kfree_skb_any(tpd->skb);
36495 - atomic_inc(&tpd->vcc->stats->tx_err);
36496 + atomic_inc_unchecked(&tpd->vcc->stats->tx_err);
36497 }
36498 pci_pool_free(he_dev->tpd_pool, tpd, TPD_ADDR(tpd->status));
36499 return;
36500 @@ -2508,7 +2508,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
36501 vcc->pop(vcc, skb);
36502 else
36503 dev_kfree_skb_any(skb);
36504 - atomic_inc(&vcc->stats->tx_err);
36505 + atomic_inc_unchecked(&vcc->stats->tx_err);
36506 return -EINVAL;
36507 }
36508
36509 @@ -2519,7 +2519,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
36510 vcc->pop(vcc, skb);
36511 else
36512 dev_kfree_skb_any(skb);
36513 - atomic_inc(&vcc->stats->tx_err);
36514 + atomic_inc_unchecked(&vcc->stats->tx_err);
36515 return -EINVAL;
36516 }
36517 #endif
36518 @@ -2531,7 +2531,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
36519 vcc->pop(vcc, skb);
36520 else
36521 dev_kfree_skb_any(skb);
36522 - atomic_inc(&vcc->stats->tx_err);
36523 + atomic_inc_unchecked(&vcc->stats->tx_err);
36524 spin_unlock_irqrestore(&he_dev->global_lock, flags);
36525 return -ENOMEM;
36526 }
36527 @@ -2573,7 +2573,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
36528 vcc->pop(vcc, skb);
36529 else
36530 dev_kfree_skb_any(skb);
36531 - atomic_inc(&vcc->stats->tx_err);
36532 + atomic_inc_unchecked(&vcc->stats->tx_err);
36533 spin_unlock_irqrestore(&he_dev->global_lock, flags);
36534 return -ENOMEM;
36535 }
36536 @@ -2604,7 +2604,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
36537 __enqueue_tpd(he_dev, tpd, cid);
36538 spin_unlock_irqrestore(&he_dev->global_lock, flags);
36539
36540 - atomic_inc(&vcc->stats->tx);
36541 + atomic_inc_unchecked(&vcc->stats->tx);
36542
36543 return 0;
36544 }
36545 diff --git a/drivers/atm/horizon.c b/drivers/atm/horizon.c
36546 index 1dc0519..1aadaf7 100644
36547 --- a/drivers/atm/horizon.c
36548 +++ b/drivers/atm/horizon.c
36549 @@ -1034,7 +1034,7 @@ static void rx_schedule (hrz_dev * dev, int irq) {
36550 {
36551 struct atm_vcc * vcc = ATM_SKB(skb)->vcc;
36552 // VC layer stats
36553 - atomic_inc(&vcc->stats->rx);
36554 + atomic_inc_unchecked(&vcc->stats->rx);
36555 __net_timestamp(skb);
36556 // end of our responsibility
36557 vcc->push (vcc, skb);
36558 @@ -1186,7 +1186,7 @@ static void tx_schedule (hrz_dev * const dev, int irq) {
36559 dev->tx_iovec = NULL;
36560
36561 // VC layer stats
36562 - atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
36563 + atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
36564
36565 // free the skb
36566 hrz_kfree_skb (skb);
36567 diff --git a/drivers/atm/idt77252.c b/drivers/atm/idt77252.c
36568 index 1bdf104..9dc44b1 100644
36569 --- a/drivers/atm/idt77252.c
36570 +++ b/drivers/atm/idt77252.c
36571 @@ -812,7 +812,7 @@ drain_scq(struct idt77252_dev *card, struct vc_map *vc)
36572 else
36573 dev_kfree_skb(skb);
36574
36575 - atomic_inc(&vcc->stats->tx);
36576 + atomic_inc_unchecked(&vcc->stats->tx);
36577 }
36578
36579 atomic_dec(&scq->used);
36580 @@ -1075,13 +1075,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
36581 if ((sb = dev_alloc_skb(64)) == NULL) {
36582 printk("%s: Can't allocate buffers for aal0.\n",
36583 card->name);
36584 - atomic_add(i, &vcc->stats->rx_drop);
36585 + atomic_add_unchecked(i, &vcc->stats->rx_drop);
36586 break;
36587 }
36588 if (!atm_charge(vcc, sb->truesize)) {
36589 RXPRINTK("%s: atm_charge() dropped aal0 packets.\n",
36590 card->name);
36591 - atomic_add(i - 1, &vcc->stats->rx_drop);
36592 + atomic_add_unchecked(i - 1, &vcc->stats->rx_drop);
36593 dev_kfree_skb(sb);
36594 break;
36595 }
36596 @@ -1098,7 +1098,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
36597 ATM_SKB(sb)->vcc = vcc;
36598 __net_timestamp(sb);
36599 vcc->push(vcc, sb);
36600 - atomic_inc(&vcc->stats->rx);
36601 + atomic_inc_unchecked(&vcc->stats->rx);
36602
36603 cell += ATM_CELL_PAYLOAD;
36604 }
36605 @@ -1135,13 +1135,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
36606 "(CDC: %08x)\n",
36607 card->name, len, rpp->len, readl(SAR_REG_CDC));
36608 recycle_rx_pool_skb(card, rpp);
36609 - atomic_inc(&vcc->stats->rx_err);
36610 + atomic_inc_unchecked(&vcc->stats->rx_err);
36611 return;
36612 }
36613 if (stat & SAR_RSQE_CRC) {
36614 RXPRINTK("%s: AAL5 CRC error.\n", card->name);
36615 recycle_rx_pool_skb(card, rpp);
36616 - atomic_inc(&vcc->stats->rx_err);
36617 + atomic_inc_unchecked(&vcc->stats->rx_err);
36618 return;
36619 }
36620 if (skb_queue_len(&rpp->queue) > 1) {
36621 @@ -1152,7 +1152,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
36622 RXPRINTK("%s: Can't alloc RX skb.\n",
36623 card->name);
36624 recycle_rx_pool_skb(card, rpp);
36625 - atomic_inc(&vcc->stats->rx_err);
36626 + atomic_inc_unchecked(&vcc->stats->rx_err);
36627 return;
36628 }
36629 if (!atm_charge(vcc, skb->truesize)) {
36630 @@ -1171,7 +1171,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
36631 __net_timestamp(skb);
36632
36633 vcc->push(vcc, skb);
36634 - atomic_inc(&vcc->stats->rx);
36635 + atomic_inc_unchecked(&vcc->stats->rx);
36636
36637 return;
36638 }
36639 @@ -1193,7 +1193,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
36640 __net_timestamp(skb);
36641
36642 vcc->push(vcc, skb);
36643 - atomic_inc(&vcc->stats->rx);
36644 + atomic_inc_unchecked(&vcc->stats->rx);
36645
36646 if (skb->truesize > SAR_FB_SIZE_3)
36647 add_rx_skb(card, 3, SAR_FB_SIZE_3, 1);
36648 @@ -1304,14 +1304,14 @@ idt77252_rx_raw(struct idt77252_dev *card)
36649 if (vcc->qos.aal != ATM_AAL0) {
36650 RPRINTK("%s: raw cell for non AAL0 vc %u.%u\n",
36651 card->name, vpi, vci);
36652 - atomic_inc(&vcc->stats->rx_drop);
36653 + atomic_inc_unchecked(&vcc->stats->rx_drop);
36654 goto drop;
36655 }
36656
36657 if ((sb = dev_alloc_skb(64)) == NULL) {
36658 printk("%s: Can't allocate buffers for AAL0.\n",
36659 card->name);
36660 - atomic_inc(&vcc->stats->rx_err);
36661 + atomic_inc_unchecked(&vcc->stats->rx_err);
36662 goto drop;
36663 }
36664
36665 @@ -1330,7 +1330,7 @@ idt77252_rx_raw(struct idt77252_dev *card)
36666 ATM_SKB(sb)->vcc = vcc;
36667 __net_timestamp(sb);
36668 vcc->push(vcc, sb);
36669 - atomic_inc(&vcc->stats->rx);
36670 + atomic_inc_unchecked(&vcc->stats->rx);
36671
36672 drop:
36673 skb_pull(queue, 64);
36674 @@ -1955,13 +1955,13 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
36675
36676 if (vc == NULL) {
36677 printk("%s: NULL connection in send().\n", card->name);
36678 - atomic_inc(&vcc->stats->tx_err);
36679 + atomic_inc_unchecked(&vcc->stats->tx_err);
36680 dev_kfree_skb(skb);
36681 return -EINVAL;
36682 }
36683 if (!test_bit(VCF_TX, &vc->flags)) {
36684 printk("%s: Trying to transmit on a non-tx VC.\n", card->name);
36685 - atomic_inc(&vcc->stats->tx_err);
36686 + atomic_inc_unchecked(&vcc->stats->tx_err);
36687 dev_kfree_skb(skb);
36688 return -EINVAL;
36689 }
36690 @@ -1973,14 +1973,14 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
36691 break;
36692 default:
36693 printk("%s: Unsupported AAL: %d\n", card->name, vcc->qos.aal);
36694 - atomic_inc(&vcc->stats->tx_err);
36695 + atomic_inc_unchecked(&vcc->stats->tx_err);
36696 dev_kfree_skb(skb);
36697 return -EINVAL;
36698 }
36699
36700 if (skb_shinfo(skb)->nr_frags != 0) {
36701 printk("%s: No scatter-gather yet.\n", card->name);
36702 - atomic_inc(&vcc->stats->tx_err);
36703 + atomic_inc_unchecked(&vcc->stats->tx_err);
36704 dev_kfree_skb(skb);
36705 return -EINVAL;
36706 }
36707 @@ -1988,7 +1988,7 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
36708
36709 err = queue_skb(card, vc, skb, oam);
36710 if (err) {
36711 - atomic_inc(&vcc->stats->tx_err);
36712 + atomic_inc_unchecked(&vcc->stats->tx_err);
36713 dev_kfree_skb(skb);
36714 return err;
36715 }
36716 @@ -2011,7 +2011,7 @@ idt77252_send_oam(struct atm_vcc *vcc, void *cell, int flags)
36717 skb = dev_alloc_skb(64);
36718 if (!skb) {
36719 printk("%s: Out of memory in send_oam().\n", card->name);
36720 - atomic_inc(&vcc->stats->tx_err);
36721 + atomic_inc_unchecked(&vcc->stats->tx_err);
36722 return -ENOMEM;
36723 }
36724 atomic_add(skb->truesize, &sk_atm(vcc)->sk_wmem_alloc);
36725 diff --git a/drivers/atm/iphase.c b/drivers/atm/iphase.c
36726 index 4217f29..88f547a 100644
36727 --- a/drivers/atm/iphase.c
36728 +++ b/drivers/atm/iphase.c
36729 @@ -1145,7 +1145,7 @@ static int rx_pkt(struct atm_dev *dev)
36730 status = (u_short) (buf_desc_ptr->desc_mode);
36731 if (status & (RX_CER | RX_PTE | RX_OFL))
36732 {
36733 - atomic_inc(&vcc->stats->rx_err);
36734 + atomic_inc_unchecked(&vcc->stats->rx_err);
36735 IF_ERR(printk("IA: bad packet, dropping it");)
36736 if (status & RX_CER) {
36737 IF_ERR(printk(" cause: packet CRC error\n");)
36738 @@ -1168,7 +1168,7 @@ static int rx_pkt(struct atm_dev *dev)
36739 len = dma_addr - buf_addr;
36740 if (len > iadev->rx_buf_sz) {
36741 printk("Over %d bytes sdu received, dropped!!!\n", iadev->rx_buf_sz);
36742 - atomic_inc(&vcc->stats->rx_err);
36743 + atomic_inc_unchecked(&vcc->stats->rx_err);
36744 goto out_free_desc;
36745 }
36746
36747 @@ -1318,7 +1318,7 @@ static void rx_dle_intr(struct atm_dev *dev)
36748 ia_vcc = INPH_IA_VCC(vcc);
36749 if (ia_vcc == NULL)
36750 {
36751 - atomic_inc(&vcc->stats->rx_err);
36752 + atomic_inc_unchecked(&vcc->stats->rx_err);
36753 atm_return(vcc, skb->truesize);
36754 dev_kfree_skb_any(skb);
36755 goto INCR_DLE;
36756 @@ -1330,7 +1330,7 @@ static void rx_dle_intr(struct atm_dev *dev)
36757 if ((length > iadev->rx_buf_sz) || (length >
36758 (skb->len - sizeof(struct cpcs_trailer))))
36759 {
36760 - atomic_inc(&vcc->stats->rx_err);
36761 + atomic_inc_unchecked(&vcc->stats->rx_err);
36762 IF_ERR(printk("rx_dle_intr: Bad AAL5 trailer %d (skb len %d)",
36763 length, skb->len);)
36764 atm_return(vcc, skb->truesize);
36765 @@ -1346,7 +1346,7 @@ static void rx_dle_intr(struct atm_dev *dev)
36766
36767 IF_RX(printk("rx_dle_intr: skb push");)
36768 vcc->push(vcc,skb);
36769 - atomic_inc(&vcc->stats->rx);
36770 + atomic_inc_unchecked(&vcc->stats->rx);
36771 iadev->rx_pkt_cnt++;
36772 }
36773 INCR_DLE:
36774 @@ -2826,15 +2826,15 @@ static int ia_ioctl(struct atm_dev *dev, unsigned int cmd, void __user *arg)
36775 {
36776 struct k_sonet_stats *stats;
36777 stats = &PRIV(_ia_dev[board])->sonet_stats;
36778 - printk("section_bip: %d\n", atomic_read(&stats->section_bip));
36779 - printk("line_bip : %d\n", atomic_read(&stats->line_bip));
36780 - printk("path_bip : %d\n", atomic_read(&stats->path_bip));
36781 - printk("line_febe : %d\n", atomic_read(&stats->line_febe));
36782 - printk("path_febe : %d\n", atomic_read(&stats->path_febe));
36783 - printk("corr_hcs : %d\n", atomic_read(&stats->corr_hcs));
36784 - printk("uncorr_hcs : %d\n", atomic_read(&stats->uncorr_hcs));
36785 - printk("tx_cells : %d\n", atomic_read(&stats->tx_cells));
36786 - printk("rx_cells : %d\n", atomic_read(&stats->rx_cells));
36787 + printk("section_bip: %d\n", atomic_read_unchecked(&stats->section_bip));
36788 + printk("line_bip : %d\n", atomic_read_unchecked(&stats->line_bip));
36789 + printk("path_bip : %d\n", atomic_read_unchecked(&stats->path_bip));
36790 + printk("line_febe : %d\n", atomic_read_unchecked(&stats->line_febe));
36791 + printk("path_febe : %d\n", atomic_read_unchecked(&stats->path_febe));
36792 + printk("corr_hcs : %d\n", atomic_read_unchecked(&stats->corr_hcs));
36793 + printk("uncorr_hcs : %d\n", atomic_read_unchecked(&stats->uncorr_hcs));
36794 + printk("tx_cells : %d\n", atomic_read_unchecked(&stats->tx_cells));
36795 + printk("rx_cells : %d\n", atomic_read_unchecked(&stats->rx_cells));
36796 }
36797 ia_cmds.status = 0;
36798 break;
36799 @@ -2939,7 +2939,7 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
36800 if ((desc == 0) || (desc > iadev->num_tx_desc))
36801 {
36802 IF_ERR(printk(DEV_LABEL "invalid desc for send: %d\n", desc);)
36803 - atomic_inc(&vcc->stats->tx);
36804 + atomic_inc_unchecked(&vcc->stats->tx);
36805 if (vcc->pop)
36806 vcc->pop(vcc, skb);
36807 else
36808 @@ -3044,14 +3044,14 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
36809 ATM_DESC(skb) = vcc->vci;
36810 skb_queue_tail(&iadev->tx_dma_q, skb);
36811
36812 - atomic_inc(&vcc->stats->tx);
36813 + atomic_inc_unchecked(&vcc->stats->tx);
36814 iadev->tx_pkt_cnt++;
36815 /* Increment transaction counter */
36816 writel(2, iadev->dma+IPHASE5575_TX_COUNTER);
36817
36818 #if 0
36819 /* add flow control logic */
36820 - if (atomic_read(&vcc->stats->tx) % 20 == 0) {
36821 + if (atomic_read_unchecked(&vcc->stats->tx) % 20 == 0) {
36822 if (iavcc->vc_desc_cnt > 10) {
36823 vcc->tx_quota = vcc->tx_quota * 3 / 4;
36824 printk("Tx1: vcc->tx_quota = %d \n", (u32)vcc->tx_quota );
36825 diff --git a/drivers/atm/lanai.c b/drivers/atm/lanai.c
36826 index fa7d701..1e404c7 100644
36827 --- a/drivers/atm/lanai.c
36828 +++ b/drivers/atm/lanai.c
36829 @@ -1303,7 +1303,7 @@ static void lanai_send_one_aal5(struct lanai_dev *lanai,
36830 vcc_tx_add_aal5_trailer(lvcc, skb->len, 0, 0);
36831 lanai_endtx(lanai, lvcc);
36832 lanai_free_skb(lvcc->tx.atmvcc, skb);
36833 - atomic_inc(&lvcc->tx.atmvcc->stats->tx);
36834 + atomic_inc_unchecked(&lvcc->tx.atmvcc->stats->tx);
36835 }
36836
36837 /* Try to fill the buffer - don't call unless there is backlog */
36838 @@ -1426,7 +1426,7 @@ static void vcc_rx_aal5(struct lanai_vcc *lvcc, int endptr)
36839 ATM_SKB(skb)->vcc = lvcc->rx.atmvcc;
36840 __net_timestamp(skb);
36841 lvcc->rx.atmvcc->push(lvcc->rx.atmvcc, skb);
36842 - atomic_inc(&lvcc->rx.atmvcc->stats->rx);
36843 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx);
36844 out:
36845 lvcc->rx.buf.ptr = end;
36846 cardvcc_write(lvcc, endptr, vcc_rxreadptr);
36847 @@ -1667,7 +1667,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
36848 DPRINTK("(itf %d) got RX service entry 0x%X for non-AAL5 "
36849 "vcc %d\n", lanai->number, (unsigned int) s, vci);
36850 lanai->stats.service_rxnotaal5++;
36851 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
36852 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
36853 return 0;
36854 }
36855 if (likely(!(s & (SERVICE_TRASH | SERVICE_STREAM | SERVICE_CRCERR)))) {
36856 @@ -1679,7 +1679,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
36857 int bytes;
36858 read_unlock(&vcc_sklist_lock);
36859 DPRINTK("got trashed rx pdu on vci %d\n", vci);
36860 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
36861 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
36862 lvcc->stats.x.aal5.service_trash++;
36863 bytes = (SERVICE_GET_END(s) * 16) -
36864 (((unsigned long) lvcc->rx.buf.ptr) -
36865 @@ -1691,7 +1691,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
36866 }
36867 if (s & SERVICE_STREAM) {
36868 read_unlock(&vcc_sklist_lock);
36869 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
36870 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
36871 lvcc->stats.x.aal5.service_stream++;
36872 printk(KERN_ERR DEV_LABEL "(itf %d): Got AAL5 stream "
36873 "PDU on VCI %d!\n", lanai->number, vci);
36874 @@ -1699,7 +1699,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
36875 return 0;
36876 }
36877 DPRINTK("got rx crc error on vci %d\n", vci);
36878 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
36879 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
36880 lvcc->stats.x.aal5.service_rxcrc++;
36881 lvcc->rx.buf.ptr = &lvcc->rx.buf.start[SERVICE_GET_END(s) * 4];
36882 cardvcc_write(lvcc, SERVICE_GET_END(s), vcc_rxreadptr);
36883 diff --git a/drivers/atm/nicstar.c b/drivers/atm/nicstar.c
36884 index 5aca5f4..ce3a6b0 100644
36885 --- a/drivers/atm/nicstar.c
36886 +++ b/drivers/atm/nicstar.c
36887 @@ -1640,7 +1640,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
36888 if ((vc = (vc_map *) vcc->dev_data) == NULL) {
36889 printk("nicstar%d: vcc->dev_data == NULL on ns_send().\n",
36890 card->index);
36891 - atomic_inc(&vcc->stats->tx_err);
36892 + atomic_inc_unchecked(&vcc->stats->tx_err);
36893 dev_kfree_skb_any(skb);
36894 return -EINVAL;
36895 }
36896 @@ -1648,7 +1648,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
36897 if (!vc->tx) {
36898 printk("nicstar%d: Trying to transmit on a non-tx VC.\n",
36899 card->index);
36900 - atomic_inc(&vcc->stats->tx_err);
36901 + atomic_inc_unchecked(&vcc->stats->tx_err);
36902 dev_kfree_skb_any(skb);
36903 return -EINVAL;
36904 }
36905 @@ -1656,14 +1656,14 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
36906 if (vcc->qos.aal != ATM_AAL5 && vcc->qos.aal != ATM_AAL0) {
36907 printk("nicstar%d: Only AAL0 and AAL5 are supported.\n",
36908 card->index);
36909 - atomic_inc(&vcc->stats->tx_err);
36910 + atomic_inc_unchecked(&vcc->stats->tx_err);
36911 dev_kfree_skb_any(skb);
36912 return -EINVAL;
36913 }
36914
36915 if (skb_shinfo(skb)->nr_frags != 0) {
36916 printk("nicstar%d: No scatter-gather yet.\n", card->index);
36917 - atomic_inc(&vcc->stats->tx_err);
36918 + atomic_inc_unchecked(&vcc->stats->tx_err);
36919 dev_kfree_skb_any(skb);
36920 return -EINVAL;
36921 }
36922 @@ -1711,11 +1711,11 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
36923 }
36924
36925 if (push_scqe(card, vc, scq, &scqe, skb) != 0) {
36926 - atomic_inc(&vcc->stats->tx_err);
36927 + atomic_inc_unchecked(&vcc->stats->tx_err);
36928 dev_kfree_skb_any(skb);
36929 return -EIO;
36930 }
36931 - atomic_inc(&vcc->stats->tx);
36932 + atomic_inc_unchecked(&vcc->stats->tx);
36933
36934 return 0;
36935 }
36936 @@ -2032,14 +2032,14 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
36937 printk
36938 ("nicstar%d: Can't allocate buffers for aal0.\n",
36939 card->index);
36940 - atomic_add(i, &vcc->stats->rx_drop);
36941 + atomic_add_unchecked(i, &vcc->stats->rx_drop);
36942 break;
36943 }
36944 if (!atm_charge(vcc, sb->truesize)) {
36945 RXPRINTK
36946 ("nicstar%d: atm_charge() dropped aal0 packets.\n",
36947 card->index);
36948 - atomic_add(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
36949 + atomic_add_unchecked(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
36950 dev_kfree_skb_any(sb);
36951 break;
36952 }
36953 @@ -2054,7 +2054,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
36954 ATM_SKB(sb)->vcc = vcc;
36955 __net_timestamp(sb);
36956 vcc->push(vcc, sb);
36957 - atomic_inc(&vcc->stats->rx);
36958 + atomic_inc_unchecked(&vcc->stats->rx);
36959 cell += ATM_CELL_PAYLOAD;
36960 }
36961
36962 @@ -2071,7 +2071,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
36963 if (iovb == NULL) {
36964 printk("nicstar%d: Out of iovec buffers.\n",
36965 card->index);
36966 - atomic_inc(&vcc->stats->rx_drop);
36967 + atomic_inc_unchecked(&vcc->stats->rx_drop);
36968 recycle_rx_buf(card, skb);
36969 return;
36970 }
36971 @@ -2095,7 +2095,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
36972 small or large buffer itself. */
36973 } else if (NS_PRV_IOVCNT(iovb) >= NS_MAX_IOVECS) {
36974 printk("nicstar%d: received too big AAL5 SDU.\n", card->index);
36975 - atomic_inc(&vcc->stats->rx_err);
36976 + atomic_inc_unchecked(&vcc->stats->rx_err);
36977 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
36978 NS_MAX_IOVECS);
36979 NS_PRV_IOVCNT(iovb) = 0;
36980 @@ -2115,7 +2115,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
36981 ("nicstar%d: Expected a small buffer, and this is not one.\n",
36982 card->index);
36983 which_list(card, skb);
36984 - atomic_inc(&vcc->stats->rx_err);
36985 + atomic_inc_unchecked(&vcc->stats->rx_err);
36986 recycle_rx_buf(card, skb);
36987 vc->rx_iov = NULL;
36988 recycle_iov_buf(card, iovb);
36989 @@ -2128,7 +2128,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
36990 ("nicstar%d: Expected a large buffer, and this is not one.\n",
36991 card->index);
36992 which_list(card, skb);
36993 - atomic_inc(&vcc->stats->rx_err);
36994 + atomic_inc_unchecked(&vcc->stats->rx_err);
36995 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
36996 NS_PRV_IOVCNT(iovb));
36997 vc->rx_iov = NULL;
36998 @@ -2151,7 +2151,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
36999 printk(" - PDU size mismatch.\n");
37000 else
37001 printk(".\n");
37002 - atomic_inc(&vcc->stats->rx_err);
37003 + atomic_inc_unchecked(&vcc->stats->rx_err);
37004 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
37005 NS_PRV_IOVCNT(iovb));
37006 vc->rx_iov = NULL;
37007 @@ -2165,7 +2165,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37008 /* skb points to a small buffer */
37009 if (!atm_charge(vcc, skb->truesize)) {
37010 push_rxbufs(card, skb);
37011 - atomic_inc(&vcc->stats->rx_drop);
37012 + atomic_inc_unchecked(&vcc->stats->rx_drop);
37013 } else {
37014 skb_put(skb, len);
37015 dequeue_sm_buf(card, skb);
37016 @@ -2175,7 +2175,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37017 ATM_SKB(skb)->vcc = vcc;
37018 __net_timestamp(skb);
37019 vcc->push(vcc, skb);
37020 - atomic_inc(&vcc->stats->rx);
37021 + atomic_inc_unchecked(&vcc->stats->rx);
37022 }
37023 } else if (NS_PRV_IOVCNT(iovb) == 2) { /* One small plus one large buffer */
37024 struct sk_buff *sb;
37025 @@ -2186,7 +2186,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37026 if (len <= NS_SMBUFSIZE) {
37027 if (!atm_charge(vcc, sb->truesize)) {
37028 push_rxbufs(card, sb);
37029 - atomic_inc(&vcc->stats->rx_drop);
37030 + atomic_inc_unchecked(&vcc->stats->rx_drop);
37031 } else {
37032 skb_put(sb, len);
37033 dequeue_sm_buf(card, sb);
37034 @@ -2196,7 +2196,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37035 ATM_SKB(sb)->vcc = vcc;
37036 __net_timestamp(sb);
37037 vcc->push(vcc, sb);
37038 - atomic_inc(&vcc->stats->rx);
37039 + atomic_inc_unchecked(&vcc->stats->rx);
37040 }
37041
37042 push_rxbufs(card, skb);
37043 @@ -2205,7 +2205,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37044
37045 if (!atm_charge(vcc, skb->truesize)) {
37046 push_rxbufs(card, skb);
37047 - atomic_inc(&vcc->stats->rx_drop);
37048 + atomic_inc_unchecked(&vcc->stats->rx_drop);
37049 } else {
37050 dequeue_lg_buf(card, skb);
37051 #ifdef NS_USE_DESTRUCTORS
37052 @@ -2218,7 +2218,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37053 ATM_SKB(skb)->vcc = vcc;
37054 __net_timestamp(skb);
37055 vcc->push(vcc, skb);
37056 - atomic_inc(&vcc->stats->rx);
37057 + atomic_inc_unchecked(&vcc->stats->rx);
37058 }
37059
37060 push_rxbufs(card, sb);
37061 @@ -2239,7 +2239,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37062 printk
37063 ("nicstar%d: Out of huge buffers.\n",
37064 card->index);
37065 - atomic_inc(&vcc->stats->rx_drop);
37066 + atomic_inc_unchecked(&vcc->stats->rx_drop);
37067 recycle_iovec_rx_bufs(card,
37068 (struct iovec *)
37069 iovb->data,
37070 @@ -2290,7 +2290,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37071 card->hbpool.count++;
37072 } else
37073 dev_kfree_skb_any(hb);
37074 - atomic_inc(&vcc->stats->rx_drop);
37075 + atomic_inc_unchecked(&vcc->stats->rx_drop);
37076 } else {
37077 /* Copy the small buffer to the huge buffer */
37078 sb = (struct sk_buff *)iov->iov_base;
37079 @@ -2327,7 +2327,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37080 #endif /* NS_USE_DESTRUCTORS */
37081 __net_timestamp(hb);
37082 vcc->push(vcc, hb);
37083 - atomic_inc(&vcc->stats->rx);
37084 + atomic_inc_unchecked(&vcc->stats->rx);
37085 }
37086 }
37087
37088 diff --git a/drivers/atm/solos-pci.c b/drivers/atm/solos-pci.c
37089 index 32784d1..4a8434a 100644
37090 --- a/drivers/atm/solos-pci.c
37091 +++ b/drivers/atm/solos-pci.c
37092 @@ -838,7 +838,7 @@ void solos_bh(unsigned long card_arg)
37093 }
37094 atm_charge(vcc, skb->truesize);
37095 vcc->push(vcc, skb);
37096 - atomic_inc(&vcc->stats->rx);
37097 + atomic_inc_unchecked(&vcc->stats->rx);
37098 break;
37099
37100 case PKT_STATUS:
37101 @@ -1116,7 +1116,7 @@ static uint32_t fpga_tx(struct solos_card *card)
37102 vcc = SKB_CB(oldskb)->vcc;
37103
37104 if (vcc) {
37105 - atomic_inc(&vcc->stats->tx);
37106 + atomic_inc_unchecked(&vcc->stats->tx);
37107 solos_pop(vcc, oldskb);
37108 } else {
37109 dev_kfree_skb_irq(oldskb);
37110 diff --git a/drivers/atm/suni.c b/drivers/atm/suni.c
37111 index 0215934..ce9f5b1 100644
37112 --- a/drivers/atm/suni.c
37113 +++ b/drivers/atm/suni.c
37114 @@ -49,8 +49,8 @@ static DEFINE_SPINLOCK(sunis_lock);
37115
37116
37117 #define ADD_LIMITED(s,v) \
37118 - atomic_add((v),&stats->s); \
37119 - if (atomic_read(&stats->s) < 0) atomic_set(&stats->s,INT_MAX);
37120 + atomic_add_unchecked((v),&stats->s); \
37121 + if (atomic_read_unchecked(&stats->s) < 0) atomic_set_unchecked(&stats->s,INT_MAX);
37122
37123
37124 static void suni_hz(unsigned long from_timer)
37125 diff --git a/drivers/atm/uPD98402.c b/drivers/atm/uPD98402.c
37126 index 5120a96..e2572bd 100644
37127 --- a/drivers/atm/uPD98402.c
37128 +++ b/drivers/atm/uPD98402.c
37129 @@ -42,7 +42,7 @@ static int fetch_stats(struct atm_dev *dev,struct sonet_stats __user *arg,int ze
37130 struct sonet_stats tmp;
37131 int error = 0;
37132
37133 - atomic_add(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
37134 + atomic_add_unchecked(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
37135 sonet_copy_stats(&PRIV(dev)->sonet_stats,&tmp);
37136 if (arg) error = copy_to_user(arg,&tmp,sizeof(tmp));
37137 if (zero && !error) {
37138 @@ -161,9 +161,9 @@ static int uPD98402_ioctl(struct atm_dev *dev,unsigned int cmd,void __user *arg)
37139
37140
37141 #define ADD_LIMITED(s,v) \
37142 - { atomic_add(GET(v),&PRIV(dev)->sonet_stats.s); \
37143 - if (atomic_read(&PRIV(dev)->sonet_stats.s) < 0) \
37144 - atomic_set(&PRIV(dev)->sonet_stats.s,INT_MAX); }
37145 + { atomic_add_unchecked(GET(v),&PRIV(dev)->sonet_stats.s); \
37146 + if (atomic_read_unchecked(&PRIV(dev)->sonet_stats.s) < 0) \
37147 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.s,INT_MAX); }
37148
37149
37150 static void stat_event(struct atm_dev *dev)
37151 @@ -194,7 +194,7 @@ static void uPD98402_int(struct atm_dev *dev)
37152 if (reason & uPD98402_INT_PFM) stat_event(dev);
37153 if (reason & uPD98402_INT_PCO) {
37154 (void) GET(PCOCR); /* clear interrupt cause */
37155 - atomic_add(GET(HECCT),
37156 + atomic_add_unchecked(GET(HECCT),
37157 &PRIV(dev)->sonet_stats.uncorr_hcs);
37158 }
37159 if ((reason & uPD98402_INT_RFO) &&
37160 @@ -222,9 +222,9 @@ static int uPD98402_start(struct atm_dev *dev)
37161 PUT(~(uPD98402_INT_PFM | uPD98402_INT_ALM | uPD98402_INT_RFO |
37162 uPD98402_INT_LOS),PIMR); /* enable them */
37163 (void) fetch_stats(dev,NULL,1); /* clear kernel counters */
37164 - atomic_set(&PRIV(dev)->sonet_stats.corr_hcs,-1);
37165 - atomic_set(&PRIV(dev)->sonet_stats.tx_cells,-1);
37166 - atomic_set(&PRIV(dev)->sonet_stats.rx_cells,-1);
37167 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.corr_hcs,-1);
37168 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.tx_cells,-1);
37169 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.rx_cells,-1);
37170 return 0;
37171 }
37172
37173 diff --git a/drivers/atm/zatm.c b/drivers/atm/zatm.c
37174 index 969c3c2..9b72956 100644
37175 --- a/drivers/atm/zatm.c
37176 +++ b/drivers/atm/zatm.c
37177 @@ -459,7 +459,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
37178 }
37179 if (!size) {
37180 dev_kfree_skb_irq(skb);
37181 - if (vcc) atomic_inc(&vcc->stats->rx_err);
37182 + if (vcc) atomic_inc_unchecked(&vcc->stats->rx_err);
37183 continue;
37184 }
37185 if (!atm_charge(vcc,skb->truesize)) {
37186 @@ -469,7 +469,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
37187 skb->len = size;
37188 ATM_SKB(skb)->vcc = vcc;
37189 vcc->push(vcc,skb);
37190 - atomic_inc(&vcc->stats->rx);
37191 + atomic_inc_unchecked(&vcc->stats->rx);
37192 }
37193 zout(pos & 0xffff,MTA(mbx));
37194 #if 0 /* probably a stupid idea */
37195 @@ -733,7 +733,7 @@ if (*ZATM_PRV_DSC(skb) != (uPD98401_TXPD_V | uPD98401_TXPD_DP |
37196 skb_queue_head(&zatm_vcc->backlog,skb);
37197 break;
37198 }
37199 - atomic_inc(&vcc->stats->tx);
37200 + atomic_inc_unchecked(&vcc->stats->tx);
37201 wake_up(&zatm_vcc->tx_wait);
37202 }
37203
37204 diff --git a/drivers/base/bus.c b/drivers/base/bus.c
37205 index 73f6c29..b0c0e13 100644
37206 --- a/drivers/base/bus.c
37207 +++ b/drivers/base/bus.c
37208 @@ -1115,7 +1115,7 @@ int subsys_interface_register(struct subsys_interface *sif)
37209 return -EINVAL;
37210
37211 mutex_lock(&subsys->p->mutex);
37212 - list_add_tail(&sif->node, &subsys->p->interfaces);
37213 + pax_list_add_tail((struct list_head *)&sif->node, &subsys->p->interfaces);
37214 if (sif->add_dev) {
37215 subsys_dev_iter_init(&iter, subsys, NULL, NULL);
37216 while ((dev = subsys_dev_iter_next(&iter)))
37217 @@ -1140,7 +1140,7 @@ void subsys_interface_unregister(struct subsys_interface *sif)
37218 subsys = sif->subsys;
37219
37220 mutex_lock(&subsys->p->mutex);
37221 - list_del_init(&sif->node);
37222 + pax_list_del_init((struct list_head *)&sif->node);
37223 if (sif->remove_dev) {
37224 subsys_dev_iter_init(&iter, subsys, NULL, NULL);
37225 while ((dev = subsys_dev_iter_next(&iter)))
37226 diff --git a/drivers/base/devtmpfs.c b/drivers/base/devtmpfs.c
37227 index 0f38201..6c2b444 100644
37228 --- a/drivers/base/devtmpfs.c
37229 +++ b/drivers/base/devtmpfs.c
37230 @@ -354,7 +354,7 @@ int devtmpfs_mount(const char *mntdir)
37231 if (!thread)
37232 return 0;
37233
37234 - err = sys_mount("devtmpfs", (char *)mntdir, "devtmpfs", MS_SILENT, NULL);
37235 + err = sys_mount((char __force_user *)"devtmpfs", (char __force_user *)mntdir, (char __force_user *)"devtmpfs", MS_SILENT, NULL);
37236 if (err)
37237 printk(KERN_INFO "devtmpfs: error mounting %i\n", err);
37238 else
37239 @@ -380,11 +380,11 @@ static int devtmpfsd(void *p)
37240 *err = sys_unshare(CLONE_NEWNS);
37241 if (*err)
37242 goto out;
37243 - *err = sys_mount("devtmpfs", "/", "devtmpfs", MS_SILENT, options);
37244 + *err = sys_mount((char __force_user *)"devtmpfs", (char __force_user *)"/", (char __force_user *)"devtmpfs", MS_SILENT, (char __force_user *)options);
37245 if (*err)
37246 goto out;
37247 - sys_chdir("/.."); /* will traverse into overmounted root */
37248 - sys_chroot(".");
37249 + sys_chdir((char __force_user *)"/.."); /* will traverse into overmounted root */
37250 + sys_chroot((char __force_user *)".");
37251 complete(&setup_done);
37252 while (1) {
37253 spin_lock(&req_lock);
37254 diff --git a/drivers/base/node.c b/drivers/base/node.c
37255 index bc9f43b..29703b8 100644
37256 --- a/drivers/base/node.c
37257 +++ b/drivers/base/node.c
37258 @@ -620,7 +620,7 @@ static ssize_t print_nodes_state(enum node_states state, char *buf)
37259 struct node_attr {
37260 struct device_attribute attr;
37261 enum node_states state;
37262 -};
37263 +} __do_const;
37264
37265 static ssize_t show_node_state(struct device *dev,
37266 struct device_attribute *attr, char *buf)
37267 diff --git a/drivers/base/power/domain.c b/drivers/base/power/domain.c
37268 index bfb8955..4ebff34 100644
37269 --- a/drivers/base/power/domain.c
37270 +++ b/drivers/base/power/domain.c
37271 @@ -1809,9 +1809,9 @@ int __pm_genpd_remove_callbacks(struct device *dev, bool clear_td)
37272
37273 if (dev->power.subsys_data->domain_data) {
37274 gpd_data = to_gpd_data(dev->power.subsys_data->domain_data);
37275 - gpd_data->ops = (struct gpd_dev_ops){ NULL };
37276 + memset(&gpd_data->ops, 0, sizeof(gpd_data->ops));
37277 if (clear_td)
37278 - gpd_data->td = (struct gpd_timing_data){ 0 };
37279 + memset(&gpd_data->td, 0, sizeof(gpd_data->td));
37280
37281 if (--gpd_data->refcount == 0) {
37282 dev->power.subsys_data->domain_data = NULL;
37283 @@ -1850,7 +1850,7 @@ int pm_genpd_attach_cpuidle(struct generic_pm_domain *genpd, int state)
37284 {
37285 struct cpuidle_driver *cpuidle_drv;
37286 struct gpd_cpu_data *cpu_data;
37287 - struct cpuidle_state *idle_state;
37288 + cpuidle_state_no_const *idle_state;
37289 int ret = 0;
37290
37291 if (IS_ERR_OR_NULL(genpd) || state < 0)
37292 @@ -1918,7 +1918,7 @@ int pm_genpd_name_attach_cpuidle(const char *name, int state)
37293 int pm_genpd_detach_cpuidle(struct generic_pm_domain *genpd)
37294 {
37295 struct gpd_cpu_data *cpu_data;
37296 - struct cpuidle_state *idle_state;
37297 + cpuidle_state_no_const *idle_state;
37298 int ret = 0;
37299
37300 if (IS_ERR_OR_NULL(genpd))
37301 diff --git a/drivers/base/power/sysfs.c b/drivers/base/power/sysfs.c
37302 index 03e089a..0e9560c 100644
37303 --- a/drivers/base/power/sysfs.c
37304 +++ b/drivers/base/power/sysfs.c
37305 @@ -185,7 +185,7 @@ static ssize_t rtpm_status_show(struct device *dev,
37306 return -EIO;
37307 }
37308 }
37309 - return sprintf(buf, p);
37310 + return sprintf(buf, "%s", p);
37311 }
37312
37313 static DEVICE_ATTR(runtime_status, 0444, rtpm_status_show, NULL);
37314 diff --git a/drivers/base/power/wakeup.c b/drivers/base/power/wakeup.c
37315 index 2d56f41..8830f19 100644
37316 --- a/drivers/base/power/wakeup.c
37317 +++ b/drivers/base/power/wakeup.c
37318 @@ -29,14 +29,14 @@ bool events_check_enabled __read_mostly;
37319 * They need to be modified together atomically, so it's better to use one
37320 * atomic variable to hold them both.
37321 */
37322 -static atomic_t combined_event_count = ATOMIC_INIT(0);
37323 +static atomic_unchecked_t combined_event_count = ATOMIC_INIT(0);
37324
37325 #define IN_PROGRESS_BITS (sizeof(int) * 4)
37326 #define MAX_IN_PROGRESS ((1 << IN_PROGRESS_BITS) - 1)
37327
37328 static void split_counters(unsigned int *cnt, unsigned int *inpr)
37329 {
37330 - unsigned int comb = atomic_read(&combined_event_count);
37331 + unsigned int comb = atomic_read_unchecked(&combined_event_count);
37332
37333 *cnt = (comb >> IN_PROGRESS_BITS);
37334 *inpr = comb & MAX_IN_PROGRESS;
37335 @@ -395,7 +395,7 @@ static void wakeup_source_activate(struct wakeup_source *ws)
37336 ws->start_prevent_time = ws->last_time;
37337
37338 /* Increment the counter of events in progress. */
37339 - cec = atomic_inc_return(&combined_event_count);
37340 + cec = atomic_inc_return_unchecked(&combined_event_count);
37341
37342 trace_wakeup_source_activate(ws->name, cec);
37343 }
37344 @@ -521,7 +521,7 @@ static void wakeup_source_deactivate(struct wakeup_source *ws)
37345 * Increment the counter of registered wakeup events and decrement the
37346 * couter of wakeup events in progress simultaneously.
37347 */
37348 - cec = atomic_add_return(MAX_IN_PROGRESS, &combined_event_count);
37349 + cec = atomic_add_return_unchecked(MAX_IN_PROGRESS, &combined_event_count);
37350 trace_wakeup_source_deactivate(ws->name, cec);
37351
37352 split_counters(&cnt, &inpr);
37353 diff --git a/drivers/base/syscore.c b/drivers/base/syscore.c
37354 index e8d11b6..7b1b36f 100644
37355 --- a/drivers/base/syscore.c
37356 +++ b/drivers/base/syscore.c
37357 @@ -21,7 +21,7 @@ static DEFINE_MUTEX(syscore_ops_lock);
37358 void register_syscore_ops(struct syscore_ops *ops)
37359 {
37360 mutex_lock(&syscore_ops_lock);
37361 - list_add_tail(&ops->node, &syscore_ops_list);
37362 + pax_list_add_tail((struct list_head *)&ops->node, &syscore_ops_list);
37363 mutex_unlock(&syscore_ops_lock);
37364 }
37365 EXPORT_SYMBOL_GPL(register_syscore_ops);
37366 @@ -33,7 +33,7 @@ EXPORT_SYMBOL_GPL(register_syscore_ops);
37367 void unregister_syscore_ops(struct syscore_ops *ops)
37368 {
37369 mutex_lock(&syscore_ops_lock);
37370 - list_del(&ops->node);
37371 + pax_list_del((struct list_head *)&ops->node);
37372 mutex_unlock(&syscore_ops_lock);
37373 }
37374 EXPORT_SYMBOL_GPL(unregister_syscore_ops);
37375 diff --git a/drivers/block/cciss.c b/drivers/block/cciss.c
37376 index b35fc4f..c902870 100644
37377 --- a/drivers/block/cciss.c
37378 +++ b/drivers/block/cciss.c
37379 @@ -3011,7 +3011,7 @@ static void start_io(ctlr_info_t *h)
37380 while (!list_empty(&h->reqQ)) {
37381 c = list_entry(h->reqQ.next, CommandList_struct, list);
37382 /* can't do anything if fifo is full */
37383 - if ((h->access.fifo_full(h))) {
37384 + if ((h->access->fifo_full(h))) {
37385 dev_warn(&h->pdev->dev, "fifo full\n");
37386 break;
37387 }
37388 @@ -3021,7 +3021,7 @@ static void start_io(ctlr_info_t *h)
37389 h->Qdepth--;
37390
37391 /* Tell the controller execute command */
37392 - h->access.submit_command(h, c);
37393 + h->access->submit_command(h, c);
37394
37395 /* Put job onto the completed Q */
37396 addQ(&h->cmpQ, c);
37397 @@ -3447,17 +3447,17 @@ startio:
37398
37399 static inline unsigned long get_next_completion(ctlr_info_t *h)
37400 {
37401 - return h->access.command_completed(h);
37402 + return h->access->command_completed(h);
37403 }
37404
37405 static inline int interrupt_pending(ctlr_info_t *h)
37406 {
37407 - return h->access.intr_pending(h);
37408 + return h->access->intr_pending(h);
37409 }
37410
37411 static inline long interrupt_not_for_us(ctlr_info_t *h)
37412 {
37413 - return ((h->access.intr_pending(h) == 0) ||
37414 + return ((h->access->intr_pending(h) == 0) ||
37415 (h->interrupts_enabled == 0));
37416 }
37417
37418 @@ -3490,7 +3490,7 @@ static inline u32 next_command(ctlr_info_t *h)
37419 u32 a;
37420
37421 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
37422 - return h->access.command_completed(h);
37423 + return h->access->command_completed(h);
37424
37425 if ((*(h->reply_pool_head) & 1) == (h->reply_pool_wraparound)) {
37426 a = *(h->reply_pool_head); /* Next cmd in ring buffer */
37427 @@ -4047,7 +4047,7 @@ static void cciss_put_controller_into_performant_mode(ctlr_info_t *h)
37428 trans_support & CFGTBL_Trans_use_short_tags);
37429
37430 /* Change the access methods to the performant access methods */
37431 - h->access = SA5_performant_access;
37432 + h->access = &SA5_performant_access;
37433 h->transMethod = CFGTBL_Trans_Performant;
37434
37435 return;
37436 @@ -4327,7 +4327,7 @@ static int cciss_pci_init(ctlr_info_t *h)
37437 if (prod_index < 0)
37438 return -ENODEV;
37439 h->product_name = products[prod_index].product_name;
37440 - h->access = *(products[prod_index].access);
37441 + h->access = products[prod_index].access;
37442
37443 if (cciss_board_disabled(h)) {
37444 dev_warn(&h->pdev->dev, "controller appears to be disabled\n");
37445 @@ -5059,7 +5059,7 @@ reinit_after_soft_reset:
37446 }
37447
37448 /* make sure the board interrupts are off */
37449 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
37450 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
37451 rc = cciss_request_irq(h, do_cciss_msix_intr, do_cciss_intx);
37452 if (rc)
37453 goto clean2;
37454 @@ -5109,7 +5109,7 @@ reinit_after_soft_reset:
37455 * fake ones to scoop up any residual completions.
37456 */
37457 spin_lock_irqsave(&h->lock, flags);
37458 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
37459 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
37460 spin_unlock_irqrestore(&h->lock, flags);
37461 free_irq(h->intr[h->intr_mode], h);
37462 rc = cciss_request_irq(h, cciss_msix_discard_completions,
37463 @@ -5129,9 +5129,9 @@ reinit_after_soft_reset:
37464 dev_info(&h->pdev->dev, "Board READY.\n");
37465 dev_info(&h->pdev->dev,
37466 "Waiting for stale completions to drain.\n");
37467 - h->access.set_intr_mask(h, CCISS_INTR_ON);
37468 + h->access->set_intr_mask(h, CCISS_INTR_ON);
37469 msleep(10000);
37470 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
37471 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
37472
37473 rc = controller_reset_failed(h->cfgtable);
37474 if (rc)
37475 @@ -5154,7 +5154,7 @@ reinit_after_soft_reset:
37476 cciss_scsi_setup(h);
37477
37478 /* Turn the interrupts on so we can service requests */
37479 - h->access.set_intr_mask(h, CCISS_INTR_ON);
37480 + h->access->set_intr_mask(h, CCISS_INTR_ON);
37481
37482 /* Get the firmware version */
37483 inq_buff = kzalloc(sizeof(InquiryData_struct), GFP_KERNEL);
37484 @@ -5226,7 +5226,7 @@ static void cciss_shutdown(struct pci_dev *pdev)
37485 kfree(flush_buf);
37486 if (return_code != IO_OK)
37487 dev_warn(&h->pdev->dev, "Error flushing cache\n");
37488 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
37489 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
37490 free_irq(h->intr[h->intr_mode], h);
37491 }
37492
37493 diff --git a/drivers/block/cciss.h b/drivers/block/cciss.h
37494 index 7fda30e..2f27946 100644
37495 --- a/drivers/block/cciss.h
37496 +++ b/drivers/block/cciss.h
37497 @@ -101,7 +101,7 @@ struct ctlr_info
37498 /* information about each logical volume */
37499 drive_info_struct *drv[CISS_MAX_LUN];
37500
37501 - struct access_method access;
37502 + struct access_method *access;
37503
37504 /* queue and queue Info */
37505 struct list_head reqQ;
37506 @@ -402,27 +402,27 @@ static bool SA5_performant_intr_pending(ctlr_info_t *h)
37507 }
37508
37509 static struct access_method SA5_access = {
37510 - SA5_submit_command,
37511 - SA5_intr_mask,
37512 - SA5_fifo_full,
37513 - SA5_intr_pending,
37514 - SA5_completed,
37515 + .submit_command = SA5_submit_command,
37516 + .set_intr_mask = SA5_intr_mask,
37517 + .fifo_full = SA5_fifo_full,
37518 + .intr_pending = SA5_intr_pending,
37519 + .command_completed = SA5_completed,
37520 };
37521
37522 static struct access_method SA5B_access = {
37523 - SA5_submit_command,
37524 - SA5B_intr_mask,
37525 - SA5_fifo_full,
37526 - SA5B_intr_pending,
37527 - SA5_completed,
37528 + .submit_command = SA5_submit_command,
37529 + .set_intr_mask = SA5B_intr_mask,
37530 + .fifo_full = SA5_fifo_full,
37531 + .intr_pending = SA5B_intr_pending,
37532 + .command_completed = SA5_completed,
37533 };
37534
37535 static struct access_method SA5_performant_access = {
37536 - SA5_submit_command,
37537 - SA5_performant_intr_mask,
37538 - SA5_fifo_full,
37539 - SA5_performant_intr_pending,
37540 - SA5_performant_completed,
37541 + .submit_command = SA5_submit_command,
37542 + .set_intr_mask = SA5_performant_intr_mask,
37543 + .fifo_full = SA5_fifo_full,
37544 + .intr_pending = SA5_performant_intr_pending,
37545 + .command_completed = SA5_performant_completed,
37546 };
37547
37548 struct board_type {
37549 diff --git a/drivers/block/cpqarray.c b/drivers/block/cpqarray.c
37550 index 2b94403..fd6ad1f 100644
37551 --- a/drivers/block/cpqarray.c
37552 +++ b/drivers/block/cpqarray.c
37553 @@ -404,7 +404,7 @@ static int cpqarray_register_ctlr(int i, struct pci_dev *pdev)
37554 if (register_blkdev(COMPAQ_SMART2_MAJOR+i, hba[i]->devname)) {
37555 goto Enomem4;
37556 }
37557 - hba[i]->access.set_intr_mask(hba[i], 0);
37558 + hba[i]->access->set_intr_mask(hba[i], 0);
37559 if (request_irq(hba[i]->intr, do_ida_intr,
37560 IRQF_DISABLED|IRQF_SHARED, hba[i]->devname, hba[i]))
37561 {
37562 @@ -459,7 +459,7 @@ static int cpqarray_register_ctlr(int i, struct pci_dev *pdev)
37563 add_timer(&hba[i]->timer);
37564
37565 /* Enable IRQ now that spinlock and rate limit timer are set up */
37566 - hba[i]->access.set_intr_mask(hba[i], FIFO_NOT_EMPTY);
37567 + hba[i]->access->set_intr_mask(hba[i], FIFO_NOT_EMPTY);
37568
37569 for(j=0; j<NWD; j++) {
37570 struct gendisk *disk = ida_gendisk[i][j];
37571 @@ -694,7 +694,7 @@ DBGINFO(
37572 for(i=0; i<NR_PRODUCTS; i++) {
37573 if (board_id == products[i].board_id) {
37574 c->product_name = products[i].product_name;
37575 - c->access = *(products[i].access);
37576 + c->access = products[i].access;
37577 break;
37578 }
37579 }
37580 @@ -792,7 +792,7 @@ static int cpqarray_eisa_detect(void)
37581 hba[ctlr]->intr = intr;
37582 sprintf(hba[ctlr]->devname, "ida%d", nr_ctlr);
37583 hba[ctlr]->product_name = products[j].product_name;
37584 - hba[ctlr]->access = *(products[j].access);
37585 + hba[ctlr]->access = products[j].access;
37586 hba[ctlr]->ctlr = ctlr;
37587 hba[ctlr]->board_id = board_id;
37588 hba[ctlr]->pci_dev = NULL; /* not PCI */
37589 @@ -978,7 +978,7 @@ static void start_io(ctlr_info_t *h)
37590
37591 while((c = h->reqQ) != NULL) {
37592 /* Can't do anything if we're busy */
37593 - if (h->access.fifo_full(h) == 0)
37594 + if (h->access->fifo_full(h) == 0)
37595 return;
37596
37597 /* Get the first entry from the request Q */
37598 @@ -986,7 +986,7 @@ static void start_io(ctlr_info_t *h)
37599 h->Qdepth--;
37600
37601 /* Tell the controller to do our bidding */
37602 - h->access.submit_command(h, c);
37603 + h->access->submit_command(h, c);
37604
37605 /* Get onto the completion Q */
37606 addQ(&h->cmpQ, c);
37607 @@ -1048,7 +1048,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
37608 unsigned long flags;
37609 __u32 a,a1;
37610
37611 - istat = h->access.intr_pending(h);
37612 + istat = h->access->intr_pending(h);
37613 /* Is this interrupt for us? */
37614 if (istat == 0)
37615 return IRQ_NONE;
37616 @@ -1059,7 +1059,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
37617 */
37618 spin_lock_irqsave(IDA_LOCK(h->ctlr), flags);
37619 if (istat & FIFO_NOT_EMPTY) {
37620 - while((a = h->access.command_completed(h))) {
37621 + while((a = h->access->command_completed(h))) {
37622 a1 = a; a &= ~3;
37623 if ((c = h->cmpQ) == NULL)
37624 {
37625 @@ -1448,11 +1448,11 @@ static int sendcmd(
37626 /*
37627 * Disable interrupt
37628 */
37629 - info_p->access.set_intr_mask(info_p, 0);
37630 + info_p->access->set_intr_mask(info_p, 0);
37631 /* Make sure there is room in the command FIFO */
37632 /* Actually it should be completely empty at this time. */
37633 for (i = 200000; i > 0; i--) {
37634 - temp = info_p->access.fifo_full(info_p);
37635 + temp = info_p->access->fifo_full(info_p);
37636 if (temp != 0) {
37637 break;
37638 }
37639 @@ -1465,7 +1465,7 @@ DBG(
37640 /*
37641 * Send the cmd
37642 */
37643 - info_p->access.submit_command(info_p, c);
37644 + info_p->access->submit_command(info_p, c);
37645 complete = pollcomplete(ctlr);
37646
37647 pci_unmap_single(info_p->pci_dev, (dma_addr_t) c->req.sg[0].addr,
37648 @@ -1548,9 +1548,9 @@ static int revalidate_allvol(ctlr_info_t *host)
37649 * we check the new geometry. Then turn interrupts back on when
37650 * we're done.
37651 */
37652 - host->access.set_intr_mask(host, 0);
37653 + host->access->set_intr_mask(host, 0);
37654 getgeometry(ctlr);
37655 - host->access.set_intr_mask(host, FIFO_NOT_EMPTY);
37656 + host->access->set_intr_mask(host, FIFO_NOT_EMPTY);
37657
37658 for(i=0; i<NWD; i++) {
37659 struct gendisk *disk = ida_gendisk[ctlr][i];
37660 @@ -1590,7 +1590,7 @@ static int pollcomplete(int ctlr)
37661 /* Wait (up to 2 seconds) for a command to complete */
37662
37663 for (i = 200000; i > 0; i--) {
37664 - done = hba[ctlr]->access.command_completed(hba[ctlr]);
37665 + done = hba[ctlr]->access->command_completed(hba[ctlr]);
37666 if (done == 0) {
37667 udelay(10); /* a short fixed delay */
37668 } else
37669 diff --git a/drivers/block/cpqarray.h b/drivers/block/cpqarray.h
37670 index be73e9d..7fbf140 100644
37671 --- a/drivers/block/cpqarray.h
37672 +++ b/drivers/block/cpqarray.h
37673 @@ -99,7 +99,7 @@ struct ctlr_info {
37674 drv_info_t drv[NWD];
37675 struct proc_dir_entry *proc;
37676
37677 - struct access_method access;
37678 + struct access_method *access;
37679
37680 cmdlist_t *reqQ;
37681 cmdlist_t *cmpQ;
37682 diff --git a/drivers/block/drbd/drbd_int.h b/drivers/block/drbd/drbd_int.h
37683 index 0e06f0c..c47b81d 100644
37684 --- a/drivers/block/drbd/drbd_int.h
37685 +++ b/drivers/block/drbd/drbd_int.h
37686 @@ -582,7 +582,7 @@ struct drbd_epoch {
37687 struct drbd_tconn *tconn;
37688 struct list_head list;
37689 unsigned int barrier_nr;
37690 - atomic_t epoch_size; /* increased on every request added. */
37691 + atomic_unchecked_t epoch_size; /* increased on every request added. */
37692 atomic_t active; /* increased on every req. added, and dec on every finished. */
37693 unsigned long flags;
37694 };
37695 @@ -1022,7 +1022,7 @@ struct drbd_conf {
37696 unsigned int al_tr_number;
37697 int al_tr_cycle;
37698 wait_queue_head_t seq_wait;
37699 - atomic_t packet_seq;
37700 + atomic_unchecked_t packet_seq;
37701 unsigned int peer_seq;
37702 spinlock_t peer_seq_lock;
37703 unsigned int minor;
37704 @@ -1573,7 +1573,7 @@ static inline int drbd_setsockopt(struct socket *sock, int level, int optname,
37705 char __user *uoptval;
37706 int err;
37707
37708 - uoptval = (char __user __force *)optval;
37709 + uoptval = (char __force_user *)optval;
37710
37711 set_fs(KERNEL_DS);
37712 if (level == SOL_SOCKET)
37713 diff --git a/drivers/block/drbd/drbd_interval.c b/drivers/block/drbd/drbd_interval.c
37714 index 89c497c..9c736ae 100644
37715 --- a/drivers/block/drbd/drbd_interval.c
37716 +++ b/drivers/block/drbd/drbd_interval.c
37717 @@ -67,9 +67,9 @@ static void augment_rotate(struct rb_node *rb_old, struct rb_node *rb_new)
37718 }
37719
37720 static const struct rb_augment_callbacks augment_callbacks = {
37721 - augment_propagate,
37722 - augment_copy,
37723 - augment_rotate,
37724 + .propagate = augment_propagate,
37725 + .copy = augment_copy,
37726 + .rotate = augment_rotate,
37727 };
37728
37729 /**
37730 diff --git a/drivers/block/drbd/drbd_main.c b/drivers/block/drbd/drbd_main.c
37731 index 9e3818b..7b64c92 100644
37732 --- a/drivers/block/drbd/drbd_main.c
37733 +++ b/drivers/block/drbd/drbd_main.c
37734 @@ -1317,7 +1317,7 @@ static int _drbd_send_ack(struct drbd_conf *mdev, enum drbd_packet cmd,
37735 p->sector = sector;
37736 p->block_id = block_id;
37737 p->blksize = blksize;
37738 - p->seq_num = cpu_to_be32(atomic_inc_return(&mdev->packet_seq));
37739 + p->seq_num = cpu_to_be32(atomic_inc_return_unchecked(&mdev->packet_seq));
37740 return drbd_send_command(mdev, sock, cmd, sizeof(*p), NULL, 0);
37741 }
37742
37743 @@ -1619,7 +1619,7 @@ int drbd_send_dblock(struct drbd_conf *mdev, struct drbd_request *req)
37744 return -EIO;
37745 p->sector = cpu_to_be64(req->i.sector);
37746 p->block_id = (unsigned long)req;
37747 - p->seq_num = cpu_to_be32(atomic_inc_return(&mdev->packet_seq));
37748 + p->seq_num = cpu_to_be32(atomic_inc_return_unchecked(&mdev->packet_seq));
37749 dp_flags = bio_flags_to_wire(mdev, req->master_bio->bi_rw);
37750 if (mdev->state.conn >= C_SYNC_SOURCE &&
37751 mdev->state.conn <= C_PAUSED_SYNC_T)
37752 @@ -2574,8 +2574,8 @@ void conn_destroy(struct kref *kref)
37753 {
37754 struct drbd_tconn *tconn = container_of(kref, struct drbd_tconn, kref);
37755
37756 - if (atomic_read(&tconn->current_epoch->epoch_size) != 0)
37757 - conn_err(tconn, "epoch_size:%d\n", atomic_read(&tconn->current_epoch->epoch_size));
37758 + if (atomic_read_unchecked(&tconn->current_epoch->epoch_size) != 0)
37759 + conn_err(tconn, "epoch_size:%d\n", atomic_read_unchecked(&tconn->current_epoch->epoch_size));
37760 kfree(tconn->current_epoch);
37761
37762 idr_destroy(&tconn->volumes);
37763 diff --git a/drivers/block/drbd/drbd_nl.c b/drivers/block/drbd/drbd_nl.c
37764 index c706d50..5e1b472 100644
37765 --- a/drivers/block/drbd/drbd_nl.c
37766 +++ b/drivers/block/drbd/drbd_nl.c
37767 @@ -3440,7 +3440,7 @@ out:
37768
37769 void drbd_bcast_event(struct drbd_conf *mdev, const struct sib_info *sib)
37770 {
37771 - static atomic_t drbd_genl_seq = ATOMIC_INIT(2); /* two. */
37772 + static atomic_unchecked_t drbd_genl_seq = ATOMIC_INIT(2); /* two. */
37773 struct sk_buff *msg;
37774 struct drbd_genlmsghdr *d_out;
37775 unsigned seq;
37776 @@ -3453,7 +3453,7 @@ void drbd_bcast_event(struct drbd_conf *mdev, const struct sib_info *sib)
37777 return;
37778 }
37779
37780 - seq = atomic_inc_return(&drbd_genl_seq);
37781 + seq = atomic_inc_return_unchecked(&drbd_genl_seq);
37782 msg = genlmsg_new(NLMSG_GOODSIZE, GFP_NOIO);
37783 if (!msg)
37784 goto failed;
37785 diff --git a/drivers/block/drbd/drbd_receiver.c b/drivers/block/drbd/drbd_receiver.c
37786 index 6fa6673..b7f97e9 100644
37787 --- a/drivers/block/drbd/drbd_receiver.c
37788 +++ b/drivers/block/drbd/drbd_receiver.c
37789 @@ -834,7 +834,7 @@ int drbd_connected(struct drbd_conf *mdev)
37790 {
37791 int err;
37792
37793 - atomic_set(&mdev->packet_seq, 0);
37794 + atomic_set_unchecked(&mdev->packet_seq, 0);
37795 mdev->peer_seq = 0;
37796
37797 mdev->state_mutex = mdev->tconn->agreed_pro_version < 100 ?
37798 @@ -1193,7 +1193,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_tconn *tconn,
37799 do {
37800 next_epoch = NULL;
37801
37802 - epoch_size = atomic_read(&epoch->epoch_size);
37803 + epoch_size = atomic_read_unchecked(&epoch->epoch_size);
37804
37805 switch (ev & ~EV_CLEANUP) {
37806 case EV_PUT:
37807 @@ -1233,7 +1233,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_tconn *tconn,
37808 rv = FE_DESTROYED;
37809 } else {
37810 epoch->flags = 0;
37811 - atomic_set(&epoch->epoch_size, 0);
37812 + atomic_set_unchecked(&epoch->epoch_size, 0);
37813 /* atomic_set(&epoch->active, 0); is already zero */
37814 if (rv == FE_STILL_LIVE)
37815 rv = FE_RECYCLED;
37816 @@ -1451,7 +1451,7 @@ static int receive_Barrier(struct drbd_tconn *tconn, struct packet_info *pi)
37817 conn_wait_active_ee_empty(tconn);
37818 drbd_flush(tconn);
37819
37820 - if (atomic_read(&tconn->current_epoch->epoch_size)) {
37821 + if (atomic_read_unchecked(&tconn->current_epoch->epoch_size)) {
37822 epoch = kmalloc(sizeof(struct drbd_epoch), GFP_NOIO);
37823 if (epoch)
37824 break;
37825 @@ -1464,11 +1464,11 @@ static int receive_Barrier(struct drbd_tconn *tconn, struct packet_info *pi)
37826 }
37827
37828 epoch->flags = 0;
37829 - atomic_set(&epoch->epoch_size, 0);
37830 + atomic_set_unchecked(&epoch->epoch_size, 0);
37831 atomic_set(&epoch->active, 0);
37832
37833 spin_lock(&tconn->epoch_lock);
37834 - if (atomic_read(&tconn->current_epoch->epoch_size)) {
37835 + if (atomic_read_unchecked(&tconn->current_epoch->epoch_size)) {
37836 list_add(&epoch->list, &tconn->current_epoch->list);
37837 tconn->current_epoch = epoch;
37838 tconn->epochs++;
37839 @@ -2163,7 +2163,7 @@ static int receive_Data(struct drbd_tconn *tconn, struct packet_info *pi)
37840
37841 err = wait_for_and_update_peer_seq(mdev, peer_seq);
37842 drbd_send_ack_dp(mdev, P_NEG_ACK, p, pi->size);
37843 - atomic_inc(&tconn->current_epoch->epoch_size);
37844 + atomic_inc_unchecked(&tconn->current_epoch->epoch_size);
37845 err2 = drbd_drain_block(mdev, pi->size);
37846 if (!err)
37847 err = err2;
37848 @@ -2197,7 +2197,7 @@ static int receive_Data(struct drbd_tconn *tconn, struct packet_info *pi)
37849
37850 spin_lock(&tconn->epoch_lock);
37851 peer_req->epoch = tconn->current_epoch;
37852 - atomic_inc(&peer_req->epoch->epoch_size);
37853 + atomic_inc_unchecked(&peer_req->epoch->epoch_size);
37854 atomic_inc(&peer_req->epoch->active);
37855 spin_unlock(&tconn->epoch_lock);
37856
37857 @@ -4344,7 +4344,7 @@ struct data_cmd {
37858 int expect_payload;
37859 size_t pkt_size;
37860 int (*fn)(struct drbd_tconn *, struct packet_info *);
37861 -};
37862 +} __do_const;
37863
37864 static struct data_cmd drbd_cmd_handler[] = {
37865 [P_DATA] = { 1, sizeof(struct p_data), receive_Data },
37866 @@ -4464,7 +4464,7 @@ static void conn_disconnect(struct drbd_tconn *tconn)
37867 if (!list_empty(&tconn->current_epoch->list))
37868 conn_err(tconn, "ASSERTION FAILED: tconn->current_epoch->list not empty\n");
37869 /* ok, no more ee's on the fly, it is safe to reset the epoch_size */
37870 - atomic_set(&tconn->current_epoch->epoch_size, 0);
37871 + atomic_set_unchecked(&tconn->current_epoch->epoch_size, 0);
37872 tconn->send.seen_any_write_yet = false;
37873
37874 conn_info(tconn, "Connection closed\n");
37875 @@ -5220,7 +5220,7 @@ static int tconn_finish_peer_reqs(struct drbd_tconn *tconn)
37876 struct asender_cmd {
37877 size_t pkt_size;
37878 int (*fn)(struct drbd_tconn *tconn, struct packet_info *);
37879 -};
37880 +} __do_const;
37881
37882 static struct asender_cmd asender_tbl[] = {
37883 [P_PING] = { 0, got_Ping },
37884 diff --git a/drivers/block/loop.c b/drivers/block/loop.c
37885 index c8dac73..1800093 100644
37886 --- a/drivers/block/loop.c
37887 +++ b/drivers/block/loop.c
37888 @@ -232,7 +232,7 @@ static int __do_lo_send_write(struct file *file,
37889
37890 file_start_write(file);
37891 set_fs(get_ds());
37892 - bw = file->f_op->write(file, buf, len, &pos);
37893 + bw = file->f_op->write(file, (const char __force_user *)buf, len, &pos);
37894 set_fs(old_fs);
37895 file_end_write(file);
37896 if (likely(bw == len))
37897 diff --git a/drivers/block/null_blk.c b/drivers/block/null_blk.c
37898 index 83a598e..2de5ce3 100644
37899 --- a/drivers/block/null_blk.c
37900 +++ b/drivers/block/null_blk.c
37901 @@ -407,14 +407,24 @@ static int null_init_hctx(struct blk_mq_hw_ctx *hctx, void *data,
37902 return 0;
37903 }
37904
37905 -static struct blk_mq_ops null_mq_ops = {
37906 - .queue_rq = null_queue_rq,
37907 - .map_queue = blk_mq_map_queue,
37908 +static struct blk_mq_ops null_mq_single_ops = {
37909 + .queue_rq = null_queue_rq,
37910 + .map_queue = blk_mq_map_queue,
37911 .init_hctx = null_init_hctx,
37912 + .alloc_hctx = blk_mq_alloc_single_hw_queue,
37913 + .free_hctx = blk_mq_free_single_hw_queue,
37914 +};
37915 +
37916 +static struct blk_mq_ops null_mq_per_node_ops = {
37917 + .queue_rq = null_queue_rq,
37918 + .map_queue = blk_mq_map_queue,
37919 + .init_hctx = null_init_hctx,
37920 + .alloc_hctx = null_alloc_hctx,
37921 + .free_hctx = null_free_hctx,
37922 };
37923
37924 static struct blk_mq_reg null_mq_reg = {
37925 - .ops = &null_mq_ops,
37926 + .ops = &null_mq_single_ops,
37927 .queue_depth = 64,
37928 .cmd_size = sizeof(struct nullb_cmd),
37929 .flags = BLK_MQ_F_SHOULD_MERGE,
37930 @@ -545,13 +555,8 @@ static int null_add_dev(void)
37931 null_mq_reg.queue_depth = hw_queue_depth;
37932 null_mq_reg.nr_hw_queues = submit_queues;
37933
37934 - if (use_per_node_hctx) {
37935 - null_mq_reg.ops->alloc_hctx = null_alloc_hctx;
37936 - null_mq_reg.ops->free_hctx = null_free_hctx;
37937 - } else {
37938 - null_mq_reg.ops->alloc_hctx = blk_mq_alloc_single_hw_queue;
37939 - null_mq_reg.ops->free_hctx = blk_mq_free_single_hw_queue;
37940 - }
37941 + if (use_per_node_hctx)
37942 + null_mq_reg.ops = &null_mq_per_node_ops;
37943
37944 nullb->q = blk_mq_init_queue(&null_mq_reg, nullb);
37945 } else if (queue_mode == NULL_Q_BIO) {
37946 diff --git a/drivers/block/pktcdvd.c b/drivers/block/pktcdvd.c
37947 index ff8668c..f62167a 100644
37948 --- a/drivers/block/pktcdvd.c
37949 +++ b/drivers/block/pktcdvd.c
37950 @@ -108,7 +108,7 @@ static int pkt_seq_show(struct seq_file *m, void *p);
37951
37952 static sector_t get_zone(sector_t sector, struct pktcdvd_device *pd)
37953 {
37954 - return (sector + pd->offset) & ~(sector_t)(pd->settings.size - 1);
37955 + return (sector + pd->offset) & ~(sector_t)(pd->settings.size - 1UL);
37956 }
37957
37958 /*
37959 @@ -1883,7 +1883,7 @@ static noinline_for_stack int pkt_probe_settings(struct pktcdvd_device *pd)
37960 return -EROFS;
37961 }
37962 pd->settings.fp = ti.fp;
37963 - pd->offset = (be32_to_cpu(ti.track_start) << 2) & (pd->settings.size - 1);
37964 + pd->offset = (be32_to_cpu(ti.track_start) << 2) & (pd->settings.size - 1UL);
37965
37966 if (ti.nwa_v) {
37967 pd->nwa = be32_to_cpu(ti.next_writable);
37968 diff --git a/drivers/block/smart1,2.h b/drivers/block/smart1,2.h
37969 index e5565fb..71be10b4 100644
37970 --- a/drivers/block/smart1,2.h
37971 +++ b/drivers/block/smart1,2.h
37972 @@ -108,11 +108,11 @@ static unsigned long smart4_intr_pending(ctlr_info_t *h)
37973 }
37974
37975 static struct access_method smart4_access = {
37976 - smart4_submit_command,
37977 - smart4_intr_mask,
37978 - smart4_fifo_full,
37979 - smart4_intr_pending,
37980 - smart4_completed,
37981 + .submit_command = smart4_submit_command,
37982 + .set_intr_mask = smart4_intr_mask,
37983 + .fifo_full = smart4_fifo_full,
37984 + .intr_pending = smart4_intr_pending,
37985 + .command_completed = smart4_completed,
37986 };
37987
37988 /*
37989 @@ -144,11 +144,11 @@ static unsigned long smart2_intr_pending(ctlr_info_t *h)
37990 }
37991
37992 static struct access_method smart2_access = {
37993 - smart2_submit_command,
37994 - smart2_intr_mask,
37995 - smart2_fifo_full,
37996 - smart2_intr_pending,
37997 - smart2_completed,
37998 + .submit_command = smart2_submit_command,
37999 + .set_intr_mask = smart2_intr_mask,
38000 + .fifo_full = smart2_fifo_full,
38001 + .intr_pending = smart2_intr_pending,
38002 + .command_completed = smart2_completed,
38003 };
38004
38005 /*
38006 @@ -180,11 +180,11 @@ static unsigned long smart2e_intr_pending(ctlr_info_t *h)
38007 }
38008
38009 static struct access_method smart2e_access = {
38010 - smart2e_submit_command,
38011 - smart2e_intr_mask,
38012 - smart2e_fifo_full,
38013 - smart2e_intr_pending,
38014 - smart2e_completed,
38015 + .submit_command = smart2e_submit_command,
38016 + .set_intr_mask = smart2e_intr_mask,
38017 + .fifo_full = smart2e_fifo_full,
38018 + .intr_pending = smart2e_intr_pending,
38019 + .command_completed = smart2e_completed,
38020 };
38021
38022 /*
38023 @@ -270,9 +270,9 @@ static unsigned long smart1_intr_pending(ctlr_info_t *h)
38024 }
38025
38026 static struct access_method smart1_access = {
38027 - smart1_submit_command,
38028 - smart1_intr_mask,
38029 - smart1_fifo_full,
38030 - smart1_intr_pending,
38031 - smart1_completed,
38032 + .submit_command = smart1_submit_command,
38033 + .set_intr_mask = smart1_intr_mask,
38034 + .fifo_full = smart1_fifo_full,
38035 + .intr_pending = smart1_intr_pending,
38036 + .command_completed = smart1_completed,
38037 };
38038 diff --git a/drivers/bluetooth/btwilink.c b/drivers/bluetooth/btwilink.c
38039 index f038dba..bb74c08 100644
38040 --- a/drivers/bluetooth/btwilink.c
38041 +++ b/drivers/bluetooth/btwilink.c
38042 @@ -288,7 +288,7 @@ static int ti_st_send_frame(struct hci_dev *hdev, struct sk_buff *skb)
38043
38044 static int bt_ti_probe(struct platform_device *pdev)
38045 {
38046 - static struct ti_st *hst;
38047 + struct ti_st *hst;
38048 struct hci_dev *hdev;
38049 int err;
38050
38051 diff --git a/drivers/bus/arm-cci.c b/drivers/bus/arm-cci.c
38052 index b6739cb..962fd35 100644
38053 --- a/drivers/bus/arm-cci.c
38054 +++ b/drivers/bus/arm-cci.c
38055 @@ -979,7 +979,7 @@ static int cci_probe(void)
38056
38057 nb_cci_ports = cci_config->nb_ace + cci_config->nb_ace_lite;
38058
38059 - ports = kcalloc(sizeof(*ports), nb_cci_ports, GFP_KERNEL);
38060 + ports = kcalloc(nb_cci_ports, sizeof(*ports), GFP_KERNEL);
38061 if (!ports)
38062 return -ENOMEM;
38063
38064 diff --git a/drivers/cdrom/cdrom.c b/drivers/cdrom/cdrom.c
38065 index 8a3aff7..d7538c2 100644
38066 --- a/drivers/cdrom/cdrom.c
38067 +++ b/drivers/cdrom/cdrom.c
38068 @@ -416,7 +416,6 @@ int register_cdrom(struct cdrom_device_info *cdi)
38069 ENSURE(reset, CDC_RESET);
38070 ENSURE(generic_packet, CDC_GENERIC_PACKET);
38071 cdi->mc_flags = 0;
38072 - cdo->n_minors = 0;
38073 cdi->options = CDO_USE_FFLAGS;
38074
38075 if (autoclose==1 && CDROM_CAN(CDC_CLOSE_TRAY))
38076 @@ -436,8 +435,11 @@ int register_cdrom(struct cdrom_device_info *cdi)
38077 else
38078 cdi->cdda_method = CDDA_OLD;
38079
38080 - if (!cdo->generic_packet)
38081 - cdo->generic_packet = cdrom_dummy_generic_packet;
38082 + if (!cdo->generic_packet) {
38083 + pax_open_kernel();
38084 + *(void **)&cdo->generic_packet = cdrom_dummy_generic_packet;
38085 + pax_close_kernel();
38086 + }
38087
38088 cdinfo(CD_REG_UNREG, "drive \"/dev/%s\" registered\n", cdi->name);
38089 mutex_lock(&cdrom_mutex);
38090 @@ -458,7 +460,6 @@ void unregister_cdrom(struct cdrom_device_info *cdi)
38091 if (cdi->exit)
38092 cdi->exit(cdi);
38093
38094 - cdi->ops->n_minors--;
38095 cdinfo(CD_REG_UNREG, "drive \"/dev/%s\" unregistered\n", cdi->name);
38096 }
38097
38098 @@ -2107,7 +2108,7 @@ static int cdrom_read_cdda_old(struct cdrom_device_info *cdi, __u8 __user *ubuf,
38099 */
38100 nr = nframes;
38101 do {
38102 - cgc.buffer = kmalloc(CD_FRAMESIZE_RAW * nr, GFP_KERNEL);
38103 + cgc.buffer = kzalloc(CD_FRAMESIZE_RAW * nr, GFP_KERNEL);
38104 if (cgc.buffer)
38105 break;
38106
38107 @@ -3429,7 +3430,7 @@ static int cdrom_print_info(const char *header, int val, char *info,
38108 struct cdrom_device_info *cdi;
38109 int ret;
38110
38111 - ret = scnprintf(info + *pos, max_size - *pos, header);
38112 + ret = scnprintf(info + *pos, max_size - *pos, "%s", header);
38113 if (!ret)
38114 return 1;
38115
38116 diff --git a/drivers/cdrom/gdrom.c b/drivers/cdrom/gdrom.c
38117 index 5980cb9..6d7bd7e 100644
38118 --- a/drivers/cdrom/gdrom.c
38119 +++ b/drivers/cdrom/gdrom.c
38120 @@ -491,7 +491,6 @@ static struct cdrom_device_ops gdrom_ops = {
38121 .audio_ioctl = gdrom_audio_ioctl,
38122 .capability = CDC_MULTI_SESSION | CDC_MEDIA_CHANGED |
38123 CDC_RESET | CDC_DRIVE_STATUS | CDC_CD_R,
38124 - .n_minors = 1,
38125 };
38126
38127 static int gdrom_bdops_open(struct block_device *bdev, fmode_t mode)
38128 diff --git a/drivers/char/Kconfig b/drivers/char/Kconfig
38129 index fa3243d..8c98297 100644
38130 --- a/drivers/char/Kconfig
38131 +++ b/drivers/char/Kconfig
38132 @@ -8,7 +8,8 @@ source "drivers/tty/Kconfig"
38133
38134 config DEVKMEM
38135 bool "/dev/kmem virtual device support"
38136 - default y
38137 + default n
38138 + depends on !GRKERNSEC_KMEM
38139 help
38140 Say Y here if you want to support the /dev/kmem device. The
38141 /dev/kmem device is rarely used, but can be used for certain
38142 @@ -576,6 +577,7 @@ config DEVPORT
38143 bool
38144 depends on !M68K
38145 depends on ISA || PCI
38146 + depends on !GRKERNSEC_KMEM
38147 default y
38148
38149 source "drivers/s390/char/Kconfig"
38150 diff --git a/drivers/char/agp/compat_ioctl.c b/drivers/char/agp/compat_ioctl.c
38151 index a48e05b..6bac831 100644
38152 --- a/drivers/char/agp/compat_ioctl.c
38153 +++ b/drivers/char/agp/compat_ioctl.c
38154 @@ -108,7 +108,7 @@ static int compat_agpioc_reserve_wrap(struct agp_file_private *priv, void __user
38155 return -ENOMEM;
38156 }
38157
38158 - if (copy_from_user(usegment, (void __user *) ureserve.seg_list,
38159 + if (copy_from_user(usegment, (void __force_user *) ureserve.seg_list,
38160 sizeof(*usegment) * ureserve.seg_count)) {
38161 kfree(usegment);
38162 kfree(ksegment);
38163 diff --git a/drivers/char/agp/frontend.c b/drivers/char/agp/frontend.c
38164 index 1b19239..b87b143 100644
38165 --- a/drivers/char/agp/frontend.c
38166 +++ b/drivers/char/agp/frontend.c
38167 @@ -819,7 +819,7 @@ static int agpioc_reserve_wrap(struct agp_file_private *priv, void __user *arg)
38168 if (copy_from_user(&reserve, arg, sizeof(struct agp_region)))
38169 return -EFAULT;
38170
38171 - if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment))
38172 + if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment_priv))
38173 return -EFAULT;
38174
38175 client = agp_find_client_by_pid(reserve.pid);
38176 @@ -849,7 +849,7 @@ static int agpioc_reserve_wrap(struct agp_file_private *priv, void __user *arg)
38177 if (segment == NULL)
38178 return -ENOMEM;
38179
38180 - if (copy_from_user(segment, (void __user *) reserve.seg_list,
38181 + if (copy_from_user(segment, (void __force_user *) reserve.seg_list,
38182 sizeof(struct agp_segment) * reserve.seg_count)) {
38183 kfree(segment);
38184 return -EFAULT;
38185 diff --git a/drivers/char/genrtc.c b/drivers/char/genrtc.c
38186 index 4f94375..413694e 100644
38187 --- a/drivers/char/genrtc.c
38188 +++ b/drivers/char/genrtc.c
38189 @@ -273,6 +273,7 @@ static int gen_rtc_ioctl(struct file *file,
38190 switch (cmd) {
38191
38192 case RTC_PLL_GET:
38193 + memset(&pll, 0, sizeof(pll));
38194 if (get_rtc_pll(&pll))
38195 return -EINVAL;
38196 else
38197 diff --git a/drivers/char/hpet.c b/drivers/char/hpet.c
38198 index 5d9c31d..c94ccb5 100644
38199 --- a/drivers/char/hpet.c
38200 +++ b/drivers/char/hpet.c
38201 @@ -578,7 +578,7 @@ static inline unsigned long hpet_time_div(struct hpets *hpets,
38202 }
38203
38204 static int
38205 -hpet_ioctl_common(struct hpet_dev *devp, int cmd, unsigned long arg,
38206 +hpet_ioctl_common(struct hpet_dev *devp, unsigned int cmd, unsigned long arg,
38207 struct hpet_info *info)
38208 {
38209 struct hpet_timer __iomem *timer;
38210 diff --git a/drivers/char/hw_random/intel-rng.c b/drivers/char/hw_random/intel-rng.c
38211 index 86fe45c..c0ea948 100644
38212 --- a/drivers/char/hw_random/intel-rng.c
38213 +++ b/drivers/char/hw_random/intel-rng.c
38214 @@ -314,7 +314,7 @@ PFX "RNG, try using the 'no_fwh_detect' option.\n";
38215
38216 if (no_fwh_detect)
38217 return -ENODEV;
38218 - printk(warning);
38219 + printk("%s", warning);
38220 return -EBUSY;
38221 }
38222
38223 diff --git a/drivers/char/ipmi/ipmi_msghandler.c b/drivers/char/ipmi/ipmi_msghandler.c
38224 index ec4e10f..f2a763b 100644
38225 --- a/drivers/char/ipmi/ipmi_msghandler.c
38226 +++ b/drivers/char/ipmi/ipmi_msghandler.c
38227 @@ -420,7 +420,7 @@ struct ipmi_smi {
38228 struct proc_dir_entry *proc_dir;
38229 char proc_dir_name[10];
38230
38231 - atomic_t stats[IPMI_NUM_STATS];
38232 + atomic_unchecked_t stats[IPMI_NUM_STATS];
38233
38234 /*
38235 * run_to_completion duplicate of smb_info, smi_info
38236 @@ -453,9 +453,9 @@ static DEFINE_MUTEX(smi_watchers_mutex);
38237
38238
38239 #define ipmi_inc_stat(intf, stat) \
38240 - atomic_inc(&(intf)->stats[IPMI_STAT_ ## stat])
38241 + atomic_inc_unchecked(&(intf)->stats[IPMI_STAT_ ## stat])
38242 #define ipmi_get_stat(intf, stat) \
38243 - ((unsigned int) atomic_read(&(intf)->stats[IPMI_STAT_ ## stat]))
38244 + ((unsigned int) atomic_read_unchecked(&(intf)->stats[IPMI_STAT_ ## stat]))
38245
38246 static int is_lan_addr(struct ipmi_addr *addr)
38247 {
38248 @@ -2883,7 +2883,7 @@ int ipmi_register_smi(struct ipmi_smi_handlers *handlers,
38249 INIT_LIST_HEAD(&intf->cmd_rcvrs);
38250 init_waitqueue_head(&intf->waitq);
38251 for (i = 0; i < IPMI_NUM_STATS; i++)
38252 - atomic_set(&intf->stats[i], 0);
38253 + atomic_set_unchecked(&intf->stats[i], 0);
38254
38255 intf->proc_dir = NULL;
38256
38257 diff --git a/drivers/char/ipmi/ipmi_si_intf.c b/drivers/char/ipmi/ipmi_si_intf.c
38258 index 15e4a60..b046093 100644
38259 --- a/drivers/char/ipmi/ipmi_si_intf.c
38260 +++ b/drivers/char/ipmi/ipmi_si_intf.c
38261 @@ -280,7 +280,7 @@ struct smi_info {
38262 unsigned char slave_addr;
38263
38264 /* Counters and things for the proc filesystem. */
38265 - atomic_t stats[SI_NUM_STATS];
38266 + atomic_unchecked_t stats[SI_NUM_STATS];
38267
38268 struct task_struct *thread;
38269
38270 @@ -289,9 +289,9 @@ struct smi_info {
38271 };
38272
38273 #define smi_inc_stat(smi, stat) \
38274 - atomic_inc(&(smi)->stats[SI_STAT_ ## stat])
38275 + atomic_inc_unchecked(&(smi)->stats[SI_STAT_ ## stat])
38276 #define smi_get_stat(smi, stat) \
38277 - ((unsigned int) atomic_read(&(smi)->stats[SI_STAT_ ## stat]))
38278 + ((unsigned int) atomic_read_unchecked(&(smi)->stats[SI_STAT_ ## stat]))
38279
38280 #define SI_MAX_PARMS 4
38281
38282 @@ -3324,7 +3324,7 @@ static int try_smi_init(struct smi_info *new_smi)
38283 atomic_set(&new_smi->req_events, 0);
38284 new_smi->run_to_completion = 0;
38285 for (i = 0; i < SI_NUM_STATS; i++)
38286 - atomic_set(&new_smi->stats[i], 0);
38287 + atomic_set_unchecked(&new_smi->stats[i], 0);
38288
38289 new_smi->interrupt_disabled = 1;
38290 atomic_set(&new_smi->stop_operation, 0);
38291 diff --git a/drivers/char/mem.c b/drivers/char/mem.c
38292 index f895a8c..2bc9147 100644
38293 --- a/drivers/char/mem.c
38294 +++ b/drivers/char/mem.c
38295 @@ -18,6 +18,7 @@
38296 #include <linux/raw.h>
38297 #include <linux/tty.h>
38298 #include <linux/capability.h>
38299 +#include <linux/security.h>
38300 #include <linux/ptrace.h>
38301 #include <linux/device.h>
38302 #include <linux/highmem.h>
38303 @@ -37,6 +38,10 @@
38304
38305 #define DEVPORT_MINOR 4
38306
38307 +#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
38308 +extern const struct file_operations grsec_fops;
38309 +#endif
38310 +
38311 static inline unsigned long size_inside_page(unsigned long start,
38312 unsigned long size)
38313 {
38314 @@ -68,9 +73,13 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
38315
38316 while (cursor < to) {
38317 if (!devmem_is_allowed(pfn)) {
38318 +#ifdef CONFIG_GRKERNSEC_KMEM
38319 + gr_handle_mem_readwrite(from, to);
38320 +#else
38321 printk(KERN_INFO
38322 "Program %s tried to access /dev/mem between %Lx->%Lx.\n",
38323 current->comm, from, to);
38324 +#endif
38325 return 0;
38326 }
38327 cursor += PAGE_SIZE;
38328 @@ -78,6 +87,11 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
38329 }
38330 return 1;
38331 }
38332 +#elif defined(CONFIG_GRKERNSEC_KMEM)
38333 +static inline int range_is_allowed(unsigned long pfn, unsigned long size)
38334 +{
38335 + return 0;
38336 +}
38337 #else
38338 static inline int range_is_allowed(unsigned long pfn, unsigned long size)
38339 {
38340 @@ -120,6 +134,7 @@ static ssize_t read_mem(struct file *file, char __user *buf,
38341
38342 while (count > 0) {
38343 unsigned long remaining;
38344 + char *temp;
38345
38346 sz = size_inside_page(p, count);
38347
38348 @@ -135,7 +150,23 @@ static ssize_t read_mem(struct file *file, char __user *buf,
38349 if (!ptr)
38350 return -EFAULT;
38351
38352 - remaining = copy_to_user(buf, ptr, sz);
38353 +#ifdef CONFIG_PAX_USERCOPY
38354 + temp = kmalloc(sz, GFP_KERNEL|GFP_USERCOPY);
38355 + if (!temp) {
38356 + unxlate_dev_mem_ptr(p, ptr);
38357 + return -ENOMEM;
38358 + }
38359 + memcpy(temp, ptr, sz);
38360 +#else
38361 + temp = ptr;
38362 +#endif
38363 +
38364 + remaining = copy_to_user(buf, temp, sz);
38365 +
38366 +#ifdef CONFIG_PAX_USERCOPY
38367 + kfree(temp);
38368 +#endif
38369 +
38370 unxlate_dev_mem_ptr(p, ptr);
38371 if (remaining)
38372 return -EFAULT;
38373 @@ -364,9 +395,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
38374 size_t count, loff_t *ppos)
38375 {
38376 unsigned long p = *ppos;
38377 - ssize_t low_count, read, sz;
38378 + ssize_t low_count, read, sz, err = 0;
38379 char *kbuf; /* k-addr because vread() takes vmlist_lock rwlock */
38380 - int err = 0;
38381
38382 read = 0;
38383 if (p < (unsigned long) high_memory) {
38384 @@ -388,6 +418,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
38385 }
38386 #endif
38387 while (low_count > 0) {
38388 + char *temp;
38389 +
38390 sz = size_inside_page(p, low_count);
38391
38392 /*
38393 @@ -397,7 +429,22 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
38394 */
38395 kbuf = xlate_dev_kmem_ptr((char *)p);
38396
38397 - if (copy_to_user(buf, kbuf, sz))
38398 +#ifdef CONFIG_PAX_USERCOPY
38399 + temp = kmalloc(sz, GFP_KERNEL|GFP_USERCOPY);
38400 + if (!temp)
38401 + return -ENOMEM;
38402 + memcpy(temp, kbuf, sz);
38403 +#else
38404 + temp = kbuf;
38405 +#endif
38406 +
38407 + err = copy_to_user(buf, temp, sz);
38408 +
38409 +#ifdef CONFIG_PAX_USERCOPY
38410 + kfree(temp);
38411 +#endif
38412 +
38413 + if (err)
38414 return -EFAULT;
38415 buf += sz;
38416 p += sz;
38417 @@ -822,6 +869,9 @@ static const struct memdev {
38418 #ifdef CONFIG_PRINTK
38419 [11] = { "kmsg", 0644, &kmsg_fops, NULL },
38420 #endif
38421 +#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
38422 + [13] = { "grsec",S_IRUSR | S_IWUGO, &grsec_fops, NULL },
38423 +#endif
38424 };
38425
38426 static int memory_open(struct inode *inode, struct file *filp)
38427 @@ -893,7 +943,7 @@ static int __init chr_dev_init(void)
38428 continue;
38429
38430 device_create(mem_class, NULL, MKDEV(MEM_MAJOR, minor),
38431 - NULL, devlist[minor].name);
38432 + NULL, "%s", devlist[minor].name);
38433 }
38434
38435 return tty_init();
38436 diff --git a/drivers/char/nvram.c b/drivers/char/nvram.c
38437 index 9df78e2..01ba9ae 100644
38438 --- a/drivers/char/nvram.c
38439 +++ b/drivers/char/nvram.c
38440 @@ -247,7 +247,7 @@ static ssize_t nvram_read(struct file *file, char __user *buf,
38441
38442 spin_unlock_irq(&rtc_lock);
38443
38444 - if (copy_to_user(buf, contents, tmp - contents))
38445 + if (tmp - contents > sizeof(contents) || copy_to_user(buf, contents, tmp - contents))
38446 return -EFAULT;
38447
38448 *ppos = i;
38449 diff --git a/drivers/char/pcmcia/synclink_cs.c b/drivers/char/pcmcia/synclink_cs.c
38450 index d39cca6..8c1e269 100644
38451 --- a/drivers/char/pcmcia/synclink_cs.c
38452 +++ b/drivers/char/pcmcia/synclink_cs.c
38453 @@ -2345,9 +2345,9 @@ static void mgslpc_close(struct tty_struct *tty, struct file * filp)
38454
38455 if (debug_level >= DEBUG_LEVEL_INFO)
38456 printk("%s(%d):mgslpc_close(%s) entry, count=%d\n",
38457 - __FILE__, __LINE__, info->device_name, port->count);
38458 + __FILE__, __LINE__, info->device_name, atomic_read(&port->count));
38459
38460 - WARN_ON(!port->count);
38461 + WARN_ON(!atomic_read(&port->count));
38462
38463 if (tty_port_close_start(port, tty, filp) == 0)
38464 goto cleanup;
38465 @@ -2365,7 +2365,7 @@ static void mgslpc_close(struct tty_struct *tty, struct file * filp)
38466 cleanup:
38467 if (debug_level >= DEBUG_LEVEL_INFO)
38468 printk("%s(%d):mgslpc_close(%s) exit, count=%d\n", __FILE__, __LINE__,
38469 - tty->driver->name, port->count);
38470 + tty->driver->name, atomic_read(&port->count));
38471 }
38472
38473 /* Wait until the transmitter is empty.
38474 @@ -2507,7 +2507,7 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp)
38475
38476 if (debug_level >= DEBUG_LEVEL_INFO)
38477 printk("%s(%d):mgslpc_open(%s), old ref count = %d\n",
38478 - __FILE__, __LINE__, tty->driver->name, port->count);
38479 + __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
38480
38481 /* If port is closing, signal caller to try again */
38482 if (tty_hung_up_p(filp) || port->flags & ASYNC_CLOSING){
38483 @@ -2527,11 +2527,11 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp)
38484 goto cleanup;
38485 }
38486 spin_lock(&port->lock);
38487 - port->count++;
38488 + atomic_inc(&port->count);
38489 spin_unlock(&port->lock);
38490 spin_unlock_irqrestore(&info->netlock, flags);
38491
38492 - if (port->count == 1) {
38493 + if (atomic_read(&port->count) == 1) {
38494 /* 1st open on this device, init hardware */
38495 retval = startup(info, tty);
38496 if (retval < 0)
38497 @@ -3920,7 +3920,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
38498 unsigned short new_crctype;
38499
38500 /* return error if TTY interface open */
38501 - if (info->port.count)
38502 + if (atomic_read(&info->port.count))
38503 return -EBUSY;
38504
38505 switch (encoding)
38506 @@ -4024,7 +4024,7 @@ static int hdlcdev_open(struct net_device *dev)
38507
38508 /* arbitrate between network and tty opens */
38509 spin_lock_irqsave(&info->netlock, flags);
38510 - if (info->port.count != 0 || info->netcount != 0) {
38511 + if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
38512 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
38513 spin_unlock_irqrestore(&info->netlock, flags);
38514 return -EBUSY;
38515 @@ -4114,7 +4114,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
38516 printk("%s:hdlcdev_ioctl(%s)\n", __FILE__, dev->name);
38517
38518 /* return error if TTY interface open */
38519 - if (info->port.count)
38520 + if (atomic_read(&info->port.count))
38521 return -EBUSY;
38522
38523 if (cmd != SIOCWANDEV)
38524 diff --git a/drivers/char/random.c b/drivers/char/random.c
38525 index 429b75b..a7f4145 100644
38526 --- a/drivers/char/random.c
38527 +++ b/drivers/char/random.c
38528 @@ -270,10 +270,17 @@
38529 /*
38530 * Configuration information
38531 */
38532 +#ifdef CONFIG_GRKERNSEC_RANDNET
38533 +#define INPUT_POOL_SHIFT 14
38534 +#define INPUT_POOL_WORDS (1 << (INPUT_POOL_SHIFT-5))
38535 +#define OUTPUT_POOL_SHIFT 12
38536 +#define OUTPUT_POOL_WORDS (1 << (OUTPUT_POOL_SHIFT-5))
38537 +#else
38538 #define INPUT_POOL_SHIFT 12
38539 #define INPUT_POOL_WORDS (1 << (INPUT_POOL_SHIFT-5))
38540 #define OUTPUT_POOL_SHIFT 10
38541 #define OUTPUT_POOL_WORDS (1 << (OUTPUT_POOL_SHIFT-5))
38542 +#endif
38543 #define SEC_XFER_SIZE 512
38544 #define EXTRACT_SIZE 10
38545
38546 @@ -284,9 +291,6 @@
38547 /*
38548 * To allow fractional bits to be tracked, the entropy_count field is
38549 * denominated in units of 1/8th bits.
38550 - *
38551 - * 2*(ENTROPY_SHIFT + log2(poolbits)) must <= 31, or the multiply in
38552 - * credit_entropy_bits() needs to be 64 bits wide.
38553 */
38554 #define ENTROPY_SHIFT 3
38555 #define ENTROPY_BITS(r) ((r)->entropy_count >> ENTROPY_SHIFT)
38556 @@ -361,12 +365,19 @@ static struct poolinfo {
38557 #define S(x) ilog2(x)+5, (x), (x)*4, (x)*32, (x) << (ENTROPY_SHIFT+5)
38558 int tap1, tap2, tap3, tap4, tap5;
38559 } poolinfo_table[] = {
38560 +#ifdef CONFIG_GRKERNSEC_RANDNET
38561 + /* x^512 + x^411 + x^308 + x^208 +x^104 + x + 1 -- 225 */
38562 + { S(512), 411, 308, 208, 104, 1 },
38563 + /* x^128 + x^104 + x^76 + x^51 + x^25 + x + 1 -- 105 */
38564 + { S(128), 104, 76, 51, 25, 1 },
38565 +#else
38566 /* was: x^128 + x^103 + x^76 + x^51 +x^25 + x + 1 */
38567 /* x^128 + x^104 + x^76 + x^51 +x^25 + x + 1 */
38568 { S(128), 104, 76, 51, 25, 1 },
38569 /* was: x^32 + x^26 + x^20 + x^14 + x^7 + x + 1 */
38570 /* x^32 + x^26 + x^19 + x^14 + x^7 + x + 1 */
38571 { S(32), 26, 19, 14, 7, 1 },
38572 +#endif
38573 #if 0
38574 /* x^2048 + x^1638 + x^1231 + x^819 + x^411 + x + 1 -- 115 */
38575 { S(2048), 1638, 1231, 819, 411, 1 },
38576 @@ -433,9 +444,9 @@ struct entropy_store {
38577 };
38578
38579 static void push_to_pool(struct work_struct *work);
38580 -static __u32 input_pool_data[INPUT_POOL_WORDS];
38581 -static __u32 blocking_pool_data[OUTPUT_POOL_WORDS];
38582 -static __u32 nonblocking_pool_data[OUTPUT_POOL_WORDS];
38583 +static __u32 input_pool_data[INPUT_POOL_WORDS] __latent_entropy;
38584 +static __u32 blocking_pool_data[OUTPUT_POOL_WORDS] __latent_entropy;
38585 +static __u32 nonblocking_pool_data[OUTPUT_POOL_WORDS] __latent_entropy;
38586
38587 static struct entropy_store input_pool = {
38588 .poolinfo = &poolinfo_table[0],
38589 @@ -524,8 +535,8 @@ static void _mix_pool_bytes(struct entropy_store *r, const void *in,
38590 input_rotate = (input_rotate + (i ? 7 : 14)) & 31;
38591 }
38592
38593 - ACCESS_ONCE(r->input_rotate) = input_rotate;
38594 - ACCESS_ONCE(r->add_ptr) = i;
38595 + ACCESS_ONCE_RW(r->input_rotate) = input_rotate;
38596 + ACCESS_ONCE_RW(r->add_ptr) = i;
38597 smp_wmb();
38598
38599 if (out)
38600 @@ -632,7 +643,7 @@ retry:
38601 /* The +2 corresponds to the /4 in the denominator */
38602
38603 do {
38604 - unsigned int anfrac = min(pnfrac, pool_size/2);
38605 + u64 anfrac = min(pnfrac, pool_size/2);
38606 unsigned int add =
38607 ((pool_size - entropy_count)*anfrac*3) >> s;
38608
38609 @@ -1151,7 +1162,7 @@ static ssize_t extract_entropy_user(struct entropy_store *r, void __user *buf,
38610
38611 extract_buf(r, tmp);
38612 i = min_t(int, nbytes, EXTRACT_SIZE);
38613 - if (copy_to_user(buf, tmp, i)) {
38614 + if (i > sizeof(tmp) || copy_to_user(buf, tmp, i)) {
38615 ret = -EFAULT;
38616 break;
38617 }
38618 @@ -1507,7 +1518,7 @@ EXPORT_SYMBOL(generate_random_uuid);
38619 #include <linux/sysctl.h>
38620
38621 static int min_read_thresh = 8, min_write_thresh;
38622 -static int max_read_thresh = INPUT_POOL_WORDS * 32;
38623 +static int max_read_thresh = OUTPUT_POOL_WORDS * 32;
38624 static int max_write_thresh = INPUT_POOL_WORDS * 32;
38625 static char sysctl_bootid[16];
38626
38627 @@ -1523,7 +1534,7 @@ static char sysctl_bootid[16];
38628 static int proc_do_uuid(struct ctl_table *table, int write,
38629 void __user *buffer, size_t *lenp, loff_t *ppos)
38630 {
38631 - struct ctl_table fake_table;
38632 + ctl_table_no_const fake_table;
38633 unsigned char buf[64], tmp_uuid[16], *uuid;
38634
38635 uuid = table->data;
38636 @@ -1553,7 +1564,7 @@ static int proc_do_uuid(struct ctl_table *table, int write,
38637 static int proc_do_entropy(ctl_table *table, int write,
38638 void __user *buffer, size_t *lenp, loff_t *ppos)
38639 {
38640 - ctl_table fake_table;
38641 + ctl_table_no_const fake_table;
38642 int entropy_count;
38643
38644 entropy_count = *(int *)table->data >> ENTROPY_SHIFT;
38645 diff --git a/drivers/char/sonypi.c b/drivers/char/sonypi.c
38646 index 7cc1fe22..b602d6b 100644
38647 --- a/drivers/char/sonypi.c
38648 +++ b/drivers/char/sonypi.c
38649 @@ -54,6 +54,7 @@
38650
38651 #include <asm/uaccess.h>
38652 #include <asm/io.h>
38653 +#include <asm/local.h>
38654
38655 #include <linux/sonypi.h>
38656
38657 @@ -490,7 +491,7 @@ static struct sonypi_device {
38658 spinlock_t fifo_lock;
38659 wait_queue_head_t fifo_proc_list;
38660 struct fasync_struct *fifo_async;
38661 - int open_count;
38662 + local_t open_count;
38663 int model;
38664 struct input_dev *input_jog_dev;
38665 struct input_dev *input_key_dev;
38666 @@ -892,7 +893,7 @@ static int sonypi_misc_fasync(int fd, struct file *filp, int on)
38667 static int sonypi_misc_release(struct inode *inode, struct file *file)
38668 {
38669 mutex_lock(&sonypi_device.lock);
38670 - sonypi_device.open_count--;
38671 + local_dec(&sonypi_device.open_count);
38672 mutex_unlock(&sonypi_device.lock);
38673 return 0;
38674 }
38675 @@ -901,9 +902,9 @@ static int sonypi_misc_open(struct inode *inode, struct file *file)
38676 {
38677 mutex_lock(&sonypi_device.lock);
38678 /* Flush input queue on first open */
38679 - if (!sonypi_device.open_count)
38680 + if (!local_read(&sonypi_device.open_count))
38681 kfifo_reset(&sonypi_device.fifo);
38682 - sonypi_device.open_count++;
38683 + local_inc(&sonypi_device.open_count);
38684 mutex_unlock(&sonypi_device.lock);
38685
38686 return 0;
38687 diff --git a/drivers/char/tpm/tpm_acpi.c b/drivers/char/tpm/tpm_acpi.c
38688 index 64420b3..5c40b56 100644
38689 --- a/drivers/char/tpm/tpm_acpi.c
38690 +++ b/drivers/char/tpm/tpm_acpi.c
38691 @@ -98,11 +98,12 @@ int read_log(struct tpm_bios_log *log)
38692 virt = acpi_os_map_memory(start, len);
38693 if (!virt) {
38694 kfree(log->bios_event_log);
38695 + log->bios_event_log = NULL;
38696 printk("%s: ERROR - Unable to map memory\n", __func__);
38697 return -EIO;
38698 }
38699
38700 - memcpy_fromio(log->bios_event_log, virt, len);
38701 + memcpy_fromio(log->bios_event_log, (const char __force_kernel *)virt, len);
38702
38703 acpi_os_unmap_memory(virt, len);
38704 return 0;
38705 diff --git a/drivers/char/tpm/tpm_eventlog.c b/drivers/char/tpm/tpm_eventlog.c
38706 index 59f7cb2..bac8b6d 100644
38707 --- a/drivers/char/tpm/tpm_eventlog.c
38708 +++ b/drivers/char/tpm/tpm_eventlog.c
38709 @@ -95,7 +95,7 @@ static void *tpm_bios_measurements_start(struct seq_file *m, loff_t *pos)
38710 event = addr;
38711
38712 if ((event->event_type == 0 && event->event_size == 0) ||
38713 - ((addr + sizeof(struct tcpa_event) + event->event_size) >= limit))
38714 + (event->event_size >= limit - addr - sizeof(struct tcpa_event)))
38715 return NULL;
38716
38717 return addr;
38718 @@ -120,7 +120,7 @@ static void *tpm_bios_measurements_next(struct seq_file *m, void *v,
38719 return NULL;
38720
38721 if ((event->event_type == 0 && event->event_size == 0) ||
38722 - ((v + sizeof(struct tcpa_event) + event->event_size) >= limit))
38723 + (event->event_size >= limit - v - sizeof(struct tcpa_event)))
38724 return NULL;
38725
38726 (*pos)++;
38727 @@ -213,7 +213,8 @@ static int tpm_binary_bios_measurements_show(struct seq_file *m, void *v)
38728 int i;
38729
38730 for (i = 0; i < sizeof(struct tcpa_event) + event->event_size; i++)
38731 - seq_putc(m, data[i]);
38732 + if (!seq_putc(m, data[i]))
38733 + return -EFAULT;
38734
38735 return 0;
38736 }
38737 diff --git a/drivers/char/virtio_console.c b/drivers/char/virtio_console.c
38738 index feea87c..18aefff 100644
38739 --- a/drivers/char/virtio_console.c
38740 +++ b/drivers/char/virtio_console.c
38741 @@ -684,7 +684,7 @@ static ssize_t fill_readbuf(struct port *port, char *out_buf, size_t out_count,
38742 if (to_user) {
38743 ssize_t ret;
38744
38745 - ret = copy_to_user(out_buf, buf->buf + buf->offset, out_count);
38746 + ret = copy_to_user((char __force_user *)out_buf, buf->buf + buf->offset, out_count);
38747 if (ret)
38748 return -EFAULT;
38749 } else {
38750 @@ -787,7 +787,7 @@ static ssize_t port_fops_read(struct file *filp, char __user *ubuf,
38751 if (!port_has_data(port) && !port->host_connected)
38752 return 0;
38753
38754 - return fill_readbuf(port, ubuf, count, true);
38755 + return fill_readbuf(port, (char __force_kernel *)ubuf, count, true);
38756 }
38757
38758 static int wait_port_writable(struct port *port, bool nonblock)
38759 diff --git a/drivers/clk/clk-composite.c b/drivers/clk/clk-composite.c
38760 index a33f46f..a720eed 100644
38761 --- a/drivers/clk/clk-composite.c
38762 +++ b/drivers/clk/clk-composite.c
38763 @@ -122,7 +122,7 @@ struct clk *clk_register_composite(struct device *dev, const char *name,
38764 struct clk *clk;
38765 struct clk_init_data init;
38766 struct clk_composite *composite;
38767 - struct clk_ops *clk_composite_ops;
38768 + clk_ops_no_const *clk_composite_ops;
38769
38770 composite = kzalloc(sizeof(*composite), GFP_KERNEL);
38771 if (!composite) {
38772 diff --git a/drivers/clk/socfpga/clk.c b/drivers/clk/socfpga/clk.c
38773 index 81dd31a..ef5c542 100644
38774 --- a/drivers/clk/socfpga/clk.c
38775 +++ b/drivers/clk/socfpga/clk.c
38776 @@ -22,6 +22,7 @@
38777 #include <linux/clk-provider.h>
38778 #include <linux/io.h>
38779 #include <linux/of.h>
38780 +#include <asm/pgtable.h>
38781
38782 /* Clock Manager offsets */
38783 #define CLKMGR_CTRL 0x0
38784 @@ -152,8 +153,10 @@ static __init struct clk *socfpga_clk_init(struct device_node *node,
38785 streq(clk_name, "periph_pll") ||
38786 streq(clk_name, "sdram_pll")) {
38787 socfpga_clk->hw.bit_idx = SOCFPGA_PLL_EXT_ENA;
38788 - clk_pll_ops.enable = clk_gate_ops.enable;
38789 - clk_pll_ops.disable = clk_gate_ops.disable;
38790 + pax_open_kernel();
38791 + *(void **)&clk_pll_ops.enable = clk_gate_ops.enable;
38792 + *(void **)&clk_pll_ops.disable = clk_gate_ops.disable;
38793 + pax_close_kernel();
38794 }
38795
38796 clk = clk_register(NULL, &socfpga_clk->hw.hw);
38797 @@ -244,7 +247,7 @@ static unsigned long socfpga_clk_recalc_rate(struct clk_hw *hwclk,
38798 return parent_rate / div;
38799 }
38800
38801 -static struct clk_ops gateclk_ops = {
38802 +static clk_ops_no_const gateclk_ops __read_only = {
38803 .recalc_rate = socfpga_clk_recalc_rate,
38804 .get_parent = socfpga_clk_get_parent,
38805 .set_parent = socfpga_clk_set_parent,
38806 diff --git a/drivers/cpufreq/acpi-cpufreq.c b/drivers/cpufreq/acpi-cpufreq.c
38807 index caf41eb..223d27a 100644
38808 --- a/drivers/cpufreq/acpi-cpufreq.c
38809 +++ b/drivers/cpufreq/acpi-cpufreq.c
38810 @@ -172,7 +172,7 @@ static ssize_t show_global_boost(struct kobject *kobj,
38811 return sprintf(buf, "%u\n", boost_enabled);
38812 }
38813
38814 -static struct global_attr global_boost = __ATTR(boost, 0644,
38815 +static global_attr_no_const global_boost = __ATTR(boost, 0644,
38816 show_global_boost,
38817 store_global_boost);
38818
38819 @@ -693,8 +693,11 @@ static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy)
38820 data->acpi_data = per_cpu_ptr(acpi_perf_data, cpu);
38821 per_cpu(acfreq_data, cpu) = data;
38822
38823 - if (cpu_has(c, X86_FEATURE_CONSTANT_TSC))
38824 - acpi_cpufreq_driver.flags |= CPUFREQ_CONST_LOOPS;
38825 + if (cpu_has(c, X86_FEATURE_CONSTANT_TSC)) {
38826 + pax_open_kernel();
38827 + *(u8 *)&acpi_cpufreq_driver.flags |= CPUFREQ_CONST_LOOPS;
38828 + pax_close_kernel();
38829 + }
38830
38831 result = acpi_processor_register_performance(data->acpi_data, cpu);
38832 if (result)
38833 @@ -827,7 +830,9 @@ static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy)
38834 policy->cur = acpi_cpufreq_guess_freq(data, policy->cpu);
38835 break;
38836 case ACPI_ADR_SPACE_FIXED_HARDWARE:
38837 - acpi_cpufreq_driver.get = get_cur_freq_on_cpu;
38838 + pax_open_kernel();
38839 + *(void **)&acpi_cpufreq_driver.get = get_cur_freq_on_cpu;
38840 + pax_close_kernel();
38841 break;
38842 default:
38843 break;
38844 diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
38845 index 99a443e..8cb6f02 100644
38846 --- a/drivers/cpufreq/cpufreq.c
38847 +++ b/drivers/cpufreq/cpufreq.c
38848 @@ -1878,7 +1878,7 @@ void cpufreq_unregister_governor(struct cpufreq_governor *governor)
38849 #endif
38850
38851 mutex_lock(&cpufreq_governor_mutex);
38852 - list_del(&governor->governor_list);
38853 + pax_list_del(&governor->governor_list);
38854 mutex_unlock(&cpufreq_governor_mutex);
38855 return;
38856 }
38857 @@ -2108,7 +2108,7 @@ static int cpufreq_cpu_callback(struct notifier_block *nfb,
38858 return NOTIFY_OK;
38859 }
38860
38861 -static struct notifier_block __refdata cpufreq_cpu_notifier = {
38862 +static struct notifier_block cpufreq_cpu_notifier = {
38863 .notifier_call = cpufreq_cpu_callback,
38864 };
38865
38866 @@ -2141,8 +2141,11 @@ int cpufreq_register_driver(struct cpufreq_driver *driver_data)
38867
38868 pr_debug("trying to register driver %s\n", driver_data->name);
38869
38870 - if (driver_data->setpolicy)
38871 - driver_data->flags |= CPUFREQ_CONST_LOOPS;
38872 + if (driver_data->setpolicy) {
38873 + pax_open_kernel();
38874 + *(u8 *)&driver_data->flags |= CPUFREQ_CONST_LOOPS;
38875 + pax_close_kernel();
38876 + }
38877
38878 write_lock_irqsave(&cpufreq_driver_lock, flags);
38879 if (cpufreq_driver) {
38880 diff --git a/drivers/cpufreq/cpufreq_governor.c b/drivers/cpufreq/cpufreq_governor.c
38881 index e6be635..f8a90dc 100644
38882 --- a/drivers/cpufreq/cpufreq_governor.c
38883 +++ b/drivers/cpufreq/cpufreq_governor.c
38884 @@ -187,7 +187,7 @@ int cpufreq_governor_dbs(struct cpufreq_policy *policy,
38885 struct dbs_data *dbs_data;
38886 struct od_cpu_dbs_info_s *od_dbs_info = NULL;
38887 struct cs_cpu_dbs_info_s *cs_dbs_info = NULL;
38888 - struct od_ops *od_ops = NULL;
38889 + const struct od_ops *od_ops = NULL;
38890 struct od_dbs_tuners *od_tuners = NULL;
38891 struct cs_dbs_tuners *cs_tuners = NULL;
38892 struct cpu_dbs_common_info *cpu_cdbs;
38893 @@ -253,7 +253,7 @@ int cpufreq_governor_dbs(struct cpufreq_policy *policy,
38894
38895 if ((cdata->governor == GOV_CONSERVATIVE) &&
38896 (!policy->governor->initialized)) {
38897 - struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
38898 + const struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
38899
38900 cpufreq_register_notifier(cs_ops->notifier_block,
38901 CPUFREQ_TRANSITION_NOTIFIER);
38902 @@ -273,7 +273,7 @@ int cpufreq_governor_dbs(struct cpufreq_policy *policy,
38903
38904 if ((dbs_data->cdata->governor == GOV_CONSERVATIVE) &&
38905 (policy->governor->initialized == 1)) {
38906 - struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
38907 + const struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
38908
38909 cpufreq_unregister_notifier(cs_ops->notifier_block,
38910 CPUFREQ_TRANSITION_NOTIFIER);
38911 diff --git a/drivers/cpufreq/cpufreq_governor.h b/drivers/cpufreq/cpufreq_governor.h
38912 index b5f2b86..daa801b 100644
38913 --- a/drivers/cpufreq/cpufreq_governor.h
38914 +++ b/drivers/cpufreq/cpufreq_governor.h
38915 @@ -205,7 +205,7 @@ struct common_dbs_data {
38916 void (*exit)(struct dbs_data *dbs_data);
38917
38918 /* Governor specific ops, see below */
38919 - void *gov_ops;
38920 + const void *gov_ops;
38921 };
38922
38923 /* Governor Per policy data */
38924 @@ -225,7 +225,7 @@ struct od_ops {
38925 unsigned int (*powersave_bias_target)(struct cpufreq_policy *policy,
38926 unsigned int freq_next, unsigned int relation);
38927 void (*freq_increase)(struct cpufreq_policy *policy, unsigned int freq);
38928 -};
38929 +} __no_const;
38930
38931 struct cs_ops {
38932 struct notifier_block *notifier_block;
38933 diff --git a/drivers/cpufreq/cpufreq_ondemand.c b/drivers/cpufreq/cpufreq_ondemand.c
38934 index 18d4091..434be15 100644
38935 --- a/drivers/cpufreq/cpufreq_ondemand.c
38936 +++ b/drivers/cpufreq/cpufreq_ondemand.c
38937 @@ -521,7 +521,7 @@ static void od_exit(struct dbs_data *dbs_data)
38938
38939 define_get_cpu_dbs_routines(od_cpu_dbs_info);
38940
38941 -static struct od_ops od_ops = {
38942 +static struct od_ops od_ops __read_only = {
38943 .powersave_bias_init_cpu = ondemand_powersave_bias_init_cpu,
38944 .powersave_bias_target = generic_powersave_bias_target,
38945 .freq_increase = dbs_freq_increase,
38946 @@ -576,14 +576,18 @@ void od_register_powersave_bias_handler(unsigned int (*f)
38947 (struct cpufreq_policy *, unsigned int, unsigned int),
38948 unsigned int powersave_bias)
38949 {
38950 - od_ops.powersave_bias_target = f;
38951 + pax_open_kernel();
38952 + *(void **)&od_ops.powersave_bias_target = f;
38953 + pax_close_kernel();
38954 od_set_powersave_bias(powersave_bias);
38955 }
38956 EXPORT_SYMBOL_GPL(od_register_powersave_bias_handler);
38957
38958 void od_unregister_powersave_bias_handler(void)
38959 {
38960 - od_ops.powersave_bias_target = generic_powersave_bias_target;
38961 + pax_open_kernel();
38962 + *(void **)&od_ops.powersave_bias_target = generic_powersave_bias_target;
38963 + pax_close_kernel();
38964 od_set_powersave_bias(0);
38965 }
38966 EXPORT_SYMBOL_GPL(od_unregister_powersave_bias_handler);
38967 diff --git a/drivers/cpufreq/cpufreq_stats.c b/drivers/cpufreq/cpufreq_stats.c
38968 index 4cf0d28..5830372 100644
38969 --- a/drivers/cpufreq/cpufreq_stats.c
38970 +++ b/drivers/cpufreq/cpufreq_stats.c
38971 @@ -352,7 +352,7 @@ static int cpufreq_stat_cpu_callback(struct notifier_block *nfb,
38972 }
38973
38974 /* priority=1 so this will get called before cpufreq_remove_dev */
38975 -static struct notifier_block cpufreq_stat_cpu_notifier __refdata = {
38976 +static struct notifier_block cpufreq_stat_cpu_notifier = {
38977 .notifier_call = cpufreq_stat_cpu_callback,
38978 .priority = 1,
38979 };
38980 diff --git a/drivers/cpufreq/intel_pstate.c b/drivers/cpufreq/intel_pstate.c
38981 index b687df8..ae733fc 100644
38982 --- a/drivers/cpufreq/intel_pstate.c
38983 +++ b/drivers/cpufreq/intel_pstate.c
38984 @@ -123,10 +123,10 @@ struct pstate_funcs {
38985 struct cpu_defaults {
38986 struct pstate_adjust_policy pid_policy;
38987 struct pstate_funcs funcs;
38988 -};
38989 +} __do_const;
38990
38991 static struct pstate_adjust_policy pid_params;
38992 -static struct pstate_funcs pstate_funcs;
38993 +static struct pstate_funcs *pstate_funcs;
38994
38995 struct perf_limits {
38996 int no_turbo;
38997 @@ -517,7 +517,7 @@ static void intel_pstate_set_pstate(struct cpudata *cpu, int pstate)
38998
38999 cpu->pstate.current_pstate = pstate;
39000
39001 - pstate_funcs.set(cpu, pstate);
39002 + pstate_funcs->set(cpu, pstate);
39003 }
39004
39005 static inline void intel_pstate_pstate_increase(struct cpudata *cpu, int steps)
39006 @@ -539,12 +539,12 @@ static void intel_pstate_get_cpu_pstates(struct cpudata *cpu)
39007 {
39008 sprintf(cpu->name, "Intel 2nd generation core");
39009
39010 - cpu->pstate.min_pstate = pstate_funcs.get_min();
39011 - cpu->pstate.max_pstate = pstate_funcs.get_max();
39012 - cpu->pstate.turbo_pstate = pstate_funcs.get_turbo();
39013 + cpu->pstate.min_pstate = pstate_funcs->get_min();
39014 + cpu->pstate.max_pstate = pstate_funcs->get_max();
39015 + cpu->pstate.turbo_pstate = pstate_funcs->get_turbo();
39016
39017 - if (pstate_funcs.get_vid)
39018 - pstate_funcs.get_vid(cpu);
39019 + if (pstate_funcs->get_vid)
39020 + pstate_funcs->get_vid(cpu);
39021
39022 /*
39023 * goto max pstate so we don't slow up boot if we are built-in if we are
39024 @@ -808,9 +808,9 @@ static int intel_pstate_msrs_not_valid(void)
39025 rdmsrl(MSR_IA32_APERF, aperf);
39026 rdmsrl(MSR_IA32_MPERF, mperf);
39027
39028 - if (!pstate_funcs.get_max() ||
39029 - !pstate_funcs.get_min() ||
39030 - !pstate_funcs.get_turbo())
39031 + if (!pstate_funcs->get_max() ||
39032 + !pstate_funcs->get_min() ||
39033 + !pstate_funcs->get_turbo())
39034 return -ENODEV;
39035
39036 rdmsrl(MSR_IA32_APERF, tmp);
39037 @@ -824,7 +824,7 @@ static int intel_pstate_msrs_not_valid(void)
39038 return 0;
39039 }
39040
39041 -static void copy_pid_params(struct pstate_adjust_policy *policy)
39042 +static void copy_pid_params(const struct pstate_adjust_policy *policy)
39043 {
39044 pid_params.sample_rate_ms = policy->sample_rate_ms;
39045 pid_params.p_gain_pct = policy->p_gain_pct;
39046 @@ -836,11 +836,7 @@ static void copy_pid_params(struct pstate_adjust_policy *policy)
39047
39048 static void copy_cpu_funcs(struct pstate_funcs *funcs)
39049 {
39050 - pstate_funcs.get_max = funcs->get_max;
39051 - pstate_funcs.get_min = funcs->get_min;
39052 - pstate_funcs.get_turbo = funcs->get_turbo;
39053 - pstate_funcs.set = funcs->set;
39054 - pstate_funcs.get_vid = funcs->get_vid;
39055 + pstate_funcs = funcs;
39056 }
39057
39058 #if IS_ENABLED(CONFIG_ACPI)
39059 diff --git a/drivers/cpufreq/p4-clockmod.c b/drivers/cpufreq/p4-clockmod.c
39060 index 3d1cba9..0ab21d2 100644
39061 --- a/drivers/cpufreq/p4-clockmod.c
39062 +++ b/drivers/cpufreq/p4-clockmod.c
39063 @@ -134,10 +134,14 @@ static unsigned int cpufreq_p4_get_frequency(struct cpuinfo_x86 *c)
39064 case 0x0F: /* Core Duo */
39065 case 0x16: /* Celeron Core */
39066 case 0x1C: /* Atom */
39067 - p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
39068 + pax_open_kernel();
39069 + *(u8 *)&p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
39070 + pax_close_kernel();
39071 return speedstep_get_frequency(SPEEDSTEP_CPU_PCORE);
39072 case 0x0D: /* Pentium M (Dothan) */
39073 - p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
39074 + pax_open_kernel();
39075 + *(u8 *)&p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
39076 + pax_close_kernel();
39077 /* fall through */
39078 case 0x09: /* Pentium M (Banias) */
39079 return speedstep_get_frequency(SPEEDSTEP_CPU_PM);
39080 @@ -149,7 +153,9 @@ static unsigned int cpufreq_p4_get_frequency(struct cpuinfo_x86 *c)
39081
39082 /* on P-4s, the TSC runs with constant frequency independent whether
39083 * throttling is active or not. */
39084 - p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
39085 + pax_open_kernel();
39086 + *(u8 *)&p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
39087 + pax_close_kernel();
39088
39089 if (speedstep_detect_processor() == SPEEDSTEP_CPU_P4M) {
39090 printk(KERN_WARNING PFX "Warning: Pentium 4-M detected. "
39091 diff --git a/drivers/cpufreq/sparc-us3-cpufreq.c b/drivers/cpufreq/sparc-us3-cpufreq.c
39092 index 724ffbd..ad83692 100644
39093 --- a/drivers/cpufreq/sparc-us3-cpufreq.c
39094 +++ b/drivers/cpufreq/sparc-us3-cpufreq.c
39095 @@ -18,14 +18,12 @@
39096 #include <asm/head.h>
39097 #include <asm/timer.h>
39098
39099 -static struct cpufreq_driver *cpufreq_us3_driver;
39100 -
39101 struct us3_freq_percpu_info {
39102 struct cpufreq_frequency_table table[4];
39103 };
39104
39105 /* Indexed by cpu number. */
39106 -static struct us3_freq_percpu_info *us3_freq_table;
39107 +static struct us3_freq_percpu_info us3_freq_table[NR_CPUS];
39108
39109 /* UltraSPARC-III has three dividers: 1, 2, and 32. These are controlled
39110 * in the Safari config register.
39111 @@ -156,14 +154,26 @@ static int __init us3_freq_cpu_init(struct cpufreq_policy *policy)
39112
39113 static int us3_freq_cpu_exit(struct cpufreq_policy *policy)
39114 {
39115 - if (cpufreq_us3_driver) {
39116 - cpufreq_frequency_table_put_attr(policy->cpu);
39117 - us3_freq_target(policy, 0);
39118 - }
39119 + cpufreq_frequency_table_put_attr(policy->cpu);
39120 + us3_freq_target(policy, 0);
39121
39122 return 0;
39123 }
39124
39125 +static int __init us3_freq_init(void);
39126 +static void __exit us3_freq_exit(void);
39127 +
39128 +static struct cpufreq_driver cpufreq_us3_driver = {
39129 + .init = us3_freq_cpu_init,
39130 + .verify = cpufreq_generic_frequency_table_verify,
39131 + .target_index = us3_freq_target,
39132 + .get = us3_freq_get,
39133 + .exit = us3_freq_cpu_exit,
39134 + .owner = THIS_MODULE,
39135 + .name = "UltraSPARC-III",
39136 +
39137 +};
39138 +
39139 static int __init us3_freq_init(void)
39140 {
39141 unsigned long manuf, impl, ver;
39142 @@ -180,55 +190,15 @@ static int __init us3_freq_init(void)
39143 (impl == CHEETAH_IMPL ||
39144 impl == CHEETAH_PLUS_IMPL ||
39145 impl == JAGUAR_IMPL ||
39146 - impl == PANTHER_IMPL)) {
39147 - struct cpufreq_driver *driver;
39148 -
39149 - ret = -ENOMEM;
39150 - driver = kzalloc(sizeof(*driver), GFP_KERNEL);
39151 - if (!driver)
39152 - goto err_out;
39153 -
39154 - us3_freq_table = kzalloc((NR_CPUS * sizeof(*us3_freq_table)),
39155 - GFP_KERNEL);
39156 - if (!us3_freq_table)
39157 - goto err_out;
39158 -
39159 - driver->init = us3_freq_cpu_init;
39160 - driver->verify = cpufreq_generic_frequency_table_verify;
39161 - driver->target_index = us3_freq_target;
39162 - driver->get = us3_freq_get;
39163 - driver->exit = us3_freq_cpu_exit;
39164 - strcpy(driver->name, "UltraSPARC-III");
39165 -
39166 - cpufreq_us3_driver = driver;
39167 - ret = cpufreq_register_driver(driver);
39168 - if (ret)
39169 - goto err_out;
39170 -
39171 - return 0;
39172 -
39173 -err_out:
39174 - if (driver) {
39175 - kfree(driver);
39176 - cpufreq_us3_driver = NULL;
39177 - }
39178 - kfree(us3_freq_table);
39179 - us3_freq_table = NULL;
39180 - return ret;
39181 - }
39182 + impl == PANTHER_IMPL))
39183 + return cpufreq_register_driver(&cpufreq_us3_driver);
39184
39185 return -ENODEV;
39186 }
39187
39188 static void __exit us3_freq_exit(void)
39189 {
39190 - if (cpufreq_us3_driver) {
39191 - cpufreq_unregister_driver(cpufreq_us3_driver);
39192 - kfree(cpufreq_us3_driver);
39193 - cpufreq_us3_driver = NULL;
39194 - kfree(us3_freq_table);
39195 - us3_freq_table = NULL;
39196 - }
39197 + cpufreq_unregister_driver(&cpufreq_us3_driver);
39198 }
39199
39200 MODULE_AUTHOR("David S. Miller <davem@redhat.com>");
39201 diff --git a/drivers/cpufreq/speedstep-centrino.c b/drivers/cpufreq/speedstep-centrino.c
39202 index 4e1daca..e707b61 100644
39203 --- a/drivers/cpufreq/speedstep-centrino.c
39204 +++ b/drivers/cpufreq/speedstep-centrino.c
39205 @@ -351,8 +351,11 @@ static int centrino_cpu_init(struct cpufreq_policy *policy)
39206 !cpu_has(cpu, X86_FEATURE_EST))
39207 return -ENODEV;
39208
39209 - if (cpu_has(cpu, X86_FEATURE_CONSTANT_TSC))
39210 - centrino_driver.flags |= CPUFREQ_CONST_LOOPS;
39211 + if (cpu_has(cpu, X86_FEATURE_CONSTANT_TSC)) {
39212 + pax_open_kernel();
39213 + *(u8 *)&centrino_driver.flags |= CPUFREQ_CONST_LOOPS;
39214 + pax_close_kernel();
39215 + }
39216
39217 if (policy->cpu != 0)
39218 return -ENODEV;
39219 diff --git a/drivers/cpuidle/driver.c b/drivers/cpuidle/driver.c
39220 index 06dbe7c..c2c8671 100644
39221 --- a/drivers/cpuidle/driver.c
39222 +++ b/drivers/cpuidle/driver.c
39223 @@ -202,7 +202,7 @@ static int poll_idle(struct cpuidle_device *dev,
39224
39225 static void poll_idle_init(struct cpuidle_driver *drv)
39226 {
39227 - struct cpuidle_state *state = &drv->states[0];
39228 + cpuidle_state_no_const *state = &drv->states[0];
39229
39230 snprintf(state->name, CPUIDLE_NAME_LEN, "POLL");
39231 snprintf(state->desc, CPUIDLE_DESC_LEN, "CPUIDLE CORE POLL IDLE");
39232 diff --git a/drivers/cpuidle/governor.c b/drivers/cpuidle/governor.c
39233 index ca89412..a7b9c49 100644
39234 --- a/drivers/cpuidle/governor.c
39235 +++ b/drivers/cpuidle/governor.c
39236 @@ -87,7 +87,7 @@ int cpuidle_register_governor(struct cpuidle_governor *gov)
39237 mutex_lock(&cpuidle_lock);
39238 if (__cpuidle_find_governor(gov->name) == NULL) {
39239 ret = 0;
39240 - list_add_tail(&gov->governor_list, &cpuidle_governors);
39241 + pax_list_add_tail((struct list_head *)&gov->governor_list, &cpuidle_governors);
39242 if (!cpuidle_curr_governor ||
39243 cpuidle_curr_governor->rating < gov->rating)
39244 cpuidle_switch_governor(gov);
39245 diff --git a/drivers/cpuidle/sysfs.c b/drivers/cpuidle/sysfs.c
39246 index e918b6d..f87ea80 100644
39247 --- a/drivers/cpuidle/sysfs.c
39248 +++ b/drivers/cpuidle/sysfs.c
39249 @@ -135,7 +135,7 @@ static struct attribute *cpuidle_switch_attrs[] = {
39250 NULL
39251 };
39252
39253 -static struct attribute_group cpuidle_attr_group = {
39254 +static attribute_group_no_const cpuidle_attr_group = {
39255 .attrs = cpuidle_default_attrs,
39256 .name = "cpuidle",
39257 };
39258 diff --git a/drivers/crypto/hifn_795x.c b/drivers/crypto/hifn_795x.c
39259 index 12fea3e..1e28f47 100644
39260 --- a/drivers/crypto/hifn_795x.c
39261 +++ b/drivers/crypto/hifn_795x.c
39262 @@ -51,7 +51,7 @@ module_param_string(hifn_pll_ref, hifn_pll_ref, sizeof(hifn_pll_ref), 0444);
39263 MODULE_PARM_DESC(hifn_pll_ref,
39264 "PLL reference clock (pci[freq] or ext[freq], default ext)");
39265
39266 -static atomic_t hifn_dev_number;
39267 +static atomic_unchecked_t hifn_dev_number;
39268
39269 #define ACRYPTO_OP_DECRYPT 0
39270 #define ACRYPTO_OP_ENCRYPT 1
39271 @@ -2577,7 +2577,7 @@ static int hifn_probe(struct pci_dev *pdev, const struct pci_device_id *id)
39272 goto err_out_disable_pci_device;
39273
39274 snprintf(name, sizeof(name), "hifn%d",
39275 - atomic_inc_return(&hifn_dev_number)-1);
39276 + atomic_inc_return_unchecked(&hifn_dev_number)-1);
39277
39278 err = pci_request_regions(pdev, name);
39279 if (err)
39280 diff --git a/drivers/devfreq/devfreq.c b/drivers/devfreq/devfreq.c
39281 index a0b2f7e..1b6f028 100644
39282 --- a/drivers/devfreq/devfreq.c
39283 +++ b/drivers/devfreq/devfreq.c
39284 @@ -607,7 +607,7 @@ int devfreq_add_governor(struct devfreq_governor *governor)
39285 goto err_out;
39286 }
39287
39288 - list_add(&governor->node, &devfreq_governor_list);
39289 + pax_list_add((struct list_head *)&governor->node, &devfreq_governor_list);
39290
39291 list_for_each_entry(devfreq, &devfreq_list, node) {
39292 int ret = 0;
39293 @@ -695,7 +695,7 @@ int devfreq_remove_governor(struct devfreq_governor *governor)
39294 }
39295 }
39296
39297 - list_del(&governor->node);
39298 + pax_list_del((struct list_head *)&governor->node);
39299 err_out:
39300 mutex_unlock(&devfreq_list_lock);
39301
39302 diff --git a/drivers/dma/sh/shdmac.c b/drivers/dma/sh/shdmac.c
39303 index 0d765c0..60b7480 100644
39304 --- a/drivers/dma/sh/shdmac.c
39305 +++ b/drivers/dma/sh/shdmac.c
39306 @@ -511,7 +511,7 @@ static int sh_dmae_nmi_handler(struct notifier_block *self,
39307 return ret;
39308 }
39309
39310 -static struct notifier_block sh_dmae_nmi_notifier __read_mostly = {
39311 +static struct notifier_block sh_dmae_nmi_notifier = {
39312 .notifier_call = sh_dmae_nmi_handler,
39313
39314 /* Run before NMI debug handler and KGDB */
39315 diff --git a/drivers/edac/edac_device.c b/drivers/edac/edac_device.c
39316 index 1026743..80b081c 100644
39317 --- a/drivers/edac/edac_device.c
39318 +++ b/drivers/edac/edac_device.c
39319 @@ -474,9 +474,9 @@ void edac_device_reset_delay_period(struct edac_device_ctl_info *edac_dev,
39320 */
39321 int edac_device_alloc_index(void)
39322 {
39323 - static atomic_t device_indexes = ATOMIC_INIT(0);
39324 + static atomic_unchecked_t device_indexes = ATOMIC_INIT(0);
39325
39326 - return atomic_inc_return(&device_indexes) - 1;
39327 + return atomic_inc_return_unchecked(&device_indexes) - 1;
39328 }
39329 EXPORT_SYMBOL_GPL(edac_device_alloc_index);
39330
39331 diff --git a/drivers/edac/edac_mc_sysfs.c b/drivers/edac/edac_mc_sysfs.c
39332 index e5bdf21..b8f9055 100644
39333 --- a/drivers/edac/edac_mc_sysfs.c
39334 +++ b/drivers/edac/edac_mc_sysfs.c
39335 @@ -152,7 +152,7 @@ static const char * const edac_caps[] = {
39336 struct dev_ch_attribute {
39337 struct device_attribute attr;
39338 int channel;
39339 -};
39340 +} __do_const;
39341
39342 #define DEVICE_CHANNEL(_name, _mode, _show, _store, _var) \
39343 struct dev_ch_attribute dev_attr_legacy_##_name = \
39344 @@ -1009,14 +1009,16 @@ int edac_create_sysfs_mci_device(struct mem_ctl_info *mci)
39345 }
39346
39347 if (mci->set_sdram_scrub_rate || mci->get_sdram_scrub_rate) {
39348 + pax_open_kernel();
39349 if (mci->get_sdram_scrub_rate) {
39350 - dev_attr_sdram_scrub_rate.attr.mode |= S_IRUGO;
39351 - dev_attr_sdram_scrub_rate.show = &mci_sdram_scrub_rate_show;
39352 + *(umode_t *)&dev_attr_sdram_scrub_rate.attr.mode |= S_IRUGO;
39353 + *(void **)&dev_attr_sdram_scrub_rate.show = &mci_sdram_scrub_rate_show;
39354 }
39355 if (mci->set_sdram_scrub_rate) {
39356 - dev_attr_sdram_scrub_rate.attr.mode |= S_IWUSR;
39357 - dev_attr_sdram_scrub_rate.store = &mci_sdram_scrub_rate_store;
39358 + *(umode_t *)&dev_attr_sdram_scrub_rate.attr.mode |= S_IWUSR;
39359 + *(void **)&dev_attr_sdram_scrub_rate.store = &mci_sdram_scrub_rate_store;
39360 }
39361 + pax_close_kernel();
39362 err = device_create_file(&mci->dev,
39363 &dev_attr_sdram_scrub_rate);
39364 if (err) {
39365 diff --git a/drivers/edac/edac_pci.c b/drivers/edac/edac_pci.c
39366 index 2cf44b4d..6dd2dc7 100644
39367 --- a/drivers/edac/edac_pci.c
39368 +++ b/drivers/edac/edac_pci.c
39369 @@ -29,7 +29,7 @@
39370
39371 static DEFINE_MUTEX(edac_pci_ctls_mutex);
39372 static LIST_HEAD(edac_pci_list);
39373 -static atomic_t pci_indexes = ATOMIC_INIT(0);
39374 +static atomic_unchecked_t pci_indexes = ATOMIC_INIT(0);
39375
39376 /*
39377 * edac_pci_alloc_ctl_info
39378 @@ -315,7 +315,7 @@ EXPORT_SYMBOL_GPL(edac_pci_reset_delay_period);
39379 */
39380 int edac_pci_alloc_index(void)
39381 {
39382 - return atomic_inc_return(&pci_indexes) - 1;
39383 + return atomic_inc_return_unchecked(&pci_indexes) - 1;
39384 }
39385 EXPORT_SYMBOL_GPL(edac_pci_alloc_index);
39386
39387 diff --git a/drivers/edac/edac_pci_sysfs.c b/drivers/edac/edac_pci_sysfs.c
39388 index e8658e4..22746d6 100644
39389 --- a/drivers/edac/edac_pci_sysfs.c
39390 +++ b/drivers/edac/edac_pci_sysfs.c
39391 @@ -26,8 +26,8 @@ static int edac_pci_log_pe = 1; /* log PCI parity errors */
39392 static int edac_pci_log_npe = 1; /* log PCI non-parity error errors */
39393 static int edac_pci_poll_msec = 1000; /* one second workq period */
39394
39395 -static atomic_t pci_parity_count = ATOMIC_INIT(0);
39396 -static atomic_t pci_nonparity_count = ATOMIC_INIT(0);
39397 +static atomic_unchecked_t pci_parity_count = ATOMIC_INIT(0);
39398 +static atomic_unchecked_t pci_nonparity_count = ATOMIC_INIT(0);
39399
39400 static struct kobject *edac_pci_top_main_kobj;
39401 static atomic_t edac_pci_sysfs_refcount = ATOMIC_INIT(0);
39402 @@ -235,7 +235,7 @@ struct edac_pci_dev_attribute {
39403 void *value;
39404 ssize_t(*show) (void *, char *);
39405 ssize_t(*store) (void *, const char *, size_t);
39406 -};
39407 +} __do_const;
39408
39409 /* Set of show/store abstract level functions for PCI Parity object */
39410 static ssize_t edac_pci_dev_show(struct kobject *kobj, struct attribute *attr,
39411 @@ -579,7 +579,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
39412 edac_printk(KERN_CRIT, EDAC_PCI,
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 @@ -587,7 +587,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
39421 "Master Data Parity Error on %s\n",
39422 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 @@ -595,7 +595,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 @@ -618,7 +618,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
39439 edac_printk(KERN_CRIT, EDAC_PCI, "Bridge "
39440 "Signaled System Error on %s\n",
39441 pci_name(dev));
39442 - atomic_inc(&pci_nonparity_count);
39443 + atomic_inc_unchecked(&pci_nonparity_count);
39444 }
39445
39446 if (status & (PCI_STATUS_PARITY)) {
39447 @@ -626,7 +626,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
39448 "Master Data Parity Error on "
39449 "%s\n", pci_name(dev));
39450
39451 - atomic_inc(&pci_parity_count);
39452 + atomic_inc_unchecked(&pci_parity_count);
39453 }
39454
39455 if (status & (PCI_STATUS_DETECTED_PARITY)) {
39456 @@ -634,7 +634,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
39457 "Detected Parity Error on %s\n",
39458 pci_name(dev));
39459
39460 - atomic_inc(&pci_parity_count);
39461 + atomic_inc_unchecked(&pci_parity_count);
39462 }
39463 }
39464 }
39465 @@ -672,7 +672,7 @@ void edac_pci_do_parity_check(void)
39466 if (!check_pci_errors)
39467 return;
39468
39469 - before_count = atomic_read(&pci_parity_count);
39470 + before_count = atomic_read_unchecked(&pci_parity_count);
39471
39472 /* scan all PCI devices looking for a Parity Error on devices and
39473 * bridges.
39474 @@ -684,7 +684,7 @@ void edac_pci_do_parity_check(void)
39475 /* Only if operator has selected panic on PCI Error */
39476 if (edac_pci_get_panic_on_pe()) {
39477 /* If the count is different 'after' from 'before' */
39478 - if (before_count != atomic_read(&pci_parity_count))
39479 + if (before_count != atomic_read_unchecked(&pci_parity_count))
39480 panic("EDAC: PCI Parity Error");
39481 }
39482 }
39483 diff --git a/drivers/edac/mce_amd.h b/drivers/edac/mce_amd.h
39484 index 51b7e3a..aa8a3e8 100644
39485 --- a/drivers/edac/mce_amd.h
39486 +++ b/drivers/edac/mce_amd.h
39487 @@ -77,7 +77,7 @@ struct amd_decoder_ops {
39488 bool (*mc0_mce)(u16, u8);
39489 bool (*mc1_mce)(u16, u8);
39490 bool (*mc2_mce)(u16, u8);
39491 -};
39492 +} __no_const;
39493
39494 void amd_report_gart_errors(bool);
39495 void amd_register_ecc_decoder(void (*f)(int, struct mce *));
39496 diff --git a/drivers/firewire/core-card.c b/drivers/firewire/core-card.c
39497 index 57ea7f4..af06b76 100644
39498 --- a/drivers/firewire/core-card.c
39499 +++ b/drivers/firewire/core-card.c
39500 @@ -528,9 +528,9 @@ void fw_card_initialize(struct fw_card *card,
39501 const struct fw_card_driver *driver,
39502 struct device *device)
39503 {
39504 - static atomic_t index = ATOMIC_INIT(-1);
39505 + static atomic_unchecked_t index = ATOMIC_INIT(-1);
39506
39507 - card->index = atomic_inc_return(&index);
39508 + card->index = atomic_inc_return_unchecked(&index);
39509 card->driver = driver;
39510 card->device = device;
39511 card->current_tlabel = 0;
39512 @@ -680,7 +680,7 @@ EXPORT_SYMBOL_GPL(fw_card_release);
39513
39514 void fw_core_remove_card(struct fw_card *card)
39515 {
39516 - struct fw_card_driver dummy_driver = dummy_driver_template;
39517 + fw_card_driver_no_const dummy_driver = dummy_driver_template;
39518
39519 card->driver->update_phy_reg(card, 4,
39520 PHY_LINK_ACTIVE | PHY_CONTENDER, 0);
39521 diff --git a/drivers/firewire/core-device.c b/drivers/firewire/core-device.c
39522 index 2c6d5e1..a2cca6b 100644
39523 --- a/drivers/firewire/core-device.c
39524 +++ b/drivers/firewire/core-device.c
39525 @@ -253,7 +253,7 @@ EXPORT_SYMBOL(fw_device_enable_phys_dma);
39526 struct config_rom_attribute {
39527 struct device_attribute attr;
39528 u32 key;
39529 -};
39530 +} __do_const;
39531
39532 static ssize_t show_immediate(struct device *dev,
39533 struct device_attribute *dattr, char *buf)
39534 diff --git a/drivers/firewire/core-transaction.c b/drivers/firewire/core-transaction.c
39535 index 0e79951..b180217 100644
39536 --- a/drivers/firewire/core-transaction.c
39537 +++ b/drivers/firewire/core-transaction.c
39538 @@ -38,6 +38,7 @@
39539 #include <linux/timer.h>
39540 #include <linux/types.h>
39541 #include <linux/workqueue.h>
39542 +#include <linux/sched.h>
39543
39544 #include <asm/byteorder.h>
39545
39546 diff --git a/drivers/firewire/core.h b/drivers/firewire/core.h
39547 index 515a42c..5ecf3ba 100644
39548 --- a/drivers/firewire/core.h
39549 +++ b/drivers/firewire/core.h
39550 @@ -111,6 +111,7 @@ struct fw_card_driver {
39551
39552 int (*stop_iso)(struct fw_iso_context *ctx);
39553 };
39554 +typedef struct fw_card_driver __no_const fw_card_driver_no_const;
39555
39556 void fw_card_initialize(struct fw_card *card,
39557 const struct fw_card_driver *driver, struct device *device);
39558 diff --git a/drivers/firmware/dmi-id.c b/drivers/firmware/dmi-id.c
39559 index 94a58a0..f5eba42 100644
39560 --- a/drivers/firmware/dmi-id.c
39561 +++ b/drivers/firmware/dmi-id.c
39562 @@ -16,7 +16,7 @@
39563 struct dmi_device_attribute{
39564 struct device_attribute dev_attr;
39565 int field;
39566 -};
39567 +} __do_const;
39568 #define to_dmi_dev_attr(_dev_attr) \
39569 container_of(_dev_attr, struct dmi_device_attribute, dev_attr)
39570
39571 diff --git a/drivers/firmware/dmi_scan.c b/drivers/firmware/dmi_scan.c
39572 index c7e81ff..94a7401 100644
39573 --- a/drivers/firmware/dmi_scan.c
39574 +++ b/drivers/firmware/dmi_scan.c
39575 @@ -835,7 +835,7 @@ int dmi_walk(void (*decode)(const struct dmi_header *, void *),
39576 if (buf == NULL)
39577 return -1;
39578
39579 - dmi_table(buf, dmi_len, dmi_num, decode, private_data);
39580 + dmi_table((char __force_kernel *)buf, dmi_len, dmi_num, decode, private_data);
39581
39582 iounmap(buf);
39583 return 0;
39584 diff --git a/drivers/firmware/efi/cper.c b/drivers/firmware/efi/cper.c
39585 index 1491dd4..aa910db 100644
39586 --- a/drivers/firmware/efi/cper.c
39587 +++ b/drivers/firmware/efi/cper.c
39588 @@ -41,12 +41,12 @@
39589 */
39590 u64 cper_next_record_id(void)
39591 {
39592 - static atomic64_t seq;
39593 + static atomic64_unchecked_t seq;
39594
39595 - if (!atomic64_read(&seq))
39596 - atomic64_set(&seq, ((u64)get_seconds()) << 32);
39597 + if (!atomic64_read_unchecked(&seq))
39598 + atomic64_set_unchecked(&seq, ((u64)get_seconds()) << 32);
39599
39600 - return atomic64_inc_return(&seq);
39601 + return atomic64_inc_return_unchecked(&seq);
39602 }
39603 EXPORT_SYMBOL_GPL(cper_next_record_id);
39604
39605 diff --git a/drivers/firmware/efi/efi.c b/drivers/firmware/efi/efi.c
39606 index 2e2fbde..7676c8b 100644
39607 --- a/drivers/firmware/efi/efi.c
39608 +++ b/drivers/firmware/efi/efi.c
39609 @@ -81,14 +81,16 @@ static struct attribute_group efi_subsys_attr_group = {
39610 };
39611
39612 static struct efivars generic_efivars;
39613 -static struct efivar_operations generic_ops;
39614 +static efivar_operations_no_const generic_ops __read_only;
39615
39616 static int generic_ops_register(void)
39617 {
39618 - generic_ops.get_variable = efi.get_variable;
39619 - generic_ops.set_variable = efi.set_variable;
39620 - generic_ops.get_next_variable = efi.get_next_variable;
39621 - generic_ops.query_variable_store = efi_query_variable_store;
39622 + pax_open_kernel();
39623 + *(void **)&generic_ops.get_variable = efi.get_variable;
39624 + *(void **)&generic_ops.set_variable = efi.set_variable;
39625 + *(void **)&generic_ops.get_next_variable = efi.get_next_variable;
39626 + *(void **)&generic_ops.query_variable_store = efi_query_variable_store;
39627 + pax_close_kernel();
39628
39629 return efivars_register(&generic_efivars, &generic_ops, efi_kobj);
39630 }
39631 diff --git a/drivers/firmware/efi/efivars.c b/drivers/firmware/efi/efivars.c
39632 index 3dc2482..7bd2f61 100644
39633 --- a/drivers/firmware/efi/efivars.c
39634 +++ b/drivers/firmware/efi/efivars.c
39635 @@ -456,7 +456,7 @@ efivar_create_sysfs_entry(struct efivar_entry *new_var)
39636 static int
39637 create_efivars_bin_attributes(void)
39638 {
39639 - struct bin_attribute *attr;
39640 + bin_attribute_no_const *attr;
39641 int error;
39642
39643 /* new_var */
39644 diff --git a/drivers/firmware/google/memconsole.c b/drivers/firmware/google/memconsole.c
39645 index 2a90ba6..07f3733 100644
39646 --- a/drivers/firmware/google/memconsole.c
39647 +++ b/drivers/firmware/google/memconsole.c
39648 @@ -147,7 +147,9 @@ static int __init memconsole_init(void)
39649 if (!found_memconsole())
39650 return -ENODEV;
39651
39652 - memconsole_bin_attr.size = memconsole_length;
39653 + pax_open_kernel();
39654 + *(size_t *)&memconsole_bin_attr.size = memconsole_length;
39655 + pax_close_kernel();
39656
39657 ret = sysfs_create_bin_file(firmware_kobj, &memconsole_bin_attr);
39658
39659 diff --git a/drivers/gpio/gpio-em.c b/drivers/gpio/gpio-em.c
39660 index ec19036..8ffafc2 100644
39661 --- a/drivers/gpio/gpio-em.c
39662 +++ b/drivers/gpio/gpio-em.c
39663 @@ -257,7 +257,7 @@ static int em_gio_probe(struct platform_device *pdev)
39664 struct em_gio_priv *p;
39665 struct resource *io[2], *irq[2];
39666 struct gpio_chip *gpio_chip;
39667 - struct irq_chip *irq_chip;
39668 + irq_chip_no_const *irq_chip;
39669 const char *name = dev_name(&pdev->dev);
39670 int ret;
39671
39672 diff --git a/drivers/gpio/gpio-ich.c b/drivers/gpio/gpio-ich.c
39673 index 814addb..0937d7f 100644
39674 --- a/drivers/gpio/gpio-ich.c
39675 +++ b/drivers/gpio/gpio-ich.c
39676 @@ -71,7 +71,7 @@ struct ichx_desc {
39677 /* Some chipsets have quirks, let these use their own request/get */
39678 int (*request)(struct gpio_chip *chip, unsigned offset);
39679 int (*get)(struct gpio_chip *chip, unsigned offset);
39680 -};
39681 +} __do_const;
39682
39683 static struct {
39684 spinlock_t lock;
39685 diff --git a/drivers/gpio/gpio-rcar.c b/drivers/gpio/gpio-rcar.c
39686 index 8b7e719..dc089dc 100644
39687 --- a/drivers/gpio/gpio-rcar.c
39688 +++ b/drivers/gpio/gpio-rcar.c
39689 @@ -316,7 +316,7 @@ static int gpio_rcar_probe(struct platform_device *pdev)
39690 struct gpio_rcar_priv *p;
39691 struct resource *io, *irq;
39692 struct gpio_chip *gpio_chip;
39693 - struct irq_chip *irq_chip;
39694 + irq_chip_no_const *irq_chip;
39695 const char *name = dev_name(&pdev->dev);
39696 int ret;
39697
39698 diff --git a/drivers/gpio/gpio-vr41xx.c b/drivers/gpio/gpio-vr41xx.c
39699 index 9902732..64b62dd 100644
39700 --- a/drivers/gpio/gpio-vr41xx.c
39701 +++ b/drivers/gpio/gpio-vr41xx.c
39702 @@ -204,7 +204,7 @@ static int giu_get_irq(unsigned int irq)
39703 printk(KERN_ERR "spurious GIU interrupt: %04x(%04x),%04x(%04x)\n",
39704 maskl, pendl, maskh, pendh);
39705
39706 - atomic_inc(&irq_err_count);
39707 + atomic_inc_unchecked(&irq_err_count);
39708
39709 return -EINVAL;
39710 }
39711 diff --git a/drivers/gpu/drm/drm_crtc.c b/drivers/gpu/drm/drm_crtc.c
39712 index d6cf77c..2842146 100644
39713 --- a/drivers/gpu/drm/drm_crtc.c
39714 +++ b/drivers/gpu/drm/drm_crtc.c
39715 @@ -3102,7 +3102,7 @@ int drm_mode_getproperty_ioctl(struct drm_device *dev,
39716 goto done;
39717 }
39718
39719 - if (copy_to_user(&enum_ptr[copied].name,
39720 + if (copy_to_user(enum_ptr[copied].name,
39721 &prop_enum->name, DRM_PROP_NAME_LEN)) {
39722 ret = -EFAULT;
39723 goto done;
39724 diff --git a/drivers/gpu/drm/drm_crtc_helper.c b/drivers/gpu/drm/drm_crtc_helper.c
39725 index 01361ab..891e821 100644
39726 --- a/drivers/gpu/drm/drm_crtc_helper.c
39727 +++ b/drivers/gpu/drm/drm_crtc_helper.c
39728 @@ -338,7 +338,7 @@ static bool drm_encoder_crtc_ok(struct drm_encoder *encoder,
39729 struct drm_crtc *tmp;
39730 int crtc_mask = 1;
39731
39732 - WARN(!crtc, "checking null crtc?\n");
39733 + BUG_ON(!crtc);
39734
39735 dev = crtc->dev;
39736
39737 diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c
39738 index d9137e4..69b73a0 100644
39739 --- a/drivers/gpu/drm/drm_drv.c
39740 +++ b/drivers/gpu/drm/drm_drv.c
39741 @@ -233,7 +233,7 @@ module_exit(drm_core_exit);
39742 /**
39743 * Copy and IOCTL return string to user space
39744 */
39745 -static int drm_copy_field(char *buf, size_t *buf_len, const char *value)
39746 +static int drm_copy_field(char __user *buf, size_t *buf_len, const char *value)
39747 {
39748 int len;
39749
39750 @@ -303,7 +303,7 @@ long drm_ioctl(struct file *filp,
39751 struct drm_file *file_priv = filp->private_data;
39752 struct drm_device *dev;
39753 const struct drm_ioctl_desc *ioctl = NULL;
39754 - drm_ioctl_t *func;
39755 + drm_ioctl_no_const_t func;
39756 unsigned int nr = DRM_IOCTL_NR(cmd);
39757 int retcode = -EINVAL;
39758 char stack_kdata[128];
39759 diff --git a/drivers/gpu/drm/drm_fops.c b/drivers/gpu/drm/drm_fops.c
39760 index c5b929c..8a3b8be 100644
39761 --- a/drivers/gpu/drm/drm_fops.c
39762 +++ b/drivers/gpu/drm/drm_fops.c
39763 @@ -97,7 +97,7 @@ int drm_open(struct inode *inode, struct file *filp)
39764 if (drm_device_is_unplugged(dev))
39765 return -ENODEV;
39766
39767 - if (!dev->open_count++)
39768 + if (local_inc_return(&dev->open_count) == 1)
39769 need_setup = 1;
39770 mutex_lock(&dev->struct_mutex);
39771 old_imapping = inode->i_mapping;
39772 @@ -127,7 +127,7 @@ err_undo:
39773 iput(container_of(dev->dev_mapping, struct inode, i_data));
39774 dev->dev_mapping = old_mapping;
39775 mutex_unlock(&dev->struct_mutex);
39776 - dev->open_count--;
39777 + local_dec(&dev->open_count);
39778 return retcode;
39779 }
39780 EXPORT_SYMBOL(drm_open);
39781 @@ -467,7 +467,7 @@ int drm_release(struct inode *inode, struct file *filp)
39782
39783 mutex_lock(&drm_global_mutex);
39784
39785 - DRM_DEBUG("open_count = %d\n", dev->open_count);
39786 + DRM_DEBUG("open_count = %ld\n", local_read(&dev->open_count));
39787
39788 if (dev->driver->preclose)
39789 dev->driver->preclose(dev, file_priv);
39790 @@ -476,10 +476,10 @@ int drm_release(struct inode *inode, struct file *filp)
39791 * Begin inline drm_release
39792 */
39793
39794 - DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %d\n",
39795 + DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %ld\n",
39796 task_pid_nr(current),
39797 (long)old_encode_dev(file_priv->minor->device),
39798 - dev->open_count);
39799 + local_read(&dev->open_count));
39800
39801 /* Release any auth tokens that might point to this file_priv,
39802 (do that under the drm_global_mutex) */
39803 @@ -577,7 +577,7 @@ int drm_release(struct inode *inode, struct file *filp)
39804 * End inline drm_release
39805 */
39806
39807 - if (!--dev->open_count) {
39808 + if (local_dec_and_test(&dev->open_count)) {
39809 if (atomic_read(&dev->ioctl_count)) {
39810 DRM_ERROR("Device busy: %d\n",
39811 atomic_read(&dev->ioctl_count));
39812 diff --git a/drivers/gpu/drm/drm_global.c b/drivers/gpu/drm/drm_global.c
39813 index 3d2e91c..d31c4c9 100644
39814 --- a/drivers/gpu/drm/drm_global.c
39815 +++ b/drivers/gpu/drm/drm_global.c
39816 @@ -36,7 +36,7 @@
39817 struct drm_global_item {
39818 struct mutex mutex;
39819 void *object;
39820 - int refcount;
39821 + atomic_t refcount;
39822 };
39823
39824 static struct drm_global_item glob[DRM_GLOBAL_NUM];
39825 @@ -49,7 +49,7 @@ void drm_global_init(void)
39826 struct drm_global_item *item = &glob[i];
39827 mutex_init(&item->mutex);
39828 item->object = NULL;
39829 - item->refcount = 0;
39830 + atomic_set(&item->refcount, 0);
39831 }
39832 }
39833
39834 @@ -59,7 +59,7 @@ void drm_global_release(void)
39835 for (i = 0; i < DRM_GLOBAL_NUM; ++i) {
39836 struct drm_global_item *item = &glob[i];
39837 BUG_ON(item->object != NULL);
39838 - BUG_ON(item->refcount != 0);
39839 + BUG_ON(atomic_read(&item->refcount) != 0);
39840 }
39841 }
39842
39843 @@ -69,7 +69,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
39844 struct drm_global_item *item = &glob[ref->global_type];
39845
39846 mutex_lock(&item->mutex);
39847 - if (item->refcount == 0) {
39848 + if (atomic_read(&item->refcount) == 0) {
39849 item->object = kzalloc(ref->size, GFP_KERNEL);
39850 if (unlikely(item->object == NULL)) {
39851 ret = -ENOMEM;
39852 @@ -82,7 +82,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
39853 goto out_err;
39854
39855 }
39856 - ++item->refcount;
39857 + atomic_inc(&item->refcount);
39858 ref->object = item->object;
39859 mutex_unlock(&item->mutex);
39860 return 0;
39861 @@ -98,9 +98,9 @@ void drm_global_item_unref(struct drm_global_reference *ref)
39862 struct drm_global_item *item = &glob[ref->global_type];
39863
39864 mutex_lock(&item->mutex);
39865 - BUG_ON(item->refcount == 0);
39866 + BUG_ON(atomic_read(&item->refcount) == 0);
39867 BUG_ON(ref->object != item->object);
39868 - if (--item->refcount == 0) {
39869 + if (atomic_dec_and_test(&item->refcount)) {
39870 ref->release(ref);
39871 item->object = NULL;
39872 }
39873 diff --git a/drivers/gpu/drm/drm_info.c b/drivers/gpu/drm/drm_info.c
39874 index 7d5a152..d7186da 100644
39875 --- a/drivers/gpu/drm/drm_info.c
39876 +++ b/drivers/gpu/drm/drm_info.c
39877 @@ -75,10 +75,14 @@ int drm_vm_info(struct seq_file *m, void *data)
39878 struct drm_local_map *map;
39879 struct drm_map_list *r_list;
39880
39881 - /* Hardcoded from _DRM_FRAME_BUFFER,
39882 - _DRM_REGISTERS, _DRM_SHM, _DRM_AGP, and
39883 - _DRM_SCATTER_GATHER and _DRM_CONSISTENT */
39884 - const char *types[] = { "FB", "REG", "SHM", "AGP", "SG", "PCI" };
39885 + static const char * const types[] = {
39886 + [_DRM_FRAME_BUFFER] = "FB",
39887 + [_DRM_REGISTERS] = "REG",
39888 + [_DRM_SHM] = "SHM",
39889 + [_DRM_AGP] = "AGP",
39890 + [_DRM_SCATTER_GATHER] = "SG",
39891 + [_DRM_CONSISTENT] = "PCI",
39892 + [_DRM_GEM] = "GEM" };
39893 const char *type;
39894 int i;
39895
39896 @@ -89,7 +93,7 @@ int drm_vm_info(struct seq_file *m, void *data)
39897 map = r_list->map;
39898 if (!map)
39899 continue;
39900 - if (map->type < 0 || map->type > 5)
39901 + if (map->type >= ARRAY_SIZE(types))
39902 type = "??";
39903 else
39904 type = types[map->type];
39905 @@ -257,7 +261,11 @@ int drm_vma_info(struct seq_file *m, void *data)
39906 vma->vm_flags & VM_MAYSHARE ? 's' : 'p',
39907 vma->vm_flags & VM_LOCKED ? 'l' : '-',
39908 vma->vm_flags & VM_IO ? 'i' : '-',
39909 +#ifdef CONFIG_GRKERNSEC_HIDESYM
39910 + 0);
39911 +#else
39912 vma->vm_pgoff);
39913 +#endif
39914
39915 #if defined(__i386__)
39916 pgprot = pgprot_val(vma->vm_page_prot);
39917 diff --git a/drivers/gpu/drm/drm_ioc32.c b/drivers/gpu/drm/drm_ioc32.c
39918 index 2f4c4343..dd12cd2 100644
39919 --- a/drivers/gpu/drm/drm_ioc32.c
39920 +++ b/drivers/gpu/drm/drm_ioc32.c
39921 @@ -457,7 +457,7 @@ static int compat_drm_infobufs(struct file *file, unsigned int cmd,
39922 request = compat_alloc_user_space(nbytes);
39923 if (!access_ok(VERIFY_WRITE, request, nbytes))
39924 return -EFAULT;
39925 - list = (struct drm_buf_desc *) (request + 1);
39926 + list = (struct drm_buf_desc __user *) (request + 1);
39927
39928 if (__put_user(count, &request->count)
39929 || __put_user(list, &request->list))
39930 @@ -518,7 +518,7 @@ static int compat_drm_mapbufs(struct file *file, unsigned int cmd,
39931 request = compat_alloc_user_space(nbytes);
39932 if (!access_ok(VERIFY_WRITE, request, nbytes))
39933 return -EFAULT;
39934 - list = (struct drm_buf_pub *) (request + 1);
39935 + list = (struct drm_buf_pub __user *) (request + 1);
39936
39937 if (__put_user(count, &request->count)
39938 || __put_user(list, &request->list))
39939 @@ -1016,7 +1016,7 @@ static int compat_drm_wait_vblank(struct file *file, unsigned int cmd,
39940 return 0;
39941 }
39942
39943 -drm_ioctl_compat_t *drm_compat_ioctls[] = {
39944 +drm_ioctl_compat_t drm_compat_ioctls[] = {
39945 [DRM_IOCTL_NR(DRM_IOCTL_VERSION32)] = compat_drm_version,
39946 [DRM_IOCTL_NR(DRM_IOCTL_GET_UNIQUE32)] = compat_drm_getunique,
39947 [DRM_IOCTL_NR(DRM_IOCTL_GET_MAP32)] = compat_drm_getmap,
39948 @@ -1062,7 +1062,6 @@ drm_ioctl_compat_t *drm_compat_ioctls[] = {
39949 long drm_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
39950 {
39951 unsigned int nr = DRM_IOCTL_NR(cmd);
39952 - drm_ioctl_compat_t *fn;
39953 int ret;
39954
39955 /* Assume that ioctls without an explicit compat routine will just
39956 @@ -1072,10 +1071,8 @@ long drm_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
39957 if (nr >= ARRAY_SIZE(drm_compat_ioctls))
39958 return drm_ioctl(filp, cmd, arg);
39959
39960 - fn = drm_compat_ioctls[nr];
39961 -
39962 - if (fn != NULL)
39963 - ret = (*fn) (filp, cmd, arg);
39964 + if (drm_compat_ioctls[nr] != NULL)
39965 + ret = (*drm_compat_ioctls[nr]) (filp, cmd, arg);
39966 else
39967 ret = drm_ioctl(filp, cmd, arg);
39968
39969 diff --git a/drivers/gpu/drm/drm_stub.c b/drivers/gpu/drm/drm_stub.c
39970 index 66dd3a0..3bed6c4 100644
39971 --- a/drivers/gpu/drm/drm_stub.c
39972 +++ b/drivers/gpu/drm/drm_stub.c
39973 @@ -403,7 +403,7 @@ void drm_unplug_dev(struct drm_device *dev)
39974
39975 drm_device_set_unplugged(dev);
39976
39977 - if (dev->open_count == 0) {
39978 + if (local_read(&dev->open_count) == 0) {
39979 drm_put_dev(dev);
39980 }
39981 mutex_unlock(&drm_global_mutex);
39982 diff --git a/drivers/gpu/drm/drm_sysfs.c b/drivers/gpu/drm/drm_sysfs.c
39983 index c22c309..ae758c3 100644
39984 --- a/drivers/gpu/drm/drm_sysfs.c
39985 +++ b/drivers/gpu/drm/drm_sysfs.c
39986 @@ -505,7 +505,7 @@ static void drm_sysfs_release(struct device *dev)
39987 */
39988 int drm_sysfs_device_add(struct drm_minor *minor)
39989 {
39990 - char *minor_str;
39991 + const char *minor_str;
39992 int r;
39993
39994 if (minor->type == DRM_MINOR_CONTROL)
39995 diff --git a/drivers/gpu/drm/i810/i810_drv.h b/drivers/gpu/drm/i810/i810_drv.h
39996 index d4d16ed..8fb0b51 100644
39997 --- a/drivers/gpu/drm/i810/i810_drv.h
39998 +++ b/drivers/gpu/drm/i810/i810_drv.h
39999 @@ -108,8 +108,8 @@ typedef struct drm_i810_private {
40000 int page_flipping;
40001
40002 wait_queue_head_t irq_queue;
40003 - atomic_t irq_received;
40004 - atomic_t irq_emitted;
40005 + atomic_unchecked_t irq_received;
40006 + atomic_unchecked_t irq_emitted;
40007
40008 int front_offset;
40009 } drm_i810_private_t;
40010 diff --git a/drivers/gpu/drm/i915/i915_debugfs.c b/drivers/gpu/drm/i915/i915_debugfs.c
40011 index 6ed45a9..eb6dc41 100644
40012 --- a/drivers/gpu/drm/i915/i915_debugfs.c
40013 +++ b/drivers/gpu/drm/i915/i915_debugfs.c
40014 @@ -702,7 +702,7 @@ static int i915_interrupt_info(struct seq_file *m, void *data)
40015 I915_READ(GTIMR));
40016 }
40017 seq_printf(m, "Interrupts received: %d\n",
40018 - atomic_read(&dev_priv->irq_received));
40019 + atomic_read_unchecked(&dev_priv->irq_received));
40020 for_each_ring(ring, dev_priv, i) {
40021 if (INTEL_INFO(dev)->gen >= 6) {
40022 seq_printf(m,
40023 diff --git a/drivers/gpu/drm/i915/i915_dma.c b/drivers/gpu/drm/i915/i915_dma.c
40024 index e02266a..e3411aa 100644
40025 --- a/drivers/gpu/drm/i915/i915_dma.c
40026 +++ b/drivers/gpu/drm/i915/i915_dma.c
40027 @@ -1271,7 +1271,7 @@ static bool i915_switcheroo_can_switch(struct pci_dev *pdev)
40028 bool can_switch;
40029
40030 spin_lock(&dev->count_lock);
40031 - can_switch = (dev->open_count == 0);
40032 + can_switch = (local_read(&dev->open_count) == 0);
40033 spin_unlock(&dev->count_lock);
40034 return can_switch;
40035 }
40036 diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h
40037 index 221ac62..f56acc8 100644
40038 --- a/drivers/gpu/drm/i915/i915_drv.h
40039 +++ b/drivers/gpu/drm/i915/i915_drv.h
40040 @@ -1326,7 +1326,7 @@ typedef struct drm_i915_private {
40041 drm_dma_handle_t *status_page_dmah;
40042 struct resource mch_res;
40043
40044 - atomic_t irq_received;
40045 + atomic_unchecked_t irq_received;
40046
40047 /* protects the irq masks */
40048 spinlock_t irq_lock;
40049 diff --git a/drivers/gpu/drm/i915/i915_gem_execbuffer.c b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
40050 index a3ba9a8..ee52ddd 100644
40051 --- a/drivers/gpu/drm/i915/i915_gem_execbuffer.c
40052 +++ b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
40053 @@ -861,9 +861,9 @@ i915_gem_check_execbuffer(struct drm_i915_gem_execbuffer2 *exec)
40054
40055 static int
40056 validate_exec_list(struct drm_i915_gem_exec_object2 *exec,
40057 - int count)
40058 + unsigned int count)
40059 {
40060 - int i;
40061 + unsigned int i;
40062 unsigned relocs_total = 0;
40063 unsigned relocs_max = UINT_MAX / sizeof(struct drm_i915_gem_relocation_entry);
40064
40065 diff --git a/drivers/gpu/drm/i915/i915_ioc32.c b/drivers/gpu/drm/i915/i915_ioc32.c
40066 index 3c59584..500f2e9 100644
40067 --- a/drivers/gpu/drm/i915/i915_ioc32.c
40068 +++ b/drivers/gpu/drm/i915/i915_ioc32.c
40069 @@ -181,7 +181,7 @@ static int compat_i915_alloc(struct file *file, unsigned int cmd,
40070 (unsigned long)request);
40071 }
40072
40073 -static drm_ioctl_compat_t *i915_compat_ioctls[] = {
40074 +static drm_ioctl_compat_t i915_compat_ioctls[] = {
40075 [DRM_I915_BATCHBUFFER] = compat_i915_batchbuffer,
40076 [DRM_I915_CMDBUFFER] = compat_i915_cmdbuffer,
40077 [DRM_I915_GETPARAM] = compat_i915_getparam,
40078 @@ -202,18 +202,15 @@ static drm_ioctl_compat_t *i915_compat_ioctls[] = {
40079 long i915_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
40080 {
40081 unsigned int nr = DRM_IOCTL_NR(cmd);
40082 - drm_ioctl_compat_t *fn = NULL;
40083 int ret;
40084
40085 if (nr < DRM_COMMAND_BASE)
40086 return drm_compat_ioctl(filp, cmd, arg);
40087
40088 - if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(i915_compat_ioctls))
40089 - fn = i915_compat_ioctls[nr - DRM_COMMAND_BASE];
40090 -
40091 - if (fn != NULL)
40092 + if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(i915_compat_ioctls)) {
40093 + drm_ioctl_compat_t fn = i915_compat_ioctls[nr - DRM_COMMAND_BASE];
40094 ret = (*fn) (filp, cmd, arg);
40095 - else
40096 + } else
40097 ret = drm_ioctl(filp, cmd, arg);
40098
40099 return ret;
40100 diff --git a/drivers/gpu/drm/i915/i915_irq.c b/drivers/gpu/drm/i915/i915_irq.c
40101 index 9702704..3fb9e40 100644
40102 --- a/drivers/gpu/drm/i915/i915_irq.c
40103 +++ b/drivers/gpu/drm/i915/i915_irq.c
40104 @@ -1419,7 +1419,7 @@ static irqreturn_t valleyview_irq_handler(int irq, void *arg)
40105 int pipe;
40106 u32 pipe_stats[I915_MAX_PIPES];
40107
40108 - atomic_inc(&dev_priv->irq_received);
40109 + atomic_inc_unchecked(&dev_priv->irq_received);
40110
40111 while (true) {
40112 iir = I915_READ(VLV_IIR);
40113 @@ -1729,7 +1729,7 @@ static irqreturn_t ironlake_irq_handler(int irq, void *arg)
40114 u32 de_iir, gt_iir, de_ier, sde_ier = 0;
40115 irqreturn_t ret = IRQ_NONE;
40116
40117 - atomic_inc(&dev_priv->irq_received);
40118 + atomic_inc_unchecked(&dev_priv->irq_received);
40119
40120 /* We get interrupts on unclaimed registers, so check for this before we
40121 * do any I915_{READ,WRITE}. */
40122 @@ -1799,7 +1799,7 @@ static irqreturn_t gen8_irq_handler(int irq, void *arg)
40123 uint32_t tmp = 0;
40124 enum pipe pipe;
40125
40126 - atomic_inc(&dev_priv->irq_received);
40127 + atomic_inc_unchecked(&dev_priv->irq_received);
40128
40129 master_ctl = I915_READ(GEN8_MASTER_IRQ);
40130 master_ctl &= ~GEN8_MASTER_IRQ_CONTROL;
40131 @@ -2623,7 +2623,7 @@ static void ironlake_irq_preinstall(struct drm_device *dev)
40132 {
40133 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
40134
40135 - atomic_set(&dev_priv->irq_received, 0);
40136 + atomic_set_unchecked(&dev_priv->irq_received, 0);
40137
40138 I915_WRITE(HWSTAM, 0xeffe);
40139
40140 @@ -2641,7 +2641,7 @@ static void valleyview_irq_preinstall(struct drm_device *dev)
40141 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
40142 int pipe;
40143
40144 - atomic_set(&dev_priv->irq_received, 0);
40145 + atomic_set_unchecked(&dev_priv->irq_received, 0);
40146
40147 /* VLV magic */
40148 I915_WRITE(VLV_IMR, 0);
40149 @@ -2672,7 +2672,7 @@ static void gen8_irq_preinstall(struct drm_device *dev)
40150 struct drm_i915_private *dev_priv = dev->dev_private;
40151 int pipe;
40152
40153 - atomic_set(&dev_priv->irq_received, 0);
40154 + atomic_set_unchecked(&dev_priv->irq_received, 0);
40155
40156 I915_WRITE(GEN8_MASTER_IRQ, 0);
40157 POSTING_READ(GEN8_MASTER_IRQ);
40158 @@ -2996,7 +2996,7 @@ static void gen8_irq_uninstall(struct drm_device *dev)
40159 if (!dev_priv)
40160 return;
40161
40162 - atomic_set(&dev_priv->irq_received, 0);
40163 + atomic_set_unchecked(&dev_priv->irq_received, 0);
40164
40165 I915_WRITE(GEN8_MASTER_IRQ, 0);
40166
40167 @@ -3090,7 +3090,7 @@ static void i8xx_irq_preinstall(struct drm_device * dev)
40168 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
40169 int pipe;
40170
40171 - atomic_set(&dev_priv->irq_received, 0);
40172 + atomic_set_unchecked(&dev_priv->irq_received, 0);
40173
40174 for_each_pipe(pipe)
40175 I915_WRITE(PIPESTAT(pipe), 0);
40176 @@ -3176,7 +3176,7 @@ static irqreturn_t i8xx_irq_handler(int irq, void *arg)
40177 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
40178 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
40179
40180 - atomic_inc(&dev_priv->irq_received);
40181 + atomic_inc_unchecked(&dev_priv->irq_received);
40182
40183 iir = I915_READ16(IIR);
40184 if (iir == 0)
40185 @@ -3251,7 +3251,7 @@ static void i915_irq_preinstall(struct drm_device * dev)
40186 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
40187 int pipe;
40188
40189 - atomic_set(&dev_priv->irq_received, 0);
40190 + atomic_set_unchecked(&dev_priv->irq_received, 0);
40191
40192 if (I915_HAS_HOTPLUG(dev)) {
40193 I915_WRITE(PORT_HOTPLUG_EN, 0);
40194 @@ -3358,7 +3358,7 @@ static irqreturn_t i915_irq_handler(int irq, void *arg)
40195 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
40196 int pipe, ret = IRQ_NONE;
40197
40198 - atomic_inc(&dev_priv->irq_received);
40199 + atomic_inc_unchecked(&dev_priv->irq_received);
40200
40201 iir = I915_READ(IIR);
40202 do {
40203 @@ -3485,7 +3485,7 @@ static void i965_irq_preinstall(struct drm_device * dev)
40204 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
40205 int pipe;
40206
40207 - atomic_set(&dev_priv->irq_received, 0);
40208 + atomic_set_unchecked(&dev_priv->irq_received, 0);
40209
40210 I915_WRITE(PORT_HOTPLUG_EN, 0);
40211 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
40212 @@ -3601,7 +3601,7 @@ static irqreturn_t i965_irq_handler(int irq, void *arg)
40213 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
40214 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
40215
40216 - atomic_inc(&dev_priv->irq_received);
40217 + atomic_inc_unchecked(&dev_priv->irq_received);
40218
40219 iir = I915_READ(IIR);
40220
40221 diff --git a/drivers/gpu/drm/i915/intel_display.c b/drivers/gpu/drm/i915/intel_display.c
40222 index 3c5ff7a..ae759ca 100644
40223 --- a/drivers/gpu/drm/i915/intel_display.c
40224 +++ b/drivers/gpu/drm/i915/intel_display.c
40225 @@ -10506,13 +10506,13 @@ struct intel_quirk {
40226 int subsystem_vendor;
40227 int subsystem_device;
40228 void (*hook)(struct drm_device *dev);
40229 -};
40230 +} __do_const;
40231
40232 /* For systems that don't have a meaningful PCI subdevice/subvendor ID */
40233 struct intel_dmi_quirk {
40234 void (*hook)(struct drm_device *dev);
40235 const struct dmi_system_id (*dmi_id_list)[];
40236 -};
40237 +} __do_const;
40238
40239 static int intel_dmi_reverse_brightness(const struct dmi_system_id *id)
40240 {
40241 @@ -10520,18 +10520,20 @@ static int intel_dmi_reverse_brightness(const struct dmi_system_id *id)
40242 return 1;
40243 }
40244
40245 -static const struct intel_dmi_quirk intel_dmi_quirks[] = {
40246 +static const struct dmi_system_id intel_dmi_quirks_table[] = {
40247 {
40248 - .dmi_id_list = &(const struct dmi_system_id[]) {
40249 - {
40250 - .callback = intel_dmi_reverse_brightness,
40251 - .ident = "NCR Corporation",
40252 - .matches = {DMI_MATCH(DMI_SYS_VENDOR, "NCR Corporation"),
40253 - DMI_MATCH(DMI_PRODUCT_NAME, ""),
40254 - },
40255 - },
40256 - { } /* terminating entry */
40257 + .callback = intel_dmi_reverse_brightness,
40258 + .ident = "NCR Corporation",
40259 + .matches = {DMI_MATCH(DMI_SYS_VENDOR, "NCR Corporation"),
40260 + DMI_MATCH(DMI_PRODUCT_NAME, ""),
40261 },
40262 + },
40263 + { } /* terminating entry */
40264 +};
40265 +
40266 +static const struct intel_dmi_quirk intel_dmi_quirks[] = {
40267 + {
40268 + .dmi_id_list = &intel_dmi_quirks_table,
40269 .hook = quirk_invert_brightness,
40270 },
40271 };
40272 diff --git a/drivers/gpu/drm/mga/mga_drv.h b/drivers/gpu/drm/mga/mga_drv.h
40273 index ca4bc54..ee598a2 100644
40274 --- a/drivers/gpu/drm/mga/mga_drv.h
40275 +++ b/drivers/gpu/drm/mga/mga_drv.h
40276 @@ -120,9 +120,9 @@ typedef struct drm_mga_private {
40277 u32 clear_cmd;
40278 u32 maccess;
40279
40280 - atomic_t vbl_received; /**< Number of vblanks received. */
40281 + atomic_unchecked_t vbl_received; /**< Number of vblanks received. */
40282 wait_queue_head_t fence_queue;
40283 - atomic_t last_fence_retired;
40284 + atomic_unchecked_t last_fence_retired;
40285 u32 next_fence_to_post;
40286
40287 unsigned int fb_cpp;
40288 diff --git a/drivers/gpu/drm/mga/mga_ioc32.c b/drivers/gpu/drm/mga/mga_ioc32.c
40289 index 709e90d..89a1c0d 100644
40290 --- a/drivers/gpu/drm/mga/mga_ioc32.c
40291 +++ b/drivers/gpu/drm/mga/mga_ioc32.c
40292 @@ -189,7 +189,7 @@ static int compat_mga_dma_bootstrap(struct file *file, unsigned int cmd,
40293 return 0;
40294 }
40295
40296 -drm_ioctl_compat_t *mga_compat_ioctls[] = {
40297 +drm_ioctl_compat_t mga_compat_ioctls[] = {
40298 [DRM_MGA_INIT] = compat_mga_init,
40299 [DRM_MGA_GETPARAM] = compat_mga_getparam,
40300 [DRM_MGA_DMA_BOOTSTRAP] = compat_mga_dma_bootstrap,
40301 @@ -207,18 +207,15 @@ drm_ioctl_compat_t *mga_compat_ioctls[] = {
40302 long mga_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
40303 {
40304 unsigned int nr = DRM_IOCTL_NR(cmd);
40305 - drm_ioctl_compat_t *fn = NULL;
40306 int ret;
40307
40308 if (nr < DRM_COMMAND_BASE)
40309 return drm_compat_ioctl(filp, cmd, arg);
40310
40311 - if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(mga_compat_ioctls))
40312 - fn = mga_compat_ioctls[nr - DRM_COMMAND_BASE];
40313 -
40314 - if (fn != NULL)
40315 + if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(mga_compat_ioctls)) {
40316 + drm_ioctl_compat_t fn = mga_compat_ioctls[nr - DRM_COMMAND_BASE];
40317 ret = (*fn) (filp, cmd, arg);
40318 - else
40319 + } else
40320 ret = drm_ioctl(filp, cmd, arg);
40321
40322 return ret;
40323 diff --git a/drivers/gpu/drm/mga/mga_irq.c b/drivers/gpu/drm/mga/mga_irq.c
40324 index 2b0ceb8..517e99e 100644
40325 --- a/drivers/gpu/drm/mga/mga_irq.c
40326 +++ b/drivers/gpu/drm/mga/mga_irq.c
40327 @@ -43,7 +43,7 @@ u32 mga_get_vblank_counter(struct drm_device *dev, int crtc)
40328 if (crtc != 0)
40329 return 0;
40330
40331 - return atomic_read(&dev_priv->vbl_received);
40332 + return atomic_read_unchecked(&dev_priv->vbl_received);
40333 }
40334
40335
40336 @@ -59,7 +59,7 @@ irqreturn_t mga_driver_irq_handler(DRM_IRQ_ARGS)
40337 /* VBLANK interrupt */
40338 if (status & MGA_VLINEPEN) {
40339 MGA_WRITE(MGA_ICLEAR, MGA_VLINEICLR);
40340 - atomic_inc(&dev_priv->vbl_received);
40341 + atomic_inc_unchecked(&dev_priv->vbl_received);
40342 drm_handle_vblank(dev, 0);
40343 handled = 1;
40344 }
40345 @@ -78,7 +78,7 @@ irqreturn_t mga_driver_irq_handler(DRM_IRQ_ARGS)
40346 if ((prim_start & ~0x03) != (prim_end & ~0x03))
40347 MGA_WRITE(MGA_PRIMEND, prim_end);
40348
40349 - atomic_inc(&dev_priv->last_fence_retired);
40350 + atomic_inc_unchecked(&dev_priv->last_fence_retired);
40351 DRM_WAKEUP(&dev_priv->fence_queue);
40352 handled = 1;
40353 }
40354 @@ -129,7 +129,7 @@ int mga_driver_fence_wait(struct drm_device *dev, unsigned int *sequence)
40355 * using fences.
40356 */
40357 DRM_WAIT_ON(ret, dev_priv->fence_queue, 3 * DRM_HZ,
40358 - (((cur_fence = atomic_read(&dev_priv->last_fence_retired))
40359 + (((cur_fence = atomic_read_unchecked(&dev_priv->last_fence_retired))
40360 - *sequence) <= (1 << 23)));
40361
40362 *sequence = cur_fence;
40363 diff --git a/drivers/gpu/drm/nouveau/nouveau_bios.c b/drivers/gpu/drm/nouveau/nouveau_bios.c
40364 index 4c3feaa..26391ce 100644
40365 --- a/drivers/gpu/drm/nouveau/nouveau_bios.c
40366 +++ b/drivers/gpu/drm/nouveau/nouveau_bios.c
40367 @@ -965,7 +965,7 @@ static int parse_bit_tmds_tbl_entry(struct drm_device *dev, struct nvbios *bios,
40368 struct bit_table {
40369 const char id;
40370 int (* const parse_fn)(struct drm_device *, struct nvbios *, struct bit_entry *);
40371 -};
40372 +} __no_const;
40373
40374 #define BIT_TABLE(id, funcid) ((struct bit_table){ id, parse_bit_##funcid##_tbl_entry })
40375
40376 diff --git a/drivers/gpu/drm/nouveau/nouveau_drm.h b/drivers/gpu/drm/nouveau/nouveau_drm.h
40377 index 4b0fb6c..67667a9 100644
40378 --- a/drivers/gpu/drm/nouveau/nouveau_drm.h
40379 +++ b/drivers/gpu/drm/nouveau/nouveau_drm.h
40380 @@ -96,7 +96,6 @@ struct nouveau_drm {
40381 struct drm_global_reference mem_global_ref;
40382 struct ttm_bo_global_ref bo_global_ref;
40383 struct ttm_bo_device bdev;
40384 - atomic_t validate_sequence;
40385 int (*move)(struct nouveau_channel *,
40386 struct ttm_buffer_object *,
40387 struct ttm_mem_reg *, struct ttm_mem_reg *);
40388 diff --git a/drivers/gpu/drm/nouveau/nouveau_ioc32.c b/drivers/gpu/drm/nouveau/nouveau_ioc32.c
40389 index c1a7e5a..38b8539 100644
40390 --- a/drivers/gpu/drm/nouveau/nouveau_ioc32.c
40391 +++ b/drivers/gpu/drm/nouveau/nouveau_ioc32.c
40392 @@ -50,7 +50,7 @@ long nouveau_compat_ioctl(struct file *filp, unsigned int cmd,
40393 unsigned long arg)
40394 {
40395 unsigned int nr = DRM_IOCTL_NR(cmd);
40396 - drm_ioctl_compat_t *fn = NULL;
40397 + drm_ioctl_compat_t fn = NULL;
40398 int ret;
40399
40400 if (nr < DRM_COMMAND_BASE)
40401 diff --git a/drivers/gpu/drm/nouveau/nouveau_ttm.c b/drivers/gpu/drm/nouveau/nouveau_ttm.c
40402 index 19e3757..ad16478 100644
40403 --- a/drivers/gpu/drm/nouveau/nouveau_ttm.c
40404 +++ b/drivers/gpu/drm/nouveau/nouveau_ttm.c
40405 @@ -130,11 +130,11 @@ nouveau_vram_manager_debug(struct ttm_mem_type_manager *man, const char *prefix)
40406 }
40407
40408 const struct ttm_mem_type_manager_func nouveau_vram_manager = {
40409 - nouveau_vram_manager_init,
40410 - nouveau_vram_manager_fini,
40411 - nouveau_vram_manager_new,
40412 - nouveau_vram_manager_del,
40413 - nouveau_vram_manager_debug
40414 + .init = nouveau_vram_manager_init,
40415 + .takedown = nouveau_vram_manager_fini,
40416 + .get_node = nouveau_vram_manager_new,
40417 + .put_node = nouveau_vram_manager_del,
40418 + .debug = nouveau_vram_manager_debug
40419 };
40420
40421 static int
40422 @@ -198,11 +198,11 @@ nouveau_gart_manager_debug(struct ttm_mem_type_manager *man, const char *prefix)
40423 }
40424
40425 const struct ttm_mem_type_manager_func nouveau_gart_manager = {
40426 - nouveau_gart_manager_init,
40427 - nouveau_gart_manager_fini,
40428 - nouveau_gart_manager_new,
40429 - nouveau_gart_manager_del,
40430 - nouveau_gart_manager_debug
40431 + .init = nouveau_gart_manager_init,
40432 + .takedown = nouveau_gart_manager_fini,
40433 + .get_node = nouveau_gart_manager_new,
40434 + .put_node = nouveau_gart_manager_del,
40435 + .debug = nouveau_gart_manager_debug
40436 };
40437
40438 #include <core/subdev/vm/nv04.h>
40439 @@ -270,11 +270,11 @@ nv04_gart_manager_debug(struct ttm_mem_type_manager *man, const char *prefix)
40440 }
40441
40442 const struct ttm_mem_type_manager_func nv04_gart_manager = {
40443 - nv04_gart_manager_init,
40444 - nv04_gart_manager_fini,
40445 - nv04_gart_manager_new,
40446 - nv04_gart_manager_del,
40447 - nv04_gart_manager_debug
40448 + .init = nv04_gart_manager_init,
40449 + .takedown = nv04_gart_manager_fini,
40450 + .get_node = nv04_gart_manager_new,
40451 + .put_node = nv04_gart_manager_del,
40452 + .debug = nv04_gart_manager_debug
40453 };
40454
40455 int
40456 diff --git a/drivers/gpu/drm/nouveau/nouveau_vga.c b/drivers/gpu/drm/nouveau/nouveau_vga.c
40457 index 81638d7..2e45854 100644
40458 --- a/drivers/gpu/drm/nouveau/nouveau_vga.c
40459 +++ b/drivers/gpu/drm/nouveau/nouveau_vga.c
40460 @@ -65,7 +65,7 @@ nouveau_switcheroo_can_switch(struct pci_dev *pdev)
40461 bool can_switch;
40462
40463 spin_lock(&dev->count_lock);
40464 - can_switch = (dev->open_count == 0);
40465 + can_switch = (local_read(&dev->open_count) == 0);
40466 spin_unlock(&dev->count_lock);
40467 return can_switch;
40468 }
40469 diff --git a/drivers/gpu/drm/qxl/qxl_cmd.c b/drivers/gpu/drm/qxl/qxl_cmd.c
40470 index eb89653..613cf71 100644
40471 --- a/drivers/gpu/drm/qxl/qxl_cmd.c
40472 +++ b/drivers/gpu/drm/qxl/qxl_cmd.c
40473 @@ -285,27 +285,27 @@ static int wait_for_io_cmd_user(struct qxl_device *qdev, uint8_t val, long port,
40474 int ret;
40475
40476 mutex_lock(&qdev->async_io_mutex);
40477 - irq_num = atomic_read(&qdev->irq_received_io_cmd);
40478 + irq_num = atomic_read_unchecked(&qdev->irq_received_io_cmd);
40479 if (qdev->last_sent_io_cmd > irq_num) {
40480 if (intr)
40481 ret = wait_event_interruptible_timeout(qdev->io_cmd_event,
40482 - atomic_read(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
40483 + atomic_read_unchecked(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
40484 else
40485 ret = wait_event_timeout(qdev->io_cmd_event,
40486 - atomic_read(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
40487 + atomic_read_unchecked(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
40488 /* 0 is timeout, just bail the "hw" has gone away */
40489 if (ret <= 0)
40490 goto out;
40491 - irq_num = atomic_read(&qdev->irq_received_io_cmd);
40492 + irq_num = atomic_read_unchecked(&qdev->irq_received_io_cmd);
40493 }
40494 outb(val, addr);
40495 qdev->last_sent_io_cmd = irq_num + 1;
40496 if (intr)
40497 ret = wait_event_interruptible_timeout(qdev->io_cmd_event,
40498 - atomic_read(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
40499 + atomic_read_unchecked(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
40500 else
40501 ret = wait_event_timeout(qdev->io_cmd_event,
40502 - atomic_read(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
40503 + atomic_read_unchecked(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
40504 out:
40505 if (ret > 0)
40506 ret = 0;
40507 diff --git a/drivers/gpu/drm/qxl/qxl_debugfs.c b/drivers/gpu/drm/qxl/qxl_debugfs.c
40508 index c3c2bbd..bc3c0fb 100644
40509 --- a/drivers/gpu/drm/qxl/qxl_debugfs.c
40510 +++ b/drivers/gpu/drm/qxl/qxl_debugfs.c
40511 @@ -42,10 +42,10 @@ qxl_debugfs_irq_received(struct seq_file *m, void *data)
40512 struct drm_info_node *node = (struct drm_info_node *) m->private;
40513 struct qxl_device *qdev = node->minor->dev->dev_private;
40514
40515 - seq_printf(m, "%d\n", atomic_read(&qdev->irq_received));
40516 - seq_printf(m, "%d\n", atomic_read(&qdev->irq_received_display));
40517 - seq_printf(m, "%d\n", atomic_read(&qdev->irq_received_cursor));
40518 - seq_printf(m, "%d\n", atomic_read(&qdev->irq_received_io_cmd));
40519 + seq_printf(m, "%d\n", atomic_read_unchecked(&qdev->irq_received));
40520 + seq_printf(m, "%d\n", atomic_read_unchecked(&qdev->irq_received_display));
40521 + seq_printf(m, "%d\n", atomic_read_unchecked(&qdev->irq_received_cursor));
40522 + seq_printf(m, "%d\n", atomic_read_unchecked(&qdev->irq_received_io_cmd));
40523 seq_printf(m, "%d\n", qdev->irq_received_error);
40524 return 0;
40525 }
40526 diff --git a/drivers/gpu/drm/qxl/qxl_drv.h b/drivers/gpu/drm/qxl/qxl_drv.h
40527 index 7bda32f..dd98fc5 100644
40528 --- a/drivers/gpu/drm/qxl/qxl_drv.h
40529 +++ b/drivers/gpu/drm/qxl/qxl_drv.h
40530 @@ -290,10 +290,10 @@ struct qxl_device {
40531 unsigned int last_sent_io_cmd;
40532
40533 /* interrupt handling */
40534 - atomic_t irq_received;
40535 - atomic_t irq_received_display;
40536 - atomic_t irq_received_cursor;
40537 - atomic_t irq_received_io_cmd;
40538 + atomic_unchecked_t irq_received;
40539 + atomic_unchecked_t irq_received_display;
40540 + atomic_unchecked_t irq_received_cursor;
40541 + atomic_unchecked_t irq_received_io_cmd;
40542 unsigned irq_received_error;
40543 wait_queue_head_t display_event;
40544 wait_queue_head_t cursor_event;
40545 diff --git a/drivers/gpu/drm/qxl/qxl_ioctl.c b/drivers/gpu/drm/qxl/qxl_ioctl.c
40546 index 7b95c75..9cffb4f 100644
40547 --- a/drivers/gpu/drm/qxl/qxl_ioctl.c
40548 +++ b/drivers/gpu/drm/qxl/qxl_ioctl.c
40549 @@ -181,7 +181,7 @@ static int qxl_process_single_command(struct qxl_device *qdev,
40550
40551 /* TODO copy slow path code from i915 */
40552 fb_cmd = qxl_bo_kmap_atomic_page(qdev, cmd_bo, (release->release_offset & PAGE_SIZE));
40553 - 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);
40554 + 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);
40555
40556 {
40557 struct qxl_drawable *draw = fb_cmd;
40558 @@ -201,7 +201,7 @@ static int qxl_process_single_command(struct qxl_device *qdev,
40559 struct drm_qxl_reloc reloc;
40560
40561 if (DRM_COPY_FROM_USER(&reloc,
40562 - &((struct drm_qxl_reloc *)(uintptr_t)cmd->relocs)[i],
40563 + &((struct drm_qxl_reloc __force_user *)(uintptr_t)cmd->relocs)[i],
40564 sizeof(reloc))) {
40565 ret = -EFAULT;
40566 goto out_free_bos;
40567 @@ -297,7 +297,7 @@ static int qxl_execbuffer_ioctl(struct drm_device *dev, void *data,
40568 struct drm_qxl_command *commands =
40569 (struct drm_qxl_command *)(uintptr_t)execbuffer->commands;
40570
40571 - if (DRM_COPY_FROM_USER(&user_cmd, &commands[cmd_num],
40572 + if (DRM_COPY_FROM_USER(&user_cmd, (struct drm_qxl_command __force_user *)&commands[cmd_num],
40573 sizeof(user_cmd)))
40574 return -EFAULT;
40575
40576 diff --git a/drivers/gpu/drm/qxl/qxl_irq.c b/drivers/gpu/drm/qxl/qxl_irq.c
40577 index 21393dc..329f3a9 100644
40578 --- a/drivers/gpu/drm/qxl/qxl_irq.c
40579 +++ b/drivers/gpu/drm/qxl/qxl_irq.c
40580 @@ -33,19 +33,19 @@ irqreturn_t qxl_irq_handler(DRM_IRQ_ARGS)
40581
40582 pending = xchg(&qdev->ram_header->int_pending, 0);
40583
40584 - atomic_inc(&qdev->irq_received);
40585 + atomic_inc_unchecked(&qdev->irq_received);
40586
40587 if (pending & QXL_INTERRUPT_DISPLAY) {
40588 - atomic_inc(&qdev->irq_received_display);
40589 + atomic_inc_unchecked(&qdev->irq_received_display);
40590 wake_up_all(&qdev->display_event);
40591 qxl_queue_garbage_collect(qdev, false);
40592 }
40593 if (pending & QXL_INTERRUPT_CURSOR) {
40594 - atomic_inc(&qdev->irq_received_cursor);
40595 + atomic_inc_unchecked(&qdev->irq_received_cursor);
40596 wake_up_all(&qdev->cursor_event);
40597 }
40598 if (pending & QXL_INTERRUPT_IO_CMD) {
40599 - atomic_inc(&qdev->irq_received_io_cmd);
40600 + atomic_inc_unchecked(&qdev->irq_received_io_cmd);
40601 wake_up_all(&qdev->io_cmd_event);
40602 }
40603 if (pending & QXL_INTERRUPT_ERROR) {
40604 @@ -82,10 +82,10 @@ int qxl_irq_init(struct qxl_device *qdev)
40605 init_waitqueue_head(&qdev->io_cmd_event);
40606 INIT_WORK(&qdev->client_monitors_config_work,
40607 qxl_client_monitors_config_work_func);
40608 - atomic_set(&qdev->irq_received, 0);
40609 - atomic_set(&qdev->irq_received_display, 0);
40610 - atomic_set(&qdev->irq_received_cursor, 0);
40611 - atomic_set(&qdev->irq_received_io_cmd, 0);
40612 + atomic_set_unchecked(&qdev->irq_received, 0);
40613 + atomic_set_unchecked(&qdev->irq_received_display, 0);
40614 + atomic_set_unchecked(&qdev->irq_received_cursor, 0);
40615 + atomic_set_unchecked(&qdev->irq_received_io_cmd, 0);
40616 qdev->irq_received_error = 0;
40617 ret = drm_irq_install(qdev->ddev);
40618 qdev->ram_header->int_mask = QXL_INTERRUPT_MASK;
40619 diff --git a/drivers/gpu/drm/qxl/qxl_ttm.c b/drivers/gpu/drm/qxl/qxl_ttm.c
40620 index c7e7e65..7dddd4d 100644
40621 --- a/drivers/gpu/drm/qxl/qxl_ttm.c
40622 +++ b/drivers/gpu/drm/qxl/qxl_ttm.c
40623 @@ -103,7 +103,7 @@ static void qxl_ttm_global_fini(struct qxl_device *qdev)
40624 }
40625 }
40626
40627 -static struct vm_operations_struct qxl_ttm_vm_ops;
40628 +static vm_operations_struct_no_const qxl_ttm_vm_ops __read_only;
40629 static const struct vm_operations_struct *ttm_vm_ops;
40630
40631 static int qxl_ttm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
40632 @@ -147,8 +147,10 @@ int qxl_mmap(struct file *filp, struct vm_area_struct *vma)
40633 return r;
40634 if (unlikely(ttm_vm_ops == NULL)) {
40635 ttm_vm_ops = vma->vm_ops;
40636 + pax_open_kernel();
40637 qxl_ttm_vm_ops = *ttm_vm_ops;
40638 qxl_ttm_vm_ops.fault = &qxl_ttm_fault;
40639 + pax_close_kernel();
40640 }
40641 vma->vm_ops = &qxl_ttm_vm_ops;
40642 return 0;
40643 @@ -560,25 +562,23 @@ static int qxl_mm_dump_table(struct seq_file *m, void *data)
40644 static int qxl_ttm_debugfs_init(struct qxl_device *qdev)
40645 {
40646 #if defined(CONFIG_DEBUG_FS)
40647 - static struct drm_info_list qxl_mem_types_list[QXL_DEBUGFS_MEM_TYPES];
40648 - static char qxl_mem_types_names[QXL_DEBUGFS_MEM_TYPES][32];
40649 - unsigned i;
40650 + static struct drm_info_list qxl_mem_types_list[QXL_DEBUGFS_MEM_TYPES] = {
40651 + {
40652 + .name = "qxl_mem_mm",
40653 + .show = &qxl_mm_dump_table,
40654 + },
40655 + {
40656 + .name = "qxl_surf_mm",
40657 + .show = &qxl_mm_dump_table,
40658 + }
40659 + };
40660
40661 - for (i = 0; i < QXL_DEBUGFS_MEM_TYPES; i++) {
40662 - if (i == 0)
40663 - sprintf(qxl_mem_types_names[i], "qxl_mem_mm");
40664 - else
40665 - sprintf(qxl_mem_types_names[i], "qxl_surf_mm");
40666 - qxl_mem_types_list[i].name = qxl_mem_types_names[i];
40667 - qxl_mem_types_list[i].show = &qxl_mm_dump_table;
40668 - qxl_mem_types_list[i].driver_features = 0;
40669 - if (i == 0)
40670 - qxl_mem_types_list[i].data = qdev->mman.bdev.man[TTM_PL_VRAM].priv;
40671 - else
40672 - qxl_mem_types_list[i].data = qdev->mman.bdev.man[TTM_PL_PRIV0].priv;
40673 + pax_open_kernel();
40674 + *(void **)&qxl_mem_types_list[0].data = qdev->mman.bdev.man[TTM_PL_VRAM].priv;
40675 + *(void **)&qxl_mem_types_list[1].data = qdev->mman.bdev.man[TTM_PL_PRIV0].priv;
40676 + pax_close_kernel();
40677
40678 - }
40679 - return qxl_debugfs_add_files(qdev, qxl_mem_types_list, i);
40680 + return qxl_debugfs_add_files(qdev, qxl_mem_types_list, QXL_DEBUGFS_MEM_TYPES);
40681 #else
40682 return 0;
40683 #endif
40684 diff --git a/drivers/gpu/drm/r128/r128_cce.c b/drivers/gpu/drm/r128/r128_cce.c
40685 index c451257..0ad2134 100644
40686 --- a/drivers/gpu/drm/r128/r128_cce.c
40687 +++ b/drivers/gpu/drm/r128/r128_cce.c
40688 @@ -377,7 +377,7 @@ static int r128_do_init_cce(struct drm_device *dev, drm_r128_init_t *init)
40689
40690 /* GH: Simple idle check.
40691 */
40692 - atomic_set(&dev_priv->idle_count, 0);
40693 + atomic_set_unchecked(&dev_priv->idle_count, 0);
40694
40695 /* We don't support anything other than bus-mastering ring mode,
40696 * but the ring can be in either AGP or PCI space for the ring
40697 diff --git a/drivers/gpu/drm/r128/r128_drv.h b/drivers/gpu/drm/r128/r128_drv.h
40698 index 56eb5e3..c4ec43d 100644
40699 --- a/drivers/gpu/drm/r128/r128_drv.h
40700 +++ b/drivers/gpu/drm/r128/r128_drv.h
40701 @@ -90,14 +90,14 @@ typedef struct drm_r128_private {
40702 int is_pci;
40703 unsigned long cce_buffers_offset;
40704
40705 - atomic_t idle_count;
40706 + atomic_unchecked_t idle_count;
40707
40708 int page_flipping;
40709 int current_page;
40710 u32 crtc_offset;
40711 u32 crtc_offset_cntl;
40712
40713 - atomic_t vbl_received;
40714 + atomic_unchecked_t vbl_received;
40715
40716 u32 color_fmt;
40717 unsigned int front_offset;
40718 diff --git a/drivers/gpu/drm/r128/r128_ioc32.c b/drivers/gpu/drm/r128/r128_ioc32.c
40719 index a954c54..9cc595c 100644
40720 --- a/drivers/gpu/drm/r128/r128_ioc32.c
40721 +++ b/drivers/gpu/drm/r128/r128_ioc32.c
40722 @@ -177,7 +177,7 @@ static int compat_r128_getparam(struct file *file, unsigned int cmd,
40723 return drm_ioctl(file, DRM_IOCTL_R128_GETPARAM, (unsigned long)getparam);
40724 }
40725
40726 -drm_ioctl_compat_t *r128_compat_ioctls[] = {
40727 +drm_ioctl_compat_t r128_compat_ioctls[] = {
40728 [DRM_R128_INIT] = compat_r128_init,
40729 [DRM_R128_DEPTH] = compat_r128_depth,
40730 [DRM_R128_STIPPLE] = compat_r128_stipple,
40731 @@ -196,18 +196,15 @@ drm_ioctl_compat_t *r128_compat_ioctls[] = {
40732 long r128_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
40733 {
40734 unsigned int nr = DRM_IOCTL_NR(cmd);
40735 - drm_ioctl_compat_t *fn = NULL;
40736 int ret;
40737
40738 if (nr < DRM_COMMAND_BASE)
40739 return drm_compat_ioctl(filp, cmd, arg);
40740
40741 - if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(r128_compat_ioctls))
40742 - fn = r128_compat_ioctls[nr - DRM_COMMAND_BASE];
40743 -
40744 - if (fn != NULL)
40745 + if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(r128_compat_ioctls)) {
40746 + drm_ioctl_compat_t fn = r128_compat_ioctls[nr - DRM_COMMAND_BASE];
40747 ret = (*fn) (filp, cmd, arg);
40748 - else
40749 + } else
40750 ret = drm_ioctl(filp, cmd, arg);
40751
40752 return ret;
40753 diff --git a/drivers/gpu/drm/r128/r128_irq.c b/drivers/gpu/drm/r128/r128_irq.c
40754 index 2ea4f09..d391371 100644
40755 --- a/drivers/gpu/drm/r128/r128_irq.c
40756 +++ b/drivers/gpu/drm/r128/r128_irq.c
40757 @@ -41,7 +41,7 @@ u32 r128_get_vblank_counter(struct drm_device *dev, int crtc)
40758 if (crtc != 0)
40759 return 0;
40760
40761 - return atomic_read(&dev_priv->vbl_received);
40762 + return atomic_read_unchecked(&dev_priv->vbl_received);
40763 }
40764
40765 irqreturn_t r128_driver_irq_handler(DRM_IRQ_ARGS)
40766 @@ -55,7 +55,7 @@ irqreturn_t r128_driver_irq_handler(DRM_IRQ_ARGS)
40767 /* VBLANK interrupt */
40768 if (status & R128_CRTC_VBLANK_INT) {
40769 R128_WRITE(R128_GEN_INT_STATUS, R128_CRTC_VBLANK_INT_AK);
40770 - atomic_inc(&dev_priv->vbl_received);
40771 + atomic_inc_unchecked(&dev_priv->vbl_received);
40772 drm_handle_vblank(dev, 0);
40773 return IRQ_HANDLED;
40774 }
40775 diff --git a/drivers/gpu/drm/r128/r128_state.c b/drivers/gpu/drm/r128/r128_state.c
40776 index 01dd9ae..6352f04 100644
40777 --- a/drivers/gpu/drm/r128/r128_state.c
40778 +++ b/drivers/gpu/drm/r128/r128_state.c
40779 @@ -320,10 +320,10 @@ static void r128_clear_box(drm_r128_private_t *dev_priv,
40780
40781 static void r128_cce_performance_boxes(drm_r128_private_t *dev_priv)
40782 {
40783 - if (atomic_read(&dev_priv->idle_count) == 0)
40784 + if (atomic_read_unchecked(&dev_priv->idle_count) == 0)
40785 r128_clear_box(dev_priv, 64, 4, 8, 8, 0, 255, 0);
40786 else
40787 - atomic_set(&dev_priv->idle_count, 0);
40788 + atomic_set_unchecked(&dev_priv->idle_count, 0);
40789 }
40790
40791 #endif
40792 diff --git a/drivers/gpu/drm/radeon/mkregtable.c b/drivers/gpu/drm/radeon/mkregtable.c
40793 index af85299..ed9ac8d 100644
40794 --- a/drivers/gpu/drm/radeon/mkregtable.c
40795 +++ b/drivers/gpu/drm/radeon/mkregtable.c
40796 @@ -624,14 +624,14 @@ static int parser_auth(struct table *t, const char *filename)
40797 regex_t mask_rex;
40798 regmatch_t match[4];
40799 char buf[1024];
40800 - size_t end;
40801 + long end;
40802 int len;
40803 int done = 0;
40804 int r;
40805 unsigned o;
40806 struct offset *offset;
40807 char last_reg_s[10];
40808 - int last_reg;
40809 + unsigned long last_reg;
40810
40811 if (regcomp
40812 (&mask_rex, "(0x[0-9a-fA-F]*) *([_a-zA-Z0-9]*)", REG_EXTENDED)) {
40813 diff --git a/drivers/gpu/drm/radeon/radeon_device.c b/drivers/gpu/drm/radeon/radeon_device.c
40814 index 39b033b..6efc056 100644
40815 --- a/drivers/gpu/drm/radeon/radeon_device.c
40816 +++ b/drivers/gpu/drm/radeon/radeon_device.c
40817 @@ -1120,7 +1120,7 @@ static bool radeon_switcheroo_can_switch(struct pci_dev *pdev)
40818 bool can_switch;
40819
40820 spin_lock(&dev->count_lock);
40821 - can_switch = (dev->open_count == 0);
40822 + can_switch = (local_read(&dev->open_count) == 0);
40823 spin_unlock(&dev->count_lock);
40824 return can_switch;
40825 }
40826 diff --git a/drivers/gpu/drm/radeon/radeon_drv.h b/drivers/gpu/drm/radeon/radeon_drv.h
40827 index 00e0d44..08381a4 100644
40828 --- a/drivers/gpu/drm/radeon/radeon_drv.h
40829 +++ b/drivers/gpu/drm/radeon/radeon_drv.h
40830 @@ -262,7 +262,7 @@ typedef struct drm_radeon_private {
40831
40832 /* SW interrupt */
40833 wait_queue_head_t swi_queue;
40834 - atomic_t swi_emitted;
40835 + atomic_unchecked_t swi_emitted;
40836 int vblank_crtc;
40837 uint32_t irq_enable_reg;
40838 uint32_t r500_disp_irq_reg;
40839 diff --git a/drivers/gpu/drm/radeon/radeon_ioc32.c b/drivers/gpu/drm/radeon/radeon_ioc32.c
40840 index bdb0f93..5ff558f 100644
40841 --- a/drivers/gpu/drm/radeon/radeon_ioc32.c
40842 +++ b/drivers/gpu/drm/radeon/radeon_ioc32.c
40843 @@ -358,7 +358,7 @@ static int compat_radeon_cp_setparam(struct file *file, unsigned int cmd,
40844 request = compat_alloc_user_space(sizeof(*request));
40845 if (!access_ok(VERIFY_WRITE, request, sizeof(*request))
40846 || __put_user(req32.param, &request->param)
40847 - || __put_user((void __user *)(unsigned long)req32.value,
40848 + || __put_user((unsigned long)req32.value,
40849 &request->value))
40850 return -EFAULT;
40851
40852 @@ -368,7 +368,7 @@ static int compat_radeon_cp_setparam(struct file *file, unsigned int cmd,
40853 #define compat_radeon_cp_setparam NULL
40854 #endif /* X86_64 || IA64 */
40855
40856 -static drm_ioctl_compat_t *radeon_compat_ioctls[] = {
40857 +static drm_ioctl_compat_t radeon_compat_ioctls[] = {
40858 [DRM_RADEON_CP_INIT] = compat_radeon_cp_init,
40859 [DRM_RADEON_CLEAR] = compat_radeon_cp_clear,
40860 [DRM_RADEON_STIPPLE] = compat_radeon_cp_stipple,
40861 @@ -393,18 +393,15 @@ static drm_ioctl_compat_t *radeon_compat_ioctls[] = {
40862 long radeon_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
40863 {
40864 unsigned int nr = DRM_IOCTL_NR(cmd);
40865 - drm_ioctl_compat_t *fn = NULL;
40866 int ret;
40867
40868 if (nr < DRM_COMMAND_BASE)
40869 return drm_compat_ioctl(filp, cmd, arg);
40870
40871 - if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(radeon_compat_ioctls))
40872 - fn = radeon_compat_ioctls[nr - DRM_COMMAND_BASE];
40873 -
40874 - if (fn != NULL)
40875 + if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(radeon_compat_ioctls)) {
40876 + drm_ioctl_compat_t fn = radeon_compat_ioctls[nr - DRM_COMMAND_BASE];
40877 ret = (*fn) (filp, cmd, arg);
40878 - else
40879 + } else
40880 ret = drm_ioctl(filp, cmd, arg);
40881
40882 return ret;
40883 diff --git a/drivers/gpu/drm/radeon/radeon_irq.c b/drivers/gpu/drm/radeon/radeon_irq.c
40884 index 8d68e97..9dcfed8 100644
40885 --- a/drivers/gpu/drm/radeon/radeon_irq.c
40886 +++ b/drivers/gpu/drm/radeon/radeon_irq.c
40887 @@ -226,8 +226,8 @@ static int radeon_emit_irq(struct drm_device * dev)
40888 unsigned int ret;
40889 RING_LOCALS;
40890
40891 - atomic_inc(&dev_priv->swi_emitted);
40892 - ret = atomic_read(&dev_priv->swi_emitted);
40893 + atomic_inc_unchecked(&dev_priv->swi_emitted);
40894 + ret = atomic_read_unchecked(&dev_priv->swi_emitted);
40895
40896 BEGIN_RING(4);
40897 OUT_RING_REG(RADEON_LAST_SWI_REG, ret);
40898 @@ -353,7 +353,7 @@ int radeon_driver_irq_postinstall(struct drm_device *dev)
40899 drm_radeon_private_t *dev_priv =
40900 (drm_radeon_private_t *) dev->dev_private;
40901
40902 - atomic_set(&dev_priv->swi_emitted, 0);
40903 + atomic_set_unchecked(&dev_priv->swi_emitted, 0);
40904 DRM_INIT_WAITQUEUE(&dev_priv->swi_queue);
40905
40906 dev->max_vblank_count = 0x001fffff;
40907 diff --git a/drivers/gpu/drm/radeon/radeon_state.c b/drivers/gpu/drm/radeon/radeon_state.c
40908 index 4d20910..6726b6d 100644
40909 --- a/drivers/gpu/drm/radeon/radeon_state.c
40910 +++ b/drivers/gpu/drm/radeon/radeon_state.c
40911 @@ -2168,7 +2168,7 @@ static int radeon_cp_clear(struct drm_device *dev, void *data, struct drm_file *
40912 if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS)
40913 sarea_priv->nbox = RADEON_NR_SAREA_CLIPRECTS;
40914
40915 - if (DRM_COPY_FROM_USER(&depth_boxes, clear->depth_boxes,
40916 + if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS || DRM_COPY_FROM_USER(&depth_boxes, clear->depth_boxes,
40917 sarea_priv->nbox * sizeof(depth_boxes[0])))
40918 return -EFAULT;
40919
40920 @@ -3031,7 +3031,7 @@ static int radeon_cp_getparam(struct drm_device *dev, void *data, struct drm_fil
40921 {
40922 drm_radeon_private_t *dev_priv = dev->dev_private;
40923 drm_radeon_getparam_t *param = data;
40924 - int value;
40925 + int value = 0;
40926
40927 DRM_DEBUG("pid=%d\n", DRM_CURRENTPID);
40928
40929 diff --git a/drivers/gpu/drm/radeon/radeon_ttm.c b/drivers/gpu/drm/radeon/radeon_ttm.c
40930 index 84323c9..cf07baf 100644
40931 --- a/drivers/gpu/drm/radeon/radeon_ttm.c
40932 +++ b/drivers/gpu/drm/radeon/radeon_ttm.c
40933 @@ -787,7 +787,7 @@ void radeon_ttm_set_active_vram_size(struct radeon_device *rdev, u64 size)
40934 man->size = size >> PAGE_SHIFT;
40935 }
40936
40937 -static struct vm_operations_struct radeon_ttm_vm_ops;
40938 +static vm_operations_struct_no_const radeon_ttm_vm_ops __read_only;
40939 static const struct vm_operations_struct *ttm_vm_ops = NULL;
40940
40941 static int radeon_ttm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
40942 @@ -828,8 +828,10 @@ int radeon_mmap(struct file *filp, struct vm_area_struct *vma)
40943 }
40944 if (unlikely(ttm_vm_ops == NULL)) {
40945 ttm_vm_ops = vma->vm_ops;
40946 + pax_open_kernel();
40947 radeon_ttm_vm_ops = *ttm_vm_ops;
40948 radeon_ttm_vm_ops.fault = &radeon_ttm_fault;
40949 + pax_close_kernel();
40950 }
40951 vma->vm_ops = &radeon_ttm_vm_ops;
40952 return 0;
40953 @@ -858,38 +860,33 @@ static int radeon_mm_dump_table(struct seq_file *m, void *data)
40954 static int radeon_ttm_debugfs_init(struct radeon_device *rdev)
40955 {
40956 #if defined(CONFIG_DEBUG_FS)
40957 - static struct drm_info_list radeon_mem_types_list[RADEON_DEBUGFS_MEM_TYPES+2];
40958 - static char radeon_mem_types_names[RADEON_DEBUGFS_MEM_TYPES+2][32];
40959 - unsigned i;
40960 + static struct drm_info_list radeon_mem_types_list[RADEON_DEBUGFS_MEM_TYPES+2] = {
40961 + {
40962 + .name = "radeon_vram_mm",
40963 + .show = &radeon_mm_dump_table,
40964 + },
40965 + {
40966 + .name = "radeon_gtt_mm",
40967 + .show = &radeon_mm_dump_table,
40968 + },
40969 + {
40970 + .name = "ttm_page_pool",
40971 + .show = &ttm_page_alloc_debugfs,
40972 + },
40973 + {
40974 + .name = "ttm_dma_page_pool",
40975 + .show = &ttm_dma_page_alloc_debugfs,
40976 + },
40977 + };
40978 + unsigned i = RADEON_DEBUGFS_MEM_TYPES + 1;
40979
40980 - for (i = 0; i < RADEON_DEBUGFS_MEM_TYPES; i++) {
40981 - if (i == 0)
40982 - sprintf(radeon_mem_types_names[i], "radeon_vram_mm");
40983 - else
40984 - sprintf(radeon_mem_types_names[i], "radeon_gtt_mm");
40985 - radeon_mem_types_list[i].name = radeon_mem_types_names[i];
40986 - radeon_mem_types_list[i].show = &radeon_mm_dump_table;
40987 - radeon_mem_types_list[i].driver_features = 0;
40988 - if (i == 0)
40989 - radeon_mem_types_list[i].data = rdev->mman.bdev.man[TTM_PL_VRAM].priv;
40990 - else
40991 - radeon_mem_types_list[i].data = rdev->mman.bdev.man[TTM_PL_TT].priv;
40992 -
40993 - }
40994 - /* Add ttm page pool to debugfs */
40995 - sprintf(radeon_mem_types_names[i], "ttm_page_pool");
40996 - radeon_mem_types_list[i].name = radeon_mem_types_names[i];
40997 - radeon_mem_types_list[i].show = &ttm_page_alloc_debugfs;
40998 - radeon_mem_types_list[i].driver_features = 0;
40999 - radeon_mem_types_list[i++].data = NULL;
41000 + pax_open_kernel();
41001 + *(void **)&radeon_mem_types_list[0].data = rdev->mman.bdev.man[TTM_PL_VRAM].priv;
41002 + *(void **)&radeon_mem_types_list[1].data = rdev->mman.bdev.man[TTM_PL_TT].priv;
41003 + pax_close_kernel();
41004 #ifdef CONFIG_SWIOTLB
41005 - if (swiotlb_nr_tbl()) {
41006 - sprintf(radeon_mem_types_names[i], "ttm_dma_page_pool");
41007 - radeon_mem_types_list[i].name = radeon_mem_types_names[i];
41008 - radeon_mem_types_list[i].show = &ttm_dma_page_alloc_debugfs;
41009 - radeon_mem_types_list[i].driver_features = 0;
41010 - radeon_mem_types_list[i++].data = NULL;
41011 - }
41012 + if (swiotlb_nr_tbl())
41013 + i++;
41014 #endif
41015 return radeon_debugfs_add_files(rdev, radeon_mem_types_list, i);
41016
41017 diff --git a/drivers/gpu/drm/tegra/dc.c b/drivers/gpu/drm/tegra/dc.c
41018 index ae1cb31..5b5b6b7c 100644
41019 --- a/drivers/gpu/drm/tegra/dc.c
41020 +++ b/drivers/gpu/drm/tegra/dc.c
41021 @@ -1064,7 +1064,7 @@ static int tegra_dc_debugfs_init(struct tegra_dc *dc, struct drm_minor *minor)
41022 }
41023
41024 for (i = 0; i < ARRAY_SIZE(debugfs_files); i++)
41025 - dc->debugfs_files[i].data = dc;
41026 + *(void **)&dc->debugfs_files[i].data = dc;
41027
41028 err = drm_debugfs_create_files(dc->debugfs_files,
41029 ARRAY_SIZE(debugfs_files),
41030 diff --git a/drivers/gpu/drm/tegra/hdmi.c b/drivers/gpu/drm/tegra/hdmi.c
41031 index 0cd9bc2..9759be4 100644
41032 --- a/drivers/gpu/drm/tegra/hdmi.c
41033 +++ b/drivers/gpu/drm/tegra/hdmi.c
41034 @@ -57,7 +57,7 @@ struct tegra_hdmi {
41035 bool stereo;
41036 bool dvi;
41037
41038 - struct drm_info_list *debugfs_files;
41039 + drm_info_list_no_const *debugfs_files;
41040 struct drm_minor *minor;
41041 struct dentry *debugfs;
41042 };
41043 diff --git a/drivers/gpu/drm/ttm/ttm_bo_manager.c b/drivers/gpu/drm/ttm/ttm_bo_manager.c
41044 index c58eba33..83c2728 100644
41045 --- a/drivers/gpu/drm/ttm/ttm_bo_manager.c
41046 +++ b/drivers/gpu/drm/ttm/ttm_bo_manager.c
41047 @@ -141,10 +141,10 @@ static void ttm_bo_man_debug(struct ttm_mem_type_manager *man,
41048 }
41049
41050 const struct ttm_mem_type_manager_func ttm_bo_manager_func = {
41051 - ttm_bo_man_init,
41052 - ttm_bo_man_takedown,
41053 - ttm_bo_man_get_node,
41054 - ttm_bo_man_put_node,
41055 - ttm_bo_man_debug
41056 + .init = ttm_bo_man_init,
41057 + .takedown = ttm_bo_man_takedown,
41058 + .get_node = ttm_bo_man_get_node,
41059 + .put_node = ttm_bo_man_put_node,
41060 + .debug = ttm_bo_man_debug
41061 };
41062 EXPORT_SYMBOL(ttm_bo_manager_func);
41063 diff --git a/drivers/gpu/drm/ttm/ttm_memory.c b/drivers/gpu/drm/ttm/ttm_memory.c
41064 index dbc2def..0a9f710 100644
41065 --- a/drivers/gpu/drm/ttm/ttm_memory.c
41066 +++ b/drivers/gpu/drm/ttm/ttm_memory.c
41067 @@ -264,7 +264,7 @@ static int ttm_mem_init_kernel_zone(struct ttm_mem_global *glob,
41068 zone->glob = glob;
41069 glob->zone_kernel = zone;
41070 ret = kobject_init_and_add(
41071 - &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, zone->name);
41072 + &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, "%s", zone->name);
41073 if (unlikely(ret != 0)) {
41074 kobject_put(&zone->kobj);
41075 return ret;
41076 @@ -347,7 +347,7 @@ static int ttm_mem_init_dma32_zone(struct ttm_mem_global *glob,
41077 zone->glob = glob;
41078 glob->zone_dma32 = zone;
41079 ret = kobject_init_and_add(
41080 - &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, zone->name);
41081 + &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, "%s", zone->name);
41082 if (unlikely(ret != 0)) {
41083 kobject_put(&zone->kobj);
41084 return ret;
41085 diff --git a/drivers/gpu/drm/ttm/ttm_page_alloc.c b/drivers/gpu/drm/ttm/ttm_page_alloc.c
41086 index 863bef9..cba15cf 100644
41087 --- a/drivers/gpu/drm/ttm/ttm_page_alloc.c
41088 +++ b/drivers/gpu/drm/ttm/ttm_page_alloc.c
41089 @@ -391,9 +391,9 @@ out:
41090 static unsigned long
41091 ttm_pool_shrink_scan(struct shrinker *shrink, struct shrink_control *sc)
41092 {
41093 - static atomic_t start_pool = ATOMIC_INIT(0);
41094 + static atomic_unchecked_t start_pool = ATOMIC_INIT(0);
41095 unsigned i;
41096 - unsigned pool_offset = atomic_add_return(1, &start_pool);
41097 + unsigned pool_offset = atomic_add_return_unchecked(1, &start_pool);
41098 struct ttm_page_pool *pool;
41099 int shrink_pages = sc->nr_to_scan;
41100 unsigned long freed = 0;
41101 diff --git a/drivers/gpu/drm/udl/udl_fb.c b/drivers/gpu/drm/udl/udl_fb.c
41102 index 97e9d61..bf23c461 100644
41103 --- a/drivers/gpu/drm/udl/udl_fb.c
41104 +++ b/drivers/gpu/drm/udl/udl_fb.c
41105 @@ -367,7 +367,6 @@ static int udl_fb_release(struct fb_info *info, int user)
41106 fb_deferred_io_cleanup(info);
41107 kfree(info->fbdefio);
41108 info->fbdefio = NULL;
41109 - info->fbops->fb_mmap = udl_fb_mmap;
41110 }
41111
41112 pr_warn("released /dev/fb%d user=%d count=%d\n",
41113 diff --git a/drivers/gpu/drm/via/via_drv.h b/drivers/gpu/drm/via/via_drv.h
41114 index a811ef2..ff99b05 100644
41115 --- a/drivers/gpu/drm/via/via_drv.h
41116 +++ b/drivers/gpu/drm/via/via_drv.h
41117 @@ -51,7 +51,7 @@ typedef struct drm_via_ring_buffer {
41118 typedef uint32_t maskarray_t[5];
41119
41120 typedef struct drm_via_irq {
41121 - atomic_t irq_received;
41122 + atomic_unchecked_t irq_received;
41123 uint32_t pending_mask;
41124 uint32_t enable_mask;
41125 wait_queue_head_t irq_queue;
41126 @@ -75,7 +75,7 @@ typedef struct drm_via_private {
41127 struct timeval last_vblank;
41128 int last_vblank_valid;
41129 unsigned usec_per_vblank;
41130 - atomic_t vbl_received;
41131 + atomic_unchecked_t vbl_received;
41132 drm_via_state_t hc_state;
41133 char pci_buf[VIA_PCI_BUF_SIZE];
41134 const uint32_t *fire_offsets[VIA_FIRE_BUF_SIZE];
41135 diff --git a/drivers/gpu/drm/via/via_irq.c b/drivers/gpu/drm/via/via_irq.c
41136 index ac98964..5dbf512 100644
41137 --- a/drivers/gpu/drm/via/via_irq.c
41138 +++ b/drivers/gpu/drm/via/via_irq.c
41139 @@ -101,7 +101,7 @@ u32 via_get_vblank_counter(struct drm_device *dev, int crtc)
41140 if (crtc != 0)
41141 return 0;
41142
41143 - return atomic_read(&dev_priv->vbl_received);
41144 + return atomic_read_unchecked(&dev_priv->vbl_received);
41145 }
41146
41147 irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
41148 @@ -116,8 +116,8 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
41149
41150 status = VIA_READ(VIA_REG_INTERRUPT);
41151 if (status & VIA_IRQ_VBLANK_PENDING) {
41152 - atomic_inc(&dev_priv->vbl_received);
41153 - if (!(atomic_read(&dev_priv->vbl_received) & 0x0F)) {
41154 + atomic_inc_unchecked(&dev_priv->vbl_received);
41155 + if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0x0F)) {
41156 do_gettimeofday(&cur_vblank);
41157 if (dev_priv->last_vblank_valid) {
41158 dev_priv->usec_per_vblank =
41159 @@ -127,7 +127,7 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
41160 dev_priv->last_vblank = cur_vblank;
41161 dev_priv->last_vblank_valid = 1;
41162 }
41163 - if (!(atomic_read(&dev_priv->vbl_received) & 0xFF)) {
41164 + if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0xFF)) {
41165 DRM_DEBUG("US per vblank is: %u\n",
41166 dev_priv->usec_per_vblank);
41167 }
41168 @@ -137,7 +137,7 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
41169
41170 for (i = 0; i < dev_priv->num_irqs; ++i) {
41171 if (status & cur_irq->pending_mask) {
41172 - atomic_inc(&cur_irq->irq_received);
41173 + atomic_inc_unchecked(&cur_irq->irq_received);
41174 DRM_WAKEUP(&cur_irq->irq_queue);
41175 handled = 1;
41176 if (dev_priv->irq_map[drm_via_irq_dma0_td] == i)
41177 @@ -242,11 +242,11 @@ via_driver_irq_wait(struct drm_device *dev, unsigned int irq, int force_sequence
41178 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ,
41179 ((VIA_READ(masks[irq][2]) & masks[irq][3]) ==
41180 masks[irq][4]));
41181 - cur_irq_sequence = atomic_read(&cur_irq->irq_received);
41182 + cur_irq_sequence = atomic_read_unchecked(&cur_irq->irq_received);
41183 } else {
41184 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ,
41185 (((cur_irq_sequence =
41186 - atomic_read(&cur_irq->irq_received)) -
41187 + atomic_read_unchecked(&cur_irq->irq_received)) -
41188 *sequence) <= (1 << 23)));
41189 }
41190 *sequence = cur_irq_sequence;
41191 @@ -284,7 +284,7 @@ void via_driver_irq_preinstall(struct drm_device *dev)
41192 }
41193
41194 for (i = 0; i < dev_priv->num_irqs; ++i) {
41195 - atomic_set(&cur_irq->irq_received, 0);
41196 + atomic_set_unchecked(&cur_irq->irq_received, 0);
41197 cur_irq->enable_mask = dev_priv->irq_masks[i][0];
41198 cur_irq->pending_mask = dev_priv->irq_masks[i][1];
41199 DRM_INIT_WAITQUEUE(&cur_irq->irq_queue);
41200 @@ -366,7 +366,7 @@ int via_wait_irq(struct drm_device *dev, void *data, struct drm_file *file_priv)
41201 switch (irqwait->request.type & ~VIA_IRQ_FLAGS_MASK) {
41202 case VIA_IRQ_RELATIVE:
41203 irqwait->request.sequence +=
41204 - atomic_read(&cur_irq->irq_received);
41205 + atomic_read_unchecked(&cur_irq->irq_received);
41206 irqwait->request.type &= ~_DRM_VBLANK_RELATIVE;
41207 case VIA_IRQ_ABSOLUTE:
41208 break;
41209 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
41210 index c0b73b9..f6f7f34 100644
41211 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
41212 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
41213 @@ -341,7 +341,7 @@ struct vmw_private {
41214 * Fencing and IRQs.
41215 */
41216
41217 - atomic_t marker_seq;
41218 + atomic_unchecked_t marker_seq;
41219 wait_queue_head_t fence_queue;
41220 wait_queue_head_t fifo_queue;
41221 int fence_queue_waiters; /* Protected by hw_mutex */
41222 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
41223 index 3eb1486..0a47ee9 100644
41224 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
41225 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
41226 @@ -137,7 +137,7 @@ int vmw_fifo_init(struct vmw_private *dev_priv, struct vmw_fifo_state *fifo)
41227 (unsigned int) min,
41228 (unsigned int) fifo->capabilities);
41229
41230 - atomic_set(&dev_priv->marker_seq, dev_priv->last_read_seqno);
41231 + atomic_set_unchecked(&dev_priv->marker_seq, dev_priv->last_read_seqno);
41232 iowrite32(dev_priv->last_read_seqno, fifo_mem + SVGA_FIFO_FENCE);
41233 vmw_marker_queue_init(&fifo->marker_queue);
41234 return vmw_fifo_send_fence(dev_priv, &dummy);
41235 @@ -355,7 +355,7 @@ void *vmw_fifo_reserve(struct vmw_private *dev_priv, uint32_t bytes)
41236 if (reserveable)
41237 iowrite32(bytes, fifo_mem +
41238 SVGA_FIFO_RESERVED);
41239 - return fifo_mem + (next_cmd >> 2);
41240 + return (__le32 __force_kernel *)fifo_mem + (next_cmd >> 2);
41241 } else {
41242 need_bounce = true;
41243 }
41244 @@ -475,7 +475,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
41245
41246 fm = vmw_fifo_reserve(dev_priv, bytes);
41247 if (unlikely(fm == NULL)) {
41248 - *seqno = atomic_read(&dev_priv->marker_seq);
41249 + *seqno = atomic_read_unchecked(&dev_priv->marker_seq);
41250 ret = -ENOMEM;
41251 (void)vmw_fallback_wait(dev_priv, false, true, *seqno,
41252 false, 3*HZ);
41253 @@ -483,7 +483,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
41254 }
41255
41256 do {
41257 - *seqno = atomic_add_return(1, &dev_priv->marker_seq);
41258 + *seqno = atomic_add_return_unchecked(1, &dev_priv->marker_seq);
41259 } while (*seqno == 0);
41260
41261 if (!(fifo_state->capabilities & SVGA_FIFO_CAP_FENCE)) {
41262 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c b/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c
41263 index c5c054a..46f0548 100644
41264 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c
41265 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c
41266 @@ -153,9 +153,9 @@ static void vmw_gmrid_man_debug(struct ttm_mem_type_manager *man,
41267 }
41268
41269 const struct ttm_mem_type_manager_func vmw_gmrid_manager_func = {
41270 - vmw_gmrid_man_init,
41271 - vmw_gmrid_man_takedown,
41272 - vmw_gmrid_man_get_node,
41273 - vmw_gmrid_man_put_node,
41274 - vmw_gmrid_man_debug
41275 + .init = vmw_gmrid_man_init,
41276 + .takedown = vmw_gmrid_man_takedown,
41277 + .get_node = vmw_gmrid_man_get_node,
41278 + .put_node = vmw_gmrid_man_put_node,
41279 + .debug = vmw_gmrid_man_debug
41280 };
41281 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c b/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c
41282 index 45d5b5a..f3f5e4e 100644
41283 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c
41284 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c
41285 @@ -141,7 +141,7 @@ int vmw_present_ioctl(struct drm_device *dev, void *data,
41286 int ret;
41287
41288 num_clips = arg->num_clips;
41289 - clips_ptr = (struct drm_vmw_rect *)(unsigned long)arg->clips_ptr;
41290 + clips_ptr = (struct drm_vmw_rect __user *)(unsigned long)arg->clips_ptr;
41291
41292 if (unlikely(num_clips == 0))
41293 return 0;
41294 @@ -225,7 +225,7 @@ int vmw_present_readback_ioctl(struct drm_device *dev, void *data,
41295 int ret;
41296
41297 num_clips = arg->num_clips;
41298 - clips_ptr = (struct drm_vmw_rect *)(unsigned long)arg->clips_ptr;
41299 + clips_ptr = (struct drm_vmw_rect __user *)(unsigned long)arg->clips_ptr;
41300
41301 if (unlikely(num_clips == 0))
41302 return 0;
41303 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
41304 index 4640adb..e1384ed 100644
41305 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
41306 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
41307 @@ -107,7 +107,7 @@ bool vmw_seqno_passed(struct vmw_private *dev_priv,
41308 * emitted. Then the fence is stale and signaled.
41309 */
41310
41311 - ret = ((atomic_read(&dev_priv->marker_seq) - seqno)
41312 + ret = ((atomic_read_unchecked(&dev_priv->marker_seq) - seqno)
41313 > VMW_FENCE_WRAP);
41314
41315 return ret;
41316 @@ -138,7 +138,7 @@ int vmw_fallback_wait(struct vmw_private *dev_priv,
41317
41318 if (fifo_idle)
41319 down_read(&fifo_state->rwsem);
41320 - signal_seq = atomic_read(&dev_priv->marker_seq);
41321 + signal_seq = atomic_read_unchecked(&dev_priv->marker_seq);
41322 ret = 0;
41323
41324 for (;;) {
41325 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
41326 index 8a8725c2..afed796 100644
41327 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
41328 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
41329 @@ -151,7 +151,7 @@ int vmw_wait_lag(struct vmw_private *dev_priv,
41330 while (!vmw_lag_lt(queue, us)) {
41331 spin_lock(&queue->lock);
41332 if (list_empty(&queue->head))
41333 - seqno = atomic_read(&dev_priv->marker_seq);
41334 + seqno = atomic_read_unchecked(&dev_priv->marker_seq);
41335 else {
41336 marker = list_first_entry(&queue->head,
41337 struct vmw_marker, head);
41338 diff --git a/drivers/gpu/vga/vga_switcheroo.c b/drivers/gpu/vga/vga_switcheroo.c
41339 index ec0ae2d..dc0780b 100644
41340 --- a/drivers/gpu/vga/vga_switcheroo.c
41341 +++ b/drivers/gpu/vga/vga_switcheroo.c
41342 @@ -643,7 +643,7 @@ static int vga_switcheroo_runtime_resume(struct device *dev)
41343
41344 /* this version is for the case where the power switch is separate
41345 to the device being powered down. */
41346 -int vga_switcheroo_init_domain_pm_ops(struct device *dev, struct dev_pm_domain *domain)
41347 +int vga_switcheroo_init_domain_pm_ops(struct device *dev, dev_pm_domain_no_const *domain)
41348 {
41349 /* copy over all the bus versions */
41350 if (dev->bus && dev->bus->pm) {
41351 @@ -688,7 +688,7 @@ static int vga_switcheroo_runtime_resume_hdmi_audio(struct device *dev)
41352 return ret;
41353 }
41354
41355 -int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, struct dev_pm_domain *domain)
41356 +int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, dev_pm_domain_no_const *domain)
41357 {
41358 /* copy over all the bus versions */
41359 if (dev->bus && dev->bus->pm) {
41360 diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
41361 index 253fe23..0dfec5f 100644
41362 --- a/drivers/hid/hid-core.c
41363 +++ b/drivers/hid/hid-core.c
41364 @@ -2416,7 +2416,7 @@ EXPORT_SYMBOL_GPL(hid_ignore);
41365
41366 int hid_add_device(struct hid_device *hdev)
41367 {
41368 - static atomic_t id = ATOMIC_INIT(0);
41369 + static atomic_unchecked_t id = ATOMIC_INIT(0);
41370 int ret;
41371
41372 if (WARN_ON(hdev->status & HID_STAT_ADDED))
41373 @@ -2450,7 +2450,7 @@ int hid_add_device(struct hid_device *hdev)
41374 /* XXX hack, any other cleaner solution after the driver core
41375 * is converted to allow more than 20 bytes as the device name? */
41376 dev_set_name(&hdev->dev, "%04X:%04X:%04X.%04X", hdev->bus,
41377 - hdev->vendor, hdev->product, atomic_inc_return(&id));
41378 + hdev->vendor, hdev->product, atomic_inc_return_unchecked(&id));
41379
41380 hid_debug_register(hdev, dev_name(&hdev->dev));
41381 ret = device_add(&hdev->dev);
41382 diff --git a/drivers/hid/hid-wiimote-debug.c b/drivers/hid/hid-wiimote-debug.c
41383 index c13fb5b..55a3802 100644
41384 --- a/drivers/hid/hid-wiimote-debug.c
41385 +++ b/drivers/hid/hid-wiimote-debug.c
41386 @@ -66,7 +66,7 @@ static ssize_t wiidebug_eeprom_read(struct file *f, char __user *u, size_t s,
41387 else if (size == 0)
41388 return -EIO;
41389
41390 - if (copy_to_user(u, buf, size))
41391 + if (size > sizeof(buf) || copy_to_user(u, buf, size))
41392 return -EFAULT;
41393
41394 *off += size;
41395 diff --git a/drivers/hid/uhid.c b/drivers/hid/uhid.c
41396 index cedc6da..2c3da2a 100644
41397 --- a/drivers/hid/uhid.c
41398 +++ b/drivers/hid/uhid.c
41399 @@ -47,7 +47,7 @@ struct uhid_device {
41400 struct mutex report_lock;
41401 wait_queue_head_t report_wait;
41402 atomic_t report_done;
41403 - atomic_t report_id;
41404 + atomic_unchecked_t report_id;
41405 struct uhid_event report_buf;
41406 };
41407
41408 @@ -163,7 +163,7 @@ static int uhid_hid_get_raw(struct hid_device *hid, unsigned char rnum,
41409
41410 spin_lock_irqsave(&uhid->qlock, flags);
41411 ev->type = UHID_FEATURE;
41412 - ev->u.feature.id = atomic_inc_return(&uhid->report_id);
41413 + ev->u.feature.id = atomic_inc_return_unchecked(&uhid->report_id);
41414 ev->u.feature.rnum = rnum;
41415 ev->u.feature.rtype = report_type;
41416
41417 @@ -446,7 +446,7 @@ static int uhid_dev_feature_answer(struct uhid_device *uhid,
41418 spin_lock_irqsave(&uhid->qlock, flags);
41419
41420 /* id for old report; drop it silently */
41421 - if (atomic_read(&uhid->report_id) != ev->u.feature_answer.id)
41422 + if (atomic_read_unchecked(&uhid->report_id) != ev->u.feature_answer.id)
41423 goto unlock;
41424 if (atomic_read(&uhid->report_done))
41425 goto unlock;
41426 diff --git a/drivers/hv/channel.c b/drivers/hv/channel.c
41427 index cea623c..73011b0 100644
41428 --- a/drivers/hv/channel.c
41429 +++ b/drivers/hv/channel.c
41430 @@ -362,8 +362,8 @@ int vmbus_establish_gpadl(struct vmbus_channel *channel, void *kbuffer,
41431 int ret = 0;
41432 int t;
41433
41434 - next_gpadl_handle = atomic_read(&vmbus_connection.next_gpadl_handle);
41435 - atomic_inc(&vmbus_connection.next_gpadl_handle);
41436 + next_gpadl_handle = atomic_read_unchecked(&vmbus_connection.next_gpadl_handle);
41437 + atomic_inc_unchecked(&vmbus_connection.next_gpadl_handle);
41438
41439 ret = create_gpadl_header(kbuffer, size, &msginfo, &msgcount);
41440 if (ret)
41441 diff --git a/drivers/hv/hv.c b/drivers/hv/hv.c
41442 index f0c5e07..49a4d4a 100644
41443 --- a/drivers/hv/hv.c
41444 +++ b/drivers/hv/hv.c
41445 @@ -112,7 +112,7 @@ static u64 do_hypercall(u64 control, void *input, void *output)
41446 u64 output_address = (output) ? virt_to_phys(output) : 0;
41447 u32 output_address_hi = output_address >> 32;
41448 u32 output_address_lo = output_address & 0xFFFFFFFF;
41449 - void *hypercall_page = hv_context.hypercall_page;
41450 + void *hypercall_page = ktva_ktla(hv_context.hypercall_page);
41451
41452 __asm__ __volatile__ ("call *%8" : "=d"(hv_status_hi),
41453 "=a"(hv_status_lo) : "d" (control_hi),
41454 @@ -154,7 +154,7 @@ int hv_init(void)
41455 /* See if the hypercall page is already set */
41456 rdmsrl(HV_X64_MSR_HYPERCALL, hypercall_msr.as_uint64);
41457
41458 - virtaddr = __vmalloc(PAGE_SIZE, GFP_KERNEL, PAGE_KERNEL_EXEC);
41459 + virtaddr = __vmalloc(PAGE_SIZE, GFP_KERNEL, PAGE_KERNEL_RX);
41460
41461 if (!virtaddr)
41462 goto cleanup;
41463 diff --git a/drivers/hv/hv_balloon.c b/drivers/hv/hv_balloon.c
41464 index 7e17a54..a50a33d 100644
41465 --- a/drivers/hv/hv_balloon.c
41466 +++ b/drivers/hv/hv_balloon.c
41467 @@ -464,7 +464,7 @@ MODULE_PARM_DESC(hot_add, "If set attempt memory hot_add");
41468
41469 module_param(pressure_report_delay, uint, (S_IRUGO | S_IWUSR));
41470 MODULE_PARM_DESC(pressure_report_delay, "Delay in secs in reporting pressure");
41471 -static atomic_t trans_id = ATOMIC_INIT(0);
41472 +static atomic_unchecked_t trans_id = ATOMIC_INIT(0);
41473
41474 static int dm_ring_size = (5 * PAGE_SIZE);
41475
41476 @@ -886,7 +886,7 @@ static void hot_add_req(struct work_struct *dummy)
41477 pr_info("Memory hot add failed\n");
41478
41479 dm->state = DM_INITIALIZED;
41480 - resp.hdr.trans_id = atomic_inc_return(&trans_id);
41481 + resp.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
41482 vmbus_sendpacket(dm->dev->channel, &resp,
41483 sizeof(struct dm_hot_add_response),
41484 (unsigned long)NULL,
41485 @@ -960,7 +960,7 @@ static void post_status(struct hv_dynmem_device *dm)
41486 memset(&status, 0, sizeof(struct dm_status));
41487 status.hdr.type = DM_STATUS_REPORT;
41488 status.hdr.size = sizeof(struct dm_status);
41489 - status.hdr.trans_id = atomic_inc_return(&trans_id);
41490 + status.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
41491
41492 /*
41493 * The host expects the guest to report free memory.
41494 @@ -980,7 +980,7 @@ static void post_status(struct hv_dynmem_device *dm)
41495 * send the status. This can happen if we were interrupted
41496 * after we picked our transaction ID.
41497 */
41498 - if (status.hdr.trans_id != atomic_read(&trans_id))
41499 + if (status.hdr.trans_id != atomic_read_unchecked(&trans_id))
41500 return;
41501
41502 vmbus_sendpacket(dm->dev->channel, &status,
41503 @@ -1108,7 +1108,7 @@ static void balloon_up(struct work_struct *dummy)
41504 */
41505
41506 do {
41507 - bl_resp->hdr.trans_id = atomic_inc_return(&trans_id);
41508 + bl_resp->hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
41509 ret = vmbus_sendpacket(dm_device.dev->channel,
41510 bl_resp,
41511 bl_resp->hdr.size,
41512 @@ -1152,7 +1152,7 @@ static void balloon_down(struct hv_dynmem_device *dm,
41513
41514 memset(&resp, 0, sizeof(struct dm_unballoon_response));
41515 resp.hdr.type = DM_UNBALLOON_RESPONSE;
41516 - resp.hdr.trans_id = atomic_inc_return(&trans_id);
41517 + resp.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
41518 resp.hdr.size = sizeof(struct dm_unballoon_response);
41519
41520 vmbus_sendpacket(dm_device.dev->channel, &resp,
41521 @@ -1215,7 +1215,7 @@ static void version_resp(struct hv_dynmem_device *dm,
41522 memset(&version_req, 0, sizeof(struct dm_version_request));
41523 version_req.hdr.type = DM_VERSION_REQUEST;
41524 version_req.hdr.size = sizeof(struct dm_version_request);
41525 - version_req.hdr.trans_id = atomic_inc_return(&trans_id);
41526 + version_req.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
41527 version_req.version.version = DYNMEM_PROTOCOL_VERSION_WIN7;
41528 version_req.is_last_attempt = 1;
41529
41530 @@ -1385,7 +1385,7 @@ static int balloon_probe(struct hv_device *dev,
41531 memset(&version_req, 0, sizeof(struct dm_version_request));
41532 version_req.hdr.type = DM_VERSION_REQUEST;
41533 version_req.hdr.size = sizeof(struct dm_version_request);
41534 - version_req.hdr.trans_id = atomic_inc_return(&trans_id);
41535 + version_req.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
41536 version_req.version.version = DYNMEM_PROTOCOL_VERSION_WIN8;
41537 version_req.is_last_attempt = 0;
41538
41539 @@ -1416,7 +1416,7 @@ static int balloon_probe(struct hv_device *dev,
41540 memset(&cap_msg, 0, sizeof(struct dm_capabilities));
41541 cap_msg.hdr.type = DM_CAPABILITIES_REPORT;
41542 cap_msg.hdr.size = sizeof(struct dm_capabilities);
41543 - cap_msg.hdr.trans_id = atomic_inc_return(&trans_id);
41544 + cap_msg.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
41545
41546 cap_msg.caps.cap_bits.balloon = 1;
41547 cap_msg.caps.cap_bits.hot_add = 1;
41548 diff --git a/drivers/hv/hyperv_vmbus.h b/drivers/hv/hyperv_vmbus.h
41549 index e055176..c22ff1f 100644
41550 --- a/drivers/hv/hyperv_vmbus.h
41551 +++ b/drivers/hv/hyperv_vmbus.h
41552 @@ -602,7 +602,7 @@ enum vmbus_connect_state {
41553 struct vmbus_connection {
41554 enum vmbus_connect_state conn_state;
41555
41556 - atomic_t next_gpadl_handle;
41557 + atomic_unchecked_t next_gpadl_handle;
41558
41559 /*
41560 * Represents channel interrupts. Each bit position represents a
41561 diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c
41562 index 48aad4f..c768fb2 100644
41563 --- a/drivers/hv/vmbus_drv.c
41564 +++ b/drivers/hv/vmbus_drv.c
41565 @@ -846,10 +846,10 @@ int vmbus_device_register(struct hv_device *child_device_obj)
41566 {
41567 int ret = 0;
41568
41569 - static atomic_t device_num = ATOMIC_INIT(0);
41570 + static atomic_unchecked_t device_num = ATOMIC_INIT(0);
41571
41572 dev_set_name(&child_device_obj->device, "vmbus_0_%d",
41573 - atomic_inc_return(&device_num));
41574 + atomic_inc_return_unchecked(&device_num));
41575
41576 child_device_obj->device.bus = &hv_bus;
41577 child_device_obj->device.parent = &hv_acpi_dev->dev;
41578 diff --git a/drivers/hwmon/acpi_power_meter.c b/drivers/hwmon/acpi_power_meter.c
41579 index 6a34f7f..aa4c3a6 100644
41580 --- a/drivers/hwmon/acpi_power_meter.c
41581 +++ b/drivers/hwmon/acpi_power_meter.c
41582 @@ -117,7 +117,7 @@ struct sensor_template {
41583 struct device_attribute *devattr,
41584 const char *buf, size_t count);
41585 int index;
41586 -};
41587 +} __do_const;
41588
41589 /* Averaging interval */
41590 static int update_avg_interval(struct acpi_power_meter_resource *resource)
41591 @@ -632,7 +632,7 @@ static int register_attrs(struct acpi_power_meter_resource *resource,
41592 struct sensor_template *attrs)
41593 {
41594 struct device *dev = &resource->acpi_dev->dev;
41595 - struct sensor_device_attribute *sensors =
41596 + sensor_device_attribute_no_const *sensors =
41597 &resource->sensors[resource->num_sensors];
41598 int res = 0;
41599
41600 diff --git a/drivers/hwmon/applesmc.c b/drivers/hwmon/applesmc.c
41601 index 3288f13..71cfb4e 100644
41602 --- a/drivers/hwmon/applesmc.c
41603 +++ b/drivers/hwmon/applesmc.c
41604 @@ -1106,7 +1106,7 @@ static int applesmc_create_nodes(struct applesmc_node_group *groups, int num)
41605 {
41606 struct applesmc_node_group *grp;
41607 struct applesmc_dev_attr *node;
41608 - struct attribute *attr;
41609 + attribute_no_const *attr;
41610 int ret, i;
41611
41612 for (grp = groups; grp->format; grp++) {
41613 diff --git a/drivers/hwmon/asus_atk0110.c b/drivers/hwmon/asus_atk0110.c
41614 index dafc63c..4abb96c 100644
41615 --- a/drivers/hwmon/asus_atk0110.c
41616 +++ b/drivers/hwmon/asus_atk0110.c
41617 @@ -151,10 +151,10 @@ MODULE_DEVICE_TABLE(acpi, atk_ids);
41618 struct atk_sensor_data {
41619 struct list_head list;
41620 struct atk_data *data;
41621 - struct device_attribute label_attr;
41622 - struct device_attribute input_attr;
41623 - struct device_attribute limit1_attr;
41624 - struct device_attribute limit2_attr;
41625 + device_attribute_no_const label_attr;
41626 + device_attribute_no_const input_attr;
41627 + device_attribute_no_const limit1_attr;
41628 + device_attribute_no_const limit2_attr;
41629 char label_attr_name[ATTR_NAME_SIZE];
41630 char input_attr_name[ATTR_NAME_SIZE];
41631 char limit1_attr_name[ATTR_NAME_SIZE];
41632 @@ -274,7 +274,7 @@ static ssize_t atk_name_show(struct device *dev,
41633 static struct device_attribute atk_name_attr =
41634 __ATTR(name, 0444, atk_name_show, NULL);
41635
41636 -static void atk_init_attribute(struct device_attribute *attr, char *name,
41637 +static void atk_init_attribute(device_attribute_no_const *attr, char *name,
41638 sysfs_show_func show)
41639 {
41640 sysfs_attr_init(&attr->attr);
41641 diff --git a/drivers/hwmon/coretemp.c b/drivers/hwmon/coretemp.c
41642 index 9425098..7646cc5 100644
41643 --- a/drivers/hwmon/coretemp.c
41644 +++ b/drivers/hwmon/coretemp.c
41645 @@ -797,7 +797,7 @@ static int coretemp_cpu_callback(struct notifier_block *nfb,
41646 return NOTIFY_OK;
41647 }
41648
41649 -static struct notifier_block coretemp_cpu_notifier __refdata = {
41650 +static struct notifier_block coretemp_cpu_notifier = {
41651 .notifier_call = coretemp_cpu_callback,
41652 };
41653
41654 diff --git a/drivers/hwmon/ibmaem.c b/drivers/hwmon/ibmaem.c
41655 index 632f1dc..57e6a58 100644
41656 --- a/drivers/hwmon/ibmaem.c
41657 +++ b/drivers/hwmon/ibmaem.c
41658 @@ -926,7 +926,7 @@ static int aem_register_sensors(struct aem_data *data,
41659 struct aem_rw_sensor_template *rw)
41660 {
41661 struct device *dev = &data->pdev->dev;
41662 - struct sensor_device_attribute *sensors = data->sensors;
41663 + sensor_device_attribute_no_const *sensors = data->sensors;
41664 int err;
41665
41666 /* Set up read-only sensors */
41667 diff --git a/drivers/hwmon/iio_hwmon.c b/drivers/hwmon/iio_hwmon.c
41668 index 708081b..fe2d4ab 100644
41669 --- a/drivers/hwmon/iio_hwmon.c
41670 +++ b/drivers/hwmon/iio_hwmon.c
41671 @@ -73,7 +73,7 @@ static int iio_hwmon_probe(struct platform_device *pdev)
41672 {
41673 struct device *dev = &pdev->dev;
41674 struct iio_hwmon_state *st;
41675 - struct sensor_device_attribute *a;
41676 + sensor_device_attribute_no_const *a;
41677 int ret, i;
41678 int in_i = 1, temp_i = 1, curr_i = 1;
41679 enum iio_chan_type type;
41680 diff --git a/drivers/hwmon/nct6775.c b/drivers/hwmon/nct6775.c
41681 index cf811c1..4c17110 100644
41682 --- a/drivers/hwmon/nct6775.c
41683 +++ b/drivers/hwmon/nct6775.c
41684 @@ -944,10 +944,10 @@ static struct attribute_group *
41685 nct6775_create_attr_group(struct device *dev, struct sensor_template_group *tg,
41686 int repeat)
41687 {
41688 - struct attribute_group *group;
41689 + attribute_group_no_const *group;
41690 struct sensor_device_attr_u *su;
41691 - struct sensor_device_attribute *a;
41692 - struct sensor_device_attribute_2 *a2;
41693 + sensor_device_attribute_no_const *a;
41694 + sensor_device_attribute_2_no_const *a2;
41695 struct attribute **attrs;
41696 struct sensor_device_template **t;
41697 int i, count;
41698 diff --git a/drivers/hwmon/pmbus/pmbus_core.c b/drivers/hwmon/pmbus/pmbus_core.c
41699 index 3cbf66e..8c5cc2a 100644
41700 --- a/drivers/hwmon/pmbus/pmbus_core.c
41701 +++ b/drivers/hwmon/pmbus/pmbus_core.c
41702 @@ -782,7 +782,7 @@ static int pmbus_add_attribute(struct pmbus_data *data, struct attribute *attr)
41703 return 0;
41704 }
41705
41706 -static void pmbus_dev_attr_init(struct device_attribute *dev_attr,
41707 +static void pmbus_dev_attr_init(device_attribute_no_const *dev_attr,
41708 const char *name,
41709 umode_t mode,
41710 ssize_t (*show)(struct device *dev,
41711 @@ -799,7 +799,7 @@ static void pmbus_dev_attr_init(struct device_attribute *dev_attr,
41712 dev_attr->store = store;
41713 }
41714
41715 -static void pmbus_attr_init(struct sensor_device_attribute *a,
41716 +static void pmbus_attr_init(sensor_device_attribute_no_const *a,
41717 const char *name,
41718 umode_t mode,
41719 ssize_t (*show)(struct device *dev,
41720 @@ -821,7 +821,7 @@ static int pmbus_add_boolean(struct pmbus_data *data,
41721 u16 reg, u8 mask)
41722 {
41723 struct pmbus_boolean *boolean;
41724 - struct sensor_device_attribute *a;
41725 + sensor_device_attribute_no_const *a;
41726
41727 boolean = devm_kzalloc(data->dev, sizeof(*boolean), GFP_KERNEL);
41728 if (!boolean)
41729 @@ -846,7 +846,7 @@ static struct pmbus_sensor *pmbus_add_sensor(struct pmbus_data *data,
41730 bool update, bool readonly)
41731 {
41732 struct pmbus_sensor *sensor;
41733 - struct device_attribute *a;
41734 + device_attribute_no_const *a;
41735
41736 sensor = devm_kzalloc(data->dev, sizeof(*sensor), GFP_KERNEL);
41737 if (!sensor)
41738 @@ -877,7 +877,7 @@ static int pmbus_add_label(struct pmbus_data *data,
41739 const char *lstring, int index)
41740 {
41741 struct pmbus_label *label;
41742 - struct device_attribute *a;
41743 + device_attribute_no_const *a;
41744
41745 label = devm_kzalloc(data->dev, sizeof(*label), GFP_KERNEL);
41746 if (!label)
41747 diff --git a/drivers/hwmon/sht15.c b/drivers/hwmon/sht15.c
41748 index 97cd45a..ac54d8b 100644
41749 --- a/drivers/hwmon/sht15.c
41750 +++ b/drivers/hwmon/sht15.c
41751 @@ -169,7 +169,7 @@ struct sht15_data {
41752 int supply_uv;
41753 bool supply_uv_valid;
41754 struct work_struct update_supply_work;
41755 - atomic_t interrupt_handled;
41756 + atomic_unchecked_t interrupt_handled;
41757 };
41758
41759 /**
41760 @@ -542,13 +542,13 @@ static int sht15_measurement(struct sht15_data *data,
41761 ret = gpio_direction_input(data->pdata->gpio_data);
41762 if (ret)
41763 return ret;
41764 - atomic_set(&data->interrupt_handled, 0);
41765 + atomic_set_unchecked(&data->interrupt_handled, 0);
41766
41767 enable_irq(gpio_to_irq(data->pdata->gpio_data));
41768 if (gpio_get_value(data->pdata->gpio_data) == 0) {
41769 disable_irq_nosync(gpio_to_irq(data->pdata->gpio_data));
41770 /* Only relevant if the interrupt hasn't occurred. */
41771 - if (!atomic_read(&data->interrupt_handled))
41772 + if (!atomic_read_unchecked(&data->interrupt_handled))
41773 schedule_work(&data->read_work);
41774 }
41775 ret = wait_event_timeout(data->wait_queue,
41776 @@ -820,7 +820,7 @@ static irqreturn_t sht15_interrupt_fired(int irq, void *d)
41777
41778 /* First disable the interrupt */
41779 disable_irq_nosync(irq);
41780 - atomic_inc(&data->interrupt_handled);
41781 + atomic_inc_unchecked(&data->interrupt_handled);
41782 /* Then schedule a reading work struct */
41783 if (data->state != SHT15_READING_NOTHING)
41784 schedule_work(&data->read_work);
41785 @@ -842,11 +842,11 @@ static void sht15_bh_read_data(struct work_struct *work_s)
41786 * If not, then start the interrupt again - care here as could
41787 * have gone low in meantime so verify it hasn't!
41788 */
41789 - atomic_set(&data->interrupt_handled, 0);
41790 + atomic_set_unchecked(&data->interrupt_handled, 0);
41791 enable_irq(gpio_to_irq(data->pdata->gpio_data));
41792 /* If still not occurred or another handler was scheduled */
41793 if (gpio_get_value(data->pdata->gpio_data)
41794 - || atomic_read(&data->interrupt_handled))
41795 + || atomic_read_unchecked(&data->interrupt_handled))
41796 return;
41797 }
41798
41799 diff --git a/drivers/hwmon/via-cputemp.c b/drivers/hwmon/via-cputemp.c
41800 index 38944e9..ae9e5ed 100644
41801 --- a/drivers/hwmon/via-cputemp.c
41802 +++ b/drivers/hwmon/via-cputemp.c
41803 @@ -296,7 +296,7 @@ static int via_cputemp_cpu_callback(struct notifier_block *nfb,
41804 return NOTIFY_OK;
41805 }
41806
41807 -static struct notifier_block via_cputemp_cpu_notifier __refdata = {
41808 +static struct notifier_block via_cputemp_cpu_notifier = {
41809 .notifier_call = via_cputemp_cpu_callback,
41810 };
41811
41812 diff --git a/drivers/i2c/busses/i2c-amd756-s4882.c b/drivers/i2c/busses/i2c-amd756-s4882.c
41813 index 07f01ac..d79ad3d 100644
41814 --- a/drivers/i2c/busses/i2c-amd756-s4882.c
41815 +++ b/drivers/i2c/busses/i2c-amd756-s4882.c
41816 @@ -43,7 +43,7 @@
41817 extern struct i2c_adapter amd756_smbus;
41818
41819 static struct i2c_adapter *s4882_adapter;
41820 -static struct i2c_algorithm *s4882_algo;
41821 +static i2c_algorithm_no_const *s4882_algo;
41822
41823 /* Wrapper access functions for multiplexed SMBus */
41824 static DEFINE_MUTEX(amd756_lock);
41825 diff --git a/drivers/i2c/busses/i2c-diolan-u2c.c b/drivers/i2c/busses/i2c-diolan-u2c.c
41826 index 721f7eb..0fd2a09 100644
41827 --- a/drivers/i2c/busses/i2c-diolan-u2c.c
41828 +++ b/drivers/i2c/busses/i2c-diolan-u2c.c
41829 @@ -98,7 +98,7 @@ MODULE_PARM_DESC(frequency, "I2C clock frequency in hertz");
41830 /* usb layer */
41831
41832 /* Send command to device, and get response. */
41833 -static int diolan_usb_transfer(struct i2c_diolan_u2c *dev)
41834 +static int __intentional_overflow(-1) diolan_usb_transfer(struct i2c_diolan_u2c *dev)
41835 {
41836 int ret = 0;
41837 int actual;
41838 diff --git a/drivers/i2c/busses/i2c-nforce2-s4985.c b/drivers/i2c/busses/i2c-nforce2-s4985.c
41839 index 2ca268d..c6acbdf 100644
41840 --- a/drivers/i2c/busses/i2c-nforce2-s4985.c
41841 +++ b/drivers/i2c/busses/i2c-nforce2-s4985.c
41842 @@ -41,7 +41,7 @@
41843 extern struct i2c_adapter *nforce2_smbus;
41844
41845 static struct i2c_adapter *s4985_adapter;
41846 -static struct i2c_algorithm *s4985_algo;
41847 +static i2c_algorithm_no_const *s4985_algo;
41848
41849 /* Wrapper access functions for multiplexed SMBus */
41850 static DEFINE_MUTEX(nforce2_lock);
41851 diff --git a/drivers/i2c/i2c-dev.c b/drivers/i2c/i2c-dev.c
41852 index 80b47e8..1a6040d9 100644
41853 --- a/drivers/i2c/i2c-dev.c
41854 +++ b/drivers/i2c/i2c-dev.c
41855 @@ -277,7 +277,7 @@ static noinline int i2cdev_ioctl_rdrw(struct i2c_client *client,
41856 break;
41857 }
41858
41859 - data_ptrs[i] = (u8 __user *)rdwr_pa[i].buf;
41860 + data_ptrs[i] = (u8 __force_user *)rdwr_pa[i].buf;
41861 rdwr_pa[i].buf = memdup_user(data_ptrs[i], rdwr_pa[i].len);
41862 if (IS_ERR(rdwr_pa[i].buf)) {
41863 res = PTR_ERR(rdwr_pa[i].buf);
41864 diff --git a/drivers/ide/ide-cd.c b/drivers/ide/ide-cd.c
41865 index 0b510ba..4fbb5085 100644
41866 --- a/drivers/ide/ide-cd.c
41867 +++ b/drivers/ide/ide-cd.c
41868 @@ -768,7 +768,7 @@ static void cdrom_do_block_pc(ide_drive_t *drive, struct request *rq)
41869 alignment = queue_dma_alignment(q) | q->dma_pad_mask;
41870 if ((unsigned long)buf & alignment
41871 || blk_rq_bytes(rq) & q->dma_pad_mask
41872 - || object_is_on_stack(buf))
41873 + || object_starts_on_stack(buf))
41874 drive->dma = 0;
41875 }
41876 }
41877 diff --git a/drivers/iio/industrialio-core.c b/drivers/iio/industrialio-core.c
41878 index 18f72e3..3722327 100644
41879 --- a/drivers/iio/industrialio-core.c
41880 +++ b/drivers/iio/industrialio-core.c
41881 @@ -521,7 +521,7 @@ static ssize_t iio_write_channel_info(struct device *dev,
41882 }
41883
41884 static
41885 -int __iio_device_attr_init(struct device_attribute *dev_attr,
41886 +int __iio_device_attr_init(device_attribute_no_const *dev_attr,
41887 const char *postfix,
41888 struct iio_chan_spec const *chan,
41889 ssize_t (*readfunc)(struct device *dev,
41890 diff --git a/drivers/infiniband/core/cm.c b/drivers/infiniband/core/cm.c
41891 index f2ef7ef..743d02f 100644
41892 --- a/drivers/infiniband/core/cm.c
41893 +++ b/drivers/infiniband/core/cm.c
41894 @@ -114,7 +114,7 @@ static char const counter_group_names[CM_COUNTER_GROUPS]
41895
41896 struct cm_counter_group {
41897 struct kobject obj;
41898 - atomic_long_t counter[CM_ATTR_COUNT];
41899 + atomic_long_unchecked_t counter[CM_ATTR_COUNT];
41900 };
41901
41902 struct cm_counter_attribute {
41903 @@ -1392,7 +1392,7 @@ static void cm_dup_req_handler(struct cm_work *work,
41904 struct ib_mad_send_buf *msg = NULL;
41905 int ret;
41906
41907 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
41908 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
41909 counter[CM_REQ_COUNTER]);
41910
41911 /* Quick state check to discard duplicate REQs. */
41912 @@ -1776,7 +1776,7 @@ static void cm_dup_rep_handler(struct cm_work *work)
41913 if (!cm_id_priv)
41914 return;
41915
41916 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
41917 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
41918 counter[CM_REP_COUNTER]);
41919 ret = cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg);
41920 if (ret)
41921 @@ -1943,7 +1943,7 @@ static int cm_rtu_handler(struct cm_work *work)
41922 if (cm_id_priv->id.state != IB_CM_REP_SENT &&
41923 cm_id_priv->id.state != IB_CM_MRA_REP_RCVD) {
41924 spin_unlock_irq(&cm_id_priv->lock);
41925 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
41926 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
41927 counter[CM_RTU_COUNTER]);
41928 goto out;
41929 }
41930 @@ -2126,7 +2126,7 @@ static int cm_dreq_handler(struct cm_work *work)
41931 cm_id_priv = cm_acquire_id(dreq_msg->remote_comm_id,
41932 dreq_msg->local_comm_id);
41933 if (!cm_id_priv) {
41934 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
41935 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
41936 counter[CM_DREQ_COUNTER]);
41937 cm_issue_drep(work->port, work->mad_recv_wc);
41938 return -EINVAL;
41939 @@ -2151,7 +2151,7 @@ static int cm_dreq_handler(struct cm_work *work)
41940 case IB_CM_MRA_REP_RCVD:
41941 break;
41942 case IB_CM_TIMEWAIT:
41943 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
41944 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
41945 counter[CM_DREQ_COUNTER]);
41946 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
41947 goto unlock;
41948 @@ -2165,7 +2165,7 @@ static int cm_dreq_handler(struct cm_work *work)
41949 cm_free_msg(msg);
41950 goto deref;
41951 case IB_CM_DREQ_RCVD:
41952 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
41953 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
41954 counter[CM_DREQ_COUNTER]);
41955 goto unlock;
41956 default:
41957 @@ -2532,7 +2532,7 @@ static int cm_mra_handler(struct cm_work *work)
41958 ib_modify_mad(cm_id_priv->av.port->mad_agent,
41959 cm_id_priv->msg, timeout)) {
41960 if (cm_id_priv->id.lap_state == IB_CM_MRA_LAP_RCVD)
41961 - atomic_long_inc(&work->port->
41962 + atomic_long_inc_unchecked(&work->port->
41963 counter_group[CM_RECV_DUPLICATES].
41964 counter[CM_MRA_COUNTER]);
41965 goto out;
41966 @@ -2541,7 +2541,7 @@ static int cm_mra_handler(struct cm_work *work)
41967 break;
41968 case IB_CM_MRA_REQ_RCVD:
41969 case IB_CM_MRA_REP_RCVD:
41970 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
41971 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
41972 counter[CM_MRA_COUNTER]);
41973 /* fall through */
41974 default:
41975 @@ -2703,7 +2703,7 @@ static int cm_lap_handler(struct cm_work *work)
41976 case IB_CM_LAP_IDLE:
41977 break;
41978 case IB_CM_MRA_LAP_SENT:
41979 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
41980 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
41981 counter[CM_LAP_COUNTER]);
41982 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
41983 goto unlock;
41984 @@ -2719,7 +2719,7 @@ static int cm_lap_handler(struct cm_work *work)
41985 cm_free_msg(msg);
41986 goto deref;
41987 case IB_CM_LAP_RCVD:
41988 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
41989 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
41990 counter[CM_LAP_COUNTER]);
41991 goto unlock;
41992 default:
41993 @@ -3003,7 +3003,7 @@ static int cm_sidr_req_handler(struct cm_work *work)
41994 cur_cm_id_priv = cm_insert_remote_sidr(cm_id_priv);
41995 if (cur_cm_id_priv) {
41996 spin_unlock_irq(&cm.lock);
41997 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
41998 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
41999 counter[CM_SIDR_REQ_COUNTER]);
42000 goto out; /* Duplicate message. */
42001 }
42002 @@ -3215,10 +3215,10 @@ static void cm_send_handler(struct ib_mad_agent *mad_agent,
42003 if (!msg->context[0] && (attr_index != CM_REJ_COUNTER))
42004 msg->retries = 1;
42005
42006 - atomic_long_add(1 + msg->retries,
42007 + atomic_long_add_unchecked(1 + msg->retries,
42008 &port->counter_group[CM_XMIT].counter[attr_index]);
42009 if (msg->retries)
42010 - atomic_long_add(msg->retries,
42011 + atomic_long_add_unchecked(msg->retries,
42012 &port->counter_group[CM_XMIT_RETRIES].
42013 counter[attr_index]);
42014
42015 @@ -3428,7 +3428,7 @@ static void cm_recv_handler(struct ib_mad_agent *mad_agent,
42016 }
42017
42018 attr_id = be16_to_cpu(mad_recv_wc->recv_buf.mad->mad_hdr.attr_id);
42019 - atomic_long_inc(&port->counter_group[CM_RECV].
42020 + atomic_long_inc_unchecked(&port->counter_group[CM_RECV].
42021 counter[attr_id - CM_ATTR_ID_OFFSET]);
42022
42023 work = kmalloc(sizeof *work + sizeof(struct ib_sa_path_rec) * paths,
42024 @@ -3633,7 +3633,7 @@ static ssize_t cm_show_counter(struct kobject *obj, struct attribute *attr,
42025 cm_attr = container_of(attr, struct cm_counter_attribute, attr);
42026
42027 return sprintf(buf, "%ld\n",
42028 - atomic_long_read(&group->counter[cm_attr->index]));
42029 + atomic_long_read_unchecked(&group->counter[cm_attr->index]));
42030 }
42031
42032 static const struct sysfs_ops cm_counter_ops = {
42033 diff --git a/drivers/infiniband/core/fmr_pool.c b/drivers/infiniband/core/fmr_pool.c
42034 index 9f5ad7c..588cd84 100644
42035 --- a/drivers/infiniband/core/fmr_pool.c
42036 +++ b/drivers/infiniband/core/fmr_pool.c
42037 @@ -98,8 +98,8 @@ struct ib_fmr_pool {
42038
42039 struct task_struct *thread;
42040
42041 - atomic_t req_ser;
42042 - atomic_t flush_ser;
42043 + atomic_unchecked_t req_ser;
42044 + atomic_unchecked_t flush_ser;
42045
42046 wait_queue_head_t force_wait;
42047 };
42048 @@ -179,10 +179,10 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
42049 struct ib_fmr_pool *pool = pool_ptr;
42050
42051 do {
42052 - if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) < 0) {
42053 + if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) < 0) {
42054 ib_fmr_batch_release(pool);
42055
42056 - atomic_inc(&pool->flush_ser);
42057 + atomic_inc_unchecked(&pool->flush_ser);
42058 wake_up_interruptible(&pool->force_wait);
42059
42060 if (pool->flush_function)
42061 @@ -190,7 +190,7 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
42062 }
42063
42064 set_current_state(TASK_INTERRUPTIBLE);
42065 - if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) >= 0 &&
42066 + if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) >= 0 &&
42067 !kthread_should_stop())
42068 schedule();
42069 __set_current_state(TASK_RUNNING);
42070 @@ -282,8 +282,8 @@ struct ib_fmr_pool *ib_create_fmr_pool(struct ib_pd *pd,
42071 pool->dirty_watermark = params->dirty_watermark;
42072 pool->dirty_len = 0;
42073 spin_lock_init(&pool->pool_lock);
42074 - atomic_set(&pool->req_ser, 0);
42075 - atomic_set(&pool->flush_ser, 0);
42076 + atomic_set_unchecked(&pool->req_ser, 0);
42077 + atomic_set_unchecked(&pool->flush_ser, 0);
42078 init_waitqueue_head(&pool->force_wait);
42079
42080 pool->thread = kthread_run(ib_fmr_cleanup_thread,
42081 @@ -411,11 +411,11 @@ int ib_flush_fmr_pool(struct ib_fmr_pool *pool)
42082 }
42083 spin_unlock_irq(&pool->pool_lock);
42084
42085 - serial = atomic_inc_return(&pool->req_ser);
42086 + serial = atomic_inc_return_unchecked(&pool->req_ser);
42087 wake_up_process(pool->thread);
42088
42089 if (wait_event_interruptible(pool->force_wait,
42090 - atomic_read(&pool->flush_ser) - serial >= 0))
42091 + atomic_read_unchecked(&pool->flush_ser) - serial >= 0))
42092 return -EINTR;
42093
42094 return 0;
42095 @@ -525,7 +525,7 @@ int ib_fmr_pool_unmap(struct ib_pool_fmr *fmr)
42096 } else {
42097 list_add_tail(&fmr->list, &pool->dirty_list);
42098 if (++pool->dirty_len >= pool->dirty_watermark) {
42099 - atomic_inc(&pool->req_ser);
42100 + atomic_inc_unchecked(&pool->req_ser);
42101 wake_up_process(pool->thread);
42102 }
42103 }
42104 diff --git a/drivers/infiniband/hw/cxgb4/mem.c b/drivers/infiniband/hw/cxgb4/mem.c
42105 index 84e4500..2c9beeb 100644
42106 --- a/drivers/infiniband/hw/cxgb4/mem.c
42107 +++ b/drivers/infiniband/hw/cxgb4/mem.c
42108 @@ -249,7 +249,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
42109 int err;
42110 struct fw_ri_tpte tpt;
42111 u32 stag_idx;
42112 - static atomic_t key;
42113 + static atomic_unchecked_t key;
42114
42115 if (c4iw_fatal_error(rdev))
42116 return -EIO;
42117 @@ -266,7 +266,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
42118 if (rdev->stats.stag.cur > rdev->stats.stag.max)
42119 rdev->stats.stag.max = rdev->stats.stag.cur;
42120 mutex_unlock(&rdev->stats.lock);
42121 - *stag = (stag_idx << 8) | (atomic_inc_return(&key) & 0xff);
42122 + *stag = (stag_idx << 8) | (atomic_inc_return_unchecked(&key) & 0xff);
42123 }
42124 PDBG("%s stag_state 0x%0x type 0x%0x pdid 0x%0x, stag_idx 0x%x\n",
42125 __func__, stag_state, type, pdid, stag_idx);
42126 diff --git a/drivers/infiniband/hw/ipath/ipath_dma.c b/drivers/infiniband/hw/ipath/ipath_dma.c
42127 index 644c2c7..ecf0879 100644
42128 --- a/drivers/infiniband/hw/ipath/ipath_dma.c
42129 +++ b/drivers/infiniband/hw/ipath/ipath_dma.c
42130 @@ -176,17 +176,17 @@ static void ipath_dma_free_coherent(struct ib_device *dev, size_t size,
42131 }
42132
42133 struct ib_dma_mapping_ops ipath_dma_mapping_ops = {
42134 - ipath_mapping_error,
42135 - ipath_dma_map_single,
42136 - ipath_dma_unmap_single,
42137 - ipath_dma_map_page,
42138 - ipath_dma_unmap_page,
42139 - ipath_map_sg,
42140 - ipath_unmap_sg,
42141 - ipath_sg_dma_address,
42142 - ipath_sg_dma_len,
42143 - ipath_sync_single_for_cpu,
42144 - ipath_sync_single_for_device,
42145 - ipath_dma_alloc_coherent,
42146 - ipath_dma_free_coherent
42147 + .mapping_error = ipath_mapping_error,
42148 + .map_single = ipath_dma_map_single,
42149 + .unmap_single = ipath_dma_unmap_single,
42150 + .map_page = ipath_dma_map_page,
42151 + .unmap_page = ipath_dma_unmap_page,
42152 + .map_sg = ipath_map_sg,
42153 + .unmap_sg = ipath_unmap_sg,
42154 + .dma_address = ipath_sg_dma_address,
42155 + .dma_len = ipath_sg_dma_len,
42156 + .sync_single_for_cpu = ipath_sync_single_for_cpu,
42157 + .sync_single_for_device = ipath_sync_single_for_device,
42158 + .alloc_coherent = ipath_dma_alloc_coherent,
42159 + .free_coherent = ipath_dma_free_coherent
42160 };
42161 diff --git a/drivers/infiniband/hw/ipath/ipath_rc.c b/drivers/infiniband/hw/ipath/ipath_rc.c
42162 index 79b3dbc..96e5fcc 100644
42163 --- a/drivers/infiniband/hw/ipath/ipath_rc.c
42164 +++ b/drivers/infiniband/hw/ipath/ipath_rc.c
42165 @@ -1868,7 +1868,7 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
42166 struct ib_atomic_eth *ateth;
42167 struct ipath_ack_entry *e;
42168 u64 vaddr;
42169 - atomic64_t *maddr;
42170 + atomic64_unchecked_t *maddr;
42171 u64 sdata;
42172 u32 rkey;
42173 u8 next;
42174 @@ -1903,11 +1903,11 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
42175 IB_ACCESS_REMOTE_ATOMIC)))
42176 goto nack_acc_unlck;
42177 /* Perform atomic OP and save result. */
42178 - maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
42179 + maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
42180 sdata = be64_to_cpu(ateth->swap_data);
42181 e = &qp->s_ack_queue[qp->r_head_ack_queue];
42182 e->atomic_data = (opcode == OP(FETCH_ADD)) ?
42183 - (u64) atomic64_add_return(sdata, maddr) - sdata :
42184 + (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
42185 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
42186 be64_to_cpu(ateth->compare_data),
42187 sdata);
42188 diff --git a/drivers/infiniband/hw/ipath/ipath_ruc.c b/drivers/infiniband/hw/ipath/ipath_ruc.c
42189 index 1f95bba..9530f87 100644
42190 --- a/drivers/infiniband/hw/ipath/ipath_ruc.c
42191 +++ b/drivers/infiniband/hw/ipath/ipath_ruc.c
42192 @@ -266,7 +266,7 @@ static void ipath_ruc_loopback(struct ipath_qp *sqp)
42193 unsigned long flags;
42194 struct ib_wc wc;
42195 u64 sdata;
42196 - atomic64_t *maddr;
42197 + atomic64_unchecked_t *maddr;
42198 enum ib_wc_status send_status;
42199
42200 /*
42201 @@ -382,11 +382,11 @@ again:
42202 IB_ACCESS_REMOTE_ATOMIC)))
42203 goto acc_err;
42204 /* Perform atomic OP and save result. */
42205 - maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
42206 + maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
42207 sdata = wqe->wr.wr.atomic.compare_add;
42208 *(u64 *) sqp->s_sge.sge.vaddr =
42209 (wqe->wr.opcode == IB_WR_ATOMIC_FETCH_AND_ADD) ?
42210 - (u64) atomic64_add_return(sdata, maddr) - sdata :
42211 + (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
42212 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
42213 sdata, wqe->wr.wr.atomic.swap);
42214 goto send_comp;
42215 diff --git a/drivers/infiniband/hw/mlx4/mad.c b/drivers/infiniband/hw/mlx4/mad.c
42216 index f2a3f48..673ec79 100644
42217 --- a/drivers/infiniband/hw/mlx4/mad.c
42218 +++ b/drivers/infiniband/hw/mlx4/mad.c
42219 @@ -98,7 +98,7 @@ __be64 mlx4_ib_gen_node_guid(void)
42220
42221 __be64 mlx4_ib_get_new_demux_tid(struct mlx4_ib_demux_ctx *ctx)
42222 {
42223 - return cpu_to_be64(atomic_inc_return(&ctx->tid)) |
42224 + return cpu_to_be64(atomic_inc_return_unchecked(&ctx->tid)) |
42225 cpu_to_be64(0xff00000000000000LL);
42226 }
42227
42228 diff --git a/drivers/infiniband/hw/mlx4/mcg.c b/drivers/infiniband/hw/mlx4/mcg.c
42229 index 25b2cdf..099ff97 100644
42230 --- a/drivers/infiniband/hw/mlx4/mcg.c
42231 +++ b/drivers/infiniband/hw/mlx4/mcg.c
42232 @@ -1040,7 +1040,7 @@ int mlx4_ib_mcg_port_init(struct mlx4_ib_demux_ctx *ctx)
42233 {
42234 char name[20];
42235
42236 - atomic_set(&ctx->tid, 0);
42237 + atomic_set_unchecked(&ctx->tid, 0);
42238 sprintf(name, "mlx4_ib_mcg%d", ctx->port);
42239 ctx->mcg_wq = create_singlethread_workqueue(name);
42240 if (!ctx->mcg_wq)
42241 diff --git a/drivers/infiniband/hw/mlx4/mlx4_ib.h b/drivers/infiniband/hw/mlx4/mlx4_ib.h
42242 index 036b663..c9a8c73 100644
42243 --- a/drivers/infiniband/hw/mlx4/mlx4_ib.h
42244 +++ b/drivers/infiniband/hw/mlx4/mlx4_ib.h
42245 @@ -404,7 +404,7 @@ struct mlx4_ib_demux_ctx {
42246 struct list_head mcg_mgid0_list;
42247 struct workqueue_struct *mcg_wq;
42248 struct mlx4_ib_demux_pv_ctx **tun;
42249 - atomic_t tid;
42250 + atomic_unchecked_t tid;
42251 int flushing; /* flushing the work queue */
42252 };
42253
42254 diff --git a/drivers/infiniband/hw/mthca/mthca_cmd.c b/drivers/infiniband/hw/mthca/mthca_cmd.c
42255 index 9d3e5c1..6f166df 100644
42256 --- a/drivers/infiniband/hw/mthca/mthca_cmd.c
42257 +++ b/drivers/infiniband/hw/mthca/mthca_cmd.c
42258 @@ -772,7 +772,7 @@ static void mthca_setup_cmd_doorbells(struct mthca_dev *dev, u64 base)
42259 mthca_dbg(dev, "Mapped doorbell page for posting FW commands\n");
42260 }
42261
42262 -int mthca_QUERY_FW(struct mthca_dev *dev)
42263 +int __intentional_overflow(-1) mthca_QUERY_FW(struct mthca_dev *dev)
42264 {
42265 struct mthca_mailbox *mailbox;
42266 u32 *outbox;
42267 @@ -1612,7 +1612,7 @@ int mthca_HW2SW_MPT(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
42268 CMD_TIME_CLASS_B);
42269 }
42270
42271 -int mthca_WRITE_MTT(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
42272 +int __intentional_overflow(-1) mthca_WRITE_MTT(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
42273 int num_mtt)
42274 {
42275 return mthca_cmd(dev, mailbox->dma, num_mtt, 0, CMD_WRITE_MTT,
42276 @@ -1634,7 +1634,7 @@ int mthca_MAP_EQ(struct mthca_dev *dev, u64 event_mask, int unmap,
42277 0, CMD_MAP_EQ, CMD_TIME_CLASS_B);
42278 }
42279
42280 -int mthca_SW2HW_EQ(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
42281 +int __intentional_overflow(-1) mthca_SW2HW_EQ(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
42282 int eq_num)
42283 {
42284 return mthca_cmd(dev, mailbox->dma, eq_num, 0, CMD_SW2HW_EQ,
42285 @@ -1857,7 +1857,7 @@ int mthca_CONF_SPECIAL_QP(struct mthca_dev *dev, int type, u32 qpn)
42286 CMD_TIME_CLASS_B);
42287 }
42288
42289 -int mthca_MAD_IFC(struct mthca_dev *dev, int ignore_mkey, int ignore_bkey,
42290 +int __intentional_overflow(-1) mthca_MAD_IFC(struct mthca_dev *dev, int ignore_mkey, int ignore_bkey,
42291 int port, struct ib_wc *in_wc, struct ib_grh *in_grh,
42292 void *in_mad, void *response_mad)
42293 {
42294 diff --git a/drivers/infiniband/hw/mthca/mthca_main.c b/drivers/infiniband/hw/mthca/mthca_main.c
42295 index 87897b9..7e79542 100644
42296 --- a/drivers/infiniband/hw/mthca/mthca_main.c
42297 +++ b/drivers/infiniband/hw/mthca/mthca_main.c
42298 @@ -692,7 +692,7 @@ err_close:
42299 return err;
42300 }
42301
42302 -static int mthca_setup_hca(struct mthca_dev *dev)
42303 +static int __intentional_overflow(-1) mthca_setup_hca(struct mthca_dev *dev)
42304 {
42305 int err;
42306
42307 diff --git a/drivers/infiniband/hw/mthca/mthca_mr.c b/drivers/infiniband/hw/mthca/mthca_mr.c
42308 index ed9a989..6aa5dc2 100644
42309 --- a/drivers/infiniband/hw/mthca/mthca_mr.c
42310 +++ b/drivers/infiniband/hw/mthca/mthca_mr.c
42311 @@ -81,7 +81,7 @@ struct mthca_mpt_entry {
42312 * through the bitmaps)
42313 */
42314
42315 -static u32 mthca_buddy_alloc(struct mthca_buddy *buddy, int order)
42316 +static u32 __intentional_overflow(-1) mthca_buddy_alloc(struct mthca_buddy *buddy, int order)
42317 {
42318 int o;
42319 int m;
42320 @@ -426,7 +426,7 @@ static inline u32 adjust_key(struct mthca_dev *dev, u32 key)
42321 return key;
42322 }
42323
42324 -int mthca_mr_alloc(struct mthca_dev *dev, u32 pd, int buffer_size_shift,
42325 +int __intentional_overflow(-1) mthca_mr_alloc(struct mthca_dev *dev, u32 pd, int buffer_size_shift,
42326 u64 iova, u64 total_size, u32 access, struct mthca_mr *mr)
42327 {
42328 struct mthca_mailbox *mailbox;
42329 @@ -516,7 +516,7 @@ int mthca_mr_alloc_notrans(struct mthca_dev *dev, u32 pd,
42330 return mthca_mr_alloc(dev, pd, 12, 0, ~0ULL, access, mr);
42331 }
42332
42333 -int mthca_mr_alloc_phys(struct mthca_dev *dev, u32 pd,
42334 +int __intentional_overflow(-1) mthca_mr_alloc_phys(struct mthca_dev *dev, u32 pd,
42335 u64 *buffer_list, int buffer_size_shift,
42336 int list_len, u64 iova, u64 total_size,
42337 u32 access, struct mthca_mr *mr)
42338 diff --git a/drivers/infiniband/hw/mthca/mthca_provider.c b/drivers/infiniband/hw/mthca/mthca_provider.c
42339 index 5b71d43..35a9e14 100644
42340 --- a/drivers/infiniband/hw/mthca/mthca_provider.c
42341 +++ b/drivers/infiniband/hw/mthca/mthca_provider.c
42342 @@ -763,7 +763,7 @@ unlock:
42343 return 0;
42344 }
42345
42346 -static int mthca_resize_cq(struct ib_cq *ibcq, int entries, struct ib_udata *udata)
42347 +static int __intentional_overflow(-1) mthca_resize_cq(struct ib_cq *ibcq, int entries, struct ib_udata *udata)
42348 {
42349 struct mthca_dev *dev = to_mdev(ibcq->device);
42350 struct mthca_cq *cq = to_mcq(ibcq);
42351 diff --git a/drivers/infiniband/hw/nes/nes.c b/drivers/infiniband/hw/nes/nes.c
42352 index 4291410..d2ab1fb 100644
42353 --- a/drivers/infiniband/hw/nes/nes.c
42354 +++ b/drivers/infiniband/hw/nes/nes.c
42355 @@ -98,7 +98,7 @@ MODULE_PARM_DESC(limit_maxrdreqsz, "Limit max read request size to 256 Bytes");
42356 LIST_HEAD(nes_adapter_list);
42357 static LIST_HEAD(nes_dev_list);
42358
42359 -atomic_t qps_destroyed;
42360 +atomic_unchecked_t qps_destroyed;
42361
42362 static unsigned int ee_flsh_adapter;
42363 static unsigned int sysfs_nonidx_addr;
42364 @@ -269,7 +269,7 @@ static void nes_cqp_rem_ref_callback(struct nes_device *nesdev, struct nes_cqp_r
42365 struct nes_qp *nesqp = cqp_request->cqp_callback_pointer;
42366 struct nes_adapter *nesadapter = nesdev->nesadapter;
42367
42368 - atomic_inc(&qps_destroyed);
42369 + atomic_inc_unchecked(&qps_destroyed);
42370
42371 /* Free the control structures */
42372
42373 diff --git a/drivers/infiniband/hw/nes/nes.h b/drivers/infiniband/hw/nes/nes.h
42374 index 33cc589..3bd6538 100644
42375 --- a/drivers/infiniband/hw/nes/nes.h
42376 +++ b/drivers/infiniband/hw/nes/nes.h
42377 @@ -177,17 +177,17 @@ extern unsigned int nes_debug_level;
42378 extern unsigned int wqm_quanta;
42379 extern struct list_head nes_adapter_list;
42380
42381 -extern atomic_t cm_connects;
42382 -extern atomic_t cm_accepts;
42383 -extern atomic_t cm_disconnects;
42384 -extern atomic_t cm_closes;
42385 -extern atomic_t cm_connecteds;
42386 -extern atomic_t cm_connect_reqs;
42387 -extern atomic_t cm_rejects;
42388 -extern atomic_t mod_qp_timouts;
42389 -extern atomic_t qps_created;
42390 -extern atomic_t qps_destroyed;
42391 -extern atomic_t sw_qps_destroyed;
42392 +extern atomic_unchecked_t cm_connects;
42393 +extern atomic_unchecked_t cm_accepts;
42394 +extern atomic_unchecked_t cm_disconnects;
42395 +extern atomic_unchecked_t cm_closes;
42396 +extern atomic_unchecked_t cm_connecteds;
42397 +extern atomic_unchecked_t cm_connect_reqs;
42398 +extern atomic_unchecked_t cm_rejects;
42399 +extern atomic_unchecked_t mod_qp_timouts;
42400 +extern atomic_unchecked_t qps_created;
42401 +extern atomic_unchecked_t qps_destroyed;
42402 +extern atomic_unchecked_t sw_qps_destroyed;
42403 extern u32 mh_detected;
42404 extern u32 mh_pauses_sent;
42405 extern u32 cm_packets_sent;
42406 @@ -196,16 +196,16 @@ extern u32 cm_packets_created;
42407 extern u32 cm_packets_received;
42408 extern u32 cm_packets_dropped;
42409 extern u32 cm_packets_retrans;
42410 -extern atomic_t cm_listens_created;
42411 -extern atomic_t cm_listens_destroyed;
42412 +extern atomic_unchecked_t cm_listens_created;
42413 +extern atomic_unchecked_t cm_listens_destroyed;
42414 extern u32 cm_backlog_drops;
42415 -extern atomic_t cm_loopbacks;
42416 -extern atomic_t cm_nodes_created;
42417 -extern atomic_t cm_nodes_destroyed;
42418 -extern atomic_t cm_accel_dropped_pkts;
42419 -extern atomic_t cm_resets_recvd;
42420 -extern atomic_t pau_qps_created;
42421 -extern atomic_t pau_qps_destroyed;
42422 +extern atomic_unchecked_t cm_loopbacks;
42423 +extern atomic_unchecked_t cm_nodes_created;
42424 +extern atomic_unchecked_t cm_nodes_destroyed;
42425 +extern atomic_unchecked_t cm_accel_dropped_pkts;
42426 +extern atomic_unchecked_t cm_resets_recvd;
42427 +extern atomic_unchecked_t pau_qps_created;
42428 +extern atomic_unchecked_t pau_qps_destroyed;
42429
42430 extern u32 int_mod_timer_init;
42431 extern u32 int_mod_cq_depth_256;
42432 diff --git a/drivers/infiniband/hw/nes/nes_cm.c b/drivers/infiniband/hw/nes/nes_cm.c
42433 index 6b29249..461d143 100644
42434 --- a/drivers/infiniband/hw/nes/nes_cm.c
42435 +++ b/drivers/infiniband/hw/nes/nes_cm.c
42436 @@ -68,14 +68,14 @@ u32 cm_packets_dropped;
42437 u32 cm_packets_retrans;
42438 u32 cm_packets_created;
42439 u32 cm_packets_received;
42440 -atomic_t cm_listens_created;
42441 -atomic_t cm_listens_destroyed;
42442 +atomic_unchecked_t cm_listens_created;
42443 +atomic_unchecked_t cm_listens_destroyed;
42444 u32 cm_backlog_drops;
42445 -atomic_t cm_loopbacks;
42446 -atomic_t cm_nodes_created;
42447 -atomic_t cm_nodes_destroyed;
42448 -atomic_t cm_accel_dropped_pkts;
42449 -atomic_t cm_resets_recvd;
42450 +atomic_unchecked_t cm_loopbacks;
42451 +atomic_unchecked_t cm_nodes_created;
42452 +atomic_unchecked_t cm_nodes_destroyed;
42453 +atomic_unchecked_t cm_accel_dropped_pkts;
42454 +atomic_unchecked_t cm_resets_recvd;
42455
42456 static inline int mini_cm_accelerated(struct nes_cm_core *, struct nes_cm_node *);
42457 static struct nes_cm_listener *mini_cm_listen(struct nes_cm_core *, struct nes_vnic *, struct nes_cm_info *);
42458 @@ -133,28 +133,28 @@ static void print_core(struct nes_cm_core *core);
42459 /* instance of function pointers for client API */
42460 /* set address of this instance to cm_core->cm_ops at cm_core alloc */
42461 static struct nes_cm_ops nes_cm_api = {
42462 - mini_cm_accelerated,
42463 - mini_cm_listen,
42464 - mini_cm_del_listen,
42465 - mini_cm_connect,
42466 - mini_cm_close,
42467 - mini_cm_accept,
42468 - mini_cm_reject,
42469 - mini_cm_recv_pkt,
42470 - mini_cm_dealloc_core,
42471 - mini_cm_get,
42472 - mini_cm_set
42473 + .accelerated = mini_cm_accelerated,
42474 + .listen = mini_cm_listen,
42475 + .stop_listener = mini_cm_del_listen,
42476 + .connect = mini_cm_connect,
42477 + .close = mini_cm_close,
42478 + .accept = mini_cm_accept,
42479 + .reject = mini_cm_reject,
42480 + .recv_pkt = mini_cm_recv_pkt,
42481 + .destroy_cm_core = mini_cm_dealloc_core,
42482 + .get = mini_cm_get,
42483 + .set = mini_cm_set
42484 };
42485
42486 static struct nes_cm_core *g_cm_core;
42487
42488 -atomic_t cm_connects;
42489 -atomic_t cm_accepts;
42490 -atomic_t cm_disconnects;
42491 -atomic_t cm_closes;
42492 -atomic_t cm_connecteds;
42493 -atomic_t cm_connect_reqs;
42494 -atomic_t cm_rejects;
42495 +atomic_unchecked_t cm_connects;
42496 +atomic_unchecked_t cm_accepts;
42497 +atomic_unchecked_t cm_disconnects;
42498 +atomic_unchecked_t cm_closes;
42499 +atomic_unchecked_t cm_connecteds;
42500 +atomic_unchecked_t cm_connect_reqs;
42501 +atomic_unchecked_t cm_rejects;
42502
42503 int nes_add_ref_cm_node(struct nes_cm_node *cm_node)
42504 {
42505 @@ -1272,7 +1272,7 @@ static int mini_cm_dec_refcnt_listen(struct nes_cm_core *cm_core,
42506 kfree(listener);
42507 listener = NULL;
42508 ret = 0;
42509 - atomic_inc(&cm_listens_destroyed);
42510 + atomic_inc_unchecked(&cm_listens_destroyed);
42511 } else {
42512 spin_unlock_irqrestore(&cm_core->listen_list_lock, flags);
42513 }
42514 @@ -1466,7 +1466,7 @@ static struct nes_cm_node *make_cm_node(struct nes_cm_core *cm_core,
42515 cm_node->rem_mac);
42516
42517 add_hte_node(cm_core, cm_node);
42518 - atomic_inc(&cm_nodes_created);
42519 + atomic_inc_unchecked(&cm_nodes_created);
42520
42521 return cm_node;
42522 }
42523 @@ -1524,7 +1524,7 @@ static int rem_ref_cm_node(struct nes_cm_core *cm_core,
42524 }
42525
42526 atomic_dec(&cm_core->node_cnt);
42527 - atomic_inc(&cm_nodes_destroyed);
42528 + atomic_inc_unchecked(&cm_nodes_destroyed);
42529 nesqp = cm_node->nesqp;
42530 if (nesqp) {
42531 nesqp->cm_node = NULL;
42532 @@ -1588,7 +1588,7 @@ static int process_options(struct nes_cm_node *cm_node, u8 *optionsloc,
42533
42534 static void drop_packet(struct sk_buff *skb)
42535 {
42536 - atomic_inc(&cm_accel_dropped_pkts);
42537 + atomic_inc_unchecked(&cm_accel_dropped_pkts);
42538 dev_kfree_skb_any(skb);
42539 }
42540
42541 @@ -1651,7 +1651,7 @@ static void handle_rst_pkt(struct nes_cm_node *cm_node, struct sk_buff *skb,
42542 {
42543
42544 int reset = 0; /* whether to send reset in case of err.. */
42545 - atomic_inc(&cm_resets_recvd);
42546 + atomic_inc_unchecked(&cm_resets_recvd);
42547 nes_debug(NES_DBG_CM, "Received Reset, cm_node = %p, state = %u."
42548 " refcnt=%d\n", cm_node, cm_node->state,
42549 atomic_read(&cm_node->ref_count));
42550 @@ -2292,7 +2292,7 @@ static struct nes_cm_node *mini_cm_connect(struct nes_cm_core *cm_core,
42551 rem_ref_cm_node(cm_node->cm_core, cm_node);
42552 return NULL;
42553 }
42554 - atomic_inc(&cm_loopbacks);
42555 + atomic_inc_unchecked(&cm_loopbacks);
42556 loopbackremotenode->loopbackpartner = cm_node;
42557 loopbackremotenode->tcp_cntxt.rcv_wscale =
42558 NES_CM_DEFAULT_RCV_WND_SCALE;
42559 @@ -2567,7 +2567,7 @@ static int mini_cm_recv_pkt(struct nes_cm_core *cm_core,
42560 nes_queue_mgt_skbs(skb, nesvnic, cm_node->nesqp);
42561 else {
42562 rem_ref_cm_node(cm_core, cm_node);
42563 - atomic_inc(&cm_accel_dropped_pkts);
42564 + atomic_inc_unchecked(&cm_accel_dropped_pkts);
42565 dev_kfree_skb_any(skb);
42566 }
42567 break;
42568 @@ -2875,7 +2875,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
42569
42570 if ((cm_id) && (cm_id->event_handler)) {
42571 if (issue_disconn) {
42572 - atomic_inc(&cm_disconnects);
42573 + atomic_inc_unchecked(&cm_disconnects);
42574 cm_event.event = IW_CM_EVENT_DISCONNECT;
42575 cm_event.status = disconn_status;
42576 cm_event.local_addr = cm_id->local_addr;
42577 @@ -2897,7 +2897,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
42578 }
42579
42580 if (issue_close) {
42581 - atomic_inc(&cm_closes);
42582 + atomic_inc_unchecked(&cm_closes);
42583 nes_disconnect(nesqp, 1);
42584
42585 cm_id->provider_data = nesqp;
42586 @@ -3035,7 +3035,7 @@ int nes_accept(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
42587
42588 nes_debug(NES_DBG_CM, "QP%u, cm_node=%p, jiffies = %lu listener = %p\n",
42589 nesqp->hwqp.qp_id, cm_node, jiffies, cm_node->listener);
42590 - atomic_inc(&cm_accepts);
42591 + atomic_inc_unchecked(&cm_accepts);
42592
42593 nes_debug(NES_DBG_CM, "netdev refcnt = %u.\n",
42594 netdev_refcnt_read(nesvnic->netdev));
42595 @@ -3224,7 +3224,7 @@ int nes_reject(struct iw_cm_id *cm_id, const void *pdata, u8 pdata_len)
42596 struct nes_cm_core *cm_core;
42597 u8 *start_buff;
42598
42599 - atomic_inc(&cm_rejects);
42600 + atomic_inc_unchecked(&cm_rejects);
42601 cm_node = (struct nes_cm_node *)cm_id->provider_data;
42602 loopback = cm_node->loopbackpartner;
42603 cm_core = cm_node->cm_core;
42604 @@ -3286,7 +3286,7 @@ int nes_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
42605 ntohs(raddr->sin_port), ntohl(laddr->sin_addr.s_addr),
42606 ntohs(laddr->sin_port));
42607
42608 - atomic_inc(&cm_connects);
42609 + atomic_inc_unchecked(&cm_connects);
42610 nesqp->active_conn = 1;
42611
42612 /* cache the cm_id in the qp */
42613 @@ -3398,7 +3398,7 @@ int nes_create_listen(struct iw_cm_id *cm_id, int backlog)
42614 g_cm_core->api->stop_listener(g_cm_core, (void *)cm_node);
42615 return err;
42616 }
42617 - atomic_inc(&cm_listens_created);
42618 + atomic_inc_unchecked(&cm_listens_created);
42619 }
42620
42621 cm_id->add_ref(cm_id);
42622 @@ -3505,7 +3505,7 @@ static void cm_event_connected(struct nes_cm_event *event)
42623
42624 if (nesqp->destroyed)
42625 return;
42626 - atomic_inc(&cm_connecteds);
42627 + atomic_inc_unchecked(&cm_connecteds);
42628 nes_debug(NES_DBG_CM, "QP%u attempting to connect to 0x%08X:0x%04X on"
42629 " local port 0x%04X. jiffies = %lu.\n",
42630 nesqp->hwqp.qp_id, ntohl(raddr->sin_addr.s_addr),
42631 @@ -3686,7 +3686,7 @@ static void cm_event_reset(struct nes_cm_event *event)
42632
42633 cm_id->add_ref(cm_id);
42634 ret = cm_id->event_handler(cm_id, &cm_event);
42635 - atomic_inc(&cm_closes);
42636 + atomic_inc_unchecked(&cm_closes);
42637 cm_event.event = IW_CM_EVENT_CLOSE;
42638 cm_event.status = 0;
42639 cm_event.provider_data = cm_id->provider_data;
42640 @@ -3726,7 +3726,7 @@ static void cm_event_mpa_req(struct nes_cm_event *event)
42641 return;
42642 cm_id = cm_node->cm_id;
42643
42644 - atomic_inc(&cm_connect_reqs);
42645 + atomic_inc_unchecked(&cm_connect_reqs);
42646 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
42647 cm_node, cm_id, jiffies);
42648
42649 @@ -3770,7 +3770,7 @@ static void cm_event_mpa_reject(struct nes_cm_event *event)
42650 return;
42651 cm_id = cm_node->cm_id;
42652
42653 - atomic_inc(&cm_connect_reqs);
42654 + atomic_inc_unchecked(&cm_connect_reqs);
42655 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
42656 cm_node, cm_id, jiffies);
42657
42658 diff --git a/drivers/infiniband/hw/nes/nes_mgt.c b/drivers/infiniband/hw/nes/nes_mgt.c
42659 index 4166452..fc952c3 100644
42660 --- a/drivers/infiniband/hw/nes/nes_mgt.c
42661 +++ b/drivers/infiniband/hw/nes/nes_mgt.c
42662 @@ -40,8 +40,8 @@
42663 #include "nes.h"
42664 #include "nes_mgt.h"
42665
42666 -atomic_t pau_qps_created;
42667 -atomic_t pau_qps_destroyed;
42668 +atomic_unchecked_t pau_qps_created;
42669 +atomic_unchecked_t pau_qps_destroyed;
42670
42671 static void nes_replenish_mgt_rq(struct nes_vnic_mgt *mgtvnic)
42672 {
42673 @@ -621,7 +621,7 @@ void nes_destroy_pau_qp(struct nes_device *nesdev, struct nes_qp *nesqp)
42674 {
42675 struct sk_buff *skb;
42676 unsigned long flags;
42677 - atomic_inc(&pau_qps_destroyed);
42678 + atomic_inc_unchecked(&pau_qps_destroyed);
42679
42680 /* Free packets that have not yet been forwarded */
42681 /* Lock is acquired by skb_dequeue when removing the skb */
42682 @@ -810,7 +810,7 @@ static void nes_mgt_ce_handler(struct nes_device *nesdev, struct nes_hw_nic_cq *
42683 cq->cq_vbase[head].cqe_words[NES_NIC_CQE_HASH_RCVNXT]);
42684 skb_queue_head_init(&nesqp->pau_list);
42685 spin_lock_init(&nesqp->pau_lock);
42686 - atomic_inc(&pau_qps_created);
42687 + atomic_inc_unchecked(&pau_qps_created);
42688 nes_change_quad_hash(nesdev, mgtvnic->nesvnic, nesqp);
42689 }
42690
42691 diff --git a/drivers/infiniband/hw/nes/nes_nic.c b/drivers/infiniband/hw/nes/nes_nic.c
42692 index 49eb511..a774366 100644
42693 --- a/drivers/infiniband/hw/nes/nes_nic.c
42694 +++ b/drivers/infiniband/hw/nes/nes_nic.c
42695 @@ -1273,39 +1273,39 @@ static void nes_netdev_get_ethtool_stats(struct net_device *netdev,
42696 target_stat_values[++index] = mh_detected;
42697 target_stat_values[++index] = mh_pauses_sent;
42698 target_stat_values[++index] = nesvnic->endnode_ipv4_tcp_retransmits;
42699 - target_stat_values[++index] = atomic_read(&cm_connects);
42700 - target_stat_values[++index] = atomic_read(&cm_accepts);
42701 - target_stat_values[++index] = atomic_read(&cm_disconnects);
42702 - target_stat_values[++index] = atomic_read(&cm_connecteds);
42703 - target_stat_values[++index] = atomic_read(&cm_connect_reqs);
42704 - target_stat_values[++index] = atomic_read(&cm_rejects);
42705 - target_stat_values[++index] = atomic_read(&mod_qp_timouts);
42706 - target_stat_values[++index] = atomic_read(&qps_created);
42707 - target_stat_values[++index] = atomic_read(&sw_qps_destroyed);
42708 - target_stat_values[++index] = atomic_read(&qps_destroyed);
42709 - target_stat_values[++index] = atomic_read(&cm_closes);
42710 + target_stat_values[++index] = atomic_read_unchecked(&cm_connects);
42711 + target_stat_values[++index] = atomic_read_unchecked(&cm_accepts);
42712 + target_stat_values[++index] = atomic_read_unchecked(&cm_disconnects);
42713 + target_stat_values[++index] = atomic_read_unchecked(&cm_connecteds);
42714 + target_stat_values[++index] = atomic_read_unchecked(&cm_connect_reqs);
42715 + target_stat_values[++index] = atomic_read_unchecked(&cm_rejects);
42716 + target_stat_values[++index] = atomic_read_unchecked(&mod_qp_timouts);
42717 + target_stat_values[++index] = atomic_read_unchecked(&qps_created);
42718 + target_stat_values[++index] = atomic_read_unchecked(&sw_qps_destroyed);
42719 + target_stat_values[++index] = atomic_read_unchecked(&qps_destroyed);
42720 + target_stat_values[++index] = atomic_read_unchecked(&cm_closes);
42721 target_stat_values[++index] = cm_packets_sent;
42722 target_stat_values[++index] = cm_packets_bounced;
42723 target_stat_values[++index] = cm_packets_created;
42724 target_stat_values[++index] = cm_packets_received;
42725 target_stat_values[++index] = cm_packets_dropped;
42726 target_stat_values[++index] = cm_packets_retrans;
42727 - target_stat_values[++index] = atomic_read(&cm_listens_created);
42728 - target_stat_values[++index] = atomic_read(&cm_listens_destroyed);
42729 + target_stat_values[++index] = atomic_read_unchecked(&cm_listens_created);
42730 + target_stat_values[++index] = atomic_read_unchecked(&cm_listens_destroyed);
42731 target_stat_values[++index] = cm_backlog_drops;
42732 - target_stat_values[++index] = atomic_read(&cm_loopbacks);
42733 - target_stat_values[++index] = atomic_read(&cm_nodes_created);
42734 - target_stat_values[++index] = atomic_read(&cm_nodes_destroyed);
42735 - target_stat_values[++index] = atomic_read(&cm_accel_dropped_pkts);
42736 - target_stat_values[++index] = atomic_read(&cm_resets_recvd);
42737 + target_stat_values[++index] = atomic_read_unchecked(&cm_loopbacks);
42738 + target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_created);
42739 + target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_destroyed);
42740 + target_stat_values[++index] = atomic_read_unchecked(&cm_accel_dropped_pkts);
42741 + target_stat_values[++index] = atomic_read_unchecked(&cm_resets_recvd);
42742 target_stat_values[++index] = nesadapter->free_4kpbl;
42743 target_stat_values[++index] = nesadapter->free_256pbl;
42744 target_stat_values[++index] = int_mod_timer_init;
42745 target_stat_values[++index] = nesvnic->lro_mgr.stats.aggregated;
42746 target_stat_values[++index] = nesvnic->lro_mgr.stats.flushed;
42747 target_stat_values[++index] = nesvnic->lro_mgr.stats.no_desc;
42748 - target_stat_values[++index] = atomic_read(&pau_qps_created);
42749 - target_stat_values[++index] = atomic_read(&pau_qps_destroyed);
42750 + target_stat_values[++index] = atomic_read_unchecked(&pau_qps_created);
42751 + target_stat_values[++index] = atomic_read_unchecked(&pau_qps_destroyed);
42752 }
42753
42754 /**
42755 diff --git a/drivers/infiniband/hw/nes/nes_verbs.c b/drivers/infiniband/hw/nes/nes_verbs.c
42756 index 8308e36..ae0d3b5 100644
42757 --- a/drivers/infiniband/hw/nes/nes_verbs.c
42758 +++ b/drivers/infiniband/hw/nes/nes_verbs.c
42759 @@ -46,9 +46,9 @@
42760
42761 #include <rdma/ib_umem.h>
42762
42763 -atomic_t mod_qp_timouts;
42764 -atomic_t qps_created;
42765 -atomic_t sw_qps_destroyed;
42766 +atomic_unchecked_t mod_qp_timouts;
42767 +atomic_unchecked_t qps_created;
42768 +atomic_unchecked_t sw_qps_destroyed;
42769
42770 static void nes_unregister_ofa_device(struct nes_ib_device *nesibdev);
42771
42772 @@ -1134,7 +1134,7 @@ static struct ib_qp *nes_create_qp(struct ib_pd *ibpd,
42773 if (init_attr->create_flags)
42774 return ERR_PTR(-EINVAL);
42775
42776 - atomic_inc(&qps_created);
42777 + atomic_inc_unchecked(&qps_created);
42778 switch (init_attr->qp_type) {
42779 case IB_QPT_RC:
42780 if (nes_drv_opt & NES_DRV_OPT_NO_INLINE_DATA) {
42781 @@ -1466,7 +1466,7 @@ static int nes_destroy_qp(struct ib_qp *ibqp)
42782 struct iw_cm_event cm_event;
42783 int ret = 0;
42784
42785 - atomic_inc(&sw_qps_destroyed);
42786 + atomic_inc_unchecked(&sw_qps_destroyed);
42787 nesqp->destroyed = 1;
42788
42789 /* Blow away the connection if it exists. */
42790 diff --git a/drivers/infiniband/hw/qib/qib.h b/drivers/infiniband/hw/qib/qib.h
42791 index 1946101..09766d2 100644
42792 --- a/drivers/infiniband/hw/qib/qib.h
42793 +++ b/drivers/infiniband/hw/qib/qib.h
42794 @@ -52,6 +52,7 @@
42795 #include <linux/kref.h>
42796 #include <linux/sched.h>
42797 #include <linux/kthread.h>
42798 +#include <linux/slab.h>
42799
42800 #include "qib_common.h"
42801 #include "qib_verbs.h"
42802 diff --git a/drivers/input/gameport/gameport.c b/drivers/input/gameport/gameport.c
42803 index 24c41ba..102d71f 100644
42804 --- a/drivers/input/gameport/gameport.c
42805 +++ b/drivers/input/gameport/gameport.c
42806 @@ -490,14 +490,14 @@ EXPORT_SYMBOL(gameport_set_phys);
42807 */
42808 static void gameport_init_port(struct gameport *gameport)
42809 {
42810 - static atomic_t gameport_no = ATOMIC_INIT(0);
42811 + static atomic_unchecked_t gameport_no = ATOMIC_INIT(0);
42812
42813 __module_get(THIS_MODULE);
42814
42815 mutex_init(&gameport->drv_mutex);
42816 device_initialize(&gameport->dev);
42817 dev_set_name(&gameport->dev, "gameport%lu",
42818 - (unsigned long)atomic_inc_return(&gameport_no) - 1);
42819 + (unsigned long)atomic_inc_return_unchecked(&gameport_no) - 1);
42820 gameport->dev.bus = &gameport_bus;
42821 gameport->dev.release = gameport_release_port;
42822 if (gameport->parent)
42823 diff --git a/drivers/input/input.c b/drivers/input/input.c
42824 index d2965e4..f52b7d7 100644
42825 --- a/drivers/input/input.c
42826 +++ b/drivers/input/input.c
42827 @@ -1734,7 +1734,7 @@ EXPORT_SYMBOL_GPL(input_class);
42828 */
42829 struct input_dev *input_allocate_device(void)
42830 {
42831 - static atomic_t input_no = ATOMIC_INIT(0);
42832 + static atomic_unchecked_t input_no = ATOMIC_INIT(0);
42833 struct input_dev *dev;
42834
42835 dev = kzalloc(sizeof(struct input_dev), GFP_KERNEL);
42836 @@ -1749,7 +1749,7 @@ struct input_dev *input_allocate_device(void)
42837 INIT_LIST_HEAD(&dev->node);
42838
42839 dev_set_name(&dev->dev, "input%ld",
42840 - (unsigned long) atomic_inc_return(&input_no) - 1);
42841 + (unsigned long) atomic_inc_return_unchecked(&input_no) - 1);
42842
42843 __module_get(THIS_MODULE);
42844 }
42845 diff --git a/drivers/input/joystick/sidewinder.c b/drivers/input/joystick/sidewinder.c
42846 index 04c69af..5f92d00 100644
42847 --- a/drivers/input/joystick/sidewinder.c
42848 +++ b/drivers/input/joystick/sidewinder.c
42849 @@ -30,6 +30,7 @@
42850 #include <linux/kernel.h>
42851 #include <linux/module.h>
42852 #include <linux/slab.h>
42853 +#include <linux/sched.h>
42854 #include <linux/init.h>
42855 #include <linux/input.h>
42856 #include <linux/gameport.h>
42857 diff --git a/drivers/input/joystick/xpad.c b/drivers/input/joystick/xpad.c
42858 index 75e3b10..fb390fd 100644
42859 --- a/drivers/input/joystick/xpad.c
42860 +++ b/drivers/input/joystick/xpad.c
42861 @@ -736,7 +736,7 @@ static void xpad_led_set(struct led_classdev *led_cdev,
42862
42863 static int xpad_led_probe(struct usb_xpad *xpad)
42864 {
42865 - static atomic_t led_seq = ATOMIC_INIT(0);
42866 + static atomic_unchecked_t led_seq = ATOMIC_INIT(0);
42867 long led_no;
42868 struct xpad_led *led;
42869 struct led_classdev *led_cdev;
42870 @@ -749,7 +749,7 @@ static int xpad_led_probe(struct usb_xpad *xpad)
42871 if (!led)
42872 return -ENOMEM;
42873
42874 - led_no = (long)atomic_inc_return(&led_seq) - 1;
42875 + led_no = (long)atomic_inc_return_unchecked(&led_seq) - 1;
42876
42877 snprintf(led->name, sizeof(led->name), "xpad%ld", led_no);
42878 led->xpad = xpad;
42879 diff --git a/drivers/input/misc/ims-pcu.c b/drivers/input/misc/ims-pcu.c
42880 index e204f26..8459f15 100644
42881 --- a/drivers/input/misc/ims-pcu.c
42882 +++ b/drivers/input/misc/ims-pcu.c
42883 @@ -1621,7 +1621,7 @@ static int ims_pcu_identify_type(struct ims_pcu *pcu, u8 *device_id)
42884
42885 static int ims_pcu_init_application_mode(struct ims_pcu *pcu)
42886 {
42887 - static atomic_t device_no = ATOMIC_INIT(0);
42888 + static atomic_unchecked_t device_no = ATOMIC_INIT(0);
42889
42890 const struct ims_pcu_device_info *info;
42891 u8 device_id;
42892 @@ -1653,7 +1653,7 @@ static int ims_pcu_init_application_mode(struct ims_pcu *pcu)
42893 }
42894
42895 /* Device appears to be operable, complete initialization */
42896 - pcu->device_no = atomic_inc_return(&device_no) - 1;
42897 + pcu->device_no = atomic_inc_return_unchecked(&device_no) - 1;
42898
42899 error = ims_pcu_setup_backlight(pcu);
42900 if (error)
42901 diff --git a/drivers/input/mouse/psmouse.h b/drivers/input/mouse/psmouse.h
42902 index 2f0b39d..7370f13 100644
42903 --- a/drivers/input/mouse/psmouse.h
42904 +++ b/drivers/input/mouse/psmouse.h
42905 @@ -116,7 +116,7 @@ struct psmouse_attribute {
42906 ssize_t (*set)(struct psmouse *psmouse, void *data,
42907 const char *buf, size_t count);
42908 bool protect;
42909 -};
42910 +} __do_const;
42911 #define to_psmouse_attr(a) container_of((a), struct psmouse_attribute, dattr)
42912
42913 ssize_t psmouse_attr_show_helper(struct device *dev, struct device_attribute *attr,
42914 diff --git a/drivers/input/mousedev.c b/drivers/input/mousedev.c
42915 index b604564..3f14ae4 100644
42916 --- a/drivers/input/mousedev.c
42917 +++ b/drivers/input/mousedev.c
42918 @@ -744,7 +744,7 @@ static ssize_t mousedev_read(struct file *file, char __user *buffer,
42919
42920 spin_unlock_irq(&client->packet_lock);
42921
42922 - if (copy_to_user(buffer, data, count))
42923 + if (count > sizeof(data) || copy_to_user(buffer, data, count))
42924 return -EFAULT;
42925
42926 return count;
42927 diff --git a/drivers/input/serio/serio.c b/drivers/input/serio/serio.c
42928 index 8f4c4ab..5fc8a45 100644
42929 --- a/drivers/input/serio/serio.c
42930 +++ b/drivers/input/serio/serio.c
42931 @@ -505,7 +505,7 @@ static void serio_release_port(struct device *dev)
42932 */
42933 static void serio_init_port(struct serio *serio)
42934 {
42935 - static atomic_t serio_no = ATOMIC_INIT(0);
42936 + static atomic_unchecked_t serio_no = ATOMIC_INIT(0);
42937
42938 __module_get(THIS_MODULE);
42939
42940 @@ -516,7 +516,7 @@ static void serio_init_port(struct serio *serio)
42941 mutex_init(&serio->drv_mutex);
42942 device_initialize(&serio->dev);
42943 dev_set_name(&serio->dev, "serio%ld",
42944 - (long)atomic_inc_return(&serio_no) - 1);
42945 + (long)atomic_inc_return_unchecked(&serio_no) - 1);
42946 serio->dev.bus = &serio_bus;
42947 serio->dev.release = serio_release_port;
42948 serio->dev.groups = serio_device_attr_groups;
42949 diff --git a/drivers/input/serio/serio_raw.c b/drivers/input/serio/serio_raw.c
42950 index 59df2e7..8f1cafb 100644
42951 --- a/drivers/input/serio/serio_raw.c
42952 +++ b/drivers/input/serio/serio_raw.c
42953 @@ -293,7 +293,7 @@ static irqreturn_t serio_raw_interrupt(struct serio *serio, unsigned char data,
42954
42955 static int serio_raw_connect(struct serio *serio, struct serio_driver *drv)
42956 {
42957 - static atomic_t serio_raw_no = ATOMIC_INIT(0);
42958 + static atomic_unchecked_t serio_raw_no = ATOMIC_INIT(0);
42959 struct serio_raw *serio_raw;
42960 int err;
42961
42962 @@ -304,7 +304,7 @@ static int serio_raw_connect(struct serio *serio, struct serio_driver *drv)
42963 }
42964
42965 snprintf(serio_raw->name, sizeof(serio_raw->name),
42966 - "serio_raw%ld", (long)atomic_inc_return(&serio_raw_no) - 1);
42967 + "serio_raw%ld", (long)atomic_inc_return_unchecked(&serio_raw_no) - 1);
42968 kref_init(&serio_raw->kref);
42969 INIT_LIST_HEAD(&serio_raw->client_list);
42970 init_waitqueue_head(&serio_raw->wait);
42971 diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c
42972 index e5555fc..937986d 100644
42973 --- a/drivers/iommu/iommu.c
42974 +++ b/drivers/iommu/iommu.c
42975 @@ -588,7 +588,7 @@ static struct notifier_block iommu_bus_nb = {
42976 static void iommu_bus_init(struct bus_type *bus, struct iommu_ops *ops)
42977 {
42978 bus_register_notifier(bus, &iommu_bus_nb);
42979 - bus_for_each_dev(bus, NULL, ops, add_iommu_group);
42980 + bus_for_each_dev(bus, NULL, (void *)ops, add_iommu_group);
42981 }
42982
42983 /**
42984 diff --git a/drivers/iommu/irq_remapping.c b/drivers/iommu/irq_remapping.c
42985 index 39f81ae..2660096 100644
42986 --- a/drivers/iommu/irq_remapping.c
42987 +++ b/drivers/iommu/irq_remapping.c
42988 @@ -356,7 +356,7 @@ int setup_hpet_msi_remapped(unsigned int irq, unsigned int id)
42989 void panic_if_irq_remap(const char *msg)
42990 {
42991 if (irq_remapping_enabled)
42992 - panic(msg);
42993 + panic("%s", msg);
42994 }
42995
42996 static void ir_ack_apic_edge(struct irq_data *data)
42997 @@ -377,10 +377,12 @@ static void ir_print_prefix(struct irq_data *data, struct seq_file *p)
42998
42999 void irq_remap_modify_chip_defaults(struct irq_chip *chip)
43000 {
43001 - chip->irq_print_chip = ir_print_prefix;
43002 - chip->irq_ack = ir_ack_apic_edge;
43003 - chip->irq_eoi = ir_ack_apic_level;
43004 - chip->irq_set_affinity = x86_io_apic_ops.set_affinity;
43005 + pax_open_kernel();
43006 + *(void **)&chip->irq_print_chip = ir_print_prefix;
43007 + *(void **)&chip->irq_ack = ir_ack_apic_edge;
43008 + *(void **)&chip->irq_eoi = ir_ack_apic_level;
43009 + *(void **)&chip->irq_set_affinity = x86_io_apic_ops.set_affinity;
43010 + pax_close_kernel();
43011 }
43012
43013 bool setup_remapped_irq(int irq, struct irq_cfg *cfg, struct irq_chip *chip)
43014 diff --git a/drivers/irqchip/irq-gic.c b/drivers/irqchip/irq-gic.c
43015 index 341c601..e5f407e 100644
43016 --- a/drivers/irqchip/irq-gic.c
43017 +++ b/drivers/irqchip/irq-gic.c
43018 @@ -84,7 +84,7 @@ static u8 gic_cpu_map[NR_GIC_CPU_IF] __read_mostly;
43019 * Supported arch specific GIC irq extension.
43020 * Default make them NULL.
43021 */
43022 -struct irq_chip gic_arch_extn = {
43023 +irq_chip_no_const gic_arch_extn = {
43024 .irq_eoi = NULL,
43025 .irq_mask = NULL,
43026 .irq_unmask = NULL,
43027 @@ -332,7 +332,7 @@ static void gic_handle_cascade_irq(unsigned int irq, struct irq_desc *desc)
43028 chained_irq_exit(chip, desc);
43029 }
43030
43031 -static struct irq_chip gic_chip = {
43032 +static irq_chip_no_const gic_chip __read_only = {
43033 .name = "GIC",
43034 .irq_mask = gic_mask_irq,
43035 .irq_unmask = gic_unmask_irq,
43036 diff --git a/drivers/isdn/capi/capi.c b/drivers/isdn/capi/capi.c
43037 index ac6f72b..81150f2 100644
43038 --- a/drivers/isdn/capi/capi.c
43039 +++ b/drivers/isdn/capi/capi.c
43040 @@ -81,8 +81,8 @@ struct capiminor {
43041
43042 struct capi20_appl *ap;
43043 u32 ncci;
43044 - atomic_t datahandle;
43045 - atomic_t msgid;
43046 + atomic_unchecked_t datahandle;
43047 + atomic_unchecked_t msgid;
43048
43049 struct tty_port port;
43050 int ttyinstop;
43051 @@ -391,7 +391,7 @@ gen_data_b3_resp_for(struct capiminor *mp, struct sk_buff *skb)
43052 capimsg_setu16(s, 2, mp->ap->applid);
43053 capimsg_setu8 (s, 4, CAPI_DATA_B3);
43054 capimsg_setu8 (s, 5, CAPI_RESP);
43055 - capimsg_setu16(s, 6, atomic_inc_return(&mp->msgid));
43056 + capimsg_setu16(s, 6, atomic_inc_return_unchecked(&mp->msgid));
43057 capimsg_setu32(s, 8, mp->ncci);
43058 capimsg_setu16(s, 12, datahandle);
43059 }
43060 @@ -512,14 +512,14 @@ static void handle_minor_send(struct capiminor *mp)
43061 mp->outbytes -= len;
43062 spin_unlock_bh(&mp->outlock);
43063
43064 - datahandle = atomic_inc_return(&mp->datahandle);
43065 + datahandle = atomic_inc_return_unchecked(&mp->datahandle);
43066 skb_push(skb, CAPI_DATA_B3_REQ_LEN);
43067 memset(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
43068 capimsg_setu16(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
43069 capimsg_setu16(skb->data, 2, mp->ap->applid);
43070 capimsg_setu8 (skb->data, 4, CAPI_DATA_B3);
43071 capimsg_setu8 (skb->data, 5, CAPI_REQ);
43072 - capimsg_setu16(skb->data, 6, atomic_inc_return(&mp->msgid));
43073 + capimsg_setu16(skb->data, 6, atomic_inc_return_unchecked(&mp->msgid));
43074 capimsg_setu32(skb->data, 8, mp->ncci); /* NCCI */
43075 capimsg_setu32(skb->data, 12, (u32)(long)skb->data);/* Data32 */
43076 capimsg_setu16(skb->data, 16, len); /* Data length */
43077 diff --git a/drivers/isdn/gigaset/bas-gigaset.c b/drivers/isdn/gigaset/bas-gigaset.c
43078 index c44950d..10ac276 100644
43079 --- a/drivers/isdn/gigaset/bas-gigaset.c
43080 +++ b/drivers/isdn/gigaset/bas-gigaset.c
43081 @@ -2564,22 +2564,22 @@ static int gigaset_post_reset(struct usb_interface *intf)
43082
43083
43084 static const struct gigaset_ops gigops = {
43085 - gigaset_write_cmd,
43086 - gigaset_write_room,
43087 - gigaset_chars_in_buffer,
43088 - gigaset_brkchars,
43089 - gigaset_init_bchannel,
43090 - gigaset_close_bchannel,
43091 - gigaset_initbcshw,
43092 - gigaset_freebcshw,
43093 - gigaset_reinitbcshw,
43094 - gigaset_initcshw,
43095 - gigaset_freecshw,
43096 - gigaset_set_modem_ctrl,
43097 - gigaset_baud_rate,
43098 - gigaset_set_line_ctrl,
43099 - gigaset_isoc_send_skb,
43100 - gigaset_isoc_input,
43101 + .write_cmd = gigaset_write_cmd,
43102 + .write_room = gigaset_write_room,
43103 + .chars_in_buffer = gigaset_chars_in_buffer,
43104 + .brkchars = gigaset_brkchars,
43105 + .init_bchannel = gigaset_init_bchannel,
43106 + .close_bchannel = gigaset_close_bchannel,
43107 + .initbcshw = gigaset_initbcshw,
43108 + .freebcshw = gigaset_freebcshw,
43109 + .reinitbcshw = gigaset_reinitbcshw,
43110 + .initcshw = gigaset_initcshw,
43111 + .freecshw = gigaset_freecshw,
43112 + .set_modem_ctrl = gigaset_set_modem_ctrl,
43113 + .baud_rate = gigaset_baud_rate,
43114 + .set_line_ctrl = gigaset_set_line_ctrl,
43115 + .send_skb = gigaset_isoc_send_skb,
43116 + .handle_input = gigaset_isoc_input,
43117 };
43118
43119 /* bas_gigaset_init
43120 diff --git a/drivers/isdn/gigaset/interface.c b/drivers/isdn/gigaset/interface.c
43121 index 600c79b..3752bab 100644
43122 --- a/drivers/isdn/gigaset/interface.c
43123 +++ b/drivers/isdn/gigaset/interface.c
43124 @@ -130,9 +130,9 @@ static int if_open(struct tty_struct *tty, struct file *filp)
43125 }
43126 tty->driver_data = cs;
43127
43128 - ++cs->port.count;
43129 + atomic_inc(&cs->port.count);
43130
43131 - if (cs->port.count == 1) {
43132 + if (atomic_read(&cs->port.count) == 1) {
43133 tty_port_tty_set(&cs->port, tty);
43134 cs->port.low_latency = 1;
43135 }
43136 @@ -156,9 +156,9 @@ static void if_close(struct tty_struct *tty, struct file *filp)
43137
43138 if (!cs->connected)
43139 gig_dbg(DEBUG_IF, "not connected"); /* nothing to do */
43140 - else if (!cs->port.count)
43141 + else if (!atomic_read(&cs->port.count))
43142 dev_warn(cs->dev, "%s: device not opened\n", __func__);
43143 - else if (!--cs->port.count)
43144 + else if (!atomic_dec_return(&cs->port.count))
43145 tty_port_tty_set(&cs->port, NULL);
43146
43147 mutex_unlock(&cs->mutex);
43148 diff --git a/drivers/isdn/gigaset/ser-gigaset.c b/drivers/isdn/gigaset/ser-gigaset.c
43149 index 8c91fd5..14f13ce 100644
43150 --- a/drivers/isdn/gigaset/ser-gigaset.c
43151 +++ b/drivers/isdn/gigaset/ser-gigaset.c
43152 @@ -453,22 +453,22 @@ static int gigaset_set_line_ctrl(struct cardstate *cs, unsigned cflag)
43153 }
43154
43155 static const struct gigaset_ops ops = {
43156 - gigaset_write_cmd,
43157 - gigaset_write_room,
43158 - gigaset_chars_in_buffer,
43159 - gigaset_brkchars,
43160 - gigaset_init_bchannel,
43161 - gigaset_close_bchannel,
43162 - gigaset_initbcshw,
43163 - gigaset_freebcshw,
43164 - gigaset_reinitbcshw,
43165 - gigaset_initcshw,
43166 - gigaset_freecshw,
43167 - gigaset_set_modem_ctrl,
43168 - gigaset_baud_rate,
43169 - gigaset_set_line_ctrl,
43170 - gigaset_m10x_send_skb, /* asyncdata.c */
43171 - gigaset_m10x_input, /* asyncdata.c */
43172 + .write_cmd = gigaset_write_cmd,
43173 + .write_room = gigaset_write_room,
43174 + .chars_in_buffer = gigaset_chars_in_buffer,
43175 + .brkchars = gigaset_brkchars,
43176 + .init_bchannel = gigaset_init_bchannel,
43177 + .close_bchannel = gigaset_close_bchannel,
43178 + .initbcshw = gigaset_initbcshw,
43179 + .freebcshw = gigaset_freebcshw,
43180 + .reinitbcshw = gigaset_reinitbcshw,
43181 + .initcshw = gigaset_initcshw,
43182 + .freecshw = gigaset_freecshw,
43183 + .set_modem_ctrl = gigaset_set_modem_ctrl,
43184 + .baud_rate = gigaset_baud_rate,
43185 + .set_line_ctrl = gigaset_set_line_ctrl,
43186 + .send_skb = gigaset_m10x_send_skb, /* asyncdata.c */
43187 + .handle_input = gigaset_m10x_input, /* asyncdata.c */
43188 };
43189
43190
43191 diff --git a/drivers/isdn/gigaset/usb-gigaset.c b/drivers/isdn/gigaset/usb-gigaset.c
43192 index d0a41cb..b953e50 100644
43193 --- a/drivers/isdn/gigaset/usb-gigaset.c
43194 +++ b/drivers/isdn/gigaset/usb-gigaset.c
43195 @@ -547,7 +547,7 @@ static int gigaset_brkchars(struct cardstate *cs, const unsigned char buf[6])
43196 gigaset_dbg_buffer(DEBUG_USBREQ, "brkchars", 6, buf);
43197 memcpy(cs->hw.usb->bchars, buf, 6);
43198 return usb_control_msg(udev, usb_sndctrlpipe(udev, 0), 0x19, 0x41,
43199 - 0, 0, &buf, 6, 2000);
43200 + 0, 0, buf, 6, 2000);
43201 }
43202
43203 static void gigaset_freebcshw(struct bc_state *bcs)
43204 @@ -869,22 +869,22 @@ static int gigaset_pre_reset(struct usb_interface *intf)
43205 }
43206
43207 static const struct gigaset_ops ops = {
43208 - gigaset_write_cmd,
43209 - gigaset_write_room,
43210 - gigaset_chars_in_buffer,
43211 - gigaset_brkchars,
43212 - gigaset_init_bchannel,
43213 - gigaset_close_bchannel,
43214 - gigaset_initbcshw,
43215 - gigaset_freebcshw,
43216 - gigaset_reinitbcshw,
43217 - gigaset_initcshw,
43218 - gigaset_freecshw,
43219 - gigaset_set_modem_ctrl,
43220 - gigaset_baud_rate,
43221 - gigaset_set_line_ctrl,
43222 - gigaset_m10x_send_skb,
43223 - gigaset_m10x_input,
43224 + .write_cmd = gigaset_write_cmd,
43225 + .write_room = gigaset_write_room,
43226 + .chars_in_buffer = gigaset_chars_in_buffer,
43227 + .brkchars = gigaset_brkchars,
43228 + .init_bchannel = gigaset_init_bchannel,
43229 + .close_bchannel = gigaset_close_bchannel,
43230 + .initbcshw = gigaset_initbcshw,
43231 + .freebcshw = gigaset_freebcshw,
43232 + .reinitbcshw = gigaset_reinitbcshw,
43233 + .initcshw = gigaset_initcshw,
43234 + .freecshw = gigaset_freecshw,
43235 + .set_modem_ctrl = gigaset_set_modem_ctrl,
43236 + .baud_rate = gigaset_baud_rate,
43237 + .set_line_ctrl = gigaset_set_line_ctrl,
43238 + .send_skb = gigaset_m10x_send_skb,
43239 + .handle_input = gigaset_m10x_input,
43240 };
43241
43242 /*
43243 diff --git a/drivers/isdn/hardware/avm/b1.c b/drivers/isdn/hardware/avm/b1.c
43244 index 4d9b195..455075c 100644
43245 --- a/drivers/isdn/hardware/avm/b1.c
43246 +++ b/drivers/isdn/hardware/avm/b1.c
43247 @@ -176,7 +176,7 @@ int b1_load_t4file(avmcard *card, capiloaddatapart *t4file)
43248 }
43249 if (left) {
43250 if (t4file->user) {
43251 - if (copy_from_user(buf, dp, left))
43252 + if (left > sizeof buf || copy_from_user(buf, dp, left))
43253 return -EFAULT;
43254 } else {
43255 memcpy(buf, dp, left);
43256 @@ -224,7 +224,7 @@ int b1_load_config(avmcard *card, capiloaddatapart *config)
43257 }
43258 if (left) {
43259 if (config->user) {
43260 - if (copy_from_user(buf, dp, left))
43261 + if (left > sizeof buf || copy_from_user(buf, dp, left))
43262 return -EFAULT;
43263 } else {
43264 memcpy(buf, dp, left);
43265 diff --git a/drivers/isdn/i4l/isdn_common.c b/drivers/isdn/i4l/isdn_common.c
43266 index 9bb12ba..d4262f7 100644
43267 --- a/drivers/isdn/i4l/isdn_common.c
43268 +++ b/drivers/isdn/i4l/isdn_common.c
43269 @@ -1651,6 +1651,8 @@ isdn_ioctl(struct file *file, uint cmd, ulong arg)
43270 } else
43271 return -EINVAL;
43272 case IIOCDBGVAR:
43273 + if (!capable(CAP_SYS_RAWIO))
43274 + return -EPERM;
43275 if (arg) {
43276 if (copy_to_user(argp, &dev, sizeof(ulong)))
43277 return -EFAULT;
43278 diff --git a/drivers/isdn/i4l/isdn_concap.c b/drivers/isdn/i4l/isdn_concap.c
43279 index 91d5730..336523e 100644
43280 --- a/drivers/isdn/i4l/isdn_concap.c
43281 +++ b/drivers/isdn/i4l/isdn_concap.c
43282 @@ -80,9 +80,9 @@ static int isdn_concap_dl_disconn_req(struct concap_proto *concap)
43283 }
43284
43285 struct concap_device_ops isdn_concap_reliable_dl_dops = {
43286 - &isdn_concap_dl_data_req,
43287 - &isdn_concap_dl_connect_req,
43288 - &isdn_concap_dl_disconn_req
43289 + .data_req = &isdn_concap_dl_data_req,
43290 + .connect_req = &isdn_concap_dl_connect_req,
43291 + .disconn_req = &isdn_concap_dl_disconn_req
43292 };
43293
43294 /* The following should better go into a dedicated source file such that
43295 diff --git a/drivers/isdn/i4l/isdn_tty.c b/drivers/isdn/i4l/isdn_tty.c
43296 index 3c5f249..5fac4d0 100644
43297 --- a/drivers/isdn/i4l/isdn_tty.c
43298 +++ b/drivers/isdn/i4l/isdn_tty.c
43299 @@ -1508,9 +1508,9 @@ isdn_tty_open(struct tty_struct *tty, struct file *filp)
43300
43301 #ifdef ISDN_DEBUG_MODEM_OPEN
43302 printk(KERN_DEBUG "isdn_tty_open %s, count = %d\n", tty->name,
43303 - port->count);
43304 + atomic_read(&port->count));
43305 #endif
43306 - port->count++;
43307 + atomic_inc(&port->count);
43308 port->tty = tty;
43309 /*
43310 * Start up serial port
43311 @@ -1554,7 +1554,7 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
43312 #endif
43313 return;
43314 }
43315 - if ((tty->count == 1) && (port->count != 1)) {
43316 + if ((tty->count == 1) && (atomic_read(&port->count) != 1)) {
43317 /*
43318 * Uh, oh. tty->count is 1, which means that the tty
43319 * structure will be freed. Info->count should always
43320 @@ -1563,15 +1563,15 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
43321 * serial port won't be shutdown.
43322 */
43323 printk(KERN_ERR "isdn_tty_close: bad port count; tty->count is 1, "
43324 - "info->count is %d\n", port->count);
43325 - port->count = 1;
43326 + "info->count is %d\n", atomic_read(&port->count));
43327 + atomic_set(&port->count, 1);
43328 }
43329 - if (--port->count < 0) {
43330 + if (atomic_dec_return(&port->count) < 0) {
43331 printk(KERN_ERR "isdn_tty_close: bad port count for ttyi%d: %d\n",
43332 - info->line, port->count);
43333 - port->count = 0;
43334 + info->line, atomic_read(&port->count));
43335 + atomic_set(&port->count, 0);
43336 }
43337 - if (port->count) {
43338 + if (atomic_read(&port->count)) {
43339 #ifdef ISDN_DEBUG_MODEM_OPEN
43340 printk(KERN_DEBUG "isdn_tty_close after info->count != 0\n");
43341 #endif
43342 @@ -1625,7 +1625,7 @@ isdn_tty_hangup(struct tty_struct *tty)
43343 if (isdn_tty_paranoia_check(info, tty->name, "isdn_tty_hangup"))
43344 return;
43345 isdn_tty_shutdown(info);
43346 - port->count = 0;
43347 + atomic_set(&port->count, 0);
43348 port->flags &= ~ASYNC_NORMAL_ACTIVE;
43349 port->tty = NULL;
43350 wake_up_interruptible(&port->open_wait);
43351 @@ -1970,7 +1970,7 @@ isdn_tty_find_icall(int di, int ch, setup_parm *setup)
43352 for (i = 0; i < ISDN_MAX_CHANNELS; i++) {
43353 modem_info *info = &dev->mdm.info[i];
43354
43355 - if (info->port.count == 0)
43356 + if (atomic_read(&info->port.count) == 0)
43357 continue;
43358 if ((info->emu.mdmreg[REG_SI1] & si2bit[si1]) && /* SI1 is matching */
43359 (info->emu.mdmreg[REG_SI2] == si2)) { /* SI2 is matching */
43360 diff --git a/drivers/isdn/i4l/isdn_x25iface.c b/drivers/isdn/i4l/isdn_x25iface.c
43361 index e2d4e58..40cd045 100644
43362 --- a/drivers/isdn/i4l/isdn_x25iface.c
43363 +++ b/drivers/isdn/i4l/isdn_x25iface.c
43364 @@ -53,14 +53,14 @@ static int isdn_x25iface_disconn_ind(struct concap_proto *);
43365
43366
43367 static struct concap_proto_ops ix25_pops = {
43368 - &isdn_x25iface_proto_new,
43369 - &isdn_x25iface_proto_del,
43370 - &isdn_x25iface_proto_restart,
43371 - &isdn_x25iface_proto_close,
43372 - &isdn_x25iface_xmit,
43373 - &isdn_x25iface_receive,
43374 - &isdn_x25iface_connect_ind,
43375 - &isdn_x25iface_disconn_ind
43376 + .proto_new = &isdn_x25iface_proto_new,
43377 + .proto_del = &isdn_x25iface_proto_del,
43378 + .restart = &isdn_x25iface_proto_restart,
43379 + .close = &isdn_x25iface_proto_close,
43380 + .encap_and_xmit = &isdn_x25iface_xmit,
43381 + .data_ind = &isdn_x25iface_receive,
43382 + .connect_ind = &isdn_x25iface_connect_ind,
43383 + .disconn_ind = &isdn_x25iface_disconn_ind
43384 };
43385
43386 /* error message helper function */
43387 diff --git a/drivers/isdn/icn/icn.c b/drivers/isdn/icn/icn.c
43388 index 53d487f..f020f41 100644
43389 --- a/drivers/isdn/icn/icn.c
43390 +++ b/drivers/isdn/icn/icn.c
43391 @@ -1045,7 +1045,7 @@ icn_writecmd(const u_char *buf, int len, int user, icn_card *card)
43392 if (count > len)
43393 count = len;
43394 if (user) {
43395 - if (copy_from_user(msg, buf, count))
43396 + if (count > sizeof msg || copy_from_user(msg, buf, count))
43397 return -EFAULT;
43398 } else
43399 memcpy(msg, buf, count);
43400 diff --git a/drivers/isdn/mISDN/dsp_cmx.c b/drivers/isdn/mISDN/dsp_cmx.c
43401 index a4f05c5..1433bc5 100644
43402 --- a/drivers/isdn/mISDN/dsp_cmx.c
43403 +++ b/drivers/isdn/mISDN/dsp_cmx.c
43404 @@ -1628,7 +1628,7 @@ unsigned long dsp_spl_jiffies; /* calculate the next time to fire */
43405 static u16 dsp_count; /* last sample count */
43406 static int dsp_count_valid; /* if we have last sample count */
43407
43408 -void
43409 +void __intentional_overflow(-1)
43410 dsp_cmx_send(void *arg)
43411 {
43412 struct dsp_conf *conf;
43413 diff --git a/drivers/leds/leds-clevo-mail.c b/drivers/leds/leds-clevo-mail.c
43414 index d93e245..e7ece6b 100644
43415 --- a/drivers/leds/leds-clevo-mail.c
43416 +++ b/drivers/leds/leds-clevo-mail.c
43417 @@ -40,7 +40,7 @@ static int __init clevo_mail_led_dmi_callback(const struct dmi_system_id *id)
43418 * detected as working, but in reality it is not) as low as
43419 * possible.
43420 */
43421 -static struct dmi_system_id clevo_mail_led_dmi_table[] __initdata = {
43422 +static struct dmi_system_id clevo_mail_led_dmi_table[] __initconst = {
43423 {
43424 .callback = clevo_mail_led_dmi_callback,
43425 .ident = "Clevo D410J",
43426 diff --git a/drivers/leds/leds-ss4200.c b/drivers/leds/leds-ss4200.c
43427 index 5b8f938..b73d657 100644
43428 --- a/drivers/leds/leds-ss4200.c
43429 +++ b/drivers/leds/leds-ss4200.c
43430 @@ -91,7 +91,7 @@ MODULE_PARM_DESC(nodetect, "Skip DMI-based hardware detection");
43431 * detected as working, but in reality it is not) as low as
43432 * possible.
43433 */
43434 -static struct dmi_system_id nas_led_whitelist[] __initdata = {
43435 +static struct dmi_system_id nas_led_whitelist[] __initconst = {
43436 {
43437 .callback = ss4200_led_dmi_callback,
43438 .ident = "Intel SS4200-E",
43439 diff --git a/drivers/lguest/core.c b/drivers/lguest/core.c
43440 index 0bf1e4e..b4bf44e 100644
43441 --- a/drivers/lguest/core.c
43442 +++ b/drivers/lguest/core.c
43443 @@ -97,9 +97,17 @@ static __init int map_switcher(void)
43444 * The end address needs +1 because __get_vm_area allocates an
43445 * extra guard page, so we need space for that.
43446 */
43447 +
43448 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
43449 + switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
43450 + VM_ALLOC | VM_KERNEXEC, switcher_addr, switcher_addr
43451 + + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
43452 +#else
43453 switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
43454 VM_ALLOC, switcher_addr, switcher_addr
43455 + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
43456 +#endif
43457 +
43458 if (!switcher_vma) {
43459 err = -ENOMEM;
43460 printk("lguest: could not map switcher pages high\n");
43461 @@ -124,7 +132,7 @@ static __init int map_switcher(void)
43462 * Now the Switcher is mapped at the right address, we can't fail!
43463 * Copy in the compiled-in Switcher code (from x86/switcher_32.S).
43464 */
43465 - memcpy(switcher_vma->addr, start_switcher_text,
43466 + memcpy(switcher_vma->addr, ktla_ktva(start_switcher_text),
43467 end_switcher_text - start_switcher_text);
43468
43469 printk(KERN_INFO "lguest: mapped switcher at %p\n",
43470 diff --git a/drivers/lguest/page_tables.c b/drivers/lguest/page_tables.c
43471 index bfb39bb..08a603b 100644
43472 --- a/drivers/lguest/page_tables.c
43473 +++ b/drivers/lguest/page_tables.c
43474 @@ -559,7 +559,7 @@ void pin_page(struct lg_cpu *cpu, unsigned long vaddr)
43475 /*:*/
43476
43477 #ifdef CONFIG_X86_PAE
43478 -static void release_pmd(pmd_t *spmd)
43479 +static void __intentional_overflow(-1) release_pmd(pmd_t *spmd)
43480 {
43481 /* If the entry's not present, there's nothing to release. */
43482 if (pmd_flags(*spmd) & _PAGE_PRESENT) {
43483 diff --git a/drivers/lguest/x86/core.c b/drivers/lguest/x86/core.c
43484 index 922a1ac..9dd0c2a 100644
43485 --- a/drivers/lguest/x86/core.c
43486 +++ b/drivers/lguest/x86/core.c
43487 @@ -59,7 +59,7 @@ static struct {
43488 /* Offset from where switcher.S was compiled to where we've copied it */
43489 static unsigned long switcher_offset(void)
43490 {
43491 - return switcher_addr - (unsigned long)start_switcher_text;
43492 + return switcher_addr - (unsigned long)ktla_ktva(start_switcher_text);
43493 }
43494
43495 /* This cpu's struct lguest_pages (after the Switcher text page) */
43496 @@ -99,7 +99,13 @@ static void copy_in_guest_info(struct lg_cpu *cpu, struct lguest_pages *pages)
43497 * These copies are pretty cheap, so we do them unconditionally: */
43498 /* Save the current Host top-level page directory.
43499 */
43500 +
43501 +#ifdef CONFIG_PAX_PER_CPU_PGD
43502 + pages->state.host_cr3 = read_cr3();
43503 +#else
43504 pages->state.host_cr3 = __pa(current->mm->pgd);
43505 +#endif
43506 +
43507 /*
43508 * Set up the Guest's page tables to see this CPU's pages (and no
43509 * other CPU's pages).
43510 @@ -477,7 +483,7 @@ void __init lguest_arch_host_init(void)
43511 * compiled-in switcher code and the high-mapped copy we just made.
43512 */
43513 for (i = 0; i < IDT_ENTRIES; i++)
43514 - default_idt_entries[i] += switcher_offset();
43515 + default_idt_entries[i] = ktla_ktva(default_idt_entries[i]) + switcher_offset();
43516
43517 /*
43518 * Set up the Switcher's per-cpu areas.
43519 @@ -560,7 +566,7 @@ void __init lguest_arch_host_init(void)
43520 * it will be undisturbed when we switch. To change %cs and jump we
43521 * need this structure to feed to Intel's "lcall" instruction.
43522 */
43523 - lguest_entry.offset = (long)switch_to_guest + switcher_offset();
43524 + lguest_entry.offset = (long)ktla_ktva(switch_to_guest) + switcher_offset();
43525 lguest_entry.segment = LGUEST_CS;
43526
43527 /*
43528 diff --git a/drivers/lguest/x86/switcher_32.S b/drivers/lguest/x86/switcher_32.S
43529 index 40634b0..4f5855e 100644
43530 --- a/drivers/lguest/x86/switcher_32.S
43531 +++ b/drivers/lguest/x86/switcher_32.S
43532 @@ -87,6 +87,7 @@
43533 #include <asm/page.h>
43534 #include <asm/segment.h>
43535 #include <asm/lguest.h>
43536 +#include <asm/processor-flags.h>
43537
43538 // We mark the start of the code to copy
43539 // It's placed in .text tho it's never run here
43540 @@ -149,6 +150,13 @@ ENTRY(switch_to_guest)
43541 // Changes type when we load it: damn Intel!
43542 // For after we switch over our page tables
43543 // That entry will be read-only: we'd crash.
43544 +
43545 +#ifdef CONFIG_PAX_KERNEXEC
43546 + mov %cr0, %edx
43547 + xor $X86_CR0_WP, %edx
43548 + mov %edx, %cr0
43549 +#endif
43550 +
43551 movl $(GDT_ENTRY_TSS*8), %edx
43552 ltr %dx
43553
43554 @@ -157,9 +165,15 @@ ENTRY(switch_to_guest)
43555 // Let's clear it again for our return.
43556 // The GDT descriptor of the Host
43557 // Points to the table after two "size" bytes
43558 - movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %edx
43559 + movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %eax
43560 // Clear "used" from type field (byte 5, bit 2)
43561 - andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%edx)
43562 + andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%eax)
43563 +
43564 +#ifdef CONFIG_PAX_KERNEXEC
43565 + mov %cr0, %eax
43566 + xor $X86_CR0_WP, %eax
43567 + mov %eax, %cr0
43568 +#endif
43569
43570 // Once our page table's switched, the Guest is live!
43571 // The Host fades as we run this final step.
43572 @@ -295,13 +309,12 @@ deliver_to_host:
43573 // I consulted gcc, and it gave
43574 // These instructions, which I gladly credit:
43575 leal (%edx,%ebx,8), %eax
43576 - movzwl (%eax),%edx
43577 - movl 4(%eax), %eax
43578 - xorw %ax, %ax
43579 - orl %eax, %edx
43580 + movl 4(%eax), %edx
43581 + movw (%eax), %dx
43582 // Now the address of the handler's in %edx
43583 // We call it now: its "iret" drops us home.
43584 - jmp *%edx
43585 + ljmp $__KERNEL_CS, $1f
43586 +1: jmp *%edx
43587
43588 // Every interrupt can come to us here
43589 // But we must truly tell each apart.
43590 diff --git a/drivers/md/bcache/closure.h b/drivers/md/bcache/closure.h
43591 index 9762f1b..3e79734 100644
43592 --- a/drivers/md/bcache/closure.h
43593 +++ b/drivers/md/bcache/closure.h
43594 @@ -483,7 +483,7 @@ static inline void closure_queue(struct closure *cl)
43595 static inline void set_closure_fn(struct closure *cl, closure_fn *fn,
43596 struct workqueue_struct *wq)
43597 {
43598 - BUG_ON(object_is_on_stack(cl));
43599 + BUG_ON(object_starts_on_stack(cl));
43600 closure_set_ip(cl);
43601 cl->fn = fn;
43602 cl->wq = wq;
43603 diff --git a/drivers/md/bitmap.c b/drivers/md/bitmap.c
43604 index 12dc29b..1596277 100644
43605 --- a/drivers/md/bitmap.c
43606 +++ b/drivers/md/bitmap.c
43607 @@ -1779,7 +1779,7 @@ void bitmap_status(struct seq_file *seq, struct bitmap *bitmap)
43608 chunk_kb ? "KB" : "B");
43609 if (bitmap->storage.file) {
43610 seq_printf(seq, ", file: ");
43611 - seq_path(seq, &bitmap->storage.file->f_path, " \t\n");
43612 + seq_path(seq, &bitmap->storage.file->f_path, " \t\n\\");
43613 }
43614
43615 seq_printf(seq, "\n");
43616 diff --git a/drivers/md/dm-ioctl.c b/drivers/md/dm-ioctl.c
43617 index 5152142..623d141 100644
43618 --- a/drivers/md/dm-ioctl.c
43619 +++ b/drivers/md/dm-ioctl.c
43620 @@ -1769,7 +1769,7 @@ static int validate_params(uint cmd, struct dm_ioctl *param)
43621 cmd == DM_LIST_VERSIONS_CMD)
43622 return 0;
43623
43624 - if ((cmd == DM_DEV_CREATE_CMD)) {
43625 + if (cmd == DM_DEV_CREATE_CMD) {
43626 if (!*param->name) {
43627 DMWARN("name not supplied when creating device");
43628 return -EINVAL;
43629 diff --git a/drivers/md/dm-raid1.c b/drivers/md/dm-raid1.c
43630 index 9584443..9fc9ac9 100644
43631 --- a/drivers/md/dm-raid1.c
43632 +++ b/drivers/md/dm-raid1.c
43633 @@ -40,7 +40,7 @@ enum dm_raid1_error {
43634
43635 struct mirror {
43636 struct mirror_set *ms;
43637 - atomic_t error_count;
43638 + atomic_unchecked_t error_count;
43639 unsigned long error_type;
43640 struct dm_dev *dev;
43641 sector_t offset;
43642 @@ -186,7 +186,7 @@ static struct mirror *get_valid_mirror(struct mirror_set *ms)
43643 struct mirror *m;
43644
43645 for (m = ms->mirror; m < ms->mirror + ms->nr_mirrors; m++)
43646 - if (!atomic_read(&m->error_count))
43647 + if (!atomic_read_unchecked(&m->error_count))
43648 return m;
43649
43650 return NULL;
43651 @@ -218,7 +218,7 @@ static void fail_mirror(struct mirror *m, enum dm_raid1_error error_type)
43652 * simple way to tell if a device has encountered
43653 * errors.
43654 */
43655 - atomic_inc(&m->error_count);
43656 + atomic_inc_unchecked(&m->error_count);
43657
43658 if (test_and_set_bit(error_type, &m->error_type))
43659 return;
43660 @@ -409,7 +409,7 @@ static struct mirror *choose_mirror(struct mirror_set *ms, sector_t sector)
43661 struct mirror *m = get_default_mirror(ms);
43662
43663 do {
43664 - if (likely(!atomic_read(&m->error_count)))
43665 + if (likely(!atomic_read_unchecked(&m->error_count)))
43666 return m;
43667
43668 if (m-- == ms->mirror)
43669 @@ -423,7 +423,7 @@ static int default_ok(struct mirror *m)
43670 {
43671 struct mirror *default_mirror = get_default_mirror(m->ms);
43672
43673 - return !atomic_read(&default_mirror->error_count);
43674 + return !atomic_read_unchecked(&default_mirror->error_count);
43675 }
43676
43677 static int mirror_available(struct mirror_set *ms, struct bio *bio)
43678 @@ -560,7 +560,7 @@ static void do_reads(struct mirror_set *ms, struct bio_list *reads)
43679 */
43680 if (likely(region_in_sync(ms, region, 1)))
43681 m = choose_mirror(ms, bio->bi_sector);
43682 - else if (m && atomic_read(&m->error_count))
43683 + else if (m && atomic_read_unchecked(&m->error_count))
43684 m = NULL;
43685
43686 if (likely(m))
43687 @@ -927,7 +927,7 @@ static int get_mirror(struct mirror_set *ms, struct dm_target *ti,
43688 }
43689
43690 ms->mirror[mirror].ms = ms;
43691 - atomic_set(&(ms->mirror[mirror].error_count), 0);
43692 + atomic_set_unchecked(&(ms->mirror[mirror].error_count), 0);
43693 ms->mirror[mirror].error_type = 0;
43694 ms->mirror[mirror].offset = offset;
43695
43696 @@ -1339,7 +1339,7 @@ static void mirror_resume(struct dm_target *ti)
43697 */
43698 static char device_status_char(struct mirror *m)
43699 {
43700 - if (!atomic_read(&(m->error_count)))
43701 + if (!atomic_read_unchecked(&(m->error_count)))
43702 return 'A';
43703
43704 return (test_bit(DM_RAID1_FLUSH_ERROR, &(m->error_type))) ? 'F' :
43705 diff --git a/drivers/md/dm-stats.c b/drivers/md/dm-stats.c
43706 index 28a9012..9c0f6a5 100644
43707 --- a/drivers/md/dm-stats.c
43708 +++ b/drivers/md/dm-stats.c
43709 @@ -382,7 +382,7 @@ do_sync_free:
43710 synchronize_rcu_expedited();
43711 dm_stat_free(&s->rcu_head);
43712 } else {
43713 - ACCESS_ONCE(dm_stat_need_rcu_barrier) = 1;
43714 + ACCESS_ONCE_RW(dm_stat_need_rcu_barrier) = 1;
43715 call_rcu(&s->rcu_head, dm_stat_free);
43716 }
43717 return 0;
43718 @@ -554,8 +554,8 @@ void dm_stats_account_io(struct dm_stats *stats, unsigned long bi_rw,
43719 ((bi_rw & (REQ_WRITE | REQ_DISCARD)) ==
43720 (ACCESS_ONCE(last->last_rw) & (REQ_WRITE | REQ_DISCARD)))
43721 ));
43722 - ACCESS_ONCE(last->last_sector) = end_sector;
43723 - ACCESS_ONCE(last->last_rw) = bi_rw;
43724 + ACCESS_ONCE_RW(last->last_sector) = end_sector;
43725 + ACCESS_ONCE_RW(last->last_rw) = bi_rw;
43726 }
43727
43728 rcu_read_lock();
43729 diff --git a/drivers/md/dm-stripe.c b/drivers/md/dm-stripe.c
43730 index 73c1712..7347292 100644
43731 --- a/drivers/md/dm-stripe.c
43732 +++ b/drivers/md/dm-stripe.c
43733 @@ -21,7 +21,7 @@ struct stripe {
43734 struct dm_dev *dev;
43735 sector_t physical_start;
43736
43737 - atomic_t error_count;
43738 + atomic_unchecked_t error_count;
43739 };
43740
43741 struct stripe_c {
43742 @@ -186,7 +186,7 @@ static int stripe_ctr(struct dm_target *ti, unsigned int argc, char **argv)
43743 kfree(sc);
43744 return r;
43745 }
43746 - atomic_set(&(sc->stripe[i].error_count), 0);
43747 + atomic_set_unchecked(&(sc->stripe[i].error_count), 0);
43748 }
43749
43750 ti->private = sc;
43751 @@ -327,7 +327,7 @@ static void stripe_status(struct dm_target *ti, status_type_t type,
43752 DMEMIT("%d ", sc->stripes);
43753 for (i = 0; i < sc->stripes; i++) {
43754 DMEMIT("%s ", sc->stripe[i].dev->name);
43755 - buffer[i] = atomic_read(&(sc->stripe[i].error_count)) ?
43756 + buffer[i] = atomic_read_unchecked(&(sc->stripe[i].error_count)) ?
43757 'D' : 'A';
43758 }
43759 buffer[i] = '\0';
43760 @@ -372,8 +372,8 @@ static int stripe_end_io(struct dm_target *ti, struct bio *bio, int error)
43761 */
43762 for (i = 0; i < sc->stripes; i++)
43763 if (!strcmp(sc->stripe[i].dev->name, major_minor)) {
43764 - atomic_inc(&(sc->stripe[i].error_count));
43765 - if (atomic_read(&(sc->stripe[i].error_count)) <
43766 + atomic_inc_unchecked(&(sc->stripe[i].error_count));
43767 + if (atomic_read_unchecked(&(sc->stripe[i].error_count)) <
43768 DM_IO_ERROR_THRESHOLD)
43769 schedule_work(&sc->trigger_event);
43770 }
43771 diff --git a/drivers/md/dm-table.c b/drivers/md/dm-table.c
43772 index 3ba6a38..b0fa9b0 100644
43773 --- a/drivers/md/dm-table.c
43774 +++ b/drivers/md/dm-table.c
43775 @@ -291,7 +291,7 @@ static struct dm_dev_internal *find_device(struct list_head *l, dev_t dev)
43776 static int open_dev(struct dm_dev_internal *d, dev_t dev,
43777 struct mapped_device *md)
43778 {
43779 - static char *_claim_ptr = "I belong to device-mapper";
43780 + static char _claim_ptr[] = "I belong to device-mapper";
43781 struct block_device *bdev;
43782
43783 int r;
43784 @@ -359,7 +359,7 @@ static int device_area_is_invalid(struct dm_target *ti, struct dm_dev *dev,
43785 if (!dev_size)
43786 return 0;
43787
43788 - if ((start >= dev_size) || (start + len > dev_size)) {
43789 + if ((start >= dev_size) || (len > dev_size - start)) {
43790 DMWARN("%s: %s too small for target: "
43791 "start=%llu, len=%llu, dev_size=%llu",
43792 dm_device_name(ti->table->md), bdevname(bdev, b),
43793 diff --git a/drivers/md/dm-thin-metadata.c b/drivers/md/dm-thin-metadata.c
43794 index 3bb4506..56e20cc 100644
43795 --- a/drivers/md/dm-thin-metadata.c
43796 +++ b/drivers/md/dm-thin-metadata.c
43797 @@ -397,7 +397,7 @@ static void __setup_btree_details(struct dm_pool_metadata *pmd)
43798 {
43799 pmd->info.tm = pmd->tm;
43800 pmd->info.levels = 2;
43801 - pmd->info.value_type.context = pmd->data_sm;
43802 + pmd->info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
43803 pmd->info.value_type.size = sizeof(__le64);
43804 pmd->info.value_type.inc = data_block_inc;
43805 pmd->info.value_type.dec = data_block_dec;
43806 @@ -416,7 +416,7 @@ static void __setup_btree_details(struct dm_pool_metadata *pmd)
43807
43808 pmd->bl_info.tm = pmd->tm;
43809 pmd->bl_info.levels = 1;
43810 - pmd->bl_info.value_type.context = pmd->data_sm;
43811 + pmd->bl_info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
43812 pmd->bl_info.value_type.size = sizeof(__le64);
43813 pmd->bl_info.value_type.inc = data_block_inc;
43814 pmd->bl_info.value_type.dec = data_block_dec;
43815 diff --git a/drivers/md/dm.c b/drivers/md/dm.c
43816 index b49c762..c9503cf 100644
43817 --- a/drivers/md/dm.c
43818 +++ b/drivers/md/dm.c
43819 @@ -185,9 +185,9 @@ struct mapped_device {
43820 /*
43821 * Event handling.
43822 */
43823 - atomic_t event_nr;
43824 + atomic_unchecked_t event_nr;
43825 wait_queue_head_t eventq;
43826 - atomic_t uevent_seq;
43827 + atomic_unchecked_t uevent_seq;
43828 struct list_head uevent_list;
43829 spinlock_t uevent_lock; /* Protect access to uevent_list */
43830
43831 @@ -2021,8 +2021,8 @@ static struct mapped_device *alloc_dev(int minor)
43832 spin_lock_init(&md->deferred_lock);
43833 atomic_set(&md->holders, 1);
43834 atomic_set(&md->open_count, 0);
43835 - atomic_set(&md->event_nr, 0);
43836 - atomic_set(&md->uevent_seq, 0);
43837 + atomic_set_unchecked(&md->event_nr, 0);
43838 + atomic_set_unchecked(&md->uevent_seq, 0);
43839 INIT_LIST_HEAD(&md->uevent_list);
43840 spin_lock_init(&md->uevent_lock);
43841
43842 @@ -2176,7 +2176,7 @@ static void event_callback(void *context)
43843
43844 dm_send_uevents(&uevents, &disk_to_dev(md->disk)->kobj);
43845
43846 - atomic_inc(&md->event_nr);
43847 + atomic_inc_unchecked(&md->event_nr);
43848 wake_up(&md->eventq);
43849 }
43850
43851 @@ -2869,18 +2869,18 @@ int dm_kobject_uevent(struct mapped_device *md, enum kobject_action action,
43852
43853 uint32_t dm_next_uevent_seq(struct mapped_device *md)
43854 {
43855 - return atomic_add_return(1, &md->uevent_seq);
43856 + return atomic_add_return_unchecked(1, &md->uevent_seq);
43857 }
43858
43859 uint32_t dm_get_event_nr(struct mapped_device *md)
43860 {
43861 - return atomic_read(&md->event_nr);
43862 + return atomic_read_unchecked(&md->event_nr);
43863 }
43864
43865 int dm_wait_event(struct mapped_device *md, int event_nr)
43866 {
43867 return wait_event_interruptible(md->eventq,
43868 - (event_nr != atomic_read(&md->event_nr)));
43869 + (event_nr != atomic_read_unchecked(&md->event_nr)));
43870 }
43871
43872 void dm_uevent_add(struct mapped_device *md, struct list_head *elist)
43873 diff --git a/drivers/md/md.c b/drivers/md/md.c
43874 index 369d919..ba7049c 100644
43875 --- a/drivers/md/md.c
43876 +++ b/drivers/md/md.c
43877 @@ -194,10 +194,10 @@ EXPORT_SYMBOL_GPL(bio_clone_mddev);
43878 * start build, activate spare
43879 */
43880 static DECLARE_WAIT_QUEUE_HEAD(md_event_waiters);
43881 -static atomic_t md_event_count;
43882 +static atomic_unchecked_t md_event_count;
43883 void md_new_event(struct mddev *mddev)
43884 {
43885 - atomic_inc(&md_event_count);
43886 + atomic_inc_unchecked(&md_event_count);
43887 wake_up(&md_event_waiters);
43888 }
43889 EXPORT_SYMBOL_GPL(md_new_event);
43890 @@ -207,7 +207,7 @@ EXPORT_SYMBOL_GPL(md_new_event);
43891 */
43892 static void md_new_event_inintr(struct mddev *mddev)
43893 {
43894 - atomic_inc(&md_event_count);
43895 + atomic_inc_unchecked(&md_event_count);
43896 wake_up(&md_event_waiters);
43897 }
43898
43899 @@ -1463,7 +1463,7 @@ static int super_1_load(struct md_rdev *rdev, struct md_rdev *refdev, int minor_
43900 if ((le32_to_cpu(sb->feature_map) & MD_FEATURE_RESHAPE_ACTIVE) &&
43901 (le32_to_cpu(sb->feature_map) & MD_FEATURE_NEW_OFFSET))
43902 rdev->new_data_offset += (s32)le32_to_cpu(sb->new_offset);
43903 - atomic_set(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
43904 + atomic_set_unchecked(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
43905
43906 rdev->sb_size = le32_to_cpu(sb->max_dev) * 2 + 256;
43907 bmask = queue_logical_block_size(rdev->bdev->bd_disk->queue)-1;
43908 @@ -1710,7 +1710,7 @@ static void super_1_sync(struct mddev *mddev, struct md_rdev *rdev)
43909 else
43910 sb->resync_offset = cpu_to_le64(0);
43911
43912 - sb->cnt_corrected_read = cpu_to_le32(atomic_read(&rdev->corrected_errors));
43913 + sb->cnt_corrected_read = cpu_to_le32(atomic_read_unchecked(&rdev->corrected_errors));
43914
43915 sb->raid_disks = cpu_to_le32(mddev->raid_disks);
43916 sb->size = cpu_to_le64(mddev->dev_sectors);
43917 @@ -2715,7 +2715,7 @@ __ATTR(state, S_IRUGO|S_IWUSR, state_show, state_store);
43918 static ssize_t
43919 errors_show(struct md_rdev *rdev, char *page)
43920 {
43921 - return sprintf(page, "%d\n", atomic_read(&rdev->corrected_errors));
43922 + return sprintf(page, "%d\n", atomic_read_unchecked(&rdev->corrected_errors));
43923 }
43924
43925 static ssize_t
43926 @@ -2724,7 +2724,7 @@ errors_store(struct md_rdev *rdev, const char *buf, size_t len)
43927 char *e;
43928 unsigned long n = simple_strtoul(buf, &e, 10);
43929 if (*buf && (*e == 0 || *e == '\n')) {
43930 - atomic_set(&rdev->corrected_errors, n);
43931 + atomic_set_unchecked(&rdev->corrected_errors, n);
43932 return len;
43933 }
43934 return -EINVAL;
43935 @@ -3173,8 +3173,8 @@ int md_rdev_init(struct md_rdev *rdev)
43936 rdev->sb_loaded = 0;
43937 rdev->bb_page = NULL;
43938 atomic_set(&rdev->nr_pending, 0);
43939 - atomic_set(&rdev->read_errors, 0);
43940 - atomic_set(&rdev->corrected_errors, 0);
43941 + atomic_set_unchecked(&rdev->read_errors, 0);
43942 + atomic_set_unchecked(&rdev->corrected_errors, 0);
43943
43944 INIT_LIST_HEAD(&rdev->same_set);
43945 init_waitqueue_head(&rdev->blocked_wait);
43946 @@ -7038,7 +7038,7 @@ static int md_seq_show(struct seq_file *seq, void *v)
43947
43948 spin_unlock(&pers_lock);
43949 seq_printf(seq, "\n");
43950 - seq->poll_event = atomic_read(&md_event_count);
43951 + seq->poll_event = atomic_read_unchecked(&md_event_count);
43952 return 0;
43953 }
43954 if (v == (void*)2) {
43955 @@ -7141,7 +7141,7 @@ static int md_seq_open(struct inode *inode, struct file *file)
43956 return error;
43957
43958 seq = file->private_data;
43959 - seq->poll_event = atomic_read(&md_event_count);
43960 + seq->poll_event = atomic_read_unchecked(&md_event_count);
43961 return error;
43962 }
43963
43964 @@ -7155,7 +7155,7 @@ static unsigned int mdstat_poll(struct file *filp, poll_table *wait)
43965 /* always allow read */
43966 mask = POLLIN | POLLRDNORM;
43967
43968 - if (seq->poll_event != atomic_read(&md_event_count))
43969 + if (seq->poll_event != atomic_read_unchecked(&md_event_count))
43970 mask |= POLLERR | POLLPRI;
43971 return mask;
43972 }
43973 @@ -7199,7 +7199,7 @@ static int is_mddev_idle(struct mddev *mddev, int init)
43974 struct gendisk *disk = rdev->bdev->bd_contains->bd_disk;
43975 curr_events = (int)part_stat_read(&disk->part0, sectors[0]) +
43976 (int)part_stat_read(&disk->part0, sectors[1]) -
43977 - atomic_read(&disk->sync_io);
43978 + atomic_read_unchecked(&disk->sync_io);
43979 /* sync IO will cause sync_io to increase before the disk_stats
43980 * as sync_io is counted when a request starts, and
43981 * disk_stats is counted when it completes.
43982 diff --git a/drivers/md/md.h b/drivers/md/md.h
43983 index 0095ec8..c89277a 100644
43984 --- a/drivers/md/md.h
43985 +++ b/drivers/md/md.h
43986 @@ -94,13 +94,13 @@ struct md_rdev {
43987 * only maintained for arrays that
43988 * support hot removal
43989 */
43990 - atomic_t read_errors; /* number of consecutive read errors that
43991 + atomic_unchecked_t read_errors; /* number of consecutive read errors that
43992 * we have tried to ignore.
43993 */
43994 struct timespec last_read_error; /* monotonic time since our
43995 * last read error
43996 */
43997 - atomic_t corrected_errors; /* number of corrected read errors,
43998 + atomic_unchecked_t corrected_errors; /* number of corrected read errors,
43999 * for reporting to userspace and storing
44000 * in superblock.
44001 */
44002 @@ -449,7 +449,7 @@ static inline void rdev_dec_pending(struct md_rdev *rdev, struct mddev *mddev)
44003
44004 static inline void md_sync_acct(struct block_device *bdev, unsigned long nr_sectors)
44005 {
44006 - atomic_add(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
44007 + atomic_add_unchecked(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
44008 }
44009
44010 struct md_personality
44011 diff --git a/drivers/md/persistent-data/dm-space-map-metadata.c b/drivers/md/persistent-data/dm-space-map-metadata.c
44012 index 579b582..9fb6185 100644
44013 --- a/drivers/md/persistent-data/dm-space-map-metadata.c
44014 +++ b/drivers/md/persistent-data/dm-space-map-metadata.c
44015 @@ -679,7 +679,7 @@ static int sm_metadata_extend(struct dm_space_map *sm, dm_block_t extra_blocks)
44016 * Flick into a mode where all blocks get allocated in the new area.
44017 */
44018 smm->begin = old_len;
44019 - memcpy(sm, &bootstrap_ops, sizeof(*sm));
44020 + memcpy((void *)sm, &bootstrap_ops, sizeof(*sm));
44021
44022 /*
44023 * Extend.
44024 @@ -710,7 +710,7 @@ out:
44025 /*
44026 * Switch back to normal behaviour.
44027 */
44028 - memcpy(sm, &ops, sizeof(*sm));
44029 + memcpy((void *)sm, &ops, sizeof(*sm));
44030 return r;
44031 }
44032
44033 diff --git a/drivers/md/persistent-data/dm-space-map.h b/drivers/md/persistent-data/dm-space-map.h
44034 index 3e6d115..ffecdeb 100644
44035 --- a/drivers/md/persistent-data/dm-space-map.h
44036 +++ b/drivers/md/persistent-data/dm-space-map.h
44037 @@ -71,6 +71,7 @@ struct dm_space_map {
44038 dm_sm_threshold_fn fn,
44039 void *context);
44040 };
44041 +typedef struct dm_space_map __no_const dm_space_map_no_const;
44042
44043 /*----------------------------------------------------------------*/
44044
44045 diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c
44046 index 63b2e8d..225f16b 100644
44047 --- a/drivers/md/raid1.c
44048 +++ b/drivers/md/raid1.c
44049 @@ -1921,7 +1921,7 @@ static int fix_sync_read_error(struct r1bio *r1_bio)
44050 if (r1_sync_page_io(rdev, sect, s,
44051 bio->bi_io_vec[idx].bv_page,
44052 READ) != 0)
44053 - atomic_add(s, &rdev->corrected_errors);
44054 + atomic_add_unchecked(s, &rdev->corrected_errors);
44055 }
44056 sectors -= s;
44057 sect += s;
44058 @@ -2155,7 +2155,7 @@ static void fix_read_error(struct r1conf *conf, int read_disk,
44059 test_bit(In_sync, &rdev->flags)) {
44060 if (r1_sync_page_io(rdev, sect, s,
44061 conf->tmppage, READ)) {
44062 - atomic_add(s, &rdev->corrected_errors);
44063 + atomic_add_unchecked(s, &rdev->corrected_errors);
44064 printk(KERN_INFO
44065 "md/raid1:%s: read error corrected "
44066 "(%d sectors at %llu on %s)\n",
44067 diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
44068 index 06eeb99..770613e 100644
44069 --- a/drivers/md/raid10.c
44070 +++ b/drivers/md/raid10.c
44071 @@ -1963,7 +1963,7 @@ static void end_sync_read(struct bio *bio, int error)
44072 /* The write handler will notice the lack of
44073 * R10BIO_Uptodate and record any errors etc
44074 */
44075 - atomic_add(r10_bio->sectors,
44076 + atomic_add_unchecked(r10_bio->sectors,
44077 &conf->mirrors[d].rdev->corrected_errors);
44078
44079 /* for reconstruct, we always reschedule after a read.
44080 @@ -2321,7 +2321,7 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
44081 {
44082 struct timespec cur_time_mon;
44083 unsigned long hours_since_last;
44084 - unsigned int read_errors = atomic_read(&rdev->read_errors);
44085 + unsigned int read_errors = atomic_read_unchecked(&rdev->read_errors);
44086
44087 ktime_get_ts(&cur_time_mon);
44088
44089 @@ -2343,9 +2343,9 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
44090 * overflowing the shift of read_errors by hours_since_last.
44091 */
44092 if (hours_since_last >= 8 * sizeof(read_errors))
44093 - atomic_set(&rdev->read_errors, 0);
44094 + atomic_set_unchecked(&rdev->read_errors, 0);
44095 else
44096 - atomic_set(&rdev->read_errors, read_errors >> hours_since_last);
44097 + atomic_set_unchecked(&rdev->read_errors, read_errors >> hours_since_last);
44098 }
44099
44100 static int r10_sync_page_io(struct md_rdev *rdev, sector_t sector,
44101 @@ -2399,8 +2399,8 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
44102 return;
44103
44104 check_decay_read_errors(mddev, rdev);
44105 - atomic_inc(&rdev->read_errors);
44106 - if (atomic_read(&rdev->read_errors) > max_read_errors) {
44107 + atomic_inc_unchecked(&rdev->read_errors);
44108 + if (atomic_read_unchecked(&rdev->read_errors) > max_read_errors) {
44109 char b[BDEVNAME_SIZE];
44110 bdevname(rdev->bdev, b);
44111
44112 @@ -2408,7 +2408,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
44113 "md/raid10:%s: %s: Raid device exceeded "
44114 "read_error threshold [cur %d:max %d]\n",
44115 mdname(mddev), b,
44116 - atomic_read(&rdev->read_errors), max_read_errors);
44117 + atomic_read_unchecked(&rdev->read_errors), max_read_errors);
44118 printk(KERN_NOTICE
44119 "md/raid10:%s: %s: Failing raid device\n",
44120 mdname(mddev), b);
44121 @@ -2563,7 +2563,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
44122 sect +
44123 choose_data_offset(r10_bio, rdev)),
44124 bdevname(rdev->bdev, b));
44125 - atomic_add(s, &rdev->corrected_errors);
44126 + atomic_add_unchecked(s, &rdev->corrected_errors);
44127 }
44128
44129 rdev_dec_pending(rdev, mddev);
44130 diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
44131 index 48cdec8..c7726b1 100644
44132 --- a/drivers/md/raid5.c
44133 +++ b/drivers/md/raid5.c
44134 @@ -1991,21 +1991,21 @@ static void raid5_end_read_request(struct bio * bi, int error)
44135 mdname(conf->mddev), STRIPE_SECTORS,
44136 (unsigned long long)s,
44137 bdevname(rdev->bdev, b));
44138 - atomic_add(STRIPE_SECTORS, &rdev->corrected_errors);
44139 + atomic_add_unchecked(STRIPE_SECTORS, &rdev->corrected_errors);
44140 clear_bit(R5_ReadError, &sh->dev[i].flags);
44141 clear_bit(R5_ReWrite, &sh->dev[i].flags);
44142 } else if (test_bit(R5_ReadNoMerge, &sh->dev[i].flags))
44143 clear_bit(R5_ReadNoMerge, &sh->dev[i].flags);
44144
44145 - if (atomic_read(&rdev->read_errors))
44146 - atomic_set(&rdev->read_errors, 0);
44147 + if (atomic_read_unchecked(&rdev->read_errors))
44148 + atomic_set_unchecked(&rdev->read_errors, 0);
44149 } else {
44150 const char *bdn = bdevname(rdev->bdev, b);
44151 int retry = 0;
44152 int set_bad = 0;
44153
44154 clear_bit(R5_UPTODATE, &sh->dev[i].flags);
44155 - atomic_inc(&rdev->read_errors);
44156 + atomic_inc_unchecked(&rdev->read_errors);
44157 if (test_bit(R5_ReadRepl, &sh->dev[i].flags))
44158 printk_ratelimited(
44159 KERN_WARNING
44160 @@ -2033,7 +2033,7 @@ static void raid5_end_read_request(struct bio * bi, int error)
44161 mdname(conf->mddev),
44162 (unsigned long long)s,
44163 bdn);
44164 - } else if (atomic_read(&rdev->read_errors)
44165 + } else if (atomic_read_unchecked(&rdev->read_errors)
44166 > conf->max_nr_stripes)
44167 printk(KERN_WARNING
44168 "md/raid:%s: Too many read errors, failing device %s.\n",
44169 diff --git a/drivers/media/dvb-core/dvbdev.c b/drivers/media/dvb-core/dvbdev.c
44170 index 983db75..ef9248c 100644
44171 --- a/drivers/media/dvb-core/dvbdev.c
44172 +++ b/drivers/media/dvb-core/dvbdev.c
44173 @@ -185,7 +185,7 @@ int dvb_register_device(struct dvb_adapter *adap, struct dvb_device **pdvbdev,
44174 const struct dvb_device *template, void *priv, int type)
44175 {
44176 struct dvb_device *dvbdev;
44177 - struct file_operations *dvbdevfops;
44178 + file_operations_no_const *dvbdevfops;
44179 struct device *clsdev;
44180 int minor;
44181 int id;
44182 diff --git a/drivers/media/dvb-frontends/dib3000.h b/drivers/media/dvb-frontends/dib3000.h
44183 index 9b6c3bb..baeb5c7 100644
44184 --- a/drivers/media/dvb-frontends/dib3000.h
44185 +++ b/drivers/media/dvb-frontends/dib3000.h
44186 @@ -39,7 +39,7 @@ struct dib_fe_xfer_ops
44187 int (*fifo_ctrl)(struct dvb_frontend *fe, int onoff);
44188 int (*pid_ctrl)(struct dvb_frontend *fe, int index, int pid, int onoff);
44189 int (*tuner_pass_ctrl)(struct dvb_frontend *fe, int onoff, u8 pll_ctrl);
44190 -};
44191 +} __no_const;
44192
44193 #if IS_ENABLED(CONFIG_DVB_DIB3000MB)
44194 extern struct dvb_frontend* dib3000mb_attach(const struct dib3000_config* config,
44195 diff --git a/drivers/media/pci/cx88/cx88-video.c b/drivers/media/pci/cx88/cx88-video.c
44196 index ed8cb90..5ef7f79 100644
44197 --- a/drivers/media/pci/cx88/cx88-video.c
44198 +++ b/drivers/media/pci/cx88/cx88-video.c
44199 @@ -50,9 +50,9 @@ MODULE_VERSION(CX88_VERSION);
44200
44201 /* ------------------------------------------------------------------ */
44202
44203 -static unsigned int video_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
44204 -static unsigned int vbi_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
44205 -static unsigned int radio_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
44206 +static int video_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
44207 +static int vbi_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
44208 +static int radio_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
44209
44210 module_param_array(video_nr, int, NULL, 0444);
44211 module_param_array(vbi_nr, int, NULL, 0444);
44212 diff --git a/drivers/media/pci/ivtv/ivtv-driver.c b/drivers/media/pci/ivtv/ivtv-driver.c
44213 index 802642d..5534900 100644
44214 --- a/drivers/media/pci/ivtv/ivtv-driver.c
44215 +++ b/drivers/media/pci/ivtv/ivtv-driver.c
44216 @@ -83,7 +83,7 @@ static struct pci_device_id ivtv_pci_tbl[] = {
44217 MODULE_DEVICE_TABLE(pci,ivtv_pci_tbl);
44218
44219 /* ivtv instance counter */
44220 -static atomic_t ivtv_instance = ATOMIC_INIT(0);
44221 +static atomic_unchecked_t ivtv_instance = ATOMIC_INIT(0);
44222
44223 /* Parameter declarations */
44224 static int cardtype[IVTV_MAX_CARDS];
44225 diff --git a/drivers/media/platform/omap/omap_vout.c b/drivers/media/platform/omap/omap_vout.c
44226 index dfd0a21..6bbb465 100644
44227 --- a/drivers/media/platform/omap/omap_vout.c
44228 +++ b/drivers/media/platform/omap/omap_vout.c
44229 @@ -63,7 +63,6 @@ enum omap_vout_channels {
44230 OMAP_VIDEO2,
44231 };
44232
44233 -static struct videobuf_queue_ops video_vbq_ops;
44234 /* Variables configurable through module params*/
44235 static u32 video1_numbuffers = 3;
44236 static u32 video2_numbuffers = 3;
44237 @@ -1014,6 +1013,12 @@ static int omap_vout_open(struct file *file)
44238 {
44239 struct videobuf_queue *q;
44240 struct omap_vout_device *vout = NULL;
44241 + static struct videobuf_queue_ops video_vbq_ops = {
44242 + .buf_setup = omap_vout_buffer_setup,
44243 + .buf_prepare = omap_vout_buffer_prepare,
44244 + .buf_release = omap_vout_buffer_release,
44245 + .buf_queue = omap_vout_buffer_queue,
44246 + };
44247
44248 vout = video_drvdata(file);
44249 v4l2_dbg(1, debug, &vout->vid_dev->v4l2_dev, "Entering %s\n", __func__);
44250 @@ -1031,10 +1036,6 @@ static int omap_vout_open(struct file *file)
44251 vout->type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
44252
44253 q = &vout->vbq;
44254 - video_vbq_ops.buf_setup = omap_vout_buffer_setup;
44255 - video_vbq_ops.buf_prepare = omap_vout_buffer_prepare;
44256 - video_vbq_ops.buf_release = omap_vout_buffer_release;
44257 - video_vbq_ops.buf_queue = omap_vout_buffer_queue;
44258 spin_lock_init(&vout->vbq_lock);
44259
44260 videobuf_queue_dma_contig_init(q, &video_vbq_ops, q->dev,
44261 diff --git a/drivers/media/platform/s5p-tv/mixer.h b/drivers/media/platform/s5p-tv/mixer.h
44262 index fb2acc5..a2fcbdc4 100644
44263 --- a/drivers/media/platform/s5p-tv/mixer.h
44264 +++ b/drivers/media/platform/s5p-tv/mixer.h
44265 @@ -156,7 +156,7 @@ struct mxr_layer {
44266 /** layer index (unique identifier) */
44267 int idx;
44268 /** callbacks for layer methods */
44269 - struct mxr_layer_ops ops;
44270 + struct mxr_layer_ops *ops;
44271 /** format array */
44272 const struct mxr_format **fmt_array;
44273 /** size of format array */
44274 diff --git a/drivers/media/platform/s5p-tv/mixer_grp_layer.c b/drivers/media/platform/s5p-tv/mixer_grp_layer.c
44275 index 74344c7..a39e70e 100644
44276 --- a/drivers/media/platform/s5p-tv/mixer_grp_layer.c
44277 +++ b/drivers/media/platform/s5p-tv/mixer_grp_layer.c
44278 @@ -235,7 +235,7 @@ struct mxr_layer *mxr_graph_layer_create(struct mxr_device *mdev, int idx)
44279 {
44280 struct mxr_layer *layer;
44281 int ret;
44282 - struct mxr_layer_ops ops = {
44283 + static struct mxr_layer_ops ops = {
44284 .release = mxr_graph_layer_release,
44285 .buffer_set = mxr_graph_buffer_set,
44286 .stream_set = mxr_graph_stream_set,
44287 diff --git a/drivers/media/platform/s5p-tv/mixer_reg.c b/drivers/media/platform/s5p-tv/mixer_reg.c
44288 index b713403..53cb5ad 100644
44289 --- a/drivers/media/platform/s5p-tv/mixer_reg.c
44290 +++ b/drivers/media/platform/s5p-tv/mixer_reg.c
44291 @@ -276,7 +276,7 @@ static void mxr_irq_layer_handle(struct mxr_layer *layer)
44292 layer->update_buf = next;
44293 }
44294
44295 - layer->ops.buffer_set(layer, layer->update_buf);
44296 + layer->ops->buffer_set(layer, layer->update_buf);
44297
44298 if (done && done != layer->shadow_buf)
44299 vb2_buffer_done(&done->vb, VB2_BUF_STATE_DONE);
44300 diff --git a/drivers/media/platform/s5p-tv/mixer_video.c b/drivers/media/platform/s5p-tv/mixer_video.c
44301 index 81b97db..b089ccd 100644
44302 --- a/drivers/media/platform/s5p-tv/mixer_video.c
44303 +++ b/drivers/media/platform/s5p-tv/mixer_video.c
44304 @@ -210,7 +210,7 @@ static void mxr_layer_default_geo(struct mxr_layer *layer)
44305 layer->geo.src.height = layer->geo.src.full_height;
44306
44307 mxr_geometry_dump(mdev, &layer->geo);
44308 - layer->ops.fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
44309 + layer->ops->fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
44310 mxr_geometry_dump(mdev, &layer->geo);
44311 }
44312
44313 @@ -228,7 +228,7 @@ static void mxr_layer_update_output(struct mxr_layer *layer)
44314 layer->geo.dst.full_width = mbus_fmt.width;
44315 layer->geo.dst.full_height = mbus_fmt.height;
44316 layer->geo.dst.field = mbus_fmt.field;
44317 - layer->ops.fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
44318 + layer->ops->fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
44319
44320 mxr_geometry_dump(mdev, &layer->geo);
44321 }
44322 @@ -334,7 +334,7 @@ static int mxr_s_fmt(struct file *file, void *priv,
44323 /* set source size to highest accepted value */
44324 geo->src.full_width = max(geo->dst.full_width, pix->width);
44325 geo->src.full_height = max(geo->dst.full_height, pix->height);
44326 - layer->ops.fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
44327 + layer->ops->fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
44328 mxr_geometry_dump(mdev, &layer->geo);
44329 /* set cropping to total visible screen */
44330 geo->src.width = pix->width;
44331 @@ -342,12 +342,12 @@ static int mxr_s_fmt(struct file *file, void *priv,
44332 geo->src.x_offset = 0;
44333 geo->src.y_offset = 0;
44334 /* assure consistency of geometry */
44335 - layer->ops.fix_geometry(layer, MXR_GEOMETRY_CROP, MXR_NO_OFFSET);
44336 + layer->ops->fix_geometry(layer, MXR_GEOMETRY_CROP, MXR_NO_OFFSET);
44337 mxr_geometry_dump(mdev, &layer->geo);
44338 /* set full size to lowest possible value */
44339 geo->src.full_width = 0;
44340 geo->src.full_height = 0;
44341 - layer->ops.fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
44342 + layer->ops->fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
44343 mxr_geometry_dump(mdev, &layer->geo);
44344
44345 /* returning results */
44346 @@ -474,7 +474,7 @@ static int mxr_s_selection(struct file *file, void *fh,
44347 target->width = s->r.width;
44348 target->height = s->r.height;
44349
44350 - layer->ops.fix_geometry(layer, stage, s->flags);
44351 + layer->ops->fix_geometry(layer, stage, s->flags);
44352
44353 /* retrieve update selection rectangle */
44354 res.left = target->x_offset;
44355 @@ -955,13 +955,13 @@ static int start_streaming(struct vb2_queue *vq, unsigned int count)
44356 mxr_output_get(mdev);
44357
44358 mxr_layer_update_output(layer);
44359 - layer->ops.format_set(layer);
44360 + layer->ops->format_set(layer);
44361 /* enabling layer in hardware */
44362 spin_lock_irqsave(&layer->enq_slock, flags);
44363 layer->state = MXR_LAYER_STREAMING;
44364 spin_unlock_irqrestore(&layer->enq_slock, flags);
44365
44366 - layer->ops.stream_set(layer, MXR_ENABLE);
44367 + layer->ops->stream_set(layer, MXR_ENABLE);
44368 mxr_streamer_get(mdev);
44369
44370 return 0;
44371 @@ -1031,7 +1031,7 @@ static int stop_streaming(struct vb2_queue *vq)
44372 spin_unlock_irqrestore(&layer->enq_slock, flags);
44373
44374 /* disabling layer in hardware */
44375 - layer->ops.stream_set(layer, MXR_DISABLE);
44376 + layer->ops->stream_set(layer, MXR_DISABLE);
44377 /* remove one streamer */
44378 mxr_streamer_put(mdev);
44379 /* allow changes in output configuration */
44380 @@ -1070,8 +1070,8 @@ void mxr_base_layer_unregister(struct mxr_layer *layer)
44381
44382 void mxr_layer_release(struct mxr_layer *layer)
44383 {
44384 - if (layer->ops.release)
44385 - layer->ops.release(layer);
44386 + if (layer->ops->release)
44387 + layer->ops->release(layer);
44388 }
44389
44390 void mxr_base_layer_release(struct mxr_layer *layer)
44391 @@ -1097,7 +1097,7 @@ struct mxr_layer *mxr_base_layer_create(struct mxr_device *mdev,
44392
44393 layer->mdev = mdev;
44394 layer->idx = idx;
44395 - layer->ops = *ops;
44396 + layer->ops = ops;
44397
44398 spin_lock_init(&layer->enq_slock);
44399 INIT_LIST_HEAD(&layer->enq_list);
44400 diff --git a/drivers/media/platform/s5p-tv/mixer_vp_layer.c b/drivers/media/platform/s5p-tv/mixer_vp_layer.c
44401 index c9388c4..ce71ece 100644
44402 --- a/drivers/media/platform/s5p-tv/mixer_vp_layer.c
44403 +++ b/drivers/media/platform/s5p-tv/mixer_vp_layer.c
44404 @@ -206,7 +206,7 @@ struct mxr_layer *mxr_vp_layer_create(struct mxr_device *mdev, int idx)
44405 {
44406 struct mxr_layer *layer;
44407 int ret;
44408 - struct mxr_layer_ops ops = {
44409 + static struct mxr_layer_ops ops = {
44410 .release = mxr_vp_layer_release,
44411 .buffer_set = mxr_vp_buffer_set,
44412 .stream_set = mxr_vp_stream_set,
44413 diff --git a/drivers/media/platform/vivi.c b/drivers/media/platform/vivi.c
44414 index 2d4e73b..8b4d5b6 100644
44415 --- a/drivers/media/platform/vivi.c
44416 +++ b/drivers/media/platform/vivi.c
44417 @@ -58,8 +58,8 @@ MODULE_AUTHOR("Mauro Carvalho Chehab, Ted Walther and John Sokol");
44418 MODULE_LICENSE("Dual BSD/GPL");
44419 MODULE_VERSION(VIVI_VERSION);
44420
44421 -static unsigned video_nr = -1;
44422 -module_param(video_nr, uint, 0644);
44423 +static int video_nr = -1;
44424 +module_param(video_nr, int, 0644);
44425 MODULE_PARM_DESC(video_nr, "videoX start number, -1 is autodetect");
44426
44427 static unsigned n_devs = 1;
44428 diff --git a/drivers/media/radio/radio-cadet.c b/drivers/media/radio/radio-cadet.c
44429 index 545c04c..a14bded 100644
44430 --- a/drivers/media/radio/radio-cadet.c
44431 +++ b/drivers/media/radio/radio-cadet.c
44432 @@ -324,6 +324,8 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
44433 unsigned char readbuf[RDS_BUFFER];
44434 int i = 0;
44435
44436 + if (count > RDS_BUFFER)
44437 + return -EFAULT;
44438 mutex_lock(&dev->lock);
44439 if (dev->rdsstat == 0)
44440 cadet_start_rds(dev);
44441 @@ -339,7 +341,7 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
44442 while (i < count && dev->rdsin != dev->rdsout)
44443 readbuf[i++] = dev->rdsbuf[dev->rdsout++];
44444
44445 - if (i && copy_to_user(data, readbuf, i))
44446 + if (i > sizeof(readbuf) || copy_to_user(data, readbuf, i))
44447 i = -EFAULT;
44448 unlock:
44449 mutex_unlock(&dev->lock);
44450 diff --git a/drivers/media/radio/radio-maxiradio.c b/drivers/media/radio/radio-maxiradio.c
44451 index 5236035..c622c74 100644
44452 --- a/drivers/media/radio/radio-maxiradio.c
44453 +++ b/drivers/media/radio/radio-maxiradio.c
44454 @@ -61,7 +61,7 @@ MODULE_PARM_DESC(radio_nr, "Radio device number");
44455 /* TEA5757 pin mappings */
44456 static const int clk = 1, data = 2, wren = 4, mo_st = 8, power = 16;
44457
44458 -static atomic_t maxiradio_instance = ATOMIC_INIT(0);
44459 +static atomic_unchecked_t maxiradio_instance = ATOMIC_INIT(0);
44460
44461 #define PCI_VENDOR_ID_GUILLEMOT 0x5046
44462 #define PCI_DEVICE_ID_GUILLEMOT_MAXIRADIO 0x1001
44463 diff --git a/drivers/media/radio/radio-shark.c b/drivers/media/radio/radio-shark.c
44464 index 050b3bb..79f62b9 100644
44465 --- a/drivers/media/radio/radio-shark.c
44466 +++ b/drivers/media/radio/radio-shark.c
44467 @@ -79,7 +79,7 @@ struct shark_device {
44468 u32 last_val;
44469 };
44470
44471 -static atomic_t shark_instance = ATOMIC_INIT(0);
44472 +static atomic_unchecked_t shark_instance = ATOMIC_INIT(0);
44473
44474 static void shark_write_val(struct snd_tea575x *tea, u32 val)
44475 {
44476 diff --git a/drivers/media/radio/radio-shark2.c b/drivers/media/radio/radio-shark2.c
44477 index 8654e0d..0608a64 100644
44478 --- a/drivers/media/radio/radio-shark2.c
44479 +++ b/drivers/media/radio/radio-shark2.c
44480 @@ -74,7 +74,7 @@ struct shark_device {
44481 u8 *transfer_buffer;
44482 };
44483
44484 -static atomic_t shark_instance = ATOMIC_INIT(0);
44485 +static atomic_unchecked_t shark_instance = ATOMIC_INIT(0);
44486
44487 static int shark_write_reg(struct radio_tea5777 *tea, u64 reg)
44488 {
44489 diff --git a/drivers/media/radio/radio-si476x.c b/drivers/media/radio/radio-si476x.c
44490 index 2fd9009..278cc1e 100644
44491 --- a/drivers/media/radio/radio-si476x.c
44492 +++ b/drivers/media/radio/radio-si476x.c
44493 @@ -1445,7 +1445,7 @@ static int si476x_radio_probe(struct platform_device *pdev)
44494 struct si476x_radio *radio;
44495 struct v4l2_ctrl *ctrl;
44496
44497 - static atomic_t instance = ATOMIC_INIT(0);
44498 + static atomic_unchecked_t instance = ATOMIC_INIT(0);
44499
44500 radio = devm_kzalloc(&pdev->dev, sizeof(*radio), GFP_KERNEL);
44501 if (!radio)
44502 diff --git a/drivers/media/rc/rc-main.c b/drivers/media/rc/rc-main.c
44503 index 46da365..3ba4206 100644
44504 --- a/drivers/media/rc/rc-main.c
44505 +++ b/drivers/media/rc/rc-main.c
44506 @@ -1065,7 +1065,7 @@ EXPORT_SYMBOL_GPL(rc_free_device);
44507 int rc_register_device(struct rc_dev *dev)
44508 {
44509 static bool raw_init = false; /* raw decoders loaded? */
44510 - static atomic_t devno = ATOMIC_INIT(0);
44511 + static atomic_unchecked_t devno = ATOMIC_INIT(0);
44512 struct rc_map *rc_map;
44513 const char *path;
44514 int rc;
44515 @@ -1096,7 +1096,7 @@ int rc_register_device(struct rc_dev *dev)
44516 */
44517 mutex_lock(&dev->lock);
44518
44519 - dev->devno = (unsigned long)(atomic_inc_return(&devno) - 1);
44520 + dev->devno = (unsigned long)(atomic_inc_return_unchecked(&devno) - 1);
44521 dev_set_name(&dev->dev, "rc%ld", dev->devno);
44522 dev_set_drvdata(&dev->dev, dev);
44523 rc = device_add(&dev->dev);
44524 diff --git a/drivers/media/usb/dvb-usb/cxusb.c b/drivers/media/usb/dvb-usb/cxusb.c
44525 index a1c641e..3007da9 100644
44526 --- a/drivers/media/usb/dvb-usb/cxusb.c
44527 +++ b/drivers/media/usb/dvb-usb/cxusb.c
44528 @@ -1112,7 +1112,7 @@ static struct dib0070_config dib7070p_dib0070_config = {
44529
44530 struct dib0700_adapter_state {
44531 int (*set_param_save) (struct dvb_frontend *);
44532 -};
44533 +} __no_const;
44534
44535 static int dib7070_set_param_override(struct dvb_frontend *fe)
44536 {
44537 diff --git a/drivers/media/usb/dvb-usb/dw2102.c b/drivers/media/usb/dvb-usb/dw2102.c
44538 index f272ed8..6289f9c 100644
44539 --- a/drivers/media/usb/dvb-usb/dw2102.c
44540 +++ b/drivers/media/usb/dvb-usb/dw2102.c
44541 @@ -121,7 +121,7 @@ struct su3000_state {
44542
44543 struct s6x0_state {
44544 int (*old_set_voltage)(struct dvb_frontend *f, fe_sec_voltage_t v);
44545 -};
44546 +} __no_const;
44547
44548 /* debug */
44549 static int dvb_usb_dw2102_debug;
44550 diff --git a/drivers/media/v4l2-core/v4l2-compat-ioctl32.c b/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
44551 index 8f7a6a4..eb0e1d4 100644
44552 --- a/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
44553 +++ b/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
44554 @@ -326,7 +326,7 @@ struct v4l2_buffer32 {
44555 __u32 reserved;
44556 };
44557
44558 -static int get_v4l2_plane32(struct v4l2_plane *up, struct v4l2_plane32 *up32,
44559 +static int get_v4l2_plane32(struct v4l2_plane __user *up, struct v4l2_plane32 __user *up32,
44560 enum v4l2_memory memory)
44561 {
44562 void __user *up_pln;
44563 @@ -355,7 +355,7 @@ static int get_v4l2_plane32(struct v4l2_plane *up, struct v4l2_plane32 *up32,
44564 return 0;
44565 }
44566
44567 -static int put_v4l2_plane32(struct v4l2_plane *up, struct v4l2_plane32 *up32,
44568 +static int put_v4l2_plane32(struct v4l2_plane __user *up, struct v4l2_plane32 __user *up32,
44569 enum v4l2_memory memory)
44570 {
44571 if (copy_in_user(up32, up, 2 * sizeof(__u32)) ||
44572 @@ -425,7 +425,7 @@ static int get_v4l2_buffer32(struct v4l2_buffer *kp, struct v4l2_buffer32 __user
44573 * by passing a very big num_planes value */
44574 uplane = compat_alloc_user_space(num_planes *
44575 sizeof(struct v4l2_plane));
44576 - kp->m.planes = uplane;
44577 + kp->m.planes = (struct v4l2_plane __force_kernel *)uplane;
44578
44579 while (--num_planes >= 0) {
44580 ret = get_v4l2_plane32(uplane, uplane32, kp->memory);
44581 @@ -496,7 +496,7 @@ static int put_v4l2_buffer32(struct v4l2_buffer *kp, struct v4l2_buffer32 __user
44582 if (num_planes == 0)
44583 return 0;
44584
44585 - uplane = kp->m.planes;
44586 + uplane = (struct v4l2_plane __force_user *)kp->m.planes;
44587 if (get_user(p, &up->m.planes))
44588 return -EFAULT;
44589 uplane32 = compat_ptr(p);
44590 @@ -550,7 +550,7 @@ static int get_v4l2_framebuffer32(struct v4l2_framebuffer *kp, struct v4l2_frame
44591 get_user(kp->capability, &up->capability) ||
44592 get_user(kp->flags, &up->flags))
44593 return -EFAULT;
44594 - kp->base = compat_ptr(tmp);
44595 + kp->base = (void __force_kernel *)compat_ptr(tmp);
44596 get_v4l2_pix_format(&kp->fmt, &up->fmt);
44597 return 0;
44598 }
44599 @@ -656,7 +656,7 @@ static int get_v4l2_ext_controls32(struct v4l2_ext_controls *kp, struct v4l2_ext
44600 n * sizeof(struct v4l2_ext_control32)))
44601 return -EFAULT;
44602 kcontrols = compat_alloc_user_space(n * sizeof(struct v4l2_ext_control));
44603 - kp->controls = kcontrols;
44604 + kp->controls = (struct v4l2_ext_control __force_kernel *)kcontrols;
44605 while (--n >= 0) {
44606 if (copy_in_user(kcontrols, ucontrols, sizeof(*ucontrols)))
44607 return -EFAULT;
44608 @@ -678,7 +678,7 @@ static int get_v4l2_ext_controls32(struct v4l2_ext_controls *kp, struct v4l2_ext
44609 static int put_v4l2_ext_controls32(struct v4l2_ext_controls *kp, struct v4l2_ext_controls32 __user *up)
44610 {
44611 struct v4l2_ext_control32 __user *ucontrols;
44612 - struct v4l2_ext_control __user *kcontrols = kp->controls;
44613 + struct v4l2_ext_control __user *kcontrols = (struct v4l2_ext_control __force_user *)kp->controls;
44614 int n = kp->count;
44615 compat_caddr_t p;
44616
44617 @@ -772,7 +772,7 @@ static int put_v4l2_subdev_edid32(struct v4l2_subdev_edid *kp, struct v4l2_subde
44618 put_user(kp->start_block, &up->start_block) ||
44619 put_user(kp->blocks, &up->blocks) ||
44620 put_user(tmp, &up->edid) ||
44621 - copy_to_user(kp->reserved, up->reserved, sizeof(kp->reserved)))
44622 + copy_to_user(up->reserved, kp->reserved, sizeof(kp->reserved)))
44623 return -EFAULT;
44624 return 0;
44625 }
44626 diff --git a/drivers/media/v4l2-core/v4l2-ctrls.c b/drivers/media/v4l2-core/v4l2-ctrls.c
44627 index fb46790..ae1f8fa 100644
44628 --- a/drivers/media/v4l2-core/v4l2-ctrls.c
44629 +++ b/drivers/media/v4l2-core/v4l2-ctrls.c
44630 @@ -1396,8 +1396,8 @@ static int validate_new(const struct v4l2_ctrl *ctrl,
44631 return 0;
44632
44633 case V4L2_CTRL_TYPE_STRING:
44634 - len = strlen(c->string);
44635 - if (len < ctrl->minimum)
44636 + len = strlen_user(c->string);
44637 + if (!len || len < ctrl->minimum)
44638 return -ERANGE;
44639 if ((len - ctrl->minimum) % ctrl->step)
44640 return -ERANGE;
44641 diff --git a/drivers/media/v4l2-core/v4l2-device.c b/drivers/media/v4l2-core/v4l2-device.c
44642 index 02d1b63..5fd6b16 100644
44643 --- a/drivers/media/v4l2-core/v4l2-device.c
44644 +++ b/drivers/media/v4l2-core/v4l2-device.c
44645 @@ -75,9 +75,9 @@ int v4l2_device_put(struct v4l2_device *v4l2_dev)
44646 EXPORT_SYMBOL_GPL(v4l2_device_put);
44647
44648 int v4l2_device_set_name(struct v4l2_device *v4l2_dev, const char *basename,
44649 - atomic_t *instance)
44650 + atomic_unchecked_t *instance)
44651 {
44652 - int num = atomic_inc_return(instance) - 1;
44653 + int num = atomic_inc_return_unchecked(instance) - 1;
44654 int len = strlen(basename);
44655
44656 if (basename[len - 1] >= '0' && basename[len - 1] <= '9')
44657 diff --git a/drivers/media/v4l2-core/v4l2-ioctl.c b/drivers/media/v4l2-core/v4l2-ioctl.c
44658 index 68e6b5e..8eb2aec 100644
44659 --- a/drivers/media/v4l2-core/v4l2-ioctl.c
44660 +++ b/drivers/media/v4l2-core/v4l2-ioctl.c
44661 @@ -1939,7 +1939,8 @@ struct v4l2_ioctl_info {
44662 struct file *file, void *fh, void *p);
44663 } u;
44664 void (*debug)(const void *arg, bool write_only);
44665 -};
44666 +} __do_const;
44667 +typedef struct v4l2_ioctl_info __no_const v4l2_ioctl_info_no_const;
44668
44669 /* This control needs a priority check */
44670 #define INFO_FL_PRIO (1 << 0)
44671 @@ -2120,7 +2121,7 @@ static long __video_do_ioctl(struct file *file,
44672 struct video_device *vfd = video_devdata(file);
44673 const struct v4l2_ioctl_ops *ops = vfd->ioctl_ops;
44674 bool write_only = false;
44675 - struct v4l2_ioctl_info default_info;
44676 + v4l2_ioctl_info_no_const default_info;
44677 const struct v4l2_ioctl_info *info;
44678 void *fh = file->private_data;
44679 struct v4l2_fh *vfh = NULL;
44680 @@ -2194,7 +2195,7 @@ done:
44681 }
44682
44683 static int check_array_args(unsigned int cmd, void *parg, size_t *array_size,
44684 - void * __user *user_ptr, void ***kernel_ptr)
44685 + void __user **user_ptr, void ***kernel_ptr)
44686 {
44687 int ret = 0;
44688
44689 @@ -2210,7 +2211,7 @@ static int check_array_args(unsigned int cmd, void *parg, size_t *array_size,
44690 ret = -EINVAL;
44691 break;
44692 }
44693 - *user_ptr = (void __user *)buf->m.planes;
44694 + *user_ptr = (void __force_user *)buf->m.planes;
44695 *kernel_ptr = (void *)&buf->m.planes;
44696 *array_size = sizeof(struct v4l2_plane) * buf->length;
44697 ret = 1;
44698 @@ -2245,7 +2246,7 @@ static int check_array_args(unsigned int cmd, void *parg, size_t *array_size,
44699 ret = -EINVAL;
44700 break;
44701 }
44702 - *user_ptr = (void __user *)ctrls->controls;
44703 + *user_ptr = (void __force_user *)ctrls->controls;
44704 *kernel_ptr = (void *)&ctrls->controls;
44705 *array_size = sizeof(struct v4l2_ext_control)
44706 * ctrls->count;
44707 @@ -2340,7 +2341,7 @@ video_usercopy(struct file *file, unsigned int cmd, unsigned long arg,
44708 err = -ENOTTY;
44709
44710 if (has_array_args) {
44711 - *kernel_ptr = user_ptr;
44712 + *kernel_ptr = (void __force_kernel *)user_ptr;
44713 if (copy_to_user(user_ptr, mbuf, array_size))
44714 err = -EFAULT;
44715 goto out_array_args;
44716 diff --git a/drivers/message/fusion/mptbase.c b/drivers/message/fusion/mptbase.c
44717 index 767ff4d..c69d259 100644
44718 --- a/drivers/message/fusion/mptbase.c
44719 +++ b/drivers/message/fusion/mptbase.c
44720 @@ -6755,8 +6755,13 @@ static int mpt_iocinfo_proc_show(struct seq_file *m, void *v)
44721 seq_printf(m, " MaxChainDepth = 0x%02x frames\n", ioc->facts.MaxChainDepth);
44722 seq_printf(m, " MinBlockSize = 0x%02x bytes\n", 4*ioc->facts.BlockSize);
44723
44724 +#ifdef CONFIG_GRKERNSEC_HIDESYM
44725 + seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n", NULL, NULL);
44726 +#else
44727 seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n",
44728 (void *)ioc->req_frames, (void *)(ulong)ioc->req_frames_dma);
44729 +#endif
44730 +
44731 /*
44732 * Rounding UP to nearest 4-kB boundary here...
44733 */
44734 @@ -6769,7 +6774,11 @@ static int mpt_iocinfo_proc_show(struct seq_file *m, void *v)
44735 ioc->facts.GlobalCredits);
44736
44737 seq_printf(m, " Frames @ 0x%p (Dma @ 0x%p)\n",
44738 +#ifdef CONFIG_GRKERNSEC_HIDESYM
44739 + NULL, NULL);
44740 +#else
44741 (void *)ioc->alloc, (void *)(ulong)ioc->alloc_dma);
44742 +#endif
44743 sz = (ioc->reply_sz * ioc->reply_depth) + 128;
44744 seq_printf(m, " {CurRepSz=%d} x {CurRepDepth=%d} = %d bytes ^= 0x%x\n",
44745 ioc->reply_sz, ioc->reply_depth, ioc->reply_sz*ioc->reply_depth, sz);
44746 diff --git a/drivers/message/fusion/mptsas.c b/drivers/message/fusion/mptsas.c
44747 index dd239bd..689c4f7 100644
44748 --- a/drivers/message/fusion/mptsas.c
44749 +++ b/drivers/message/fusion/mptsas.c
44750 @@ -446,6 +446,23 @@ mptsas_is_end_device(struct mptsas_devinfo * attached)
44751 return 0;
44752 }
44753
44754 +static inline void
44755 +mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
44756 +{
44757 + if (phy_info->port_details) {
44758 + phy_info->port_details->rphy = rphy;
44759 + dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
44760 + ioc->name, rphy));
44761 + }
44762 +
44763 + if (rphy) {
44764 + dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
44765 + &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
44766 + dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
44767 + ioc->name, rphy, rphy->dev.release));
44768 + }
44769 +}
44770 +
44771 /* no mutex */
44772 static void
44773 mptsas_port_delete(MPT_ADAPTER *ioc, struct mptsas_portinfo_details * port_details)
44774 @@ -484,23 +501,6 @@ mptsas_get_rphy(struct mptsas_phyinfo *phy_info)
44775 return NULL;
44776 }
44777
44778 -static inline void
44779 -mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
44780 -{
44781 - if (phy_info->port_details) {
44782 - phy_info->port_details->rphy = rphy;
44783 - dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
44784 - ioc->name, rphy));
44785 - }
44786 -
44787 - if (rphy) {
44788 - dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
44789 - &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
44790 - dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
44791 - ioc->name, rphy, rphy->dev.release));
44792 - }
44793 -}
44794 -
44795 static inline struct sas_port *
44796 mptsas_get_port(struct mptsas_phyinfo *phy_info)
44797 {
44798 diff --git a/drivers/message/fusion/mptscsih.c b/drivers/message/fusion/mptscsih.c
44799 index 727819c..ad74694 100644
44800 --- a/drivers/message/fusion/mptscsih.c
44801 +++ b/drivers/message/fusion/mptscsih.c
44802 @@ -1271,15 +1271,16 @@ mptscsih_info(struct Scsi_Host *SChost)
44803
44804 h = shost_priv(SChost);
44805
44806 - if (h) {
44807 - if (h->info_kbuf == NULL)
44808 - if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
44809 - return h->info_kbuf;
44810 - h->info_kbuf[0] = '\0';
44811 + if (!h)
44812 + return NULL;
44813
44814 - mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
44815 - h->info_kbuf[size-1] = '\0';
44816 - }
44817 + if (h->info_kbuf == NULL)
44818 + if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
44819 + return h->info_kbuf;
44820 + h->info_kbuf[0] = '\0';
44821 +
44822 + mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
44823 + h->info_kbuf[size-1] = '\0';
44824
44825 return h->info_kbuf;
44826 }
44827 diff --git a/drivers/message/i2o/i2o_proc.c b/drivers/message/i2o/i2o_proc.c
44828 index b7d87cd..3fb36da 100644
44829 --- a/drivers/message/i2o/i2o_proc.c
44830 +++ b/drivers/message/i2o/i2o_proc.c
44831 @@ -255,12 +255,6 @@ static char *scsi_devices[] = {
44832 "Array Controller Device"
44833 };
44834
44835 -static char *chtostr(char *tmp, u8 *chars, int n)
44836 -{
44837 - tmp[0] = 0;
44838 - return strncat(tmp, (char *)chars, n);
44839 -}
44840 -
44841 static int i2o_report_query_status(struct seq_file *seq, int block_status,
44842 char *group)
44843 {
44844 @@ -707,9 +701,9 @@ static int i2o_seq_show_status(struct seq_file *seq, void *v)
44845 static int i2o_seq_show_hw(struct seq_file *seq, void *v)
44846 {
44847 struct i2o_controller *c = (struct i2o_controller *)seq->private;
44848 - static u32 work32[5];
44849 - static u8 *work8 = (u8 *) work32;
44850 - static u16 *work16 = (u16 *) work32;
44851 + u32 work32[5];
44852 + u8 *work8 = (u8 *) work32;
44853 + u16 *work16 = (u16 *) work32;
44854 int token;
44855 u32 hwcap;
44856
44857 @@ -790,7 +784,6 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
44858 } *result;
44859
44860 i2o_exec_execute_ddm_table ddm_table;
44861 - char tmp[28 + 1];
44862
44863 result = kmalloc(sizeof(*result), GFP_KERNEL);
44864 if (!result)
44865 @@ -825,8 +818,7 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
44866
44867 seq_printf(seq, "%-#7x", ddm_table.i2o_vendor_id);
44868 seq_printf(seq, "%-#8x", ddm_table.module_id);
44869 - seq_printf(seq, "%-29s",
44870 - chtostr(tmp, ddm_table.module_name_version, 28));
44871 + seq_printf(seq, "%-.28s", ddm_table.module_name_version);
44872 seq_printf(seq, "%9d ", ddm_table.data_size);
44873 seq_printf(seq, "%8d", ddm_table.code_size);
44874
44875 @@ -893,7 +885,6 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
44876
44877 i2o_driver_result_table *result;
44878 i2o_driver_store_table *dst;
44879 - char tmp[28 + 1];
44880
44881 result = kmalloc(sizeof(i2o_driver_result_table), GFP_KERNEL);
44882 if (result == NULL)
44883 @@ -928,9 +919,8 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
44884
44885 seq_printf(seq, "%-#7x", dst->i2o_vendor_id);
44886 seq_printf(seq, "%-#8x", dst->module_id);
44887 - seq_printf(seq, "%-29s",
44888 - chtostr(tmp, dst->module_name_version, 28));
44889 - seq_printf(seq, "%-9s", chtostr(tmp, dst->date, 8));
44890 + seq_printf(seq, "%-.28s", dst->module_name_version);
44891 + seq_printf(seq, "%-.8s", dst->date);
44892 seq_printf(seq, "%8d ", dst->module_size);
44893 seq_printf(seq, "%8d ", dst->mpb_size);
44894 seq_printf(seq, "0x%04x", dst->module_flags);
44895 @@ -1246,11 +1236,10 @@ static int i2o_seq_show_authorized_users(struct seq_file *seq, void *v)
44896 static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
44897 {
44898 struct i2o_device *d = (struct i2o_device *)seq->private;
44899 - static u32 work32[128]; // allow for "stuff" + up to 256 byte (max) serial number
44900 + u32 work32[128]; // allow for "stuff" + up to 256 byte (max) serial number
44901 // == (allow) 512d bytes (max)
44902 - static u16 *work16 = (u16 *) work32;
44903 + u16 *work16 = (u16 *) work32;
44904 int token;
44905 - char tmp[16 + 1];
44906
44907 token = i2o_parm_field_get(d, 0xF100, -1, &work32, sizeof(work32));
44908
44909 @@ -1262,14 +1251,10 @@ static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
44910 seq_printf(seq, "Device Class : %s\n", i2o_get_class_name(work16[0]));
44911 seq_printf(seq, "Owner TID : %0#5x\n", work16[2]);
44912 seq_printf(seq, "Parent TID : %0#5x\n", work16[3]);
44913 - seq_printf(seq, "Vendor info : %s\n",
44914 - chtostr(tmp, (u8 *) (work32 + 2), 16));
44915 - seq_printf(seq, "Product info : %s\n",
44916 - chtostr(tmp, (u8 *) (work32 + 6), 16));
44917 - seq_printf(seq, "Description : %s\n",
44918 - chtostr(tmp, (u8 *) (work32 + 10), 16));
44919 - seq_printf(seq, "Product rev. : %s\n",
44920 - chtostr(tmp, (u8 *) (work32 + 14), 8));
44921 + seq_printf(seq, "Vendor info : %.16s\n", (u8 *) (work32 + 2));
44922 + seq_printf(seq, "Product info : %.16s\n", (u8 *) (work32 + 6));
44923 + seq_printf(seq, "Description : %.16s\n", (u8 *) (work32 + 10));
44924 + seq_printf(seq, "Product rev. : %.8s\n", (u8 *) (work32 + 14));
44925
44926 seq_printf(seq, "Serial number : ");
44927 print_serial_number(seq, (u8 *) (work32 + 16),
44928 @@ -1306,8 +1291,6 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
44929 u8 pad[256]; // allow up to 256 byte (max) serial number
44930 } result;
44931
44932 - char tmp[24 + 1];
44933 -
44934 token = i2o_parm_field_get(d, 0xF101, -1, &result, sizeof(result));
44935
44936 if (token < 0) {
44937 @@ -1316,10 +1299,8 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
44938 }
44939
44940 seq_printf(seq, "Registering DDM TID : 0x%03x\n", result.ddm_tid);
44941 - seq_printf(seq, "Module name : %s\n",
44942 - chtostr(tmp, result.module_name, 24));
44943 - seq_printf(seq, "Module revision : %s\n",
44944 - chtostr(tmp, result.module_rev, 8));
44945 + seq_printf(seq, "Module name : %.24s\n", result.module_name);
44946 + seq_printf(seq, "Module revision : %.8s\n", result.module_rev);
44947
44948 seq_printf(seq, "Serial number : ");
44949 print_serial_number(seq, result.serial_number, sizeof(result) - 36);
44950 @@ -1343,8 +1324,6 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
44951 u8 instance_number[4];
44952 } result;
44953
44954 - char tmp[64 + 1];
44955 -
44956 token = i2o_parm_field_get(d, 0xF102, -1, &result, sizeof(result));
44957
44958 if (token < 0) {
44959 @@ -1352,14 +1331,10 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
44960 return 0;
44961 }
44962
44963 - seq_printf(seq, "Device name : %s\n",
44964 - chtostr(tmp, result.device_name, 64));
44965 - seq_printf(seq, "Service name : %s\n",
44966 - chtostr(tmp, result.service_name, 64));
44967 - seq_printf(seq, "Physical name : %s\n",
44968 - chtostr(tmp, result.physical_location, 64));
44969 - seq_printf(seq, "Instance number : %s\n",
44970 - chtostr(tmp, result.instance_number, 4));
44971 + seq_printf(seq, "Device name : %.64s\n", result.device_name);
44972 + seq_printf(seq, "Service name : %.64s\n", result.service_name);
44973 + seq_printf(seq, "Physical name : %.64s\n", result.physical_location);
44974 + seq_printf(seq, "Instance number : %.4s\n", result.instance_number);
44975
44976 return 0;
44977 }
44978 @@ -1368,9 +1343,9 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
44979 static int i2o_seq_show_sgl_limits(struct seq_file *seq, void *v)
44980 {
44981 struct i2o_device *d = (struct i2o_device *)seq->private;
44982 - static u32 work32[12];
44983 - static u16 *work16 = (u16 *) work32;
44984 - static u8 *work8 = (u8 *) work32;
44985 + u32 work32[12];
44986 + u16 *work16 = (u16 *) work32;
44987 + u8 *work8 = (u8 *) work32;
44988 int token;
44989
44990 token = i2o_parm_field_get(d, 0xF103, -1, &work32, sizeof(work32));
44991 diff --git a/drivers/message/i2o/iop.c b/drivers/message/i2o/iop.c
44992 index a8c08f3..155fe3d 100644
44993 --- a/drivers/message/i2o/iop.c
44994 +++ b/drivers/message/i2o/iop.c
44995 @@ -111,10 +111,10 @@ u32 i2o_cntxt_list_add(struct i2o_controller * c, void *ptr)
44996
44997 spin_lock_irqsave(&c->context_list_lock, flags);
44998
44999 - if (unlikely(atomic_inc_and_test(&c->context_list_counter)))
45000 - atomic_inc(&c->context_list_counter);
45001 + if (unlikely(atomic_inc_and_test_unchecked(&c->context_list_counter)))
45002 + atomic_inc_unchecked(&c->context_list_counter);
45003
45004 - entry->context = atomic_read(&c->context_list_counter);
45005 + entry->context = atomic_read_unchecked(&c->context_list_counter);
45006
45007 list_add(&entry->list, &c->context_list);
45008
45009 @@ -1077,7 +1077,7 @@ struct i2o_controller *i2o_iop_alloc(void)
45010
45011 #if BITS_PER_LONG == 64
45012 spin_lock_init(&c->context_list_lock);
45013 - atomic_set(&c->context_list_counter, 0);
45014 + atomic_set_unchecked(&c->context_list_counter, 0);
45015 INIT_LIST_HEAD(&c->context_list);
45016 #endif
45017
45018 diff --git a/drivers/mfd/ab8500-debugfs.c b/drivers/mfd/ab8500-debugfs.c
45019 index e33e385..28dfd23 100644
45020 --- a/drivers/mfd/ab8500-debugfs.c
45021 +++ b/drivers/mfd/ab8500-debugfs.c
45022 @@ -100,7 +100,7 @@ static int irq_last;
45023 static u32 *irq_count;
45024 static int num_irqs;
45025
45026 -static struct device_attribute **dev_attr;
45027 +static device_attribute_no_const **dev_attr;
45028 static char **event_name;
45029
45030 static u8 avg_sample = SAMPLE_16;
45031 diff --git a/drivers/mfd/janz-cmodio.c b/drivers/mfd/janz-cmodio.c
45032 index fcbb2e9..2635e11 100644
45033 --- a/drivers/mfd/janz-cmodio.c
45034 +++ b/drivers/mfd/janz-cmodio.c
45035 @@ -13,6 +13,7 @@
45036
45037 #include <linux/kernel.h>
45038 #include <linux/module.h>
45039 +#include <linux/slab.h>
45040 #include <linux/init.h>
45041 #include <linux/pci.h>
45042 #include <linux/interrupt.h>
45043 diff --git a/drivers/mfd/max8925-i2c.c b/drivers/mfd/max8925-i2c.c
45044 index 176aa26..27811b2 100644
45045 --- a/drivers/mfd/max8925-i2c.c
45046 +++ b/drivers/mfd/max8925-i2c.c
45047 @@ -152,7 +152,7 @@ static int max8925_probe(struct i2c_client *client,
45048 const struct i2c_device_id *id)
45049 {
45050 struct max8925_platform_data *pdata = dev_get_platdata(&client->dev);
45051 - static struct max8925_chip *chip;
45052 + struct max8925_chip *chip;
45053 struct device_node *node = client->dev.of_node;
45054
45055 if (node && !pdata) {
45056 diff --git a/drivers/mfd/tps65910.c b/drivers/mfd/tps65910.c
45057 index c0f608e..286f8ec 100644
45058 --- a/drivers/mfd/tps65910.c
45059 +++ b/drivers/mfd/tps65910.c
45060 @@ -230,7 +230,7 @@ static int tps65910_irq_init(struct tps65910 *tps65910, int irq,
45061 struct tps65910_platform_data *pdata)
45062 {
45063 int ret = 0;
45064 - static struct regmap_irq_chip *tps6591x_irqs_chip;
45065 + struct regmap_irq_chip *tps6591x_irqs_chip;
45066
45067 if (!irq) {
45068 dev_warn(tps65910->dev, "No interrupt support, no core IRQ\n");
45069 diff --git a/drivers/mfd/twl4030-irq.c b/drivers/mfd/twl4030-irq.c
45070 index 9aa6d1e..1631bfc 100644
45071 --- a/drivers/mfd/twl4030-irq.c
45072 +++ b/drivers/mfd/twl4030-irq.c
45073 @@ -35,6 +35,7 @@
45074 #include <linux/of.h>
45075 #include <linux/irqdomain.h>
45076 #include <linux/i2c/twl.h>
45077 +#include <asm/pgtable.h>
45078
45079 #include "twl-core.h"
45080
45081 @@ -726,10 +727,12 @@ int twl4030_init_irq(struct device *dev, int irq_num)
45082 * Install an irq handler for each of the SIH modules;
45083 * clone dummy irq_chip since PIH can't *do* anything
45084 */
45085 - twl4030_irq_chip = dummy_irq_chip;
45086 - twl4030_irq_chip.name = "twl4030";
45087 + pax_open_kernel();
45088 + memcpy((void *)&twl4030_irq_chip, &dummy_irq_chip, sizeof twl4030_irq_chip);
45089 + *(const char **)&twl4030_irq_chip.name = "twl4030";
45090
45091 - twl4030_sih_irq_chip.irq_ack = dummy_irq_chip.irq_ack;
45092 + *(void **)&twl4030_sih_irq_chip.irq_ack = dummy_irq_chip.irq_ack;
45093 + pax_close_kernel();
45094
45095 for (i = irq_base; i < irq_end; i++) {
45096 irq_set_chip_and_handler(i, &twl4030_irq_chip,
45097 diff --git a/drivers/misc/c2port/core.c b/drivers/misc/c2port/core.c
45098 index 464419b..64bae8d 100644
45099 --- a/drivers/misc/c2port/core.c
45100 +++ b/drivers/misc/c2port/core.c
45101 @@ -922,7 +922,9 @@ struct c2port_device *c2port_device_register(char *name,
45102 goto error_idr_alloc;
45103 c2dev->id = ret;
45104
45105 - bin_attr_flash_data.size = ops->blocks_num * ops->block_size;
45106 + pax_open_kernel();
45107 + *(size_t *)&bin_attr_flash_data.size = ops->blocks_num * ops->block_size;
45108 + pax_close_kernel();
45109
45110 c2dev->dev = device_create(c2port_class, NULL, 0, c2dev,
45111 "c2port%d", c2dev->id);
45112 diff --git a/drivers/misc/eeprom/sunxi_sid.c b/drivers/misc/eeprom/sunxi_sid.c
45113 index 9c34e57..b981cda 100644
45114 --- a/drivers/misc/eeprom/sunxi_sid.c
45115 +++ b/drivers/misc/eeprom/sunxi_sid.c
45116 @@ -127,7 +127,9 @@ static int sunxi_sid_probe(struct platform_device *pdev)
45117
45118 platform_set_drvdata(pdev, sid_data);
45119
45120 - sid_bin_attr.size = sid_data->keysize;
45121 + pax_open_kernel();
45122 + *(size_t *)&sid_bin_attr.size = sid_data->keysize;
45123 + pax_close_kernel();
45124 if (device_create_bin_file(&pdev->dev, &sid_bin_attr))
45125 return -ENODEV;
45126
45127 diff --git a/drivers/misc/kgdbts.c b/drivers/misc/kgdbts.c
45128 index 36f5d52..32311c3 100644
45129 --- a/drivers/misc/kgdbts.c
45130 +++ b/drivers/misc/kgdbts.c
45131 @@ -834,7 +834,7 @@ static void run_plant_and_detach_test(int is_early)
45132 char before[BREAK_INSTR_SIZE];
45133 char after[BREAK_INSTR_SIZE];
45134
45135 - probe_kernel_read(before, (char *)kgdbts_break_test,
45136 + probe_kernel_read(before, ktla_ktva((char *)kgdbts_break_test),
45137 BREAK_INSTR_SIZE);
45138 init_simple_test();
45139 ts.tst = plant_and_detach_test;
45140 @@ -842,7 +842,7 @@ static void run_plant_and_detach_test(int is_early)
45141 /* Activate test with initial breakpoint */
45142 if (!is_early)
45143 kgdb_breakpoint();
45144 - probe_kernel_read(after, (char *)kgdbts_break_test,
45145 + probe_kernel_read(after, ktla_ktva((char *)kgdbts_break_test),
45146 BREAK_INSTR_SIZE);
45147 if (memcmp(before, after, BREAK_INSTR_SIZE)) {
45148 printk(KERN_CRIT "kgdbts: ERROR kgdb corrupted memory\n");
45149 diff --git a/drivers/misc/lis3lv02d/lis3lv02d.c b/drivers/misc/lis3lv02d/lis3lv02d.c
45150 index 036effe..b3a6336 100644
45151 --- a/drivers/misc/lis3lv02d/lis3lv02d.c
45152 +++ b/drivers/misc/lis3lv02d/lis3lv02d.c
45153 @@ -498,7 +498,7 @@ static irqreturn_t lis302dl_interrupt(int irq, void *data)
45154 * the lid is closed. This leads to interrupts as soon as a little move
45155 * is done.
45156 */
45157 - atomic_inc(&lis3->count);
45158 + atomic_inc_unchecked(&lis3->count);
45159
45160 wake_up_interruptible(&lis3->misc_wait);
45161 kill_fasync(&lis3->async_queue, SIGIO, POLL_IN);
45162 @@ -584,7 +584,7 @@ static int lis3lv02d_misc_open(struct inode *inode, struct file *file)
45163 if (lis3->pm_dev)
45164 pm_runtime_get_sync(lis3->pm_dev);
45165
45166 - atomic_set(&lis3->count, 0);
45167 + atomic_set_unchecked(&lis3->count, 0);
45168 return 0;
45169 }
45170
45171 @@ -616,7 +616,7 @@ static ssize_t lis3lv02d_misc_read(struct file *file, char __user *buf,
45172 add_wait_queue(&lis3->misc_wait, &wait);
45173 while (true) {
45174 set_current_state(TASK_INTERRUPTIBLE);
45175 - data = atomic_xchg(&lis3->count, 0);
45176 + data = atomic_xchg_unchecked(&lis3->count, 0);
45177 if (data)
45178 break;
45179
45180 @@ -657,7 +657,7 @@ static unsigned int lis3lv02d_misc_poll(struct file *file, poll_table *wait)
45181 struct lis3lv02d, miscdev);
45182
45183 poll_wait(file, &lis3->misc_wait, wait);
45184 - if (atomic_read(&lis3->count))
45185 + if (atomic_read_unchecked(&lis3->count))
45186 return POLLIN | POLLRDNORM;
45187 return 0;
45188 }
45189 diff --git a/drivers/misc/lis3lv02d/lis3lv02d.h b/drivers/misc/lis3lv02d/lis3lv02d.h
45190 index c439c82..1f20f57 100644
45191 --- a/drivers/misc/lis3lv02d/lis3lv02d.h
45192 +++ b/drivers/misc/lis3lv02d/lis3lv02d.h
45193 @@ -297,7 +297,7 @@ struct lis3lv02d {
45194 struct input_polled_dev *idev; /* input device */
45195 struct platform_device *pdev; /* platform device */
45196 struct regulator_bulk_data regulators[2];
45197 - atomic_t count; /* interrupt count after last read */
45198 + atomic_unchecked_t count; /* interrupt count after last read */
45199 union axis_conversion ac; /* hw -> logical axis */
45200 int mapped_btns[3];
45201
45202 diff --git a/drivers/misc/sgi-gru/gruhandles.c b/drivers/misc/sgi-gru/gruhandles.c
45203 index 2f30bad..c4c13d0 100644
45204 --- a/drivers/misc/sgi-gru/gruhandles.c
45205 +++ b/drivers/misc/sgi-gru/gruhandles.c
45206 @@ -44,8 +44,8 @@ static void update_mcs_stats(enum mcs_op op, unsigned long clks)
45207 unsigned long nsec;
45208
45209 nsec = CLKS2NSEC(clks);
45210 - atomic_long_inc(&mcs_op_statistics[op].count);
45211 - atomic_long_add(nsec, &mcs_op_statistics[op].total);
45212 + atomic_long_inc_unchecked(&mcs_op_statistics[op].count);
45213 + atomic_long_add_unchecked(nsec, &mcs_op_statistics[op].total);
45214 if (mcs_op_statistics[op].max < nsec)
45215 mcs_op_statistics[op].max = nsec;
45216 }
45217 diff --git a/drivers/misc/sgi-gru/gruprocfs.c b/drivers/misc/sgi-gru/gruprocfs.c
45218 index 4f76359..cdfcb2e 100644
45219 --- a/drivers/misc/sgi-gru/gruprocfs.c
45220 +++ b/drivers/misc/sgi-gru/gruprocfs.c
45221 @@ -32,9 +32,9 @@
45222
45223 #define printstat(s, f) printstat_val(s, &gru_stats.f, #f)
45224
45225 -static void printstat_val(struct seq_file *s, atomic_long_t *v, char *id)
45226 +static void printstat_val(struct seq_file *s, atomic_long_unchecked_t *v, char *id)
45227 {
45228 - unsigned long val = atomic_long_read(v);
45229 + unsigned long val = atomic_long_read_unchecked(v);
45230
45231 seq_printf(s, "%16lu %s\n", val, id);
45232 }
45233 @@ -134,8 +134,8 @@ static int mcs_statistics_show(struct seq_file *s, void *p)
45234
45235 seq_printf(s, "%-20s%12s%12s%12s\n", "#id", "count", "aver-clks", "max-clks");
45236 for (op = 0; op < mcsop_last; op++) {
45237 - count = atomic_long_read(&mcs_op_statistics[op].count);
45238 - total = atomic_long_read(&mcs_op_statistics[op].total);
45239 + count = atomic_long_read_unchecked(&mcs_op_statistics[op].count);
45240 + total = atomic_long_read_unchecked(&mcs_op_statistics[op].total);
45241 max = mcs_op_statistics[op].max;
45242 seq_printf(s, "%-20s%12ld%12ld%12ld\n", id[op], count,
45243 count ? total / count : 0, max);
45244 diff --git a/drivers/misc/sgi-gru/grutables.h b/drivers/misc/sgi-gru/grutables.h
45245 index 5c3ce24..4915ccb 100644
45246 --- a/drivers/misc/sgi-gru/grutables.h
45247 +++ b/drivers/misc/sgi-gru/grutables.h
45248 @@ -167,82 +167,82 @@ extern unsigned int gru_max_gids;
45249 * GRU statistics.
45250 */
45251 struct gru_stats_s {
45252 - atomic_long_t vdata_alloc;
45253 - atomic_long_t vdata_free;
45254 - atomic_long_t gts_alloc;
45255 - atomic_long_t gts_free;
45256 - atomic_long_t gms_alloc;
45257 - atomic_long_t gms_free;
45258 - atomic_long_t gts_double_allocate;
45259 - atomic_long_t assign_context;
45260 - atomic_long_t assign_context_failed;
45261 - atomic_long_t free_context;
45262 - atomic_long_t load_user_context;
45263 - atomic_long_t load_kernel_context;
45264 - atomic_long_t lock_kernel_context;
45265 - atomic_long_t unlock_kernel_context;
45266 - atomic_long_t steal_user_context;
45267 - atomic_long_t steal_kernel_context;
45268 - atomic_long_t steal_context_failed;
45269 - atomic_long_t nopfn;
45270 - atomic_long_t asid_new;
45271 - atomic_long_t asid_next;
45272 - atomic_long_t asid_wrap;
45273 - atomic_long_t asid_reuse;
45274 - atomic_long_t intr;
45275 - atomic_long_t intr_cbr;
45276 - atomic_long_t intr_tfh;
45277 - atomic_long_t intr_spurious;
45278 - atomic_long_t intr_mm_lock_failed;
45279 - atomic_long_t call_os;
45280 - atomic_long_t call_os_wait_queue;
45281 - atomic_long_t user_flush_tlb;
45282 - atomic_long_t user_unload_context;
45283 - atomic_long_t user_exception;
45284 - atomic_long_t set_context_option;
45285 - atomic_long_t check_context_retarget_intr;
45286 - atomic_long_t check_context_unload;
45287 - atomic_long_t tlb_dropin;
45288 - atomic_long_t tlb_preload_page;
45289 - atomic_long_t tlb_dropin_fail_no_asid;
45290 - atomic_long_t tlb_dropin_fail_upm;
45291 - atomic_long_t tlb_dropin_fail_invalid;
45292 - atomic_long_t tlb_dropin_fail_range_active;
45293 - atomic_long_t tlb_dropin_fail_idle;
45294 - atomic_long_t tlb_dropin_fail_fmm;
45295 - atomic_long_t tlb_dropin_fail_no_exception;
45296 - atomic_long_t tfh_stale_on_fault;
45297 - atomic_long_t mmu_invalidate_range;
45298 - atomic_long_t mmu_invalidate_page;
45299 - atomic_long_t flush_tlb;
45300 - atomic_long_t flush_tlb_gru;
45301 - atomic_long_t flush_tlb_gru_tgh;
45302 - atomic_long_t flush_tlb_gru_zero_asid;
45303 + atomic_long_unchecked_t vdata_alloc;
45304 + atomic_long_unchecked_t vdata_free;
45305 + atomic_long_unchecked_t gts_alloc;
45306 + atomic_long_unchecked_t gts_free;
45307 + atomic_long_unchecked_t gms_alloc;
45308 + atomic_long_unchecked_t gms_free;
45309 + atomic_long_unchecked_t gts_double_allocate;
45310 + atomic_long_unchecked_t assign_context;
45311 + atomic_long_unchecked_t assign_context_failed;
45312 + atomic_long_unchecked_t free_context;
45313 + atomic_long_unchecked_t load_user_context;
45314 + atomic_long_unchecked_t load_kernel_context;
45315 + atomic_long_unchecked_t lock_kernel_context;
45316 + atomic_long_unchecked_t unlock_kernel_context;
45317 + atomic_long_unchecked_t steal_user_context;
45318 + atomic_long_unchecked_t steal_kernel_context;
45319 + atomic_long_unchecked_t steal_context_failed;
45320 + atomic_long_unchecked_t nopfn;
45321 + atomic_long_unchecked_t asid_new;
45322 + atomic_long_unchecked_t asid_next;
45323 + atomic_long_unchecked_t asid_wrap;
45324 + atomic_long_unchecked_t asid_reuse;
45325 + atomic_long_unchecked_t intr;
45326 + atomic_long_unchecked_t intr_cbr;
45327 + atomic_long_unchecked_t intr_tfh;
45328 + atomic_long_unchecked_t intr_spurious;
45329 + atomic_long_unchecked_t intr_mm_lock_failed;
45330 + atomic_long_unchecked_t call_os;
45331 + atomic_long_unchecked_t call_os_wait_queue;
45332 + atomic_long_unchecked_t user_flush_tlb;
45333 + atomic_long_unchecked_t user_unload_context;
45334 + atomic_long_unchecked_t user_exception;
45335 + atomic_long_unchecked_t set_context_option;
45336 + atomic_long_unchecked_t check_context_retarget_intr;
45337 + atomic_long_unchecked_t check_context_unload;
45338 + atomic_long_unchecked_t tlb_dropin;
45339 + atomic_long_unchecked_t tlb_preload_page;
45340 + atomic_long_unchecked_t tlb_dropin_fail_no_asid;
45341 + atomic_long_unchecked_t tlb_dropin_fail_upm;
45342 + atomic_long_unchecked_t tlb_dropin_fail_invalid;
45343 + atomic_long_unchecked_t tlb_dropin_fail_range_active;
45344 + atomic_long_unchecked_t tlb_dropin_fail_idle;
45345 + atomic_long_unchecked_t tlb_dropin_fail_fmm;
45346 + atomic_long_unchecked_t tlb_dropin_fail_no_exception;
45347 + atomic_long_unchecked_t tfh_stale_on_fault;
45348 + atomic_long_unchecked_t mmu_invalidate_range;
45349 + atomic_long_unchecked_t mmu_invalidate_page;
45350 + atomic_long_unchecked_t flush_tlb;
45351 + atomic_long_unchecked_t flush_tlb_gru;
45352 + atomic_long_unchecked_t flush_tlb_gru_tgh;
45353 + atomic_long_unchecked_t flush_tlb_gru_zero_asid;
45354
45355 - atomic_long_t copy_gpa;
45356 - atomic_long_t read_gpa;
45357 + atomic_long_unchecked_t copy_gpa;
45358 + atomic_long_unchecked_t read_gpa;
45359
45360 - atomic_long_t mesq_receive;
45361 - atomic_long_t mesq_receive_none;
45362 - atomic_long_t mesq_send;
45363 - atomic_long_t mesq_send_failed;
45364 - atomic_long_t mesq_noop;
45365 - atomic_long_t mesq_send_unexpected_error;
45366 - atomic_long_t mesq_send_lb_overflow;
45367 - atomic_long_t mesq_send_qlimit_reached;
45368 - atomic_long_t mesq_send_amo_nacked;
45369 - atomic_long_t mesq_send_put_nacked;
45370 - atomic_long_t mesq_page_overflow;
45371 - atomic_long_t mesq_qf_locked;
45372 - atomic_long_t mesq_qf_noop_not_full;
45373 - atomic_long_t mesq_qf_switch_head_failed;
45374 - atomic_long_t mesq_qf_unexpected_error;
45375 - atomic_long_t mesq_noop_unexpected_error;
45376 - atomic_long_t mesq_noop_lb_overflow;
45377 - atomic_long_t mesq_noop_qlimit_reached;
45378 - atomic_long_t mesq_noop_amo_nacked;
45379 - atomic_long_t mesq_noop_put_nacked;
45380 - atomic_long_t mesq_noop_page_overflow;
45381 + atomic_long_unchecked_t mesq_receive;
45382 + atomic_long_unchecked_t mesq_receive_none;
45383 + atomic_long_unchecked_t mesq_send;
45384 + atomic_long_unchecked_t mesq_send_failed;
45385 + atomic_long_unchecked_t mesq_noop;
45386 + atomic_long_unchecked_t mesq_send_unexpected_error;
45387 + atomic_long_unchecked_t mesq_send_lb_overflow;
45388 + atomic_long_unchecked_t mesq_send_qlimit_reached;
45389 + atomic_long_unchecked_t mesq_send_amo_nacked;
45390 + atomic_long_unchecked_t mesq_send_put_nacked;
45391 + atomic_long_unchecked_t mesq_page_overflow;
45392 + atomic_long_unchecked_t mesq_qf_locked;
45393 + atomic_long_unchecked_t mesq_qf_noop_not_full;
45394 + atomic_long_unchecked_t mesq_qf_switch_head_failed;
45395 + atomic_long_unchecked_t mesq_qf_unexpected_error;
45396 + atomic_long_unchecked_t mesq_noop_unexpected_error;
45397 + atomic_long_unchecked_t mesq_noop_lb_overflow;
45398 + atomic_long_unchecked_t mesq_noop_qlimit_reached;
45399 + atomic_long_unchecked_t mesq_noop_amo_nacked;
45400 + atomic_long_unchecked_t mesq_noop_put_nacked;
45401 + atomic_long_unchecked_t mesq_noop_page_overflow;
45402
45403 };
45404
45405 @@ -251,8 +251,8 @@ enum mcs_op {cchop_allocate, cchop_start, cchop_interrupt, cchop_interrupt_sync,
45406 tghop_invalidate, mcsop_last};
45407
45408 struct mcs_op_statistic {
45409 - atomic_long_t count;
45410 - atomic_long_t total;
45411 + atomic_long_unchecked_t count;
45412 + atomic_long_unchecked_t total;
45413 unsigned long max;
45414 };
45415
45416 @@ -275,7 +275,7 @@ extern struct mcs_op_statistic mcs_op_statistics[mcsop_last];
45417
45418 #define STAT(id) do { \
45419 if (gru_options & OPT_STATS) \
45420 - atomic_long_inc(&gru_stats.id); \
45421 + atomic_long_inc_unchecked(&gru_stats.id); \
45422 } while (0)
45423
45424 #ifdef CONFIG_SGI_GRU_DEBUG
45425 diff --git a/drivers/misc/sgi-xp/xp.h b/drivers/misc/sgi-xp/xp.h
45426 index c862cd4..0d176fe 100644
45427 --- a/drivers/misc/sgi-xp/xp.h
45428 +++ b/drivers/misc/sgi-xp/xp.h
45429 @@ -288,7 +288,7 @@ struct xpc_interface {
45430 xpc_notify_func, void *);
45431 void (*received) (short, int, void *);
45432 enum xp_retval (*partid_to_nasids) (short, void *);
45433 -};
45434 +} __no_const;
45435
45436 extern struct xpc_interface xpc_interface;
45437
45438 diff --git a/drivers/misc/sgi-xp/xp_main.c b/drivers/misc/sgi-xp/xp_main.c
45439 index 01be66d..e3a0c7e 100644
45440 --- a/drivers/misc/sgi-xp/xp_main.c
45441 +++ b/drivers/misc/sgi-xp/xp_main.c
45442 @@ -78,13 +78,13 @@ xpc_notloaded(void)
45443 }
45444
45445 struct xpc_interface xpc_interface = {
45446 - (void (*)(int))xpc_notloaded,
45447 - (void (*)(int))xpc_notloaded,
45448 - (enum xp_retval(*)(short, int, u32, void *, u16))xpc_notloaded,
45449 - (enum xp_retval(*)(short, int, u32, void *, u16, xpc_notify_func,
45450 + .connect = (void (*)(int))xpc_notloaded,
45451 + .disconnect = (void (*)(int))xpc_notloaded,
45452 + .send = (enum xp_retval(*)(short, int, u32, void *, u16))xpc_notloaded,
45453 + .send_notify = (enum xp_retval(*)(short, int, u32, void *, u16, xpc_notify_func,
45454 void *))xpc_notloaded,
45455 - (void (*)(short, int, void *))xpc_notloaded,
45456 - (enum xp_retval(*)(short, void *))xpc_notloaded
45457 + .received = (void (*)(short, int, void *))xpc_notloaded,
45458 + .partid_to_nasids = (enum xp_retval(*)(short, void *))xpc_notloaded
45459 };
45460 EXPORT_SYMBOL_GPL(xpc_interface);
45461
45462 diff --git a/drivers/misc/sgi-xp/xpc.h b/drivers/misc/sgi-xp/xpc.h
45463 index b94d5f7..7f494c5 100644
45464 --- a/drivers/misc/sgi-xp/xpc.h
45465 +++ b/drivers/misc/sgi-xp/xpc.h
45466 @@ -835,6 +835,7 @@ struct xpc_arch_operations {
45467 void (*received_payload) (struct xpc_channel *, void *);
45468 void (*notify_senders_of_disconnect) (struct xpc_channel *);
45469 };
45470 +typedef struct xpc_arch_operations __no_const xpc_arch_operations_no_const;
45471
45472 /* struct xpc_partition act_state values (for XPC HB) */
45473
45474 @@ -876,7 +877,7 @@ extern struct xpc_registration xpc_registrations[];
45475 /* found in xpc_main.c */
45476 extern struct device *xpc_part;
45477 extern struct device *xpc_chan;
45478 -extern struct xpc_arch_operations xpc_arch_ops;
45479 +extern xpc_arch_operations_no_const xpc_arch_ops;
45480 extern int xpc_disengage_timelimit;
45481 extern int xpc_disengage_timedout;
45482 extern int xpc_activate_IRQ_rcvd;
45483 diff --git a/drivers/misc/sgi-xp/xpc_main.c b/drivers/misc/sgi-xp/xpc_main.c
45484 index 82dc574..8539ab2 100644
45485 --- a/drivers/misc/sgi-xp/xpc_main.c
45486 +++ b/drivers/misc/sgi-xp/xpc_main.c
45487 @@ -166,7 +166,7 @@ static struct notifier_block xpc_die_notifier = {
45488 .notifier_call = xpc_system_die,
45489 };
45490
45491 -struct xpc_arch_operations xpc_arch_ops;
45492 +xpc_arch_operations_no_const xpc_arch_ops;
45493
45494 /*
45495 * Timer function to enforce the timelimit on the partition disengage.
45496 @@ -1210,7 +1210,7 @@ xpc_system_die(struct notifier_block *nb, unsigned long event, void *_die_args)
45497
45498 if (((die_args->trapnr == X86_TRAP_MF) ||
45499 (die_args->trapnr == X86_TRAP_XF)) &&
45500 - !user_mode_vm(die_args->regs))
45501 + !user_mode(die_args->regs))
45502 xpc_die_deactivate();
45503
45504 break;
45505 diff --git a/drivers/mmc/card/block.c b/drivers/mmc/card/block.c
45506 index 7b5424f..ed1d6ac 100644
45507 --- a/drivers/mmc/card/block.c
45508 +++ b/drivers/mmc/card/block.c
45509 @@ -575,7 +575,7 @@ static int mmc_blk_ioctl_cmd(struct block_device *bdev,
45510 if (idata->ic.postsleep_min_us)
45511 usleep_range(idata->ic.postsleep_min_us, idata->ic.postsleep_max_us);
45512
45513 - if (copy_to_user(&(ic_ptr->response), cmd.resp, sizeof(cmd.resp))) {
45514 + if (copy_to_user(ic_ptr->response, cmd.resp, sizeof(cmd.resp))) {
45515 err = -EFAULT;
45516 goto cmd_rel_host;
45517 }
45518 diff --git a/drivers/mmc/core/mmc_ops.c b/drivers/mmc/core/mmc_ops.c
45519 index e5b5eeb..7bf2212 100644
45520 --- a/drivers/mmc/core/mmc_ops.c
45521 +++ b/drivers/mmc/core/mmc_ops.c
45522 @@ -247,7 +247,7 @@ mmc_send_cxd_data(struct mmc_card *card, struct mmc_host *host,
45523 void *data_buf;
45524 int is_on_stack;
45525
45526 - is_on_stack = object_is_on_stack(buf);
45527 + is_on_stack = object_starts_on_stack(buf);
45528 if (is_on_stack) {
45529 /*
45530 * dma onto stack is unsafe/nonportable, but callers to this
45531 diff --git a/drivers/mmc/host/dw_mmc.h b/drivers/mmc/host/dw_mmc.h
45532 index 6bf24ab..13d0293b 100644
45533 --- a/drivers/mmc/host/dw_mmc.h
45534 +++ b/drivers/mmc/host/dw_mmc.h
45535 @@ -258,5 +258,5 @@ struct dw_mci_drv_data {
45536 int (*parse_dt)(struct dw_mci *host);
45537 int (*execute_tuning)(struct dw_mci_slot *slot, u32 opcode,
45538 struct dw_mci_tuning_data *tuning_data);
45539 -};
45540 +} __do_const;
45541 #endif /* _DW_MMC_H_ */
45542 diff --git a/drivers/mmc/host/mmci.c b/drivers/mmc/host/mmci.c
45543 index f320579..7b7ebac 100644
45544 --- a/drivers/mmc/host/mmci.c
45545 +++ b/drivers/mmc/host/mmci.c
45546 @@ -1504,7 +1504,9 @@ static int mmci_probe(struct amba_device *dev,
45547 }
45548
45549 if (variant->busy_detect) {
45550 - mmci_ops.card_busy = mmci_card_busy;
45551 + pax_open_kernel();
45552 + *(void **)&mmci_ops.card_busy = mmci_card_busy;
45553 + pax_close_kernel();
45554 mmci_write_datactrlreg(host, MCI_ST_DPSM_BUSYMODE);
45555 }
45556
45557 diff --git a/drivers/mmc/host/sdhci-esdhc-imx.c b/drivers/mmc/host/sdhci-esdhc-imx.c
45558 index 1dcaf8a..025af25 100644
45559 --- a/drivers/mmc/host/sdhci-esdhc-imx.c
45560 +++ b/drivers/mmc/host/sdhci-esdhc-imx.c
45561 @@ -1009,9 +1009,12 @@ static int sdhci_esdhc_imx_probe(struct platform_device *pdev)
45562 host->quirks2 |= SDHCI_QUIRK2_PRESET_VALUE_BROKEN;
45563 }
45564
45565 - if (imx_data->socdata->flags & ESDHC_FLAG_MAN_TUNING)
45566 - sdhci_esdhc_ops.platform_execute_tuning =
45567 + if (imx_data->socdata->flags & ESDHC_FLAG_MAN_TUNING) {
45568 + pax_open_kernel();
45569 + *(void **)&sdhci_esdhc_ops.platform_execute_tuning =
45570 esdhc_executing_tuning;
45571 + pax_close_kernel();
45572 + }
45573 boarddata = &imx_data->boarddata;
45574 if (sdhci_esdhc_imx_probe_dt(pdev, boarddata) < 0) {
45575 if (!host->mmc->parent->platform_data) {
45576 diff --git a/drivers/mmc/host/sdhci-s3c.c b/drivers/mmc/host/sdhci-s3c.c
45577 index 6debda9..2ba7427 100644
45578 --- a/drivers/mmc/host/sdhci-s3c.c
45579 +++ b/drivers/mmc/host/sdhci-s3c.c
45580 @@ -668,9 +668,11 @@ static int sdhci_s3c_probe(struct platform_device *pdev)
45581 * we can use overriding functions instead of default.
45582 */
45583 if (host->quirks & SDHCI_QUIRK_NONSTANDARD_CLOCK) {
45584 - sdhci_s3c_ops.set_clock = sdhci_cmu_set_clock;
45585 - sdhci_s3c_ops.get_min_clock = sdhci_cmu_get_min_clock;
45586 - sdhci_s3c_ops.get_max_clock = sdhci_cmu_get_max_clock;
45587 + pax_open_kernel();
45588 + *(void **)&sdhci_s3c_ops.set_clock = sdhci_cmu_set_clock;
45589 + *(void **)&sdhci_s3c_ops.get_min_clock = sdhci_cmu_get_min_clock;
45590 + *(void **)&sdhci_s3c_ops.get_max_clock = sdhci_cmu_get_max_clock;
45591 + pax_close_kernel();
45592 }
45593
45594 /* It supports additional host capabilities if needed */
45595 diff --git a/drivers/mtd/chips/cfi_cmdset_0020.c b/drivers/mtd/chips/cfi_cmdset_0020.c
45596 index 096993f..f02c23b 100644
45597 --- a/drivers/mtd/chips/cfi_cmdset_0020.c
45598 +++ b/drivers/mtd/chips/cfi_cmdset_0020.c
45599 @@ -669,7 +669,7 @@ cfi_staa_writev(struct mtd_info *mtd, const struct kvec *vecs,
45600 size_t totlen = 0, thislen;
45601 int ret = 0;
45602 size_t buflen = 0;
45603 - static char *buffer;
45604 + char *buffer;
45605
45606 if (!ECCBUF_SIZE) {
45607 /* We should fall back to a general writev implementation.
45608 diff --git a/drivers/mtd/nand/denali.c b/drivers/mtd/nand/denali.c
45609 index 370b9dd..1a1176b 100644
45610 --- a/drivers/mtd/nand/denali.c
45611 +++ b/drivers/mtd/nand/denali.c
45612 @@ -24,6 +24,7 @@
45613 #include <linux/slab.h>
45614 #include <linux/mtd/mtd.h>
45615 #include <linux/module.h>
45616 +#include <linux/slab.h>
45617
45618 #include "denali.h"
45619
45620 diff --git a/drivers/mtd/nftlmount.c b/drivers/mtd/nftlmount.c
45621 index 51b9d6a..52af9a7 100644
45622 --- a/drivers/mtd/nftlmount.c
45623 +++ b/drivers/mtd/nftlmount.c
45624 @@ -24,6 +24,7 @@
45625 #include <asm/errno.h>
45626 #include <linux/delay.h>
45627 #include <linux/slab.h>
45628 +#include <linux/sched.h>
45629 #include <linux/mtd/mtd.h>
45630 #include <linux/mtd/nand.h>
45631 #include <linux/mtd/nftl.h>
45632 diff --git a/drivers/mtd/sm_ftl.c b/drivers/mtd/sm_ftl.c
45633 index 4b8e895..6b3c498 100644
45634 --- a/drivers/mtd/sm_ftl.c
45635 +++ b/drivers/mtd/sm_ftl.c
45636 @@ -56,7 +56,7 @@ static ssize_t sm_attr_show(struct device *dev, struct device_attribute *attr,
45637 #define SM_CIS_VENDOR_OFFSET 0x59
45638 static struct attribute_group *sm_create_sysfs_attributes(struct sm_ftl *ftl)
45639 {
45640 - struct attribute_group *attr_group;
45641 + attribute_group_no_const *attr_group;
45642 struct attribute **attributes;
45643 struct sm_sysfs_attribute *vendor_attribute;
45644
45645 diff --git a/drivers/net/bonding/bond_main.c b/drivers/net/bonding/bond_main.c
45646 index 4b8c58b..a200546 100644
45647 --- a/drivers/net/bonding/bond_main.c
45648 +++ b/drivers/net/bonding/bond_main.c
45649 @@ -4527,6 +4527,7 @@ static void __exit bonding_exit(void)
45650
45651 bond_netlink_fini();
45652 unregister_pernet_subsys(&bond_net_ops);
45653 + rtnl_link_unregister(&bond_link_ops);
45654
45655 #ifdef CONFIG_NET_POLL_CONTROLLER
45656 /*
45657 diff --git a/drivers/net/bonding/bond_netlink.c b/drivers/net/bonding/bond_netlink.c
45658 index 40e7b1c..6a70fff 100644
45659 --- a/drivers/net/bonding/bond_netlink.c
45660 +++ b/drivers/net/bonding/bond_netlink.c
45661 @@ -102,7 +102,7 @@ nla_put_failure:
45662 return -EMSGSIZE;
45663 }
45664
45665 -struct rtnl_link_ops bond_link_ops __read_mostly = {
45666 +struct rtnl_link_ops bond_link_ops = {
45667 .kind = "bond",
45668 .priv_size = sizeof(struct bonding),
45669 .setup = bond_setup,
45670 diff --git a/drivers/net/can/Kconfig b/drivers/net/can/Kconfig
45671 index 3c06947..fd0e5de 100644
45672 --- a/drivers/net/can/Kconfig
45673 +++ b/drivers/net/can/Kconfig
45674 @@ -104,7 +104,7 @@ config CAN_JANZ_ICAN3
45675
45676 config CAN_FLEXCAN
45677 tristate "Support for Freescale FLEXCAN based chips"
45678 - depends on ARM || PPC
45679 + depends on (ARM && CPU_LITTLE_ENDIAN) || PPC
45680 ---help---
45681 Say Y here if you want to support for Freescale FlexCAN.
45682
45683 diff --git a/drivers/net/ethernet/8390/ax88796.c b/drivers/net/ethernet/8390/ax88796.c
45684 index 36fa577..a158806 100644
45685 --- a/drivers/net/ethernet/8390/ax88796.c
45686 +++ b/drivers/net/ethernet/8390/ax88796.c
45687 @@ -872,9 +872,11 @@ static int ax_probe(struct platform_device *pdev)
45688 if (ax->plat->reg_offsets)
45689 ei_local->reg_offset = ax->plat->reg_offsets;
45690 else {
45691 + resource_size_t _mem_size = mem_size;
45692 + do_div(_mem_size, 0x18);
45693 ei_local->reg_offset = ax->reg_offsets;
45694 for (ret = 0; ret < 0x18; ret++)
45695 - ax->reg_offsets[ret] = (mem_size / 0x18) * ret;
45696 + ax->reg_offsets[ret] = _mem_size * ret;
45697 }
45698
45699 if (!request_mem_region(mem->start, mem_size, pdev->name)) {
45700 diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
45701 index 41f3ca5a..1ee5364 100644
45702 --- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
45703 +++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
45704 @@ -1139,7 +1139,7 @@ static inline u8 bnx2x_get_path_func_num(struct bnx2x *bp)
45705 static inline void bnx2x_init_bp_objs(struct bnx2x *bp)
45706 {
45707 /* RX_MODE controlling object */
45708 - bnx2x_init_rx_mode_obj(bp, &bp->rx_mode_obj);
45709 + bnx2x_init_rx_mode_obj(bp);
45710
45711 /* multicast configuration controlling object */
45712 bnx2x_init_mcast_obj(bp, &bp->mcast_obj, bp->fp->cl_id, bp->fp->cid,
45713 diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
45714 index 18438a5..c923b8e 100644
45715 --- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
45716 +++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
45717 @@ -2591,15 +2591,14 @@ int bnx2x_config_rx_mode(struct bnx2x *bp,
45718 return rc;
45719 }
45720
45721 -void bnx2x_init_rx_mode_obj(struct bnx2x *bp,
45722 - struct bnx2x_rx_mode_obj *o)
45723 +void bnx2x_init_rx_mode_obj(struct bnx2x *bp)
45724 {
45725 if (CHIP_IS_E1x(bp)) {
45726 - o->wait_comp = bnx2x_empty_rx_mode_wait;
45727 - o->config_rx_mode = bnx2x_set_rx_mode_e1x;
45728 + bp->rx_mode_obj.wait_comp = bnx2x_empty_rx_mode_wait;
45729 + bp->rx_mode_obj.config_rx_mode = bnx2x_set_rx_mode_e1x;
45730 } else {
45731 - o->wait_comp = bnx2x_wait_rx_mode_comp_e2;
45732 - o->config_rx_mode = bnx2x_set_rx_mode_e2;
45733 + bp->rx_mode_obj.wait_comp = bnx2x_wait_rx_mode_comp_e2;
45734 + bp->rx_mode_obj.config_rx_mode = bnx2x_set_rx_mode_e2;
45735 }
45736 }
45737
45738 diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
45739 index 6a53c15..6e7d1e7 100644
45740 --- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
45741 +++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
45742 @@ -1332,8 +1332,7 @@ int bnx2x_vlan_mac_move(struct bnx2x *bp,
45743
45744 /********************* RX MODE ****************/
45745
45746 -void bnx2x_init_rx_mode_obj(struct bnx2x *bp,
45747 - struct bnx2x_rx_mode_obj *o);
45748 +void bnx2x_init_rx_mode_obj(struct bnx2x *bp);
45749
45750 /**
45751 * bnx2x_config_rx_mode - Send and RX_MODE ramrod according to the provided parameters.
45752 diff --git a/drivers/net/ethernet/broadcom/tg3.h b/drivers/net/ethernet/broadcom/tg3.h
45753 index cf9917b..c658558 100644
45754 --- a/drivers/net/ethernet/broadcom/tg3.h
45755 +++ b/drivers/net/ethernet/broadcom/tg3.h
45756 @@ -150,6 +150,7 @@
45757 #define CHIPREV_ID_5750_A0 0x4000
45758 #define CHIPREV_ID_5750_A1 0x4001
45759 #define CHIPREV_ID_5750_A3 0x4003
45760 +#define CHIPREV_ID_5750_C1 0x4201
45761 #define CHIPREV_ID_5750_C2 0x4202
45762 #define CHIPREV_ID_5752_A0_HW 0x5000
45763 #define CHIPREV_ID_5752_A0 0x6000
45764 diff --git a/drivers/net/ethernet/brocade/bna/bna_enet.c b/drivers/net/ethernet/brocade/bna/bna_enet.c
45765 index 3ca77fa..fcc015f 100644
45766 --- a/drivers/net/ethernet/brocade/bna/bna_enet.c
45767 +++ b/drivers/net/ethernet/brocade/bna/bna_enet.c
45768 @@ -1690,10 +1690,10 @@ bna_cb_ioceth_reset(void *arg)
45769 }
45770
45771 static struct bfa_ioc_cbfn bna_ioceth_cbfn = {
45772 - bna_cb_ioceth_enable,
45773 - bna_cb_ioceth_disable,
45774 - bna_cb_ioceth_hbfail,
45775 - bna_cb_ioceth_reset
45776 + .enable_cbfn = bna_cb_ioceth_enable,
45777 + .disable_cbfn = bna_cb_ioceth_disable,
45778 + .hbfail_cbfn = bna_cb_ioceth_hbfail,
45779 + .reset_cbfn = bna_cb_ioceth_reset
45780 };
45781
45782 static void bna_attr_init(struct bna_ioceth *ioceth)
45783 diff --git a/drivers/net/ethernet/chelsio/cxgb3/l2t.h b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
45784 index 8cffcdf..aadf043 100644
45785 --- a/drivers/net/ethernet/chelsio/cxgb3/l2t.h
45786 +++ b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
45787 @@ -87,7 +87,7 @@ typedef void (*arp_failure_handler_func)(struct t3cdev * dev,
45788 */
45789 struct l2t_skb_cb {
45790 arp_failure_handler_func arp_failure_handler;
45791 -};
45792 +} __no_const;
45793
45794 #define L2T_SKB_CB(skb) ((struct l2t_skb_cb *)(skb)->cb)
45795
45796 diff --git a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c
45797 index fff02ed..d421412 100644
45798 --- a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c
45799 +++ b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c
45800 @@ -2120,7 +2120,7 @@ static void get_regs(struct net_device *dev, struct ethtool_regs *regs,
45801
45802 int i;
45803 struct adapter *ap = netdev2adap(dev);
45804 - static const unsigned int *reg_ranges;
45805 + const unsigned int *reg_ranges;
45806 int arr_size = 0, buf_size = 0;
45807
45808 if (is_t4(ap->params.chip)) {
45809 diff --git a/drivers/net/ethernet/dec/tulip/de4x5.c b/drivers/net/ethernet/dec/tulip/de4x5.c
45810 index c05b66d..ed69872 100644
45811 --- a/drivers/net/ethernet/dec/tulip/de4x5.c
45812 +++ b/drivers/net/ethernet/dec/tulip/de4x5.c
45813 @@ -5388,7 +5388,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
45814 for (i=0; i<ETH_ALEN; i++) {
45815 tmp.addr[i] = dev->dev_addr[i];
45816 }
45817 - if (copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
45818 + if (ioc->len > sizeof tmp.addr || copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
45819 break;
45820
45821 case DE4X5_SET_HWADDR: /* Set the hardware address */
45822 @@ -5428,7 +5428,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
45823 spin_lock_irqsave(&lp->lock, flags);
45824 memcpy(&statbuf, &lp->pktStats, ioc->len);
45825 spin_unlock_irqrestore(&lp->lock, flags);
45826 - if (copy_to_user(ioc->data, &statbuf, ioc->len))
45827 + if (ioc->len > sizeof statbuf || copy_to_user(ioc->data, &statbuf, ioc->len))
45828 return -EFAULT;
45829 break;
45830 }
45831 diff --git a/drivers/net/ethernet/emulex/benet/be_main.c b/drivers/net/ethernet/emulex/benet/be_main.c
45832 index a37039d..a51d7e8 100644
45833 --- a/drivers/net/ethernet/emulex/benet/be_main.c
45834 +++ b/drivers/net/ethernet/emulex/benet/be_main.c
45835 @@ -533,7 +533,7 @@ static void accumulate_16bit_val(u32 *acc, u16 val)
45836
45837 if (wrapped)
45838 newacc += 65536;
45839 - ACCESS_ONCE(*acc) = newacc;
45840 + ACCESS_ONCE_RW(*acc) = newacc;
45841 }
45842
45843 static void populate_erx_stats(struct be_adapter *adapter,
45844 diff --git a/drivers/net/ethernet/faraday/ftgmac100.c b/drivers/net/ethernet/faraday/ftgmac100.c
45845 index 212f44b..fb69959 100644
45846 --- a/drivers/net/ethernet/faraday/ftgmac100.c
45847 +++ b/drivers/net/ethernet/faraday/ftgmac100.c
45848 @@ -31,6 +31,8 @@
45849 #include <linux/netdevice.h>
45850 #include <linux/phy.h>
45851 #include <linux/platform_device.h>
45852 +#include <linux/interrupt.h>
45853 +#include <linux/irqreturn.h>
45854 #include <net/ip.h>
45855
45856 #include "ftgmac100.h"
45857 diff --git a/drivers/net/ethernet/faraday/ftmac100.c b/drivers/net/ethernet/faraday/ftmac100.c
45858 index 8be5b40..081bc1b 100644
45859 --- a/drivers/net/ethernet/faraday/ftmac100.c
45860 +++ b/drivers/net/ethernet/faraday/ftmac100.c
45861 @@ -31,6 +31,8 @@
45862 #include <linux/module.h>
45863 #include <linux/netdevice.h>
45864 #include <linux/platform_device.h>
45865 +#include <linux/interrupt.h>
45866 +#include <linux/irqreturn.h>
45867
45868 #include "ftmac100.h"
45869
45870 diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
45871 index 5184e2a..acb28c3 100644
45872 --- a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
45873 +++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
45874 @@ -776,7 +776,7 @@ void ixgbe_ptp_start_cyclecounter(struct ixgbe_adapter *adapter)
45875 }
45876
45877 /* update the base incval used to calculate frequency adjustment */
45878 - ACCESS_ONCE(adapter->base_incval) = incval;
45879 + ACCESS_ONCE_RW(adapter->base_incval) = incval;
45880 smp_mb();
45881
45882 /* need lock to prevent incorrect read while modifying cyclecounter */
45883 diff --git a/drivers/net/ethernet/neterion/vxge/vxge-config.c b/drivers/net/ethernet/neterion/vxge/vxge-config.c
45884 index fbe5363..266b4e3 100644
45885 --- a/drivers/net/ethernet/neterion/vxge/vxge-config.c
45886 +++ b/drivers/net/ethernet/neterion/vxge/vxge-config.c
45887 @@ -3461,7 +3461,10 @@ __vxge_hw_fifo_create(struct __vxge_hw_vpath_handle *vp,
45888 struct __vxge_hw_fifo *fifo;
45889 struct vxge_hw_fifo_config *config;
45890 u32 txdl_size, txdl_per_memblock;
45891 - struct vxge_hw_mempool_cbs fifo_mp_callback;
45892 + static struct vxge_hw_mempool_cbs fifo_mp_callback = {
45893 + .item_func_alloc = __vxge_hw_fifo_mempool_item_alloc,
45894 + };
45895 +
45896 struct __vxge_hw_virtualpath *vpath;
45897
45898 if ((vp == NULL) || (attr == NULL)) {
45899 @@ -3544,8 +3547,6 @@ __vxge_hw_fifo_create(struct __vxge_hw_vpath_handle *vp,
45900 goto exit;
45901 }
45902
45903 - fifo_mp_callback.item_func_alloc = __vxge_hw_fifo_mempool_item_alloc;
45904 -
45905 fifo->mempool =
45906 __vxge_hw_mempool_create(vpath->hldev,
45907 fifo->config->memblock_size,
45908 diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c
45909 index 918e18d..4ca3650 100644
45910 --- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c
45911 +++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c
45912 @@ -2086,7 +2086,9 @@ int qlcnic_83xx_configure_opmode(struct qlcnic_adapter *adapter)
45913 adapter->max_tx_rings = QLCNIC_MAX_VNIC_TX_RINGS;
45914 } else if (ret == QLC_83XX_DEFAULT_OPMODE) {
45915 ahw->nic_mode = QLCNIC_DEFAULT_MODE;
45916 - adapter->nic_ops->init_driver = qlcnic_83xx_init_default_driver;
45917 + pax_open_kernel();
45918 + *(void **)&adapter->nic_ops->init_driver = qlcnic_83xx_init_default_driver;
45919 + pax_close_kernel();
45920 ahw->idc.state_entry = qlcnic_83xx_idc_ready_state_entry;
45921 adapter->max_sds_rings = QLCNIC_MAX_SDS_RINGS;
45922 adapter->max_tx_rings = QLCNIC_MAX_TX_RINGS;
45923 diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c
45924 index 734d286..b017bf5 100644
45925 --- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c
45926 +++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c
45927 @@ -207,17 +207,23 @@ int qlcnic_83xx_config_vnic_opmode(struct qlcnic_adapter *adapter)
45928 case QLCNIC_NON_PRIV_FUNC:
45929 ahw->op_mode = QLCNIC_NON_PRIV_FUNC;
45930 ahw->idc.state_entry = qlcnic_83xx_idc_ready_state_entry;
45931 - nic_ops->init_driver = qlcnic_83xx_init_non_privileged_vnic;
45932 + pax_open_kernel();
45933 + *(void **)&nic_ops->init_driver = qlcnic_83xx_init_non_privileged_vnic;
45934 + pax_close_kernel();
45935 break;
45936 case QLCNIC_PRIV_FUNC:
45937 ahw->op_mode = QLCNIC_PRIV_FUNC;
45938 ahw->idc.state_entry = qlcnic_83xx_idc_vnic_pf_entry;
45939 - nic_ops->init_driver = qlcnic_83xx_init_privileged_vnic;
45940 + pax_open_kernel();
45941 + *(void **)&nic_ops->init_driver = qlcnic_83xx_init_privileged_vnic;
45942 + pax_close_kernel();
45943 break;
45944 case QLCNIC_MGMT_FUNC:
45945 ahw->op_mode = QLCNIC_MGMT_FUNC;
45946 ahw->idc.state_entry = qlcnic_83xx_idc_ready_state_entry;
45947 - nic_ops->init_driver = qlcnic_83xx_init_mgmt_vnic;
45948 + pax_open_kernel();
45949 + *(void **)&nic_ops->init_driver = qlcnic_83xx_init_mgmt_vnic;
45950 + pax_close_kernel();
45951 break;
45952 default:
45953 dev_err(&adapter->pdev->dev, "Invalid Virtual NIC opmode\n");
45954 diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_minidump.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_minidump.c
45955 index 7763962..c3499a7 100644
45956 --- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_minidump.c
45957 +++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_minidump.c
45958 @@ -1108,7 +1108,7 @@ int qlcnic_dump_fw(struct qlcnic_adapter *adapter)
45959 struct qlcnic_dump_entry *entry;
45960 struct qlcnic_fw_dump *fw_dump = &adapter->ahw->fw_dump;
45961 struct qlcnic_dump_template_hdr *tmpl_hdr = fw_dump->tmpl_hdr;
45962 - static const struct qlcnic_dump_operations *fw_dump_ops;
45963 + const struct qlcnic_dump_operations *fw_dump_ops;
45964 struct device *dev = &adapter->pdev->dev;
45965 struct qlcnic_hardware_context *ahw;
45966 void *temp_buffer;
45967 diff --git a/drivers/net/ethernet/realtek/r8169.c b/drivers/net/ethernet/realtek/r8169.c
45968 index c737f0e..32b8682 100644
45969 --- a/drivers/net/ethernet/realtek/r8169.c
45970 +++ b/drivers/net/ethernet/realtek/r8169.c
45971 @@ -759,22 +759,22 @@ struct rtl8169_private {
45972 struct mdio_ops {
45973 void (*write)(struct rtl8169_private *, int, int);
45974 int (*read)(struct rtl8169_private *, int);
45975 - } mdio_ops;
45976 + } __no_const mdio_ops;
45977
45978 struct pll_power_ops {
45979 void (*down)(struct rtl8169_private *);
45980 void (*up)(struct rtl8169_private *);
45981 - } pll_power_ops;
45982 + } __no_const pll_power_ops;
45983
45984 struct jumbo_ops {
45985 void (*enable)(struct rtl8169_private *);
45986 void (*disable)(struct rtl8169_private *);
45987 - } jumbo_ops;
45988 + } __no_const jumbo_ops;
45989
45990 struct csi_ops {
45991 void (*write)(struct rtl8169_private *, int, int);
45992 u32 (*read)(struct rtl8169_private *, int);
45993 - } csi_ops;
45994 + } __no_const csi_ops;
45995
45996 int (*set_speed)(struct net_device *, u8 aneg, u16 sp, u8 dpx, u32 adv);
45997 int (*get_settings)(struct net_device *, struct ethtool_cmd *);
45998 diff --git a/drivers/net/ethernet/sfc/ptp.c b/drivers/net/ethernet/sfc/ptp.c
45999 index a124103..59c74f8 100644
46000 --- a/drivers/net/ethernet/sfc/ptp.c
46001 +++ b/drivers/net/ethernet/sfc/ptp.c
46002 @@ -541,7 +541,7 @@ static int efx_ptp_synchronize(struct efx_nic *efx, unsigned int num_readings)
46003 ptp->start.dma_addr);
46004
46005 /* Clear flag that signals MC ready */
46006 - ACCESS_ONCE(*start) = 0;
46007 + ACCESS_ONCE_RW(*start) = 0;
46008 rc = efx_mcdi_rpc_start(efx, MC_CMD_PTP, synch_buf,
46009 MC_CMD_PTP_IN_SYNCHRONIZE_LEN);
46010 EFX_BUG_ON_PARANOID(rc);
46011 diff --git a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
46012 index 50617c5..b13724c 100644
46013 --- a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
46014 +++ b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
46015 @@ -140,8 +140,8 @@ void dwmac_mmc_ctrl(void __iomem *ioaddr, unsigned int mode)
46016
46017 writel(value, ioaddr + MMC_CNTRL);
46018
46019 - pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
46020 - MMC_CNTRL, value);
46021 +// pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
46022 +// MMC_CNTRL, value);
46023 }
46024
46025 /* To mask all all interrupts.*/
46026 diff --git a/drivers/net/hyperv/hyperv_net.h b/drivers/net/hyperv/hyperv_net.h
46027 index e6fe0d8..2b7d752 100644
46028 --- a/drivers/net/hyperv/hyperv_net.h
46029 +++ b/drivers/net/hyperv/hyperv_net.h
46030 @@ -101,7 +101,7 @@ struct rndis_device {
46031
46032 enum rndis_device_state state;
46033 bool link_state;
46034 - atomic_t new_req_id;
46035 + atomic_unchecked_t new_req_id;
46036
46037 spinlock_t request_lock;
46038 struct list_head req_list;
46039 diff --git a/drivers/net/hyperv/rndis_filter.c b/drivers/net/hyperv/rndis_filter.c
46040 index 0775f0a..d4fb316 100644
46041 --- a/drivers/net/hyperv/rndis_filter.c
46042 +++ b/drivers/net/hyperv/rndis_filter.c
46043 @@ -104,7 +104,7 @@ static struct rndis_request *get_rndis_request(struct rndis_device *dev,
46044 * template
46045 */
46046 set = &rndis_msg->msg.set_req;
46047 - set->req_id = atomic_inc_return(&dev->new_req_id);
46048 + set->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
46049
46050 /* Add to the request list */
46051 spin_lock_irqsave(&dev->request_lock, flags);
46052 @@ -752,7 +752,7 @@ static void rndis_filter_halt_device(struct rndis_device *dev)
46053
46054 /* Setup the rndis set */
46055 halt = &request->request_msg.msg.halt_req;
46056 - halt->req_id = atomic_inc_return(&dev->new_req_id);
46057 + halt->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
46058
46059 /* Ignore return since this msg is optional. */
46060 rndis_filter_send_request(dev, request);
46061 diff --git a/drivers/net/ieee802154/fakehard.c b/drivers/net/ieee802154/fakehard.c
46062 index bf0d55e..82bcfbd1 100644
46063 --- a/drivers/net/ieee802154/fakehard.c
46064 +++ b/drivers/net/ieee802154/fakehard.c
46065 @@ -364,7 +364,7 @@ static int ieee802154fake_probe(struct platform_device *pdev)
46066 phy->transmit_power = 0xbf;
46067
46068 dev->netdev_ops = &fake_ops;
46069 - dev->ml_priv = &fake_mlme;
46070 + dev->ml_priv = (void *)&fake_mlme;
46071
46072 priv = netdev_priv(dev);
46073 priv->phy = phy;
46074 diff --git a/drivers/net/macvlan.c b/drivers/net/macvlan.c
46075 index d7e2907..1f8bfee 100644
46076 --- a/drivers/net/macvlan.c
46077 +++ b/drivers/net/macvlan.c
46078 @@ -993,13 +993,15 @@ static const struct nla_policy macvlan_policy[IFLA_MACVLAN_MAX + 1] = {
46079 int macvlan_link_register(struct rtnl_link_ops *ops)
46080 {
46081 /* common fields */
46082 - ops->priv_size = sizeof(struct macvlan_dev);
46083 - ops->validate = macvlan_validate;
46084 - ops->maxtype = IFLA_MACVLAN_MAX;
46085 - ops->policy = macvlan_policy;
46086 - ops->changelink = macvlan_changelink;
46087 - ops->get_size = macvlan_get_size;
46088 - ops->fill_info = macvlan_fill_info;
46089 + pax_open_kernel();
46090 + *(size_t *)&ops->priv_size = sizeof(struct macvlan_dev);
46091 + *(void **)&ops->validate = macvlan_validate;
46092 + *(int *)&ops->maxtype = IFLA_MACVLAN_MAX;
46093 + *(const void **)&ops->policy = macvlan_policy;
46094 + *(void **)&ops->changelink = macvlan_changelink;
46095 + *(void **)&ops->get_size = macvlan_get_size;
46096 + *(void **)&ops->fill_info = macvlan_fill_info;
46097 + pax_close_kernel();
46098
46099 return rtnl_link_register(ops);
46100 };
46101 @@ -1054,7 +1056,7 @@ static int macvlan_device_event(struct notifier_block *unused,
46102 return NOTIFY_DONE;
46103 }
46104
46105 -static struct notifier_block macvlan_notifier_block __read_mostly = {
46106 +static struct notifier_block macvlan_notifier_block = {
46107 .notifier_call = macvlan_device_event,
46108 };
46109
46110 diff --git a/drivers/net/macvtap.c b/drivers/net/macvtap.c
46111 index 2a89da0..c17fe1d 100644
46112 --- a/drivers/net/macvtap.c
46113 +++ b/drivers/net/macvtap.c
46114 @@ -1012,7 +1012,7 @@ static long macvtap_ioctl(struct file *file, unsigned int cmd,
46115 }
46116
46117 ret = 0;
46118 - if (copy_to_user(&ifr->ifr_name, vlan->dev->name, IFNAMSIZ) ||
46119 + if (copy_to_user(ifr->ifr_name, vlan->dev->name, IFNAMSIZ) ||
46120 put_user(q->flags, &ifr->ifr_flags))
46121 ret = -EFAULT;
46122 macvtap_put_vlan(vlan);
46123 @@ -1182,7 +1182,7 @@ static int macvtap_device_event(struct notifier_block *unused,
46124 return NOTIFY_DONE;
46125 }
46126
46127 -static struct notifier_block macvtap_notifier_block __read_mostly = {
46128 +static struct notifier_block macvtap_notifier_block = {
46129 .notifier_call = macvtap_device_event,
46130 };
46131
46132 diff --git a/drivers/net/phy/mdio-bitbang.c b/drivers/net/phy/mdio-bitbang.c
46133 index daec9b0..6428fcb 100644
46134 --- a/drivers/net/phy/mdio-bitbang.c
46135 +++ b/drivers/net/phy/mdio-bitbang.c
46136 @@ -234,6 +234,7 @@ void free_mdio_bitbang(struct mii_bus *bus)
46137 struct mdiobb_ctrl *ctrl = bus->priv;
46138
46139 module_put(ctrl->ops->owner);
46140 + mdiobus_unregister(bus);
46141 mdiobus_free(bus);
46142 }
46143 EXPORT_SYMBOL(free_mdio_bitbang);
46144 diff --git a/drivers/net/ppp/ppp_generic.c b/drivers/net/ppp/ppp_generic.c
46145 index 72ff14b..11d442d 100644
46146 --- a/drivers/net/ppp/ppp_generic.c
46147 +++ b/drivers/net/ppp/ppp_generic.c
46148 @@ -999,7 +999,6 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
46149 void __user *addr = (void __user *) ifr->ifr_ifru.ifru_data;
46150 struct ppp_stats stats;
46151 struct ppp_comp_stats cstats;
46152 - char *vers;
46153
46154 switch (cmd) {
46155 case SIOCGPPPSTATS:
46156 @@ -1021,8 +1020,7 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
46157 break;
46158
46159 case SIOCGPPPVER:
46160 - vers = PPP_VERSION;
46161 - if (copy_to_user(addr, vers, strlen(vers) + 1))
46162 + if (copy_to_user(addr, PPP_VERSION, sizeof(PPP_VERSION)))
46163 break;
46164 err = 0;
46165 break;
46166 diff --git a/drivers/net/slip/slhc.c b/drivers/net/slip/slhc.c
46167 index 1252d9c..80e660b 100644
46168 --- a/drivers/net/slip/slhc.c
46169 +++ b/drivers/net/slip/slhc.c
46170 @@ -488,7 +488,7 @@ slhc_uncompress(struct slcompress *comp, unsigned char *icp, int isize)
46171 register struct tcphdr *thp;
46172 register struct iphdr *ip;
46173 register struct cstate *cs;
46174 - int len, hdrlen;
46175 + long len, hdrlen;
46176 unsigned char *cp = icp;
46177
46178 /* We've got a compressed packet; read the change byte */
46179 diff --git a/drivers/net/team/team.c b/drivers/net/team/team.c
46180 index b75ae5b..953c157 100644
46181 --- a/drivers/net/team/team.c
46182 +++ b/drivers/net/team/team.c
46183 @@ -2865,7 +2865,7 @@ static int team_device_event(struct notifier_block *unused,
46184 return NOTIFY_DONE;
46185 }
46186
46187 -static struct notifier_block team_notifier_block __read_mostly = {
46188 +static struct notifier_block team_notifier_block = {
46189 .notifier_call = team_device_event,
46190 };
46191
46192 diff --git a/drivers/net/tun.c b/drivers/net/tun.c
46193 index 55c9238..ebb6ee5 100644
46194 --- a/drivers/net/tun.c
46195 +++ b/drivers/net/tun.c
46196 @@ -1841,7 +1841,7 @@ unlock:
46197 }
46198
46199 static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
46200 - unsigned long arg, int ifreq_len)
46201 + unsigned long arg, size_t ifreq_len)
46202 {
46203 struct tun_file *tfile = file->private_data;
46204 struct tun_struct *tun;
46205 @@ -1854,6 +1854,9 @@ static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
46206 unsigned int ifindex;
46207 int ret;
46208
46209 + if (ifreq_len > sizeof ifr)
46210 + return -EFAULT;
46211 +
46212 if (cmd == TUNSETIFF || cmd == TUNSETQUEUE || _IOC_TYPE(cmd) == 0x89) {
46213 if (copy_from_user(&ifr, argp, ifreq_len))
46214 return -EFAULT;
46215 diff --git a/drivers/net/usb/hso.c b/drivers/net/usb/hso.c
46216 index 1a48234..a555339 100644
46217 --- a/drivers/net/usb/hso.c
46218 +++ b/drivers/net/usb/hso.c
46219 @@ -71,7 +71,7 @@
46220 #include <asm/byteorder.h>
46221 #include <linux/serial_core.h>
46222 #include <linux/serial.h>
46223 -
46224 +#include <asm/local.h>
46225
46226 #define MOD_AUTHOR "Option Wireless"
46227 #define MOD_DESCRIPTION "USB High Speed Option driver"
46228 @@ -1179,7 +1179,7 @@ static void put_rxbuf_data_and_resubmit_ctrl_urb(struct hso_serial *serial)
46229 struct urb *urb;
46230
46231 urb = serial->rx_urb[0];
46232 - if (serial->port.count > 0) {
46233 + if (atomic_read(&serial->port.count) > 0) {
46234 count = put_rxbuf_data(urb, serial);
46235 if (count == -1)
46236 return;
46237 @@ -1215,7 +1215,7 @@ static void hso_std_serial_read_bulk_callback(struct urb *urb)
46238 DUMP1(urb->transfer_buffer, urb->actual_length);
46239
46240 /* Anyone listening? */
46241 - if (serial->port.count == 0)
46242 + if (atomic_read(&serial->port.count) == 0)
46243 return;
46244
46245 if (status == 0) {
46246 @@ -1297,8 +1297,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
46247 tty_port_tty_set(&serial->port, tty);
46248
46249 /* check for port already opened, if not set the termios */
46250 - serial->port.count++;
46251 - if (serial->port.count == 1) {
46252 + if (atomic_inc_return(&serial->port.count) == 1) {
46253 serial->rx_state = RX_IDLE;
46254 /* Force default termio settings */
46255 _hso_serial_set_termios(tty, NULL);
46256 @@ -1310,7 +1309,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
46257 result = hso_start_serial_device(serial->parent, GFP_KERNEL);
46258 if (result) {
46259 hso_stop_serial_device(serial->parent);
46260 - serial->port.count--;
46261 + atomic_dec(&serial->port.count);
46262 kref_put(&serial->parent->ref, hso_serial_ref_free);
46263 }
46264 } else {
46265 @@ -1347,10 +1346,10 @@ static void hso_serial_close(struct tty_struct *tty, struct file *filp)
46266
46267 /* reset the rts and dtr */
46268 /* do the actual close */
46269 - serial->port.count--;
46270 + atomic_dec(&serial->port.count);
46271
46272 - if (serial->port.count <= 0) {
46273 - serial->port.count = 0;
46274 + if (atomic_read(&serial->port.count) <= 0) {
46275 + atomic_set(&serial->port.count, 0);
46276 tty_port_tty_set(&serial->port, NULL);
46277 if (!usb_gone)
46278 hso_stop_serial_device(serial->parent);
46279 @@ -1426,7 +1425,7 @@ static void hso_serial_set_termios(struct tty_struct *tty, struct ktermios *old)
46280
46281 /* the actual setup */
46282 spin_lock_irqsave(&serial->serial_lock, flags);
46283 - if (serial->port.count)
46284 + if (atomic_read(&serial->port.count))
46285 _hso_serial_set_termios(tty, old);
46286 else
46287 tty->termios = *old;
46288 @@ -1895,7 +1894,7 @@ static void intr_callback(struct urb *urb)
46289 D1("Pending read interrupt on port %d\n", i);
46290 spin_lock(&serial->serial_lock);
46291 if (serial->rx_state == RX_IDLE &&
46292 - serial->port.count > 0) {
46293 + atomic_read(&serial->port.count) > 0) {
46294 /* Setup and send a ctrl req read on
46295 * port i */
46296 if (!serial->rx_urb_filled[0]) {
46297 @@ -3071,7 +3070,7 @@ static int hso_resume(struct usb_interface *iface)
46298 /* Start all serial ports */
46299 for (i = 0; i < HSO_SERIAL_TTY_MINORS; i++) {
46300 if (serial_table[i] && (serial_table[i]->interface == iface)) {
46301 - if (dev2ser(serial_table[i])->port.count) {
46302 + if (atomic_read(&dev2ser(serial_table[i])->port.count)) {
46303 result =
46304 hso_start_serial_device(serial_table[i], GFP_NOIO);
46305 hso_kick_transmit(dev2ser(serial_table[i]));
46306 diff --git a/drivers/net/usb/sierra_net.c b/drivers/net/usb/sierra_net.c
46307 index a79e9d3..78cd4fa 100644
46308 --- a/drivers/net/usb/sierra_net.c
46309 +++ b/drivers/net/usb/sierra_net.c
46310 @@ -52,7 +52,7 @@ static const char driver_name[] = "sierra_net";
46311 /* atomic counter partially included in MAC address to make sure 2 devices
46312 * do not end up with the same MAC - concept breaks in case of > 255 ifaces
46313 */
46314 -static atomic_t iface_counter = ATOMIC_INIT(0);
46315 +static atomic_unchecked_t iface_counter = ATOMIC_INIT(0);
46316
46317 /*
46318 * SYNC Timer Delay definition used to set the expiry time
46319 @@ -698,7 +698,7 @@ static int sierra_net_bind(struct usbnet *dev, struct usb_interface *intf)
46320 dev->net->netdev_ops = &sierra_net_device_ops;
46321
46322 /* change MAC addr to include, ifacenum, and to be unique */
46323 - dev->net->dev_addr[ETH_ALEN-2] = atomic_inc_return(&iface_counter);
46324 + dev->net->dev_addr[ETH_ALEN-2] = atomic_inc_return_unchecked(&iface_counter);
46325 dev->net->dev_addr[ETH_ALEN-1] = ifacenum;
46326
46327 /* we will have to manufacture ethernet headers, prepare template */
46328 diff --git a/drivers/net/vxlan.c b/drivers/net/vxlan.c
46329 index fc5d2b7..48e2984 100644
46330 --- a/drivers/net/vxlan.c
46331 +++ b/drivers/net/vxlan.c
46332 @@ -2721,7 +2721,7 @@ nla_put_failure:
46333 return -EMSGSIZE;
46334 }
46335
46336 -static struct rtnl_link_ops vxlan_link_ops __read_mostly = {
46337 +static struct rtnl_link_ops vxlan_link_ops = {
46338 .kind = "vxlan",
46339 .maxtype = IFLA_VXLAN_MAX,
46340 .policy = vxlan_policy,
46341 diff --git a/drivers/net/wan/lmc/lmc_media.c b/drivers/net/wan/lmc/lmc_media.c
46342 index 5920c99..ff2e4a5 100644
46343 --- a/drivers/net/wan/lmc/lmc_media.c
46344 +++ b/drivers/net/wan/lmc/lmc_media.c
46345 @@ -95,62 +95,63 @@ static inline void write_av9110_bit (lmc_softc_t *, int);
46346 static void write_av9110(lmc_softc_t *, u32, u32, u32, u32, u32);
46347
46348 lmc_media_t lmc_ds3_media = {
46349 - lmc_ds3_init, /* special media init stuff */
46350 - lmc_ds3_default, /* reset to default state */
46351 - lmc_ds3_set_status, /* reset status to state provided */
46352 - lmc_dummy_set_1, /* set clock source */
46353 - lmc_dummy_set2_1, /* set line speed */
46354 - lmc_ds3_set_100ft, /* set cable length */
46355 - lmc_ds3_set_scram, /* set scrambler */
46356 - lmc_ds3_get_link_status, /* get link status */
46357 - lmc_dummy_set_1, /* set link status */
46358 - lmc_ds3_set_crc_length, /* set CRC length */
46359 - lmc_dummy_set_1, /* set T1 or E1 circuit type */
46360 - lmc_ds3_watchdog
46361 + .init = lmc_ds3_init, /* special media init stuff */
46362 + .defaults = lmc_ds3_default, /* reset to default state */
46363 + .set_status = lmc_ds3_set_status, /* reset status to state provided */
46364 + .set_clock_source = lmc_dummy_set_1, /* set clock source */
46365 + .set_speed = lmc_dummy_set2_1, /* set line speed */
46366 + .set_cable_length = lmc_ds3_set_100ft, /* set cable length */
46367 + .set_scrambler = lmc_ds3_set_scram, /* set scrambler */
46368 + .get_link_status = lmc_ds3_get_link_status, /* get link status */
46369 + .set_link_status = lmc_dummy_set_1, /* set link status */
46370 + .set_crc_length = lmc_ds3_set_crc_length, /* set CRC length */
46371 + .set_circuit_type = lmc_dummy_set_1, /* set T1 or E1 circuit type */
46372 + .watchdog = lmc_ds3_watchdog
46373 };
46374
46375 lmc_media_t lmc_hssi_media = {
46376 - lmc_hssi_init, /* special media init stuff */
46377 - lmc_hssi_default, /* reset to default state */
46378 - lmc_hssi_set_status, /* reset status to state provided */
46379 - lmc_hssi_set_clock, /* set clock source */
46380 - lmc_dummy_set2_1, /* set line speed */
46381 - lmc_dummy_set_1, /* set cable length */
46382 - lmc_dummy_set_1, /* set scrambler */
46383 - lmc_hssi_get_link_status, /* get link status */
46384 - lmc_hssi_set_link_status, /* set link status */
46385 - lmc_hssi_set_crc_length, /* set CRC length */
46386 - lmc_dummy_set_1, /* set T1 or E1 circuit type */
46387 - lmc_hssi_watchdog
46388 + .init = lmc_hssi_init, /* special media init stuff */
46389 + .defaults = lmc_hssi_default, /* reset to default state */
46390 + .set_status = lmc_hssi_set_status, /* reset status to state provided */
46391 + .set_clock_source = lmc_hssi_set_clock, /* set clock source */
46392 + .set_speed = lmc_dummy_set2_1, /* set line speed */
46393 + .set_cable_length = lmc_dummy_set_1, /* set cable length */
46394 + .set_scrambler = lmc_dummy_set_1, /* set scrambler */
46395 + .get_link_status = lmc_hssi_get_link_status, /* get link status */
46396 + .set_link_status = lmc_hssi_set_link_status, /* set link status */
46397 + .set_crc_length = lmc_hssi_set_crc_length, /* set CRC length */
46398 + .set_circuit_type = lmc_dummy_set_1, /* set T1 or E1 circuit type */
46399 + .watchdog = lmc_hssi_watchdog
46400 };
46401
46402 -lmc_media_t lmc_ssi_media = { lmc_ssi_init, /* special media init stuff */
46403 - lmc_ssi_default, /* reset to default state */
46404 - lmc_ssi_set_status, /* reset status to state provided */
46405 - lmc_ssi_set_clock, /* set clock source */
46406 - lmc_ssi_set_speed, /* set line speed */
46407 - lmc_dummy_set_1, /* set cable length */
46408 - lmc_dummy_set_1, /* set scrambler */
46409 - lmc_ssi_get_link_status, /* get link status */
46410 - lmc_ssi_set_link_status, /* set link status */
46411 - lmc_ssi_set_crc_length, /* set CRC length */
46412 - lmc_dummy_set_1, /* set T1 or E1 circuit type */
46413 - lmc_ssi_watchdog
46414 +lmc_media_t lmc_ssi_media = {
46415 + .init = lmc_ssi_init, /* special media init stuff */
46416 + .defaults = lmc_ssi_default, /* reset to default state */
46417 + .set_status = lmc_ssi_set_status, /* reset status to state provided */
46418 + .set_clock_source = lmc_ssi_set_clock, /* set clock source */
46419 + .set_speed = lmc_ssi_set_speed, /* set line speed */
46420 + .set_cable_length = lmc_dummy_set_1, /* set cable length */
46421 + .set_scrambler = lmc_dummy_set_1, /* set scrambler */
46422 + .get_link_status = lmc_ssi_get_link_status, /* get link status */
46423 + .set_link_status = lmc_ssi_set_link_status, /* set link status */
46424 + .set_crc_length = lmc_ssi_set_crc_length, /* set CRC length */
46425 + .set_circuit_type = lmc_dummy_set_1, /* set T1 or E1 circuit type */
46426 + .watchdog = lmc_ssi_watchdog
46427 };
46428
46429 lmc_media_t lmc_t1_media = {
46430 - lmc_t1_init, /* special media init stuff */
46431 - lmc_t1_default, /* reset to default state */
46432 - lmc_t1_set_status, /* reset status to state provided */
46433 - lmc_t1_set_clock, /* set clock source */
46434 - lmc_dummy_set2_1, /* set line speed */
46435 - lmc_dummy_set_1, /* set cable length */
46436 - lmc_dummy_set_1, /* set scrambler */
46437 - lmc_t1_get_link_status, /* get link status */
46438 - lmc_dummy_set_1, /* set link status */
46439 - lmc_t1_set_crc_length, /* set CRC length */
46440 - lmc_t1_set_circuit_type, /* set T1 or E1 circuit type */
46441 - lmc_t1_watchdog
46442 + .init = lmc_t1_init, /* special media init stuff */
46443 + .defaults = lmc_t1_default, /* reset to default state */
46444 + .set_status = lmc_t1_set_status, /* reset status to state provided */
46445 + .set_clock_source = lmc_t1_set_clock, /* set clock source */
46446 + .set_speed = lmc_dummy_set2_1, /* set line speed */
46447 + .set_cable_length = lmc_dummy_set_1, /* set cable length */
46448 + .set_scrambler = lmc_dummy_set_1, /* set scrambler */
46449 + .get_link_status = lmc_t1_get_link_status, /* get link status */
46450 + .set_link_status = lmc_dummy_set_1, /* set link status */
46451 + .set_crc_length = lmc_t1_set_crc_length, /* set CRC length */
46452 + .set_circuit_type = lmc_t1_set_circuit_type, /* set T1 or E1 circuit type */
46453 + .watchdog = lmc_t1_watchdog
46454 };
46455
46456 static void
46457 diff --git a/drivers/net/wan/z85230.c b/drivers/net/wan/z85230.c
46458 index feacc3b..5bac0de 100644
46459 --- a/drivers/net/wan/z85230.c
46460 +++ b/drivers/net/wan/z85230.c
46461 @@ -485,9 +485,9 @@ static void z8530_status(struct z8530_channel *chan)
46462
46463 struct z8530_irqhandler z8530_sync =
46464 {
46465 - z8530_rx,
46466 - z8530_tx,
46467 - z8530_status
46468 + .rx = z8530_rx,
46469 + .tx = z8530_tx,
46470 + .status = z8530_status
46471 };
46472
46473 EXPORT_SYMBOL(z8530_sync);
46474 @@ -605,15 +605,15 @@ static void z8530_dma_status(struct z8530_channel *chan)
46475 }
46476
46477 static struct z8530_irqhandler z8530_dma_sync = {
46478 - z8530_dma_rx,
46479 - z8530_dma_tx,
46480 - z8530_dma_status
46481 + .rx = z8530_dma_rx,
46482 + .tx = z8530_dma_tx,
46483 + .status = z8530_dma_status
46484 };
46485
46486 static struct z8530_irqhandler z8530_txdma_sync = {
46487 - z8530_rx,
46488 - z8530_dma_tx,
46489 - z8530_dma_status
46490 + .rx = z8530_rx,
46491 + .tx = z8530_dma_tx,
46492 + .status = z8530_dma_status
46493 };
46494
46495 /**
46496 @@ -680,9 +680,9 @@ static void z8530_status_clear(struct z8530_channel *chan)
46497
46498 struct z8530_irqhandler z8530_nop=
46499 {
46500 - z8530_rx_clear,
46501 - z8530_tx_clear,
46502 - z8530_status_clear
46503 + .rx = z8530_rx_clear,
46504 + .tx = z8530_tx_clear,
46505 + .status = z8530_status_clear
46506 };
46507
46508
46509 diff --git a/drivers/net/wimax/i2400m/rx.c b/drivers/net/wimax/i2400m/rx.c
46510 index 0b60295..b8bfa5b 100644
46511 --- a/drivers/net/wimax/i2400m/rx.c
46512 +++ b/drivers/net/wimax/i2400m/rx.c
46513 @@ -1359,7 +1359,7 @@ int i2400m_rx_setup(struct i2400m *i2400m)
46514 if (i2400m->rx_roq == NULL)
46515 goto error_roq_alloc;
46516
46517 - rd = kcalloc(I2400M_RO_CIN + 1, sizeof(*i2400m->rx_roq[0].log),
46518 + rd = kcalloc(sizeof(*i2400m->rx_roq[0].log), I2400M_RO_CIN + 1,
46519 GFP_KERNEL);
46520 if (rd == NULL) {
46521 result = -ENOMEM;
46522 diff --git a/drivers/net/wireless/airo.c b/drivers/net/wireless/airo.c
46523 index edf4b57..68b51c0 100644
46524 --- a/drivers/net/wireless/airo.c
46525 +++ b/drivers/net/wireless/airo.c
46526 @@ -7843,7 +7843,7 @@ static int writerids(struct net_device *dev, aironet_ioctl *comp) {
46527 struct airo_info *ai = dev->ml_priv;
46528 int ridcode;
46529 int enabled;
46530 - static int (* writer)(struct airo_info *, u16 rid, const void *, int, int);
46531 + int (* writer)(struct airo_info *, u16 rid, const void *, int, int);
46532 unsigned char *iobuf;
46533
46534 /* Only super-user can write RIDs */
46535 diff --git a/drivers/net/wireless/at76c50x-usb.c b/drivers/net/wireless/at76c50x-usb.c
46536 index 34c8a33..3261fdc 100644
46537 --- a/drivers/net/wireless/at76c50x-usb.c
46538 +++ b/drivers/net/wireless/at76c50x-usb.c
46539 @@ -353,7 +353,7 @@ static int at76_dfu_get_state(struct usb_device *udev, u8 *state)
46540 }
46541
46542 /* Convert timeout from the DFU status to jiffies */
46543 -static inline unsigned long at76_get_timeout(struct dfu_status *s)
46544 +static inline unsigned long __intentional_overflow(-1) at76_get_timeout(struct dfu_status *s)
46545 {
46546 return msecs_to_jiffies((s->poll_timeout[2] << 16)
46547 | (s->poll_timeout[1] << 8)
46548 diff --git a/drivers/net/wireless/ath/ath10k/htc.c b/drivers/net/wireless/ath/ath10k/htc.c
46549 index edae50b..b24278c 100644
46550 --- a/drivers/net/wireless/ath/ath10k/htc.c
46551 +++ b/drivers/net/wireless/ath/ath10k/htc.c
46552 @@ -842,7 +842,10 @@ void ath10k_htc_stop(struct ath10k_htc *htc)
46553 /* registered target arrival callback from the HIF layer */
46554 int ath10k_htc_init(struct ath10k *ar)
46555 {
46556 - struct ath10k_hif_cb htc_callbacks;
46557 + static struct ath10k_hif_cb htc_callbacks = {
46558 + .rx_completion = ath10k_htc_rx_completion_handler,
46559 + .tx_completion = ath10k_htc_tx_completion_handler,
46560 + };
46561 struct ath10k_htc_ep *ep = NULL;
46562 struct ath10k_htc *htc = &ar->htc;
46563
46564 @@ -852,8 +855,6 @@ int ath10k_htc_init(struct ath10k *ar)
46565 ath10k_htc_reset_endpoint_states(htc);
46566
46567 /* setup HIF layer callbacks */
46568 - htc_callbacks.rx_completion = ath10k_htc_rx_completion_handler;
46569 - htc_callbacks.tx_completion = ath10k_htc_tx_completion_handler;
46570 htc->ar = ar;
46571
46572 /* Get HIF default pipe for HTC message exchange */
46573 diff --git a/drivers/net/wireless/ath/ath10k/htc.h b/drivers/net/wireless/ath/ath10k/htc.h
46574 index 4716d33..a688310 100644
46575 --- a/drivers/net/wireless/ath/ath10k/htc.h
46576 +++ b/drivers/net/wireless/ath/ath10k/htc.h
46577 @@ -271,13 +271,13 @@ enum ath10k_htc_ep_id {
46578
46579 struct ath10k_htc_ops {
46580 void (*target_send_suspend_complete)(struct ath10k *ar);
46581 -};
46582 +} __no_const;
46583
46584 struct ath10k_htc_ep_ops {
46585 void (*ep_tx_complete)(struct ath10k *, struct sk_buff *);
46586 void (*ep_rx_complete)(struct ath10k *, struct sk_buff *);
46587 void (*ep_tx_credits)(struct ath10k *);
46588 -};
46589 +} __no_const;
46590
46591 /* service connection information */
46592 struct ath10k_htc_svc_conn_req {
46593 diff --git a/drivers/net/wireless/ath/ath9k/ar9002_mac.c b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
46594 index a366d6b..b6f28f8 100644
46595 --- a/drivers/net/wireless/ath/ath9k/ar9002_mac.c
46596 +++ b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
46597 @@ -218,8 +218,8 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
46598 ads->ds_txstatus6 = ads->ds_txstatus7 = 0;
46599 ads->ds_txstatus8 = ads->ds_txstatus9 = 0;
46600
46601 - ACCESS_ONCE(ads->ds_link) = i->link;
46602 - ACCESS_ONCE(ads->ds_data) = i->buf_addr[0];
46603 + ACCESS_ONCE_RW(ads->ds_link) = i->link;
46604 + ACCESS_ONCE_RW(ads->ds_data) = i->buf_addr[0];
46605
46606 ctl1 = i->buf_len[0] | (i->is_last ? 0 : AR_TxMore);
46607 ctl6 = SM(i->keytype, AR_EncrType);
46608 @@ -233,26 +233,26 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
46609
46610 if ((i->is_first || i->is_last) &&
46611 i->aggr != AGGR_BUF_MIDDLE && i->aggr != AGGR_BUF_LAST) {
46612 - ACCESS_ONCE(ads->ds_ctl2) = set11nTries(i->rates, 0)
46613 + ACCESS_ONCE_RW(ads->ds_ctl2) = set11nTries(i->rates, 0)
46614 | set11nTries(i->rates, 1)
46615 | set11nTries(i->rates, 2)
46616 | set11nTries(i->rates, 3)
46617 | (i->dur_update ? AR_DurUpdateEna : 0)
46618 | SM(0, AR_BurstDur);
46619
46620 - ACCESS_ONCE(ads->ds_ctl3) = set11nRate(i->rates, 0)
46621 + ACCESS_ONCE_RW(ads->ds_ctl3) = set11nRate(i->rates, 0)
46622 | set11nRate(i->rates, 1)
46623 | set11nRate(i->rates, 2)
46624 | set11nRate(i->rates, 3);
46625 } else {
46626 - ACCESS_ONCE(ads->ds_ctl2) = 0;
46627 - ACCESS_ONCE(ads->ds_ctl3) = 0;
46628 + ACCESS_ONCE_RW(ads->ds_ctl2) = 0;
46629 + ACCESS_ONCE_RW(ads->ds_ctl3) = 0;
46630 }
46631
46632 if (!i->is_first) {
46633 - ACCESS_ONCE(ads->ds_ctl0) = 0;
46634 - ACCESS_ONCE(ads->ds_ctl1) = ctl1;
46635 - ACCESS_ONCE(ads->ds_ctl6) = ctl6;
46636 + ACCESS_ONCE_RW(ads->ds_ctl0) = 0;
46637 + ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
46638 + ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
46639 return;
46640 }
46641
46642 @@ -277,7 +277,7 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
46643 break;
46644 }
46645
46646 - ACCESS_ONCE(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
46647 + ACCESS_ONCE_RW(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
46648 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
46649 | SM(i->txpower, AR_XmitPower)
46650 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
46651 @@ -287,19 +287,19 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
46652 | (i->flags & ATH9K_TXDESC_RTSENA ? AR_RTSEnable :
46653 (i->flags & ATH9K_TXDESC_CTSENA ? AR_CTSEnable : 0));
46654
46655 - ACCESS_ONCE(ads->ds_ctl1) = ctl1;
46656 - ACCESS_ONCE(ads->ds_ctl6) = ctl6;
46657 + ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
46658 + ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
46659
46660 if (i->aggr == AGGR_BUF_MIDDLE || i->aggr == AGGR_BUF_LAST)
46661 return;
46662
46663 - ACCESS_ONCE(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
46664 + ACCESS_ONCE_RW(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
46665 | set11nPktDurRTSCTS(i->rates, 1);
46666
46667 - ACCESS_ONCE(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
46668 + ACCESS_ONCE_RW(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
46669 | set11nPktDurRTSCTS(i->rates, 3);
46670
46671 - ACCESS_ONCE(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
46672 + ACCESS_ONCE_RW(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
46673 | set11nRateFlags(i->rates, 1)
46674 | set11nRateFlags(i->rates, 2)
46675 | set11nRateFlags(i->rates, 3)
46676 diff --git a/drivers/net/wireless/ath/ath9k/ar9003_mac.c b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
46677 index f6c5c1b..6058354 100644
46678 --- a/drivers/net/wireless/ath/ath9k/ar9003_mac.c
46679 +++ b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
46680 @@ -39,47 +39,47 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
46681 (i->qcu << AR_TxQcuNum_S) | desc_len;
46682
46683 checksum += val;
46684 - ACCESS_ONCE(ads->info) = val;
46685 + ACCESS_ONCE_RW(ads->info) = val;
46686
46687 checksum += i->link;
46688 - ACCESS_ONCE(ads->link) = i->link;
46689 + ACCESS_ONCE_RW(ads->link) = i->link;
46690
46691 checksum += i->buf_addr[0];
46692 - ACCESS_ONCE(ads->data0) = i->buf_addr[0];
46693 + ACCESS_ONCE_RW(ads->data0) = i->buf_addr[0];
46694 checksum += i->buf_addr[1];
46695 - ACCESS_ONCE(ads->data1) = i->buf_addr[1];
46696 + ACCESS_ONCE_RW(ads->data1) = i->buf_addr[1];
46697 checksum += i->buf_addr[2];
46698 - ACCESS_ONCE(ads->data2) = i->buf_addr[2];
46699 + ACCESS_ONCE_RW(ads->data2) = i->buf_addr[2];
46700 checksum += i->buf_addr[3];
46701 - ACCESS_ONCE(ads->data3) = i->buf_addr[3];
46702 + ACCESS_ONCE_RW(ads->data3) = i->buf_addr[3];
46703
46704 checksum += (val = (i->buf_len[0] << AR_BufLen_S) & AR_BufLen);
46705 - ACCESS_ONCE(ads->ctl3) = val;
46706 + ACCESS_ONCE_RW(ads->ctl3) = val;
46707 checksum += (val = (i->buf_len[1] << AR_BufLen_S) & AR_BufLen);
46708 - ACCESS_ONCE(ads->ctl5) = val;
46709 + ACCESS_ONCE_RW(ads->ctl5) = val;
46710 checksum += (val = (i->buf_len[2] << AR_BufLen_S) & AR_BufLen);
46711 - ACCESS_ONCE(ads->ctl7) = val;
46712 + ACCESS_ONCE_RW(ads->ctl7) = val;
46713 checksum += (val = (i->buf_len[3] << AR_BufLen_S) & AR_BufLen);
46714 - ACCESS_ONCE(ads->ctl9) = val;
46715 + ACCESS_ONCE_RW(ads->ctl9) = val;
46716
46717 checksum = (u16) (((checksum & 0xffff) + (checksum >> 16)) & 0xffff);
46718 - ACCESS_ONCE(ads->ctl10) = checksum;
46719 + ACCESS_ONCE_RW(ads->ctl10) = checksum;
46720
46721 if (i->is_first || i->is_last) {
46722 - ACCESS_ONCE(ads->ctl13) = set11nTries(i->rates, 0)
46723 + ACCESS_ONCE_RW(ads->ctl13) = set11nTries(i->rates, 0)
46724 | set11nTries(i->rates, 1)
46725 | set11nTries(i->rates, 2)
46726 | set11nTries(i->rates, 3)
46727 | (i->dur_update ? AR_DurUpdateEna : 0)
46728 | SM(0, AR_BurstDur);
46729
46730 - ACCESS_ONCE(ads->ctl14) = set11nRate(i->rates, 0)
46731 + ACCESS_ONCE_RW(ads->ctl14) = set11nRate(i->rates, 0)
46732 | set11nRate(i->rates, 1)
46733 | set11nRate(i->rates, 2)
46734 | set11nRate(i->rates, 3);
46735 } else {
46736 - ACCESS_ONCE(ads->ctl13) = 0;
46737 - ACCESS_ONCE(ads->ctl14) = 0;
46738 + ACCESS_ONCE_RW(ads->ctl13) = 0;
46739 + ACCESS_ONCE_RW(ads->ctl14) = 0;
46740 }
46741
46742 ads->ctl20 = 0;
46743 @@ -89,17 +89,17 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
46744
46745 ctl17 = SM(i->keytype, AR_EncrType);
46746 if (!i->is_first) {
46747 - ACCESS_ONCE(ads->ctl11) = 0;
46748 - ACCESS_ONCE(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
46749 - ACCESS_ONCE(ads->ctl15) = 0;
46750 - ACCESS_ONCE(ads->ctl16) = 0;
46751 - ACCESS_ONCE(ads->ctl17) = ctl17;
46752 - ACCESS_ONCE(ads->ctl18) = 0;
46753 - ACCESS_ONCE(ads->ctl19) = 0;
46754 + ACCESS_ONCE_RW(ads->ctl11) = 0;
46755 + ACCESS_ONCE_RW(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
46756 + ACCESS_ONCE_RW(ads->ctl15) = 0;
46757 + ACCESS_ONCE_RW(ads->ctl16) = 0;
46758 + ACCESS_ONCE_RW(ads->ctl17) = ctl17;
46759 + ACCESS_ONCE_RW(ads->ctl18) = 0;
46760 + ACCESS_ONCE_RW(ads->ctl19) = 0;
46761 return;
46762 }
46763
46764 - ACCESS_ONCE(ads->ctl11) = (i->pkt_len & AR_FrameLen)
46765 + ACCESS_ONCE_RW(ads->ctl11) = (i->pkt_len & AR_FrameLen)
46766 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
46767 | SM(i->txpower, AR_XmitPower)
46768 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
46769 @@ -135,22 +135,22 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
46770 val = (i->flags & ATH9K_TXDESC_PAPRD) >> ATH9K_TXDESC_PAPRD_S;
46771 ctl12 |= SM(val, AR_PAPRDChainMask);
46772
46773 - ACCESS_ONCE(ads->ctl12) = ctl12;
46774 - ACCESS_ONCE(ads->ctl17) = ctl17;
46775 + ACCESS_ONCE_RW(ads->ctl12) = ctl12;
46776 + ACCESS_ONCE_RW(ads->ctl17) = ctl17;
46777
46778 - ACCESS_ONCE(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
46779 + ACCESS_ONCE_RW(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
46780 | set11nPktDurRTSCTS(i->rates, 1);
46781
46782 - ACCESS_ONCE(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
46783 + ACCESS_ONCE_RW(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
46784 | set11nPktDurRTSCTS(i->rates, 3);
46785
46786 - ACCESS_ONCE(ads->ctl18) = set11nRateFlags(i->rates, 0)
46787 + ACCESS_ONCE_RW(ads->ctl18) = set11nRateFlags(i->rates, 0)
46788 | set11nRateFlags(i->rates, 1)
46789 | set11nRateFlags(i->rates, 2)
46790 | set11nRateFlags(i->rates, 3)
46791 | SM(i->rtscts_rate, AR_RTSCTSRate);
46792
46793 - ACCESS_ONCE(ads->ctl19) = AR_Not_Sounding;
46794 + ACCESS_ONCE_RW(ads->ctl19) = AR_Not_Sounding;
46795 }
46796
46797 static u16 ar9003_calc_ptr_chksum(struct ar9003_txc *ads)
46798 diff --git a/drivers/net/wireless/ath/ath9k/hw.h b/drivers/net/wireless/ath/ath9k/hw.h
46799 index a2c9a5d..b52273e 100644
46800 --- a/drivers/net/wireless/ath/ath9k/hw.h
46801 +++ b/drivers/net/wireless/ath/ath9k/hw.h
46802 @@ -635,7 +635,7 @@ struct ath_hw_private_ops {
46803
46804 /* ANI */
46805 void (*ani_cache_ini_regs)(struct ath_hw *ah);
46806 -};
46807 +} __no_const;
46808
46809 /**
46810 * struct ath_spec_scan - parameters for Atheros spectral scan
46811 @@ -711,7 +711,7 @@ struct ath_hw_ops {
46812 #ifdef CONFIG_ATH9K_BTCOEX_SUPPORT
46813 void (*set_bt_ant_diversity)(struct ath_hw *hw, bool enable);
46814 #endif
46815 -};
46816 +} __no_const;
46817
46818 struct ath_nf_limits {
46819 s16 max;
46820 diff --git a/drivers/net/wireless/b43/phy_lp.c b/drivers/net/wireless/b43/phy_lp.c
46821 index 92190da..f3a4c4c 100644
46822 --- a/drivers/net/wireless/b43/phy_lp.c
46823 +++ b/drivers/net/wireless/b43/phy_lp.c
46824 @@ -2514,7 +2514,7 @@ static int lpphy_b2063_tune(struct b43_wldev *dev,
46825 {
46826 struct ssb_bus *bus = dev->dev->sdev->bus;
46827
46828 - static const struct b206x_channel *chandata = NULL;
46829 + const struct b206x_channel *chandata = NULL;
46830 u32 crystal_freq = bus->chipco.pmu.crystalfreq * 1000;
46831 u32 freqref, vco_freq, val1, val2, val3, timeout, timeoutref, count;
46832 u16 old_comm15, scale;
46833 diff --git a/drivers/net/wireless/iwlegacy/3945-mac.c b/drivers/net/wireless/iwlegacy/3945-mac.c
46834 index dea3b50..543db99 100644
46835 --- a/drivers/net/wireless/iwlegacy/3945-mac.c
46836 +++ b/drivers/net/wireless/iwlegacy/3945-mac.c
46837 @@ -3639,7 +3639,9 @@ il3945_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
46838 */
46839 if (il3945_mod_params.disable_hw_scan) {
46840 D_INFO("Disabling hw_scan\n");
46841 - il3945_mac_ops.hw_scan = NULL;
46842 + pax_open_kernel();
46843 + *(void **)&il3945_mac_ops.hw_scan = NULL;
46844 + pax_close_kernel();
46845 }
46846
46847 D_INFO("*** LOAD DRIVER ***\n");
46848 diff --git a/drivers/net/wireless/iwlwifi/dvm/debugfs.c b/drivers/net/wireless/iwlwifi/dvm/debugfs.c
46849 index d94f8ab..5b568c8 100644
46850 --- a/drivers/net/wireless/iwlwifi/dvm/debugfs.c
46851 +++ b/drivers/net/wireless/iwlwifi/dvm/debugfs.c
46852 @@ -188,7 +188,7 @@ static ssize_t iwl_dbgfs_sram_write(struct file *file,
46853 {
46854 struct iwl_priv *priv = file->private_data;
46855 char buf[64];
46856 - int buf_size;
46857 + size_t buf_size;
46858 u32 offset, len;
46859
46860 memset(buf, 0, sizeof(buf));
46861 @@ -458,7 +458,7 @@ static ssize_t iwl_dbgfs_rx_handlers_write(struct file *file,
46862 struct iwl_priv *priv = file->private_data;
46863
46864 char buf[8];
46865 - int buf_size;
46866 + size_t buf_size;
46867 u32 reset_flag;
46868
46869 memset(buf, 0, sizeof(buf));
46870 @@ -539,7 +539,7 @@ static ssize_t iwl_dbgfs_disable_ht40_write(struct file *file,
46871 {
46872 struct iwl_priv *priv = file->private_data;
46873 char buf[8];
46874 - int buf_size;
46875 + size_t buf_size;
46876 int ht40;
46877
46878 memset(buf, 0, sizeof(buf));
46879 @@ -591,7 +591,7 @@ static ssize_t iwl_dbgfs_sleep_level_override_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 value;
46886
46887 memset(buf, 0, sizeof(buf));
46888 @@ -683,10 +683,10 @@ DEBUGFS_READ_FILE_OPS(temperature);
46889 DEBUGFS_READ_WRITE_FILE_OPS(sleep_level_override);
46890 DEBUGFS_READ_FILE_OPS(current_sleep_command);
46891
46892 -static const char *fmt_value = " %-30s %10u\n";
46893 -static const char *fmt_hex = " %-30s 0x%02X\n";
46894 -static const char *fmt_table = " %-30s %10u %10u %10u %10u\n";
46895 -static const char *fmt_header =
46896 +static const char fmt_value[] = " %-30s %10u\n";
46897 +static const char fmt_hex[] = " %-30s 0x%02X\n";
46898 +static const char fmt_table[] = " %-30s %10u %10u %10u %10u\n";
46899 +static const char fmt_header[] =
46900 "%-32s current cumulative delta max\n";
46901
46902 static int iwl_statistics_flag(struct iwl_priv *priv, char *buf, int bufsz)
46903 @@ -1856,7 +1856,7 @@ static ssize_t iwl_dbgfs_clear_ucode_statistics_write(struct file *file,
46904 {
46905 struct iwl_priv *priv = file->private_data;
46906 char buf[8];
46907 - int buf_size;
46908 + size_t buf_size;
46909 int clear;
46910
46911 memset(buf, 0, sizeof(buf));
46912 @@ -1901,7 +1901,7 @@ static ssize_t iwl_dbgfs_ucode_tracing_write(struct file *file,
46913 {
46914 struct iwl_priv *priv = file->private_data;
46915 char buf[8];
46916 - int buf_size;
46917 + size_t buf_size;
46918 int trace;
46919
46920 memset(buf, 0, sizeof(buf));
46921 @@ -1972,7 +1972,7 @@ static ssize_t iwl_dbgfs_missed_beacon_write(struct file *file,
46922 {
46923 struct iwl_priv *priv = file->private_data;
46924 char buf[8];
46925 - int buf_size;
46926 + size_t buf_size;
46927 int missed;
46928
46929 memset(buf, 0, sizeof(buf));
46930 @@ -2013,7 +2013,7 @@ static ssize_t iwl_dbgfs_plcp_delta_write(struct file *file,
46931
46932 struct iwl_priv *priv = file->private_data;
46933 char buf[8];
46934 - int buf_size;
46935 + size_t buf_size;
46936 int plcp;
46937
46938 memset(buf, 0, sizeof(buf));
46939 @@ -2073,7 +2073,7 @@ static ssize_t iwl_dbgfs_txfifo_flush_write(struct file *file,
46940
46941 struct iwl_priv *priv = file->private_data;
46942 char buf[8];
46943 - int buf_size;
46944 + size_t buf_size;
46945 int flush;
46946
46947 memset(buf, 0, sizeof(buf));
46948 @@ -2163,7 +2163,7 @@ static ssize_t iwl_dbgfs_protection_mode_write(struct file *file,
46949
46950 struct iwl_priv *priv = file->private_data;
46951 char buf[8];
46952 - int buf_size;
46953 + size_t buf_size;
46954 int rts;
46955
46956 if (!priv->cfg->ht_params)
46957 @@ -2205,7 +2205,7 @@ static ssize_t iwl_dbgfs_echo_test_write(struct file *file,
46958 {
46959 struct iwl_priv *priv = file->private_data;
46960 char buf[8];
46961 - int buf_size;
46962 + size_t buf_size;
46963
46964 memset(buf, 0, sizeof(buf));
46965 buf_size = min(count, sizeof(buf) - 1);
46966 @@ -2239,7 +2239,7 @@ static ssize_t iwl_dbgfs_log_event_write(struct file *file,
46967 struct iwl_priv *priv = file->private_data;
46968 u32 event_log_flag;
46969 char buf[8];
46970 - int buf_size;
46971 + size_t buf_size;
46972
46973 /* check that the interface is up */
46974 if (!iwl_is_ready(priv))
46975 @@ -2293,7 +2293,7 @@ static ssize_t iwl_dbgfs_calib_disabled_write(struct file *file,
46976 struct iwl_priv *priv = file->private_data;
46977 char buf[8];
46978 u32 calib_disabled;
46979 - int buf_size;
46980 + size_t buf_size;
46981
46982 memset(buf, 0, sizeof(buf));
46983 buf_size = min(count, sizeof(buf) - 1);
46984 diff --git a/drivers/net/wireless/iwlwifi/dvm/main.c b/drivers/net/wireless/iwlwifi/dvm/main.c
46985 index 7aad766..06addb4 100644
46986 --- a/drivers/net/wireless/iwlwifi/dvm/main.c
46987 +++ b/drivers/net/wireless/iwlwifi/dvm/main.c
46988 @@ -1123,7 +1123,7 @@ static void iwl_option_config(struct iwl_priv *priv)
46989 static int iwl_eeprom_init_hw_params(struct iwl_priv *priv)
46990 {
46991 struct iwl_nvm_data *data = priv->nvm_data;
46992 - char *debug_msg;
46993 + static const char debug_msg[] = "Device SKU: 24GHz %s %s, 52GHz %s %s, 11.n %s %s\n";
46994
46995 if (data->sku_cap_11n_enable &&
46996 !priv->cfg->ht_params) {
46997 @@ -1137,7 +1137,6 @@ static int iwl_eeprom_init_hw_params(struct iwl_priv *priv)
46998 return -EINVAL;
46999 }
47000
47001 - debug_msg = "Device SKU: 24GHz %s %s, 52GHz %s %s, 11.n %s %s\n";
47002 IWL_DEBUG_INFO(priv, debug_msg,
47003 data->sku_cap_band_24GHz_enable ? "" : "NOT", "enabled",
47004 data->sku_cap_band_52GHz_enable ? "" : "NOT", "enabled",
47005 diff --git a/drivers/net/wireless/iwlwifi/pcie/trans.c b/drivers/net/wireless/iwlwifi/pcie/trans.c
47006 index f53ef83..5e34bcb 100644
47007 --- a/drivers/net/wireless/iwlwifi/pcie/trans.c
47008 +++ b/drivers/net/wireless/iwlwifi/pcie/trans.c
47009 @@ -1390,7 +1390,7 @@ static ssize_t iwl_dbgfs_interrupt_write(struct file *file,
47010 struct isr_statistics *isr_stats = &trans_pcie->isr_stats;
47011
47012 char buf[8];
47013 - int buf_size;
47014 + size_t buf_size;
47015 u32 reset_flag;
47016
47017 memset(buf, 0, sizeof(buf));
47018 @@ -1411,7 +1411,7 @@ static ssize_t iwl_dbgfs_csr_write(struct file *file,
47019 {
47020 struct iwl_trans *trans = file->private_data;
47021 char buf[8];
47022 - int buf_size;
47023 + size_t buf_size;
47024 int csr;
47025
47026 memset(buf, 0, sizeof(buf));
47027 diff --git a/drivers/net/wireless/mac80211_hwsim.c b/drivers/net/wireless/mac80211_hwsim.c
47028 index a1b32ee..94b3c3d 100644
47029 --- a/drivers/net/wireless/mac80211_hwsim.c
47030 +++ b/drivers/net/wireless/mac80211_hwsim.c
47031 @@ -2224,25 +2224,19 @@ static int __init init_mac80211_hwsim(void)
47032
47033 if (channels > 1) {
47034 hwsim_if_comb.num_different_channels = channels;
47035 - mac80211_hwsim_ops.hw_scan = mac80211_hwsim_hw_scan;
47036 - mac80211_hwsim_ops.cancel_hw_scan =
47037 - mac80211_hwsim_cancel_hw_scan;
47038 - mac80211_hwsim_ops.sw_scan_start = NULL;
47039 - mac80211_hwsim_ops.sw_scan_complete = NULL;
47040 - mac80211_hwsim_ops.remain_on_channel =
47041 - mac80211_hwsim_roc;
47042 - mac80211_hwsim_ops.cancel_remain_on_channel =
47043 - mac80211_hwsim_croc;
47044 - mac80211_hwsim_ops.add_chanctx =
47045 - mac80211_hwsim_add_chanctx;
47046 - mac80211_hwsim_ops.remove_chanctx =
47047 - mac80211_hwsim_remove_chanctx;
47048 - mac80211_hwsim_ops.change_chanctx =
47049 - mac80211_hwsim_change_chanctx;
47050 - mac80211_hwsim_ops.assign_vif_chanctx =
47051 - mac80211_hwsim_assign_vif_chanctx;
47052 - mac80211_hwsim_ops.unassign_vif_chanctx =
47053 - mac80211_hwsim_unassign_vif_chanctx;
47054 + pax_open_kernel();
47055 + *(void **)&mac80211_hwsim_ops.hw_scan = mac80211_hwsim_hw_scan;
47056 + *(void **)&mac80211_hwsim_ops.cancel_hw_scan = mac80211_hwsim_cancel_hw_scan;
47057 + *(void **)&mac80211_hwsim_ops.sw_scan_start = NULL;
47058 + *(void **)&mac80211_hwsim_ops.sw_scan_complete = NULL;
47059 + *(void **)&mac80211_hwsim_ops.remain_on_channel = mac80211_hwsim_roc;
47060 + *(void **)&mac80211_hwsim_ops.cancel_remain_on_channel = mac80211_hwsim_croc;
47061 + *(void **)&mac80211_hwsim_ops.add_chanctx = mac80211_hwsim_add_chanctx;
47062 + *(void **)&mac80211_hwsim_ops.remove_chanctx = mac80211_hwsim_remove_chanctx;
47063 + *(void **)&mac80211_hwsim_ops.change_chanctx = mac80211_hwsim_change_chanctx;
47064 + *(void **)&mac80211_hwsim_ops.assign_vif_chanctx = mac80211_hwsim_assign_vif_chanctx;
47065 + *(void **)&mac80211_hwsim_ops.unassign_vif_chanctx = mac80211_hwsim_unassign_vif_chanctx;
47066 + pax_close_kernel();
47067 }
47068
47069 spin_lock_init(&hwsim_radio_lock);
47070 diff --git a/drivers/net/wireless/rndis_wlan.c b/drivers/net/wireless/rndis_wlan.c
47071 index 8169a85..7fa3b47 100644
47072 --- a/drivers/net/wireless/rndis_wlan.c
47073 +++ b/drivers/net/wireless/rndis_wlan.c
47074 @@ -1238,7 +1238,7 @@ static int set_rts_threshold(struct usbnet *usbdev, u32 rts_threshold)
47075
47076 netdev_dbg(usbdev->net, "%s(): %i\n", __func__, rts_threshold);
47077
47078 - if (rts_threshold < 0 || rts_threshold > 2347)
47079 + if (rts_threshold > 2347)
47080 rts_threshold = 2347;
47081
47082 tmp = cpu_to_le32(rts_threshold);
47083 diff --git a/drivers/net/wireless/rt2x00/rt2x00.h b/drivers/net/wireless/rt2x00/rt2x00.h
47084 index e4ba2ce..63d7417 100644
47085 --- a/drivers/net/wireless/rt2x00/rt2x00.h
47086 +++ b/drivers/net/wireless/rt2x00/rt2x00.h
47087 @@ -377,7 +377,7 @@ struct rt2x00_intf {
47088 * for hardware which doesn't support hardware
47089 * sequence counting.
47090 */
47091 - atomic_t seqno;
47092 + atomic_unchecked_t seqno;
47093 };
47094
47095 static inline struct rt2x00_intf* vif_to_intf(struct ieee80211_vif *vif)
47096 diff --git a/drivers/net/wireless/rt2x00/rt2x00queue.c b/drivers/net/wireless/rt2x00/rt2x00queue.c
47097 index a5d38e8..d3c24ea 100644
47098 --- a/drivers/net/wireless/rt2x00/rt2x00queue.c
47099 +++ b/drivers/net/wireless/rt2x00/rt2x00queue.c
47100 @@ -252,9 +252,9 @@ static void rt2x00queue_create_tx_descriptor_seq(struct rt2x00_dev *rt2x00dev,
47101 * sequence counter given by mac80211.
47102 */
47103 if (test_bit(ENTRY_TXD_FIRST_FRAGMENT, &txdesc->flags))
47104 - seqno = atomic_add_return(0x10, &intf->seqno);
47105 + seqno = atomic_add_return_unchecked(0x10, &intf->seqno);
47106 else
47107 - seqno = atomic_read(&intf->seqno);
47108 + seqno = atomic_read_unchecked(&intf->seqno);
47109
47110 hdr->seq_ctrl &= cpu_to_le16(IEEE80211_SCTL_FRAG);
47111 hdr->seq_ctrl |= cpu_to_le16(seqno);
47112 diff --git a/drivers/net/wireless/ti/wl1251/sdio.c b/drivers/net/wireless/ti/wl1251/sdio.c
47113 index e2b3d9c..67a5184 100644
47114 --- a/drivers/net/wireless/ti/wl1251/sdio.c
47115 +++ b/drivers/net/wireless/ti/wl1251/sdio.c
47116 @@ -271,13 +271,17 @@ static int wl1251_sdio_probe(struct sdio_func *func,
47117
47118 irq_set_irq_type(wl->irq, IRQ_TYPE_EDGE_RISING);
47119
47120 - wl1251_sdio_ops.enable_irq = wl1251_enable_line_irq;
47121 - wl1251_sdio_ops.disable_irq = wl1251_disable_line_irq;
47122 + pax_open_kernel();
47123 + *(void **)&wl1251_sdio_ops.enable_irq = wl1251_enable_line_irq;
47124 + *(void **)&wl1251_sdio_ops.disable_irq = wl1251_disable_line_irq;
47125 + pax_close_kernel();
47126
47127 wl1251_info("using dedicated interrupt line");
47128 } else {
47129 - wl1251_sdio_ops.enable_irq = wl1251_sdio_enable_irq;
47130 - wl1251_sdio_ops.disable_irq = wl1251_sdio_disable_irq;
47131 + pax_open_kernel();
47132 + *(void **)&wl1251_sdio_ops.enable_irq = wl1251_sdio_enable_irq;
47133 + *(void **)&wl1251_sdio_ops.disable_irq = wl1251_sdio_disable_irq;
47134 + pax_close_kernel();
47135
47136 wl1251_info("using SDIO interrupt");
47137 }
47138 diff --git a/drivers/net/wireless/ti/wl12xx/main.c b/drivers/net/wireless/ti/wl12xx/main.c
47139 index be7129b..4161356 100644
47140 --- a/drivers/net/wireless/ti/wl12xx/main.c
47141 +++ b/drivers/net/wireless/ti/wl12xx/main.c
47142 @@ -656,7 +656,9 @@ static int wl12xx_identify_chip(struct wl1271 *wl)
47143 sizeof(wl->conf.mem));
47144
47145 /* read data preparation is only needed by wl127x */
47146 - wl->ops->prepare_read = wl127x_prepare_read;
47147 + pax_open_kernel();
47148 + *(void **)&wl->ops->prepare_read = wl127x_prepare_read;
47149 + pax_close_kernel();
47150
47151 wlcore_set_min_fw_ver(wl, WL127X_CHIP_VER,
47152 WL127X_IFTYPE_SR_VER, WL127X_MAJOR_SR_VER,
47153 @@ -681,7 +683,9 @@ static int wl12xx_identify_chip(struct wl1271 *wl)
47154 sizeof(wl->conf.mem));
47155
47156 /* read data preparation is only needed by wl127x */
47157 - wl->ops->prepare_read = wl127x_prepare_read;
47158 + pax_open_kernel();
47159 + *(void **)&wl->ops->prepare_read = wl127x_prepare_read;
47160 + pax_close_kernel();
47161
47162 wlcore_set_min_fw_ver(wl, WL127X_CHIP_VER,
47163 WL127X_IFTYPE_SR_VER, WL127X_MAJOR_SR_VER,
47164 diff --git a/drivers/net/wireless/ti/wl18xx/main.c b/drivers/net/wireless/ti/wl18xx/main.c
47165 index ec37b16..7e34d66 100644
47166 --- a/drivers/net/wireless/ti/wl18xx/main.c
47167 +++ b/drivers/net/wireless/ti/wl18xx/main.c
47168 @@ -1823,8 +1823,10 @@ static int wl18xx_setup(struct wl1271 *wl)
47169 }
47170
47171 if (!checksum_param) {
47172 - wl18xx_ops.set_rx_csum = NULL;
47173 - wl18xx_ops.init_vif = NULL;
47174 + pax_open_kernel();
47175 + *(void **)&wl18xx_ops.set_rx_csum = NULL;
47176 + *(void **)&wl18xx_ops.init_vif = NULL;
47177 + pax_close_kernel();
47178 }
47179
47180 /* Enable 11a Band only if we have 5G antennas */
47181 diff --git a/drivers/net/wireless/zd1211rw/zd_usb.c b/drivers/net/wireless/zd1211rw/zd_usb.c
47182 index 84d94f5..bd6c61c 100644
47183 --- a/drivers/net/wireless/zd1211rw/zd_usb.c
47184 +++ b/drivers/net/wireless/zd1211rw/zd_usb.c
47185 @@ -386,7 +386,7 @@ static inline void handle_regs_int(struct urb *urb)
47186 {
47187 struct zd_usb *usb = urb->context;
47188 struct zd_usb_interrupt *intr = &usb->intr;
47189 - int len;
47190 + unsigned int len;
47191 u16 int_num;
47192
47193 ZD_ASSERT(in_interrupt());
47194 diff --git a/drivers/nfc/nfcwilink.c b/drivers/nfc/nfcwilink.c
47195 index 7130864..00e64de 100644
47196 --- a/drivers/nfc/nfcwilink.c
47197 +++ b/drivers/nfc/nfcwilink.c
47198 @@ -498,7 +498,7 @@ static struct nci_ops nfcwilink_ops = {
47199
47200 static int nfcwilink_probe(struct platform_device *pdev)
47201 {
47202 - static struct nfcwilink *drv;
47203 + struct nfcwilink *drv;
47204 int rc;
47205 __u32 protocols;
47206
47207 diff --git a/drivers/oprofile/buffer_sync.c b/drivers/oprofile/buffer_sync.c
47208 index d93b2b6..ae50401 100644
47209 --- a/drivers/oprofile/buffer_sync.c
47210 +++ b/drivers/oprofile/buffer_sync.c
47211 @@ -332,7 +332,7 @@ static void add_data(struct op_entry *entry, struct mm_struct *mm)
47212 if (cookie == NO_COOKIE)
47213 offset = pc;
47214 if (cookie == INVALID_COOKIE) {
47215 - atomic_inc(&oprofile_stats.sample_lost_no_mapping);
47216 + atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
47217 offset = pc;
47218 }
47219 if (cookie != last_cookie) {
47220 @@ -376,14 +376,14 @@ add_sample(struct mm_struct *mm, struct op_sample *s, int in_kernel)
47221 /* add userspace sample */
47222
47223 if (!mm) {
47224 - atomic_inc(&oprofile_stats.sample_lost_no_mm);
47225 + atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mm);
47226 return 0;
47227 }
47228
47229 cookie = lookup_dcookie(mm, s->eip, &offset);
47230
47231 if (cookie == INVALID_COOKIE) {
47232 - atomic_inc(&oprofile_stats.sample_lost_no_mapping);
47233 + atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
47234 return 0;
47235 }
47236
47237 @@ -552,7 +552,7 @@ void sync_buffer(int cpu)
47238 /* ignore backtraces if failed to add a sample */
47239 if (state == sb_bt_start) {
47240 state = sb_bt_ignore;
47241 - atomic_inc(&oprofile_stats.bt_lost_no_mapping);
47242 + atomic_inc_unchecked(&oprofile_stats.bt_lost_no_mapping);
47243 }
47244 }
47245 release_mm(mm);
47246 diff --git a/drivers/oprofile/event_buffer.c b/drivers/oprofile/event_buffer.c
47247 index c0cc4e7..44d4e54 100644
47248 --- a/drivers/oprofile/event_buffer.c
47249 +++ b/drivers/oprofile/event_buffer.c
47250 @@ -53,7 +53,7 @@ void add_event_entry(unsigned long value)
47251 }
47252
47253 if (buffer_pos == buffer_size) {
47254 - atomic_inc(&oprofile_stats.event_lost_overflow);
47255 + atomic_inc_unchecked(&oprofile_stats.event_lost_overflow);
47256 return;
47257 }
47258
47259 diff --git a/drivers/oprofile/oprof.c b/drivers/oprofile/oprof.c
47260 index ed2c3ec..deda85a 100644
47261 --- a/drivers/oprofile/oprof.c
47262 +++ b/drivers/oprofile/oprof.c
47263 @@ -110,7 +110,7 @@ static void switch_worker(struct work_struct *work)
47264 if (oprofile_ops.switch_events())
47265 return;
47266
47267 - atomic_inc(&oprofile_stats.multiplex_counter);
47268 + atomic_inc_unchecked(&oprofile_stats.multiplex_counter);
47269 start_switch_worker();
47270 }
47271
47272 diff --git a/drivers/oprofile/oprofile_files.c b/drivers/oprofile/oprofile_files.c
47273 index ee2cfce..7f8f699 100644
47274 --- a/drivers/oprofile/oprofile_files.c
47275 +++ b/drivers/oprofile/oprofile_files.c
47276 @@ -27,7 +27,7 @@ unsigned long oprofile_time_slice;
47277
47278 #ifdef CONFIG_OPROFILE_EVENT_MULTIPLEX
47279
47280 -static ssize_t timeout_read(struct file *file, char __user *buf,
47281 +static ssize_t __intentional_overflow(-1) timeout_read(struct file *file, char __user *buf,
47282 size_t count, loff_t *offset)
47283 {
47284 return oprofilefs_ulong_to_user(jiffies_to_msecs(oprofile_time_slice),
47285 diff --git a/drivers/oprofile/oprofile_stats.c b/drivers/oprofile/oprofile_stats.c
47286 index 59659ce..6c860a0 100644
47287 --- a/drivers/oprofile/oprofile_stats.c
47288 +++ b/drivers/oprofile/oprofile_stats.c
47289 @@ -30,11 +30,11 @@ void oprofile_reset_stats(void)
47290 cpu_buf->sample_invalid_eip = 0;
47291 }
47292
47293 - atomic_set(&oprofile_stats.sample_lost_no_mm, 0);
47294 - atomic_set(&oprofile_stats.sample_lost_no_mapping, 0);
47295 - atomic_set(&oprofile_stats.event_lost_overflow, 0);
47296 - atomic_set(&oprofile_stats.bt_lost_no_mapping, 0);
47297 - atomic_set(&oprofile_stats.multiplex_counter, 0);
47298 + atomic_set_unchecked(&oprofile_stats.sample_lost_no_mm, 0);
47299 + atomic_set_unchecked(&oprofile_stats.sample_lost_no_mapping, 0);
47300 + atomic_set_unchecked(&oprofile_stats.event_lost_overflow, 0);
47301 + atomic_set_unchecked(&oprofile_stats.bt_lost_no_mapping, 0);
47302 + atomic_set_unchecked(&oprofile_stats.multiplex_counter, 0);
47303 }
47304
47305
47306 diff --git a/drivers/oprofile/oprofile_stats.h b/drivers/oprofile/oprofile_stats.h
47307 index 1fc622b..8c48fc3 100644
47308 --- a/drivers/oprofile/oprofile_stats.h
47309 +++ b/drivers/oprofile/oprofile_stats.h
47310 @@ -13,11 +13,11 @@
47311 #include <linux/atomic.h>
47312
47313 struct oprofile_stat_struct {
47314 - atomic_t sample_lost_no_mm;
47315 - atomic_t sample_lost_no_mapping;
47316 - atomic_t bt_lost_no_mapping;
47317 - atomic_t event_lost_overflow;
47318 - atomic_t multiplex_counter;
47319 + atomic_unchecked_t sample_lost_no_mm;
47320 + atomic_unchecked_t sample_lost_no_mapping;
47321 + atomic_unchecked_t bt_lost_no_mapping;
47322 + atomic_unchecked_t event_lost_overflow;
47323 + atomic_unchecked_t multiplex_counter;
47324 };
47325
47326 extern struct oprofile_stat_struct oprofile_stats;
47327 diff --git a/drivers/oprofile/oprofilefs.c b/drivers/oprofile/oprofilefs.c
47328 index 3f49345..c750d0b 100644
47329 --- a/drivers/oprofile/oprofilefs.c
47330 +++ b/drivers/oprofile/oprofilefs.c
47331 @@ -176,8 +176,8 @@ int oprofilefs_create_ro_ulong(struct dentry *root,
47332
47333 static ssize_t atomic_read_file(struct file *file, char __user *buf, size_t count, loff_t *offset)
47334 {
47335 - atomic_t *val = file->private_data;
47336 - return oprofilefs_ulong_to_user(atomic_read(val), buf, count, offset);
47337 + atomic_unchecked_t *val = file->private_data;
47338 + return oprofilefs_ulong_to_user(atomic_read_unchecked(val), buf, count, offset);
47339 }
47340
47341
47342 @@ -189,7 +189,7 @@ static const struct file_operations atomic_ro_fops = {
47343
47344
47345 int oprofilefs_create_ro_atomic(struct dentry *root,
47346 - char const *name, atomic_t *val)
47347 + char const *name, atomic_unchecked_t *val)
47348 {
47349 return __oprofilefs_create_file(root, name,
47350 &atomic_ro_fops, 0444, val);
47351 diff --git a/drivers/oprofile/timer_int.c b/drivers/oprofile/timer_int.c
47352 index 61be1d9..dec05d7 100644
47353 --- a/drivers/oprofile/timer_int.c
47354 +++ b/drivers/oprofile/timer_int.c
47355 @@ -93,7 +93,7 @@ static int oprofile_cpu_notify(struct notifier_block *self,
47356 return NOTIFY_OK;
47357 }
47358
47359 -static struct notifier_block __refdata oprofile_cpu_notifier = {
47360 +static struct notifier_block oprofile_cpu_notifier = {
47361 .notifier_call = oprofile_cpu_notify,
47362 };
47363
47364 diff --git a/drivers/parport/procfs.c b/drivers/parport/procfs.c
47365 index 92ed045..62d39bd7 100644
47366 --- a/drivers/parport/procfs.c
47367 +++ b/drivers/parport/procfs.c
47368 @@ -64,7 +64,7 @@ static int do_active_device(ctl_table *table, int write,
47369
47370 *ppos += len;
47371
47372 - return copy_to_user(result, buffer, len) ? -EFAULT : 0;
47373 + return (len > sizeof buffer || copy_to_user(result, buffer, len)) ? -EFAULT : 0;
47374 }
47375
47376 #ifdef CONFIG_PARPORT_1284
47377 @@ -106,7 +106,7 @@ static int do_autoprobe(ctl_table *table, int write,
47378
47379 *ppos += len;
47380
47381 - return copy_to_user (result, buffer, len) ? -EFAULT : 0;
47382 + return (len > sizeof buffer || copy_to_user (result, buffer, len)) ? -EFAULT : 0;
47383 }
47384 #endif /* IEEE1284.3 support. */
47385
47386 diff --git a/drivers/pci/hotplug/acpiphp_ibm.c b/drivers/pci/hotplug/acpiphp_ibm.c
47387 index ecfac7e..41be7028 100644
47388 --- a/drivers/pci/hotplug/acpiphp_ibm.c
47389 +++ b/drivers/pci/hotplug/acpiphp_ibm.c
47390 @@ -453,7 +453,9 @@ static int __init ibm_acpiphp_init(void)
47391 goto init_cleanup;
47392 }
47393
47394 - ibm_apci_table_attr.size = ibm_get_table_from_acpi(NULL);
47395 + pax_open_kernel();
47396 + *(size_t *)&ibm_apci_table_attr.size = ibm_get_table_from_acpi(NULL);
47397 + pax_close_kernel();
47398 retval = sysfs_create_bin_file(sysdir, &ibm_apci_table_attr);
47399
47400 return retval;
47401 diff --git a/drivers/pci/hotplug/cpcihp_generic.c b/drivers/pci/hotplug/cpcihp_generic.c
47402 index 7536eef..52dc8fa 100644
47403 --- a/drivers/pci/hotplug/cpcihp_generic.c
47404 +++ b/drivers/pci/hotplug/cpcihp_generic.c
47405 @@ -73,7 +73,6 @@ static u16 port;
47406 static unsigned int enum_bit;
47407 static u8 enum_mask;
47408
47409 -static struct cpci_hp_controller_ops generic_hpc_ops;
47410 static struct cpci_hp_controller generic_hpc;
47411
47412 static int __init validate_parameters(void)
47413 @@ -139,6 +138,10 @@ static int query_enum(void)
47414 return ((value & enum_mask) == enum_mask);
47415 }
47416
47417 +static struct cpci_hp_controller_ops generic_hpc_ops = {
47418 + .query_enum = query_enum,
47419 +};
47420 +
47421 static int __init cpcihp_generic_init(void)
47422 {
47423 int status;
47424 @@ -165,7 +168,6 @@ static int __init cpcihp_generic_init(void)
47425 pci_dev_put(dev);
47426
47427 memset(&generic_hpc, 0, sizeof (struct cpci_hp_controller));
47428 - generic_hpc_ops.query_enum = query_enum;
47429 generic_hpc.ops = &generic_hpc_ops;
47430
47431 status = cpci_hp_register_controller(&generic_hpc);
47432 diff --git a/drivers/pci/hotplug/cpcihp_zt5550.c b/drivers/pci/hotplug/cpcihp_zt5550.c
47433 index e8c4a7c..7046f5c 100644
47434 --- a/drivers/pci/hotplug/cpcihp_zt5550.c
47435 +++ b/drivers/pci/hotplug/cpcihp_zt5550.c
47436 @@ -59,7 +59,6 @@
47437 /* local variables */
47438 static bool debug;
47439 static bool poll;
47440 -static struct cpci_hp_controller_ops zt5550_hpc_ops;
47441 static struct cpci_hp_controller zt5550_hpc;
47442
47443 /* Primary cPCI bus bridge device */
47444 @@ -205,6 +204,10 @@ static int zt5550_hc_disable_irq(void)
47445 return 0;
47446 }
47447
47448 +static struct cpci_hp_controller_ops zt5550_hpc_ops = {
47449 + .query_enum = zt5550_hc_query_enum,
47450 +};
47451 +
47452 static int zt5550_hc_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
47453 {
47454 int status;
47455 @@ -216,16 +219,17 @@ static int zt5550_hc_init_one (struct pci_dev *pdev, const struct pci_device_id
47456 dbg("returned from zt5550_hc_config");
47457
47458 memset(&zt5550_hpc, 0, sizeof (struct cpci_hp_controller));
47459 - zt5550_hpc_ops.query_enum = zt5550_hc_query_enum;
47460 zt5550_hpc.ops = &zt5550_hpc_ops;
47461 if(!poll) {
47462 zt5550_hpc.irq = hc_dev->irq;
47463 zt5550_hpc.irq_flags = IRQF_SHARED;
47464 zt5550_hpc.dev_id = hc_dev;
47465
47466 - zt5550_hpc_ops.enable_irq = zt5550_hc_enable_irq;
47467 - zt5550_hpc_ops.disable_irq = zt5550_hc_disable_irq;
47468 - zt5550_hpc_ops.check_irq = zt5550_hc_check_irq;
47469 + pax_open_kernel();
47470 + *(void **)&zt5550_hpc_ops.enable_irq = zt5550_hc_enable_irq;
47471 + *(void **)&zt5550_hpc_ops.disable_irq = zt5550_hc_disable_irq;
47472 + *(void **)&zt5550_hpc_ops.check_irq = zt5550_hc_check_irq;
47473 + pax_open_kernel();
47474 } else {
47475 info("using ENUM# polling mode");
47476 }
47477 diff --git a/drivers/pci/hotplug/cpqphp_nvram.c b/drivers/pci/hotplug/cpqphp_nvram.c
47478 index 76ba8a1..20ca857 100644
47479 --- a/drivers/pci/hotplug/cpqphp_nvram.c
47480 +++ b/drivers/pci/hotplug/cpqphp_nvram.c
47481 @@ -428,9 +428,13 @@ static u32 store_HRT (void __iomem *rom_start)
47482
47483 void compaq_nvram_init (void __iomem *rom_start)
47484 {
47485 +
47486 +#ifndef CONFIG_PAX_KERNEXEC
47487 if (rom_start) {
47488 compaq_int15_entry_point = (rom_start + ROM_INT15_PHY_ADDR - ROM_PHY_ADDR);
47489 }
47490 +#endif
47491 +
47492 dbg("int15 entry = %p\n", compaq_int15_entry_point);
47493
47494 /* initialize our int15 lock */
47495 diff --git a/drivers/pci/hotplug/pci_hotplug_core.c b/drivers/pci/hotplug/pci_hotplug_core.c
47496 index cfa92a9..29539c5 100644
47497 --- a/drivers/pci/hotplug/pci_hotplug_core.c
47498 +++ b/drivers/pci/hotplug/pci_hotplug_core.c
47499 @@ -441,8 +441,10 @@ int __pci_hp_register(struct hotplug_slot *slot, struct pci_bus *bus,
47500 return -EINVAL;
47501 }
47502
47503 - slot->ops->owner = owner;
47504 - slot->ops->mod_name = mod_name;
47505 + pax_open_kernel();
47506 + *(struct module **)&slot->ops->owner = owner;
47507 + *(const char **)&slot->ops->mod_name = mod_name;
47508 + pax_close_kernel();
47509
47510 mutex_lock(&pci_hp_mutex);
47511 /*
47512 diff --git a/drivers/pci/hotplug/pciehp_core.c b/drivers/pci/hotplug/pciehp_core.c
47513 index bbd48bb..6907ef4 100644
47514 --- a/drivers/pci/hotplug/pciehp_core.c
47515 +++ b/drivers/pci/hotplug/pciehp_core.c
47516 @@ -92,7 +92,7 @@ static int init_slot(struct controller *ctrl)
47517 struct slot *slot = ctrl->slot;
47518 struct hotplug_slot *hotplug = NULL;
47519 struct hotplug_slot_info *info = NULL;
47520 - struct hotplug_slot_ops *ops = NULL;
47521 + hotplug_slot_ops_no_const *ops = NULL;
47522 char name[SLOT_NAME_SIZE];
47523 int retval = -ENOMEM;
47524
47525 diff --git a/drivers/pci/pci-sysfs.c b/drivers/pci/pci-sysfs.c
47526 index c91e6c1..5c723ef 100644
47527 --- a/drivers/pci/pci-sysfs.c
47528 +++ b/drivers/pci/pci-sysfs.c
47529 @@ -1117,7 +1117,7 @@ static int pci_create_attr(struct pci_dev *pdev, int num, int write_combine)
47530 {
47531 /* allocate attribute structure, piggyback attribute name */
47532 int name_len = write_combine ? 13 : 10;
47533 - struct bin_attribute *res_attr;
47534 + bin_attribute_no_const *res_attr;
47535 int retval;
47536
47537 res_attr = kzalloc(sizeof(*res_attr) + name_len, GFP_ATOMIC);
47538 @@ -1302,7 +1302,7 @@ static struct device_attribute reset_attr = __ATTR(reset, 0200, NULL, reset_stor
47539 static int pci_create_capabilities_sysfs(struct pci_dev *dev)
47540 {
47541 int retval;
47542 - struct bin_attribute *attr;
47543 + bin_attribute_no_const *attr;
47544
47545 /* If the device has VPD, try to expose it in sysfs. */
47546 if (dev->vpd) {
47547 @@ -1349,7 +1349,7 @@ int __must_check pci_create_sysfs_dev_files (struct pci_dev *pdev)
47548 {
47549 int retval;
47550 int rom_size = 0;
47551 - struct bin_attribute *attr;
47552 + bin_attribute_no_const *attr;
47553
47554 if (!sysfs_initialized)
47555 return -EACCES;
47556 diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h
47557 index 9c91ecc..bda4796 100644
47558 --- a/drivers/pci/pci.h
47559 +++ b/drivers/pci/pci.h
47560 @@ -95,7 +95,7 @@ struct pci_vpd_ops {
47561 struct pci_vpd {
47562 unsigned int len;
47563 const struct pci_vpd_ops *ops;
47564 - struct bin_attribute *attr; /* descriptor for sysfs VPD entry */
47565 + bin_attribute_no_const *attr; /* descriptor for sysfs VPD entry */
47566 };
47567
47568 int pci_vpd_pci22_init(struct pci_dev *dev);
47569 diff --git a/drivers/pci/pcie/aspm.c b/drivers/pci/pcie/aspm.c
47570 index f1272dc..e92a1ac 100644
47571 --- a/drivers/pci/pcie/aspm.c
47572 +++ b/drivers/pci/pcie/aspm.c
47573 @@ -27,9 +27,9 @@
47574 #define MODULE_PARAM_PREFIX "pcie_aspm."
47575
47576 /* Note: those are not register definitions */
47577 -#define ASPM_STATE_L0S_UP (1) /* Upstream direction L0s state */
47578 -#define ASPM_STATE_L0S_DW (2) /* Downstream direction L0s state */
47579 -#define ASPM_STATE_L1 (4) /* L1 state */
47580 +#define ASPM_STATE_L0S_UP (1U) /* Upstream direction L0s state */
47581 +#define ASPM_STATE_L0S_DW (2U) /* Downstream direction L0s state */
47582 +#define ASPM_STATE_L1 (4U) /* L1 state */
47583 #define ASPM_STATE_L0S (ASPM_STATE_L0S_UP | ASPM_STATE_L0S_DW)
47584 #define ASPM_STATE_ALL (ASPM_STATE_L0S | ASPM_STATE_L1)
47585
47586 diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
47587 index 38e403d..a2ce55a 100644
47588 --- a/drivers/pci/probe.c
47589 +++ b/drivers/pci/probe.c
47590 @@ -175,7 +175,7 @@ int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type,
47591 struct pci_bus_region region, inverted_region;
47592 bool bar_too_big = false, bar_disabled = false;
47593
47594 - mask = type ? PCI_ROM_ADDRESS_MASK : ~0;
47595 + mask = type ? (u32)PCI_ROM_ADDRESS_MASK : ~0;
47596
47597 /* No printks while decoding is disabled! */
47598 if (!dev->mmio_always_on) {
47599 diff --git a/drivers/pci/proc.c b/drivers/pci/proc.c
47600 index 46d1378..30e452b 100644
47601 --- a/drivers/pci/proc.c
47602 +++ b/drivers/pci/proc.c
47603 @@ -434,7 +434,16 @@ static const struct file_operations proc_bus_pci_dev_operations = {
47604 static int __init pci_proc_init(void)
47605 {
47606 struct pci_dev *dev = NULL;
47607 +
47608 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
47609 +#ifdef CONFIG_GRKERNSEC_PROC_USER
47610 + proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR, NULL);
47611 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
47612 + proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
47613 +#endif
47614 +#else
47615 proc_bus_pci_dir = proc_mkdir("bus/pci", NULL);
47616 +#endif
47617 proc_create("devices", 0, proc_bus_pci_dir,
47618 &proc_bus_pci_dev_operations);
47619 proc_initialized = 1;
47620 diff --git a/drivers/platform/chrome/chromeos_laptop.c b/drivers/platform/chrome/chromeos_laptop.c
47621 index 3e5b4497..dcdfb70 100644
47622 --- a/drivers/platform/chrome/chromeos_laptop.c
47623 +++ b/drivers/platform/chrome/chromeos_laptop.c
47624 @@ -301,7 +301,7 @@ static int __init setup_tsl2563_als(const struct dmi_system_id *id)
47625 return 0;
47626 }
47627
47628 -static struct dmi_system_id __initdata chromeos_laptop_dmi_table[] = {
47629 +static struct dmi_system_id __initconst chromeos_laptop_dmi_table[] = {
47630 {
47631 .ident = "Samsung Series 5 550 - Touchpad",
47632 .matches = {
47633 diff --git a/drivers/platform/x86/asus-wmi.c b/drivers/platform/x86/asus-wmi.c
47634 index 19c313b..ed28b38 100644
47635 --- a/drivers/platform/x86/asus-wmi.c
47636 +++ b/drivers/platform/x86/asus-wmi.c
47637 @@ -1618,6 +1618,10 @@ static int show_dsts(struct seq_file *m, void *data)
47638 int err;
47639 u32 retval = -1;
47640
47641 +#ifdef CONFIG_GRKERNSEC_KMEM
47642 + return -EPERM;
47643 +#endif
47644 +
47645 err = asus_wmi_get_devstate(asus, asus->debug.dev_id, &retval);
47646
47647 if (err < 0)
47648 @@ -1634,6 +1638,10 @@ static int show_devs(struct seq_file *m, void *data)
47649 int err;
47650 u32 retval = -1;
47651
47652 +#ifdef CONFIG_GRKERNSEC_KMEM
47653 + return -EPERM;
47654 +#endif
47655 +
47656 err = asus_wmi_set_devstate(asus->debug.dev_id, asus->debug.ctrl_param,
47657 &retval);
47658
47659 @@ -1658,6 +1666,10 @@ static int show_call(struct seq_file *m, void *data)
47660 union acpi_object *obj;
47661 acpi_status status;
47662
47663 +#ifdef CONFIG_GRKERNSEC_KMEM
47664 + return -EPERM;
47665 +#endif
47666 +
47667 status = wmi_evaluate_method(ASUS_WMI_MGMT_GUID,
47668 1, asus->debug.method_id,
47669 &input, &output);
47670 diff --git a/drivers/platform/x86/msi-laptop.c b/drivers/platform/x86/msi-laptop.c
47671 index 62f8030..c7f2a45 100644
47672 --- a/drivers/platform/x86/msi-laptop.c
47673 +++ b/drivers/platform/x86/msi-laptop.c
47674 @@ -1000,12 +1000,14 @@ static int __init load_scm_model_init(struct platform_device *sdev)
47675
47676 if (!quirks->ec_read_only) {
47677 /* allow userland write sysfs file */
47678 - dev_attr_bluetooth.store = store_bluetooth;
47679 - dev_attr_wlan.store = store_wlan;
47680 - dev_attr_threeg.store = store_threeg;
47681 - dev_attr_bluetooth.attr.mode |= S_IWUSR;
47682 - dev_attr_wlan.attr.mode |= S_IWUSR;
47683 - dev_attr_threeg.attr.mode |= S_IWUSR;
47684 + pax_open_kernel();
47685 + *(void **)&dev_attr_bluetooth.store = store_bluetooth;
47686 + *(void **)&dev_attr_wlan.store = store_wlan;
47687 + *(void **)&dev_attr_threeg.store = store_threeg;
47688 + *(umode_t *)&dev_attr_bluetooth.attr.mode |= S_IWUSR;
47689 + *(umode_t *)&dev_attr_wlan.attr.mode |= S_IWUSR;
47690 + *(umode_t *)&dev_attr_threeg.attr.mode |= S_IWUSR;
47691 + pax_close_kernel();
47692 }
47693
47694 /* disable hardware control by fn key */
47695 diff --git a/drivers/platform/x86/msi-wmi.c b/drivers/platform/x86/msi-wmi.c
47696 index 70222f2..8c8ce66 100644
47697 --- a/drivers/platform/x86/msi-wmi.c
47698 +++ b/drivers/platform/x86/msi-wmi.c
47699 @@ -183,7 +183,7 @@ static const struct backlight_ops msi_backlight_ops = {
47700 static void msi_wmi_notify(u32 value, void *context)
47701 {
47702 struct acpi_buffer response = { ACPI_ALLOCATE_BUFFER, NULL };
47703 - static struct key_entry *key;
47704 + struct key_entry *key;
47705 union acpi_object *obj;
47706 acpi_status status;
47707
47708 diff --git a/drivers/platform/x86/sony-laptop.c b/drivers/platform/x86/sony-laptop.c
47709 index fb233ae..23a325c 100644
47710 --- a/drivers/platform/x86/sony-laptop.c
47711 +++ b/drivers/platform/x86/sony-laptop.c
47712 @@ -2453,7 +2453,7 @@ static void sony_nc_gfx_switch_cleanup(struct platform_device *pd)
47713 }
47714
47715 /* High speed charging function */
47716 -static struct device_attribute *hsc_handle;
47717 +static device_attribute_no_const *hsc_handle;
47718
47719 static ssize_t sony_nc_highspeed_charging_store(struct device *dev,
47720 struct device_attribute *attr,
47721 diff --git a/drivers/platform/x86/thinkpad_acpi.c b/drivers/platform/x86/thinkpad_acpi.c
47722 index 58b0274..6704626 100644
47723 --- a/drivers/platform/x86/thinkpad_acpi.c
47724 +++ b/drivers/platform/x86/thinkpad_acpi.c
47725 @@ -2100,7 +2100,7 @@ static int hotkey_mask_get(void)
47726 return 0;
47727 }
47728
47729 -void static hotkey_mask_warn_incomplete_mask(void)
47730 +static void hotkey_mask_warn_incomplete_mask(void)
47731 {
47732 /* log only what the user can fix... */
47733 const u32 wantedmask = hotkey_driver_mask &
47734 @@ -2327,11 +2327,6 @@ static void hotkey_read_nvram(struct tp_nvram_state *n, const u32 m)
47735 }
47736 }
47737
47738 -static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
47739 - struct tp_nvram_state *newn,
47740 - const u32 event_mask)
47741 -{
47742 -
47743 #define TPACPI_COMPARE_KEY(__scancode, __member) \
47744 do { \
47745 if ((event_mask & (1 << __scancode)) && \
47746 @@ -2345,36 +2340,42 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
47747 tpacpi_hotkey_send_key(__scancode); \
47748 } while (0)
47749
47750 - void issue_volchange(const unsigned int oldvol,
47751 - const unsigned int newvol)
47752 - {
47753 - unsigned int i = oldvol;
47754 +static void issue_volchange(const unsigned int oldvol,
47755 + const unsigned int newvol,
47756 + const u32 event_mask)
47757 +{
47758 + unsigned int i = oldvol;
47759
47760 - while (i > newvol) {
47761 - TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
47762 - i--;
47763 - }
47764 - while (i < newvol) {
47765 - TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
47766 - i++;
47767 - }
47768 + while (i > newvol) {
47769 + TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
47770 + i--;
47771 }
47772 + while (i < newvol) {
47773 + TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
47774 + i++;
47775 + }
47776 +}
47777
47778 - void issue_brightnesschange(const unsigned int oldbrt,
47779 - const unsigned int newbrt)
47780 - {
47781 - unsigned int i = oldbrt;
47782 +static void issue_brightnesschange(const unsigned int oldbrt,
47783 + const unsigned int newbrt,
47784 + const u32 event_mask)
47785 +{
47786 + unsigned int i = oldbrt;
47787
47788 - while (i > newbrt) {
47789 - TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
47790 - i--;
47791 - }
47792 - while (i < newbrt) {
47793 - TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
47794 - i++;
47795 - }
47796 + while (i > newbrt) {
47797 + TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
47798 + i--;
47799 + }
47800 + while (i < newbrt) {
47801 + TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
47802 + i++;
47803 }
47804 +}
47805
47806 +static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
47807 + struct tp_nvram_state *newn,
47808 + const u32 event_mask)
47809 +{
47810 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_THINKPAD, thinkpad_toggle);
47811 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNSPACE, zoom_toggle);
47812 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF7, display_toggle);
47813 @@ -2408,7 +2409,7 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
47814 oldn->volume_level != newn->volume_level) {
47815 /* recently muted, or repeated mute keypress, or
47816 * multiple presses ending in mute */
47817 - issue_volchange(oldn->volume_level, newn->volume_level);
47818 + issue_volchange(oldn->volume_level, newn->volume_level, event_mask);
47819 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_MUTE);
47820 }
47821 } else {
47822 @@ -2418,7 +2419,7 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
47823 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
47824 }
47825 if (oldn->volume_level != newn->volume_level) {
47826 - issue_volchange(oldn->volume_level, newn->volume_level);
47827 + issue_volchange(oldn->volume_level, newn->volume_level, event_mask);
47828 } else if (oldn->volume_toggle != newn->volume_toggle) {
47829 /* repeated vol up/down keypress at end of scale ? */
47830 if (newn->volume_level == 0)
47831 @@ -2431,7 +2432,8 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
47832 /* handle brightness */
47833 if (oldn->brightness_level != newn->brightness_level) {
47834 issue_brightnesschange(oldn->brightness_level,
47835 - newn->brightness_level);
47836 + newn->brightness_level,
47837 + event_mask);
47838 } else if (oldn->brightness_toggle != newn->brightness_toggle) {
47839 /* repeated key presses that didn't change state */
47840 if (newn->brightness_level == 0)
47841 @@ -2440,10 +2442,10 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
47842 && !tp_features.bright_unkfw)
47843 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
47844 }
47845 +}
47846
47847 #undef TPACPI_COMPARE_KEY
47848 #undef TPACPI_MAY_SEND_KEY
47849 -}
47850
47851 /*
47852 * Polling driver
47853 diff --git a/drivers/pnp/pnpbios/bioscalls.c b/drivers/pnp/pnpbios/bioscalls.c
47854 index 769d265..a3a05ca 100644
47855 --- a/drivers/pnp/pnpbios/bioscalls.c
47856 +++ b/drivers/pnp/pnpbios/bioscalls.c
47857 @@ -58,7 +58,7 @@ do { \
47858 set_desc_limit(&gdt[(selname) >> 3], (size) - 1); \
47859 } while(0)
47860
47861 -static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
47862 +static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
47863 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
47864
47865 /*
47866 @@ -95,7 +95,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
47867
47868 cpu = get_cpu();
47869 save_desc_40 = get_cpu_gdt_table(cpu)[0x40 / 8];
47870 +
47871 + pax_open_kernel();
47872 get_cpu_gdt_table(cpu)[0x40 / 8] = bad_bios_desc;
47873 + pax_close_kernel();
47874
47875 /* On some boxes IRQ's during PnP BIOS calls are deadly. */
47876 spin_lock_irqsave(&pnp_bios_lock, flags);
47877 @@ -133,7 +136,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
47878 :"memory");
47879 spin_unlock_irqrestore(&pnp_bios_lock, flags);
47880
47881 + pax_open_kernel();
47882 get_cpu_gdt_table(cpu)[0x40 / 8] = save_desc_40;
47883 + pax_close_kernel();
47884 +
47885 put_cpu();
47886
47887 /* If we get here and this is set then the PnP BIOS faulted on us. */
47888 @@ -467,7 +473,7 @@ int pnp_bios_read_escd(char *data, u32 nvram_base)
47889 return status;
47890 }
47891
47892 -void pnpbios_calls_init(union pnp_bios_install_struct *header)
47893 +void __init pnpbios_calls_init(union pnp_bios_install_struct *header)
47894 {
47895 int i;
47896
47897 @@ -475,6 +481,8 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
47898 pnp_bios_callpoint.offset = header->fields.pm16offset;
47899 pnp_bios_callpoint.segment = PNP_CS16;
47900
47901 + pax_open_kernel();
47902 +
47903 for_each_possible_cpu(i) {
47904 struct desc_struct *gdt = get_cpu_gdt_table(i);
47905 if (!gdt)
47906 @@ -486,4 +494,6 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
47907 set_desc_base(&gdt[GDT_ENTRY_PNPBIOS_DS],
47908 (unsigned long)__va(header->fields.pm16dseg));
47909 }
47910 +
47911 + pax_close_kernel();
47912 }
47913 diff --git a/drivers/pnp/resource.c b/drivers/pnp/resource.c
47914 index d95e101..67f0c3f 100644
47915 --- a/drivers/pnp/resource.c
47916 +++ b/drivers/pnp/resource.c
47917 @@ -360,7 +360,7 @@ int pnp_check_irq(struct pnp_dev *dev, struct resource *res)
47918 return 1;
47919
47920 /* check if the resource is valid */
47921 - if (*irq < 0 || *irq > 15)
47922 + if (*irq > 15)
47923 return 0;
47924
47925 /* check if the resource is reserved */
47926 @@ -424,7 +424,7 @@ int pnp_check_dma(struct pnp_dev *dev, struct resource *res)
47927 return 1;
47928
47929 /* check if the resource is valid */
47930 - if (*dma < 0 || *dma == 4 || *dma > 7)
47931 + if (*dma == 4 || *dma > 7)
47932 return 0;
47933
47934 /* check if the resource is reserved */
47935 diff --git a/drivers/power/pda_power.c b/drivers/power/pda_power.c
47936 index 0c52e2a..3421ab7 100644
47937 --- a/drivers/power/pda_power.c
47938 +++ b/drivers/power/pda_power.c
47939 @@ -37,7 +37,11 @@ static int polling;
47940
47941 #if IS_ENABLED(CONFIG_USB_PHY)
47942 static struct usb_phy *transceiver;
47943 -static struct notifier_block otg_nb;
47944 +static int otg_handle_notification(struct notifier_block *nb,
47945 + unsigned long event, void *unused);
47946 +static struct notifier_block otg_nb = {
47947 + .notifier_call = otg_handle_notification
47948 +};
47949 #endif
47950
47951 static struct regulator *ac_draw;
47952 @@ -369,7 +373,6 @@ static int pda_power_probe(struct platform_device *pdev)
47953
47954 #if IS_ENABLED(CONFIG_USB_PHY)
47955 if (!IS_ERR_OR_NULL(transceiver) && pdata->use_otg_notifier) {
47956 - otg_nb.notifier_call = otg_handle_notification;
47957 ret = usb_register_notifier(transceiver, &otg_nb);
47958 if (ret) {
47959 dev_err(dev, "failure to register otg notifier\n");
47960 diff --git a/drivers/power/power_supply.h b/drivers/power/power_supply.h
47961 index cc439fd..8fa30df 100644
47962 --- a/drivers/power/power_supply.h
47963 +++ b/drivers/power/power_supply.h
47964 @@ -16,12 +16,12 @@ struct power_supply;
47965
47966 #ifdef CONFIG_SYSFS
47967
47968 -extern void power_supply_init_attrs(struct device_type *dev_type);
47969 +extern void power_supply_init_attrs(void);
47970 extern int power_supply_uevent(struct device *dev, struct kobj_uevent_env *env);
47971
47972 #else
47973
47974 -static inline void power_supply_init_attrs(struct device_type *dev_type) {}
47975 +static inline void power_supply_init_attrs(void) {}
47976 #define power_supply_uevent NULL
47977
47978 #endif /* CONFIG_SYSFS */
47979 diff --git a/drivers/power/power_supply_core.c b/drivers/power/power_supply_core.c
47980 index 557af94..84dc1fe 100644
47981 --- a/drivers/power/power_supply_core.c
47982 +++ b/drivers/power/power_supply_core.c
47983 @@ -24,7 +24,10 @@
47984 struct class *power_supply_class;
47985 EXPORT_SYMBOL_GPL(power_supply_class);
47986
47987 -static struct device_type power_supply_dev_type;
47988 +extern const struct attribute_group *power_supply_attr_groups[];
47989 +static struct device_type power_supply_dev_type = {
47990 + .groups = power_supply_attr_groups,
47991 +};
47992
47993 static bool __power_supply_is_supplied_by(struct power_supply *supplier,
47994 struct power_supply *supply)
47995 @@ -584,7 +587,7 @@ static int __init power_supply_class_init(void)
47996 return PTR_ERR(power_supply_class);
47997
47998 power_supply_class->dev_uevent = power_supply_uevent;
47999 - power_supply_init_attrs(&power_supply_dev_type);
48000 + power_supply_init_attrs();
48001
48002 return 0;
48003 }
48004 diff --git a/drivers/power/power_supply_sysfs.c b/drivers/power/power_supply_sysfs.c
48005 index 44420d1..967126e 100644
48006 --- a/drivers/power/power_supply_sysfs.c
48007 +++ b/drivers/power/power_supply_sysfs.c
48008 @@ -230,17 +230,15 @@ static struct attribute_group power_supply_attr_group = {
48009 .is_visible = power_supply_attr_is_visible,
48010 };
48011
48012 -static const struct attribute_group *power_supply_attr_groups[] = {
48013 +const struct attribute_group *power_supply_attr_groups[] = {
48014 &power_supply_attr_group,
48015 NULL,
48016 };
48017
48018 -void power_supply_init_attrs(struct device_type *dev_type)
48019 +void power_supply_init_attrs(void)
48020 {
48021 int i;
48022
48023 - dev_type->groups = power_supply_attr_groups;
48024 -
48025 for (i = 0; i < ARRAY_SIZE(power_supply_attrs); i++)
48026 __power_supply_attrs[i] = &power_supply_attrs[i].attr;
48027 }
48028 diff --git a/drivers/powercap/powercap_sys.c b/drivers/powercap/powercap_sys.c
48029 index 84419af..268ede8 100644
48030 --- a/drivers/powercap/powercap_sys.c
48031 +++ b/drivers/powercap/powercap_sys.c
48032 @@ -154,8 +154,77 @@ struct powercap_constraint_attr {
48033 struct device_attribute name_attr;
48034 };
48035
48036 +static ssize_t show_constraint_name(struct device *dev,
48037 + struct device_attribute *dev_attr,
48038 + char *buf);
48039 +
48040 static struct powercap_constraint_attr
48041 - constraint_attrs[MAX_CONSTRAINTS_PER_ZONE];
48042 + constraint_attrs[MAX_CONSTRAINTS_PER_ZONE] = {
48043 + [0 ... MAX_CONSTRAINTS_PER_ZONE - 1] = {
48044 + .power_limit_attr = {
48045 + .attr = {
48046 + .name = NULL,
48047 + .mode = S_IWUSR | S_IRUGO
48048 + },
48049 + .show = show_constraint_power_limit_uw,
48050 + .store = store_constraint_power_limit_uw
48051 + },
48052 +
48053 + .time_window_attr = {
48054 + .attr = {
48055 + .name = NULL,
48056 + .mode = S_IWUSR | S_IRUGO
48057 + },
48058 + .show = show_constraint_time_window_us,
48059 + .store = store_constraint_time_window_us
48060 + },
48061 +
48062 + .max_power_attr = {
48063 + .attr = {
48064 + .name = NULL,
48065 + .mode = S_IRUGO
48066 + },
48067 + .show = show_constraint_max_power_uw,
48068 + .store = NULL
48069 + },
48070 +
48071 + .min_power_attr = {
48072 + .attr = {
48073 + .name = NULL,
48074 + .mode = S_IRUGO
48075 + },
48076 + .show = show_constraint_min_power_uw,
48077 + .store = NULL
48078 + },
48079 +
48080 + .max_time_window_attr = {
48081 + .attr = {
48082 + .name = NULL,
48083 + .mode = S_IRUGO
48084 + },
48085 + .show = show_constraint_max_time_window_us,
48086 + .store = NULL
48087 + },
48088 +
48089 + .min_time_window_attr = {
48090 + .attr = {
48091 + .name = NULL,
48092 + .mode = S_IRUGO
48093 + },
48094 + .show = show_constraint_min_time_window_us,
48095 + .store = NULL
48096 + },
48097 +
48098 + .name_attr = {
48099 + .attr = {
48100 + .name = NULL,
48101 + .mode = S_IRUGO
48102 + },
48103 + .show = show_constraint_name,
48104 + .store = NULL
48105 + }
48106 + }
48107 +};
48108
48109 /* A list of powercap control_types */
48110 static LIST_HEAD(powercap_cntrl_list);
48111 @@ -193,23 +262,16 @@ static ssize_t show_constraint_name(struct device *dev,
48112 }
48113
48114 static int create_constraint_attribute(int id, const char *name,
48115 - int mode,
48116 - struct device_attribute *dev_attr,
48117 - ssize_t (*show)(struct device *,
48118 - struct device_attribute *, char *),
48119 - ssize_t (*store)(struct device *,
48120 - struct device_attribute *,
48121 - const char *, size_t)
48122 - )
48123 + struct device_attribute *dev_attr)
48124 {
48125 + name = kasprintf(GFP_KERNEL, "constraint_%d_%s", id, name);
48126
48127 - dev_attr->attr.name = kasprintf(GFP_KERNEL, "constraint_%d_%s",
48128 - id, name);
48129 - if (!dev_attr->attr.name)
48130 + if (!name)
48131 return -ENOMEM;
48132 - dev_attr->attr.mode = mode;
48133 - dev_attr->show = show;
48134 - dev_attr->store = store;
48135 +
48136 + pax_open_kernel();
48137 + *(const char **)&dev_attr->attr.name = name;
48138 + pax_close_kernel();
48139
48140 return 0;
48141 }
48142 @@ -236,49 +298,31 @@ static int seed_constraint_attributes(void)
48143
48144 for (i = 0; i < MAX_CONSTRAINTS_PER_ZONE; ++i) {
48145 ret = create_constraint_attribute(i, "power_limit_uw",
48146 - S_IWUSR | S_IRUGO,
48147 - &constraint_attrs[i].power_limit_attr,
48148 - show_constraint_power_limit_uw,
48149 - store_constraint_power_limit_uw);
48150 + &constraint_attrs[i].power_limit_attr);
48151 if (ret)
48152 goto err_alloc;
48153 ret = create_constraint_attribute(i, "time_window_us",
48154 - S_IWUSR | S_IRUGO,
48155 - &constraint_attrs[i].time_window_attr,
48156 - show_constraint_time_window_us,
48157 - store_constraint_time_window_us);
48158 + &constraint_attrs[i].time_window_attr);
48159 if (ret)
48160 goto err_alloc;
48161 - ret = create_constraint_attribute(i, "name", S_IRUGO,
48162 - &constraint_attrs[i].name_attr,
48163 - show_constraint_name,
48164 - NULL);
48165 + ret = create_constraint_attribute(i, "name",
48166 + &constraint_attrs[i].name_attr);
48167 if (ret)
48168 goto err_alloc;
48169 - ret = create_constraint_attribute(i, "max_power_uw", S_IRUGO,
48170 - &constraint_attrs[i].max_power_attr,
48171 - show_constraint_max_power_uw,
48172 - NULL);
48173 + ret = create_constraint_attribute(i, "max_power_uw",
48174 + &constraint_attrs[i].max_power_attr);
48175 if (ret)
48176 goto err_alloc;
48177 - ret = create_constraint_attribute(i, "min_power_uw", S_IRUGO,
48178 - &constraint_attrs[i].min_power_attr,
48179 - show_constraint_min_power_uw,
48180 - NULL);
48181 + ret = create_constraint_attribute(i, "min_power_uw",
48182 + &constraint_attrs[i].min_power_attr);
48183 if (ret)
48184 goto err_alloc;
48185 ret = create_constraint_attribute(i, "max_time_window_us",
48186 - S_IRUGO,
48187 - &constraint_attrs[i].max_time_window_attr,
48188 - show_constraint_max_time_window_us,
48189 - NULL);
48190 + &constraint_attrs[i].max_time_window_attr);
48191 if (ret)
48192 goto err_alloc;
48193 ret = create_constraint_attribute(i, "min_time_window_us",
48194 - S_IRUGO,
48195 - &constraint_attrs[i].min_time_window_attr,
48196 - show_constraint_min_time_window_us,
48197 - NULL);
48198 + &constraint_attrs[i].min_time_window_attr);
48199 if (ret)
48200 goto err_alloc;
48201
48202 @@ -378,10 +422,12 @@ static void create_power_zone_common_attributes(
48203 power_zone->zone_dev_attrs[count++] =
48204 &dev_attr_max_energy_range_uj.attr;
48205 if (power_zone->ops->get_energy_uj) {
48206 + pax_open_kernel();
48207 if (power_zone->ops->reset_energy_uj)
48208 - dev_attr_energy_uj.attr.mode = S_IWUSR | S_IRUGO;
48209 + *(umode_t *)&dev_attr_energy_uj.attr.mode = S_IWUSR | S_IRUGO;
48210 else
48211 - dev_attr_energy_uj.attr.mode = S_IRUGO;
48212 + *(umode_t *)&dev_attr_energy_uj.attr.mode = S_IRUGO;
48213 + pax_close_kernel();
48214 power_zone->zone_dev_attrs[count++] =
48215 &dev_attr_energy_uj.attr;
48216 }
48217 diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c
48218 index 7271299..20217a5 100644
48219 --- a/drivers/regulator/core.c
48220 +++ b/drivers/regulator/core.c
48221 @@ -3366,7 +3366,7 @@ regulator_register(const struct regulator_desc *regulator_desc,
48222 {
48223 const struct regulation_constraints *constraints = NULL;
48224 const struct regulator_init_data *init_data;
48225 - static atomic_t regulator_no = ATOMIC_INIT(0);
48226 + static atomic_unchecked_t regulator_no = ATOMIC_INIT(0);
48227 struct regulator_dev *rdev;
48228 struct device *dev;
48229 int ret, i;
48230 @@ -3436,7 +3436,7 @@ regulator_register(const struct regulator_desc *regulator_desc,
48231 rdev->dev.of_node = config->of_node;
48232 rdev->dev.parent = dev;
48233 dev_set_name(&rdev->dev, "regulator.%d",
48234 - atomic_inc_return(&regulator_no) - 1);
48235 + atomic_inc_return_unchecked(&regulator_no) - 1);
48236 ret = device_register(&rdev->dev);
48237 if (ret != 0) {
48238 put_device(&rdev->dev);
48239 diff --git a/drivers/regulator/max8660.c b/drivers/regulator/max8660.c
48240 index 8d94d3d..653b623 100644
48241 --- a/drivers/regulator/max8660.c
48242 +++ b/drivers/regulator/max8660.c
48243 @@ -420,8 +420,10 @@ static int max8660_probe(struct i2c_client *client,
48244 max8660->shadow_regs[MAX8660_OVER1] = 5;
48245 } else {
48246 /* Otherwise devices can be toggled via software */
48247 - max8660_dcdc_ops.enable = max8660_dcdc_enable;
48248 - max8660_dcdc_ops.disable = max8660_dcdc_disable;
48249 + pax_open_kernel();
48250 + *(void **)&max8660_dcdc_ops.enable = max8660_dcdc_enable;
48251 + *(void **)&max8660_dcdc_ops.disable = max8660_dcdc_disable;
48252 + pax_close_kernel();
48253 }
48254
48255 /*
48256 diff --git a/drivers/regulator/max8973-regulator.c b/drivers/regulator/max8973-regulator.c
48257 index 892aa1e..ebd1b9c 100644
48258 --- a/drivers/regulator/max8973-regulator.c
48259 +++ b/drivers/regulator/max8973-regulator.c
48260 @@ -406,9 +406,11 @@ static int max8973_probe(struct i2c_client *client,
48261 if (!pdata || !pdata->enable_ext_control) {
48262 max->desc.enable_reg = MAX8973_VOUT;
48263 max->desc.enable_mask = MAX8973_VOUT_ENABLE;
48264 - max->ops.enable = regulator_enable_regmap;
48265 - max->ops.disable = regulator_disable_regmap;
48266 - max->ops.is_enabled = regulator_is_enabled_regmap;
48267 + pax_open_kernel();
48268 + *(void **)&max->ops.enable = regulator_enable_regmap;
48269 + *(void **)&max->ops.disable = regulator_disable_regmap;
48270 + *(void **)&max->ops.is_enabled = regulator_is_enabled_regmap;
48271 + pax_close_kernel();
48272 }
48273
48274 if (pdata) {
48275 diff --git a/drivers/regulator/mc13892-regulator.c b/drivers/regulator/mc13892-regulator.c
48276 index 96c9f80..90974ca 100644
48277 --- a/drivers/regulator/mc13892-regulator.c
48278 +++ b/drivers/regulator/mc13892-regulator.c
48279 @@ -582,10 +582,12 @@ static int mc13892_regulator_probe(struct platform_device *pdev)
48280 }
48281 mc13xxx_unlock(mc13892);
48282
48283 - mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
48284 + pax_open_kernel();
48285 + *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
48286 = mc13892_vcam_set_mode;
48287 - mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
48288 + *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
48289 = mc13892_vcam_get_mode;
48290 + pax_close_kernel();
48291
48292 mc13xxx_data = mc13xxx_parse_regulators_dt(pdev, mc13892_regulators,
48293 ARRAY_SIZE(mc13892_regulators));
48294 diff --git a/drivers/rtc/rtc-cmos.c b/drivers/rtc/rtc-cmos.c
48295 index a2325bc..04c549f 100644
48296 --- a/drivers/rtc/rtc-cmos.c
48297 +++ b/drivers/rtc/rtc-cmos.c
48298 @@ -779,7 +779,9 @@ cmos_do_probe(struct device *dev, struct resource *ports, int rtc_irq)
48299 hpet_rtc_timer_init();
48300
48301 /* export at least the first block of NVRAM */
48302 - nvram.size = address_space - NVRAM_OFFSET;
48303 + pax_open_kernel();
48304 + *(size_t *)&nvram.size = address_space - NVRAM_OFFSET;
48305 + pax_close_kernel();
48306 retval = sysfs_create_bin_file(&dev->kobj, &nvram);
48307 if (retval < 0) {
48308 dev_dbg(dev, "can't create nvram file? %d\n", retval);
48309 diff --git a/drivers/rtc/rtc-dev.c b/drivers/rtc/rtc-dev.c
48310 index d049393..bb20be0 100644
48311 --- a/drivers/rtc/rtc-dev.c
48312 +++ b/drivers/rtc/rtc-dev.c
48313 @@ -16,6 +16,7 @@
48314 #include <linux/module.h>
48315 #include <linux/rtc.h>
48316 #include <linux/sched.h>
48317 +#include <linux/grsecurity.h>
48318 #include "rtc-core.h"
48319
48320 static dev_t rtc_devt;
48321 @@ -347,6 +348,8 @@ static long rtc_dev_ioctl(struct file *file,
48322 if (copy_from_user(&tm, uarg, sizeof(tm)))
48323 return -EFAULT;
48324
48325 + gr_log_timechange();
48326 +
48327 return rtc_set_time(rtc, &tm);
48328
48329 case RTC_PIE_ON:
48330 diff --git a/drivers/rtc/rtc-ds1307.c b/drivers/rtc/rtc-ds1307.c
48331 index 4e75345..09f8663 100644
48332 --- a/drivers/rtc/rtc-ds1307.c
48333 +++ b/drivers/rtc/rtc-ds1307.c
48334 @@ -107,7 +107,7 @@ struct ds1307 {
48335 u8 offset; /* register's offset */
48336 u8 regs[11];
48337 u16 nvram_offset;
48338 - struct bin_attribute *nvram;
48339 + bin_attribute_no_const *nvram;
48340 enum ds_type type;
48341 unsigned long flags;
48342 #define HAS_NVRAM 0 /* bit 0 == sysfs file active */
48343 diff --git a/drivers/rtc/rtc-m48t59.c b/drivers/rtc/rtc-m48t59.c
48344 index 11880c1..b823aa4 100644
48345 --- a/drivers/rtc/rtc-m48t59.c
48346 +++ b/drivers/rtc/rtc-m48t59.c
48347 @@ -483,7 +483,9 @@ static int m48t59_rtc_probe(struct platform_device *pdev)
48348 if (IS_ERR(m48t59->rtc))
48349 return PTR_ERR(m48t59->rtc);
48350
48351 - m48t59_nvram_attr.size = pdata->offset;
48352 + pax_open_kernel();
48353 + *(size_t *)&m48t59_nvram_attr.size = pdata->offset;
48354 + pax_close_kernel();
48355
48356 ret = sysfs_create_bin_file(&pdev->dev.kobj, &m48t59_nvram_attr);
48357 if (ret)
48358 diff --git a/drivers/scsi/aic7xxx/aic79xx_pci.c b/drivers/scsi/aic7xxx/aic79xx_pci.c
48359 index 14b5f8d..cc9bd26 100644
48360 --- a/drivers/scsi/aic7xxx/aic79xx_pci.c
48361 +++ b/drivers/scsi/aic7xxx/aic79xx_pci.c
48362 @@ -827,7 +827,7 @@ ahd_pci_intr(struct ahd_softc *ahd)
48363 for (bit = 0; bit < 8; bit++) {
48364
48365 if ((pci_status[i] & (0x1 << bit)) != 0) {
48366 - static const char *s;
48367 + const char *s;
48368
48369 s = pci_status_strings[bit];
48370 if (i == 7/*TARG*/ && bit == 3)
48371 @@ -887,23 +887,15 @@ ahd_pci_split_intr(struct ahd_softc *ahd, u_int intstat)
48372
48373 for (bit = 0; bit < 8; bit++) {
48374
48375 - if ((split_status[i] & (0x1 << bit)) != 0) {
48376 - static const char *s;
48377 -
48378 - s = split_status_strings[bit];
48379 - printk(s, ahd_name(ahd),
48380 + if ((split_status[i] & (0x1 << bit)) != 0)
48381 + printk(split_status_strings[bit], ahd_name(ahd),
48382 split_status_source[i]);
48383 - }
48384
48385 if (i > 1)
48386 continue;
48387
48388 - if ((sg_split_status[i] & (0x1 << bit)) != 0) {
48389 - static const char *s;
48390 -
48391 - s = split_status_strings[bit];
48392 - printk(s, ahd_name(ahd), "SG");
48393 - }
48394 + if ((sg_split_status[i] & (0x1 << bit)) != 0)
48395 + printk(split_status_strings[bit], ahd_name(ahd), "SG");
48396 }
48397 }
48398 /*
48399 diff --git a/drivers/scsi/bfa/bfa_fcpim.h b/drivers/scsi/bfa/bfa_fcpim.h
48400 index e693af6..2e525b6 100644
48401 --- a/drivers/scsi/bfa/bfa_fcpim.h
48402 +++ b/drivers/scsi/bfa/bfa_fcpim.h
48403 @@ -36,7 +36,7 @@ struct bfa_iotag_s {
48404
48405 struct bfa_itn_s {
48406 bfa_isr_func_t isr;
48407 -};
48408 +} __no_const;
48409
48410 void bfa_itn_create(struct bfa_s *bfa, struct bfa_rport_s *rport,
48411 void (*isr)(struct bfa_s *bfa, struct bfi_msg_s *m));
48412 diff --git a/drivers/scsi/bfa/bfa_fcs.c b/drivers/scsi/bfa/bfa_fcs.c
48413 index a3ab5cc..8143622 100644
48414 --- a/drivers/scsi/bfa/bfa_fcs.c
48415 +++ b/drivers/scsi/bfa/bfa_fcs.c
48416 @@ -38,10 +38,21 @@ struct bfa_fcs_mod_s {
48417 #define BFA_FCS_MODULE(_mod) { _mod ## _modinit, _mod ## _modexit }
48418
48419 static struct bfa_fcs_mod_s fcs_modules[] = {
48420 - { bfa_fcs_port_attach, NULL, NULL },
48421 - { bfa_fcs_uf_attach, NULL, NULL },
48422 - { bfa_fcs_fabric_attach, bfa_fcs_fabric_modinit,
48423 - bfa_fcs_fabric_modexit },
48424 + {
48425 + .attach = bfa_fcs_port_attach,
48426 + .modinit = NULL,
48427 + .modexit = NULL
48428 + },
48429 + {
48430 + .attach = bfa_fcs_uf_attach,
48431 + .modinit = NULL,
48432 + .modexit = NULL
48433 + },
48434 + {
48435 + .attach = bfa_fcs_fabric_attach,
48436 + .modinit = bfa_fcs_fabric_modinit,
48437 + .modexit = bfa_fcs_fabric_modexit
48438 + },
48439 };
48440
48441 /*
48442 diff --git a/drivers/scsi/bfa/bfa_fcs_lport.c b/drivers/scsi/bfa/bfa_fcs_lport.c
48443 index f5e4e61..a0acaf6 100644
48444 --- a/drivers/scsi/bfa/bfa_fcs_lport.c
48445 +++ b/drivers/scsi/bfa/bfa_fcs_lport.c
48446 @@ -89,15 +89,26 @@ static struct {
48447 void (*offline) (struct bfa_fcs_lport_s *port);
48448 } __port_action[] = {
48449 {
48450 - bfa_fcs_lport_unknown_init, bfa_fcs_lport_unknown_online,
48451 - bfa_fcs_lport_unknown_offline}, {
48452 - bfa_fcs_lport_fab_init, bfa_fcs_lport_fab_online,
48453 - bfa_fcs_lport_fab_offline}, {
48454 - bfa_fcs_lport_n2n_init, bfa_fcs_lport_n2n_online,
48455 - bfa_fcs_lport_n2n_offline}, {
48456 - bfa_fcs_lport_loop_init, bfa_fcs_lport_loop_online,
48457 - bfa_fcs_lport_loop_offline},
48458 - };
48459 + .init = bfa_fcs_lport_unknown_init,
48460 + .online = bfa_fcs_lport_unknown_online,
48461 + .offline = bfa_fcs_lport_unknown_offline
48462 + },
48463 + {
48464 + .init = bfa_fcs_lport_fab_init,
48465 + .online = bfa_fcs_lport_fab_online,
48466 + .offline = bfa_fcs_lport_fab_offline
48467 + },
48468 + {
48469 + .init = bfa_fcs_lport_n2n_init,
48470 + .online = bfa_fcs_lport_n2n_online,
48471 + .offline = bfa_fcs_lport_n2n_offline
48472 + },
48473 + {
48474 + .init = bfa_fcs_lport_loop_init,
48475 + .online = bfa_fcs_lport_loop_online,
48476 + .offline = bfa_fcs_lport_loop_offline
48477 + },
48478 +};
48479
48480 /*
48481 * fcs_port_sm FCS logical port state machine
48482 diff --git a/drivers/scsi/bfa/bfa_ioc.h b/drivers/scsi/bfa/bfa_ioc.h
48483 index 90814fe..4384138 100644
48484 --- a/drivers/scsi/bfa/bfa_ioc.h
48485 +++ b/drivers/scsi/bfa/bfa_ioc.h
48486 @@ -258,7 +258,7 @@ struct bfa_ioc_cbfn_s {
48487 bfa_ioc_disable_cbfn_t disable_cbfn;
48488 bfa_ioc_hbfail_cbfn_t hbfail_cbfn;
48489 bfa_ioc_reset_cbfn_t reset_cbfn;
48490 -};
48491 +} __no_const;
48492
48493 /*
48494 * IOC event notification mechanism.
48495 @@ -352,7 +352,7 @@ struct bfa_ioc_hwif_s {
48496 void (*ioc_set_alt_fwstate) (struct bfa_ioc_s *ioc,
48497 enum bfi_ioc_state fwstate);
48498 enum bfi_ioc_state (*ioc_get_alt_fwstate) (struct bfa_ioc_s *ioc);
48499 -};
48500 +} __no_const;
48501
48502 /*
48503 * Queue element to wait for room in request queue. FIFO order is
48504 diff --git a/drivers/scsi/bfa/bfa_modules.h b/drivers/scsi/bfa/bfa_modules.h
48505 index a14c784..6de6790 100644
48506 --- a/drivers/scsi/bfa/bfa_modules.h
48507 +++ b/drivers/scsi/bfa/bfa_modules.h
48508 @@ -78,12 +78,12 @@ enum {
48509 \
48510 extern struct bfa_module_s hal_mod_ ## __mod; \
48511 struct bfa_module_s hal_mod_ ## __mod = { \
48512 - bfa_ ## __mod ## _meminfo, \
48513 - bfa_ ## __mod ## _attach, \
48514 - bfa_ ## __mod ## _detach, \
48515 - bfa_ ## __mod ## _start, \
48516 - bfa_ ## __mod ## _stop, \
48517 - bfa_ ## __mod ## _iocdisable, \
48518 + .meminfo = bfa_ ## __mod ## _meminfo, \
48519 + .attach = bfa_ ## __mod ## _attach, \
48520 + .detach = bfa_ ## __mod ## _detach, \
48521 + .start = bfa_ ## __mod ## _start, \
48522 + .stop = bfa_ ## __mod ## _stop, \
48523 + .iocdisable = bfa_ ## __mod ## _iocdisable, \
48524 }
48525
48526 #define BFA_CACHELINE_SZ (256)
48527 diff --git a/drivers/scsi/fcoe/fcoe_sysfs.c b/drivers/scsi/fcoe/fcoe_sysfs.c
48528 index 045c4e1..13de803 100644
48529 --- a/drivers/scsi/fcoe/fcoe_sysfs.c
48530 +++ b/drivers/scsi/fcoe/fcoe_sysfs.c
48531 @@ -33,8 +33,8 @@
48532 */
48533 #include "libfcoe.h"
48534
48535 -static atomic_t ctlr_num;
48536 -static atomic_t fcf_num;
48537 +static atomic_unchecked_t ctlr_num;
48538 +static atomic_unchecked_t fcf_num;
48539
48540 /*
48541 * fcoe_fcf_dev_loss_tmo: the default number of seconds that fcoe sysfs
48542 @@ -685,7 +685,7 @@ struct fcoe_ctlr_device *fcoe_ctlr_device_add(struct device *parent,
48543 if (!ctlr)
48544 goto out;
48545
48546 - ctlr->id = atomic_inc_return(&ctlr_num) - 1;
48547 + ctlr->id = atomic_inc_return_unchecked(&ctlr_num) - 1;
48548 ctlr->f = f;
48549 ctlr->mode = FIP_CONN_TYPE_FABRIC;
48550 INIT_LIST_HEAD(&ctlr->fcfs);
48551 @@ -902,7 +902,7 @@ struct fcoe_fcf_device *fcoe_fcf_device_add(struct fcoe_ctlr_device *ctlr,
48552 fcf->dev.parent = &ctlr->dev;
48553 fcf->dev.bus = &fcoe_bus_type;
48554 fcf->dev.type = &fcoe_fcf_device_type;
48555 - fcf->id = atomic_inc_return(&fcf_num) - 1;
48556 + fcf->id = atomic_inc_return_unchecked(&fcf_num) - 1;
48557 fcf->state = FCOE_FCF_STATE_UNKNOWN;
48558
48559 fcf->dev_loss_tmo = ctlr->fcf_dev_loss_tmo;
48560 @@ -938,8 +938,8 @@ int __init fcoe_sysfs_setup(void)
48561 {
48562 int error;
48563
48564 - atomic_set(&ctlr_num, 0);
48565 - atomic_set(&fcf_num, 0);
48566 + atomic_set_unchecked(&ctlr_num, 0);
48567 + atomic_set_unchecked(&fcf_num, 0);
48568
48569 error = bus_register(&fcoe_bus_type);
48570 if (error)
48571 diff --git a/drivers/scsi/hosts.c b/drivers/scsi/hosts.c
48572 index f2c5005..db36c02 100644
48573 --- a/drivers/scsi/hosts.c
48574 +++ b/drivers/scsi/hosts.c
48575 @@ -42,7 +42,7 @@
48576 #include "scsi_logging.h"
48577
48578
48579 -static atomic_t scsi_host_next_hn = ATOMIC_INIT(0); /* host_no for next new host */
48580 +static atomic_unchecked_t scsi_host_next_hn = ATOMIC_INIT(0); /* host_no for next new host */
48581
48582
48583 static void scsi_host_cls_release(struct device *dev)
48584 @@ -367,7 +367,7 @@ struct Scsi_Host *scsi_host_alloc(struct scsi_host_template *sht, int privsize)
48585 * subtract one because we increment first then return, but we need to
48586 * know what the next host number was before increment
48587 */
48588 - shost->host_no = atomic_inc_return(&scsi_host_next_hn) - 1;
48589 + shost->host_no = atomic_inc_return_unchecked(&scsi_host_next_hn) - 1;
48590 shost->dma_channel = 0xff;
48591
48592 /* These three are default values which can be overridden */
48593 diff --git a/drivers/scsi/hpsa.c b/drivers/scsi/hpsa.c
48594 index 20a5e6e..8b23cea 100644
48595 --- a/drivers/scsi/hpsa.c
48596 +++ b/drivers/scsi/hpsa.c
48597 @@ -578,7 +578,7 @@ static inline u32 next_command(struct ctlr_info *h, u8 q)
48598 unsigned long flags;
48599
48600 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
48601 - return h->access.command_completed(h, q);
48602 + return h->access->command_completed(h, q);
48603
48604 if ((rq->head[rq->current_entry] & 1) == rq->wraparound) {
48605 a = rq->head[rq->current_entry];
48606 @@ -3444,7 +3444,7 @@ static void start_io(struct ctlr_info *h)
48607 while (!list_empty(&h->reqQ)) {
48608 c = list_entry(h->reqQ.next, struct CommandList, list);
48609 /* can't do anything if fifo is full */
48610 - if ((h->access.fifo_full(h))) {
48611 + if ((h->access->fifo_full(h))) {
48612 dev_warn(&h->pdev->dev, "fifo full\n");
48613 break;
48614 }
48615 @@ -3466,7 +3466,7 @@ static void start_io(struct ctlr_info *h)
48616
48617 /* Tell the controller execute command */
48618 spin_unlock_irqrestore(&h->lock, flags);
48619 - h->access.submit_command(h, c);
48620 + h->access->submit_command(h, c);
48621 spin_lock_irqsave(&h->lock, flags);
48622 }
48623 spin_unlock_irqrestore(&h->lock, flags);
48624 @@ -3474,17 +3474,17 @@ static void start_io(struct ctlr_info *h)
48625
48626 static inline unsigned long get_next_completion(struct ctlr_info *h, u8 q)
48627 {
48628 - return h->access.command_completed(h, q);
48629 + return h->access->command_completed(h, q);
48630 }
48631
48632 static inline bool interrupt_pending(struct ctlr_info *h)
48633 {
48634 - return h->access.intr_pending(h);
48635 + return h->access->intr_pending(h);
48636 }
48637
48638 static inline long interrupt_not_for_us(struct ctlr_info *h)
48639 {
48640 - return (h->access.intr_pending(h) == 0) ||
48641 + return (h->access->intr_pending(h) == 0) ||
48642 (h->interrupts_enabled == 0);
48643 }
48644
48645 @@ -4386,7 +4386,7 @@ static int hpsa_pci_init(struct ctlr_info *h)
48646 if (prod_index < 0)
48647 return -ENODEV;
48648 h->product_name = products[prod_index].product_name;
48649 - h->access = *(products[prod_index].access);
48650 + h->access = products[prod_index].access;
48651
48652 pci_disable_link_state(h->pdev, PCIE_LINK_STATE_L0S |
48653 PCIE_LINK_STATE_L1 | PCIE_LINK_STATE_CLKPM);
48654 @@ -4668,7 +4668,7 @@ static void controller_lockup_detected(struct ctlr_info *h)
48655
48656 assert_spin_locked(&lockup_detector_lock);
48657 remove_ctlr_from_lockup_detector_list(h);
48658 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
48659 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
48660 spin_lock_irqsave(&h->lock, flags);
48661 h->lockup_detected = readl(h->vaddr + SA5_SCRATCHPAD_OFFSET);
48662 spin_unlock_irqrestore(&h->lock, flags);
48663 @@ -4845,7 +4845,7 @@ reinit_after_soft_reset:
48664 }
48665
48666 /* make sure the board interrupts are off */
48667 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
48668 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
48669
48670 if (hpsa_request_irq(h, do_hpsa_intr_msi, do_hpsa_intr_intx))
48671 goto clean2;
48672 @@ -4879,7 +4879,7 @@ reinit_after_soft_reset:
48673 * fake ones to scoop up any residual completions.
48674 */
48675 spin_lock_irqsave(&h->lock, flags);
48676 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
48677 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
48678 spin_unlock_irqrestore(&h->lock, flags);
48679 free_irqs(h);
48680 rc = hpsa_request_irq(h, hpsa_msix_discard_completions,
48681 @@ -4898,9 +4898,9 @@ reinit_after_soft_reset:
48682 dev_info(&h->pdev->dev, "Board READY.\n");
48683 dev_info(&h->pdev->dev,
48684 "Waiting for stale completions to drain.\n");
48685 - h->access.set_intr_mask(h, HPSA_INTR_ON);
48686 + h->access->set_intr_mask(h, HPSA_INTR_ON);
48687 msleep(10000);
48688 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
48689 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
48690
48691 rc = controller_reset_failed(h->cfgtable);
48692 if (rc)
48693 @@ -4921,7 +4921,7 @@ reinit_after_soft_reset:
48694 }
48695
48696 /* Turn the interrupts on so we can service requests */
48697 - h->access.set_intr_mask(h, HPSA_INTR_ON);
48698 + h->access->set_intr_mask(h, HPSA_INTR_ON);
48699
48700 hpsa_hba_inquiry(h);
48701 hpsa_register_scsi(h); /* hook ourselves into SCSI subsystem */
48702 @@ -4976,7 +4976,7 @@ static void hpsa_shutdown(struct pci_dev *pdev)
48703 * To write all data in the battery backed cache to disks
48704 */
48705 hpsa_flush_cache(h);
48706 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
48707 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
48708 hpsa_free_irqs_and_disable_msix(h);
48709 }
48710
48711 @@ -5143,7 +5143,7 @@ static void hpsa_enter_performant_mode(struct ctlr_info *h, u32 use_short_tags)
48712 return;
48713 }
48714 /* Change the access methods to the performant access methods */
48715 - h->access = SA5_performant_access;
48716 + h->access = &SA5_performant_access;
48717 h->transMethod = CFGTBL_Trans_Performant;
48718 }
48719
48720 diff --git a/drivers/scsi/hpsa.h b/drivers/scsi/hpsa.h
48721 index bc85e72..d463049 100644
48722 --- a/drivers/scsi/hpsa.h
48723 +++ b/drivers/scsi/hpsa.h
48724 @@ -79,7 +79,7 @@ struct ctlr_info {
48725 unsigned int msix_vector;
48726 unsigned int msi_vector;
48727 int intr_mode; /* either PERF_MODE_INT or SIMPLE_MODE_INT */
48728 - struct access_method access;
48729 + struct access_method *access;
48730
48731 /* queue and queue Info */
48732 struct list_head reqQ;
48733 @@ -381,19 +381,19 @@ static bool SA5_performant_intr_pending(struct ctlr_info *h)
48734 }
48735
48736 static struct access_method SA5_access = {
48737 - SA5_submit_command,
48738 - SA5_intr_mask,
48739 - SA5_fifo_full,
48740 - SA5_intr_pending,
48741 - SA5_completed,
48742 + .submit_command = SA5_submit_command,
48743 + .set_intr_mask = SA5_intr_mask,
48744 + .fifo_full = SA5_fifo_full,
48745 + .intr_pending = SA5_intr_pending,
48746 + .command_completed = SA5_completed,
48747 };
48748
48749 static struct access_method SA5_performant_access = {
48750 - SA5_submit_command,
48751 - SA5_performant_intr_mask,
48752 - SA5_fifo_full,
48753 - SA5_performant_intr_pending,
48754 - SA5_performant_completed,
48755 + .submit_command = SA5_submit_command,
48756 + .set_intr_mask = SA5_performant_intr_mask,
48757 + .fifo_full = SA5_fifo_full,
48758 + .intr_pending = SA5_performant_intr_pending,
48759 + .command_completed = SA5_performant_completed,
48760 };
48761
48762 struct board_type {
48763 diff --git a/drivers/scsi/libfc/fc_exch.c b/drivers/scsi/libfc/fc_exch.c
48764 index 1b3a094..068e683 100644
48765 --- a/drivers/scsi/libfc/fc_exch.c
48766 +++ b/drivers/scsi/libfc/fc_exch.c
48767 @@ -101,12 +101,12 @@ struct fc_exch_mgr {
48768 u16 pool_max_index;
48769
48770 struct {
48771 - atomic_t no_free_exch;
48772 - atomic_t no_free_exch_xid;
48773 - atomic_t xid_not_found;
48774 - atomic_t xid_busy;
48775 - atomic_t seq_not_found;
48776 - atomic_t non_bls_resp;
48777 + atomic_unchecked_t no_free_exch;
48778 + atomic_unchecked_t no_free_exch_xid;
48779 + atomic_unchecked_t xid_not_found;
48780 + atomic_unchecked_t xid_busy;
48781 + atomic_unchecked_t seq_not_found;
48782 + atomic_unchecked_t non_bls_resp;
48783 } stats;
48784 };
48785
48786 @@ -811,7 +811,7 @@ static struct fc_exch *fc_exch_em_alloc(struct fc_lport *lport,
48787 /* allocate memory for exchange */
48788 ep = mempool_alloc(mp->ep_pool, GFP_ATOMIC);
48789 if (!ep) {
48790 - atomic_inc(&mp->stats.no_free_exch);
48791 + atomic_inc_unchecked(&mp->stats.no_free_exch);
48792 goto out;
48793 }
48794 memset(ep, 0, sizeof(*ep));
48795 @@ -874,7 +874,7 @@ out:
48796 return ep;
48797 err:
48798 spin_unlock_bh(&pool->lock);
48799 - atomic_inc(&mp->stats.no_free_exch_xid);
48800 + atomic_inc_unchecked(&mp->stats.no_free_exch_xid);
48801 mempool_free(ep, mp->ep_pool);
48802 return NULL;
48803 }
48804 @@ -1023,7 +1023,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
48805 xid = ntohs(fh->fh_ox_id); /* we originated exch */
48806 ep = fc_exch_find(mp, xid);
48807 if (!ep) {
48808 - atomic_inc(&mp->stats.xid_not_found);
48809 + atomic_inc_unchecked(&mp->stats.xid_not_found);
48810 reject = FC_RJT_OX_ID;
48811 goto out;
48812 }
48813 @@ -1053,7 +1053,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
48814 ep = fc_exch_find(mp, xid);
48815 if ((f_ctl & FC_FC_FIRST_SEQ) && fc_sof_is_init(fr_sof(fp))) {
48816 if (ep) {
48817 - atomic_inc(&mp->stats.xid_busy);
48818 + atomic_inc_unchecked(&mp->stats.xid_busy);
48819 reject = FC_RJT_RX_ID;
48820 goto rel;
48821 }
48822 @@ -1064,7 +1064,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
48823 }
48824 xid = ep->xid; /* get our XID */
48825 } else if (!ep) {
48826 - atomic_inc(&mp->stats.xid_not_found);
48827 + atomic_inc_unchecked(&mp->stats.xid_not_found);
48828 reject = FC_RJT_RX_ID; /* XID not found */
48829 goto out;
48830 }
48831 @@ -1082,7 +1082,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
48832 } else {
48833 sp = &ep->seq;
48834 if (sp->id != fh->fh_seq_id) {
48835 - atomic_inc(&mp->stats.seq_not_found);
48836 + atomic_inc_unchecked(&mp->stats.seq_not_found);
48837 if (f_ctl & FC_FC_END_SEQ) {
48838 /*
48839 * Update sequence_id based on incoming last
48840 @@ -1533,22 +1533,22 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
48841
48842 ep = fc_exch_find(mp, ntohs(fh->fh_ox_id));
48843 if (!ep) {
48844 - atomic_inc(&mp->stats.xid_not_found);
48845 + atomic_inc_unchecked(&mp->stats.xid_not_found);
48846 goto out;
48847 }
48848 if (ep->esb_stat & ESB_ST_COMPLETE) {
48849 - atomic_inc(&mp->stats.xid_not_found);
48850 + atomic_inc_unchecked(&mp->stats.xid_not_found);
48851 goto rel;
48852 }
48853 if (ep->rxid == FC_XID_UNKNOWN)
48854 ep->rxid = ntohs(fh->fh_rx_id);
48855 if (ep->sid != 0 && ep->sid != ntoh24(fh->fh_d_id)) {
48856 - atomic_inc(&mp->stats.xid_not_found);
48857 + atomic_inc_unchecked(&mp->stats.xid_not_found);
48858 goto rel;
48859 }
48860 if (ep->did != ntoh24(fh->fh_s_id) &&
48861 ep->did != FC_FID_FLOGI) {
48862 - atomic_inc(&mp->stats.xid_not_found);
48863 + atomic_inc_unchecked(&mp->stats.xid_not_found);
48864 goto rel;
48865 }
48866 sof = fr_sof(fp);
48867 @@ -1557,7 +1557,7 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
48868 sp->ssb_stat |= SSB_ST_RESP;
48869 sp->id = fh->fh_seq_id;
48870 } else if (sp->id != fh->fh_seq_id) {
48871 - atomic_inc(&mp->stats.seq_not_found);
48872 + atomic_inc_unchecked(&mp->stats.seq_not_found);
48873 goto rel;
48874 }
48875
48876 @@ -1619,9 +1619,9 @@ static void fc_exch_recv_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
48877 sp = fc_seq_lookup_orig(mp, fp); /* doesn't hold sequence */
48878
48879 if (!sp)
48880 - atomic_inc(&mp->stats.xid_not_found);
48881 + atomic_inc_unchecked(&mp->stats.xid_not_found);
48882 else
48883 - atomic_inc(&mp->stats.non_bls_resp);
48884 + atomic_inc_unchecked(&mp->stats.non_bls_resp);
48885
48886 fc_frame_free(fp);
48887 }
48888 @@ -2261,13 +2261,13 @@ void fc_exch_update_stats(struct fc_lport *lport)
48889
48890 list_for_each_entry(ema, &lport->ema_list, ema_list) {
48891 mp = ema->mp;
48892 - st->fc_no_free_exch += atomic_read(&mp->stats.no_free_exch);
48893 + st->fc_no_free_exch += atomic_read_unchecked(&mp->stats.no_free_exch);
48894 st->fc_no_free_exch_xid +=
48895 - atomic_read(&mp->stats.no_free_exch_xid);
48896 - st->fc_xid_not_found += atomic_read(&mp->stats.xid_not_found);
48897 - st->fc_xid_busy += atomic_read(&mp->stats.xid_busy);
48898 - st->fc_seq_not_found += atomic_read(&mp->stats.seq_not_found);
48899 - st->fc_non_bls_resp += atomic_read(&mp->stats.non_bls_resp);
48900 + atomic_read_unchecked(&mp->stats.no_free_exch_xid);
48901 + st->fc_xid_not_found += atomic_read_unchecked(&mp->stats.xid_not_found);
48902 + st->fc_xid_busy += atomic_read_unchecked(&mp->stats.xid_busy);
48903 + st->fc_seq_not_found += atomic_read_unchecked(&mp->stats.seq_not_found);
48904 + st->fc_non_bls_resp += atomic_read_unchecked(&mp->stats.non_bls_resp);
48905 }
48906 }
48907 EXPORT_SYMBOL(fc_exch_update_stats);
48908 diff --git a/drivers/scsi/libsas/sas_ata.c b/drivers/scsi/libsas/sas_ata.c
48909 index d289583..b745eec 100644
48910 --- a/drivers/scsi/libsas/sas_ata.c
48911 +++ b/drivers/scsi/libsas/sas_ata.c
48912 @@ -554,7 +554,7 @@ static struct ata_port_operations sas_sata_ops = {
48913 .postreset = ata_std_postreset,
48914 .error_handler = ata_std_error_handler,
48915 .post_internal_cmd = sas_ata_post_internal,
48916 - .qc_defer = ata_std_qc_defer,
48917 + .qc_defer = ata_std_qc_defer,
48918 .qc_prep = ata_noop_qc_prep,
48919 .qc_issue = sas_ata_qc_issue,
48920 .qc_fill_rtf = sas_ata_qc_fill_rtf,
48921 diff --git a/drivers/scsi/lpfc/lpfc.h b/drivers/scsi/lpfc/lpfc.h
48922 index 4e1b75c..0bbdfa9 100644
48923 --- a/drivers/scsi/lpfc/lpfc.h
48924 +++ b/drivers/scsi/lpfc/lpfc.h
48925 @@ -432,7 +432,7 @@ struct lpfc_vport {
48926 struct dentry *debug_nodelist;
48927 struct dentry *vport_debugfs_root;
48928 struct lpfc_debugfs_trc *disc_trc;
48929 - atomic_t disc_trc_cnt;
48930 + atomic_unchecked_t disc_trc_cnt;
48931 #endif
48932 uint8_t stat_data_enabled;
48933 uint8_t stat_data_blocked;
48934 @@ -865,8 +865,8 @@ struct lpfc_hba {
48935 struct timer_list fabric_block_timer;
48936 unsigned long bit_flags;
48937 #define FABRIC_COMANDS_BLOCKED 0
48938 - atomic_t num_rsrc_err;
48939 - atomic_t num_cmd_success;
48940 + atomic_unchecked_t num_rsrc_err;
48941 + atomic_unchecked_t num_cmd_success;
48942 unsigned long last_rsrc_error_time;
48943 unsigned long last_ramp_down_time;
48944 unsigned long last_ramp_up_time;
48945 @@ -902,7 +902,7 @@ struct lpfc_hba {
48946
48947 struct dentry *debug_slow_ring_trc;
48948 struct lpfc_debugfs_trc *slow_ring_trc;
48949 - atomic_t slow_ring_trc_cnt;
48950 + atomic_unchecked_t slow_ring_trc_cnt;
48951 /* iDiag debugfs sub-directory */
48952 struct dentry *idiag_root;
48953 struct dentry *idiag_pci_cfg;
48954 diff --git a/drivers/scsi/lpfc/lpfc_debugfs.c b/drivers/scsi/lpfc/lpfc_debugfs.c
48955 index 60084e6..0e2e700 100644
48956 --- a/drivers/scsi/lpfc/lpfc_debugfs.c
48957 +++ b/drivers/scsi/lpfc/lpfc_debugfs.c
48958 @@ -106,7 +106,7 @@ MODULE_PARM_DESC(lpfc_debugfs_mask_disc_trc,
48959
48960 #include <linux/debugfs.h>
48961
48962 -static atomic_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
48963 +static atomic_unchecked_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
48964 static unsigned long lpfc_debugfs_start_time = 0L;
48965
48966 /* iDiag */
48967 @@ -147,7 +147,7 @@ lpfc_debugfs_disc_trc_data(struct lpfc_vport *vport, char *buf, int size)
48968 lpfc_debugfs_enable = 0;
48969
48970 len = 0;
48971 - index = (atomic_read(&vport->disc_trc_cnt) + 1) &
48972 + index = (atomic_read_unchecked(&vport->disc_trc_cnt) + 1) &
48973 (lpfc_debugfs_max_disc_trc - 1);
48974 for (i = index; i < lpfc_debugfs_max_disc_trc; i++) {
48975 dtp = vport->disc_trc + i;
48976 @@ -213,7 +213,7 @@ lpfc_debugfs_slow_ring_trc_data(struct lpfc_hba *phba, char *buf, int size)
48977 lpfc_debugfs_enable = 0;
48978
48979 len = 0;
48980 - index = (atomic_read(&phba->slow_ring_trc_cnt) + 1) &
48981 + index = (atomic_read_unchecked(&phba->slow_ring_trc_cnt) + 1) &
48982 (lpfc_debugfs_max_slow_ring_trc - 1);
48983 for (i = index; i < lpfc_debugfs_max_slow_ring_trc; i++) {
48984 dtp = phba->slow_ring_trc + i;
48985 @@ -646,14 +646,14 @@ lpfc_debugfs_disc_trc(struct lpfc_vport *vport, int mask, char *fmt,
48986 !vport || !vport->disc_trc)
48987 return;
48988
48989 - index = atomic_inc_return(&vport->disc_trc_cnt) &
48990 + index = atomic_inc_return_unchecked(&vport->disc_trc_cnt) &
48991 (lpfc_debugfs_max_disc_trc - 1);
48992 dtp = vport->disc_trc + index;
48993 dtp->fmt = fmt;
48994 dtp->data1 = data1;
48995 dtp->data2 = data2;
48996 dtp->data3 = data3;
48997 - dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
48998 + dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
48999 dtp->jif = jiffies;
49000 #endif
49001 return;
49002 @@ -684,14 +684,14 @@ lpfc_debugfs_slow_ring_trc(struct lpfc_hba *phba, char *fmt,
49003 !phba || !phba->slow_ring_trc)
49004 return;
49005
49006 - index = atomic_inc_return(&phba->slow_ring_trc_cnt) &
49007 + index = atomic_inc_return_unchecked(&phba->slow_ring_trc_cnt) &
49008 (lpfc_debugfs_max_slow_ring_trc - 1);
49009 dtp = phba->slow_ring_trc + index;
49010 dtp->fmt = fmt;
49011 dtp->data1 = data1;
49012 dtp->data2 = data2;
49013 dtp->data3 = data3;
49014 - dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
49015 + dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
49016 dtp->jif = jiffies;
49017 #endif
49018 return;
49019 @@ -4168,7 +4168,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
49020 "slow_ring buffer\n");
49021 goto debug_failed;
49022 }
49023 - atomic_set(&phba->slow_ring_trc_cnt, 0);
49024 + atomic_set_unchecked(&phba->slow_ring_trc_cnt, 0);
49025 memset(phba->slow_ring_trc, 0,
49026 (sizeof(struct lpfc_debugfs_trc) *
49027 lpfc_debugfs_max_slow_ring_trc));
49028 @@ -4214,7 +4214,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
49029 "buffer\n");
49030 goto debug_failed;
49031 }
49032 - atomic_set(&vport->disc_trc_cnt, 0);
49033 + atomic_set_unchecked(&vport->disc_trc_cnt, 0);
49034
49035 snprintf(name, sizeof(name), "discovery_trace");
49036 vport->debug_disc_trc =
49037 diff --git a/drivers/scsi/lpfc/lpfc_init.c b/drivers/scsi/lpfc/lpfc_init.c
49038 index 68c94cc..8c27be5 100644
49039 --- a/drivers/scsi/lpfc/lpfc_init.c
49040 +++ b/drivers/scsi/lpfc/lpfc_init.c
49041 @@ -10949,8 +10949,10 @@ lpfc_init(void)
49042 "misc_register returned with status %d", error);
49043
49044 if (lpfc_enable_npiv) {
49045 - lpfc_transport_functions.vport_create = lpfc_vport_create;
49046 - lpfc_transport_functions.vport_delete = lpfc_vport_delete;
49047 + pax_open_kernel();
49048 + *(void **)&lpfc_transport_functions.vport_create = lpfc_vport_create;
49049 + *(void **)&lpfc_transport_functions.vport_delete = lpfc_vport_delete;
49050 + pax_close_kernel();
49051 }
49052 lpfc_transport_template =
49053 fc_attach_transport(&lpfc_transport_functions);
49054 diff --git a/drivers/scsi/lpfc/lpfc_scsi.c b/drivers/scsi/lpfc/lpfc_scsi.c
49055 index b2ede05..aaf482ca 100644
49056 --- a/drivers/scsi/lpfc/lpfc_scsi.c
49057 +++ b/drivers/scsi/lpfc/lpfc_scsi.c
49058 @@ -353,7 +353,7 @@ lpfc_rampdown_queue_depth(struct lpfc_hba *phba)
49059 uint32_t evt_posted;
49060
49061 spin_lock_irqsave(&phba->hbalock, flags);
49062 - atomic_inc(&phba->num_rsrc_err);
49063 + atomic_inc_unchecked(&phba->num_rsrc_err);
49064 phba->last_rsrc_error_time = jiffies;
49065
49066 if ((phba->last_ramp_down_time + QUEUE_RAMP_DOWN_INTERVAL) > jiffies) {
49067 @@ -394,7 +394,7 @@ lpfc_rampup_queue_depth(struct lpfc_vport *vport,
49068 unsigned long flags;
49069 struct lpfc_hba *phba = vport->phba;
49070 uint32_t evt_posted;
49071 - atomic_inc(&phba->num_cmd_success);
49072 + atomic_inc_unchecked(&phba->num_cmd_success);
49073
49074 if (vport->cfg_lun_queue_depth <= queue_depth)
49075 return;
49076 @@ -438,8 +438,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
49077 unsigned long num_rsrc_err, num_cmd_success;
49078 int i;
49079
49080 - num_rsrc_err = atomic_read(&phba->num_rsrc_err);
49081 - num_cmd_success = atomic_read(&phba->num_cmd_success);
49082 + num_rsrc_err = atomic_read_unchecked(&phba->num_rsrc_err);
49083 + num_cmd_success = atomic_read_unchecked(&phba->num_cmd_success);
49084
49085 /*
49086 * The error and success command counters are global per
49087 @@ -467,8 +467,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
49088 }
49089 }
49090 lpfc_destroy_vport_work_array(phba, vports);
49091 - atomic_set(&phba->num_rsrc_err, 0);
49092 - atomic_set(&phba->num_cmd_success, 0);
49093 + atomic_set_unchecked(&phba->num_rsrc_err, 0);
49094 + atomic_set_unchecked(&phba->num_cmd_success, 0);
49095 }
49096
49097 /**
49098 @@ -502,8 +502,8 @@ lpfc_ramp_up_queue_handler(struct lpfc_hba *phba)
49099 }
49100 }
49101 lpfc_destroy_vport_work_array(phba, vports);
49102 - atomic_set(&phba->num_rsrc_err, 0);
49103 - atomic_set(&phba->num_cmd_success, 0);
49104 + atomic_set_unchecked(&phba->num_rsrc_err, 0);
49105 + atomic_set_unchecked(&phba->num_cmd_success, 0);
49106 }
49107
49108 /**
49109 diff --git a/drivers/scsi/mpt2sas/mpt2sas_scsih.c b/drivers/scsi/mpt2sas/mpt2sas_scsih.c
49110 index 7f0af4f..193ac3e 100644
49111 --- a/drivers/scsi/mpt2sas/mpt2sas_scsih.c
49112 +++ b/drivers/scsi/mpt2sas/mpt2sas_scsih.c
49113 @@ -1557,7 +1557,7 @@ _scsih_get_resync(struct device *dev)
49114 {
49115 struct scsi_device *sdev = to_scsi_device(dev);
49116 struct MPT2SAS_ADAPTER *ioc = shost_priv(sdev->host);
49117 - static struct _raid_device *raid_device;
49118 + struct _raid_device *raid_device;
49119 unsigned long flags;
49120 Mpi2RaidVolPage0_t vol_pg0;
49121 Mpi2ConfigReply_t mpi_reply;
49122 @@ -1609,7 +1609,7 @@ _scsih_get_state(struct device *dev)
49123 {
49124 struct scsi_device *sdev = to_scsi_device(dev);
49125 struct MPT2SAS_ADAPTER *ioc = shost_priv(sdev->host);
49126 - static struct _raid_device *raid_device;
49127 + struct _raid_device *raid_device;
49128 unsigned long flags;
49129 Mpi2RaidVolPage0_t vol_pg0;
49130 Mpi2ConfigReply_t mpi_reply;
49131 @@ -6637,7 +6637,7 @@ _scsih_sas_ir_operation_status_event(struct MPT2SAS_ADAPTER *ioc,
49132 struct fw_event_work *fw_event)
49133 {
49134 Mpi2EventDataIrOperationStatus_t *event_data = fw_event->event_data;
49135 - static struct _raid_device *raid_device;
49136 + struct _raid_device *raid_device;
49137 unsigned long flags;
49138 u16 handle;
49139
49140 @@ -7108,7 +7108,7 @@ _scsih_scan_for_devices_after_reset(struct MPT2SAS_ADAPTER *ioc)
49141 u64 sas_address;
49142 struct _sas_device *sas_device;
49143 struct _sas_node *expander_device;
49144 - static struct _raid_device *raid_device;
49145 + struct _raid_device *raid_device;
49146 u8 retry_count;
49147 unsigned long flags;
49148
49149 diff --git a/drivers/scsi/pmcraid.c b/drivers/scsi/pmcraid.c
49150 index be8ce54..94ed33a 100644
49151 --- a/drivers/scsi/pmcraid.c
49152 +++ b/drivers/scsi/pmcraid.c
49153 @@ -200,8 +200,8 @@ static int pmcraid_slave_alloc(struct scsi_device *scsi_dev)
49154 res->scsi_dev = scsi_dev;
49155 scsi_dev->hostdata = res;
49156 res->change_detected = 0;
49157 - atomic_set(&res->read_failures, 0);
49158 - atomic_set(&res->write_failures, 0);
49159 + atomic_set_unchecked(&res->read_failures, 0);
49160 + atomic_set_unchecked(&res->write_failures, 0);
49161 rc = 0;
49162 }
49163 spin_unlock_irqrestore(&pinstance->resource_lock, lock_flags);
49164 @@ -2687,9 +2687,9 @@ static int pmcraid_error_handler(struct pmcraid_cmd *cmd)
49165
49166 /* If this was a SCSI read/write command keep count of errors */
49167 if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_READ_CMD)
49168 - atomic_inc(&res->read_failures);
49169 + atomic_inc_unchecked(&res->read_failures);
49170 else if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_WRITE_CMD)
49171 - atomic_inc(&res->write_failures);
49172 + atomic_inc_unchecked(&res->write_failures);
49173
49174 if (!RES_IS_GSCSI(res->cfg_entry) &&
49175 masked_ioasc != PMCRAID_IOASC_HW_DEVICE_BUS_STATUS_ERROR) {
49176 @@ -3545,7 +3545,7 @@ static int pmcraid_queuecommand_lck(
49177 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
49178 * hrrq_id assigned here in queuecommand
49179 */
49180 - ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
49181 + ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
49182 pinstance->num_hrrq;
49183 cmd->cmd_done = pmcraid_io_done;
49184
49185 @@ -3857,7 +3857,7 @@ static long pmcraid_ioctl_passthrough(
49186 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
49187 * hrrq_id assigned here in queuecommand
49188 */
49189 - ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
49190 + ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
49191 pinstance->num_hrrq;
49192
49193 if (request_size) {
49194 @@ -4495,7 +4495,7 @@ static void pmcraid_worker_function(struct work_struct *workp)
49195
49196 pinstance = container_of(workp, struct pmcraid_instance, worker_q);
49197 /* add resources only after host is added into system */
49198 - if (!atomic_read(&pinstance->expose_resources))
49199 + if (!atomic_read_unchecked(&pinstance->expose_resources))
49200 return;
49201
49202 fw_version = be16_to_cpu(pinstance->inq_data->fw_version);
49203 @@ -5322,8 +5322,8 @@ static int pmcraid_init_instance(struct pci_dev *pdev, struct Scsi_Host *host,
49204 init_waitqueue_head(&pinstance->reset_wait_q);
49205
49206 atomic_set(&pinstance->outstanding_cmds, 0);
49207 - atomic_set(&pinstance->last_message_id, 0);
49208 - atomic_set(&pinstance->expose_resources, 0);
49209 + atomic_set_unchecked(&pinstance->last_message_id, 0);
49210 + atomic_set_unchecked(&pinstance->expose_resources, 0);
49211
49212 INIT_LIST_HEAD(&pinstance->free_res_q);
49213 INIT_LIST_HEAD(&pinstance->used_res_q);
49214 @@ -6036,7 +6036,7 @@ static int pmcraid_probe(struct pci_dev *pdev,
49215 /* Schedule worker thread to handle CCN and take care of adding and
49216 * removing devices to OS
49217 */
49218 - atomic_set(&pinstance->expose_resources, 1);
49219 + atomic_set_unchecked(&pinstance->expose_resources, 1);
49220 schedule_work(&pinstance->worker_q);
49221 return rc;
49222
49223 diff --git a/drivers/scsi/pmcraid.h b/drivers/scsi/pmcraid.h
49224 index e1d150f..6c6df44 100644
49225 --- a/drivers/scsi/pmcraid.h
49226 +++ b/drivers/scsi/pmcraid.h
49227 @@ -748,7 +748,7 @@ struct pmcraid_instance {
49228 struct pmcraid_isr_param hrrq_vector[PMCRAID_NUM_MSIX_VECTORS];
49229
49230 /* Message id as filled in last fired IOARCB, used to identify HRRQ */
49231 - atomic_t last_message_id;
49232 + atomic_unchecked_t last_message_id;
49233
49234 /* configuration table */
49235 struct pmcraid_config_table *cfg_table;
49236 @@ -777,7 +777,7 @@ struct pmcraid_instance {
49237 atomic_t outstanding_cmds;
49238
49239 /* should add/delete resources to mid-layer now ?*/
49240 - atomic_t expose_resources;
49241 + atomic_unchecked_t expose_resources;
49242
49243
49244
49245 @@ -813,8 +813,8 @@ struct pmcraid_resource_entry {
49246 struct pmcraid_config_table_entry_ext cfg_entry_ext;
49247 };
49248 struct scsi_device *scsi_dev; /* Link scsi_device structure */
49249 - atomic_t read_failures; /* count of failed READ commands */
49250 - atomic_t write_failures; /* count of failed WRITE commands */
49251 + atomic_unchecked_t read_failures; /* count of failed READ commands */
49252 + atomic_unchecked_t write_failures; /* count of failed WRITE commands */
49253
49254 /* To indicate add/delete/modify during CCN */
49255 u8 change_detected;
49256 diff --git a/drivers/scsi/qla2xxx/qla_attr.c b/drivers/scsi/qla2xxx/qla_attr.c
49257 index 5f174b8..98d32b0 100644
49258 --- a/drivers/scsi/qla2xxx/qla_attr.c
49259 +++ b/drivers/scsi/qla2xxx/qla_attr.c
49260 @@ -2040,7 +2040,7 @@ qla24xx_vport_disable(struct fc_vport *fc_vport, bool disable)
49261 return 0;
49262 }
49263
49264 -struct fc_function_template qla2xxx_transport_functions = {
49265 +fc_function_template_no_const qla2xxx_transport_functions = {
49266
49267 .show_host_node_name = 1,
49268 .show_host_port_name = 1,
49269 @@ -2088,7 +2088,7 @@ struct fc_function_template qla2xxx_transport_functions = {
49270 .bsg_timeout = qla24xx_bsg_timeout,
49271 };
49272
49273 -struct fc_function_template qla2xxx_transport_vport_functions = {
49274 +fc_function_template_no_const qla2xxx_transport_vport_functions = {
49275
49276 .show_host_node_name = 1,
49277 .show_host_port_name = 1,
49278 diff --git a/drivers/scsi/qla2xxx/qla_gbl.h b/drivers/scsi/qla2xxx/qla_gbl.h
49279 index 4446bf5..9a3574d 100644
49280 --- a/drivers/scsi/qla2xxx/qla_gbl.h
49281 +++ b/drivers/scsi/qla2xxx/qla_gbl.h
49282 @@ -538,8 +538,8 @@ extern void qla2x00_get_sym_node_name(scsi_qla_host_t *, uint8_t *);
49283 struct device_attribute;
49284 extern struct device_attribute *qla2x00_host_attrs[];
49285 struct fc_function_template;
49286 -extern struct fc_function_template qla2xxx_transport_functions;
49287 -extern struct fc_function_template qla2xxx_transport_vport_functions;
49288 +extern fc_function_template_no_const qla2xxx_transport_functions;
49289 +extern fc_function_template_no_const qla2xxx_transport_vport_functions;
49290 extern void qla2x00_alloc_sysfs_attr(scsi_qla_host_t *);
49291 extern void qla2x00_free_sysfs_attr(scsi_qla_host_t *);
49292 extern void qla2x00_init_host_attr(scsi_qla_host_t *);
49293 diff --git a/drivers/scsi/qla2xxx/qla_os.c b/drivers/scsi/qla2xxx/qla_os.c
49294 index 52be35e..b933907 100644
49295 --- a/drivers/scsi/qla2xxx/qla_os.c
49296 +++ b/drivers/scsi/qla2xxx/qla_os.c
49297 @@ -1568,8 +1568,10 @@ qla2x00_config_dma_addressing(struct qla_hw_data *ha)
49298 !pci_set_consistent_dma_mask(ha->pdev, DMA_BIT_MASK(64))) {
49299 /* Ok, a 64bit DMA mask is applicable. */
49300 ha->flags.enable_64bit_addressing = 1;
49301 - ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
49302 - ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
49303 + pax_open_kernel();
49304 + *(void **)&ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
49305 + *(void **)&ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
49306 + pax_close_kernel();
49307 return;
49308 }
49309 }
49310 diff --git a/drivers/scsi/qla4xxx/ql4_def.h b/drivers/scsi/qla4xxx/ql4_def.h
49311 index 084d1fd..9f939eb 100644
49312 --- a/drivers/scsi/qla4xxx/ql4_def.h
49313 +++ b/drivers/scsi/qla4xxx/ql4_def.h
49314 @@ -296,7 +296,7 @@ struct ddb_entry {
49315 * (4000 only) */
49316 atomic_t relogin_timer; /* Max Time to wait for
49317 * relogin to complete */
49318 - atomic_t relogin_retry_count; /* Num of times relogin has been
49319 + atomic_unchecked_t relogin_retry_count; /* Num of times relogin has been
49320 * retried */
49321 uint32_t default_time2wait; /* Default Min time between
49322 * relogins (+aens) */
49323 diff --git a/drivers/scsi/qla4xxx/ql4_os.c b/drivers/scsi/qla4xxx/ql4_os.c
49324 index cf174a4..128a420 100644
49325 --- a/drivers/scsi/qla4xxx/ql4_os.c
49326 +++ b/drivers/scsi/qla4xxx/ql4_os.c
49327 @@ -3311,12 +3311,12 @@ static void qla4xxx_check_relogin_flash_ddb(struct iscsi_cls_session *cls_sess)
49328 */
49329 if (!iscsi_is_session_online(cls_sess)) {
49330 /* Reset retry relogin timer */
49331 - atomic_inc(&ddb_entry->relogin_retry_count);
49332 + atomic_inc_unchecked(&ddb_entry->relogin_retry_count);
49333 DEBUG2(ql4_printk(KERN_INFO, ha,
49334 "%s: index[%d] relogin timed out-retrying"
49335 " relogin (%d), retry (%d)\n", __func__,
49336 ddb_entry->fw_ddb_index,
49337 - atomic_read(&ddb_entry->relogin_retry_count),
49338 + atomic_read_unchecked(&ddb_entry->relogin_retry_count),
49339 ddb_entry->default_time2wait + 4));
49340 set_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags);
49341 atomic_set(&ddb_entry->retry_relogin_timer,
49342 @@ -5458,7 +5458,7 @@ static void qla4xxx_setup_flash_ddb_entry(struct scsi_qla_host *ha,
49343
49344 atomic_set(&ddb_entry->retry_relogin_timer, INVALID_ENTRY);
49345 atomic_set(&ddb_entry->relogin_timer, 0);
49346 - atomic_set(&ddb_entry->relogin_retry_count, 0);
49347 + atomic_set_unchecked(&ddb_entry->relogin_retry_count, 0);
49348 def_timeout = le16_to_cpu(ddb_entry->fw_ddb_entry.def_timeout);
49349 ddb_entry->default_relogin_timeout =
49350 (def_timeout > LOGIN_TOV) && (def_timeout < LOGIN_TOV * 10) ?
49351 diff --git a/drivers/scsi/scsi.c b/drivers/scsi/scsi.c
49352 index fe0bcb1..c9255be 100644
49353 --- a/drivers/scsi/scsi.c
49354 +++ b/drivers/scsi/scsi.c
49355 @@ -655,7 +655,7 @@ int scsi_dispatch_cmd(struct scsi_cmnd *cmd)
49356 struct Scsi_Host *host = cmd->device->host;
49357 int rtn = 0;
49358
49359 - atomic_inc(&cmd->device->iorequest_cnt);
49360 + atomic_inc_unchecked(&cmd->device->iorequest_cnt);
49361
49362 /* check if the device is still usable */
49363 if (unlikely(cmd->device->sdev_state == SDEV_DEL)) {
49364 diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
49365 index 62ec84b..93159d8 100644
49366 --- a/drivers/scsi/scsi_lib.c
49367 +++ b/drivers/scsi/scsi_lib.c
49368 @@ -1474,7 +1474,7 @@ static void scsi_kill_request(struct request *req, struct request_queue *q)
49369 shost = sdev->host;
49370 scsi_init_cmd_errh(cmd);
49371 cmd->result = DID_NO_CONNECT << 16;
49372 - atomic_inc(&cmd->device->iorequest_cnt);
49373 + atomic_inc_unchecked(&cmd->device->iorequest_cnt);
49374
49375 /*
49376 * SCSI request completion path will do scsi_device_unbusy(),
49377 @@ -1500,9 +1500,9 @@ static void scsi_softirq_done(struct request *rq)
49378
49379 INIT_LIST_HEAD(&cmd->eh_entry);
49380
49381 - atomic_inc(&cmd->device->iodone_cnt);
49382 + atomic_inc_unchecked(&cmd->device->iodone_cnt);
49383 if (cmd->result)
49384 - atomic_inc(&cmd->device->ioerr_cnt);
49385 + atomic_inc_unchecked(&cmd->device->ioerr_cnt);
49386
49387 disposition = scsi_decide_disposition(cmd);
49388 if (disposition != SUCCESS &&
49389 diff --git a/drivers/scsi/scsi_sysfs.c b/drivers/scsi/scsi_sysfs.c
49390 index 8ff62c2..693b6f7 100644
49391 --- a/drivers/scsi/scsi_sysfs.c
49392 +++ b/drivers/scsi/scsi_sysfs.c
49393 @@ -725,7 +725,7 @@ show_iostat_##field(struct device *dev, struct device_attribute *attr, \
49394 char *buf) \
49395 { \
49396 struct scsi_device *sdev = to_scsi_device(dev); \
49397 - unsigned long long count = atomic_read(&sdev->field); \
49398 + unsigned long long count = atomic_read_unchecked(&sdev->field); \
49399 return snprintf(buf, 20, "0x%llx\n", count); \
49400 } \
49401 static DEVICE_ATTR(field, S_IRUGO, show_iostat_##field, NULL)
49402 diff --git a/drivers/scsi/scsi_tgt_lib.c b/drivers/scsi/scsi_tgt_lib.c
49403 index 84a1fdf..693b0d6 100644
49404 --- a/drivers/scsi/scsi_tgt_lib.c
49405 +++ b/drivers/scsi/scsi_tgt_lib.c
49406 @@ -362,7 +362,7 @@ static int scsi_map_user_pages(struct scsi_tgt_cmd *tcmd, struct scsi_cmnd *cmd,
49407 int err;
49408
49409 dprintk("%lx %u\n", uaddr, len);
49410 - err = blk_rq_map_user(q, rq, NULL, (void *)uaddr, len, GFP_KERNEL);
49411 + err = blk_rq_map_user(q, rq, NULL, (void __user *)uaddr, len, GFP_KERNEL);
49412 if (err) {
49413 /*
49414 * TODO: need to fixup sg_tablesize, max_segment_size,
49415 diff --git a/drivers/scsi/scsi_transport_fc.c b/drivers/scsi/scsi_transport_fc.c
49416 index 4628fd5..a94a1c2 100644
49417 --- a/drivers/scsi/scsi_transport_fc.c
49418 +++ b/drivers/scsi/scsi_transport_fc.c
49419 @@ -497,7 +497,7 @@ static DECLARE_TRANSPORT_CLASS(fc_vport_class,
49420 * Netlink Infrastructure
49421 */
49422
49423 -static atomic_t fc_event_seq;
49424 +static atomic_unchecked_t fc_event_seq;
49425
49426 /**
49427 * fc_get_event_number - Obtain the next sequential FC event number
49428 @@ -510,7 +510,7 @@ static atomic_t fc_event_seq;
49429 u32
49430 fc_get_event_number(void)
49431 {
49432 - return atomic_add_return(1, &fc_event_seq);
49433 + return atomic_add_return_unchecked(1, &fc_event_seq);
49434 }
49435 EXPORT_SYMBOL(fc_get_event_number);
49436
49437 @@ -654,7 +654,7 @@ static __init int fc_transport_init(void)
49438 {
49439 int error;
49440
49441 - atomic_set(&fc_event_seq, 0);
49442 + atomic_set_unchecked(&fc_event_seq, 0);
49443
49444 error = transport_class_register(&fc_host_class);
49445 if (error)
49446 @@ -844,7 +844,7 @@ static int fc_str_to_dev_loss(const char *buf, unsigned long *val)
49447 char *cp;
49448
49449 *val = simple_strtoul(buf, &cp, 0);
49450 - if ((*cp && (*cp != '\n')) || (*val < 0))
49451 + if (*cp && (*cp != '\n'))
49452 return -EINVAL;
49453 /*
49454 * Check for overflow; dev_loss_tmo is u32
49455 diff --git a/drivers/scsi/scsi_transport_iscsi.c b/drivers/scsi/scsi_transport_iscsi.c
49456 index 63a6ca4..5d5cadd 100644
49457 --- a/drivers/scsi/scsi_transport_iscsi.c
49458 +++ b/drivers/scsi/scsi_transport_iscsi.c
49459 @@ -79,7 +79,7 @@ struct iscsi_internal {
49460 struct transport_container session_cont;
49461 };
49462
49463 -static atomic_t iscsi_session_nr; /* sysfs session id for next new session */
49464 +static atomic_unchecked_t iscsi_session_nr; /* sysfs session id for next new session */
49465 static struct workqueue_struct *iscsi_eh_timer_workq;
49466
49467 static DEFINE_IDA(iscsi_sess_ida);
49468 @@ -1737,7 +1737,7 @@ int iscsi_add_session(struct iscsi_cls_session *session, unsigned int target_id)
49469 int err;
49470
49471 ihost = shost->shost_data;
49472 - session->sid = atomic_add_return(1, &iscsi_session_nr);
49473 + session->sid = atomic_add_return_unchecked(1, &iscsi_session_nr);
49474
49475 if (target_id == ISCSI_MAX_TARGET) {
49476 id = ida_simple_get(&iscsi_sess_ida, 0, 0, GFP_KERNEL);
49477 @@ -4103,7 +4103,7 @@ static __init int iscsi_transport_init(void)
49478 printk(KERN_INFO "Loading iSCSI transport class v%s.\n",
49479 ISCSI_TRANSPORT_VERSION);
49480
49481 - atomic_set(&iscsi_session_nr, 0);
49482 + atomic_set_unchecked(&iscsi_session_nr, 0);
49483
49484 err = class_register(&iscsi_transport_class);
49485 if (err)
49486 diff --git a/drivers/scsi/scsi_transport_srp.c b/drivers/scsi/scsi_transport_srp.c
49487 index 2700a5a..752ec38 100644
49488 --- a/drivers/scsi/scsi_transport_srp.c
49489 +++ b/drivers/scsi/scsi_transport_srp.c
49490 @@ -36,7 +36,7 @@
49491 #include "scsi_transport_srp_internal.h"
49492
49493 struct srp_host_attrs {
49494 - atomic_t next_port_id;
49495 + atomic_unchecked_t next_port_id;
49496 };
49497 #define to_srp_host_attrs(host) ((struct srp_host_attrs *)(host)->shost_data)
49498
49499 @@ -94,7 +94,7 @@ static int srp_host_setup(struct transport_container *tc, struct device *dev,
49500 struct Scsi_Host *shost = dev_to_shost(dev);
49501 struct srp_host_attrs *srp_host = to_srp_host_attrs(shost);
49502
49503 - atomic_set(&srp_host->next_port_id, 0);
49504 + atomic_set_unchecked(&srp_host->next_port_id, 0);
49505 return 0;
49506 }
49507
49508 @@ -730,7 +730,7 @@ struct srp_rport *srp_rport_add(struct Scsi_Host *shost,
49509 rport_fast_io_fail_timedout);
49510 INIT_DELAYED_WORK(&rport->dev_loss_work, rport_dev_loss_timedout);
49511
49512 - id = atomic_inc_return(&to_srp_host_attrs(shost)->next_port_id);
49513 + id = atomic_inc_return_unchecked(&to_srp_host_attrs(shost)->next_port_id);
49514 dev_set_name(&rport->dev, "port-%d:%d", shost->host_no, id);
49515
49516 transport_setup_device(&rport->dev);
49517 diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
49518 index 69725f7..03aaee1 100644
49519 --- a/drivers/scsi/sd.c
49520 +++ b/drivers/scsi/sd.c
49521 @@ -2964,7 +2964,7 @@ static int sd_probe(struct device *dev)
49522 sdkp->disk = gd;
49523 sdkp->index = index;
49524 atomic_set(&sdkp->openers, 0);
49525 - atomic_set(&sdkp->device->ioerr_cnt, 0);
49526 + atomic_set_unchecked(&sdkp->device->ioerr_cnt, 0);
49527
49528 if (!sdp->request_queue->rq_timeout) {
49529 if (sdp->type != TYPE_MOD)
49530 diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c
49531 index df5e961..df6b97f 100644
49532 --- a/drivers/scsi/sg.c
49533 +++ b/drivers/scsi/sg.c
49534 @@ -1102,7 +1102,7 @@ sg_ioctl(struct file *filp, unsigned int cmd_in, unsigned long arg)
49535 sdp->disk->disk_name,
49536 MKDEV(SCSI_GENERIC_MAJOR, sdp->index),
49537 NULL,
49538 - (char *)arg);
49539 + (char __user *)arg);
49540 case BLKTRACESTART:
49541 return blk_trace_startstop(sdp->device->request_queue, 1);
49542 case BLKTRACESTOP:
49543 diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
49544 index 349ebba..ff2a249 100644
49545 --- a/drivers/spi/spi.c
49546 +++ b/drivers/spi/spi.c
49547 @@ -1945,7 +1945,7 @@ int spi_bus_unlock(struct spi_master *master)
49548 EXPORT_SYMBOL_GPL(spi_bus_unlock);
49549
49550 /* portable code must never pass more than 32 bytes */
49551 -#define SPI_BUFSIZ max(32, SMP_CACHE_BYTES)
49552 +#define SPI_BUFSIZ max(32UL, SMP_CACHE_BYTES)
49553
49554 static u8 *buf;
49555
49556 diff --git a/drivers/staging/android/timed_output.c b/drivers/staging/android/timed_output.c
49557 index 2c61783..4d49e4e 100644
49558 --- a/drivers/staging/android/timed_output.c
49559 +++ b/drivers/staging/android/timed_output.c
49560 @@ -25,7 +25,7 @@
49561 #include "timed_output.h"
49562
49563 static struct class *timed_output_class;
49564 -static atomic_t device_count;
49565 +static atomic_unchecked_t device_count;
49566
49567 static ssize_t enable_show(struct device *dev, struct device_attribute *attr,
49568 char *buf)
49569 @@ -63,7 +63,7 @@ static int create_timed_output_class(void)
49570 timed_output_class = class_create(THIS_MODULE, "timed_output");
49571 if (IS_ERR(timed_output_class))
49572 return PTR_ERR(timed_output_class);
49573 - atomic_set(&device_count, 0);
49574 + atomic_set_unchecked(&device_count, 0);
49575 timed_output_class->dev_groups = timed_output_groups;
49576 }
49577
49578 @@ -81,7 +81,7 @@ int timed_output_dev_register(struct timed_output_dev *tdev)
49579 if (ret < 0)
49580 return ret;
49581
49582 - tdev->index = atomic_inc_return(&device_count);
49583 + tdev->index = atomic_inc_return_unchecked(&device_count);
49584 tdev->dev = device_create(timed_output_class, NULL,
49585 MKDEV(0, tdev->index), NULL, "%s", tdev->name);
49586 if (IS_ERR(tdev->dev))
49587 diff --git a/drivers/staging/gdm724x/gdm_tty.c b/drivers/staging/gdm724x/gdm_tty.c
49588 index c0f7cd7..5424212 100644
49589 --- a/drivers/staging/gdm724x/gdm_tty.c
49590 +++ b/drivers/staging/gdm724x/gdm_tty.c
49591 @@ -45,7 +45,7 @@
49592 #define gdm_tty_send_control(n, r, v, d, l) (\
49593 n->tty_dev->send_control(n->tty_dev->priv_dev, r, v, d, l))
49594
49595 -#define GDM_TTY_READY(gdm) (gdm && gdm->tty_dev && gdm->port.count)
49596 +#define GDM_TTY_READY(gdm) (gdm && gdm->tty_dev && atomic_read(&gdm->port.count))
49597
49598 static struct tty_driver *gdm_driver[TTY_MAX_COUNT];
49599 static struct gdm *gdm_table[TTY_MAX_COUNT][GDM_TTY_MINOR];
49600 diff --git a/drivers/staging/imx-drm/imx-drm-core.c b/drivers/staging/imx-drm/imx-drm-core.c
49601 index 96e4eee..6d7c37e 100644
49602 --- a/drivers/staging/imx-drm/imx-drm-core.c
49603 +++ b/drivers/staging/imx-drm/imx-drm-core.c
49604 @@ -510,7 +510,7 @@ int imx_drm_add_crtc(struct drm_crtc *crtc,
49605 goto err_busy;
49606 }
49607
49608 - if (imxdrm->drm->open_count) {
49609 + if (local_read(&imxdrm->drm->open_count)) {
49610 ret = -EBUSY;
49611 goto err_busy;
49612 }
49613 @@ -590,7 +590,7 @@ int imx_drm_add_encoder(struct drm_encoder *encoder,
49614
49615 mutex_lock(&imxdrm->mutex);
49616
49617 - if (imxdrm->drm->open_count) {
49618 + if (local_read(&imxdrm->drm->open_count)) {
49619 ret = -EBUSY;
49620 goto err_busy;
49621 }
49622 @@ -729,7 +729,7 @@ int imx_drm_add_connector(struct drm_connector *connector,
49623
49624 mutex_lock(&imxdrm->mutex);
49625
49626 - if (imxdrm->drm->open_count) {
49627 + if (local_read(&imxdrm->drm->open_count)) {
49628 ret = -EBUSY;
49629 goto err_busy;
49630 }
49631 diff --git a/drivers/staging/lustre/lnet/selftest/brw_test.c b/drivers/staging/lustre/lnet/selftest/brw_test.c
49632 index b7613c8..c302392 100644
49633 --- a/drivers/staging/lustre/lnet/selftest/brw_test.c
49634 +++ b/drivers/staging/lustre/lnet/selftest/brw_test.c
49635 @@ -487,13 +487,11 @@ brw_server_handle(struct srpc_server_rpc *rpc)
49636 return 0;
49637 }
49638
49639 -sfw_test_client_ops_t brw_test_client;
49640 -void brw_init_test_client(void)
49641 -{
49642 - brw_test_client.tso_init = brw_client_init;
49643 - brw_test_client.tso_fini = brw_client_fini;
49644 - brw_test_client.tso_prep_rpc = brw_client_prep_rpc;
49645 - brw_test_client.tso_done_rpc = brw_client_done_rpc;
49646 +sfw_test_client_ops_t brw_test_client = {
49647 + .tso_init = brw_client_init,
49648 + .tso_fini = brw_client_fini,
49649 + .tso_prep_rpc = brw_client_prep_rpc,
49650 + .tso_done_rpc = brw_client_done_rpc,
49651 };
49652
49653 srpc_service_t brw_test_service;
49654 diff --git a/drivers/staging/lustre/lnet/selftest/framework.c b/drivers/staging/lustre/lnet/selftest/framework.c
49655 index 483c785..e1a2a7b 100644
49656 --- a/drivers/staging/lustre/lnet/selftest/framework.c
49657 +++ b/drivers/staging/lustre/lnet/selftest/framework.c
49658 @@ -1635,12 +1635,10 @@ static srpc_service_t sfw_services[] =
49659
49660 extern sfw_test_client_ops_t ping_test_client;
49661 extern srpc_service_t ping_test_service;
49662 -extern void ping_init_test_client(void);
49663 extern void ping_init_test_service(void);
49664
49665 extern sfw_test_client_ops_t brw_test_client;
49666 extern srpc_service_t brw_test_service;
49667 -extern void brw_init_test_client(void);
49668 extern void brw_init_test_service(void);
49669
49670
49671 @@ -1684,12 +1682,10 @@ sfw_startup (void)
49672 INIT_LIST_HEAD(&sfw_data.fw_zombie_rpcs);
49673 INIT_LIST_HEAD(&sfw_data.fw_zombie_sessions);
49674
49675 - brw_init_test_client();
49676 brw_init_test_service();
49677 rc = sfw_register_test(&brw_test_service, &brw_test_client);
49678 LASSERT (rc == 0);
49679
49680 - ping_init_test_client();
49681 ping_init_test_service();
49682 rc = sfw_register_test(&ping_test_service, &ping_test_client);
49683 LASSERT (rc == 0);
49684 diff --git a/drivers/staging/lustre/lnet/selftest/ping_test.c b/drivers/staging/lustre/lnet/selftest/ping_test.c
49685 index f0f9194..b589047 100644
49686 --- a/drivers/staging/lustre/lnet/selftest/ping_test.c
49687 +++ b/drivers/staging/lustre/lnet/selftest/ping_test.c
49688 @@ -210,14 +210,12 @@ ping_server_handle(struct srpc_server_rpc *rpc)
49689 return 0;
49690 }
49691
49692 -sfw_test_client_ops_t ping_test_client;
49693 -void ping_init_test_client(void)
49694 -{
49695 - ping_test_client.tso_init = ping_client_init;
49696 - ping_test_client.tso_fini = ping_client_fini;
49697 - ping_test_client.tso_prep_rpc = ping_client_prep_rpc;
49698 - ping_test_client.tso_done_rpc = ping_client_done_rpc;
49699 -}
49700 +sfw_test_client_ops_t ping_test_client = {
49701 + .tso_init = ping_client_init,
49702 + .tso_fini = ping_client_fini,
49703 + .tso_prep_rpc = ping_client_prep_rpc,
49704 + .tso_done_rpc = ping_client_done_rpc,
49705 +};
49706
49707 srpc_service_t ping_test_service;
49708 void ping_init_test_service(void)
49709 diff --git a/drivers/staging/lustre/lustre/include/lustre_dlm.h b/drivers/staging/lustre/lustre/include/lustre_dlm.h
49710 index bc2b82f..67fd598 100644
49711 --- a/drivers/staging/lustre/lustre/include/lustre_dlm.h
49712 +++ b/drivers/staging/lustre/lustre/include/lustre_dlm.h
49713 @@ -1141,7 +1141,7 @@ struct ldlm_callback_suite {
49714 ldlm_completion_callback lcs_completion;
49715 ldlm_blocking_callback lcs_blocking;
49716 ldlm_glimpse_callback lcs_glimpse;
49717 -};
49718 +} __no_const;
49719
49720 /* ldlm_lockd.c */
49721 int ldlm_del_waiting_lock(struct ldlm_lock *lock);
49722 diff --git a/drivers/staging/lustre/lustre/include/obd.h b/drivers/staging/lustre/lustre/include/obd.h
49723 index d0aea15..7af68e1 100644
49724 --- a/drivers/staging/lustre/lustre/include/obd.h
49725 +++ b/drivers/staging/lustre/lustre/include/obd.h
49726 @@ -1417,7 +1417,7 @@ struct md_ops {
49727 * lprocfs_alloc_md_stats() in obdclass/lprocfs_status.c. Also, add a
49728 * wrapper function in include/linux/obd_class.h.
49729 */
49730 -};
49731 +} __no_const;
49732
49733 struct lsm_operations {
49734 void (*lsm_free)(struct lov_stripe_md *);
49735 diff --git a/drivers/staging/lustre/lustre/ldlm/ldlm_flock.c b/drivers/staging/lustre/lustre/ldlm/ldlm_flock.c
49736 index 39fcdac..222780f 100644
49737 --- a/drivers/staging/lustre/lustre/ldlm/ldlm_flock.c
49738 +++ b/drivers/staging/lustre/lustre/ldlm/ldlm_flock.c
49739 @@ -249,7 +249,7 @@ ldlm_process_flock_lock(struct ldlm_lock *req, __u64 *flags, int first_enq,
49740 int added = (mode == LCK_NL);
49741 int overlaps = 0;
49742 int splitted = 0;
49743 - const struct ldlm_callback_suite null_cbs = { NULL };
49744 + const struct ldlm_callback_suite null_cbs = { };
49745 int rc;
49746
49747 CDEBUG(D_DLMTRACE, "flags %#llx owner "LPU64" pid %u mode %u start "
49748 diff --git a/drivers/staging/lustre/lustre/libcfs/linux/linux-proc.c b/drivers/staging/lustre/lustre/libcfs/linux/linux-proc.c
49749 index fc6c977..df1f956 100644
49750 --- a/drivers/staging/lustre/lustre/libcfs/linux/linux-proc.c
49751 +++ b/drivers/staging/lustre/lustre/libcfs/linux/linux-proc.c
49752 @@ -219,7 +219,7 @@ DECLARE_PROC_HANDLER(proc_debug_mb)
49753 int LL_PROC_PROTO(proc_console_max_delay_cs)
49754 {
49755 int rc, max_delay_cs;
49756 - ctl_table_t dummy = *table;
49757 + ctl_table_no_const dummy = *table;
49758 cfs_duration_t d;
49759
49760 dummy.data = &max_delay_cs;
49761 @@ -250,7 +250,7 @@ int LL_PROC_PROTO(proc_console_max_delay_cs)
49762 int LL_PROC_PROTO(proc_console_min_delay_cs)
49763 {
49764 int rc, min_delay_cs;
49765 - ctl_table_t dummy = *table;
49766 + ctl_table_no_const dummy = *table;
49767 cfs_duration_t d;
49768
49769 dummy.data = &min_delay_cs;
49770 @@ -281,7 +281,7 @@ int LL_PROC_PROTO(proc_console_min_delay_cs)
49771 int LL_PROC_PROTO(proc_console_backoff)
49772 {
49773 int rc, backoff;
49774 - ctl_table_t dummy = *table;
49775 + ctl_table_no_const dummy = *table;
49776
49777 dummy.data = &backoff;
49778 dummy.proc_handler = &proc_dointvec;
49779 diff --git a/drivers/staging/lustre/lustre/libcfs/module.c b/drivers/staging/lustre/lustre/libcfs/module.c
49780 index f3108c7..cd4f9da 100644
49781 --- a/drivers/staging/lustre/lustre/libcfs/module.c
49782 +++ b/drivers/staging/lustre/lustre/libcfs/module.c
49783 @@ -348,11 +348,11 @@ out:
49784
49785
49786 struct cfs_psdev_ops libcfs_psdev_ops = {
49787 - libcfs_psdev_open,
49788 - libcfs_psdev_release,
49789 - NULL,
49790 - NULL,
49791 - libcfs_ioctl
49792 + .p_open = libcfs_psdev_open,
49793 + .p_close = libcfs_psdev_release,
49794 + .p_read = NULL,
49795 + .p_write = NULL,
49796 + .p_ioctl = libcfs_ioctl
49797 };
49798
49799 extern int insert_proc(void);
49800 diff --git a/drivers/staging/lustre/lustre/llite/dir.c b/drivers/staging/lustre/lustre/llite/dir.c
49801 index a4e0472..05d854c 100644
49802 --- a/drivers/staging/lustre/lustre/llite/dir.c
49803 +++ b/drivers/staging/lustre/lustre/llite/dir.c
49804 @@ -660,7 +660,7 @@ int ll_dir_setdirstripe(struct inode *dir, struct lmv_user_md *lump,
49805 int mode;
49806 int err;
49807
49808 - mode = (0755 & (S_IRWXUGO|S_ISVTX) & ~current->fs->umask) | S_IFDIR;
49809 + mode = (0755 & (S_IRWXUGO|S_ISVTX) & ~current_umask()) | S_IFDIR;
49810 op_data = ll_prep_md_op_data(NULL, dir, NULL, filename,
49811 strlen(filename), mode, LUSTRE_OPC_MKDIR,
49812 lump);
49813 diff --git a/drivers/staging/media/solo6x10/solo6x10-core.c b/drivers/staging/media/solo6x10/solo6x10-core.c
49814 index 3675020..e80d92c 100644
49815 --- a/drivers/staging/media/solo6x10/solo6x10-core.c
49816 +++ b/drivers/staging/media/solo6x10/solo6x10-core.c
49817 @@ -434,7 +434,7 @@ static void solo_device_release(struct device *dev)
49818
49819 static int solo_sysfs_init(struct solo_dev *solo_dev)
49820 {
49821 - struct bin_attribute *sdram_attr = &solo_dev->sdram_attr;
49822 + bin_attribute_no_const *sdram_attr = &solo_dev->sdram_attr;
49823 struct device *dev = &solo_dev->dev;
49824 const char *driver;
49825 int i;
49826 diff --git a/drivers/staging/media/solo6x10/solo6x10-g723.c b/drivers/staging/media/solo6x10/solo6x10-g723.c
49827 index 1db18c7..35e6afc 100644
49828 --- a/drivers/staging/media/solo6x10/solo6x10-g723.c
49829 +++ b/drivers/staging/media/solo6x10/solo6x10-g723.c
49830 @@ -355,7 +355,7 @@ static int solo_snd_pcm_init(struct solo_dev *solo_dev)
49831
49832 int solo_g723_init(struct solo_dev *solo_dev)
49833 {
49834 - static struct snd_device_ops ops = { NULL };
49835 + static struct snd_device_ops ops = { };
49836 struct snd_card *card;
49837 struct snd_kcontrol_new kctl;
49838 char name[32];
49839 diff --git a/drivers/staging/media/solo6x10/solo6x10-p2m.c b/drivers/staging/media/solo6x10/solo6x10-p2m.c
49840 index 7f2f247..d999137 100644
49841 --- a/drivers/staging/media/solo6x10/solo6x10-p2m.c
49842 +++ b/drivers/staging/media/solo6x10/solo6x10-p2m.c
49843 @@ -77,7 +77,7 @@ int solo_p2m_dma_desc(struct solo_dev *solo_dev,
49844
49845 /* Get next ID. According to Softlogic, 6110 has problems on !=0 P2M */
49846 if (solo_dev->type != SOLO_DEV_6110 && multi_p2m) {
49847 - p2m_id = atomic_inc_return(&solo_dev->p2m_count) % SOLO_NR_P2M;
49848 + p2m_id = atomic_inc_return_unchecked(&solo_dev->p2m_count) % SOLO_NR_P2M;
49849 if (p2m_id < 0)
49850 p2m_id = -p2m_id;
49851 }
49852 diff --git a/drivers/staging/media/solo6x10/solo6x10.h b/drivers/staging/media/solo6x10/solo6x10.h
49853 index f1bbb8c..a73eaba 100644
49854 --- a/drivers/staging/media/solo6x10/solo6x10.h
49855 +++ b/drivers/staging/media/solo6x10/solo6x10.h
49856 @@ -237,7 +237,7 @@ struct solo_dev {
49857
49858 /* P2M DMA Engine */
49859 struct solo_p2m_dev p2m_dev[SOLO_NR_P2M];
49860 - atomic_t p2m_count;
49861 + atomic_unchecked_t p2m_count;
49862 int p2m_jiffies;
49863 unsigned int p2m_timeouts;
49864
49865 diff --git a/drivers/staging/octeon/ethernet-rx.c b/drivers/staging/octeon/ethernet-rx.c
49866 index 0315f60..ce93f406 100644
49867 --- a/drivers/staging/octeon/ethernet-rx.c
49868 +++ b/drivers/staging/octeon/ethernet-rx.c
49869 @@ -418,11 +418,11 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
49870 /* Increment RX stats for virtual ports */
49871 if (work->ipprt >= CVMX_PIP_NUM_INPUT_PORTS) {
49872 #ifdef CONFIG_64BIT
49873 - atomic64_add(1, (atomic64_t *)&priv->stats.rx_packets);
49874 - atomic64_add(skb->len, (atomic64_t *)&priv->stats.rx_bytes);
49875 + atomic64_add_unchecked(1, (atomic64_unchecked_t *)&priv->stats.rx_packets);
49876 + atomic64_add_unchecked(skb->len, (atomic64_unchecked_t *)&priv->stats.rx_bytes);
49877 #else
49878 - atomic_add(1, (atomic_t *)&priv->stats.rx_packets);
49879 - atomic_add(skb->len, (atomic_t *)&priv->stats.rx_bytes);
49880 + atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_packets);
49881 + atomic_add_unchecked(skb->len, (atomic_unchecked_t *)&priv->stats.rx_bytes);
49882 #endif
49883 }
49884 netif_receive_skb(skb);
49885 @@ -433,9 +433,9 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
49886 dev->name);
49887 */
49888 #ifdef CONFIG_64BIT
49889 - atomic64_add(1, (atomic64_t *)&priv->stats.rx_dropped);
49890 + atomic64_add_unchecked(1, (atomic64_unchecked_t *)&priv->stats.rx_dropped);
49891 #else
49892 - atomic_add(1, (atomic_t *)&priv->stats.rx_dropped);
49893 + atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_dropped);
49894 #endif
49895 dev_kfree_skb_irq(skb);
49896 }
49897 diff --git a/drivers/staging/octeon/ethernet.c b/drivers/staging/octeon/ethernet.c
49898 index bd6ca71..8f0961e 100644
49899 --- a/drivers/staging/octeon/ethernet.c
49900 +++ b/drivers/staging/octeon/ethernet.c
49901 @@ -254,11 +254,11 @@ static struct net_device_stats *cvm_oct_common_get_stats(struct net_device *dev)
49902 * since the RX tasklet also increments it.
49903 */
49904 #ifdef CONFIG_64BIT
49905 - atomic64_add(rx_status.dropped_packets,
49906 - (atomic64_t *)&priv->stats.rx_dropped);
49907 + atomic64_add_unchecked(rx_status.dropped_packets,
49908 + (atomic64_unchecked_t *)&priv->stats.rx_dropped);
49909 #else
49910 - atomic_add(rx_status.dropped_packets,
49911 - (atomic_t *)&priv->stats.rx_dropped);
49912 + atomic_add_unchecked(rx_status.dropped_packets,
49913 + (atomic_unchecked_t *)&priv->stats.rx_dropped);
49914 #endif
49915 }
49916
49917 diff --git a/drivers/staging/rtl8188eu/include/hal_intf.h b/drivers/staging/rtl8188eu/include/hal_intf.h
49918 index 439c3c9..2d74293 100644
49919 --- a/drivers/staging/rtl8188eu/include/hal_intf.h
49920 +++ b/drivers/staging/rtl8188eu/include/hal_intf.h
49921 @@ -271,7 +271,7 @@ struct hal_ops {
49922 s32 (*c2h_handler)(struct adapter *padapter,
49923 struct c2h_evt_hdr *c2h_evt);
49924 c2h_id_filter c2h_id_filter_ccx;
49925 -};
49926 +} __no_const;
49927
49928 enum rt_eeprom_type {
49929 EEPROM_93C46,
49930 diff --git a/drivers/staging/rtl8188eu/include/rtw_io.h b/drivers/staging/rtl8188eu/include/rtw_io.h
49931 index eb6f0e5..e6a0958 100644
49932 --- a/drivers/staging/rtl8188eu/include/rtw_io.h
49933 +++ b/drivers/staging/rtl8188eu/include/rtw_io.h
49934 @@ -126,7 +126,7 @@ struct _io_ops {
49935 u32 (*_write_scsi)(struct intf_hdl *pintfhdl,u32 cnt, u8 *pmem);
49936 void (*_read_port_cancel)(struct intf_hdl *pintfhdl);
49937 void (*_write_port_cancel)(struct intf_hdl *pintfhdl);
49938 -};
49939 +} __no_const;
49940
49941 struct io_req {
49942 struct list_head list;
49943 diff --git a/drivers/staging/rtl8712/rtl871x_io.h b/drivers/staging/rtl8712/rtl871x_io.h
49944 index dc23395..cf7e9b1 100644
49945 --- a/drivers/staging/rtl8712/rtl871x_io.h
49946 +++ b/drivers/staging/rtl8712/rtl871x_io.h
49947 @@ -108,7 +108,7 @@ struct _io_ops {
49948 u8 *pmem);
49949 u32 (*_write_port)(struct intf_hdl *pintfhdl, u32 addr, u32 cnt,
49950 u8 *pmem);
49951 -};
49952 +} __no_const;
49953
49954 struct io_req {
49955 struct list_head list;
49956 diff --git a/drivers/staging/sbe-2t3e3/netdev.c b/drivers/staging/sbe-2t3e3/netdev.c
49957 index 1f5088b..0e59820 100644
49958 --- a/drivers/staging/sbe-2t3e3/netdev.c
49959 +++ b/drivers/staging/sbe-2t3e3/netdev.c
49960 @@ -51,7 +51,7 @@ static int t3e3_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
49961 t3e3_if_config(sc, cmd_2t3e3, (char *)&param, &resp, &rlen);
49962
49963 if (rlen)
49964 - if (copy_to_user(data, &resp, rlen))
49965 + if (rlen > sizeof resp || copy_to_user(data, &resp, rlen))
49966 return -EFAULT;
49967
49968 return 0;
49969 diff --git a/drivers/staging/usbip/vhci.h b/drivers/staging/usbip/vhci.h
49970 index a863a98..d272795 100644
49971 --- a/drivers/staging/usbip/vhci.h
49972 +++ b/drivers/staging/usbip/vhci.h
49973 @@ -83,7 +83,7 @@ struct vhci_hcd {
49974 unsigned resuming:1;
49975 unsigned long re_timeout;
49976
49977 - atomic_t seqnum;
49978 + atomic_unchecked_t seqnum;
49979
49980 /*
49981 * NOTE:
49982 diff --git a/drivers/staging/usbip/vhci_hcd.c b/drivers/staging/usbip/vhci_hcd.c
49983 index e810ad5..931336f 100644
49984 --- a/drivers/staging/usbip/vhci_hcd.c
49985 +++ b/drivers/staging/usbip/vhci_hcd.c
49986 @@ -441,7 +441,7 @@ static void vhci_tx_urb(struct urb *urb)
49987
49988 spin_lock(&vdev->priv_lock);
49989
49990 - priv->seqnum = atomic_inc_return(&the_controller->seqnum);
49991 + priv->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
49992 if (priv->seqnum == 0xffff)
49993 dev_info(&urb->dev->dev, "seqnum max\n");
49994
49995 @@ -687,7 +687,7 @@ static int vhci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
49996 return -ENOMEM;
49997 }
49998
49999 - unlink->seqnum = atomic_inc_return(&the_controller->seqnum);
50000 + unlink->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
50001 if (unlink->seqnum == 0xffff)
50002 pr_info("seqnum max\n");
50003
50004 @@ -891,7 +891,7 @@ static int vhci_start(struct usb_hcd *hcd)
50005 vdev->rhport = rhport;
50006 }
50007
50008 - atomic_set(&vhci->seqnum, 0);
50009 + atomic_set_unchecked(&vhci->seqnum, 0);
50010 spin_lock_init(&vhci->lock);
50011
50012 hcd->power_budget = 0; /* no limit */
50013 diff --git a/drivers/staging/usbip/vhci_rx.c b/drivers/staging/usbip/vhci_rx.c
50014 index d07fcb5..358e1e1 100644
50015 --- a/drivers/staging/usbip/vhci_rx.c
50016 +++ b/drivers/staging/usbip/vhci_rx.c
50017 @@ -80,7 +80,7 @@ static void vhci_recv_ret_submit(struct vhci_device *vdev,
50018 if (!urb) {
50019 pr_err("cannot find a urb of seqnum %u\n", pdu->base.seqnum);
50020 pr_info("max seqnum %d\n",
50021 - atomic_read(&the_controller->seqnum));
50022 + atomic_read_unchecked(&the_controller->seqnum));
50023 usbip_event_add(ud, VDEV_EVENT_ERROR_TCP);
50024 return;
50025 }
50026 diff --git a/drivers/staging/vt6655/hostap.c b/drivers/staging/vt6655/hostap.c
50027 index ab8b2ba..99184aa 100644
50028 --- a/drivers/staging/vt6655/hostap.c
50029 +++ b/drivers/staging/vt6655/hostap.c
50030 @@ -69,14 +69,13 @@ static int msglevel = MSG_LEVEL_INFO;
50031 *
50032 */
50033
50034 +static net_device_ops_no_const apdev_netdev_ops;
50035 +
50036 static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
50037 {
50038 PSDevice apdev_priv;
50039 struct net_device *dev = pDevice->dev;
50040 int ret;
50041 - const struct net_device_ops apdev_netdev_ops = {
50042 - .ndo_start_xmit = pDevice->tx_80211,
50043 - };
50044
50045 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
50046
50047 @@ -88,6 +87,8 @@ static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
50048 *apdev_priv = *pDevice;
50049 eth_hw_addr_inherit(pDevice->apdev, dev);
50050
50051 + /* only half broken now */
50052 + apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
50053 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
50054
50055 pDevice->apdev->type = ARPHRD_IEEE80211;
50056 diff --git a/drivers/staging/vt6656/hostap.c b/drivers/staging/vt6656/hostap.c
50057 index 67ba48b..24e602f 100644
50058 --- a/drivers/staging/vt6656/hostap.c
50059 +++ b/drivers/staging/vt6656/hostap.c
50060 @@ -60,14 +60,13 @@ static int msglevel =MSG_LEVEL_INFO;
50061 *
50062 */
50063
50064 +static net_device_ops_no_const apdev_netdev_ops;
50065 +
50066 static int hostap_enable_hostapd(struct vnt_private *pDevice, int rtnl_locked)
50067 {
50068 struct vnt_private *apdev_priv;
50069 struct net_device *dev = pDevice->dev;
50070 int ret;
50071 - const struct net_device_ops apdev_netdev_ops = {
50072 - .ndo_start_xmit = pDevice->tx_80211,
50073 - };
50074
50075 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
50076
50077 @@ -79,6 +78,8 @@ static int hostap_enable_hostapd(struct vnt_private *pDevice, int rtnl_locked)
50078 *apdev_priv = *pDevice;
50079 memcpy(pDevice->apdev->dev_addr, dev->dev_addr, ETH_ALEN);
50080
50081 + /* only half broken now */
50082 + apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
50083 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
50084
50085 pDevice->apdev->type = ARPHRD_IEEE80211;
50086 diff --git a/drivers/target/sbp/sbp_target.c b/drivers/target/sbp/sbp_target.c
50087 index 24884ca..26c8220 100644
50088 --- a/drivers/target/sbp/sbp_target.c
50089 +++ b/drivers/target/sbp/sbp_target.c
50090 @@ -62,7 +62,7 @@ static const u32 sbp_unit_directory_template[] = {
50091
50092 #define SESSION_MAINTENANCE_INTERVAL HZ
50093
50094 -static atomic_t login_id = ATOMIC_INIT(0);
50095 +static atomic_unchecked_t login_id = ATOMIC_INIT(0);
50096
50097 static void session_maintenance_work(struct work_struct *);
50098 static int sbp_run_transaction(struct fw_card *, int, int, int, int,
50099 @@ -444,7 +444,7 @@ static void sbp_management_request_login(
50100 login->lun = se_lun;
50101 login->status_fifo_addr = sbp2_pointer_to_addr(&req->orb.status_fifo);
50102 login->exclusive = LOGIN_ORB_EXCLUSIVE(be32_to_cpu(req->orb.misc));
50103 - login->login_id = atomic_inc_return(&login_id);
50104 + login->login_id = atomic_inc_return_unchecked(&login_id);
50105
50106 login->tgt_agt = sbp_target_agent_register(login);
50107 if (IS_ERR(login->tgt_agt)) {
50108 diff --git a/drivers/target/target_core_device.c b/drivers/target/target_core_device.c
50109 index d06de84..fd38c9b 100644
50110 --- a/drivers/target/target_core_device.c
50111 +++ b/drivers/target/target_core_device.c
50112 @@ -1435,7 +1435,7 @@ struct se_device *target_alloc_device(struct se_hba *hba, const char *name)
50113 spin_lock_init(&dev->se_tmr_lock);
50114 spin_lock_init(&dev->qf_cmd_lock);
50115 sema_init(&dev->caw_sem, 1);
50116 - atomic_set(&dev->dev_ordered_id, 0);
50117 + atomic_set_unchecked(&dev->dev_ordered_id, 0);
50118 INIT_LIST_HEAD(&dev->t10_wwn.t10_vpd_list);
50119 spin_lock_init(&dev->t10_wwn.t10_vpd_lock);
50120 INIT_LIST_HEAD(&dev->t10_pr.registration_list);
50121 diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c
50122 index dee2be1..f5fd8ca 100644
50123 --- a/drivers/target/target_core_transport.c
50124 +++ b/drivers/target/target_core_transport.c
50125 @@ -1113,7 +1113,7 @@ transport_check_alloc_task_attr(struct se_cmd *cmd)
50126 * Used to determine when ORDERED commands should go from
50127 * Dormant to Active status.
50128 */
50129 - cmd->se_ordered_id = atomic_inc_return(&dev->dev_ordered_id);
50130 + cmd->se_ordered_id = atomic_inc_return_unchecked(&dev->dev_ordered_id);
50131 smp_mb__after_atomic_inc();
50132 pr_debug("Allocated se_ordered_id: %u for Task Attr: 0x%02x on %s\n",
50133 cmd->se_ordered_id, cmd->sam_task_attr,
50134 diff --git a/drivers/tty/cyclades.c b/drivers/tty/cyclades.c
50135 index 33f83fe..d80f8e1 100644
50136 --- a/drivers/tty/cyclades.c
50137 +++ b/drivers/tty/cyclades.c
50138 @@ -1570,10 +1570,10 @@ static int cy_open(struct tty_struct *tty, struct file *filp)
50139 printk(KERN_DEBUG "cyc:cy_open ttyC%d, count = %d\n", info->line,
50140 info->port.count);
50141 #endif
50142 - info->port.count++;
50143 + atomic_inc(&info->port.count);
50144 #ifdef CY_DEBUG_COUNT
50145 printk(KERN_DEBUG "cyc:cy_open (%d): incrementing count to %d\n",
50146 - current->pid, info->port.count);
50147 + current->pid, atomic_read(&info->port.count));
50148 #endif
50149
50150 /*
50151 @@ -3972,7 +3972,7 @@ static int cyclades_proc_show(struct seq_file *m, void *v)
50152 for (j = 0; j < cy_card[i].nports; j++) {
50153 info = &cy_card[i].ports[j];
50154
50155 - if (info->port.count) {
50156 + if (atomic_read(&info->port.count)) {
50157 /* XXX is the ldisc num worth this? */
50158 struct tty_struct *tty;
50159 struct tty_ldisc *ld;
50160 diff --git a/drivers/tty/hvc/hvc_console.c b/drivers/tty/hvc/hvc_console.c
50161 index 9eba119..5070303 100644
50162 --- a/drivers/tty/hvc/hvc_console.c
50163 +++ b/drivers/tty/hvc/hvc_console.c
50164 @@ -338,7 +338,7 @@ static int hvc_open(struct tty_struct *tty, struct file * filp)
50165
50166 spin_lock_irqsave(&hp->port.lock, flags);
50167 /* Check and then increment for fast path open. */
50168 - if (hp->port.count++ > 0) {
50169 + if (atomic_inc_return(&hp->port.count) > 1) {
50170 spin_unlock_irqrestore(&hp->port.lock, flags);
50171 hvc_kick();
50172 return 0;
50173 @@ -393,7 +393,7 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
50174
50175 spin_lock_irqsave(&hp->port.lock, flags);
50176
50177 - if (--hp->port.count == 0) {
50178 + if (atomic_dec_return(&hp->port.count) == 0) {
50179 spin_unlock_irqrestore(&hp->port.lock, flags);
50180 /* We are done with the tty pointer now. */
50181 tty_port_tty_set(&hp->port, NULL);
50182 @@ -415,9 +415,9 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
50183 */
50184 tty_wait_until_sent_from_close(tty, HVC_CLOSE_WAIT);
50185 } else {
50186 - if (hp->port.count < 0)
50187 + if (atomic_read(&hp->port.count) < 0)
50188 printk(KERN_ERR "hvc_close %X: oops, count is %d\n",
50189 - hp->vtermno, hp->port.count);
50190 + hp->vtermno, atomic_read(&hp->port.count));
50191 spin_unlock_irqrestore(&hp->port.lock, flags);
50192 }
50193 }
50194 @@ -447,12 +447,12 @@ static void hvc_hangup(struct tty_struct *tty)
50195 * open->hangup case this can be called after the final close so prevent
50196 * that from happening for now.
50197 */
50198 - if (hp->port.count <= 0) {
50199 + if (atomic_read(&hp->port.count) <= 0) {
50200 spin_unlock_irqrestore(&hp->port.lock, flags);
50201 return;
50202 }
50203
50204 - hp->port.count = 0;
50205 + atomic_set(&hp->port.count, 0);
50206 spin_unlock_irqrestore(&hp->port.lock, flags);
50207 tty_port_tty_set(&hp->port, NULL);
50208
50209 @@ -500,7 +500,7 @@ static int hvc_write(struct tty_struct *tty, const unsigned char *buf, int count
50210 return -EPIPE;
50211
50212 /* FIXME what's this (unprotected) check for? */
50213 - if (hp->port.count <= 0)
50214 + if (atomic_read(&hp->port.count) <= 0)
50215 return -EIO;
50216
50217 spin_lock_irqsave(&hp->lock, flags);
50218 diff --git a/drivers/tty/hvc/hvcs.c b/drivers/tty/hvc/hvcs.c
50219 index 81e939e..95ead10 100644
50220 --- a/drivers/tty/hvc/hvcs.c
50221 +++ b/drivers/tty/hvc/hvcs.c
50222 @@ -83,6 +83,7 @@
50223 #include <asm/hvcserver.h>
50224 #include <asm/uaccess.h>
50225 #include <asm/vio.h>
50226 +#include <asm/local.h>
50227
50228 /*
50229 * 1.3.0 -> 1.3.1 In hvcs_open memset(..,0x00,..) instead of memset(..,0x3F,00).
50230 @@ -416,7 +417,7 @@ static ssize_t hvcs_vterm_state_store(struct device *dev, struct device_attribut
50231
50232 spin_lock_irqsave(&hvcsd->lock, flags);
50233
50234 - if (hvcsd->port.count > 0) {
50235 + if (atomic_read(&hvcsd->port.count) > 0) {
50236 spin_unlock_irqrestore(&hvcsd->lock, flags);
50237 printk(KERN_INFO "HVCS: vterm state unchanged. "
50238 "The hvcs device node is still in use.\n");
50239 @@ -1127,7 +1128,7 @@ static int hvcs_install(struct tty_driver *driver, struct tty_struct *tty)
50240 }
50241 }
50242
50243 - hvcsd->port.count = 0;
50244 + atomic_set(&hvcsd->port.count, 0);
50245 hvcsd->port.tty = tty;
50246 tty->driver_data = hvcsd;
50247
50248 @@ -1180,7 +1181,7 @@ static int hvcs_open(struct tty_struct *tty, struct file *filp)
50249 unsigned long flags;
50250
50251 spin_lock_irqsave(&hvcsd->lock, flags);
50252 - hvcsd->port.count++;
50253 + atomic_inc(&hvcsd->port.count);
50254 hvcsd->todo_mask |= HVCS_SCHED_READ;
50255 spin_unlock_irqrestore(&hvcsd->lock, flags);
50256
50257 @@ -1216,7 +1217,7 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
50258 hvcsd = tty->driver_data;
50259
50260 spin_lock_irqsave(&hvcsd->lock, flags);
50261 - if (--hvcsd->port.count == 0) {
50262 + if (atomic_dec_and_test(&hvcsd->port.count)) {
50263
50264 vio_disable_interrupts(hvcsd->vdev);
50265
50266 @@ -1241,10 +1242,10 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
50267
50268 free_irq(irq, hvcsd);
50269 return;
50270 - } else if (hvcsd->port.count < 0) {
50271 + } else if (atomic_read(&hvcsd->port.count) < 0) {
50272 printk(KERN_ERR "HVCS: vty-server@%X open_count: %d"
50273 " is missmanaged.\n",
50274 - hvcsd->vdev->unit_address, hvcsd->port.count);
50275 + hvcsd->vdev->unit_address, atomic_read(&hvcsd->port.count));
50276 }
50277
50278 spin_unlock_irqrestore(&hvcsd->lock, flags);
50279 @@ -1266,7 +1267,7 @@ static void hvcs_hangup(struct tty_struct * tty)
50280
50281 spin_lock_irqsave(&hvcsd->lock, flags);
50282 /* Preserve this so that we know how many kref refs to put */
50283 - temp_open_count = hvcsd->port.count;
50284 + temp_open_count = atomic_read(&hvcsd->port.count);
50285
50286 /*
50287 * Don't kref put inside the spinlock because the destruction
50288 @@ -1281,7 +1282,7 @@ static void hvcs_hangup(struct tty_struct * tty)
50289 tty->driver_data = NULL;
50290 hvcsd->port.tty = NULL;
50291
50292 - hvcsd->port.count = 0;
50293 + atomic_set(&hvcsd->port.count, 0);
50294
50295 /* This will drop any buffered data on the floor which is OK in a hangup
50296 * scenario. */
50297 @@ -1352,7 +1353,7 @@ static int hvcs_write(struct tty_struct *tty,
50298 * the middle of a write operation? This is a crummy place to do this
50299 * but we want to keep it all in the spinlock.
50300 */
50301 - if (hvcsd->port.count <= 0) {
50302 + if (atomic_read(&hvcsd->port.count) <= 0) {
50303 spin_unlock_irqrestore(&hvcsd->lock, flags);
50304 return -ENODEV;
50305 }
50306 @@ -1426,7 +1427,7 @@ static int hvcs_write_room(struct tty_struct *tty)
50307 {
50308 struct hvcs_struct *hvcsd = tty->driver_data;
50309
50310 - if (!hvcsd || hvcsd->port.count <= 0)
50311 + if (!hvcsd || atomic_read(&hvcsd->port.count) <= 0)
50312 return 0;
50313
50314 return HVCS_BUFF_LEN - hvcsd->chars_in_buffer;
50315 diff --git a/drivers/tty/hvc/hvsi.c b/drivers/tty/hvc/hvsi.c
50316 index 4190199..06d5bfa 100644
50317 --- a/drivers/tty/hvc/hvsi.c
50318 +++ b/drivers/tty/hvc/hvsi.c
50319 @@ -85,7 +85,7 @@ struct hvsi_struct {
50320 int n_outbuf;
50321 uint32_t vtermno;
50322 uint32_t virq;
50323 - atomic_t seqno; /* HVSI packet sequence number */
50324 + atomic_unchecked_t seqno; /* HVSI packet sequence number */
50325 uint16_t mctrl;
50326 uint8_t state; /* HVSI protocol state */
50327 uint8_t flags;
50328 @@ -295,7 +295,7 @@ static int hvsi_version_respond(struct hvsi_struct *hp, uint16_t query_seqno)
50329
50330 packet.hdr.type = VS_QUERY_RESPONSE_PACKET_HEADER;
50331 packet.hdr.len = sizeof(struct hvsi_query_response);
50332 - packet.hdr.seqno = atomic_inc_return(&hp->seqno);
50333 + packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
50334 packet.verb = VSV_SEND_VERSION_NUMBER;
50335 packet.u.version = HVSI_VERSION;
50336 packet.query_seqno = query_seqno+1;
50337 @@ -555,7 +555,7 @@ static int hvsi_query(struct hvsi_struct *hp, uint16_t verb)
50338
50339 packet.hdr.type = VS_QUERY_PACKET_HEADER;
50340 packet.hdr.len = sizeof(struct hvsi_query);
50341 - packet.hdr.seqno = atomic_inc_return(&hp->seqno);
50342 + packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
50343 packet.verb = verb;
50344
50345 pr_debug("%s: sending %i bytes\n", __func__, packet.hdr.len);
50346 @@ -597,7 +597,7 @@ static int hvsi_set_mctrl(struct hvsi_struct *hp, uint16_t mctrl)
50347 int wrote;
50348
50349 packet.hdr.type = VS_CONTROL_PACKET_HEADER,
50350 - packet.hdr.seqno = atomic_inc_return(&hp->seqno);
50351 + packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
50352 packet.hdr.len = sizeof(struct hvsi_control);
50353 packet.verb = VSV_SET_MODEM_CTL;
50354 packet.mask = HVSI_TSDTR;
50355 @@ -680,7 +680,7 @@ static int hvsi_put_chars(struct hvsi_struct *hp, const char *buf, int count)
50356 BUG_ON(count > HVSI_MAX_OUTGOING_DATA);
50357
50358 packet.hdr.type = VS_DATA_PACKET_HEADER;
50359 - packet.hdr.seqno = atomic_inc_return(&hp->seqno);
50360 + packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
50361 packet.hdr.len = count + sizeof(struct hvsi_header);
50362 memcpy(&packet.data, buf, count);
50363
50364 @@ -697,7 +697,7 @@ static void hvsi_close_protocol(struct hvsi_struct *hp)
50365 struct hvsi_control packet __ALIGNED__;
50366
50367 packet.hdr.type = VS_CONTROL_PACKET_HEADER;
50368 - packet.hdr.seqno = atomic_inc_return(&hp->seqno);
50369 + packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
50370 packet.hdr.len = 6;
50371 packet.verb = VSV_CLOSE_PROTOCOL;
50372
50373 @@ -725,7 +725,7 @@ static int hvsi_open(struct tty_struct *tty, struct file *filp)
50374
50375 tty_port_tty_set(&hp->port, tty);
50376 spin_lock_irqsave(&hp->lock, flags);
50377 - hp->port.count++;
50378 + atomic_inc(&hp->port.count);
50379 atomic_set(&hp->seqno, 0);
50380 h_vio_signal(hp->vtermno, VIO_IRQ_ENABLE);
50381 spin_unlock_irqrestore(&hp->lock, flags);
50382 @@ -782,7 +782,7 @@ static void hvsi_close(struct tty_struct *tty, struct file *filp)
50383
50384 spin_lock_irqsave(&hp->lock, flags);
50385
50386 - if (--hp->port.count == 0) {
50387 + if (atomic_dec_return(&hp->port.count) == 0) {
50388 tty_port_tty_set(&hp->port, NULL);
50389 hp->inbuf_end = hp->inbuf; /* discard remaining partial packets */
50390
50391 @@ -815,9 +815,9 @@ static void hvsi_close(struct tty_struct *tty, struct file *filp)
50392
50393 spin_lock_irqsave(&hp->lock, flags);
50394 }
50395 - } else if (hp->port.count < 0)
50396 + } else if (atomic_read(&hp->port.count) < 0)
50397 printk(KERN_ERR "hvsi_close %lu: oops, count is %d\n",
50398 - hp - hvsi_ports, hp->port.count);
50399 + hp - hvsi_ports, atomic_read(&hp->port.count));
50400
50401 spin_unlock_irqrestore(&hp->lock, flags);
50402 }
50403 @@ -832,7 +832,7 @@ static void hvsi_hangup(struct tty_struct *tty)
50404 tty_port_tty_set(&hp->port, NULL);
50405
50406 spin_lock_irqsave(&hp->lock, flags);
50407 - hp->port.count = 0;
50408 + atomic_set(&hp->port.count, 0);
50409 hp->n_outbuf = 0;
50410 spin_unlock_irqrestore(&hp->lock, flags);
50411 }
50412 diff --git a/drivers/tty/hvc/hvsi_lib.c b/drivers/tty/hvc/hvsi_lib.c
50413 index 347050e..14f8fbf 100644
50414 --- a/drivers/tty/hvc/hvsi_lib.c
50415 +++ b/drivers/tty/hvc/hvsi_lib.c
50416 @@ -9,7 +9,7 @@
50417
50418 static int hvsi_send_packet(struct hvsi_priv *pv, struct hvsi_header *packet)
50419 {
50420 - packet->seqno = cpu_to_be16(atomic_inc_return(&pv->seqno));
50421 + packet->seqno = cpu_to_be16(atomic_inc_return_unchecked(&pv->seqno));
50422
50423 /* Assumes that always succeeds, works in practice */
50424 return pv->put_chars(pv->termno, (char *)packet, packet->len);
50425 @@ -21,7 +21,7 @@ static void hvsi_start_handshake(struct hvsi_priv *pv)
50426
50427 /* Reset state */
50428 pv->established = 0;
50429 - atomic_set(&pv->seqno, 0);
50430 + atomic_set_unchecked(&pv->seqno, 0);
50431
50432 pr_devel("HVSI@%x: Handshaking started\n", pv->termno);
50433
50434 diff --git a/drivers/tty/ipwireless/tty.c b/drivers/tty/ipwireless/tty.c
50435 index 8fd72ff..34a0bed 100644
50436 --- a/drivers/tty/ipwireless/tty.c
50437 +++ b/drivers/tty/ipwireless/tty.c
50438 @@ -29,6 +29,7 @@
50439 #include <linux/tty_driver.h>
50440 #include <linux/tty_flip.h>
50441 #include <linux/uaccess.h>
50442 +#include <asm/local.h>
50443
50444 #include "tty.h"
50445 #include "network.h"
50446 @@ -99,10 +100,10 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
50447 mutex_unlock(&tty->ipw_tty_mutex);
50448 return -ENODEV;
50449 }
50450 - if (tty->port.count == 0)
50451 + if (atomic_read(&tty->port.count) == 0)
50452 tty->tx_bytes_queued = 0;
50453
50454 - tty->port.count++;
50455 + atomic_inc(&tty->port.count);
50456
50457 tty->port.tty = linux_tty;
50458 linux_tty->driver_data = tty;
50459 @@ -118,9 +119,7 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
50460
50461 static void do_ipw_close(struct ipw_tty *tty)
50462 {
50463 - tty->port.count--;
50464 -
50465 - if (tty->port.count == 0) {
50466 + if (atomic_dec_return(&tty->port.count) == 0) {
50467 struct tty_struct *linux_tty = tty->port.tty;
50468
50469 if (linux_tty != NULL) {
50470 @@ -141,7 +140,7 @@ static void ipw_hangup(struct tty_struct *linux_tty)
50471 return;
50472
50473 mutex_lock(&tty->ipw_tty_mutex);
50474 - if (tty->port.count == 0) {
50475 + if (atomic_read(&tty->port.count) == 0) {
50476 mutex_unlock(&tty->ipw_tty_mutex);
50477 return;
50478 }
50479 @@ -164,7 +163,7 @@ void ipwireless_tty_received(struct ipw_tty *tty, unsigned char *data,
50480
50481 mutex_lock(&tty->ipw_tty_mutex);
50482
50483 - if (!tty->port.count) {
50484 + if (!atomic_read(&tty->port.count)) {
50485 mutex_unlock(&tty->ipw_tty_mutex);
50486 return;
50487 }
50488 @@ -206,7 +205,7 @@ static int ipw_write(struct tty_struct *linux_tty,
50489 return -ENODEV;
50490
50491 mutex_lock(&tty->ipw_tty_mutex);
50492 - if (!tty->port.count) {
50493 + if (!atomic_read(&tty->port.count)) {
50494 mutex_unlock(&tty->ipw_tty_mutex);
50495 return -EINVAL;
50496 }
50497 @@ -246,7 +245,7 @@ static int ipw_write_room(struct tty_struct *linux_tty)
50498 if (!tty)
50499 return -ENODEV;
50500
50501 - if (!tty->port.count)
50502 + if (!atomic_read(&tty->port.count))
50503 return -EINVAL;
50504
50505 room = IPWIRELESS_TX_QUEUE_SIZE - tty->tx_bytes_queued;
50506 @@ -288,7 +287,7 @@ static int ipw_chars_in_buffer(struct tty_struct *linux_tty)
50507 if (!tty)
50508 return 0;
50509
50510 - if (!tty->port.count)
50511 + if (!atomic_read(&tty->port.count))
50512 return 0;
50513
50514 return tty->tx_bytes_queued;
50515 @@ -369,7 +368,7 @@ static int ipw_tiocmget(struct tty_struct *linux_tty)
50516 if (!tty)
50517 return -ENODEV;
50518
50519 - if (!tty->port.count)
50520 + if (!atomic_read(&tty->port.count))
50521 return -EINVAL;
50522
50523 return get_control_lines(tty);
50524 @@ -385,7 +384,7 @@ ipw_tiocmset(struct tty_struct *linux_tty,
50525 if (!tty)
50526 return -ENODEV;
50527
50528 - if (!tty->port.count)
50529 + if (!atomic_read(&tty->port.count))
50530 return -EINVAL;
50531
50532 return set_control_lines(tty, set, clear);
50533 @@ -399,7 +398,7 @@ static int ipw_ioctl(struct tty_struct *linux_tty,
50534 if (!tty)
50535 return -ENODEV;
50536
50537 - if (!tty->port.count)
50538 + if (!atomic_read(&tty->port.count))
50539 return -EINVAL;
50540
50541 /* FIXME: Exactly how is the tty object locked here .. */
50542 @@ -555,7 +554,7 @@ void ipwireless_tty_free(struct ipw_tty *tty)
50543 * are gone */
50544 mutex_lock(&ttyj->ipw_tty_mutex);
50545 }
50546 - while (ttyj->port.count)
50547 + while (atomic_read(&ttyj->port.count))
50548 do_ipw_close(ttyj);
50549 ipwireless_disassociate_network_ttys(network,
50550 ttyj->channel_idx);
50551 diff --git a/drivers/tty/moxa.c b/drivers/tty/moxa.c
50552 index 1deaca4..c8582d4 100644
50553 --- a/drivers/tty/moxa.c
50554 +++ b/drivers/tty/moxa.c
50555 @@ -1189,7 +1189,7 @@ static int moxa_open(struct tty_struct *tty, struct file *filp)
50556 }
50557
50558 ch = &brd->ports[port % MAX_PORTS_PER_BOARD];
50559 - ch->port.count++;
50560 + atomic_inc(&ch->port.count);
50561 tty->driver_data = ch;
50562 tty_port_tty_set(&ch->port, tty);
50563 mutex_lock(&ch->port.mutex);
50564 diff --git a/drivers/tty/n_gsm.c b/drivers/tty/n_gsm.c
50565 index 5056090..c80ca04 100644
50566 --- a/drivers/tty/n_gsm.c
50567 +++ b/drivers/tty/n_gsm.c
50568 @@ -1643,7 +1643,7 @@ static struct gsm_dlci *gsm_dlci_alloc(struct gsm_mux *gsm, int addr)
50569 spin_lock_init(&dlci->lock);
50570 mutex_init(&dlci->mutex);
50571 dlci->fifo = &dlci->_fifo;
50572 - if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL) < 0) {
50573 + if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL)) {
50574 kfree(dlci);
50575 return NULL;
50576 }
50577 @@ -2946,7 +2946,7 @@ static int gsmtty_open(struct tty_struct *tty, struct file *filp)
50578 struct gsm_dlci *dlci = tty->driver_data;
50579 struct tty_port *port = &dlci->port;
50580
50581 - port->count++;
50582 + atomic_inc(&port->count);
50583 dlci_get(dlci);
50584 dlci_get(dlci->gsm->dlci[0]);
50585 mux_get(dlci->gsm);
50586 diff --git a/drivers/tty/n_tty.c b/drivers/tty/n_tty.c
50587 index 4c10837..a40ec45 100644
50588 --- a/drivers/tty/n_tty.c
50589 +++ b/drivers/tty/n_tty.c
50590 @@ -114,7 +114,7 @@ struct n_tty_data {
50591 int minimum_to_wake;
50592
50593 /* consumer-published */
50594 - size_t read_tail;
50595 + size_t read_tail __intentional_overflow(-1);
50596 size_t line_start;
50597
50598 /* protected by output lock */
50599 @@ -2504,6 +2504,7 @@ void n_tty_inherit_ops(struct tty_ldisc_ops *ops)
50600 {
50601 *ops = tty_ldisc_N_TTY;
50602 ops->owner = NULL;
50603 - ops->refcount = ops->flags = 0;
50604 + atomic_set(&ops->refcount, 0);
50605 + ops->flags = 0;
50606 }
50607 EXPORT_SYMBOL_GPL(n_tty_inherit_ops);
50608 diff --git a/drivers/tty/pty.c b/drivers/tty/pty.c
50609 index 25c9bc7..24077b7 100644
50610 --- a/drivers/tty/pty.c
50611 +++ b/drivers/tty/pty.c
50612 @@ -790,8 +790,10 @@ static void __init unix98_pty_init(void)
50613 panic("Couldn't register Unix98 pts driver");
50614
50615 /* Now create the /dev/ptmx special device */
50616 + pax_open_kernel();
50617 tty_default_fops(&ptmx_fops);
50618 - ptmx_fops.open = ptmx_open;
50619 + *(void **)&ptmx_fops.open = ptmx_open;
50620 + pax_close_kernel();
50621
50622 cdev_init(&ptmx_cdev, &ptmx_fops);
50623 if (cdev_add(&ptmx_cdev, MKDEV(TTYAUX_MAJOR, 2), 1) ||
50624 diff --git a/drivers/tty/rocket.c b/drivers/tty/rocket.c
50625 index 354564e..fe50d9a 100644
50626 --- a/drivers/tty/rocket.c
50627 +++ b/drivers/tty/rocket.c
50628 @@ -914,7 +914,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
50629 tty->driver_data = info;
50630 tty_port_tty_set(port, tty);
50631
50632 - if (port->count++ == 0) {
50633 + if (atomic_inc_return(&port->count) == 1) {
50634 atomic_inc(&rp_num_ports_open);
50635
50636 #ifdef ROCKET_DEBUG_OPEN
50637 @@ -923,7 +923,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
50638 #endif
50639 }
50640 #ifdef ROCKET_DEBUG_OPEN
50641 - printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, info->port.count);
50642 + printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, atomic-read(&info->port.count));
50643 #endif
50644
50645 /*
50646 @@ -1515,7 +1515,7 @@ static void rp_hangup(struct tty_struct *tty)
50647 spin_unlock_irqrestore(&info->port.lock, flags);
50648 return;
50649 }
50650 - if (info->port.count)
50651 + if (atomic_read(&info->port.count))
50652 atomic_dec(&rp_num_ports_open);
50653 clear_bit((info->aiop * 8) + info->chan, (void *) &xmit_flags[info->board]);
50654 spin_unlock_irqrestore(&info->port.lock, flags);
50655 diff --git a/drivers/tty/serial/ioc4_serial.c b/drivers/tty/serial/ioc4_serial.c
50656 index 1274499..f541382 100644
50657 --- a/drivers/tty/serial/ioc4_serial.c
50658 +++ b/drivers/tty/serial/ioc4_serial.c
50659 @@ -437,7 +437,7 @@ struct ioc4_soft {
50660 } is_intr_info[MAX_IOC4_INTR_ENTS];
50661
50662 /* Number of entries active in the above array */
50663 - atomic_t is_num_intrs;
50664 + atomic_unchecked_t is_num_intrs;
50665 } is_intr_type[IOC4_NUM_INTR_TYPES];
50666
50667 /* is_ir_lock must be held while
50668 @@ -974,7 +974,7 @@ intr_connect(struct ioc4_soft *soft, int type,
50669 BUG_ON(!((type == IOC4_SIO_INTR_TYPE)
50670 || (type == IOC4_OTHER_INTR_TYPE)));
50671
50672 - i = atomic_inc_return(&soft-> is_intr_type[type].is_num_intrs) - 1;
50673 + i = atomic_inc_return_unchecked(&soft-> is_intr_type[type].is_num_intrs) - 1;
50674 BUG_ON(!(i < MAX_IOC4_INTR_ENTS || (printk("i %d\n", i), 0)));
50675
50676 /* Save off the lower level interrupt handler */
50677 @@ -1001,7 +1001,7 @@ static irqreturn_t ioc4_intr(int irq, void *arg)
50678
50679 soft = arg;
50680 for (intr_type = 0; intr_type < IOC4_NUM_INTR_TYPES; intr_type++) {
50681 - num_intrs = (int)atomic_read(
50682 + num_intrs = (int)atomic_read_unchecked(
50683 &soft->is_intr_type[intr_type].is_num_intrs);
50684
50685 this_mir = this_ir = pending_intrs(soft, intr_type);
50686 diff --git a/drivers/tty/serial/kgdboc.c b/drivers/tty/serial/kgdboc.c
50687 index a260cde..6b2b5ce 100644
50688 --- a/drivers/tty/serial/kgdboc.c
50689 +++ b/drivers/tty/serial/kgdboc.c
50690 @@ -24,8 +24,9 @@
50691 #define MAX_CONFIG_LEN 40
50692
50693 static struct kgdb_io kgdboc_io_ops;
50694 +static struct kgdb_io kgdboc_io_ops_console;
50695
50696 -/* -1 = init not run yet, 0 = unconfigured, 1 = configured. */
50697 +/* -1 = init not run yet, 0 = unconfigured, 1/2 = configured. */
50698 static int configured = -1;
50699
50700 static char config[MAX_CONFIG_LEN];
50701 @@ -151,6 +152,8 @@ static void cleanup_kgdboc(void)
50702 kgdboc_unregister_kbd();
50703 if (configured == 1)
50704 kgdb_unregister_io_module(&kgdboc_io_ops);
50705 + else if (configured == 2)
50706 + kgdb_unregister_io_module(&kgdboc_io_ops_console);
50707 }
50708
50709 static int configure_kgdboc(void)
50710 @@ -160,13 +163,13 @@ static int configure_kgdboc(void)
50711 int err;
50712 char *cptr = config;
50713 struct console *cons;
50714 + int is_console = 0;
50715
50716 err = kgdboc_option_setup(config);
50717 if (err || !strlen(config) || isspace(config[0]))
50718 goto noconfig;
50719
50720 err = -ENODEV;
50721 - kgdboc_io_ops.is_console = 0;
50722 kgdb_tty_driver = NULL;
50723
50724 kgdboc_use_kms = 0;
50725 @@ -187,7 +190,7 @@ static int configure_kgdboc(void)
50726 int idx;
50727 if (cons->device && cons->device(cons, &idx) == p &&
50728 idx == tty_line) {
50729 - kgdboc_io_ops.is_console = 1;
50730 + is_console = 1;
50731 break;
50732 }
50733 cons = cons->next;
50734 @@ -197,7 +200,13 @@ static int configure_kgdboc(void)
50735 kgdb_tty_line = tty_line;
50736
50737 do_register:
50738 - err = kgdb_register_io_module(&kgdboc_io_ops);
50739 + if (is_console) {
50740 + err = kgdb_register_io_module(&kgdboc_io_ops_console);
50741 + configured = 2;
50742 + } else {
50743 + err = kgdb_register_io_module(&kgdboc_io_ops);
50744 + configured = 1;
50745 + }
50746 if (err)
50747 goto noconfig;
50748
50749 @@ -205,8 +214,6 @@ do_register:
50750 if (err)
50751 goto nmi_con_failed;
50752
50753 - configured = 1;
50754 -
50755 return 0;
50756
50757 nmi_con_failed:
50758 @@ -223,7 +230,7 @@ noconfig:
50759 static int __init init_kgdboc(void)
50760 {
50761 /* Already configured? */
50762 - if (configured == 1)
50763 + if (configured >= 1)
50764 return 0;
50765
50766 return configure_kgdboc();
50767 @@ -272,7 +279,7 @@ static int param_set_kgdboc_var(const char *kmessage, struct kernel_param *kp)
50768 if (config[len - 1] == '\n')
50769 config[len - 1] = '\0';
50770
50771 - if (configured == 1)
50772 + if (configured >= 1)
50773 cleanup_kgdboc();
50774
50775 /* Go and configure with the new params. */
50776 @@ -312,6 +319,15 @@ static struct kgdb_io kgdboc_io_ops = {
50777 .post_exception = kgdboc_post_exp_handler,
50778 };
50779
50780 +static struct kgdb_io kgdboc_io_ops_console = {
50781 + .name = "kgdboc",
50782 + .read_char = kgdboc_get_char,
50783 + .write_char = kgdboc_put_char,
50784 + .pre_exception = kgdboc_pre_exp_handler,
50785 + .post_exception = kgdboc_post_exp_handler,
50786 + .is_console = 1
50787 +};
50788 +
50789 #ifdef CONFIG_KGDB_SERIAL_CONSOLE
50790 /* This is only available if kgdboc is a built in for early debugging */
50791 static int __init kgdboc_early_init(char *opt)
50792 diff --git a/drivers/tty/serial/msm_serial.c b/drivers/tty/serial/msm_serial.c
50793 index b5d779c..3622cfe 100644
50794 --- a/drivers/tty/serial/msm_serial.c
50795 +++ b/drivers/tty/serial/msm_serial.c
50796 @@ -897,7 +897,7 @@ static struct uart_driver msm_uart_driver = {
50797 .cons = MSM_CONSOLE,
50798 };
50799
50800 -static atomic_t msm_uart_next_id = ATOMIC_INIT(0);
50801 +static atomic_unchecked_t msm_uart_next_id = ATOMIC_INIT(0);
50802
50803 static const struct of_device_id msm_uartdm_table[] = {
50804 { .compatible = "qcom,msm-uartdm" },
50805 @@ -912,7 +912,7 @@ static int __init msm_serial_probe(struct platform_device *pdev)
50806 int irq;
50807
50808 if (pdev->id == -1)
50809 - pdev->id = atomic_inc_return(&msm_uart_next_id) - 1;
50810 + pdev->id = atomic_inc_return_unchecked(&msm_uart_next_id) - 1;
50811
50812 if (unlikely(pdev->id < 0 || pdev->id >= UART_NR))
50813 return -ENXIO;
50814 diff --git a/drivers/tty/serial/samsung.c b/drivers/tty/serial/samsung.c
50815 index c1af04d..0815c8a 100644
50816 --- a/drivers/tty/serial/samsung.c
50817 +++ b/drivers/tty/serial/samsung.c
50818 @@ -463,11 +463,16 @@ static void s3c24xx_serial_shutdown(struct uart_port *port)
50819 }
50820 }
50821
50822 +static int s3c64xx_serial_startup(struct uart_port *port);
50823 static int s3c24xx_serial_startup(struct uart_port *port)
50824 {
50825 struct s3c24xx_uart_port *ourport = to_ourport(port);
50826 int ret;
50827
50828 + /* Startup sequence is different for s3c64xx and higher SoC's */
50829 + if (s3c24xx_serial_has_interrupt_mask(port))
50830 + return s3c64xx_serial_startup(port);
50831 +
50832 dbg("s3c24xx_serial_startup: port=%p (%08lx,%p)\n",
50833 port->mapbase, port->membase);
50834
50835 @@ -1141,10 +1146,6 @@ static int s3c24xx_serial_init_port(struct s3c24xx_uart_port *ourport,
50836 /* setup info for port */
50837 port->dev = &platdev->dev;
50838
50839 - /* Startup sequence is different for s3c64xx and higher SoC's */
50840 - if (s3c24xx_serial_has_interrupt_mask(port))
50841 - s3c24xx_serial_ops.startup = s3c64xx_serial_startup;
50842 -
50843 port->uartclk = 1;
50844
50845 if (cfg->uart_flags & UPF_CONS_FLOW) {
50846 diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c
50847 index 0f02351..07c59c5 100644
50848 --- a/drivers/tty/serial/serial_core.c
50849 +++ b/drivers/tty/serial/serial_core.c
50850 @@ -1448,7 +1448,7 @@ static void uart_hangup(struct tty_struct *tty)
50851 uart_flush_buffer(tty);
50852 uart_shutdown(tty, state);
50853 spin_lock_irqsave(&port->lock, flags);
50854 - port->count = 0;
50855 + atomic_set(&port->count, 0);
50856 clear_bit(ASYNCB_NORMAL_ACTIVE, &port->flags);
50857 spin_unlock_irqrestore(&port->lock, flags);
50858 tty_port_tty_set(port, NULL);
50859 @@ -1544,7 +1544,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
50860 goto end;
50861 }
50862
50863 - port->count++;
50864 + atomic_inc(&port->count);
50865 if (!state->uart_port || state->uart_port->flags & UPF_DEAD) {
50866 retval = -ENXIO;
50867 goto err_dec_count;
50868 @@ -1572,7 +1572,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
50869 /*
50870 * Make sure the device is in D0 state.
50871 */
50872 - if (port->count == 1)
50873 + if (atomic_read(&port->count) == 1)
50874 uart_change_pm(state, UART_PM_STATE_ON);
50875
50876 /*
50877 @@ -1590,7 +1590,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
50878 end:
50879 return retval;
50880 err_dec_count:
50881 - port->count--;
50882 + atomic_inc(&port->count);
50883 mutex_unlock(&port->mutex);
50884 goto end;
50885 }
50886 diff --git a/drivers/tty/synclink.c b/drivers/tty/synclink.c
50887 index e1ce141..6d4ed80 100644
50888 --- a/drivers/tty/synclink.c
50889 +++ b/drivers/tty/synclink.c
50890 @@ -3090,7 +3090,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
50891
50892 if (debug_level >= DEBUG_LEVEL_INFO)
50893 printk("%s(%d):mgsl_close(%s) entry, count=%d\n",
50894 - __FILE__,__LINE__, info->device_name, info->port.count);
50895 + __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
50896
50897 if (tty_port_close_start(&info->port, tty, filp) == 0)
50898 goto cleanup;
50899 @@ -3108,7 +3108,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
50900 cleanup:
50901 if (debug_level >= DEBUG_LEVEL_INFO)
50902 printk("%s(%d):mgsl_close(%s) exit, count=%d\n", __FILE__,__LINE__,
50903 - tty->driver->name, info->port.count);
50904 + tty->driver->name, atomic_read(&info->port.count));
50905
50906 } /* end of mgsl_close() */
50907
50908 @@ -3207,8 +3207,8 @@ static void mgsl_hangup(struct tty_struct *tty)
50909
50910 mgsl_flush_buffer(tty);
50911 shutdown(info);
50912 -
50913 - info->port.count = 0;
50914 +
50915 + atomic_set(&info->port.count, 0);
50916 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
50917 info->port.tty = NULL;
50918
50919 @@ -3297,12 +3297,12 @@ 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 before block 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 spin_lock_irqsave(&info->irq_spinlock, flags);
50927 if (!tty_hung_up_p(filp)) {
50928 extra_count = true;
50929 - port->count--;
50930 + atomic_dec(&port->count);
50931 }
50932 spin_unlock_irqrestore(&info->irq_spinlock, flags);
50933 port->blocked_open++;
50934 @@ -3331,7 +3331,7 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
50935
50936 if (debug_level >= DEBUG_LEVEL_INFO)
50937 printk("%s(%d):block_til_ready 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 tty_unlock(tty);
50942 schedule();
50943 @@ -3343,12 +3343,12 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
50944
50945 /* FIXME: Racy on hangup during close wait */
50946 if (extra_count)
50947 - port->count++;
50948 + atomic_inc(&port->count);
50949 port->blocked_open--;
50950
50951 if (debug_level >= DEBUG_LEVEL_INFO)
50952 printk("%s(%d):block_til_ready after blocking on %s count=%d\n",
50953 - __FILE__,__LINE__, tty->driver->name, port->count );
50954 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
50955
50956 if (!retval)
50957 port->flags |= ASYNC_NORMAL_ACTIVE;
50958 @@ -3400,7 +3400,7 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
50959
50960 if (debug_level >= DEBUG_LEVEL_INFO)
50961 printk("%s(%d):mgsl_open(%s), old ref count = %d\n",
50962 - __FILE__,__LINE__,tty->driver->name, info->port.count);
50963 + __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
50964
50965 /* If port is closing, signal caller to try again */
50966 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
50967 @@ -3419,10 +3419,10 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
50968 spin_unlock_irqrestore(&info->netlock, flags);
50969 goto cleanup;
50970 }
50971 - info->port.count++;
50972 + atomic_inc(&info->port.count);
50973 spin_unlock_irqrestore(&info->netlock, flags);
50974
50975 - if (info->port.count == 1) {
50976 + if (atomic_read(&info->port.count) == 1) {
50977 /* 1st open on this device, init hardware */
50978 retval = startup(info);
50979 if (retval < 0)
50980 @@ -3446,8 +3446,8 @@ cleanup:
50981 if (retval) {
50982 if (tty->count == 1)
50983 info->port.tty = NULL; /* tty layer will release tty struct */
50984 - if(info->port.count)
50985 - info->port.count--;
50986 + if (atomic_read(&info->port.count))
50987 + atomic_dec(&info->port.count);
50988 }
50989
50990 return retval;
50991 @@ -7665,7 +7665,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
50992 unsigned short new_crctype;
50993
50994 /* return error if TTY interface open */
50995 - if (info->port.count)
50996 + if (atomic_read(&info->port.count))
50997 return -EBUSY;
50998
50999 switch (encoding)
51000 @@ -7760,7 +7760,7 @@ static int hdlcdev_open(struct net_device *dev)
51001
51002 /* arbitrate between network and tty opens */
51003 spin_lock_irqsave(&info->netlock, flags);
51004 - if (info->port.count != 0 || info->netcount != 0) {
51005 + if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
51006 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
51007 spin_unlock_irqrestore(&info->netlock, flags);
51008 return -EBUSY;
51009 @@ -7846,7 +7846,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
51010 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
51011
51012 /* return error if TTY interface open */
51013 - if (info->port.count)
51014 + if (atomic_read(&info->port.count))
51015 return -EBUSY;
51016
51017 if (cmd != SIOCWANDEV)
51018 diff --git a/drivers/tty/synclink_gt.c b/drivers/tty/synclink_gt.c
51019 index 1abf946..1ee34fc 100644
51020 --- a/drivers/tty/synclink_gt.c
51021 +++ b/drivers/tty/synclink_gt.c
51022 @@ -670,7 +670,7 @@ static int open(struct tty_struct *tty, struct file *filp)
51023 tty->driver_data = info;
51024 info->port.tty = tty;
51025
51026 - DBGINFO(("%s open, old ref count = %d\n", info->device_name, info->port.count));
51027 + DBGINFO(("%s open, old ref count = %d\n", info->device_name, atomic_read(&info->port.count)));
51028
51029 /* If port is closing, signal caller to try again */
51030 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
51031 @@ -691,10 +691,10 @@ static int open(struct tty_struct *tty, struct file *filp)
51032 mutex_unlock(&info->port.mutex);
51033 goto cleanup;
51034 }
51035 - info->port.count++;
51036 + atomic_inc(&info->port.count);
51037 spin_unlock_irqrestore(&info->netlock, flags);
51038
51039 - if (info->port.count == 1) {
51040 + if (atomic_read(&info->port.count) == 1) {
51041 /* 1st open on this device, init hardware */
51042 retval = startup(info);
51043 if (retval < 0) {
51044 @@ -715,8 +715,8 @@ cleanup:
51045 if (retval) {
51046 if (tty->count == 1)
51047 info->port.tty = NULL; /* tty layer will release tty struct */
51048 - if(info->port.count)
51049 - info->port.count--;
51050 + if(atomic_read(&info->port.count))
51051 + atomic_dec(&info->port.count);
51052 }
51053
51054 DBGINFO(("%s open rc=%d\n", info->device_name, retval));
51055 @@ -729,7 +729,7 @@ static void close(struct tty_struct *tty, struct file *filp)
51056
51057 if (sanity_check(info, tty->name, "close"))
51058 return;
51059 - DBGINFO(("%s close entry, count=%d\n", info->device_name, info->port.count));
51060 + DBGINFO(("%s close entry, count=%d\n", info->device_name, atomic_read(&info->port.count)));
51061
51062 if (tty_port_close_start(&info->port, tty, filp) == 0)
51063 goto cleanup;
51064 @@ -746,7 +746,7 @@ static void close(struct tty_struct *tty, struct file *filp)
51065 tty_port_close_end(&info->port, tty);
51066 info->port.tty = NULL;
51067 cleanup:
51068 - DBGINFO(("%s close exit, count=%d\n", tty->driver->name, info->port.count));
51069 + DBGINFO(("%s close exit, count=%d\n", tty->driver->name, atomic_read(&info->port.count)));
51070 }
51071
51072 static void hangup(struct tty_struct *tty)
51073 @@ -764,7 +764,7 @@ static void hangup(struct tty_struct *tty)
51074 shutdown(info);
51075
51076 spin_lock_irqsave(&info->port.lock, flags);
51077 - info->port.count = 0;
51078 + atomic_set(&info->port.count, 0);
51079 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
51080 info->port.tty = NULL;
51081 spin_unlock_irqrestore(&info->port.lock, flags);
51082 @@ -1449,7 +1449,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
51083 unsigned short new_crctype;
51084
51085 /* return error if TTY interface open */
51086 - if (info->port.count)
51087 + if (atomic_read(&info->port.count))
51088 return -EBUSY;
51089
51090 DBGINFO(("%s hdlcdev_attach\n", info->device_name));
51091 @@ -1544,7 +1544,7 @@ static int hdlcdev_open(struct net_device *dev)
51092
51093 /* arbitrate between network and tty opens */
51094 spin_lock_irqsave(&info->netlock, flags);
51095 - if (info->port.count != 0 || info->netcount != 0) {
51096 + if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
51097 DBGINFO(("%s hdlc_open busy\n", dev->name));
51098 spin_unlock_irqrestore(&info->netlock, flags);
51099 return -EBUSY;
51100 @@ -1629,7 +1629,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
51101 DBGINFO(("%s hdlcdev_ioctl\n", dev->name));
51102
51103 /* return error if TTY interface open */
51104 - if (info->port.count)
51105 + if (atomic_read(&info->port.count))
51106 return -EBUSY;
51107
51108 if (cmd != SIOCWANDEV)
51109 @@ -2413,7 +2413,7 @@ static irqreturn_t slgt_interrupt(int dummy, void *dev_id)
51110 if (port == NULL)
51111 continue;
51112 spin_lock(&port->lock);
51113 - if ((port->port.count || port->netcount) &&
51114 + if ((atomic_read(&port->port.count) || port->netcount) &&
51115 port->pending_bh && !port->bh_running &&
51116 !port->bh_requested) {
51117 DBGISR(("%s bh queued\n", port->device_name));
51118 @@ -3302,7 +3302,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
51119 spin_lock_irqsave(&info->lock, flags);
51120 if (!tty_hung_up_p(filp)) {
51121 extra_count = true;
51122 - port->count--;
51123 + atomic_dec(&port->count);
51124 }
51125 spin_unlock_irqrestore(&info->lock, flags);
51126 port->blocked_open++;
51127 @@ -3339,7 +3339,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
51128 remove_wait_queue(&port->open_wait, &wait);
51129
51130 if (extra_count)
51131 - port->count++;
51132 + atomic_inc(&port->count);
51133 port->blocked_open--;
51134
51135 if (!retval)
51136 diff --git a/drivers/tty/synclinkmp.c b/drivers/tty/synclinkmp.c
51137 index dc6e969..5dc8786 100644
51138 --- a/drivers/tty/synclinkmp.c
51139 +++ b/drivers/tty/synclinkmp.c
51140 @@ -750,7 +750,7 @@ static int open(struct tty_struct *tty, struct file *filp)
51141
51142 if (debug_level >= DEBUG_LEVEL_INFO)
51143 printk("%s(%d):%s open(), old ref count = %d\n",
51144 - __FILE__,__LINE__,tty->driver->name, info->port.count);
51145 + __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
51146
51147 /* If port is closing, signal caller to try again */
51148 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
51149 @@ -769,10 +769,10 @@ static int open(struct tty_struct *tty, struct file *filp)
51150 spin_unlock_irqrestore(&info->netlock, flags);
51151 goto cleanup;
51152 }
51153 - info->port.count++;
51154 + atomic_inc(&info->port.count);
51155 spin_unlock_irqrestore(&info->netlock, flags);
51156
51157 - if (info->port.count == 1) {
51158 + if (atomic_read(&info->port.count) == 1) {
51159 /* 1st open on this device, init hardware */
51160 retval = startup(info);
51161 if (retval < 0)
51162 @@ -796,8 +796,8 @@ cleanup:
51163 if (retval) {
51164 if (tty->count == 1)
51165 info->port.tty = NULL; /* tty layer will release tty struct */
51166 - if(info->port.count)
51167 - info->port.count--;
51168 + if(atomic_read(&info->port.count))
51169 + atomic_dec(&info->port.count);
51170 }
51171
51172 return retval;
51173 @@ -815,7 +815,7 @@ static void close(struct tty_struct *tty, struct file *filp)
51174
51175 if (debug_level >= DEBUG_LEVEL_INFO)
51176 printk("%s(%d):%s close() entry, count=%d\n",
51177 - __FILE__,__LINE__, info->device_name, info->port.count);
51178 + __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
51179
51180 if (tty_port_close_start(&info->port, tty, filp) == 0)
51181 goto cleanup;
51182 @@ -834,7 +834,7 @@ static void close(struct tty_struct *tty, struct file *filp)
51183 cleanup:
51184 if (debug_level >= DEBUG_LEVEL_INFO)
51185 printk("%s(%d):%s close() exit, count=%d\n", __FILE__,__LINE__,
51186 - tty->driver->name, info->port.count);
51187 + tty->driver->name, atomic_read(&info->port.count));
51188 }
51189
51190 /* Called by tty_hangup() when a hangup is signaled.
51191 @@ -857,7 +857,7 @@ static void hangup(struct tty_struct *tty)
51192 shutdown(info);
51193
51194 spin_lock_irqsave(&info->port.lock, flags);
51195 - info->port.count = 0;
51196 + atomic_set(&info->port.count, 0);
51197 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
51198 info->port.tty = NULL;
51199 spin_unlock_irqrestore(&info->port.lock, flags);
51200 @@ -1565,7 +1565,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
51201 unsigned short new_crctype;
51202
51203 /* return error if TTY interface open */
51204 - if (info->port.count)
51205 + if (atomic_read(&info->port.count))
51206 return -EBUSY;
51207
51208 switch (encoding)
51209 @@ -1660,7 +1660,7 @@ static int hdlcdev_open(struct net_device *dev)
51210
51211 /* arbitrate between network and tty opens */
51212 spin_lock_irqsave(&info->netlock, flags);
51213 - if (info->port.count != 0 || info->netcount != 0) {
51214 + if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
51215 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
51216 spin_unlock_irqrestore(&info->netlock, flags);
51217 return -EBUSY;
51218 @@ -1746,7 +1746,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
51219 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
51220
51221 /* return error if TTY interface open */
51222 - if (info->port.count)
51223 + if (atomic_read(&info->port.count))
51224 return -EBUSY;
51225
51226 if (cmd != SIOCWANDEV)
51227 @@ -2620,7 +2620,7 @@ static irqreturn_t synclinkmp_interrupt(int dummy, void *dev_id)
51228 * do not request bottom half processing if the
51229 * device is not open in a normal mode.
51230 */
51231 - if ( port && (port->port.count || port->netcount) &&
51232 + if ( port && (atomic_read(&port->port.count) || port->netcount) &&
51233 port->pending_bh && !port->bh_running &&
51234 !port->bh_requested ) {
51235 if ( debug_level >= DEBUG_LEVEL_ISR )
51236 @@ -3318,12 +3318,12 @@ 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() before block, count=%d\n",
51240 - __FILE__,__LINE__, tty->driver->name, port->count );
51241 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
51242
51243 spin_lock_irqsave(&info->lock, flags);
51244 if (!tty_hung_up_p(filp)) {
51245 extra_count = true;
51246 - port->count--;
51247 + atomic_dec(&port->count);
51248 }
51249 spin_unlock_irqrestore(&info->lock, flags);
51250 port->blocked_open++;
51251 @@ -3352,7 +3352,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
51252
51253 if (debug_level >= DEBUG_LEVEL_INFO)
51254 printk("%s(%d):%s block_til_ready() count=%d\n",
51255 - __FILE__,__LINE__, tty->driver->name, port->count );
51256 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
51257
51258 tty_unlock(tty);
51259 schedule();
51260 @@ -3363,12 +3363,12 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
51261 remove_wait_queue(&port->open_wait, &wait);
51262
51263 if (extra_count)
51264 - port->count++;
51265 + atomic_inc(&port->count);
51266 port->blocked_open--;
51267
51268 if (debug_level >= DEBUG_LEVEL_INFO)
51269 printk("%s(%d):%s block_til_ready() after, count=%d\n",
51270 - __FILE__,__LINE__, tty->driver->name, port->count );
51271 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
51272
51273 if (!retval)
51274 port->flags |= ASYNC_NORMAL_ACTIVE;
51275 diff --git a/drivers/tty/sysrq.c b/drivers/tty/sysrq.c
51276 index ce396ec..04a37be 100644
51277 --- a/drivers/tty/sysrq.c
51278 +++ b/drivers/tty/sysrq.c
51279 @@ -1075,7 +1075,7 @@ EXPORT_SYMBOL(unregister_sysrq_key);
51280 static ssize_t write_sysrq_trigger(struct file *file, const char __user *buf,
51281 size_t count, loff_t *ppos)
51282 {
51283 - if (count) {
51284 + if (count && capable(CAP_SYS_ADMIN)) {
51285 char c;
51286
51287 if (get_user(c, buf))
51288 diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c
51289 index c74a00a..02cf211a 100644
51290 --- a/drivers/tty/tty_io.c
51291 +++ b/drivers/tty/tty_io.c
51292 @@ -3474,7 +3474,7 @@ EXPORT_SYMBOL_GPL(get_current_tty);
51293
51294 void tty_default_fops(struct file_operations *fops)
51295 {
51296 - *fops = tty_fops;
51297 + memcpy((void *)fops, &tty_fops, sizeof(tty_fops));
51298 }
51299
51300 /*
51301 diff --git a/drivers/tty/tty_ldisc.c b/drivers/tty/tty_ldisc.c
51302 index 6458e11..6cfc218 100644
51303 --- a/drivers/tty/tty_ldisc.c
51304 +++ b/drivers/tty/tty_ldisc.c
51305 @@ -72,7 +72,7 @@ int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc)
51306 raw_spin_lock_irqsave(&tty_ldiscs_lock, flags);
51307 tty_ldiscs[disc] = new_ldisc;
51308 new_ldisc->num = disc;
51309 - new_ldisc->refcount = 0;
51310 + atomic_set(&new_ldisc->refcount, 0);
51311 raw_spin_unlock_irqrestore(&tty_ldiscs_lock, flags);
51312
51313 return ret;
51314 @@ -100,7 +100,7 @@ int tty_unregister_ldisc(int disc)
51315 return -EINVAL;
51316
51317 raw_spin_lock_irqsave(&tty_ldiscs_lock, flags);
51318 - if (tty_ldiscs[disc]->refcount)
51319 + if (atomic_read(&tty_ldiscs[disc]->refcount))
51320 ret = -EBUSY;
51321 else
51322 tty_ldiscs[disc] = NULL;
51323 @@ -121,7 +121,7 @@ static struct tty_ldisc_ops *get_ldops(int disc)
51324 if (ldops) {
51325 ret = ERR_PTR(-EAGAIN);
51326 if (try_module_get(ldops->owner)) {
51327 - ldops->refcount++;
51328 + atomic_inc(&ldops->refcount);
51329 ret = ldops;
51330 }
51331 }
51332 @@ -134,7 +134,7 @@ static void put_ldops(struct tty_ldisc_ops *ldops)
51333 unsigned long flags;
51334
51335 raw_spin_lock_irqsave(&tty_ldiscs_lock, flags);
51336 - ldops->refcount--;
51337 + atomic_dec(&ldops->refcount);
51338 module_put(ldops->owner);
51339 raw_spin_unlock_irqrestore(&tty_ldiscs_lock, flags);
51340 }
51341 diff --git a/drivers/tty/tty_port.c b/drivers/tty/tty_port.c
51342 index c94d234..8210f2d 100644
51343 --- a/drivers/tty/tty_port.c
51344 +++ b/drivers/tty/tty_port.c
51345 @@ -236,7 +236,7 @@ void tty_port_hangup(struct tty_port *port)
51346 unsigned long flags;
51347
51348 spin_lock_irqsave(&port->lock, flags);
51349 - port->count = 0;
51350 + atomic_set(&port->count, 0);
51351 port->flags &= ~ASYNC_NORMAL_ACTIVE;
51352 tty = port->tty;
51353 if (tty)
51354 @@ -394,7 +394,7 @@ int tty_port_block_til_ready(struct tty_port *port,
51355 /* The port lock protects the port counts */
51356 spin_lock_irqsave(&port->lock, flags);
51357 if (!tty_hung_up_p(filp))
51358 - port->count--;
51359 + atomic_dec(&port->count);
51360 port->blocked_open++;
51361 spin_unlock_irqrestore(&port->lock, flags);
51362
51363 @@ -436,7 +436,7 @@ int tty_port_block_til_ready(struct tty_port *port,
51364 we must not mess that up further */
51365 spin_lock_irqsave(&port->lock, flags);
51366 if (!tty_hung_up_p(filp))
51367 - port->count++;
51368 + atomic_inc(&port->count);
51369 port->blocked_open--;
51370 if (retval == 0)
51371 port->flags |= ASYNC_NORMAL_ACTIVE;
51372 @@ -470,19 +470,19 @@ int tty_port_close_start(struct tty_port *port,
51373 return 0;
51374 }
51375
51376 - if (tty->count == 1 && port->count != 1) {
51377 + if (tty->count == 1 && atomic_read(&port->count) != 1) {
51378 printk(KERN_WARNING
51379 "tty_port_close_start: tty->count = 1 port count = %d.\n",
51380 - port->count);
51381 - port->count = 1;
51382 + atomic_read(&port->count));
51383 + atomic_set(&port->count, 1);
51384 }
51385 - if (--port->count < 0) {
51386 + if (atomic_dec_return(&port->count) < 0) {
51387 printk(KERN_WARNING "tty_port_close_start: count = %d\n",
51388 - port->count);
51389 - port->count = 0;
51390 + atomic_read(&port->count));
51391 + atomic_set(&port->count, 0);
51392 }
51393
51394 - if (port->count) {
51395 + if (atomic_read(&port->count)) {
51396 spin_unlock_irqrestore(&port->lock, flags);
51397 return 0;
51398 }
51399 @@ -564,7 +564,7 @@ int tty_port_open(struct tty_port *port, struct tty_struct *tty,
51400 {
51401 spin_lock_irq(&port->lock);
51402 if (!tty_hung_up_p(filp))
51403 - ++port->count;
51404 + atomic_inc(&port->count);
51405 spin_unlock_irq(&port->lock);
51406 tty_port_tty_set(port, tty);
51407
51408 diff --git a/drivers/tty/vt/keyboard.c b/drivers/tty/vt/keyboard.c
51409 index d0e3a44..5f8b754 100644
51410 --- a/drivers/tty/vt/keyboard.c
51411 +++ b/drivers/tty/vt/keyboard.c
51412 @@ -641,6 +641,16 @@ static void k_spec(struct vc_data *vc, unsigned char value, char up_flag)
51413 kbd->kbdmode == VC_OFF) &&
51414 value != KVAL(K_SAK))
51415 return; /* SAK is allowed even in raw mode */
51416 +
51417 +#if defined(CONFIG_GRKERNSEC_PROC) || defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
51418 + {
51419 + void *func = fn_handler[value];
51420 + if (func == fn_show_state || func == fn_show_ptregs ||
51421 + func == fn_show_mem)
51422 + return;
51423 + }
51424 +#endif
51425 +
51426 fn_handler[value](vc);
51427 }
51428
51429 @@ -1776,9 +1786,6 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
51430 if (copy_from_user(&tmp, user_kbe, sizeof(struct kbentry)))
51431 return -EFAULT;
51432
51433 - if (!capable(CAP_SYS_TTY_CONFIG))
51434 - perm = 0;
51435 -
51436 switch (cmd) {
51437 case KDGKBENT:
51438 /* Ensure another thread doesn't free it under us */
51439 @@ -1793,6 +1800,9 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
51440 spin_unlock_irqrestore(&kbd_event_lock, flags);
51441 return put_user(val, &user_kbe->kb_value);
51442 case KDSKBENT:
51443 + if (!capable(CAP_SYS_TTY_CONFIG))
51444 + perm = 0;
51445 +
51446 if (!perm)
51447 return -EPERM;
51448 if (!i && v == K_NOSUCHMAP) {
51449 @@ -1883,9 +1893,6 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
51450 int i, j, k;
51451 int ret;
51452
51453 - if (!capable(CAP_SYS_TTY_CONFIG))
51454 - perm = 0;
51455 -
51456 kbs = kmalloc(sizeof(*kbs), GFP_KERNEL);
51457 if (!kbs) {
51458 ret = -ENOMEM;
51459 @@ -1919,6 +1926,9 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
51460 kfree(kbs);
51461 return ((p && *p) ? -EOVERFLOW : 0);
51462 case KDSKBSENT:
51463 + if (!capable(CAP_SYS_TTY_CONFIG))
51464 + perm = 0;
51465 +
51466 if (!perm) {
51467 ret = -EPERM;
51468 goto reterr;
51469 diff --git a/drivers/uio/uio.c b/drivers/uio/uio.c
51470 index a673e5b..36e5d32 100644
51471 --- a/drivers/uio/uio.c
51472 +++ b/drivers/uio/uio.c
51473 @@ -25,6 +25,7 @@
51474 #include <linux/kobject.h>
51475 #include <linux/cdev.h>
51476 #include <linux/uio_driver.h>
51477 +#include <asm/local.h>
51478
51479 #define UIO_MAX_DEVICES (1U << MINORBITS)
51480
51481 @@ -32,7 +33,7 @@ struct uio_device {
51482 struct module *owner;
51483 struct device *dev;
51484 int minor;
51485 - atomic_t event;
51486 + atomic_unchecked_t event;
51487 struct fasync_struct *async_queue;
51488 wait_queue_head_t wait;
51489 struct uio_info *info;
51490 @@ -243,7 +244,7 @@ static ssize_t event_show(struct device *dev,
51491 struct device_attribute *attr, char *buf)
51492 {
51493 struct uio_device *idev = dev_get_drvdata(dev);
51494 - return sprintf(buf, "%u\n", (unsigned int)atomic_read(&idev->event));
51495 + return sprintf(buf, "%u\n", (unsigned int)atomic_read_unchecked(&idev->event));
51496 }
51497 static DEVICE_ATTR_RO(event);
51498
51499 @@ -405,7 +406,7 @@ void uio_event_notify(struct uio_info *info)
51500 {
51501 struct uio_device *idev = info->uio_dev;
51502
51503 - atomic_inc(&idev->event);
51504 + atomic_inc_unchecked(&idev->event);
51505 wake_up_interruptible(&idev->wait);
51506 kill_fasync(&idev->async_queue, SIGIO, POLL_IN);
51507 }
51508 @@ -458,7 +459,7 @@ static int uio_open(struct inode *inode, struct file *filep)
51509 }
51510
51511 listener->dev = idev;
51512 - listener->event_count = atomic_read(&idev->event);
51513 + listener->event_count = atomic_read_unchecked(&idev->event);
51514 filep->private_data = listener;
51515
51516 if (idev->info->open) {
51517 @@ -509,7 +510,7 @@ static unsigned int uio_poll(struct file *filep, poll_table *wait)
51518 return -EIO;
51519
51520 poll_wait(filep, &idev->wait, wait);
51521 - if (listener->event_count != atomic_read(&idev->event))
51522 + if (listener->event_count != atomic_read_unchecked(&idev->event))
51523 return POLLIN | POLLRDNORM;
51524 return 0;
51525 }
51526 @@ -534,7 +535,7 @@ static ssize_t uio_read(struct file *filep, char __user *buf,
51527 do {
51528 set_current_state(TASK_INTERRUPTIBLE);
51529
51530 - event_count = atomic_read(&idev->event);
51531 + event_count = atomic_read_unchecked(&idev->event);
51532 if (event_count != listener->event_count) {
51533 if (copy_to_user(buf, &event_count, count))
51534 retval = -EFAULT;
51535 @@ -591,9 +592,13 @@ static ssize_t uio_write(struct file *filep, const char __user *buf,
51536 static int uio_find_mem_index(struct vm_area_struct *vma)
51537 {
51538 struct uio_device *idev = vma->vm_private_data;
51539 + unsigned long size;
51540
51541 if (vma->vm_pgoff < MAX_UIO_MAPS) {
51542 - if (idev->info->mem[vma->vm_pgoff].size == 0)
51543 + size = idev->info->mem[vma->vm_pgoff].size;
51544 + if (size == 0)
51545 + return -1;
51546 + if (vma->vm_end - vma->vm_start > size)
51547 return -1;
51548 return (int)vma->vm_pgoff;
51549 }
51550 @@ -825,7 +830,7 @@ int __uio_register_device(struct module *owner,
51551 idev->owner = owner;
51552 idev->info = info;
51553 init_waitqueue_head(&idev->wait);
51554 - atomic_set(&idev->event, 0);
51555 + atomic_set_unchecked(&idev->event, 0);
51556
51557 ret = uio_get_minor(idev);
51558 if (ret)
51559 diff --git a/drivers/usb/atm/cxacru.c b/drivers/usb/atm/cxacru.c
51560 index 8a7eb77..c00402f 100644
51561 --- a/drivers/usb/atm/cxacru.c
51562 +++ b/drivers/usb/atm/cxacru.c
51563 @@ -473,7 +473,7 @@ static ssize_t cxacru_sysfs_store_adsl_config(struct device *dev,
51564 ret = sscanf(buf + pos, "%x=%x%n", &index, &value, &tmp);
51565 if (ret < 2)
51566 return -EINVAL;
51567 - if (index < 0 || index > 0x7f)
51568 + if (index > 0x7f)
51569 return -EINVAL;
51570 pos += tmp;
51571
51572 diff --git a/drivers/usb/atm/usbatm.c b/drivers/usb/atm/usbatm.c
51573 index 25a7bfc..57f3cf5 100644
51574 --- a/drivers/usb/atm/usbatm.c
51575 +++ b/drivers/usb/atm/usbatm.c
51576 @@ -331,7 +331,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
51577 if (printk_ratelimit())
51578 atm_warn(instance, "%s: OAM not supported (vpi %d, vci %d)!\n",
51579 __func__, vpi, vci);
51580 - atomic_inc(&vcc->stats->rx_err);
51581 + atomic_inc_unchecked(&vcc->stats->rx_err);
51582 return;
51583 }
51584
51585 @@ -358,7 +358,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
51586 if (length > ATM_MAX_AAL5_PDU) {
51587 atm_rldbg(instance, "%s: bogus length %u (vcc: 0x%p)!\n",
51588 __func__, length, vcc);
51589 - atomic_inc(&vcc->stats->rx_err);
51590 + atomic_inc_unchecked(&vcc->stats->rx_err);
51591 goto out;
51592 }
51593
51594 @@ -367,14 +367,14 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
51595 if (sarb->len < pdu_length) {
51596 atm_rldbg(instance, "%s: bogus pdu_length %u (sarb->len: %u, vcc: 0x%p)!\n",
51597 __func__, pdu_length, sarb->len, vcc);
51598 - atomic_inc(&vcc->stats->rx_err);
51599 + atomic_inc_unchecked(&vcc->stats->rx_err);
51600 goto out;
51601 }
51602
51603 if (crc32_be(~0, skb_tail_pointer(sarb) - pdu_length, pdu_length) != 0xc704dd7b) {
51604 atm_rldbg(instance, "%s: packet failed crc check (vcc: 0x%p)!\n",
51605 __func__, vcc);
51606 - atomic_inc(&vcc->stats->rx_err);
51607 + atomic_inc_unchecked(&vcc->stats->rx_err);
51608 goto out;
51609 }
51610
51611 @@ -386,7 +386,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
51612 if (printk_ratelimit())
51613 atm_err(instance, "%s: no memory for skb (length: %u)!\n",
51614 __func__, length);
51615 - atomic_inc(&vcc->stats->rx_drop);
51616 + atomic_inc_unchecked(&vcc->stats->rx_drop);
51617 goto out;
51618 }
51619
51620 @@ -414,7 +414,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
51621
51622 vcc->push(vcc, skb);
51623
51624 - atomic_inc(&vcc->stats->rx);
51625 + atomic_inc_unchecked(&vcc->stats->rx);
51626 out:
51627 skb_trim(sarb, 0);
51628 }
51629 @@ -612,7 +612,7 @@ static void usbatm_tx_process(unsigned long data)
51630 struct atm_vcc *vcc = UDSL_SKB(skb)->atm.vcc;
51631
51632 usbatm_pop(vcc, skb);
51633 - atomic_inc(&vcc->stats->tx);
51634 + atomic_inc_unchecked(&vcc->stats->tx);
51635
51636 skb = skb_dequeue(&instance->sndqueue);
51637 }
51638 @@ -756,11 +756,11 @@ static int usbatm_atm_proc_read(struct atm_dev *atm_dev, loff_t * pos, char *pag
51639 if (!left--)
51640 return sprintf(page,
51641 "AAL5: tx %d ( %d err ), rx %d ( %d err, %d drop )\n",
51642 - atomic_read(&atm_dev->stats.aal5.tx),
51643 - atomic_read(&atm_dev->stats.aal5.tx_err),
51644 - atomic_read(&atm_dev->stats.aal5.rx),
51645 - atomic_read(&atm_dev->stats.aal5.rx_err),
51646 - atomic_read(&atm_dev->stats.aal5.rx_drop));
51647 + atomic_read_unchecked(&atm_dev->stats.aal5.tx),
51648 + atomic_read_unchecked(&atm_dev->stats.aal5.tx_err),
51649 + atomic_read_unchecked(&atm_dev->stats.aal5.rx),
51650 + atomic_read_unchecked(&atm_dev->stats.aal5.rx_err),
51651 + atomic_read_unchecked(&atm_dev->stats.aal5.rx_drop));
51652
51653 if (!left--) {
51654 if (instance->disconnected)
51655 diff --git a/drivers/usb/core/devices.c b/drivers/usb/core/devices.c
51656 index 2a3bbdf..91d72cf 100644
51657 --- a/drivers/usb/core/devices.c
51658 +++ b/drivers/usb/core/devices.c
51659 @@ -126,7 +126,7 @@ static const char format_endpt[] =
51660 * time it gets called.
51661 */
51662 static struct device_connect_event {
51663 - atomic_t count;
51664 + atomic_unchecked_t count;
51665 wait_queue_head_t wait;
51666 } device_event = {
51667 .count = ATOMIC_INIT(1),
51668 @@ -164,7 +164,7 @@ static const struct class_info clas_info[] = {
51669
51670 void usbfs_conn_disc_event(void)
51671 {
51672 - atomic_add(2, &device_event.count);
51673 + atomic_add_unchecked(2, &device_event.count);
51674 wake_up(&device_event.wait);
51675 }
51676
51677 @@ -652,7 +652,7 @@ static unsigned int usb_device_poll(struct file *file,
51678
51679 poll_wait(file, &device_event.wait, wait);
51680
51681 - event_count = atomic_read(&device_event.count);
51682 + event_count = atomic_read_unchecked(&device_event.count);
51683 if (file->f_version != event_count) {
51684 file->f_version = event_count;
51685 return POLLIN | POLLRDNORM;
51686 diff --git a/drivers/usb/core/devio.c b/drivers/usb/core/devio.c
51687 index 967152a..16fa2e5 100644
51688 --- a/drivers/usb/core/devio.c
51689 +++ b/drivers/usb/core/devio.c
51690 @@ -187,7 +187,7 @@ static ssize_t usbdev_read(struct file *file, char __user *buf, size_t nbytes,
51691 struct dev_state *ps = file->private_data;
51692 struct usb_device *dev = ps->dev;
51693 ssize_t ret = 0;
51694 - unsigned len;
51695 + size_t len;
51696 loff_t pos;
51697 int i;
51698
51699 @@ -229,22 +229,22 @@ static ssize_t usbdev_read(struct file *file, char __user *buf, size_t nbytes,
51700 for (i = 0; nbytes && i < dev->descriptor.bNumConfigurations; i++) {
51701 struct usb_config_descriptor *config =
51702 (struct usb_config_descriptor *)dev->rawdescriptors[i];
51703 - unsigned int length = le16_to_cpu(config->wTotalLength);
51704 + size_t length = le16_to_cpu(config->wTotalLength);
51705
51706 if (*ppos < pos + length) {
51707
51708 /* The descriptor may claim to be longer than it
51709 * really is. Here is the actual allocated length. */
51710 - unsigned alloclen =
51711 + size_t alloclen =
51712 le16_to_cpu(dev->config[i].desc.wTotalLength);
51713
51714 - len = length - (*ppos - pos);
51715 + len = length + pos - *ppos;
51716 if (len > nbytes)
51717 len = nbytes;
51718
51719 /* Simply don't write (skip over) unallocated parts */
51720 if (alloclen > (*ppos - pos)) {
51721 - alloclen -= (*ppos - pos);
51722 + alloclen = alloclen + pos - *ppos;
51723 if (copy_to_user(buf,
51724 dev->rawdescriptors[i] + (*ppos - pos),
51725 min(len, alloclen))) {
51726 diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c
51727 index d39106c..bfe13a4 100644
51728 --- a/drivers/usb/core/hcd.c
51729 +++ b/drivers/usb/core/hcd.c
51730 @@ -1549,7 +1549,7 @@ int usb_hcd_submit_urb (struct urb *urb, gfp_t mem_flags)
51731 */
51732 usb_get_urb(urb);
51733 atomic_inc(&urb->use_count);
51734 - atomic_inc(&urb->dev->urbnum);
51735 + atomic_inc_unchecked(&urb->dev->urbnum);
51736 usbmon_urb_submit(&hcd->self, urb);
51737
51738 /* NOTE requirements on root-hub callers (usbfs and the hub
51739 @@ -1576,7 +1576,7 @@ int usb_hcd_submit_urb (struct urb *urb, gfp_t mem_flags)
51740 urb->hcpriv = NULL;
51741 INIT_LIST_HEAD(&urb->urb_list);
51742 atomic_dec(&urb->use_count);
51743 - atomic_dec(&urb->dev->urbnum);
51744 + atomic_dec_unchecked(&urb->dev->urbnum);
51745 if (atomic_read(&urb->reject))
51746 wake_up(&usb_kill_urb_queue);
51747 usb_put_urb(urb);
51748 diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c
51749 index ebcd3bf..be93a64 100644
51750 --- a/drivers/usb/core/hub.c
51751 +++ b/drivers/usb/core/hub.c
51752 @@ -27,6 +27,7 @@
51753 #include <linux/freezer.h>
51754 #include <linux/random.h>
51755 #include <linux/pm_qos.h>
51756 +#include <linux/grsecurity.h>
51757
51758 #include <asm/uaccess.h>
51759 #include <asm/byteorder.h>
51760 @@ -4437,6 +4438,10 @@ static void hub_port_connect_change(struct usb_hub *hub, int port1,
51761 goto done;
51762 return;
51763 }
51764 +
51765 + if (gr_handle_new_usb())
51766 + goto done;
51767 +
51768 if (hub_is_superspeed(hub->hdev))
51769 unit_load = 150;
51770 else
51771 diff --git a/drivers/usb/core/message.c b/drivers/usb/core/message.c
51772 index bb31597..6c5ef8b 100644
51773 --- a/drivers/usb/core/message.c
51774 +++ b/drivers/usb/core/message.c
51775 @@ -129,7 +129,7 @@ static int usb_internal_control_msg(struct usb_device *usb_dev,
51776 * Return: If successful, the number of bytes transferred. Otherwise, a negative
51777 * error number.
51778 */
51779 -int usb_control_msg(struct usb_device *dev, unsigned int pipe, __u8 request,
51780 +int __intentional_overflow(-1) usb_control_msg(struct usb_device *dev, unsigned int pipe, __u8 request,
51781 __u8 requesttype, __u16 value, __u16 index, void *data,
51782 __u16 size, int timeout)
51783 {
51784 @@ -181,7 +181,7 @@ EXPORT_SYMBOL_GPL(usb_control_msg);
51785 * If successful, 0. Otherwise a negative error number. The number of actual
51786 * bytes transferred will be stored in the @actual_length paramater.
51787 */
51788 -int usb_interrupt_msg(struct usb_device *usb_dev, unsigned int pipe,
51789 +int __intentional_overflow(-1) usb_interrupt_msg(struct usb_device *usb_dev, unsigned int pipe,
51790 void *data, int len, int *actual_length, int timeout)
51791 {
51792 return usb_bulk_msg(usb_dev, pipe, data, len, actual_length, timeout);
51793 @@ -221,7 +221,7 @@ EXPORT_SYMBOL_GPL(usb_interrupt_msg);
51794 * bytes transferred will be stored in the @actual_length paramater.
51795 *
51796 */
51797 -int usb_bulk_msg(struct usb_device *usb_dev, unsigned int pipe,
51798 +int __intentional_overflow(-1) usb_bulk_msg(struct usb_device *usb_dev, unsigned int pipe,
51799 void *data, int len, int *actual_length, int timeout)
51800 {
51801 struct urb *urb;
51802 diff --git a/drivers/usb/core/sysfs.c b/drivers/usb/core/sysfs.c
51803 index 52a97ad..e73330f 100644
51804 --- a/drivers/usb/core/sysfs.c
51805 +++ b/drivers/usb/core/sysfs.c
51806 @@ -244,7 +244,7 @@ static ssize_t urbnum_show(struct device *dev, struct device_attribute *attr,
51807 struct usb_device *udev;
51808
51809 udev = to_usb_device(dev);
51810 - return sprintf(buf, "%d\n", atomic_read(&udev->urbnum));
51811 + return sprintf(buf, "%d\n", atomic_read_unchecked(&udev->urbnum));
51812 }
51813 static DEVICE_ATTR_RO(urbnum);
51814
51815 diff --git a/drivers/usb/core/usb.c b/drivers/usb/core/usb.c
51816 index 4d11449..f4ccabf 100644
51817 --- a/drivers/usb/core/usb.c
51818 +++ b/drivers/usb/core/usb.c
51819 @@ -433,7 +433,7 @@ struct usb_device *usb_alloc_dev(struct usb_device *parent,
51820 set_dev_node(&dev->dev, dev_to_node(bus->controller));
51821 dev->state = USB_STATE_ATTACHED;
51822 dev->lpm_disable_count = 1;
51823 - atomic_set(&dev->urbnum, 0);
51824 + atomic_set_unchecked(&dev->urbnum, 0);
51825
51826 INIT_LIST_HEAD(&dev->ep0.urb_list);
51827 dev->ep0.desc.bLength = USB_DT_ENDPOINT_SIZE;
51828 diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c
51829 index 02e44fc..3c4fe64 100644
51830 --- a/drivers/usb/dwc3/gadget.c
51831 +++ b/drivers/usb/dwc3/gadget.c
51832 @@ -532,8 +532,6 @@ static int __dwc3_gadget_ep_enable(struct dwc3_ep *dep,
51833 if (!usb_endpoint_xfer_isoc(desc))
51834 return 0;
51835
51836 - memset(&trb_link, 0, sizeof(trb_link));
51837 -
51838 /* Link TRB for ISOC. The HWO bit is never reset */
51839 trb_st_hw = &dep->trb_pool[0];
51840
51841 diff --git a/drivers/usb/early/ehci-dbgp.c b/drivers/usb/early/ehci-dbgp.c
51842 index 8cfc319..4868255 100644
51843 --- a/drivers/usb/early/ehci-dbgp.c
51844 +++ b/drivers/usb/early/ehci-dbgp.c
51845 @@ -98,7 +98,8 @@ static inline u32 dbgp_len_update(u32 x, u32 len)
51846
51847 #ifdef CONFIG_KGDB
51848 static struct kgdb_io kgdbdbgp_io_ops;
51849 -#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops)
51850 +static struct kgdb_io kgdbdbgp_io_ops_console;
51851 +#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops || dbg_io_ops == &kgdbdbgp_io_ops_console)
51852 #else
51853 #define dbgp_kgdb_mode (0)
51854 #endif
51855 @@ -1043,6 +1044,13 @@ static struct kgdb_io kgdbdbgp_io_ops = {
51856 .write_char = kgdbdbgp_write_char,
51857 };
51858
51859 +static struct kgdb_io kgdbdbgp_io_ops_console = {
51860 + .name = "kgdbdbgp",
51861 + .read_char = kgdbdbgp_read_char,
51862 + .write_char = kgdbdbgp_write_char,
51863 + .is_console = 1
51864 +};
51865 +
51866 static int kgdbdbgp_wait_time;
51867
51868 static int __init kgdbdbgp_parse_config(char *str)
51869 @@ -1058,8 +1066,10 @@ static int __init kgdbdbgp_parse_config(char *str)
51870 ptr++;
51871 kgdbdbgp_wait_time = simple_strtoul(ptr, &ptr, 10);
51872 }
51873 - kgdb_register_io_module(&kgdbdbgp_io_ops);
51874 - kgdbdbgp_io_ops.is_console = early_dbgp_console.index != -1;
51875 + if (early_dbgp_console.index != -1)
51876 + kgdb_register_io_module(&kgdbdbgp_io_ops_console);
51877 + else
51878 + kgdb_register_io_module(&kgdbdbgp_io_ops);
51879
51880 return 0;
51881 }
51882 diff --git a/drivers/usb/gadget/u_serial.c b/drivers/usb/gadget/u_serial.c
51883 index b369292..9f3ba40 100644
51884 --- a/drivers/usb/gadget/u_serial.c
51885 +++ b/drivers/usb/gadget/u_serial.c
51886 @@ -733,9 +733,9 @@ static int gs_open(struct tty_struct *tty, struct file *file)
51887 spin_lock_irq(&port->port_lock);
51888
51889 /* already open? Great. */
51890 - if (port->port.count) {
51891 + if (atomic_read(&port->port.count)) {
51892 status = 0;
51893 - port->port.count++;
51894 + atomic_inc(&port->port.count);
51895
51896 /* currently opening/closing? wait ... */
51897 } else if (port->openclose) {
51898 @@ -794,7 +794,7 @@ static int gs_open(struct tty_struct *tty, struct file *file)
51899 tty->driver_data = port;
51900 port->port.tty = tty;
51901
51902 - port->port.count = 1;
51903 + atomic_set(&port->port.count, 1);
51904 port->openclose = false;
51905
51906 /* if connected, start the I/O stream */
51907 @@ -836,11 +836,11 @@ static void gs_close(struct tty_struct *tty, struct file *file)
51908
51909 spin_lock_irq(&port->port_lock);
51910
51911 - if (port->port.count != 1) {
51912 - if (port->port.count == 0)
51913 + if (atomic_read(&port->port.count) != 1) {
51914 + if (atomic_read(&port->port.count) == 0)
51915 WARN_ON(1);
51916 else
51917 - --port->port.count;
51918 + atomic_dec(&port->port.count);
51919 goto exit;
51920 }
51921
51922 @@ -850,7 +850,7 @@ static void gs_close(struct tty_struct *tty, struct file *file)
51923 * and sleep if necessary
51924 */
51925 port->openclose = true;
51926 - port->port.count = 0;
51927 + atomic_set(&port->port.count, 0);
51928
51929 gser = port->port_usb;
51930 if (gser && gser->disconnect)
51931 @@ -1066,7 +1066,7 @@ static int gs_closed(struct gs_port *port)
51932 int cond;
51933
51934 spin_lock_irq(&port->port_lock);
51935 - cond = (port->port.count == 0) && !port->openclose;
51936 + cond = (atomic_read(&port->port.count) == 0) && !port->openclose;
51937 spin_unlock_irq(&port->port_lock);
51938 return cond;
51939 }
51940 @@ -1209,7 +1209,7 @@ int gserial_connect(struct gserial *gser, u8 port_num)
51941 /* if it's already open, start I/O ... and notify the serial
51942 * protocol about open/close status (connect/disconnect).
51943 */
51944 - if (port->port.count) {
51945 + if (atomic_read(&port->port.count)) {
51946 pr_debug("gserial_connect: start ttyGS%d\n", port->port_num);
51947 gs_start_io(port);
51948 if (gser->connect)
51949 @@ -1256,7 +1256,7 @@ void gserial_disconnect(struct gserial *gser)
51950
51951 port->port_usb = NULL;
51952 gser->ioport = NULL;
51953 - if (port->port.count > 0 || port->openclose) {
51954 + if (atomic_read(&port->port.count) > 0 || port->openclose) {
51955 wake_up_interruptible(&port->drain_wait);
51956 if (port->port.tty)
51957 tty_hangup(port->port.tty);
51958 @@ -1272,7 +1272,7 @@ void gserial_disconnect(struct gserial *gser)
51959
51960 /* finally, free any unused/unusable I/O buffers */
51961 spin_lock_irqsave(&port->port_lock, flags);
51962 - if (port->port.count == 0 && !port->openclose)
51963 + if (atomic_read(&port->port.count) == 0 && !port->openclose)
51964 gs_buf_free(&port->port_write_buf);
51965 gs_free_requests(gser->out, &port->read_pool, NULL);
51966 gs_free_requests(gser->out, &port->read_queue, NULL);
51967 diff --git a/drivers/usb/host/ehci-hub.c b/drivers/usb/host/ehci-hub.c
51968 index 1bb85be..29e28d9 100644
51969 --- a/drivers/usb/host/ehci-hub.c
51970 +++ b/drivers/usb/host/ehci-hub.c
51971 @@ -780,7 +780,7 @@ static struct urb *request_single_step_set_feature_urb(
51972 urb->transfer_flags = URB_DIR_IN;
51973 usb_get_urb(urb);
51974 atomic_inc(&urb->use_count);
51975 - atomic_inc(&urb->dev->urbnum);
51976 + atomic_inc_unchecked(&urb->dev->urbnum);
51977 urb->setup_dma = dma_map_single(
51978 hcd->self.controller,
51979 urb->setup_packet,
51980 @@ -847,7 +847,7 @@ static int ehset_single_step_set_feature(struct usb_hcd *hcd, int port)
51981 urb->status = -EINPROGRESS;
51982 usb_get_urb(urb);
51983 atomic_inc(&urb->use_count);
51984 - atomic_inc(&urb->dev->urbnum);
51985 + atomic_inc_unchecked(&urb->dev->urbnum);
51986 retval = submit_single_step_set_feature(hcd, urb, 0);
51987 if (!retval && !wait_for_completion_timeout(&done,
51988 msecs_to_jiffies(2000))) {
51989 diff --git a/drivers/usb/misc/appledisplay.c b/drivers/usb/misc/appledisplay.c
51990 index ba6a5d6..f88f7f3 100644
51991 --- a/drivers/usb/misc/appledisplay.c
51992 +++ b/drivers/usb/misc/appledisplay.c
51993 @@ -83,7 +83,7 @@ struct appledisplay {
51994 spinlock_t lock;
51995 };
51996
51997 -static atomic_t count_displays = ATOMIC_INIT(0);
51998 +static atomic_unchecked_t count_displays = ATOMIC_INIT(0);
51999 static struct workqueue_struct *wq;
52000
52001 static void appledisplay_complete(struct urb *urb)
52002 @@ -281,7 +281,7 @@ static int appledisplay_probe(struct usb_interface *iface,
52003
52004 /* Register backlight device */
52005 snprintf(bl_name, sizeof(bl_name), "appledisplay%d",
52006 - atomic_inc_return(&count_displays) - 1);
52007 + atomic_inc_return_unchecked(&count_displays) - 1);
52008 memset(&props, 0, sizeof(struct backlight_properties));
52009 props.type = BACKLIGHT_RAW;
52010 props.max_brightness = 0xff;
52011 diff --git a/drivers/usb/serial/console.c b/drivers/usb/serial/console.c
52012 index c69bb50..215ef37 100644
52013 --- a/drivers/usb/serial/console.c
52014 +++ b/drivers/usb/serial/console.c
52015 @@ -124,7 +124,7 @@ static int usb_console_setup(struct console *co, char *options)
52016
52017 info->port = port;
52018
52019 - ++port->port.count;
52020 + atomic_inc(&port->port.count);
52021 if (!test_bit(ASYNCB_INITIALIZED, &port->port.flags)) {
52022 if (serial->type->set_termios) {
52023 /*
52024 @@ -170,7 +170,7 @@ static int usb_console_setup(struct console *co, char *options)
52025 }
52026 /* Now that any required fake tty operations are completed restore
52027 * the tty port count */
52028 - --port->port.count;
52029 + atomic_dec(&port->port.count);
52030 /* The console is special in terms of closing the device so
52031 * indicate this port is now acting as a system console. */
52032 port->port.console = 1;
52033 @@ -183,7 +183,7 @@ static int usb_console_setup(struct console *co, char *options)
52034 free_tty:
52035 kfree(tty);
52036 reset_open_count:
52037 - port->port.count = 0;
52038 + atomic_set(&port->port.count, 0);
52039 usb_autopm_put_interface(serial->interface);
52040 error_get_interface:
52041 usb_serial_put(serial);
52042 @@ -194,7 +194,7 @@ static int usb_console_setup(struct console *co, char *options)
52043 static void usb_console_write(struct console *co,
52044 const char *buf, unsigned count)
52045 {
52046 - static struct usbcons_info *info = &usbcons_info;
52047 + struct usbcons_info *info = &usbcons_info;
52048 struct usb_serial_port *port = info->port;
52049 struct usb_serial *serial;
52050 int retval = -ENODEV;
52051 diff --git a/drivers/usb/storage/usb.h b/drivers/usb/storage/usb.h
52052 index 75f70f0..d467e1a 100644
52053 --- a/drivers/usb/storage/usb.h
52054 +++ b/drivers/usb/storage/usb.h
52055 @@ -63,7 +63,7 @@ struct us_unusual_dev {
52056 __u8 useProtocol;
52057 __u8 useTransport;
52058 int (*initFunction)(struct us_data *);
52059 -};
52060 +} __do_const;
52061
52062
52063 /* Dynamic bitflag definitions (us->dflags): used in set_bit() etc. */
52064 diff --git a/drivers/usb/wusbcore/wa-hc.h b/drivers/usb/wusbcore/wa-hc.h
52065 index e614f02..3fd60e2 100644
52066 --- a/drivers/usb/wusbcore/wa-hc.h
52067 +++ b/drivers/usb/wusbcore/wa-hc.h
52068 @@ -225,7 +225,7 @@ struct wahc {
52069 spinlock_t xfer_list_lock;
52070 struct work_struct xfer_enqueue_work;
52071 struct work_struct xfer_error_work;
52072 - atomic_t xfer_id_count;
52073 + atomic_unchecked_t xfer_id_count;
52074
52075 kernel_ulong_t quirks;
52076 };
52077 @@ -287,7 +287,7 @@ static inline void wa_init(struct wahc *wa)
52078 INIT_WORK(&wa->xfer_enqueue_work, wa_urb_enqueue_run);
52079 INIT_WORK(&wa->xfer_error_work, wa_process_errored_transfers_run);
52080 wa->dto_in_use = 0;
52081 - atomic_set(&wa->xfer_id_count, 1);
52082 + atomic_set_unchecked(&wa->xfer_id_count, 1);
52083 }
52084
52085 /**
52086 diff --git a/drivers/usb/wusbcore/wa-xfer.c b/drivers/usb/wusbcore/wa-xfer.c
52087 index ed5abe8..7036400 100644
52088 --- a/drivers/usb/wusbcore/wa-xfer.c
52089 +++ b/drivers/usb/wusbcore/wa-xfer.c
52090 @@ -312,7 +312,7 @@ static void wa_xfer_completion(struct wa_xfer *xfer)
52091 */
52092 static void wa_xfer_id_init(struct wa_xfer *xfer)
52093 {
52094 - xfer->id = atomic_add_return(1, &xfer->wa->xfer_id_count);
52095 + xfer->id = atomic_add_return_unchecked(1, &xfer->wa->xfer_id_count);
52096 }
52097
52098 /* Return the xfer's ID. */
52099 diff --git a/drivers/vfio/vfio.c b/drivers/vfio/vfio.c
52100 index 1eab4ac..e21efc9 100644
52101 --- a/drivers/vfio/vfio.c
52102 +++ b/drivers/vfio/vfio.c
52103 @@ -488,7 +488,7 @@ static int vfio_group_nb_add_dev(struct vfio_group *group, struct device *dev)
52104 return 0;
52105
52106 /* TODO Prevent device auto probing */
52107 - WARN("Device %s added to live group %d!\n", dev_name(dev),
52108 + WARN(1, "Device %s added to live group %d!\n", dev_name(dev),
52109 iommu_group_id(group->iommu_group));
52110
52111 return 0;
52112 diff --git a/drivers/vhost/vringh.c b/drivers/vhost/vringh.c
52113 index 5174eba..451e6bc 100644
52114 --- a/drivers/vhost/vringh.c
52115 +++ b/drivers/vhost/vringh.c
52116 @@ -530,17 +530,17 @@ static inline void __vringh_notify_disable(struct vringh *vrh,
52117 /* Userspace access helpers: in this case, addresses are really userspace. */
52118 static inline int getu16_user(u16 *val, const u16 *p)
52119 {
52120 - return get_user(*val, (__force u16 __user *)p);
52121 + return get_user(*val, (u16 __force_user *)p);
52122 }
52123
52124 static inline int putu16_user(u16 *p, u16 val)
52125 {
52126 - return put_user(val, (__force u16 __user *)p);
52127 + return put_user(val, (u16 __force_user *)p);
52128 }
52129
52130 static inline int copydesc_user(void *dst, const void *src, size_t len)
52131 {
52132 - return copy_from_user(dst, (__force void __user *)src, len) ?
52133 + return copy_from_user(dst, (void __force_user *)src, len) ?
52134 -EFAULT : 0;
52135 }
52136
52137 @@ -548,19 +548,19 @@ static inline int putused_user(struct vring_used_elem *dst,
52138 const struct vring_used_elem *src,
52139 unsigned int num)
52140 {
52141 - return copy_to_user((__force void __user *)dst, src,
52142 + return copy_to_user((void __force_user *)dst, src,
52143 sizeof(*dst) * num) ? -EFAULT : 0;
52144 }
52145
52146 static inline int xfer_from_user(void *src, void *dst, size_t len)
52147 {
52148 - return copy_from_user(dst, (__force void __user *)src, len) ?
52149 + return copy_from_user(dst, (void __force_user *)src, len) ?
52150 -EFAULT : 0;
52151 }
52152
52153 static inline int xfer_to_user(void *dst, void *src, size_t len)
52154 {
52155 - return copy_to_user((__force void __user *)dst, src, len) ?
52156 + return copy_to_user((void __force_user *)dst, src, len) ?
52157 -EFAULT : 0;
52158 }
52159
52160 @@ -596,9 +596,9 @@ int vringh_init_user(struct vringh *vrh, u32 features,
52161 vrh->last_used_idx = 0;
52162 vrh->vring.num = num;
52163 /* vring expects kernel addresses, but only used via accessors. */
52164 - vrh->vring.desc = (__force struct vring_desc *)desc;
52165 - vrh->vring.avail = (__force struct vring_avail *)avail;
52166 - vrh->vring.used = (__force struct vring_used *)used;
52167 + vrh->vring.desc = (__force_kernel struct vring_desc *)desc;
52168 + vrh->vring.avail = (__force_kernel struct vring_avail *)avail;
52169 + vrh->vring.used = (__force_kernel struct vring_used *)used;
52170 return 0;
52171 }
52172 EXPORT_SYMBOL(vringh_init_user);
52173 @@ -800,7 +800,7 @@ static inline int getu16_kern(u16 *val, const u16 *p)
52174
52175 static inline int putu16_kern(u16 *p, u16 val)
52176 {
52177 - ACCESS_ONCE(*p) = val;
52178 + ACCESS_ONCE_RW(*p) = val;
52179 return 0;
52180 }
52181
52182 diff --git a/drivers/video/arcfb.c b/drivers/video/arcfb.c
52183 index 1b0b233..6f34c2c 100644
52184 --- a/drivers/video/arcfb.c
52185 +++ b/drivers/video/arcfb.c
52186 @@ -458,7 +458,7 @@ static ssize_t arcfb_write(struct fb_info *info, const char __user *buf,
52187 return -ENOSPC;
52188
52189 err = 0;
52190 - if ((count + p) > fbmemlength) {
52191 + if (count > (fbmemlength - p)) {
52192 count = fbmemlength - p;
52193 err = -ENOSPC;
52194 }
52195 diff --git a/drivers/video/aty/aty128fb.c b/drivers/video/aty/aty128fb.c
52196 index 12ca031..84a8a74 100644
52197 --- a/drivers/video/aty/aty128fb.c
52198 +++ b/drivers/video/aty/aty128fb.c
52199 @@ -149,7 +149,7 @@ enum {
52200 };
52201
52202 /* Must match above enum */
52203 -static char * const r128_family[] = {
52204 +static const char * const r128_family[] = {
52205 "AGP",
52206 "PCI",
52207 "PRO AGP",
52208 diff --git a/drivers/video/aty/atyfb_base.c b/drivers/video/aty/atyfb_base.c
52209 index 28fafbf..ae91651 100644
52210 --- a/drivers/video/aty/atyfb_base.c
52211 +++ b/drivers/video/aty/atyfb_base.c
52212 @@ -1326,10 +1326,14 @@ static int atyfb_set_par(struct fb_info *info)
52213 par->accel_flags = var->accel_flags; /* hack */
52214
52215 if (var->accel_flags) {
52216 - info->fbops->fb_sync = atyfb_sync;
52217 + pax_open_kernel();
52218 + *(void **)&info->fbops->fb_sync = atyfb_sync;
52219 + pax_close_kernel();
52220 info->flags &= ~FBINFO_HWACCEL_DISABLED;
52221 } else {
52222 - info->fbops->fb_sync = NULL;
52223 + pax_open_kernel();
52224 + *(void **)&info->fbops->fb_sync = NULL;
52225 + pax_close_kernel();
52226 info->flags |= FBINFO_HWACCEL_DISABLED;
52227 }
52228
52229 diff --git a/drivers/video/aty/mach64_cursor.c b/drivers/video/aty/mach64_cursor.c
52230 index 95ec042..e6affdd 100644
52231 --- a/drivers/video/aty/mach64_cursor.c
52232 +++ b/drivers/video/aty/mach64_cursor.c
52233 @@ -7,6 +7,7 @@
52234 #include <linux/string.h>
52235
52236 #include <asm/io.h>
52237 +#include <asm/pgtable.h>
52238
52239 #ifdef __sparc__
52240 #include <asm/fbio.h>
52241 @@ -208,7 +209,9 @@ int aty_init_cursor(struct fb_info *info)
52242 info->sprite.buf_align = 16; /* and 64 lines tall. */
52243 info->sprite.flags = FB_PIXMAP_IO;
52244
52245 - info->fbops->fb_cursor = atyfb_cursor;
52246 + pax_open_kernel();
52247 + *(void **)&info->fbops->fb_cursor = atyfb_cursor;
52248 + pax_close_kernel();
52249
52250 return 0;
52251 }
52252 diff --git a/drivers/video/backlight/kb3886_bl.c b/drivers/video/backlight/kb3886_bl.c
52253 index 7592cc2..92feb56 100644
52254 --- a/drivers/video/backlight/kb3886_bl.c
52255 +++ b/drivers/video/backlight/kb3886_bl.c
52256 @@ -78,7 +78,7 @@ static struct kb3886bl_machinfo *bl_machinfo;
52257 static unsigned long kb3886bl_flags;
52258 #define KB3886BL_SUSPENDED 0x01
52259
52260 -static struct dmi_system_id __initdata kb3886bl_device_table[] = {
52261 +static const struct dmi_system_id __initconst kb3886bl_device_table[] = {
52262 {
52263 .ident = "Sahara Touch-iT",
52264 .matches = {
52265 diff --git a/drivers/video/fb_defio.c b/drivers/video/fb_defio.c
52266 index 900aa4e..6d49418 100644
52267 --- a/drivers/video/fb_defio.c
52268 +++ b/drivers/video/fb_defio.c
52269 @@ -206,7 +206,9 @@ void fb_deferred_io_init(struct fb_info *info)
52270
52271 BUG_ON(!fbdefio);
52272 mutex_init(&fbdefio->lock);
52273 - info->fbops->fb_mmap = fb_deferred_io_mmap;
52274 + pax_open_kernel();
52275 + *(void **)&info->fbops->fb_mmap = fb_deferred_io_mmap;
52276 + pax_close_kernel();
52277 INIT_DELAYED_WORK(&info->deferred_work, fb_deferred_io_work);
52278 INIT_LIST_HEAD(&fbdefio->pagelist);
52279 if (fbdefio->delay == 0) /* set a default of 1 s */
52280 @@ -237,7 +239,7 @@ void fb_deferred_io_cleanup(struct fb_info *info)
52281 page->mapping = NULL;
52282 }
52283
52284 - info->fbops->fb_mmap = NULL;
52285 + *(void **)&info->fbops->fb_mmap = NULL;
52286 mutex_destroy(&fbdefio->lock);
52287 }
52288 EXPORT_SYMBOL_GPL(fb_deferred_io_cleanup);
52289 diff --git a/drivers/video/fbmem.c b/drivers/video/fbmem.c
52290 index 010d191..7b8235a 100644
52291 --- a/drivers/video/fbmem.c
52292 +++ b/drivers/video/fbmem.c
52293 @@ -433,7 +433,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
52294 image->dx += image->width + 8;
52295 }
52296 } else if (rotate == FB_ROTATE_UD) {
52297 - for (x = 0; x < num && image->dx >= 0; x++) {
52298 + for (x = 0; x < num && (__s32)image->dx >= 0; x++) {
52299 info->fbops->fb_imageblit(info, image);
52300 image->dx -= image->width + 8;
52301 }
52302 @@ -445,7 +445,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
52303 image->dy += image->height + 8;
52304 }
52305 } else if (rotate == FB_ROTATE_CCW) {
52306 - for (x = 0; x < num && image->dy >= 0; x++) {
52307 + for (x = 0; x < num && (__s32)image->dy >= 0; x++) {
52308 info->fbops->fb_imageblit(info, image);
52309 image->dy -= image->height + 8;
52310 }
52311 @@ -1179,7 +1179,7 @@ static long do_fb_ioctl(struct fb_info *info, unsigned int cmd,
52312 return -EFAULT;
52313 if (con2fb.console < 1 || con2fb.console > MAX_NR_CONSOLES)
52314 return -EINVAL;
52315 - if (con2fb.framebuffer < 0 || con2fb.framebuffer >= FB_MAX)
52316 + if (con2fb.framebuffer >= FB_MAX)
52317 return -EINVAL;
52318 if (!registered_fb[con2fb.framebuffer])
52319 request_module("fb%d", con2fb.framebuffer);
52320 @@ -1300,7 +1300,7 @@ static int do_fscreeninfo_to_user(struct fb_fix_screeninfo *fix,
52321 __u32 data;
52322 int err;
52323
52324 - err = copy_to_user(&fix32->id, &fix->id, sizeof(fix32->id));
52325 + err = copy_to_user(fix32->id, &fix->id, sizeof(fix32->id));
52326
52327 data = (__u32) (unsigned long) fix->smem_start;
52328 err |= put_user(data, &fix32->smem_start);
52329 diff --git a/drivers/video/hyperv_fb.c b/drivers/video/hyperv_fb.c
52330 index 130708f..cdac1a9 100644
52331 --- a/drivers/video/hyperv_fb.c
52332 +++ b/drivers/video/hyperv_fb.c
52333 @@ -233,7 +233,7 @@ static uint screen_fb_size;
52334 static inline int synthvid_send(struct hv_device *hdev,
52335 struct synthvid_msg *msg)
52336 {
52337 - static atomic64_t request_id = ATOMIC64_INIT(0);
52338 + static atomic64_unchecked_t request_id = ATOMIC64_INIT(0);
52339 int ret;
52340
52341 msg->pipe_hdr.type = PIPE_MSG_DATA;
52342 @@ -241,7 +241,7 @@ static inline int synthvid_send(struct hv_device *hdev,
52343
52344 ret = vmbus_sendpacket(hdev->channel, msg,
52345 msg->vid_hdr.size + sizeof(struct pipe_msg_hdr),
52346 - atomic64_inc_return(&request_id),
52347 + atomic64_inc_return_unchecked(&request_id),
52348 VM_PKT_DATA_INBAND, 0);
52349
52350 if (ret)
52351 diff --git a/drivers/video/i810/i810_accel.c b/drivers/video/i810/i810_accel.c
52352 index 7672d2e..b56437f 100644
52353 --- a/drivers/video/i810/i810_accel.c
52354 +++ b/drivers/video/i810/i810_accel.c
52355 @@ -73,6 +73,7 @@ static inline int wait_for_space(struct fb_info *info, u32 space)
52356 }
52357 }
52358 printk("ringbuffer lockup!!!\n");
52359 + printk("head:%u tail:%u iring.size:%u space:%u\n", head, tail, par->iring.size, space);
52360 i810_report_error(mmio);
52361 par->dev_flags |= LOCKUP;
52362 info->pixmap.scan_align = 1;
52363 diff --git a/drivers/video/logo/logo_linux_clut224.ppm b/drivers/video/logo/logo_linux_clut224.ppm
52364 index 3c14e43..2630570 100644
52365 --- a/drivers/video/logo/logo_linux_clut224.ppm
52366 +++ b/drivers/video/logo/logo_linux_clut224.ppm
52367 @@ -2,1603 +2,1123 @@ P3
52368 # Standard 224-color Linux logo
52369 80 80
52370 255
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 - 6 6 6 6 6 6 10 10 10 10 10 10
52381 - 10 10 10 6 6 6 6 6 6 6 6 6
52382 - 0 0 0 0 0 0 0 0 0 0 0 0
52383 - 0 0 0 0 0 0 0 0 0 0 0 0
52384 - 0 0 0 0 0 0 0 0 0 0 0 0
52385 - 0 0 0 0 0 0 0 0 0 0 0 0
52386 - 0 0 0 0 0 0 0 0 0 0 0 0
52387 - 0 0 0 0 0 0 0 0 0 0 0 0
52388 - 0 0 0 0 0 0 0 0 0 0 0 0
52389 - 0 0 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 0 0 0 0 0 0 0
52398 - 0 0 0 0 0 0 0 0 0 0 0 0
52399 - 0 0 0 6 6 6 10 10 10 14 14 14
52400 - 22 22 22 26 26 26 30 30 30 34 34 34
52401 - 30 30 30 30 30 30 26 26 26 18 18 18
52402 - 14 14 14 10 10 10 6 6 6 0 0 0
52403 - 0 0 0 0 0 0 0 0 0 0 0 0
52404 - 0 0 0 0 0 0 0 0 0 0 0 0
52405 - 0 0 0 0 0 0 0 0 0 0 0 0
52406 - 0 0 0 0 0 0 0 0 0 0 0 0
52407 - 0 0 0 0 0 0 0 0 0 0 0 0
52408 - 0 0 0 0 0 0 0 0 0 0 0 0
52409 - 0 0 0 0 0 0 0 0 0 0 0 0
52410 - 0 0 0 0 0 0 0 0 0 0 0 0
52411 - 0 0 0 0 0 0 0 0 0 0 0 0
52412 - 0 0 0 0 0 1 0 0 1 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 0 0 0 0 0 0 0 0 0 0
52418 - 0 0 0 0 0 0 0 0 0 0 0 0
52419 - 6 6 6 14 14 14 26 26 26 42 42 42
52420 - 54 54 54 66 66 66 78 78 78 78 78 78
52421 - 78 78 78 74 74 74 66 66 66 54 54 54
52422 - 42 42 42 26 26 26 18 18 18 10 10 10
52423 - 6 6 6 0 0 0 0 0 0 0 0 0
52424 - 0 0 0 0 0 0 0 0 0 0 0 0
52425 - 0 0 0 0 0 0 0 0 0 0 0 0
52426 - 0 0 0 0 0 0 0 0 0 0 0 0
52427 - 0 0 0 0 0 0 0 0 0 0 0 0
52428 - 0 0 0 0 0 0 0 0 0 0 0 0
52429 - 0 0 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 1 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 0 0 0 0 0 0 0 0 0 0
52438 - 0 0 0 0 0 0 0 0 0 10 10 10
52439 - 22 22 22 42 42 42 66 66 66 86 86 86
52440 - 66 66 66 38 38 38 38 38 38 22 22 22
52441 - 26 26 26 34 34 34 54 54 54 66 66 66
52442 - 86 86 86 70 70 70 46 46 46 26 26 26
52443 - 14 14 14 6 6 6 0 0 0 0 0 0
52444 - 0 0 0 0 0 0 0 0 0 0 0 0
52445 - 0 0 0 0 0 0 0 0 0 0 0 0
52446 - 0 0 0 0 0 0 0 0 0 0 0 0
52447 - 0 0 0 0 0 0 0 0 0 0 0 0
52448 - 0 0 0 0 0 0 0 0 0 0 0 0
52449 - 0 0 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 1 0 0 1 0 0 1 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 10 10 10 26 26 26
52459 - 50 50 50 82 82 82 58 58 58 6 6 6
52460 - 2 2 6 2 2 6 2 2 6 2 2 6
52461 - 2 2 6 2 2 6 2 2 6 2 2 6
52462 - 6 6 6 54 54 54 86 86 86 66 66 66
52463 - 38 38 38 18 18 18 6 6 6 0 0 0
52464 - 0 0 0 0 0 0 0 0 0 0 0 0
52465 - 0 0 0 0 0 0 0 0 0 0 0 0
52466 - 0 0 0 0 0 0 0 0 0 0 0 0
52467 - 0 0 0 0 0 0 0 0 0 0 0 0
52468 - 0 0 0 0 0 0 0 0 0 0 0 0
52469 - 0 0 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 0 0 0 0 0 0 0 0 0 0
52478 - 0 0 0 6 6 6 22 22 22 50 50 50
52479 - 78 78 78 34 34 34 2 2 6 2 2 6
52480 - 2 2 6 2 2 6 2 2 6 2 2 6
52481 - 2 2 6 2 2 6 2 2 6 2 2 6
52482 - 2 2 6 2 2 6 6 6 6 70 70 70
52483 - 78 78 78 46 46 46 22 22 22 6 6 6
52484 - 0 0 0 0 0 0 0 0 0 0 0 0
52485 - 0 0 0 0 0 0 0 0 0 0 0 0
52486 - 0 0 0 0 0 0 0 0 0 0 0 0
52487 - 0 0 0 0 0 0 0 0 0 0 0 0
52488 - 0 0 0 0 0 0 0 0 0 0 0 0
52489 - 0 0 0 0 0 0 0 0 0 0 0 0
52490 - 0 0 0 0 0 0 0 0 0 0 0 0
52491 - 0 0 0 0 0 0 0 0 0 0 0 0
52492 - 0 0 1 0 0 1 0 0 1 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 0 0 0 0 0 0 0 0 0 0
52498 - 6 6 6 18 18 18 42 42 42 82 82 82
52499 - 26 26 26 2 2 6 2 2 6 2 2 6
52500 - 2 2 6 2 2 6 2 2 6 2 2 6
52501 - 2 2 6 2 2 6 2 2 6 14 14 14
52502 - 46 46 46 34 34 34 6 6 6 2 2 6
52503 - 42 42 42 78 78 78 42 42 42 18 18 18
52504 - 6 6 6 0 0 0 0 0 0 0 0 0
52505 - 0 0 0 0 0 0 0 0 0 0 0 0
52506 - 0 0 0 0 0 0 0 0 0 0 0 0
52507 - 0 0 0 0 0 0 0 0 0 0 0 0
52508 - 0 0 0 0 0 0 0 0 0 0 0 0
52509 - 0 0 0 0 0 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 1 0 0 0 0 0 1 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 0 0 0 0 0 0 0 0 0 0
52518 - 10 10 10 30 30 30 66 66 66 58 58 58
52519 - 2 2 6 2 2 6 2 2 6 2 2 6
52520 - 2 2 6 2 2 6 2 2 6 2 2 6
52521 - 2 2 6 2 2 6 2 2 6 26 26 26
52522 - 86 86 86 101 101 101 46 46 46 10 10 10
52523 - 2 2 6 58 58 58 70 70 70 34 34 34
52524 - 10 10 10 0 0 0 0 0 0 0 0 0
52525 - 0 0 0 0 0 0 0 0 0 0 0 0
52526 - 0 0 0 0 0 0 0 0 0 0 0 0
52527 - 0 0 0 0 0 0 0 0 0 0 0 0
52528 - 0 0 0 0 0 0 0 0 0 0 0 0
52529 - 0 0 0 0 0 0 0 0 0 0 0 0
52530 - 0 0 0 0 0 0 0 0 0 0 0 0
52531 - 0 0 0 0 0 0 0 0 0 0 0 0
52532 - 0 0 1 0 0 1 0 0 1 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 - 14 14 14 42 42 42 86 86 86 10 10 10
52539 - 2 2 6 2 2 6 2 2 6 2 2 6
52540 - 2 2 6 2 2 6 2 2 6 2 2 6
52541 - 2 2 6 2 2 6 2 2 6 30 30 30
52542 - 94 94 94 94 94 94 58 58 58 26 26 26
52543 - 2 2 6 6 6 6 78 78 78 54 54 54
52544 - 22 22 22 6 6 6 0 0 0 0 0 0
52545 - 0 0 0 0 0 0 0 0 0 0 0 0
52546 - 0 0 0 0 0 0 0 0 0 0 0 0
52547 - 0 0 0 0 0 0 0 0 0 0 0 0
52548 - 0 0 0 0 0 0 0 0 0 0 0 0
52549 - 0 0 0 0 0 0 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 0 0 0 0 6 6 6
52558 - 22 22 22 62 62 62 62 62 62 2 2 6
52559 - 2 2 6 2 2 6 2 2 6 2 2 6
52560 - 2 2 6 2 2 6 2 2 6 2 2 6
52561 - 2 2 6 2 2 6 2 2 6 26 26 26
52562 - 54 54 54 38 38 38 18 18 18 10 10 10
52563 - 2 2 6 2 2 6 34 34 34 82 82 82
52564 - 38 38 38 14 14 14 0 0 0 0 0 0
52565 - 0 0 0 0 0 0 0 0 0 0 0 0
52566 - 0 0 0 0 0 0 0 0 0 0 0 0
52567 - 0 0 0 0 0 0 0 0 0 0 0 0
52568 - 0 0 0 0 0 0 0 0 0 0 0 0
52569 - 0 0 0 0 0 0 0 0 0 0 0 0
52570 - 0 0 0 0 0 0 0 0 0 0 0 0
52571 - 0 0 0 0 0 0 0 0 0 0 0 0
52572 - 0 0 0 0 0 1 0 0 1 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 0 0 0 0 0 0 0 6 6 6
52578 - 30 30 30 78 78 78 30 30 30 2 2 6
52579 - 2 2 6 2 2 6 2 2 6 2 2 6
52580 - 2 2 6 2 2 6 2 2 6 2 2 6
52581 - 2 2 6 2 2 6 2 2 6 10 10 10
52582 - 10 10 10 2 2 6 2 2 6 2 2 6
52583 - 2 2 6 2 2 6 2 2 6 78 78 78
52584 - 50 50 50 18 18 18 6 6 6 0 0 0
52585 - 0 0 0 0 0 0 0 0 0 0 0 0
52586 - 0 0 0 0 0 0 0 0 0 0 0 0
52587 - 0 0 0 0 0 0 0 0 0 0 0 0
52588 - 0 0 0 0 0 0 0 0 0 0 0 0
52589 - 0 0 0 0 0 0 0 0 0 0 0 0
52590 - 0 0 0 0 0 0 0 0 0 0 0 0
52591 - 0 0 0 0 0 0 0 0 0 0 0 0
52592 - 0 0 1 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 0 0 0 0 10 10 10
52598 - 38 38 38 86 86 86 14 14 14 2 2 6
52599 - 2 2 6 2 2 6 2 2 6 2 2 6
52600 - 2 2 6 2 2 6 2 2 6 2 2 6
52601 - 2 2 6 2 2 6 2 2 6 2 2 6
52602 - 2 2 6 2 2 6 2 2 6 2 2 6
52603 - 2 2 6 2 2 6 2 2 6 54 54 54
52604 - 66 66 66 26 26 26 6 6 6 0 0 0
52605 - 0 0 0 0 0 0 0 0 0 0 0 0
52606 - 0 0 0 0 0 0 0 0 0 0 0 0
52607 - 0 0 0 0 0 0 0 0 0 0 0 0
52608 - 0 0 0 0 0 0 0 0 0 0 0 0
52609 - 0 0 0 0 0 0 0 0 0 0 0 0
52610 - 0 0 0 0 0 0 0 0 0 0 0 0
52611 - 0 0 0 0 0 0 0 0 0 0 0 0
52612 - 0 0 0 0 0 1 0 0 1 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 0 0 0 0 0 0 0 14 14 14
52618 - 42 42 42 82 82 82 2 2 6 2 2 6
52619 - 2 2 6 6 6 6 10 10 10 2 2 6
52620 - 2 2 6 2 2 6 2 2 6 2 2 6
52621 - 2 2 6 2 2 6 2 2 6 6 6 6
52622 - 14 14 14 10 10 10 2 2 6 2 2 6
52623 - 2 2 6 2 2 6 2 2 6 18 18 18
52624 - 82 82 82 34 34 34 10 10 10 0 0 0
52625 - 0 0 0 0 0 0 0 0 0 0 0 0
52626 - 0 0 0 0 0 0 0 0 0 0 0 0
52627 - 0 0 0 0 0 0 0 0 0 0 0 0
52628 - 0 0 0 0 0 0 0 0 0 0 0 0
52629 - 0 0 0 0 0 0 0 0 0 0 0 0
52630 - 0 0 0 0 0 0 0 0 0 0 0 0
52631 - 0 0 0 0 0 0 0 0 0 0 0 0
52632 - 0 0 1 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 0 0 0 0 0 0 0 14 14 14
52638 - 46 46 46 86 86 86 2 2 6 2 2 6
52639 - 6 6 6 6 6 6 22 22 22 34 34 34
52640 - 6 6 6 2 2 6 2 2 6 2 2 6
52641 - 2 2 6 2 2 6 18 18 18 34 34 34
52642 - 10 10 10 50 50 50 22 22 22 2 2 6
52643 - 2 2 6 2 2 6 2 2 6 10 10 10
52644 - 86 86 86 42 42 42 14 14 14 0 0 0
52645 - 0 0 0 0 0 0 0 0 0 0 0 0
52646 - 0 0 0 0 0 0 0 0 0 0 0 0
52647 - 0 0 0 0 0 0 0 0 0 0 0 0
52648 - 0 0 0 0 0 0 0 0 0 0 0 0
52649 - 0 0 0 0 0 0 0 0 0 0 0 0
52650 - 0 0 0 0 0 0 0 0 0 0 0 0
52651 - 0 0 0 0 0 0 0 0 0 0 0 0
52652 - 0 0 1 0 0 1 0 0 1 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 14 14 14
52658 - 46 46 46 86 86 86 2 2 6 2 2 6
52659 - 38 38 38 116 116 116 94 94 94 22 22 22
52660 - 22 22 22 2 2 6 2 2 6 2 2 6
52661 - 14 14 14 86 86 86 138 138 138 162 162 162
52662 -154 154 154 38 38 38 26 26 26 6 6 6
52663 - 2 2 6 2 2 6 2 2 6 2 2 6
52664 - 86 86 86 46 46 46 14 14 14 0 0 0
52665 - 0 0 0 0 0 0 0 0 0 0 0 0
52666 - 0 0 0 0 0 0 0 0 0 0 0 0
52667 - 0 0 0 0 0 0 0 0 0 0 0 0
52668 - 0 0 0 0 0 0 0 0 0 0 0 0
52669 - 0 0 0 0 0 0 0 0 0 0 0 0
52670 - 0 0 0 0 0 0 0 0 0 0 0 0
52671 - 0 0 0 0 0 0 0 0 0 0 0 0
52672 - 0 0 0 0 0 0 0 0 0 0 0 0
52673 - 0 0 0 0 0 0 0 0 0 0 0 0
52674 - 0 0 0 0 0 0 0 0 0 0 0 0
52675 - 0 0 0 0 0 0 0 0 0 0 0 0
52676 - 0 0 0 0 0 0 0 0 0 0 0 0
52677 - 0 0 0 0 0 0 0 0 0 14 14 14
52678 - 46 46 46 86 86 86 2 2 6 14 14 14
52679 -134 134 134 198 198 198 195 195 195 116 116 116
52680 - 10 10 10 2 2 6 2 2 6 6 6 6
52681 -101 98 89 187 187 187 210 210 210 218 218 218
52682 -214 214 214 134 134 134 14 14 14 6 6 6
52683 - 2 2 6 2 2 6 2 2 6 2 2 6
52684 - 86 86 86 50 50 50 18 18 18 6 6 6
52685 - 0 0 0 0 0 0 0 0 0 0 0 0
52686 - 0 0 0 0 0 0 0 0 0 0 0 0
52687 - 0 0 0 0 0 0 0 0 0 0 0 0
52688 - 0 0 0 0 0 0 0 0 0 0 0 0
52689 - 0 0 0 0 0 0 0 0 0 0 0 0
52690 - 0 0 0 0 0 0 0 0 0 0 0 0
52691 - 0 0 0 0 0 0 0 0 1 0 0 0
52692 - 0 0 1 0 0 1 0 0 1 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 14 14 14
52698 - 46 46 46 86 86 86 2 2 6 54 54 54
52699 -218 218 218 195 195 195 226 226 226 246 246 246
52700 - 58 58 58 2 2 6 2 2 6 30 30 30
52701 -210 210 210 253 253 253 174 174 174 123 123 123
52702 -221 221 221 234 234 234 74 74 74 2 2 6
52703 - 2 2 6 2 2 6 2 2 6 2 2 6
52704 - 70 70 70 58 58 58 22 22 22 6 6 6
52705 - 0 0 0 0 0 0 0 0 0 0 0 0
52706 - 0 0 0 0 0 0 0 0 0 0 0 0
52707 - 0 0 0 0 0 0 0 0 0 0 0 0
52708 - 0 0 0 0 0 0 0 0 0 0 0 0
52709 - 0 0 0 0 0 0 0 0 0 0 0 0
52710 - 0 0 0 0 0 0 0 0 0 0 0 0
52711 - 0 0 0 0 0 0 0 0 0 0 0 0
52712 - 0 0 0 0 0 0 0 0 0 0 0 0
52713 - 0 0 0 0 0 0 0 0 0 0 0 0
52714 - 0 0 0 0 0 0 0 0 0 0 0 0
52715 - 0 0 0 0 0 0 0 0 0 0 0 0
52716 - 0 0 0 0 0 0 0 0 0 0 0 0
52717 - 0 0 0 0 0 0 0 0 0 14 14 14
52718 - 46 46 46 82 82 82 2 2 6 106 106 106
52719 -170 170 170 26 26 26 86 86 86 226 226 226
52720 -123 123 123 10 10 10 14 14 14 46 46 46
52721 -231 231 231 190 190 190 6 6 6 70 70 70
52722 - 90 90 90 238 238 238 158 158 158 2 2 6
52723 - 2 2 6 2 2 6 2 2 6 2 2 6
52724 - 70 70 70 58 58 58 22 22 22 6 6 6
52725 - 0 0 0 0 0 0 0 0 0 0 0 0
52726 - 0 0 0 0 0 0 0 0 0 0 0 0
52727 - 0 0 0 0 0 0 0 0 0 0 0 0
52728 - 0 0 0 0 0 0 0 0 0 0 0 0
52729 - 0 0 0 0 0 0 0 0 0 0 0 0
52730 - 0 0 0 0 0 0 0 0 0 0 0 0
52731 - 0 0 0 0 0 0 0 0 1 0 0 0
52732 - 0 0 1 0 0 1 0 0 1 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 0 0 0 0
52737 - 0 0 0 0 0 0 0 0 0 14 14 14
52738 - 42 42 42 86 86 86 6 6 6 116 116 116
52739 -106 106 106 6 6 6 70 70 70 149 149 149
52740 -128 128 128 18 18 18 38 38 38 54 54 54
52741 -221 221 221 106 106 106 2 2 6 14 14 14
52742 - 46 46 46 190 190 190 198 198 198 2 2 6
52743 - 2 2 6 2 2 6 2 2 6 2 2 6
52744 - 74 74 74 62 62 62 22 22 22 6 6 6
52745 - 0 0 0 0 0 0 0 0 0 0 0 0
52746 - 0 0 0 0 0 0 0 0 0 0 0 0
52747 - 0 0 0 0 0 0 0 0 0 0 0 0
52748 - 0 0 0 0 0 0 0 0 0 0 0 0
52749 - 0 0 0 0 0 0 0 0 0 0 0 0
52750 - 0 0 0 0 0 0 0 0 0 0 0 0
52751 - 0 0 0 0 0 0 0 0 1 0 0 0
52752 - 0 0 1 0 0 0 0 0 1 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 0 0 0 0
52757 - 0 0 0 0 0 0 0 0 0 14 14 14
52758 - 42 42 42 94 94 94 14 14 14 101 101 101
52759 -128 128 128 2 2 6 18 18 18 116 116 116
52760 -118 98 46 121 92 8 121 92 8 98 78 10
52761 -162 162 162 106 106 106 2 2 6 2 2 6
52762 - 2 2 6 195 195 195 195 195 195 6 6 6
52763 - 2 2 6 2 2 6 2 2 6 2 2 6
52764 - 74 74 74 62 62 62 22 22 22 6 6 6
52765 - 0 0 0 0 0 0 0 0 0 0 0 0
52766 - 0 0 0 0 0 0 0 0 0 0 0 0
52767 - 0 0 0 0 0 0 0 0 0 0 0 0
52768 - 0 0 0 0 0 0 0 0 0 0 0 0
52769 - 0 0 0 0 0 0 0 0 0 0 0 0
52770 - 0 0 0 0 0 0 0 0 0 0 0 0
52771 - 0 0 0 0 0 0 0 0 1 0 0 1
52772 - 0 0 1 0 0 0 0 0 1 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 10 10 10
52778 - 38 38 38 90 90 90 14 14 14 58 58 58
52779 -210 210 210 26 26 26 54 38 6 154 114 10
52780 -226 170 11 236 186 11 225 175 15 184 144 12
52781 -215 174 15 175 146 61 37 26 9 2 2 6
52782 - 70 70 70 246 246 246 138 138 138 2 2 6
52783 - 2 2 6 2 2 6 2 2 6 2 2 6
52784 - 70 70 70 66 66 66 26 26 26 6 6 6
52785 - 0 0 0 0 0 0 0 0 0 0 0 0
52786 - 0 0 0 0 0 0 0 0 0 0 0 0
52787 - 0 0 0 0 0 0 0 0 0 0 0 0
52788 - 0 0 0 0 0 0 0 0 0 0 0 0
52789 - 0 0 0 0 0 0 0 0 0 0 0 0
52790 - 0 0 0 0 0 0 0 0 0 0 0 0
52791 - 0 0 0 0 0 0 0 0 0 0 0 0
52792 - 0 0 0 0 0 0 0 0 0 0 0 0
52793 - 0 0 0 0 0 0 0 0 0 0 0 0
52794 - 0 0 0 0 0 0 0 0 0 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 10 10 10
52798 - 38 38 38 86 86 86 14 14 14 10 10 10
52799 -195 195 195 188 164 115 192 133 9 225 175 15
52800 -239 182 13 234 190 10 232 195 16 232 200 30
52801 -245 207 45 241 208 19 232 195 16 184 144 12
52802 -218 194 134 211 206 186 42 42 42 2 2 6
52803 - 2 2 6 2 2 6 2 2 6 2 2 6
52804 - 50 50 50 74 74 74 30 30 30 6 6 6
52805 - 0 0 0 0 0 0 0 0 0 0 0 0
52806 - 0 0 0 0 0 0 0 0 0 0 0 0
52807 - 0 0 0 0 0 0 0 0 0 0 0 0
52808 - 0 0 0 0 0 0 0 0 0 0 0 0
52809 - 0 0 0 0 0 0 0 0 0 0 0 0
52810 - 0 0 0 0 0 0 0 0 0 0 0 0
52811 - 0 0 0 0 0 0 0 0 0 0 0 0
52812 - 0 0 0 0 0 0 0 0 0 0 0 0
52813 - 0 0 0 0 0 0 0 0 0 0 0 0
52814 - 0 0 0 0 0 0 0 0 0 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 10 10 10
52818 - 34 34 34 86 86 86 14 14 14 2 2 6
52819 -121 87 25 192 133 9 219 162 10 239 182 13
52820 -236 186 11 232 195 16 241 208 19 244 214 54
52821 -246 218 60 246 218 38 246 215 20 241 208 19
52822 -241 208 19 226 184 13 121 87 25 2 2 6
52823 - 2 2 6 2 2 6 2 2 6 2 2 6
52824 - 50 50 50 82 82 82 34 34 34 10 10 10
52825 - 0 0 0 0 0 0 0 0 0 0 0 0
52826 - 0 0 0 0 0 0 0 0 0 0 0 0
52827 - 0 0 0 0 0 0 0 0 0 0 0 0
52828 - 0 0 0 0 0 0 0 0 0 0 0 0
52829 - 0 0 0 0 0 0 0 0 0 0 0 0
52830 - 0 0 0 0 0 0 0 0 0 0 0 0
52831 - 0 0 0 0 0 0 0 0 0 0 0 0
52832 - 0 0 0 0 0 0 0 0 0 0 0 0
52833 - 0 0 0 0 0 0 0 0 0 0 0 0
52834 - 0 0 0 0 0 0 0 0 0 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 10 10 10
52838 - 34 34 34 82 82 82 30 30 30 61 42 6
52839 -180 123 7 206 145 10 230 174 11 239 182 13
52840 -234 190 10 238 202 15 241 208 19 246 218 74
52841 -246 218 38 246 215 20 246 215 20 246 215 20
52842 -226 184 13 215 174 15 184 144 12 6 6 6
52843 - 2 2 6 2 2 6 2 2 6 2 2 6
52844 - 26 26 26 94 94 94 42 42 42 14 14 14
52845 - 0 0 0 0 0 0 0 0 0 0 0 0
52846 - 0 0 0 0 0 0 0 0 0 0 0 0
52847 - 0 0 0 0 0 0 0 0 0 0 0 0
52848 - 0 0 0 0 0 0 0 0 0 0 0 0
52849 - 0 0 0 0 0 0 0 0 0 0 0 0
52850 - 0 0 0 0 0 0 0 0 0 0 0 0
52851 - 0 0 0 0 0 0 0 0 0 0 0 0
52852 - 0 0 0 0 0 0 0 0 0 0 0 0
52853 - 0 0 0 0 0 0 0 0 0 0 0 0
52854 - 0 0 0 0 0 0 0 0 0 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 10 10 10
52858 - 30 30 30 78 78 78 50 50 50 104 69 6
52859 -192 133 9 216 158 10 236 178 12 236 186 11
52860 -232 195 16 241 208 19 244 214 54 245 215 43
52861 -246 215 20 246 215 20 241 208 19 198 155 10
52862 -200 144 11 216 158 10 156 118 10 2 2 6
52863 - 2 2 6 2 2 6 2 2 6 2 2 6
52864 - 6 6 6 90 90 90 54 54 54 18 18 18
52865 - 6 6 6 0 0 0 0 0 0 0 0 0
52866 - 0 0 0 0 0 0 0 0 0 0 0 0
52867 - 0 0 0 0 0 0 0 0 0 0 0 0
52868 - 0 0 0 0 0 0 0 0 0 0 0 0
52869 - 0 0 0 0 0 0 0 0 0 0 0 0
52870 - 0 0 0 0 0 0 0 0 0 0 0 0
52871 - 0 0 0 0 0 0 0 0 0 0 0 0
52872 - 0 0 0 0 0 0 0 0 0 0 0 0
52873 - 0 0 0 0 0 0 0 0 0 0 0 0
52874 - 0 0 0 0 0 0 0 0 0 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 10 10 10
52878 - 30 30 30 78 78 78 46 46 46 22 22 22
52879 -137 92 6 210 162 10 239 182 13 238 190 10
52880 -238 202 15 241 208 19 246 215 20 246 215 20
52881 -241 208 19 203 166 17 185 133 11 210 150 10
52882 -216 158 10 210 150 10 102 78 10 2 2 6
52883 - 6 6 6 54 54 54 14 14 14 2 2 6
52884 - 2 2 6 62 62 62 74 74 74 30 30 30
52885 - 10 10 10 0 0 0 0 0 0 0 0 0
52886 - 0 0 0 0 0 0 0 0 0 0 0 0
52887 - 0 0 0 0 0 0 0 0 0 0 0 0
52888 - 0 0 0 0 0 0 0 0 0 0 0 0
52889 - 0 0 0 0 0 0 0 0 0 0 0 0
52890 - 0 0 0 0 0 0 0 0 0 0 0 0
52891 - 0 0 0 0 0 0 0 0 0 0 0 0
52892 - 0 0 0 0 0 0 0 0 0 0 0 0
52893 - 0 0 0 0 0 0 0 0 0 0 0 0
52894 - 0 0 0 0 0 0 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 10 10 10
52898 - 34 34 34 78 78 78 50 50 50 6 6 6
52899 - 94 70 30 139 102 15 190 146 13 226 184 13
52900 -232 200 30 232 195 16 215 174 15 190 146 13
52901 -168 122 10 192 133 9 210 150 10 213 154 11
52902 -202 150 34 182 157 106 101 98 89 2 2 6
52903 - 2 2 6 78 78 78 116 116 116 58 58 58
52904 - 2 2 6 22 22 22 90 90 90 46 46 46
52905 - 18 18 18 6 6 6 0 0 0 0 0 0
52906 - 0 0 0 0 0 0 0 0 0 0 0 0
52907 - 0 0 0 0 0 0 0 0 0 0 0 0
52908 - 0 0 0 0 0 0 0 0 0 0 0 0
52909 - 0 0 0 0 0 0 0 0 0 0 0 0
52910 - 0 0 0 0 0 0 0 0 0 0 0 0
52911 - 0 0 0 0 0 0 0 0 0 0 0 0
52912 - 0 0 0 0 0 0 0 0 0 0 0 0
52913 - 0 0 0 0 0 0 0 0 0 0 0 0
52914 - 0 0 0 0 0 0 0 0 0 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 10 10 10
52918 - 38 38 38 86 86 86 50 50 50 6 6 6
52919 -128 128 128 174 154 114 156 107 11 168 122 10
52920 -198 155 10 184 144 12 197 138 11 200 144 11
52921 -206 145 10 206 145 10 197 138 11 188 164 115
52922 -195 195 195 198 198 198 174 174 174 14 14 14
52923 - 2 2 6 22 22 22 116 116 116 116 116 116
52924 - 22 22 22 2 2 6 74 74 74 70 70 70
52925 - 30 30 30 10 10 10 0 0 0 0 0 0
52926 - 0 0 0 0 0 0 0 0 0 0 0 0
52927 - 0 0 0 0 0 0 0 0 0 0 0 0
52928 - 0 0 0 0 0 0 0 0 0 0 0 0
52929 - 0 0 0 0 0 0 0 0 0 0 0 0
52930 - 0 0 0 0 0 0 0 0 0 0 0 0
52931 - 0 0 0 0 0 0 0 0 0 0 0 0
52932 - 0 0 0 0 0 0 0 0 0 0 0 0
52933 - 0 0 0 0 0 0 0 0 0 0 0 0
52934 - 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 6 6 6 18 18 18
52938 - 50 50 50 101 101 101 26 26 26 10 10 10
52939 -138 138 138 190 190 190 174 154 114 156 107 11
52940 -197 138 11 200 144 11 197 138 11 192 133 9
52941 -180 123 7 190 142 34 190 178 144 187 187 187
52942 -202 202 202 221 221 221 214 214 214 66 66 66
52943 - 2 2 6 2 2 6 50 50 50 62 62 62
52944 - 6 6 6 2 2 6 10 10 10 90 90 90
52945 - 50 50 50 18 18 18 6 6 6 0 0 0
52946 - 0 0 0 0 0 0 0 0 0 0 0 0
52947 - 0 0 0 0 0 0 0 0 0 0 0 0
52948 - 0 0 0 0 0 0 0 0 0 0 0 0
52949 - 0 0 0 0 0 0 0 0 0 0 0 0
52950 - 0 0 0 0 0 0 0 0 0 0 0 0
52951 - 0 0 0 0 0 0 0 0 0 0 0 0
52952 - 0 0 0 0 0 0 0 0 0 0 0 0
52953 - 0 0 0 0 0 0 0 0 0 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 10 10 10 34 34 34
52958 - 74 74 74 74 74 74 2 2 6 6 6 6
52959 -144 144 144 198 198 198 190 190 190 178 166 146
52960 -154 121 60 156 107 11 156 107 11 168 124 44
52961 -174 154 114 187 187 187 190 190 190 210 210 210
52962 -246 246 246 253 253 253 253 253 253 182 182 182
52963 - 6 6 6 2 2 6 2 2 6 2 2 6
52964 - 2 2 6 2 2 6 2 2 6 62 62 62
52965 - 74 74 74 34 34 34 14 14 14 0 0 0
52966 - 0 0 0 0 0 0 0 0 0 0 0 0
52967 - 0 0 0 0 0 0 0 0 0 0 0 0
52968 - 0 0 0 0 0 0 0 0 0 0 0 0
52969 - 0 0 0 0 0 0 0 0 0 0 0 0
52970 - 0 0 0 0 0 0 0 0 0 0 0 0
52971 - 0 0 0 0 0 0 0 0 0 0 0 0
52972 - 0 0 0 0 0 0 0 0 0 0 0 0
52973 - 0 0 0 0 0 0 0 0 0 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 10 10 10 22 22 22 54 54 54
52978 - 94 94 94 18 18 18 2 2 6 46 46 46
52979 -234 234 234 221 221 221 190 190 190 190 190 190
52980 -190 190 190 187 187 187 187 187 187 190 190 190
52981 -190 190 190 195 195 195 214 214 214 242 242 242
52982 -253 253 253 253 253 253 253 253 253 253 253 253
52983 - 82 82 82 2 2 6 2 2 6 2 2 6
52984 - 2 2 6 2 2 6 2 2 6 14 14 14
52985 - 86 86 86 54 54 54 22 22 22 6 6 6
52986 - 0 0 0 0 0 0 0 0 0 0 0 0
52987 - 0 0 0 0 0 0 0 0 0 0 0 0
52988 - 0 0 0 0 0 0 0 0 0 0 0 0
52989 - 0 0 0 0 0 0 0 0 0 0 0 0
52990 - 0 0 0 0 0 0 0 0 0 0 0 0
52991 - 0 0 0 0 0 0 0 0 0 0 0 0
52992 - 0 0 0 0 0 0 0 0 0 0 0 0
52993 - 0 0 0 0 0 0 0 0 0 0 0 0
52994 - 0 0 0 0 0 0 0 0 0 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 - 6 6 6 18 18 18 46 46 46 90 90 90
52998 - 46 46 46 18 18 18 6 6 6 182 182 182
52999 -253 253 253 246 246 246 206 206 206 190 190 190
53000 -190 190 190 190 190 190 190 190 190 190 190 190
53001 -206 206 206 231 231 231 250 250 250 253 253 253
53002 -253 253 253 253 253 253 253 253 253 253 253 253
53003 -202 202 202 14 14 14 2 2 6 2 2 6
53004 - 2 2 6 2 2 6 2 2 6 2 2 6
53005 - 42 42 42 86 86 86 42 42 42 18 18 18
53006 - 6 6 6 0 0 0 0 0 0 0 0 0
53007 - 0 0 0 0 0 0 0 0 0 0 0 0
53008 - 0 0 0 0 0 0 0 0 0 0 0 0
53009 - 0 0 0 0 0 0 0 0 0 0 0 0
53010 - 0 0 0 0 0 0 0 0 0 0 0 0
53011 - 0 0 0 0 0 0 0 0 0 0 0 0
53012 - 0 0 0 0 0 0 0 0 0 0 0 0
53013 - 0 0 0 0 0 0 0 0 0 0 0 0
53014 - 0 0 0 0 0 0 0 0 0 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 6 6 6
53017 - 14 14 14 38 38 38 74 74 74 66 66 66
53018 - 2 2 6 6 6 6 90 90 90 250 250 250
53019 -253 253 253 253 253 253 238 238 238 198 198 198
53020 -190 190 190 190 190 190 195 195 195 221 221 221
53021 -246 246 246 253 253 253 253 253 253 253 253 253
53022 -253 253 253 253 253 253 253 253 253 253 253 253
53023 -253 253 253 82 82 82 2 2 6 2 2 6
53024 - 2 2 6 2 2 6 2 2 6 2 2 6
53025 - 2 2 6 78 78 78 70 70 70 34 34 34
53026 - 14 14 14 6 6 6 0 0 0 0 0 0
53027 - 0 0 0 0 0 0 0 0 0 0 0 0
53028 - 0 0 0 0 0 0 0 0 0 0 0 0
53029 - 0 0 0 0 0 0 0 0 0 0 0 0
53030 - 0 0 0 0 0 0 0 0 0 0 0 0
53031 - 0 0 0 0 0 0 0 0 0 0 0 0
53032 - 0 0 0 0 0 0 0 0 0 0 0 0
53033 - 0 0 0 0 0 0 0 0 0 0 0 0
53034 - 0 0 0 0 0 0 0 0 0 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 14 14 14
53037 - 34 34 34 66 66 66 78 78 78 6 6 6
53038 - 2 2 6 18 18 18 218 218 218 253 253 253
53039 -253 253 253 253 253 253 253 253 253 246 246 246
53040 -226 226 226 231 231 231 246 246 246 253 253 253
53041 -253 253 253 253 253 253 253 253 253 253 253 253
53042 -253 253 253 253 253 253 253 253 253 253 253 253
53043 -253 253 253 178 178 178 2 2 6 2 2 6
53044 - 2 2 6 2 2 6 2 2 6 2 2 6
53045 - 2 2 6 18 18 18 90 90 90 62 62 62
53046 - 30 30 30 10 10 10 0 0 0 0 0 0
53047 - 0 0 0 0 0 0 0 0 0 0 0 0
53048 - 0 0 0 0 0 0 0 0 0 0 0 0
53049 - 0 0 0 0 0 0 0 0 0 0 0 0
53050 - 0 0 0 0 0 0 0 0 0 0 0 0
53051 - 0 0 0 0 0 0 0 0 0 0 0 0
53052 - 0 0 0 0 0 0 0 0 0 0 0 0
53053 - 0 0 0 0 0 0 0 0 0 0 0 0
53054 - 0 0 0 0 0 0 0 0 0 0 0 0
53055 - 0 0 0 0 0 0 0 0 0 0 0 0
53056 - 0 0 0 0 0 0 10 10 10 26 26 26
53057 - 58 58 58 90 90 90 18 18 18 2 2 6
53058 - 2 2 6 110 110 110 253 253 253 253 253 253
53059 -253 253 253 253 253 253 253 253 253 253 253 253
53060 -250 250 250 253 253 253 253 253 253 253 253 253
53061 -253 253 253 253 253 253 253 253 253 253 253 253
53062 -253 253 253 253 253 253 253 253 253 253 253 253
53063 -253 253 253 231 231 231 18 18 18 2 2 6
53064 - 2 2 6 2 2 6 2 2 6 2 2 6
53065 - 2 2 6 2 2 6 18 18 18 94 94 94
53066 - 54 54 54 26 26 26 10 10 10 0 0 0
53067 - 0 0 0 0 0 0 0 0 0 0 0 0
53068 - 0 0 0 0 0 0 0 0 0 0 0 0
53069 - 0 0 0 0 0 0 0 0 0 0 0 0
53070 - 0 0 0 0 0 0 0 0 0 0 0 0
53071 - 0 0 0 0 0 0 0 0 0 0 0 0
53072 - 0 0 0 0 0 0 0 0 0 0 0 0
53073 - 0 0 0 0 0 0 0 0 0 0 0 0
53074 - 0 0 0 0 0 0 0 0 0 0 0 0
53075 - 0 0 0 0 0 0 0 0 0 0 0 0
53076 - 0 0 0 6 6 6 22 22 22 50 50 50
53077 - 90 90 90 26 26 26 2 2 6 2 2 6
53078 - 14 14 14 195 195 195 250 250 250 253 253 253
53079 -253 253 253 253 253 253 253 253 253 253 253 253
53080 -253 253 253 253 253 253 253 253 253 253 253 253
53081 -253 253 253 253 253 253 253 253 253 253 253 253
53082 -253 253 253 253 253 253 253 253 253 253 253 253
53083 -250 250 250 242 242 242 54 54 54 2 2 6
53084 - 2 2 6 2 2 6 2 2 6 2 2 6
53085 - 2 2 6 2 2 6 2 2 6 38 38 38
53086 - 86 86 86 50 50 50 22 22 22 6 6 6
53087 - 0 0 0 0 0 0 0 0 0 0 0 0
53088 - 0 0 0 0 0 0 0 0 0 0 0 0
53089 - 0 0 0 0 0 0 0 0 0 0 0 0
53090 - 0 0 0 0 0 0 0 0 0 0 0 0
53091 - 0 0 0 0 0 0 0 0 0 0 0 0
53092 - 0 0 0 0 0 0 0 0 0 0 0 0
53093 - 0 0 0 0 0 0 0 0 0 0 0 0
53094 - 0 0 0 0 0 0 0 0 0 0 0 0
53095 - 0 0 0 0 0 0 0 0 0 0 0 0
53096 - 6 6 6 14 14 14 38 38 38 82 82 82
53097 - 34 34 34 2 2 6 2 2 6 2 2 6
53098 - 42 42 42 195 195 195 246 246 246 253 253 253
53099 -253 253 253 253 253 253 253 253 253 250 250 250
53100 -242 242 242 242 242 242 250 250 250 253 253 253
53101 -253 253 253 253 253 253 253 253 253 253 253 253
53102 -253 253 253 250 250 250 246 246 246 238 238 238
53103 -226 226 226 231 231 231 101 101 101 6 6 6
53104 - 2 2 6 2 2 6 2 2 6 2 2 6
53105 - 2 2 6 2 2 6 2 2 6 2 2 6
53106 - 38 38 38 82 82 82 42 42 42 14 14 14
53107 - 6 6 6 0 0 0 0 0 0 0 0 0
53108 - 0 0 0 0 0 0 0 0 0 0 0 0
53109 - 0 0 0 0 0 0 0 0 0 0 0 0
53110 - 0 0 0 0 0 0 0 0 0 0 0 0
53111 - 0 0 0 0 0 0 0 0 0 0 0 0
53112 - 0 0 0 0 0 0 0 0 0 0 0 0
53113 - 0 0 0 0 0 0 0 0 0 0 0 0
53114 - 0 0 0 0 0 0 0 0 0 0 0 0
53115 - 0 0 0 0 0 0 0 0 0 0 0 0
53116 - 10 10 10 26 26 26 62 62 62 66 66 66
53117 - 2 2 6 2 2 6 2 2 6 6 6 6
53118 - 70 70 70 170 170 170 206 206 206 234 234 234
53119 -246 246 246 250 250 250 250 250 250 238 238 238
53120 -226 226 226 231 231 231 238 238 238 250 250 250
53121 -250 250 250 250 250 250 246 246 246 231 231 231
53122 -214 214 214 206 206 206 202 202 202 202 202 202
53123 -198 198 198 202 202 202 182 182 182 18 18 18
53124 - 2 2 6 2 2 6 2 2 6 2 2 6
53125 - 2 2 6 2 2 6 2 2 6 2 2 6
53126 - 2 2 6 62 62 62 66 66 66 30 30 30
53127 - 10 10 10 0 0 0 0 0 0 0 0 0
53128 - 0 0 0 0 0 0 0 0 0 0 0 0
53129 - 0 0 0 0 0 0 0 0 0 0 0 0
53130 - 0 0 0 0 0 0 0 0 0 0 0 0
53131 - 0 0 0 0 0 0 0 0 0 0 0 0
53132 - 0 0 0 0 0 0 0 0 0 0 0 0
53133 - 0 0 0 0 0 0 0 0 0 0 0 0
53134 - 0 0 0 0 0 0 0 0 0 0 0 0
53135 - 0 0 0 0 0 0 0 0 0 0 0 0
53136 - 14 14 14 42 42 42 82 82 82 18 18 18
53137 - 2 2 6 2 2 6 2 2 6 10 10 10
53138 - 94 94 94 182 182 182 218 218 218 242 242 242
53139 -250 250 250 253 253 253 253 253 253 250 250 250
53140 -234 234 234 253 253 253 253 253 253 253 253 253
53141 -253 253 253 253 253 253 253 253 253 246 246 246
53142 -238 238 238 226 226 226 210 210 210 202 202 202
53143 -195 195 195 195 195 195 210 210 210 158 158 158
53144 - 6 6 6 14 14 14 50 50 50 14 14 14
53145 - 2 2 6 2 2 6 2 2 6 2 2 6
53146 - 2 2 6 6 6 6 86 86 86 46 46 46
53147 - 18 18 18 6 6 6 0 0 0 0 0 0
53148 - 0 0 0 0 0 0 0 0 0 0 0 0
53149 - 0 0 0 0 0 0 0 0 0 0 0 0
53150 - 0 0 0 0 0 0 0 0 0 0 0 0
53151 - 0 0 0 0 0 0 0 0 0 0 0 0
53152 - 0 0 0 0 0 0 0 0 0 0 0 0
53153 - 0 0 0 0 0 0 0 0 0 0 0 0
53154 - 0 0 0 0 0 0 0 0 0 0 0 0
53155 - 0 0 0 0 0 0 0 0 0 6 6 6
53156 - 22 22 22 54 54 54 70 70 70 2 2 6
53157 - 2 2 6 10 10 10 2 2 6 22 22 22
53158 -166 166 166 231 231 231 250 250 250 253 253 253
53159 -253 253 253 253 253 253 253 253 253 250 250 250
53160 -242 242 242 253 253 253 253 253 253 253 253 253
53161 -253 253 253 253 253 253 253 253 253 253 253 253
53162 -253 253 253 253 253 253 253 253 253 246 246 246
53163 -231 231 231 206 206 206 198 198 198 226 226 226
53164 - 94 94 94 2 2 6 6 6 6 38 38 38
53165 - 30 30 30 2 2 6 2 2 6 2 2 6
53166 - 2 2 6 2 2 6 62 62 62 66 66 66
53167 - 26 26 26 10 10 10 0 0 0 0 0 0
53168 - 0 0 0 0 0 0 0 0 0 0 0 0
53169 - 0 0 0 0 0 0 0 0 0 0 0 0
53170 - 0 0 0 0 0 0 0 0 0 0 0 0
53171 - 0 0 0 0 0 0 0 0 0 0 0 0
53172 - 0 0 0 0 0 0 0 0 0 0 0 0
53173 - 0 0 0 0 0 0 0 0 0 0 0 0
53174 - 0 0 0 0 0 0 0 0 0 0 0 0
53175 - 0 0 0 0 0 0 0 0 0 10 10 10
53176 - 30 30 30 74 74 74 50 50 50 2 2 6
53177 - 26 26 26 26 26 26 2 2 6 106 106 106
53178 -238 238 238 253 253 253 253 253 253 253 253 253
53179 -253 253 253 253 253 253 253 253 253 253 253 253
53180 -253 253 253 253 253 253 253 253 253 253 253 253
53181 -253 253 253 253 253 253 253 253 253 253 253 253
53182 -253 253 253 253 253 253 253 253 253 253 253 253
53183 -253 253 253 246 246 246 218 218 218 202 202 202
53184 -210 210 210 14 14 14 2 2 6 2 2 6
53185 - 30 30 30 22 22 22 2 2 6 2 2 6
53186 - 2 2 6 2 2 6 18 18 18 86 86 86
53187 - 42 42 42 14 14 14 0 0 0 0 0 0
53188 - 0 0 0 0 0 0 0 0 0 0 0 0
53189 - 0 0 0 0 0 0 0 0 0 0 0 0
53190 - 0 0 0 0 0 0 0 0 0 0 0 0
53191 - 0 0 0 0 0 0 0 0 0 0 0 0
53192 - 0 0 0 0 0 0 0 0 0 0 0 0
53193 - 0 0 0 0 0 0 0 0 0 0 0 0
53194 - 0 0 0 0 0 0 0 0 0 0 0 0
53195 - 0 0 0 0 0 0 0 0 0 14 14 14
53196 - 42 42 42 90 90 90 22 22 22 2 2 6
53197 - 42 42 42 2 2 6 18 18 18 218 218 218
53198 -253 253 253 253 253 253 253 253 253 253 253 253
53199 -253 253 253 253 253 253 253 253 253 253 253 253
53200 -253 253 253 253 253 253 253 253 253 253 253 253
53201 -253 253 253 253 253 253 253 253 253 253 253 253
53202 -253 253 253 253 253 253 253 253 253 253 253 253
53203 -253 253 253 253 253 253 250 250 250 221 221 221
53204 -218 218 218 101 101 101 2 2 6 14 14 14
53205 - 18 18 18 38 38 38 10 10 10 2 2 6
53206 - 2 2 6 2 2 6 2 2 6 78 78 78
53207 - 58 58 58 22 22 22 6 6 6 0 0 0
53208 - 0 0 0 0 0 0 0 0 0 0 0 0
53209 - 0 0 0 0 0 0 0 0 0 0 0 0
53210 - 0 0 0 0 0 0 0 0 0 0 0 0
53211 - 0 0 0 0 0 0 0 0 0 0 0 0
53212 - 0 0 0 0 0 0 0 0 0 0 0 0
53213 - 0 0 0 0 0 0 0 0 0 0 0 0
53214 - 0 0 0 0 0 0 0 0 0 0 0 0
53215 - 0 0 0 0 0 0 6 6 6 18 18 18
53216 - 54 54 54 82 82 82 2 2 6 26 26 26
53217 - 22 22 22 2 2 6 123 123 123 253 253 253
53218 -253 253 253 253 253 253 253 253 253 253 253 253
53219 -253 253 253 253 253 253 253 253 253 253 253 253
53220 -253 253 253 253 253 253 253 253 253 253 253 253
53221 -253 253 253 253 253 253 253 253 253 253 253 253
53222 -253 253 253 253 253 253 253 253 253 253 253 253
53223 -253 253 253 253 253 253 253 253 253 250 250 250
53224 -238 238 238 198 198 198 6 6 6 38 38 38
53225 - 58 58 58 26 26 26 38 38 38 2 2 6
53226 - 2 2 6 2 2 6 2 2 6 46 46 46
53227 - 78 78 78 30 30 30 10 10 10 0 0 0
53228 - 0 0 0 0 0 0 0 0 0 0 0 0
53229 - 0 0 0 0 0 0 0 0 0 0 0 0
53230 - 0 0 0 0 0 0 0 0 0 0 0 0
53231 - 0 0 0 0 0 0 0 0 0 0 0 0
53232 - 0 0 0 0 0 0 0 0 0 0 0 0
53233 - 0 0 0 0 0 0 0 0 0 0 0 0
53234 - 0 0 0 0 0 0 0 0 0 0 0 0
53235 - 0 0 0 0 0 0 10 10 10 30 30 30
53236 - 74 74 74 58 58 58 2 2 6 42 42 42
53237 - 2 2 6 22 22 22 231 231 231 253 253 253
53238 -253 253 253 253 253 253 253 253 253 253 253 253
53239 -253 253 253 253 253 253 253 253 253 250 250 250
53240 -253 253 253 253 253 253 253 253 253 253 253 253
53241 -253 253 253 253 253 253 253 253 253 253 253 253
53242 -253 253 253 253 253 253 253 253 253 253 253 253
53243 -253 253 253 253 253 253 253 253 253 253 253 253
53244 -253 253 253 246 246 246 46 46 46 38 38 38
53245 - 42 42 42 14 14 14 38 38 38 14 14 14
53246 - 2 2 6 2 2 6 2 2 6 6 6 6
53247 - 86 86 86 46 46 46 14 14 14 0 0 0
53248 - 0 0 0 0 0 0 0 0 0 0 0 0
53249 - 0 0 0 0 0 0 0 0 0 0 0 0
53250 - 0 0 0 0 0 0 0 0 0 0 0 0
53251 - 0 0 0 0 0 0 0 0 0 0 0 0
53252 - 0 0 0 0 0 0 0 0 0 0 0 0
53253 - 0 0 0 0 0 0 0 0 0 0 0 0
53254 - 0 0 0 0 0 0 0 0 0 0 0 0
53255 - 0 0 0 6 6 6 14 14 14 42 42 42
53256 - 90 90 90 18 18 18 18 18 18 26 26 26
53257 - 2 2 6 116 116 116 253 253 253 253 253 253
53258 -253 253 253 253 253 253 253 253 253 253 253 253
53259 -253 253 253 253 253 253 250 250 250 238 238 238
53260 -253 253 253 253 253 253 253 253 253 253 253 253
53261 -253 253 253 253 253 253 253 253 253 253 253 253
53262 -253 253 253 253 253 253 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 94 94 94 6 6 6
53265 - 2 2 6 2 2 6 10 10 10 34 34 34
53266 - 2 2 6 2 2 6 2 2 6 2 2 6
53267 - 74 74 74 58 58 58 22 22 22 6 6 6
53268 - 0 0 0 0 0 0 0 0 0 0 0 0
53269 - 0 0 0 0 0 0 0 0 0 0 0 0
53270 - 0 0 0 0 0 0 0 0 0 0 0 0
53271 - 0 0 0 0 0 0 0 0 0 0 0 0
53272 - 0 0 0 0 0 0 0 0 0 0 0 0
53273 - 0 0 0 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 10 10 10 26 26 26 66 66 66
53276 - 82 82 82 2 2 6 38 38 38 6 6 6
53277 - 14 14 14 210 210 210 253 253 253 253 253 253
53278 -253 253 253 253 253 253 253 253 253 253 253 253
53279 -253 253 253 253 253 253 246 246 246 242 242 242
53280 -253 253 253 253 253 253 253 253 253 253 253 253
53281 -253 253 253 253 253 253 253 253 253 253 253 253
53282 -253 253 253 253 253 253 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 144 144 144 2 2 6
53285 - 2 2 6 2 2 6 2 2 6 46 46 46
53286 - 2 2 6 2 2 6 2 2 6 2 2 6
53287 - 42 42 42 74 74 74 30 30 30 10 10 10
53288 - 0 0 0 0 0 0 0 0 0 0 0 0
53289 - 0 0 0 0 0 0 0 0 0 0 0 0
53290 - 0 0 0 0 0 0 0 0 0 0 0 0
53291 - 0 0 0 0 0 0 0 0 0 0 0 0
53292 - 0 0 0 0 0 0 0 0 0 0 0 0
53293 - 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 - 6 6 6 14 14 14 42 42 42 90 90 90
53296 - 26 26 26 6 6 6 42 42 42 2 2 6
53297 - 74 74 74 250 250 250 253 253 253 253 253 253
53298 -253 253 253 253 253 253 253 253 253 253 253 253
53299 -253 253 253 253 253 253 242 242 242 242 242 242
53300 -253 253 253 253 253 253 253 253 253 253 253 253
53301 -253 253 253 253 253 253 253 253 253 253 253 253
53302 -253 253 253 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 182 182 182 2 2 6
53305 - 2 2 6 2 2 6 2 2 6 46 46 46
53306 - 2 2 6 2 2 6 2 2 6 2 2 6
53307 - 10 10 10 86 86 86 38 38 38 10 10 10
53308 - 0 0 0 0 0 0 0 0 0 0 0 0
53309 - 0 0 0 0 0 0 0 0 0 0 0 0
53310 - 0 0 0 0 0 0 0 0 0 0 0 0
53311 - 0 0 0 0 0 0 0 0 0 0 0 0
53312 - 0 0 0 0 0 0 0 0 0 0 0 0
53313 - 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 - 10 10 10 26 26 26 66 66 66 82 82 82
53316 - 2 2 6 22 22 22 18 18 18 2 2 6
53317 -149 149 149 253 253 253 253 253 253 253 253 253
53318 -253 253 253 253 253 253 253 253 253 253 253 253
53319 -253 253 253 253 253 253 234 234 234 242 242 242
53320 -253 253 253 253 253 253 253 253 253 253 253 253
53321 -253 253 253 253 253 253 253 253 253 253 253 253
53322 -253 253 253 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 206 206 206 2 2 6
53325 - 2 2 6 2 2 6 2 2 6 38 38 38
53326 - 2 2 6 2 2 6 2 2 6 2 2 6
53327 - 6 6 6 86 86 86 46 46 46 14 14 14
53328 - 0 0 0 0 0 0 0 0 0 0 0 0
53329 - 0 0 0 0 0 0 0 0 0 0 0 0
53330 - 0 0 0 0 0 0 0 0 0 0 0 0
53331 - 0 0 0 0 0 0 0 0 0 0 0 0
53332 - 0 0 0 0 0 0 0 0 0 0 0 0
53333 - 0 0 0 0 0 0 0 0 0 0 0 0
53334 - 0 0 0 0 0 0 0 0 0 6 6 6
53335 - 18 18 18 46 46 46 86 86 86 18 18 18
53336 - 2 2 6 34 34 34 10 10 10 6 6 6
53337 -210 210 210 253 253 253 253 253 253 253 253 253
53338 -253 253 253 253 253 253 253 253 253 253 253 253
53339 -253 253 253 253 253 253 234 234 234 242 242 242
53340 -253 253 253 253 253 253 253 253 253 253 253 253
53341 -253 253 253 253 253 253 253 253 253 253 253 253
53342 -253 253 253 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 221 221 221 6 6 6
53345 - 2 2 6 2 2 6 6 6 6 30 30 30
53346 - 2 2 6 2 2 6 2 2 6 2 2 6
53347 - 2 2 6 82 82 82 54 54 54 18 18 18
53348 - 6 6 6 0 0 0 0 0 0 0 0 0
53349 - 0 0 0 0 0 0 0 0 0 0 0 0
53350 - 0 0 0 0 0 0 0 0 0 0 0 0
53351 - 0 0 0 0 0 0 0 0 0 0 0 0
53352 - 0 0 0 0 0 0 0 0 0 0 0 0
53353 - 0 0 0 0 0 0 0 0 0 0 0 0
53354 - 0 0 0 0 0 0 0 0 0 10 10 10
53355 - 26 26 26 66 66 66 62 62 62 2 2 6
53356 - 2 2 6 38 38 38 10 10 10 26 26 26
53357 -238 238 238 253 253 253 253 253 253 253 253 253
53358 -253 253 253 253 253 253 253 253 253 253 253 253
53359 -253 253 253 253 253 253 231 231 231 238 238 238
53360 -253 253 253 253 253 253 253 253 253 253 253 253
53361 -253 253 253 253 253 253 253 253 253 253 253 253
53362 -253 253 253 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 6 6 6
53365 - 2 2 6 2 2 6 10 10 10 30 30 30
53366 - 2 2 6 2 2 6 2 2 6 2 2 6
53367 - 2 2 6 66 66 66 58 58 58 22 22 22
53368 - 6 6 6 0 0 0 0 0 0 0 0 0
53369 - 0 0 0 0 0 0 0 0 0 0 0 0
53370 - 0 0 0 0 0 0 0 0 0 0 0 0
53371 - 0 0 0 0 0 0 0 0 0 0 0 0
53372 - 0 0 0 0 0 0 0 0 0 0 0 0
53373 - 0 0 0 0 0 0 0 0 0 0 0 0
53374 - 0 0 0 0 0 0 0 0 0 10 10 10
53375 - 38 38 38 78 78 78 6 6 6 2 2 6
53376 - 2 2 6 46 46 46 14 14 14 42 42 42
53377 -246 246 246 253 253 253 253 253 253 253 253 253
53378 -253 253 253 253 253 253 253 253 253 253 253 253
53379 -253 253 253 253 253 253 231 231 231 242 242 242
53380 -253 253 253 253 253 253 253 253 253 253 253 253
53381 -253 253 253 253 253 253 253 253 253 253 253 253
53382 -253 253 253 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 234 234 234 10 10 10
53385 - 2 2 6 2 2 6 22 22 22 14 14 14
53386 - 2 2 6 2 2 6 2 2 6 2 2 6
53387 - 2 2 6 66 66 66 62 62 62 22 22 22
53388 - 6 6 6 0 0 0 0 0 0 0 0 0
53389 - 0 0 0 0 0 0 0 0 0 0 0 0
53390 - 0 0 0 0 0 0 0 0 0 0 0 0
53391 - 0 0 0 0 0 0 0 0 0 0 0 0
53392 - 0 0 0 0 0 0 0 0 0 0 0 0
53393 - 0 0 0 0 0 0 0 0 0 0 0 0
53394 - 0 0 0 0 0 0 6 6 6 18 18 18
53395 - 50 50 50 74 74 74 2 2 6 2 2 6
53396 - 14 14 14 70 70 70 34 34 34 62 62 62
53397 -250 250 250 253 253 253 253 253 253 253 253 253
53398 -253 253 253 253 253 253 253 253 253 253 253 253
53399 -253 253 253 253 253 253 231 231 231 246 246 246
53400 -253 253 253 253 253 253 253 253 253 253 253 253
53401 -253 253 253 253 253 253 253 253 253 253 253 253
53402 -253 253 253 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 234 234 234 14 14 14
53405 - 2 2 6 2 2 6 30 30 30 2 2 6
53406 - 2 2 6 2 2 6 2 2 6 2 2 6
53407 - 2 2 6 66 66 66 62 62 62 22 22 22
53408 - 6 6 6 0 0 0 0 0 0 0 0 0
53409 - 0 0 0 0 0 0 0 0 0 0 0 0
53410 - 0 0 0 0 0 0 0 0 0 0 0 0
53411 - 0 0 0 0 0 0 0 0 0 0 0 0
53412 - 0 0 0 0 0 0 0 0 0 0 0 0
53413 - 0 0 0 0 0 0 0 0 0 0 0 0
53414 - 0 0 0 0 0 0 6 6 6 18 18 18
53415 - 54 54 54 62 62 62 2 2 6 2 2 6
53416 - 2 2 6 30 30 30 46 46 46 70 70 70
53417 -250 250 250 253 253 253 253 253 253 253 253 253
53418 -253 253 253 253 253 253 253 253 253 253 253 253
53419 -253 253 253 253 253 253 231 231 231 246 246 246
53420 -253 253 253 253 253 253 253 253 253 253 253 253
53421 -253 253 253 253 253 253 253 253 253 253 253 253
53422 -253 253 253 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 226 226 226 10 10 10
53425 - 2 2 6 6 6 6 30 30 30 2 2 6
53426 - 2 2 6 2 2 6 2 2 6 2 2 6
53427 - 2 2 6 66 66 66 58 58 58 22 22 22
53428 - 6 6 6 0 0 0 0 0 0 0 0 0
53429 - 0 0 0 0 0 0 0 0 0 0 0 0
53430 - 0 0 0 0 0 0 0 0 0 0 0 0
53431 - 0 0 0 0 0 0 0 0 0 0 0 0
53432 - 0 0 0 0 0 0 0 0 0 0 0 0
53433 - 0 0 0 0 0 0 0 0 0 0 0 0
53434 - 0 0 0 0 0 0 6 6 6 22 22 22
53435 - 58 58 58 62 62 62 2 2 6 2 2 6
53436 - 2 2 6 2 2 6 30 30 30 78 78 78
53437 -250 250 250 253 253 253 253 253 253 253 253 253
53438 -253 253 253 253 253 253 253 253 253 253 253 253
53439 -253 253 253 253 253 253 231 231 231 246 246 246
53440 -253 253 253 253 253 253 253 253 253 253 253 253
53441 -253 253 253 253 253 253 253 253 253 253 253 253
53442 -253 253 253 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 206 206 206 2 2 6
53445 - 22 22 22 34 34 34 18 14 6 22 22 22
53446 - 26 26 26 18 18 18 6 6 6 2 2 6
53447 - 2 2 6 82 82 82 54 54 54 18 18 18
53448 - 6 6 6 0 0 0 0 0 0 0 0 0
53449 - 0 0 0 0 0 0 0 0 0 0 0 0
53450 - 0 0 0 0 0 0 0 0 0 0 0 0
53451 - 0 0 0 0 0 0 0 0 0 0 0 0
53452 - 0 0 0 0 0 0 0 0 0 0 0 0
53453 - 0 0 0 0 0 0 0 0 0 0 0 0
53454 - 0 0 0 0 0 0 6 6 6 26 26 26
53455 - 62 62 62 106 106 106 74 54 14 185 133 11
53456 -210 162 10 121 92 8 6 6 6 62 62 62
53457 -238 238 238 253 253 253 253 253 253 253 253 253
53458 -253 253 253 253 253 253 253 253 253 253 253 253
53459 -253 253 253 253 253 253 231 231 231 246 246 246
53460 -253 253 253 253 253 253 253 253 253 253 253 253
53461 -253 253 253 253 253 253 253 253 253 253 253 253
53462 -253 253 253 253 253 253 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 158 158 158 18 18 18
53465 - 14 14 14 2 2 6 2 2 6 2 2 6
53466 - 6 6 6 18 18 18 66 66 66 38 38 38
53467 - 6 6 6 94 94 94 50 50 50 18 18 18
53468 - 6 6 6 0 0 0 0 0 0 0 0 0
53469 - 0 0 0 0 0 0 0 0 0 0 0 0
53470 - 0 0 0 0 0 0 0 0 0 0 0 0
53471 - 0 0 0 0 0 0 0 0 0 0 0 0
53472 - 0 0 0 0 0 0 0 0 0 0 0 0
53473 - 0 0 0 0 0 0 0 0 0 6 6 6
53474 - 10 10 10 10 10 10 18 18 18 38 38 38
53475 - 78 78 78 142 134 106 216 158 10 242 186 14
53476 -246 190 14 246 190 14 156 118 10 10 10 10
53477 - 90 90 90 238 238 238 253 253 253 253 253 253
53478 -253 253 253 253 253 253 253 253 253 253 253 253
53479 -253 253 253 253 253 253 231 231 231 250 250 250
53480 -253 253 253 253 253 253 253 253 253 253 253 253
53481 -253 253 253 253 253 253 253 253 253 253 253 253
53482 -253 253 253 253 253 253 253 253 253 253 253 253
53483 -253 253 253 253 253 253 253 253 253 246 230 190
53484 -238 204 91 238 204 91 181 142 44 37 26 9
53485 - 2 2 6 2 2 6 2 2 6 2 2 6
53486 - 2 2 6 2 2 6 38 38 38 46 46 46
53487 - 26 26 26 106 106 106 54 54 54 18 18 18
53488 - 6 6 6 0 0 0 0 0 0 0 0 0
53489 - 0 0 0 0 0 0 0 0 0 0 0 0
53490 - 0 0 0 0 0 0 0 0 0 0 0 0
53491 - 0 0 0 0 0 0 0 0 0 0 0 0
53492 - 0 0 0 0 0 0 0 0 0 0 0 0
53493 - 0 0 0 6 6 6 14 14 14 22 22 22
53494 - 30 30 30 38 38 38 50 50 50 70 70 70
53495 -106 106 106 190 142 34 226 170 11 242 186 14
53496 -246 190 14 246 190 14 246 190 14 154 114 10
53497 - 6 6 6 74 74 74 226 226 226 253 253 253
53498 -253 253 253 253 253 253 253 253 253 253 253 253
53499 -253 253 253 253 253 253 231 231 231 250 250 250
53500 -253 253 253 253 253 253 253 253 253 253 253 253
53501 -253 253 253 253 253 253 253 253 253 253 253 253
53502 -253 253 253 253 253 253 253 253 253 253 253 253
53503 -253 253 253 253 253 253 253 253 253 228 184 62
53504 -241 196 14 241 208 19 232 195 16 38 30 10
53505 - 2 2 6 2 2 6 2 2 6 2 2 6
53506 - 2 2 6 6 6 6 30 30 30 26 26 26
53507 -203 166 17 154 142 90 66 66 66 26 26 26
53508 - 6 6 6 0 0 0 0 0 0 0 0 0
53509 - 0 0 0 0 0 0 0 0 0 0 0 0
53510 - 0 0 0 0 0 0 0 0 0 0 0 0
53511 - 0 0 0 0 0 0 0 0 0 0 0 0
53512 - 0 0 0 0 0 0 0 0 0 0 0 0
53513 - 6 6 6 18 18 18 38 38 38 58 58 58
53514 - 78 78 78 86 86 86 101 101 101 123 123 123
53515 -175 146 61 210 150 10 234 174 13 246 186 14
53516 -246 190 14 246 190 14 246 190 14 238 190 10
53517 -102 78 10 2 2 6 46 46 46 198 198 198
53518 -253 253 253 253 253 253 253 253 253 253 253 253
53519 -253 253 253 253 253 253 234 234 234 242 242 242
53520 -253 253 253 253 253 253 253 253 253 253 253 253
53521 -253 253 253 253 253 253 253 253 253 253 253 253
53522 -253 253 253 253 253 253 253 253 253 253 253 253
53523 -253 253 253 253 253 253 253 253 253 224 178 62
53524 -242 186 14 241 196 14 210 166 10 22 18 6
53525 - 2 2 6 2 2 6 2 2 6 2 2 6
53526 - 2 2 6 2 2 6 6 6 6 121 92 8
53527 -238 202 15 232 195 16 82 82 82 34 34 34
53528 - 10 10 10 0 0 0 0 0 0 0 0 0
53529 - 0 0 0 0 0 0 0 0 0 0 0 0
53530 - 0 0 0 0 0 0 0 0 0 0 0 0
53531 - 0 0 0 0 0 0 0 0 0 0 0 0
53532 - 0 0 0 0 0 0 0 0 0 0 0 0
53533 - 14 14 14 38 38 38 70 70 70 154 122 46
53534 -190 142 34 200 144 11 197 138 11 197 138 11
53535 -213 154 11 226 170 11 242 186 14 246 190 14
53536 -246 190 14 246 190 14 246 190 14 246 190 14
53537 -225 175 15 46 32 6 2 2 6 22 22 22
53538 -158 158 158 250 250 250 253 253 253 253 253 253
53539 -253 253 253 253 253 253 253 253 253 253 253 253
53540 -253 253 253 253 253 253 253 253 253 253 253 253
53541 -253 253 253 253 253 253 253 253 253 253 253 253
53542 -253 253 253 253 253 253 253 253 253 253 253 253
53543 -253 253 253 250 250 250 242 242 242 224 178 62
53544 -239 182 13 236 186 11 213 154 11 46 32 6
53545 - 2 2 6 2 2 6 2 2 6 2 2 6
53546 - 2 2 6 2 2 6 61 42 6 225 175 15
53547 -238 190 10 236 186 11 112 100 78 42 42 42
53548 - 14 14 14 0 0 0 0 0 0 0 0 0
53549 - 0 0 0 0 0 0 0 0 0 0 0 0
53550 - 0 0 0 0 0 0 0 0 0 0 0 0
53551 - 0 0 0 0 0 0 0 0 0 0 0 0
53552 - 0 0 0 0 0 0 0 0 0 6 6 6
53553 - 22 22 22 54 54 54 154 122 46 213 154 11
53554 -226 170 11 230 174 11 226 170 11 226 170 11
53555 -236 178 12 242 186 14 246 190 14 246 190 14
53556 -246 190 14 246 190 14 246 190 14 246 190 14
53557 -241 196 14 184 144 12 10 10 10 2 2 6
53558 - 6 6 6 116 116 116 242 242 242 253 253 253
53559 -253 253 253 253 253 253 253 253 253 253 253 253
53560 -253 253 253 253 253 253 253 253 253 253 253 253
53561 -253 253 253 253 253 253 253 253 253 253 253 253
53562 -253 253 253 253 253 253 253 253 253 253 253 253
53563 -253 253 253 231 231 231 198 198 198 214 170 54
53564 -236 178 12 236 178 12 210 150 10 137 92 6
53565 - 18 14 6 2 2 6 2 2 6 2 2 6
53566 - 6 6 6 70 47 6 200 144 11 236 178 12
53567 -239 182 13 239 182 13 124 112 88 58 58 58
53568 - 22 22 22 6 6 6 0 0 0 0 0 0
53569 - 0 0 0 0 0 0 0 0 0 0 0 0
53570 - 0 0 0 0 0 0 0 0 0 0 0 0
53571 - 0 0 0 0 0 0 0 0 0 0 0 0
53572 - 0 0 0 0 0 0 0 0 0 10 10 10
53573 - 30 30 30 70 70 70 180 133 36 226 170 11
53574 -239 182 13 242 186 14 242 186 14 246 186 14
53575 -246 190 14 246 190 14 246 190 14 246 190 14
53576 -246 190 14 246 190 14 246 190 14 246 190 14
53577 -246 190 14 232 195 16 98 70 6 2 2 6
53578 - 2 2 6 2 2 6 66 66 66 221 221 221
53579 -253 253 253 253 253 253 253 253 253 253 253 253
53580 -253 253 253 253 253 253 253 253 253 253 253 253
53581 -253 253 253 253 253 253 253 253 253 253 253 253
53582 -253 253 253 253 253 253 253 253 253 253 253 253
53583 -253 253 253 206 206 206 198 198 198 214 166 58
53584 -230 174 11 230 174 11 216 158 10 192 133 9
53585 -163 110 8 116 81 8 102 78 10 116 81 8
53586 -167 114 7 197 138 11 226 170 11 239 182 13
53587 -242 186 14 242 186 14 162 146 94 78 78 78
53588 - 34 34 34 14 14 14 6 6 6 0 0 0
53589 - 0 0 0 0 0 0 0 0 0 0 0 0
53590 - 0 0 0 0 0 0 0 0 0 0 0 0
53591 - 0 0 0 0 0 0 0 0 0 0 0 0
53592 - 0 0 0 0 0 0 0 0 0 6 6 6
53593 - 30 30 30 78 78 78 190 142 34 226 170 11
53594 -239 182 13 246 190 14 246 190 14 246 190 14
53595 -246 190 14 246 190 14 246 190 14 246 190 14
53596 -246 190 14 246 190 14 246 190 14 246 190 14
53597 -246 190 14 241 196 14 203 166 17 22 18 6
53598 - 2 2 6 2 2 6 2 2 6 38 38 38
53599 -218 218 218 253 253 253 253 253 253 253 253 253
53600 -253 253 253 253 253 253 253 253 253 253 253 253
53601 -253 253 253 253 253 253 253 253 253 253 253 253
53602 -253 253 253 253 253 253 253 253 253 253 253 253
53603 -250 250 250 206 206 206 198 198 198 202 162 69
53604 -226 170 11 236 178 12 224 166 10 210 150 10
53605 -200 144 11 197 138 11 192 133 9 197 138 11
53606 -210 150 10 226 170 11 242 186 14 246 190 14
53607 -246 190 14 246 186 14 225 175 15 124 112 88
53608 - 62 62 62 30 30 30 14 14 14 6 6 6
53609 - 0 0 0 0 0 0 0 0 0 0 0 0
53610 - 0 0 0 0 0 0 0 0 0 0 0 0
53611 - 0 0 0 0 0 0 0 0 0 0 0 0
53612 - 0 0 0 0 0 0 0 0 0 10 10 10
53613 - 30 30 30 78 78 78 174 135 50 224 166 10
53614 -239 182 13 246 190 14 246 190 14 246 190 14
53615 -246 190 14 246 190 14 246 190 14 246 190 14
53616 -246 190 14 246 190 14 246 190 14 246 190 14
53617 -246 190 14 246 190 14 241 196 14 139 102 15
53618 - 2 2 6 2 2 6 2 2 6 2 2 6
53619 - 78 78 78 250 250 250 253 253 253 253 253 253
53620 -253 253 253 253 253 253 253 253 253 253 253 253
53621 -253 253 253 253 253 253 253 253 253 253 253 253
53622 -253 253 253 253 253 253 253 253 253 253 253 253
53623 -250 250 250 214 214 214 198 198 198 190 150 46
53624 -219 162 10 236 178 12 234 174 13 224 166 10
53625 -216 158 10 213 154 11 213 154 11 216 158 10
53626 -226 170 11 239 182 13 246 190 14 246 190 14
53627 -246 190 14 246 190 14 242 186 14 206 162 42
53628 -101 101 101 58 58 58 30 30 30 14 14 14
53629 - 6 6 6 0 0 0 0 0 0 0 0 0
53630 - 0 0 0 0 0 0 0 0 0 0 0 0
53631 - 0 0 0 0 0 0 0 0 0 0 0 0
53632 - 0 0 0 0 0 0 0 0 0 10 10 10
53633 - 30 30 30 74 74 74 174 135 50 216 158 10
53634 -236 178 12 246 190 14 246 190 14 246 190 14
53635 -246 190 14 246 190 14 246 190 14 246 190 14
53636 -246 190 14 246 190 14 246 190 14 246 190 14
53637 -246 190 14 246 190 14 241 196 14 226 184 13
53638 - 61 42 6 2 2 6 2 2 6 2 2 6
53639 - 22 22 22 238 238 238 253 253 253 253 253 253
53640 -253 253 253 253 253 253 253 253 253 253 253 253
53641 -253 253 253 253 253 253 253 253 253 253 253 253
53642 -253 253 253 253 253 253 253 253 253 253 253 253
53643 -253 253 253 226 226 226 187 187 187 180 133 36
53644 -216 158 10 236 178 12 239 182 13 236 178 12
53645 -230 174 11 226 170 11 226 170 11 230 174 11
53646 -236 178 12 242 186 14 246 190 14 246 190 14
53647 -246 190 14 246 190 14 246 186 14 239 182 13
53648 -206 162 42 106 106 106 66 66 66 34 34 34
53649 - 14 14 14 6 6 6 0 0 0 0 0 0
53650 - 0 0 0 0 0 0 0 0 0 0 0 0
53651 - 0 0 0 0 0 0 0 0 0 0 0 0
53652 - 0 0 0 0 0 0 0 0 0 6 6 6
53653 - 26 26 26 70 70 70 163 133 67 213 154 11
53654 -236 178 12 246 190 14 246 190 14 246 190 14
53655 -246 190 14 246 190 14 246 190 14 246 190 14
53656 -246 190 14 246 190 14 246 190 14 246 190 14
53657 -246 190 14 246 190 14 246 190 14 241 196 14
53658 -190 146 13 18 14 6 2 2 6 2 2 6
53659 - 46 46 46 246 246 246 253 253 253 253 253 253
53660 -253 253 253 253 253 253 253 253 253 253 253 253
53661 -253 253 253 253 253 253 253 253 253 253 253 253
53662 -253 253 253 253 253 253 253 253 253 253 253 253
53663 -253 253 253 221 221 221 86 86 86 156 107 11
53664 -216 158 10 236 178 12 242 186 14 246 186 14
53665 -242 186 14 239 182 13 239 182 13 242 186 14
53666 -242 186 14 246 186 14 246 190 14 246 190 14
53667 -246 190 14 246 190 14 246 190 14 246 190 14
53668 -242 186 14 225 175 15 142 122 72 66 66 66
53669 - 30 30 30 10 10 10 0 0 0 0 0 0
53670 - 0 0 0 0 0 0 0 0 0 0 0 0
53671 - 0 0 0 0 0 0 0 0 0 0 0 0
53672 - 0 0 0 0 0 0 0 0 0 6 6 6
53673 - 26 26 26 70 70 70 163 133 67 210 150 10
53674 -236 178 12 246 190 14 246 190 14 246 190 14
53675 -246 190 14 246 190 14 246 190 14 246 190 14
53676 -246 190 14 246 190 14 246 190 14 246 190 14
53677 -246 190 14 246 190 14 246 190 14 246 190 14
53678 -232 195 16 121 92 8 34 34 34 106 106 106
53679 -221 221 221 253 253 253 253 253 253 253 253 253
53680 -253 253 253 253 253 253 253 253 253 253 253 253
53681 -253 253 253 253 253 253 253 253 253 253 253 253
53682 -253 253 253 253 253 253 253 253 253 253 253 253
53683 -242 242 242 82 82 82 18 14 6 163 110 8
53684 -216 158 10 236 178 12 242 186 14 246 190 14
53685 -246 190 14 246 190 14 246 190 14 246 190 14
53686 -246 190 14 246 190 14 246 190 14 246 190 14
53687 -246 190 14 246 190 14 246 190 14 246 190 14
53688 -246 190 14 246 190 14 242 186 14 163 133 67
53689 - 46 46 46 18 18 18 6 6 6 0 0 0
53690 - 0 0 0 0 0 0 0 0 0 0 0 0
53691 - 0 0 0 0 0 0 0 0 0 0 0 0
53692 - 0 0 0 0 0 0 0 0 0 10 10 10
53693 - 30 30 30 78 78 78 163 133 67 210 150 10
53694 -236 178 12 246 186 14 246 190 14 246 190 14
53695 -246 190 14 246 190 14 246 190 14 246 190 14
53696 -246 190 14 246 190 14 246 190 14 246 190 14
53697 -246 190 14 246 190 14 246 190 14 246 190 14
53698 -241 196 14 215 174 15 190 178 144 253 253 253
53699 -253 253 253 253 253 253 253 253 253 253 253 253
53700 -253 253 253 253 253 253 253 253 253 253 253 253
53701 -253 253 253 253 253 253 253 253 253 253 253 253
53702 -253 253 253 253 253 253 253 253 253 218 218 218
53703 - 58 58 58 2 2 6 22 18 6 167 114 7
53704 -216 158 10 236 178 12 246 186 14 246 190 14
53705 -246 190 14 246 190 14 246 190 14 246 190 14
53706 -246 190 14 246 190 14 246 190 14 246 190 14
53707 -246 190 14 246 190 14 246 190 14 246 190 14
53708 -246 190 14 246 186 14 242 186 14 190 150 46
53709 - 54 54 54 22 22 22 6 6 6 0 0 0
53710 - 0 0 0 0 0 0 0 0 0 0 0 0
53711 - 0 0 0 0 0 0 0 0 0 0 0 0
53712 - 0 0 0 0 0 0 0 0 0 14 14 14
53713 - 38 38 38 86 86 86 180 133 36 213 154 11
53714 -236 178 12 246 186 14 246 190 14 246 190 14
53715 -246 190 14 246 190 14 246 190 14 246 190 14
53716 -246 190 14 246 190 14 246 190 14 246 190 14
53717 -246 190 14 246 190 14 246 190 14 246 190 14
53718 -246 190 14 232 195 16 190 146 13 214 214 214
53719 -253 253 253 253 253 253 253 253 253 253 253 253
53720 -253 253 253 253 253 253 253 253 253 253 253 253
53721 -253 253 253 253 253 253 253 253 253 253 253 253
53722 -253 253 253 250 250 250 170 170 170 26 26 26
53723 - 2 2 6 2 2 6 37 26 9 163 110 8
53724 -219 162 10 239 182 13 246 186 14 246 190 14
53725 -246 190 14 246 190 14 246 190 14 246 190 14
53726 -246 190 14 246 190 14 246 190 14 246 190 14
53727 -246 190 14 246 190 14 246 190 14 246 190 14
53728 -246 186 14 236 178 12 224 166 10 142 122 72
53729 - 46 46 46 18 18 18 6 6 6 0 0 0
53730 - 0 0 0 0 0 0 0 0 0 0 0 0
53731 - 0 0 0 0 0 0 0 0 0 0 0 0
53732 - 0 0 0 0 0 0 6 6 6 18 18 18
53733 - 50 50 50 109 106 95 192 133 9 224 166 10
53734 -242 186 14 246 190 14 246 190 14 246 190 14
53735 -246 190 14 246 190 14 246 190 14 246 190 14
53736 -246 190 14 246 190 14 246 190 14 246 190 14
53737 -246 190 14 246 190 14 246 190 14 246 190 14
53738 -242 186 14 226 184 13 210 162 10 142 110 46
53739 -226 226 226 253 253 253 253 253 253 253 253 253
53740 -253 253 253 253 253 253 253 253 253 253 253 253
53741 -253 253 253 253 253 253 253 253 253 253 253 253
53742 -198 198 198 66 66 66 2 2 6 2 2 6
53743 - 2 2 6 2 2 6 50 34 6 156 107 11
53744 -219 162 10 239 182 13 246 186 14 246 190 14
53745 -246 190 14 246 190 14 246 190 14 246 190 14
53746 -246 190 14 246 190 14 246 190 14 246 190 14
53747 -246 190 14 246 190 14 246 190 14 242 186 14
53748 -234 174 13 213 154 11 154 122 46 66 66 66
53749 - 30 30 30 10 10 10 0 0 0 0 0 0
53750 - 0 0 0 0 0 0 0 0 0 0 0 0
53751 - 0 0 0 0 0 0 0 0 0 0 0 0
53752 - 0 0 0 0 0 0 6 6 6 22 22 22
53753 - 58 58 58 154 121 60 206 145 10 234 174 13
53754 -242 186 14 246 186 14 246 190 14 246 190 14
53755 -246 190 14 246 190 14 246 190 14 246 190 14
53756 -246 190 14 246 190 14 246 190 14 246 190 14
53757 -246 190 14 246 190 14 246 190 14 246 190 14
53758 -246 186 14 236 178 12 210 162 10 163 110 8
53759 - 61 42 6 138 138 138 218 218 218 250 250 250
53760 -253 253 253 253 253 253 253 253 253 250 250 250
53761 -242 242 242 210 210 210 144 144 144 66 66 66
53762 - 6 6 6 2 2 6 2 2 6 2 2 6
53763 - 2 2 6 2 2 6 61 42 6 163 110 8
53764 -216 158 10 236 178 12 246 190 14 246 190 14
53765 -246 190 14 246 190 14 246 190 14 246 190 14
53766 -246 190 14 246 190 14 246 190 14 246 190 14
53767 -246 190 14 239 182 13 230 174 11 216 158 10
53768 -190 142 34 124 112 88 70 70 70 38 38 38
53769 - 18 18 18 6 6 6 0 0 0 0 0 0
53770 - 0 0 0 0 0 0 0 0 0 0 0 0
53771 - 0 0 0 0 0 0 0 0 0 0 0 0
53772 - 0 0 0 0 0 0 6 6 6 22 22 22
53773 - 62 62 62 168 124 44 206 145 10 224 166 10
53774 -236 178 12 239 182 13 242 186 14 242 186 14
53775 -246 186 14 246 190 14 246 190 14 246 190 14
53776 -246 190 14 246 190 14 246 190 14 246 190 14
53777 -246 190 14 246 190 14 246 190 14 246 190 14
53778 -246 190 14 236 178 12 216 158 10 175 118 6
53779 - 80 54 7 2 2 6 6 6 6 30 30 30
53780 - 54 54 54 62 62 62 50 50 50 38 38 38
53781 - 14 14 14 2 2 6 2 2 6 2 2 6
53782 - 2 2 6 2 2 6 2 2 6 2 2 6
53783 - 2 2 6 6 6 6 80 54 7 167 114 7
53784 -213 154 11 236 178 12 246 190 14 246 190 14
53785 -246 190 14 246 190 14 246 190 14 246 190 14
53786 -246 190 14 242 186 14 239 182 13 239 182 13
53787 -230 174 11 210 150 10 174 135 50 124 112 88
53788 - 82 82 82 54 54 54 34 34 34 18 18 18
53789 - 6 6 6 0 0 0 0 0 0 0 0 0
53790 - 0 0 0 0 0 0 0 0 0 0 0 0
53791 - 0 0 0 0 0 0 0 0 0 0 0 0
53792 - 0 0 0 0 0 0 6 6 6 18 18 18
53793 - 50 50 50 158 118 36 192 133 9 200 144 11
53794 -216 158 10 219 162 10 224 166 10 226 170 11
53795 -230 174 11 236 178 12 239 182 13 239 182 13
53796 -242 186 14 246 186 14 246 190 14 246 190 14
53797 -246 190 14 246 190 14 246 190 14 246 190 14
53798 -246 186 14 230 174 11 210 150 10 163 110 8
53799 -104 69 6 10 10 10 2 2 6 2 2 6
53800 - 2 2 6 2 2 6 2 2 6 2 2 6
53801 - 2 2 6 2 2 6 2 2 6 2 2 6
53802 - 2 2 6 2 2 6 2 2 6 2 2 6
53803 - 2 2 6 6 6 6 91 60 6 167 114 7
53804 -206 145 10 230 174 11 242 186 14 246 190 14
53805 -246 190 14 246 190 14 246 186 14 242 186 14
53806 -239 182 13 230 174 11 224 166 10 213 154 11
53807 -180 133 36 124 112 88 86 86 86 58 58 58
53808 - 38 38 38 22 22 22 10 10 10 6 6 6
53809 - 0 0 0 0 0 0 0 0 0 0 0 0
53810 - 0 0 0 0 0 0 0 0 0 0 0 0
53811 - 0 0 0 0 0 0 0 0 0 0 0 0
53812 - 0 0 0 0 0 0 0 0 0 14 14 14
53813 - 34 34 34 70 70 70 138 110 50 158 118 36
53814 -167 114 7 180 123 7 192 133 9 197 138 11
53815 -200 144 11 206 145 10 213 154 11 219 162 10
53816 -224 166 10 230 174 11 239 182 13 242 186 14
53817 -246 186 14 246 186 14 246 186 14 246 186 14
53818 -239 182 13 216 158 10 185 133 11 152 99 6
53819 -104 69 6 18 14 6 2 2 6 2 2 6
53820 - 2 2 6 2 2 6 2 2 6 2 2 6
53821 - 2 2 6 2 2 6 2 2 6 2 2 6
53822 - 2 2 6 2 2 6 2 2 6 2 2 6
53823 - 2 2 6 6 6 6 80 54 7 152 99 6
53824 -192 133 9 219 162 10 236 178 12 239 182 13
53825 -246 186 14 242 186 14 239 182 13 236 178 12
53826 -224 166 10 206 145 10 192 133 9 154 121 60
53827 - 94 94 94 62 62 62 42 42 42 22 22 22
53828 - 14 14 14 6 6 6 0 0 0 0 0 0
53829 - 0 0 0 0 0 0 0 0 0 0 0 0
53830 - 0 0 0 0 0 0 0 0 0 0 0 0
53831 - 0 0 0 0 0 0 0 0 0 0 0 0
53832 - 0 0 0 0 0 0 0 0 0 6 6 6
53833 - 18 18 18 34 34 34 58 58 58 78 78 78
53834 -101 98 89 124 112 88 142 110 46 156 107 11
53835 -163 110 8 167 114 7 175 118 6 180 123 7
53836 -185 133 11 197 138 11 210 150 10 219 162 10
53837 -226 170 11 236 178 12 236 178 12 234 174 13
53838 -219 162 10 197 138 11 163 110 8 130 83 6
53839 - 91 60 6 10 10 10 2 2 6 2 2 6
53840 - 18 18 18 38 38 38 38 38 38 38 38 38
53841 - 38 38 38 38 38 38 38 38 38 38 38 38
53842 - 38 38 38 38 38 38 26 26 26 2 2 6
53843 - 2 2 6 6 6 6 70 47 6 137 92 6
53844 -175 118 6 200 144 11 219 162 10 230 174 11
53845 -234 174 13 230 174 11 219 162 10 210 150 10
53846 -192 133 9 163 110 8 124 112 88 82 82 82
53847 - 50 50 50 30 30 30 14 14 14 6 6 6
53848 - 0 0 0 0 0 0 0 0 0 0 0 0
53849 - 0 0 0 0 0 0 0 0 0 0 0 0
53850 - 0 0 0 0 0 0 0 0 0 0 0 0
53851 - 0 0 0 0 0 0 0 0 0 0 0 0
53852 - 0 0 0 0 0 0 0 0 0 0 0 0
53853 - 6 6 6 14 14 14 22 22 22 34 34 34
53854 - 42 42 42 58 58 58 74 74 74 86 86 86
53855 -101 98 89 122 102 70 130 98 46 121 87 25
53856 -137 92 6 152 99 6 163 110 8 180 123 7
53857 -185 133 11 197 138 11 206 145 10 200 144 11
53858 -180 123 7 156 107 11 130 83 6 104 69 6
53859 - 50 34 6 54 54 54 110 110 110 101 98 89
53860 - 86 86 86 82 82 82 78 78 78 78 78 78
53861 - 78 78 78 78 78 78 78 78 78 78 78 78
53862 - 78 78 78 82 82 82 86 86 86 94 94 94
53863 -106 106 106 101 101 101 86 66 34 124 80 6
53864 -156 107 11 180 123 7 192 133 9 200 144 11
53865 -206 145 10 200 144 11 192 133 9 175 118 6
53866 -139 102 15 109 106 95 70 70 70 42 42 42
53867 - 22 22 22 10 10 10 0 0 0 0 0 0
53868 - 0 0 0 0 0 0 0 0 0 0 0 0
53869 - 0 0 0 0 0 0 0 0 0 0 0 0
53870 - 0 0 0 0 0 0 0 0 0 0 0 0
53871 - 0 0 0 0 0 0 0 0 0 0 0 0
53872 - 0 0 0 0 0 0 0 0 0 0 0 0
53873 - 0 0 0 0 0 0 6 6 6 10 10 10
53874 - 14 14 14 22 22 22 30 30 30 38 38 38
53875 - 50 50 50 62 62 62 74 74 74 90 90 90
53876 -101 98 89 112 100 78 121 87 25 124 80 6
53877 -137 92 6 152 99 6 152 99 6 152 99 6
53878 -138 86 6 124 80 6 98 70 6 86 66 30
53879 -101 98 89 82 82 82 58 58 58 46 46 46
53880 - 38 38 38 34 34 34 34 34 34 34 34 34
53881 - 34 34 34 34 34 34 34 34 34 34 34 34
53882 - 34 34 34 34 34 34 38 38 38 42 42 42
53883 - 54 54 54 82 82 82 94 86 76 91 60 6
53884 -134 86 6 156 107 11 167 114 7 175 118 6
53885 -175 118 6 167 114 7 152 99 6 121 87 25
53886 -101 98 89 62 62 62 34 34 34 18 18 18
53887 - 6 6 6 0 0 0 0 0 0 0 0 0
53888 - 0 0 0 0 0 0 0 0 0 0 0 0
53889 - 0 0 0 0 0 0 0 0 0 0 0 0
53890 - 0 0 0 0 0 0 0 0 0 0 0 0
53891 - 0 0 0 0 0 0 0 0 0 0 0 0
53892 - 0 0 0 0 0 0 0 0 0 0 0 0
53893 - 0 0 0 0 0 0 0 0 0 0 0 0
53894 - 0 0 0 6 6 6 6 6 6 10 10 10
53895 - 18 18 18 22 22 22 30 30 30 42 42 42
53896 - 50 50 50 66 66 66 86 86 86 101 98 89
53897 -106 86 58 98 70 6 104 69 6 104 69 6
53898 -104 69 6 91 60 6 82 62 34 90 90 90
53899 - 62 62 62 38 38 38 22 22 22 14 14 14
53900 - 10 10 10 10 10 10 10 10 10 10 10 10
53901 - 10 10 10 10 10 10 6 6 6 10 10 10
53902 - 10 10 10 10 10 10 10 10 10 14 14 14
53903 - 22 22 22 42 42 42 70 70 70 89 81 66
53904 - 80 54 7 104 69 6 124 80 6 137 92 6
53905 -134 86 6 116 81 8 100 82 52 86 86 86
53906 - 58 58 58 30 30 30 14 14 14 6 6 6
53907 - 0 0 0 0 0 0 0 0 0 0 0 0
53908 - 0 0 0 0 0 0 0 0 0 0 0 0
53909 - 0 0 0 0 0 0 0 0 0 0 0 0
53910 - 0 0 0 0 0 0 0 0 0 0 0 0
53911 - 0 0 0 0 0 0 0 0 0 0 0 0
53912 - 0 0 0 0 0 0 0 0 0 0 0 0
53913 - 0 0 0 0 0 0 0 0 0 0 0 0
53914 - 0 0 0 0 0 0 0 0 0 0 0 0
53915 - 0 0 0 6 6 6 10 10 10 14 14 14
53916 - 18 18 18 26 26 26 38 38 38 54 54 54
53917 - 70 70 70 86 86 86 94 86 76 89 81 66
53918 - 89 81 66 86 86 86 74 74 74 50 50 50
53919 - 30 30 30 14 14 14 6 6 6 0 0 0
53920 - 0 0 0 0 0 0 0 0 0 0 0 0
53921 - 0 0 0 0 0 0 0 0 0 0 0 0
53922 - 0 0 0 0 0 0 0 0 0 0 0 0
53923 - 6 6 6 18 18 18 34 34 34 58 58 58
53924 - 82 82 82 89 81 66 89 81 66 89 81 66
53925 - 94 86 66 94 86 76 74 74 74 50 50 50
53926 - 26 26 26 14 14 14 6 6 6 0 0 0
53927 - 0 0 0 0 0 0 0 0 0 0 0 0
53928 - 0 0 0 0 0 0 0 0 0 0 0 0
53929 - 0 0 0 0 0 0 0 0 0 0 0 0
53930 - 0 0 0 0 0 0 0 0 0 0 0 0
53931 - 0 0 0 0 0 0 0 0 0 0 0 0
53932 - 0 0 0 0 0 0 0 0 0 0 0 0
53933 - 0 0 0 0 0 0 0 0 0 0 0 0
53934 - 0 0 0 0 0 0 0 0 0 0 0 0
53935 - 0 0 0 0 0 0 0 0 0 0 0 0
53936 - 6 6 6 6 6 6 14 14 14 18 18 18
53937 - 30 30 30 38 38 38 46 46 46 54 54 54
53938 - 50 50 50 42 42 42 30 30 30 18 18 18
53939 - 10 10 10 0 0 0 0 0 0 0 0 0
53940 - 0 0 0 0 0 0 0 0 0 0 0 0
53941 - 0 0 0 0 0 0 0 0 0 0 0 0
53942 - 0 0 0 0 0 0 0 0 0 0 0 0
53943 - 0 0 0 6 6 6 14 14 14 26 26 26
53944 - 38 38 38 50 50 50 58 58 58 58 58 58
53945 - 54 54 54 42 42 42 30 30 30 18 18 18
53946 - 10 10 10 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 0 0 0
53949 - 0 0 0 0 0 0 0 0 0 0 0 0
53950 - 0 0 0 0 0 0 0 0 0 0 0 0
53951 - 0 0 0 0 0 0 0 0 0 0 0 0
53952 - 0 0 0 0 0 0 0 0 0 0 0 0
53953 - 0 0 0 0 0 0 0 0 0 0 0 0
53954 - 0 0 0 0 0 0 0 0 0 0 0 0
53955 - 0 0 0 0 0 0 0 0 0 0 0 0
53956 - 0 0 0 0 0 0 0 0 0 6 6 6
53957 - 6 6 6 10 10 10 14 14 14 18 18 18
53958 - 18 18 18 14 14 14 10 10 10 6 6 6
53959 - 0 0 0 0 0 0 0 0 0 0 0 0
53960 - 0 0 0 0 0 0 0 0 0 0 0 0
53961 - 0 0 0 0 0 0 0 0 0 0 0 0
53962 - 0 0 0 0 0 0 0 0 0 0 0 0
53963 - 0 0 0 0 0 0 0 0 0 6 6 6
53964 - 14 14 14 18 18 18 22 22 22 22 22 22
53965 - 18 18 18 14 14 14 10 10 10 6 6 6
53966 - 0 0 0 0 0 0 0 0 0 0 0 0
53967 - 0 0 0 0 0 0 0 0 0 0 0 0
53968 - 0 0 0 0 0 0 0 0 0 0 0 0
53969 - 0 0 0 0 0 0 0 0 0 0 0 0
53970 - 0 0 0 0 0 0 0 0 0 0 0 0
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 4 4 4 4 4 4 4 4 4 4 4 4
53984 +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 4 4 4 4 4 4 4 4 4 4 4 4
53998 +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 4 4 4 4 4 4 4 4 4 4 4 4
54012 +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 4 4 4 4 4 4 4 4 4 4 4 4
54026 +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 4 4 4 4 4 4 4 4 4 4 4 4
54040 +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 4 4 4 4 4 4 4 4 4
54045 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 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 4 4 4 4 4 4
54050 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54051 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
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 4 4 4 4 4 4 4 4 4 4 4 4
54054 +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 4 4 4 4 4 4 4 4 4 4 4 4
54059 +4 4 4 4 4 4 4 4 4 3 3 3 0 0 0 0 0 0
54060 +0 0 0 0 0 0 0 0 0 0 0 0 3 3 3 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 4 4 4 4 4 4 4 4 4 4 4 4
54064 +4 4 4 4 4 4 4 4 4 4 4 4 1 1 1 0 0 0
54065 +0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
54066 +4 4 4 4 4 4 4 4 4 2 1 0 2 1 0 3 2 2
54067 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54068 +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 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54073 +4 4 4 4 4 4 2 2 2 0 0 0 3 4 3 26 28 28
54074 +37 38 37 37 38 37 14 17 19 2 2 2 0 0 0 2 2 2
54075 +5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
54078 +4 4 4 4 4 4 3 3 3 0 0 0 1 1 1 6 6 6
54079 +2 2 2 0 0 0 3 3 3 4 4 4 4 4 4 4 4 4
54080 +4 4 5 3 3 3 1 0 0 0 0 0 1 0 0 0 0 0
54081 +1 1 1 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54082 +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 4 4 4 4 4 4 4 4 4 4 4 4
54086 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54087 +2 2 2 0 0 0 0 0 0 14 17 19 60 74 84 137 136 137
54088 +153 152 153 137 136 137 125 124 125 60 73 81 6 6 6 3 1 0
54089 +0 0 0 3 3 3 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 4 4 4 4 4 4
54091 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54092 +4 4 4 4 4 4 0 0 0 4 4 4 41 54 63 125 124 125
54093 +60 73 81 6 6 6 4 0 0 3 3 3 4 4 4 4 4 4
54094 +4 4 4 0 0 0 6 9 11 41 54 63 41 65 82 22 30 35
54095 +2 2 2 2 1 0 4 4 4 4 4 4 4 4 4 4 4 4
54096 +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 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54100 +4 4 4 4 4 4 5 5 5 5 5 5 2 2 2 0 0 0
54101 +4 0 0 6 6 6 41 54 63 137 136 137 174 174 174 167 166 167
54102 +165 164 165 165 164 165 163 162 163 163 162 163 125 124 125 41 54 63
54103 +1 1 1 0 0 0 0 0 0 3 3 3 5 5 5 4 4 4
54104 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54105 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
54106 +3 3 3 2 0 0 4 0 0 60 73 81 156 155 156 167 166 167
54107 +163 162 163 85 115 134 5 7 8 0 0 0 4 4 4 5 5 5
54108 +0 0 0 2 5 5 55 98 126 90 154 193 90 154 193 72 125 159
54109 +37 51 59 2 0 0 1 1 1 4 5 5 4 4 4 4 4 4
54110 +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 4 4 4
54113 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54114 +4 4 4 5 5 5 4 4 4 1 1 1 0 0 0 3 3 3
54115 +37 38 37 125 124 125 163 162 163 174 174 174 158 157 158 158 157 158
54116 +156 155 156 156 155 156 158 157 158 165 164 165 174 174 174 166 165 166
54117 +125 124 125 16 19 21 1 0 0 0 0 0 0 0 0 4 4 4
54118 +5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
54119 +4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 1 1 1
54120 +0 0 0 0 0 0 37 38 37 153 152 153 174 174 174 158 157 158
54121 +174 174 174 163 162 163 37 38 37 4 3 3 4 0 0 1 1 1
54122 +0 0 0 22 40 52 101 161 196 101 161 196 90 154 193 101 161 196
54123 +64 123 161 14 17 19 0 0 0 4 4 4 4 4 4 4 4 4
54124 +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 4 4 4 4 4 4
54127 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
54128 +5 5 5 2 2 2 0 0 0 4 0 0 24 26 27 85 115 134
54129 +156 155 156 174 174 174 167 166 167 156 155 156 154 153 154 157 156 157
54130 +156 155 156 156 155 156 155 154 155 153 152 153 158 157 158 167 166 167
54131 +174 174 174 156 155 156 60 74 84 16 19 21 0 0 0 0 0 0
54132 +1 1 1 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
54133 +4 4 4 5 5 5 6 6 6 3 3 3 0 0 0 4 0 0
54134 +13 16 17 60 73 81 137 136 137 165 164 165 156 155 156 153 152 153
54135 +174 174 174 177 184 187 60 73 81 3 1 0 0 0 0 1 1 2
54136 +22 30 35 64 123 161 136 185 209 90 154 193 90 154 193 90 154 193
54137 +90 154 193 21 29 34 0 0 0 3 2 2 4 4 5 4 4 4
54138 +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 4 4 4 4 4 4 4 4 4
54141 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 3 3 3
54142 +0 0 0 0 0 0 10 13 16 60 74 84 157 156 157 174 174 174
54143 +174 174 174 158 157 158 153 152 153 154 153 154 156 155 156 155 154 155
54144 +156 155 156 155 154 155 154 153 154 157 156 157 154 153 154 153 152 153
54145 +163 162 163 174 174 174 177 184 187 137 136 137 60 73 81 13 16 17
54146 +4 0 0 0 0 0 3 3 3 5 5 5 4 4 4 4 4 4
54147 +5 5 5 4 4 4 1 1 1 0 0 0 3 3 3 41 54 63
54148 +131 129 131 174 174 174 174 174 174 174 174 174 167 166 167 174 174 174
54149 +190 197 201 137 136 137 24 26 27 4 0 0 16 21 25 50 82 103
54150 +90 154 193 136 185 209 90 154 193 101 161 196 101 161 196 101 161 196
54151 +31 91 132 3 6 7 0 0 0 4 4 4 4 4 4 4 4 4
54152 +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 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54155 +4 4 4 4 4 4 4 4 4 2 2 2 0 0 0 4 0 0
54156 +4 0 0 43 57 68 137 136 137 177 184 187 174 174 174 163 162 163
54157 +155 154 155 155 154 155 156 155 156 155 154 155 158 157 158 165 164 165
54158 +167 166 167 166 165 166 163 162 163 157 156 157 155 154 155 155 154 155
54159 +153 152 153 156 155 156 167 166 167 174 174 174 174 174 174 131 129 131
54160 +41 54 63 5 5 5 0 0 0 0 0 0 3 3 3 4 4 4
54161 +1 1 1 0 0 0 1 0 0 26 28 28 125 124 125 174 174 174
54162 +177 184 187 174 174 174 174 174 174 156 155 156 131 129 131 137 136 137
54163 +125 124 125 24 26 27 4 0 0 41 65 82 90 154 193 136 185 209
54164 +136 185 209 101 161 196 53 118 160 37 112 160 90 154 193 34 86 122
54165 +7 12 15 0 0 0 4 4 4 4 4 4 4 4 4 4 4 4
54166 +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 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54169 +4 4 4 3 3 3 0 0 0 0 0 0 5 5 5 37 38 37
54170 +125 124 125 167 166 167 174 174 174 167 166 167 158 157 158 155 154 155
54171 +156 155 156 156 155 156 156 155 156 163 162 163 167 166 167 155 154 155
54172 +137 136 137 153 152 153 156 155 156 165 164 165 163 162 163 156 155 156
54173 +156 155 156 156 155 156 155 154 155 158 157 158 166 165 166 174 174 174
54174 +167 166 167 125 124 125 37 38 37 1 0 0 0 0 0 0 0 0
54175 +0 0 0 24 26 27 60 74 84 158 157 158 174 174 174 174 174 174
54176 +166 165 166 158 157 158 125 124 125 41 54 63 13 16 17 6 6 6
54177 +6 6 6 37 38 37 80 127 157 136 185 209 101 161 196 101 161 196
54178 +90 154 193 28 67 93 6 10 14 13 20 25 13 20 25 6 10 14
54179 +1 1 2 4 3 3 4 4 4 4 4 4 4 4 4 4 4 4
54180 +4 4 4 4 4 4
54181 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54182 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54183 +1 1 1 1 0 0 4 3 3 37 38 37 60 74 84 153 152 153
54184 +167 166 167 167 166 167 158 157 158 154 153 154 155 154 155 156 155 156
54185 +157 156 157 158 157 158 167 166 167 167 166 167 131 129 131 43 57 68
54186 +26 28 28 37 38 37 60 73 81 131 129 131 165 164 165 166 165 166
54187 +158 157 158 155 154 155 156 155 156 156 155 156 156 155 156 158 157 158
54188 +165 164 165 174 174 174 163 162 163 60 74 84 16 19 21 13 16 17
54189 +60 73 81 131 129 131 174 174 174 174 174 174 167 166 167 165 164 165
54190 +137 136 137 60 73 81 24 26 27 4 0 0 4 0 0 16 19 21
54191 +52 104 138 101 161 196 136 185 209 136 185 209 90 154 193 27 99 146
54192 +13 20 25 4 5 7 2 5 5 4 5 7 1 1 2 0 0 0
54193 +4 4 4 4 4 4 3 3 3 2 2 2 2 2 2 4 4 4
54194 +4 4 4 4 4 4
54195 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54196 +4 4 4 4 4 4 4 4 4 4 4 4 3 3 3 0 0 0
54197 +0 0 0 13 16 17 60 73 81 137 136 137 174 174 174 166 165 166
54198 +158 157 158 156 155 156 157 156 157 156 155 156 155 154 155 158 157 158
54199 +167 166 167 174 174 174 153 152 153 60 73 81 16 19 21 4 0 0
54200 +4 0 0 4 0 0 6 6 6 26 28 28 60 74 84 158 157 158
54201 +174 174 174 166 165 166 157 156 157 155 154 155 156 155 156 156 155 156
54202 +155 154 155 158 157 158 167 166 167 167 166 167 131 129 131 125 124 125
54203 +137 136 137 167 166 167 167 166 167 174 174 174 158 157 158 125 124 125
54204 +16 19 21 4 0 0 4 0 0 10 13 16 49 76 92 107 159 188
54205 +136 185 209 136 185 209 90 154 193 26 108 161 22 40 52 6 10 14
54206 +2 3 3 1 1 2 1 1 2 4 4 5 4 4 5 4 4 5
54207 +4 4 5 2 2 1 0 0 0 0 0 0 0 0 0 2 2 2
54208 +4 4 4 4 4 4
54209 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54210 +4 4 4 5 5 5 3 3 3 0 0 0 1 0 0 4 0 0
54211 +37 51 59 131 129 131 167 166 167 167 166 167 163 162 163 157 156 157
54212 +157 156 157 155 154 155 153 152 153 157 156 157 167 166 167 174 174 174
54213 +153 152 153 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
54214 +4 3 3 4 3 3 4 0 0 6 6 6 4 0 0 37 38 37
54215 +125 124 125 174 174 174 174 174 174 165 164 165 156 155 156 154 153 154
54216 +156 155 156 156 155 156 155 154 155 163 162 163 158 157 158 163 162 163
54217 +174 174 174 174 174 174 174 174 174 125 124 125 37 38 37 0 0 0
54218 +4 0 0 6 9 11 41 54 63 90 154 193 136 185 209 146 190 211
54219 +136 185 209 37 112 160 22 40 52 6 10 14 3 6 7 1 1 2
54220 +1 1 2 3 3 3 1 1 2 3 3 3 4 4 4 4 4 4
54221 +2 2 2 2 0 0 16 19 21 37 38 37 24 26 27 0 0 0
54222 +0 0 0 4 4 4
54223 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
54224 +4 4 4 0 0 0 0 0 0 0 0 0 26 28 28 120 125 127
54225 +158 157 158 174 174 174 165 164 165 157 156 157 155 154 155 156 155 156
54226 +153 152 153 153 152 153 167 166 167 174 174 174 174 174 174 125 124 125
54227 +37 38 37 4 0 0 0 0 0 4 0 0 4 3 3 4 4 4
54228 +4 4 4 4 4 4 5 5 5 4 0 0 4 0 0 4 0 0
54229 +4 3 3 43 57 68 137 136 137 174 174 174 174 174 174 165 164 165
54230 +154 153 154 153 152 153 153 152 153 153 152 153 163 162 163 174 174 174
54231 +174 174 174 153 152 153 60 73 81 6 6 6 4 0 0 4 3 3
54232 +32 43 50 80 127 157 136 185 209 146 190 211 146 190 211 90 154 193
54233 +28 67 93 28 67 93 40 71 93 3 6 7 1 1 2 2 5 5
54234 +50 82 103 79 117 143 26 37 45 0 0 0 3 3 3 1 1 1
54235 +0 0 0 41 54 63 137 136 137 174 174 174 153 152 153 60 73 81
54236 +2 0 0 0 0 0
54237 +4 4 4 4 4 4 4 4 4 4 4 4 6 6 6 2 2 2
54238 +0 0 0 2 0 0 24 26 27 60 74 84 153 152 153 174 174 174
54239 +174 174 174 157 156 157 154 153 154 156 155 156 154 153 154 153 152 153
54240 +165 164 165 174 174 174 177 184 187 137 136 137 43 57 68 6 6 6
54241 +4 0 0 2 0 0 3 3 3 5 5 5 5 5 5 4 4 4
54242 +4 4 4 4 4 4 4 4 4 5 5 5 6 6 6 4 3 3
54243 +4 0 0 4 0 0 24 26 27 60 73 81 153 152 153 174 174 174
54244 +174 174 174 158 157 158 158 157 158 174 174 174 174 174 174 158 157 158
54245 +60 74 84 24 26 27 4 0 0 4 0 0 17 23 27 59 113 148
54246 +136 185 209 191 222 234 146 190 211 136 185 209 31 91 132 7 11 13
54247 +22 40 52 101 161 196 90 154 193 6 9 11 3 4 4 43 95 132
54248 +136 185 209 172 205 220 55 98 126 0 0 0 0 0 0 2 0 0
54249 +26 28 28 153 152 153 177 184 187 167 166 167 177 184 187 165 164 165
54250 +37 38 37 0 0 0
54251 +4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
54252 +13 16 17 60 73 81 137 136 137 174 174 174 174 174 174 165 164 165
54253 +153 152 153 153 152 153 155 154 155 154 153 154 158 157 158 174 174 174
54254 +177 184 187 163 162 163 60 73 81 16 19 21 4 0 0 4 0 0
54255 +4 3 3 4 4 4 5 5 5 5 5 5 4 4 4 5 5 5
54256 +5 5 5 5 5 5 5 5 5 4 4 4 4 4 4 5 5 5
54257 +6 6 6 4 0 0 4 0 0 4 0 0 24 26 27 60 74 84
54258 +166 165 166 174 174 174 177 184 187 165 164 165 125 124 125 24 26 27
54259 +4 0 0 4 0 0 5 5 5 50 82 103 136 185 209 172 205 220
54260 +146 190 211 136 185 209 26 108 161 22 40 52 7 12 15 44 81 103
54261 +71 116 144 28 67 93 37 51 59 41 65 82 100 139 164 101 161 196
54262 +90 154 193 90 154 193 28 67 93 0 0 0 0 0 0 26 28 28
54263 +125 124 125 167 166 167 163 162 163 153 152 153 163 162 163 174 174 174
54264 +85 115 134 4 0 0
54265 +4 4 4 5 5 5 4 4 4 1 0 0 4 0 0 34 47 55
54266 +125 124 125 174 174 174 174 174 174 167 166 167 157 156 157 153 152 153
54267 +155 154 155 155 154 155 158 157 158 166 165 166 167 166 167 154 153 154
54268 +125 124 125 26 28 28 4 0 0 4 0 0 4 0 0 5 5 5
54269 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 1 1 1
54270 +0 0 0 0 0 0 1 1 1 4 4 4 4 4 4 4 4 4
54271 +5 5 5 5 5 5 4 3 3 4 0 0 4 0 0 6 6 6
54272 +37 38 37 131 129 131 137 136 137 37 38 37 0 0 0 4 0 0
54273 +4 5 5 43 61 72 90 154 193 172 205 220 146 190 211 136 185 209
54274 +90 154 193 28 67 93 13 20 25 43 61 72 71 116 144 44 81 103
54275 +2 5 5 7 11 13 59 113 148 101 161 196 90 154 193 28 67 93
54276 +13 20 25 6 10 14 0 0 0 13 16 17 60 73 81 137 136 137
54277 +166 165 166 158 157 158 156 155 156 154 153 154 167 166 167 174 174 174
54278 +60 73 81 4 0 0
54279 +4 4 4 4 4 4 0 0 0 3 3 3 60 74 84 174 174 174
54280 +174 174 174 167 166 167 163 162 163 155 154 155 157 156 157 155 154 155
54281 +156 155 156 163 162 163 167 166 167 158 157 158 125 124 125 37 38 37
54282 +4 3 3 4 0 0 4 0 0 6 6 6 6 6 6 5 5 5
54283 +4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 2 3 3
54284 +10 13 16 7 11 13 1 0 0 0 0 0 2 2 1 4 4 4
54285 +4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 4 0 0
54286 +4 0 0 7 11 13 13 16 17 4 0 0 3 3 3 34 47 55
54287 +80 127 157 146 190 211 172 205 220 136 185 209 136 185 209 136 185 209
54288 +28 67 93 22 40 52 55 98 126 55 98 126 21 29 34 7 11 13
54289 +50 82 103 101 161 196 101 161 196 35 83 115 13 20 25 2 2 1
54290 +1 1 2 1 1 2 37 51 59 131 129 131 174 174 174 174 174 174
54291 +167 166 167 163 162 163 163 162 163 167 166 167 174 174 174 125 124 125
54292 +16 19 21 4 0 0
54293 +4 4 4 4 0 0 4 0 0 60 74 84 174 174 174 174 174 174
54294 +158 157 158 155 154 155 155 154 155 156 155 156 155 154 155 158 157 158
54295 +167 166 167 165 164 165 131 129 131 60 73 81 13 16 17 4 0 0
54296 +4 0 0 4 3 3 6 6 6 4 3 3 5 5 5 4 4 4
54297 +4 4 4 3 2 2 0 0 0 0 0 0 7 11 13 45 69 86
54298 +80 127 157 71 116 144 43 61 72 7 11 13 0 0 0 1 1 1
54299 +4 3 3 4 4 4 4 4 4 4 4 4 6 6 6 5 5 5
54300 +3 2 2 4 0 0 1 0 0 21 29 34 59 113 148 136 185 209
54301 +146 190 211 136 185 209 136 185 209 136 185 209 136 185 209 136 185 209
54302 +68 124 159 44 81 103 22 40 52 13 16 17 43 61 72 90 154 193
54303 +136 185 209 59 113 148 21 29 34 3 4 3 1 1 1 0 0 0
54304 +24 26 27 125 124 125 163 162 163 174 174 174 166 165 166 165 164 165
54305 +163 162 163 125 124 125 125 124 125 125 124 125 125 124 125 26 28 28
54306 +4 0 0 4 3 3
54307 +3 3 3 0 0 0 24 26 27 153 152 153 177 184 187 158 157 158
54308 +156 155 156 156 155 156 155 154 155 155 154 155 165 164 165 174 174 174
54309 +155 154 155 60 74 84 26 28 28 4 0 0 4 0 0 3 1 0
54310 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 3 3
54311 +2 0 0 0 0 0 0 0 0 32 43 50 72 125 159 101 161 196
54312 +136 185 209 101 161 196 101 161 196 79 117 143 32 43 50 0 0 0
54313 +0 0 0 2 2 2 4 4 4 4 4 4 3 3 3 1 0 0
54314 +0 0 0 4 5 5 49 76 92 101 161 196 146 190 211 146 190 211
54315 +136 185 209 136 185 209 136 185 209 136 185 209 136 185 209 90 154 193
54316 +28 67 93 13 16 17 37 51 59 80 127 157 136 185 209 90 154 193
54317 +22 40 52 6 9 11 3 4 3 2 2 1 16 19 21 60 73 81
54318 +137 136 137 163 162 163 158 157 158 166 165 166 167 166 167 153 152 153
54319 +60 74 84 37 38 37 6 6 6 13 16 17 4 0 0 1 0 0
54320 +3 2 2 4 4 4
54321 +3 2 2 4 0 0 37 38 37 137 136 137 167 166 167 158 157 158
54322 +157 156 157 154 153 154 157 156 157 167 166 167 174 174 174 125 124 125
54323 +37 38 37 4 0 0 4 0 0 4 0 0 4 3 3 4 4 4
54324 +4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
54325 +0 0 0 16 21 25 55 98 126 90 154 193 136 185 209 101 161 196
54326 +101 161 196 101 161 196 136 185 209 136 185 209 101 161 196 55 98 126
54327 +14 17 19 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
54328 +22 40 52 90 154 193 146 190 211 146 190 211 136 185 209 136 185 209
54329 +136 185 209 136 185 209 136 185 209 101 161 196 35 83 115 7 11 13
54330 +17 23 27 59 113 148 136 185 209 101 161 196 34 86 122 7 12 15
54331 +2 5 5 3 4 3 6 6 6 60 73 81 131 129 131 163 162 163
54332 +166 165 166 174 174 174 174 174 174 163 162 163 125 124 125 41 54 63
54333 +13 16 17 4 0 0 4 0 0 4 0 0 1 0 0 2 2 2
54334 +4 4 4 4 4 4
54335 +1 1 1 2 1 0 43 57 68 137 136 137 153 152 153 153 152 153
54336 +163 162 163 156 155 156 165 164 165 167 166 167 60 74 84 6 6 6
54337 +4 0 0 4 0 0 5 5 5 4 4 4 4 4 4 4 4 4
54338 +4 5 5 6 6 6 4 3 3 0 0 0 0 0 0 11 15 18
54339 +40 71 93 100 139 164 101 161 196 101 161 196 101 161 196 101 161 196
54340 +101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 136 185 209
54341 +101 161 196 45 69 86 6 6 6 0 0 0 17 23 27 55 98 126
54342 +136 185 209 146 190 211 136 185 209 136 185 209 136 185 209 136 185 209
54343 +136 185 209 136 185 209 90 154 193 22 40 52 7 11 13 50 82 103
54344 +136 185 209 136 185 209 53 118 160 22 40 52 7 11 13 2 5 5
54345 +3 4 3 37 38 37 125 124 125 157 156 157 166 165 166 167 166 167
54346 +174 174 174 174 174 174 137 136 137 60 73 81 4 0 0 4 0 0
54347 +4 0 0 4 0 0 5 5 5 3 3 3 3 3 3 4 4 4
54348 +4 4 4 4 4 4
54349 +4 0 0 4 0 0 41 54 63 137 136 137 125 124 125 131 129 131
54350 +155 154 155 167 166 167 174 174 174 60 74 84 6 6 6 4 0 0
54351 +4 3 3 6 6 6 4 4 4 4 4 4 4 4 4 5 5 5
54352 +4 4 4 1 1 1 0 0 0 3 6 7 41 65 82 72 125 159
54353 +101 161 196 101 161 196 101 161 196 90 154 193 90 154 193 101 161 196
54354 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
54355 +136 185 209 136 185 209 80 127 157 55 98 126 101 161 196 146 190 211
54356 +136 185 209 136 185 209 136 185 209 101 161 196 136 185 209 101 161 196
54357 +136 185 209 101 161 196 35 83 115 22 30 35 101 161 196 172 205 220
54358 +90 154 193 28 67 93 7 11 13 2 5 5 3 4 3 13 16 17
54359 +85 115 134 167 166 167 174 174 174 174 174 174 174 174 174 174 174 174
54360 +167 166 167 60 74 84 13 16 17 4 0 0 4 0 0 4 3 3
54361 +6 6 6 5 5 5 4 4 4 5 5 5 4 4 4 5 5 5
54362 +5 5 5 5 5 5
54363 +1 1 1 4 0 0 41 54 63 137 136 137 137 136 137 125 124 125
54364 +131 129 131 167 166 167 157 156 157 37 38 37 6 6 6 4 0 0
54365 +6 6 6 5 5 5 4 4 4 4 4 4 4 5 5 2 2 1
54366 +0 0 0 0 0 0 26 37 45 58 111 146 101 161 196 101 161 196
54367 +101 161 196 90 154 193 90 154 193 90 154 193 101 161 196 101 161 196
54368 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
54369 +101 161 196 136 185 209 136 185 209 136 185 209 146 190 211 136 185 209
54370 +136 185 209 101 161 196 136 185 209 136 185 209 101 161 196 136 185 209
54371 +101 161 196 136 185 209 136 185 209 136 185 209 136 185 209 16 89 141
54372 +7 11 13 2 5 5 2 5 5 13 16 17 60 73 81 154 154 154
54373 +174 174 174 174 174 174 174 174 174 174 174 174 163 162 163 125 124 125
54374 +24 26 27 4 0 0 4 0 0 4 0 0 5 5 5 5 5 5
54375 +4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
54376 +5 5 5 4 4 4
54377 +4 0 0 6 6 6 37 38 37 137 136 137 137 136 137 131 129 131
54378 +131 129 131 153 152 153 131 129 131 26 28 28 4 0 0 4 3 3
54379 +6 6 6 4 4 4 4 4 4 4 4 4 0 0 0 0 0 0
54380 +13 20 25 51 88 114 90 154 193 101 161 196 101 161 196 90 154 193
54381 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
54382 +101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 101 161 196
54383 +101 161 196 136 185 209 101 161 196 136 185 209 136 185 209 101 161 196
54384 +136 185 209 101 161 196 136 185 209 101 161 196 101 161 196 101 161 196
54385 +136 185 209 136 185 209 136 185 209 37 112 160 21 29 34 5 7 8
54386 +2 5 5 13 16 17 43 57 68 131 129 131 174 174 174 174 174 174
54387 +174 174 174 167 166 167 157 156 157 125 124 125 37 38 37 4 0 0
54388 +4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
54389 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54390 +4 4 4 4 4 4
54391 +1 1 1 4 0 0 41 54 63 153 152 153 137 136 137 137 136 137
54392 +137 136 137 153 152 153 125 124 125 24 26 27 4 0 0 3 2 2
54393 +4 4 4 4 4 4 4 3 3 4 0 0 3 6 7 43 61 72
54394 +64 123 161 101 161 196 90 154 193 90 154 193 90 154 193 90 154 193
54395 +90 154 193 90 154 193 90 154 193 90 154 193 101 161 196 90 154 193
54396 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
54397 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
54398 +136 185 209 101 161 196 101 161 196 136 185 209 136 185 209 101 161 196
54399 +101 161 196 90 154 193 28 67 93 13 16 17 7 11 13 3 6 7
54400 +37 51 59 125 124 125 163 162 163 174 174 174 167 166 167 166 165 166
54401 +167 166 167 131 129 131 60 73 81 4 0 0 4 0 0 4 0 0
54402 +3 3 3 5 5 5 6 6 6 4 4 4 4 4 4 4 4 4
54403 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54404 +4 4 4 4 4 4
54405 +4 0 0 4 0 0 41 54 63 137 136 137 153 152 153 137 136 137
54406 +153 152 153 157 156 157 125 124 125 24 26 27 0 0 0 2 2 2
54407 +4 4 4 4 4 4 2 0 0 0 0 0 28 67 93 90 154 193
54408 +90 154 193 90 154 193 90 154 193 90 154 193 64 123 161 90 154 193
54409 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
54410 +90 154 193 101 161 196 101 161 196 101 161 196 90 154 193 136 185 209
54411 +101 161 196 101 161 196 136 185 209 101 161 196 136 185 209 101 161 196
54412 +101 161 196 101 161 196 136 185 209 101 161 196 101 161 196 90 154 193
54413 +35 83 115 13 16 17 3 6 7 2 5 5 13 16 17 60 74 84
54414 +154 154 154 166 165 166 165 164 165 158 157 158 163 162 163 157 156 157
54415 +60 74 84 13 16 17 4 0 0 4 0 0 3 2 2 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 4 4 4 4 4 4 4 4 4 4 4 4
54418 +4 4 4 4 4 4
54419 +1 1 1 4 0 0 41 54 63 157 156 157 155 154 155 137 136 137
54420 +153 152 153 158 157 158 137 136 137 26 28 28 2 0 0 2 2 2
54421 +4 4 4 4 4 4 1 0 0 6 10 14 34 86 122 90 154 193
54422 +64 123 161 90 154 193 64 123 161 90 154 193 90 154 193 90 154 193
54423 +64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
54424 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
54425 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
54426 +136 185 209 101 161 196 136 185 209 90 154 193 26 108 161 22 40 52
54427 +13 16 17 5 7 8 2 5 5 2 5 5 37 38 37 165 164 165
54428 +174 174 174 163 162 163 154 154 154 165 164 165 167 166 167 60 73 81
54429 +6 6 6 4 0 0 4 0 0 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 4 4 4 4 4 4 4 4 4 4 4 4
54432 +4 4 4 4 4 4
54433 +4 0 0 6 6 6 41 54 63 156 155 156 158 157 158 153 152 153
54434 +156 155 156 165 164 165 137 136 137 26 28 28 0 0 0 2 2 2
54435 +4 4 5 4 4 4 2 0 0 7 12 15 31 96 139 64 123 161
54436 +90 154 193 64 123 161 90 154 193 90 154 193 64 123 161 90 154 193
54437 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
54438 +90 154 193 90 154 193 90 154 193 101 161 196 101 161 196 101 161 196
54439 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
54440 +101 161 196 136 185 209 26 108 161 22 40 52 7 11 13 5 7 8
54441 +2 5 5 2 5 5 2 5 5 2 2 1 37 38 37 158 157 158
54442 +174 174 174 154 154 154 156 155 156 167 166 167 165 164 165 37 38 37
54443 +4 0 0 4 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
54446 +4 4 4 4 4 4
54447 +3 1 0 4 0 0 60 73 81 157 156 157 163 162 163 153 152 153
54448 +158 157 158 167 166 167 137 136 137 26 28 28 2 0 0 2 2 2
54449 +4 5 5 4 4 4 4 0 0 7 12 15 24 86 132 26 108 161
54450 +37 112 160 64 123 161 90 154 193 64 123 161 90 154 193 90 154 193
54451 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
54452 +90 154 193 101 161 196 90 154 193 101 161 196 101 161 196 101 161 196
54453 +101 161 196 101 161 196 101 161 196 136 185 209 101 161 196 136 185 209
54454 +90 154 193 35 83 115 13 16 17 13 16 17 7 11 13 3 6 7
54455 +5 7 8 6 6 6 3 4 3 2 2 1 30 32 34 154 154 154
54456 +167 166 167 154 154 154 154 154 154 174 174 174 165 164 165 37 38 37
54457 +6 6 6 4 0 0 6 6 6 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 4 4 4 4 4 4 4 4 4 4 4 4
54460 +4 4 4 4 4 4
54461 +4 0 0 4 0 0 41 54 63 163 162 163 166 165 166 154 154 154
54462 +163 162 163 174 174 174 137 136 137 26 28 28 0 0 0 2 2 2
54463 +4 5 5 4 4 5 1 1 2 6 10 14 28 67 93 18 97 151
54464 +18 97 151 18 97 151 26 108 161 37 112 160 37 112 160 90 154 193
54465 +64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
54466 +90 154 193 101 161 196 101 161 196 90 154 193 101 161 196 101 161 196
54467 +101 161 196 101 161 196 101 161 196 136 185 209 90 154 193 16 89 141
54468 +13 20 25 7 11 13 5 7 8 5 7 8 2 5 5 4 5 5
54469 +3 4 3 4 5 5 3 4 3 0 0 0 37 38 37 158 157 158
54470 +174 174 174 158 157 158 158 157 158 167 166 167 174 174 174 41 54 63
54471 +4 0 0 3 2 2 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
54474 +4 4 4 4 4 4
54475 +1 1 1 4 0 0 60 73 81 165 164 165 174 174 174 158 157 158
54476 +167 166 167 174 174 174 153 152 153 26 28 28 2 0 0 2 2 2
54477 +4 5 5 4 4 4 4 0 0 7 12 15 10 87 144 10 87 144
54478 +18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
54479 +26 108 161 37 112 160 53 118 160 90 154 193 90 154 193 90 154 193
54480 +90 154 193 90 154 193 101 161 196 101 161 196 101 161 196 101 161 196
54481 +101 161 196 136 185 209 90 154 193 26 108 161 22 40 52 13 16 17
54482 +7 11 13 3 6 7 5 7 8 5 7 8 2 5 5 4 5 5
54483 +4 5 5 6 6 6 3 4 3 0 0 0 30 32 34 158 157 158
54484 +174 174 174 156 155 156 155 154 155 165 164 165 154 153 154 37 38 37
54485 +4 0 0 4 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
54488 +4 4 4 4 4 4
54489 +4 0 0 4 0 0 60 73 81 167 166 167 174 174 174 163 162 163
54490 +174 174 174 174 174 174 153 152 153 26 28 28 0 0 0 3 3 3
54491 +5 5 5 4 4 4 1 1 2 7 12 15 28 67 93 18 97 151
54492 +18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
54493 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
54494 +90 154 193 26 108 161 90 154 193 90 154 193 90 154 193 101 161 196
54495 +101 161 196 26 108 161 22 40 52 13 16 17 7 11 13 2 5 5
54496 +2 5 5 6 6 6 2 5 5 4 5 5 4 5 5 4 5 5
54497 +3 4 3 5 5 5 3 4 3 2 0 0 30 32 34 137 136 137
54498 +153 152 153 137 136 137 131 129 131 137 136 137 131 129 131 37 38 37
54499 +4 0 0 4 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
54502 +4 4 4 4 4 4
54503 +1 1 1 4 0 0 60 73 81 167 166 167 174 174 174 166 165 166
54504 +174 174 174 177 184 187 153 152 153 30 32 34 1 0 0 3 3 3
54505 +5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
54506 +18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
54507 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
54508 +26 108 161 26 108 161 26 108 161 90 154 193 90 154 193 26 108 161
54509 +35 83 115 13 16 17 7 11 13 5 7 8 3 6 7 5 7 8
54510 +2 5 5 6 6 6 4 5 5 4 5 5 3 4 3 4 5 5
54511 +3 4 3 6 6 6 3 4 3 0 0 0 26 28 28 125 124 125
54512 +131 129 131 125 124 125 125 124 125 131 129 131 131 129 131 37 38 37
54513 +4 0 0 3 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
54516 +4 4 4 4 4 4
54517 +3 1 0 4 0 0 60 73 81 174 174 174 177 184 187 167 166 167
54518 +174 174 174 177 184 187 153 152 153 30 32 34 0 0 0 3 3 3
54519 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
54520 +18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
54521 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
54522 +26 108 161 90 154 193 26 108 161 26 108 161 24 86 132 13 20 25
54523 +7 11 13 13 20 25 22 40 52 5 7 8 3 4 3 3 4 3
54524 +4 5 5 3 4 3 4 5 5 3 4 3 4 5 5 3 4 3
54525 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
54526 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
54527 +0 0 0 3 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
54530 +4 4 4 4 4 4
54531 +1 1 1 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
54532 +174 174 174 190 197 201 157 156 157 30 32 34 1 0 0 3 3 3
54533 +5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
54534 +18 97 151 19 95 150 19 95 150 18 97 151 18 97 151 26 108 161
54535 +18 97 151 26 108 161 26 108 161 26 108 161 26 108 161 90 154 193
54536 +26 108 161 26 108 161 26 108 161 22 40 52 2 5 5 3 4 3
54537 +28 67 93 37 112 160 34 86 122 2 5 5 3 4 3 3 4 3
54538 +3 4 3 3 4 3 3 4 3 2 2 1 3 4 3 4 4 4
54539 +4 5 5 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
54540 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
54541 +0 0 0 3 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
54544 +4 4 4 4 4 4
54545 +4 0 0 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
54546 +174 174 174 190 197 201 158 157 158 30 32 34 0 0 0 2 2 2
54547 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
54548 +10 87 144 19 95 150 19 95 150 18 97 151 18 97 151 18 97 151
54549 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
54550 +18 97 151 22 40 52 2 5 5 2 2 1 22 40 52 26 108 161
54551 +90 154 193 37 112 160 22 40 52 3 4 3 13 20 25 22 30 35
54552 +3 6 7 1 1 1 2 2 2 6 9 11 5 5 5 4 3 3
54553 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
54554 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
54555 +0 0 0 3 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
54558 +4 4 4 4 4 4
54559 +1 1 1 4 0 0 60 73 81 177 184 187 193 200 203 174 174 174
54560 +177 184 187 193 200 203 163 162 163 30 32 34 4 0 0 2 2 2
54561 +5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
54562 +10 87 144 10 87 144 19 95 150 19 95 150 19 95 150 18 97 151
54563 +26 108 161 26 108 161 26 108 161 90 154 193 26 108 161 28 67 93
54564 +6 10 14 2 5 5 13 20 25 24 86 132 37 112 160 90 154 193
54565 +10 87 144 7 12 15 2 5 5 28 67 93 37 112 160 28 67 93
54566 +2 2 1 7 12 15 35 83 115 28 67 93 3 6 7 1 0 0
54567 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
54568 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
54569 +0 0 0 3 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
54572 +4 4 4 4 4 4
54573 +4 0 0 4 0 0 60 73 81 174 174 174 190 197 201 174 174 174
54574 +177 184 187 193 200 203 163 162 163 30 32 34 0 0 0 2 2 2
54575 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
54576 +10 87 144 16 89 141 19 95 150 10 87 144 26 108 161 26 108 161
54577 +26 108 161 26 108 161 26 108 161 28 67 93 6 10 14 1 1 2
54578 +7 12 15 28 67 93 26 108 161 16 89 141 24 86 132 21 29 34
54579 +3 4 3 21 29 34 37 112 160 37 112 160 27 99 146 21 29 34
54580 +21 29 34 26 108 161 90 154 193 35 83 115 1 1 2 2 0 0
54581 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
54582 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
54583 +0 0 0 3 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
54586 +4 4 4 4 4 4
54587 +3 1 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
54588 +190 197 201 193 200 203 165 164 165 37 38 37 4 0 0 2 2 2
54589 +5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
54590 +10 87 144 10 87 144 16 89 141 18 97 151 18 97 151 10 87 144
54591 +24 86 132 24 86 132 13 20 25 4 5 7 4 5 7 22 40 52
54592 +18 97 151 37 112 160 26 108 161 7 12 15 1 1 1 0 0 0
54593 +28 67 93 37 112 160 26 108 161 28 67 93 22 40 52 28 67 93
54594 +26 108 161 90 154 193 26 108 161 10 87 144 0 0 0 2 0 0
54595 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
54596 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
54597 +0 0 0 3 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
54600 +4 4 4 4 4 4
54601 +4 0 0 6 6 6 60 73 81 174 174 174 193 200 203 174 174 174
54602 +190 197 201 193 200 203 165 164 165 30 32 34 0 0 0 2 2 2
54603 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
54604 +10 87 144 10 87 144 10 87 144 18 97 151 28 67 93 6 10 14
54605 +0 0 0 1 1 2 4 5 7 13 20 25 16 89 141 26 108 161
54606 +26 108 161 26 108 161 24 86 132 6 9 11 2 3 3 22 40 52
54607 +37 112 160 16 89 141 22 40 52 28 67 93 26 108 161 26 108 161
54608 +90 154 193 26 108 161 26 108 161 28 67 93 1 1 1 4 0 0
54609 +4 4 4 5 5 5 3 3 3 4 0 0 26 28 28 124 126 130
54610 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
54611 +0 0 0 3 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
54614 +4 4 4 4 4 4
54615 +4 0 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
54616 +193 200 203 193 200 203 167 166 167 37 38 37 4 0 0 2 2 2
54617 +5 5 5 4 4 4 4 0 0 6 10 14 28 67 93 10 87 144
54618 +10 87 144 10 87 144 18 97 151 10 87 144 13 20 25 4 5 7
54619 +1 1 2 1 1 1 22 40 52 26 108 161 26 108 161 26 108 161
54620 +26 108 161 26 108 161 26 108 161 24 86 132 22 40 52 22 40 52
54621 +22 40 52 22 40 52 10 87 144 26 108 161 26 108 161 26 108 161
54622 +26 108 161 26 108 161 90 154 193 10 87 144 0 0 0 4 0 0
54623 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
54624 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
54625 +0 0 0 3 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
54628 +4 4 4 4 4 4
54629 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
54630 +190 197 201 205 212 215 167 166 167 30 32 34 0 0 0 2 2 2
54631 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
54632 +10 87 144 10 87 144 10 87 144 10 87 144 22 40 52 1 1 2
54633 +2 0 0 1 1 2 24 86 132 26 108 161 26 108 161 26 108 161
54634 +26 108 161 19 95 150 16 89 141 10 87 144 22 40 52 22 40 52
54635 +10 87 144 26 108 161 37 112 160 26 108 161 26 108 161 26 108 161
54636 +26 108 161 26 108 161 26 108 161 28 67 93 2 0 0 3 1 0
54637 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
54638 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
54639 +0 0 0 3 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
54642 +4 4 4 4 4 4
54643 +4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
54644 +193 200 203 193 200 203 174 174 174 37 38 37 4 0 0 2 2 2
54645 +5 5 5 4 4 4 3 2 2 1 1 2 13 20 25 10 87 144
54646 +10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 13 20 25
54647 +13 20 25 22 40 52 10 87 144 18 97 151 18 97 151 26 108 161
54648 +10 87 144 13 20 25 6 10 14 21 29 34 24 86 132 18 97 151
54649 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
54650 +26 108 161 90 154 193 18 97 151 13 20 25 0 0 0 4 3 3
54651 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
54652 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
54653 +0 0 0 3 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
54656 +4 4 4 4 4 4
54657 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
54658 +190 197 201 220 221 221 167 166 167 30 32 34 1 0 0 2 2 2
54659 +5 5 5 4 4 4 4 4 5 2 5 5 4 5 7 13 20 25
54660 +28 67 93 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
54661 +10 87 144 10 87 144 18 97 151 10 87 144 18 97 151 18 97 151
54662 +28 67 93 2 3 3 0 0 0 28 67 93 26 108 161 26 108 161
54663 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
54664 +26 108 161 10 87 144 13 20 25 1 1 2 3 2 2 4 4 4
54665 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
54666 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
54667 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
54668 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54669 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54670 +4 4 4 4 4 4
54671 +4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
54672 +193 200 203 193 200 203 174 174 174 26 28 28 4 0 0 4 3 3
54673 +5 5 5 4 4 4 4 4 4 4 4 5 1 1 2 2 5 5
54674 +4 5 7 22 40 52 10 87 144 10 87 144 18 97 151 10 87 144
54675 +10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 18 97 151
54676 +10 87 144 28 67 93 22 40 52 10 87 144 26 108 161 18 97 151
54677 +18 97 151 18 97 151 26 108 161 26 108 161 26 108 161 26 108 161
54678 +22 40 52 1 1 2 0 0 0 2 3 3 4 4 4 4 4 4
54679 +4 4 4 5 5 5 4 4 4 0 0 0 26 28 28 131 129 131
54680 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
54681 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
54682 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54683 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54684 +4 4 4 4 4 4
54685 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
54686 +190 197 201 220 221 221 190 197 201 41 54 63 4 0 0 2 2 2
54687 +6 6 6 4 4 4 4 4 4 4 4 5 4 4 5 3 3 3
54688 +1 1 2 1 1 2 6 10 14 22 40 52 10 87 144 18 97 151
54689 +18 97 151 10 87 144 10 87 144 10 87 144 18 97 151 10 87 144
54690 +10 87 144 18 97 151 26 108 161 18 97 151 18 97 151 10 87 144
54691 +26 108 161 26 108 161 26 108 161 10 87 144 28 67 93 6 10 14
54692 +1 1 2 1 1 2 4 3 3 4 4 5 4 4 4 4 4 4
54693 +5 5 5 5 5 5 1 1 1 4 0 0 37 51 59 137 136 137
54694 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
54695 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
54696 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54697 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54698 +4 4 4 4 4 4
54699 +4 0 0 4 0 0 60 73 81 220 221 221 193 200 203 174 174 174
54700 +193 200 203 193 200 203 220 221 221 137 136 137 13 16 17 4 0 0
54701 +2 2 2 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5
54702 +4 4 5 4 3 3 1 1 2 4 5 7 13 20 25 28 67 93
54703 +10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
54704 +10 87 144 18 97 151 18 97 151 10 87 144 18 97 151 26 108 161
54705 +26 108 161 18 97 151 28 67 93 6 10 14 0 0 0 0 0 0
54706 +2 3 3 4 5 5 4 4 5 4 4 4 4 4 4 5 5 5
54707 +3 3 3 1 1 1 0 0 0 16 19 21 125 124 125 137 136 137
54708 +131 129 131 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
54709 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
54710 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54711 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54712 +4 4 4 4 4 4
54713 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
54714 +193 200 203 190 197 201 220 221 221 220 221 221 153 152 153 30 32 34
54715 +0 0 0 0 0 0 2 2 2 4 4 4 4 4 4 4 4 4
54716 +4 4 4 4 5 5 4 5 7 1 1 2 1 1 2 4 5 7
54717 +13 20 25 28 67 93 10 87 144 18 97 151 10 87 144 10 87 144
54718 +10 87 144 10 87 144 10 87 144 18 97 151 26 108 161 18 97 151
54719 +28 67 93 7 12 15 0 0 0 0 0 0 2 2 1 4 4 4
54720 +4 5 5 4 5 5 4 4 4 4 4 4 3 3 3 0 0 0
54721 +0 0 0 0 0 0 37 38 37 125 124 125 158 157 158 131 129 131
54722 +125 124 125 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
54723 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
54724 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54725 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54726 +4 4 4 4 4 4
54727 +4 3 3 4 0 0 41 54 63 193 200 203 220 221 221 174 174 174
54728 +193 200 203 193 200 203 193 200 203 220 221 221 244 246 246 193 200 203
54729 +120 125 127 5 5 5 1 0 0 0 0 0 1 1 1 4 4 4
54730 +4 4 4 4 4 4 4 5 5 4 5 5 4 4 5 1 1 2
54731 +4 5 7 4 5 7 22 40 52 10 87 144 10 87 144 10 87 144
54732 +10 87 144 10 87 144 18 97 151 10 87 144 10 87 144 13 20 25
54733 +4 5 7 2 3 3 1 1 2 4 4 4 4 5 5 4 4 4
54734 +4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 1 2
54735 +24 26 27 60 74 84 153 152 153 163 162 163 137 136 137 125 124 125
54736 +125 124 125 125 124 125 125 124 125 137 136 137 125 124 125 26 28 28
54737 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
54738 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54739 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54740 +4 4 4 4 4 4
54741 +4 0 0 6 6 6 26 28 28 156 155 156 220 221 221 220 221 221
54742 +174 174 174 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
54743 +220 221 221 167 166 167 60 73 81 7 11 13 0 0 0 0 0 0
54744 +3 3 3 4 4 4 4 4 4 4 4 4 4 4 5 4 4 5
54745 +4 4 5 1 1 2 1 1 2 4 5 7 22 40 52 10 87 144
54746 +10 87 144 10 87 144 10 87 144 22 40 52 4 5 7 1 1 2
54747 +1 1 2 4 4 5 4 4 4 4 4 4 4 4 4 4 4 4
54748 +5 5 5 2 2 2 0 0 0 4 0 0 16 19 21 60 73 81
54749 +137 136 137 167 166 167 158 157 158 137 136 137 131 129 131 131 129 131
54750 +125 124 125 125 124 125 131 129 131 155 154 155 60 74 84 5 7 8
54751 +0 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54752 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54753 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54754 +4 4 4 4 4 4
54755 +5 5 5 4 0 0 4 0 0 60 73 81 193 200 203 220 221 221
54756 +193 200 203 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
54757 +220 221 221 220 221 221 220 221 221 137 136 137 43 57 68 6 6 6
54758 +4 0 0 1 1 1 4 4 4 4 4 4 4 4 4 4 4 4
54759 +4 4 5 4 4 5 3 2 2 1 1 2 2 5 5 13 20 25
54760 +22 40 52 22 40 52 13 20 25 2 3 3 1 1 2 3 3 3
54761 +4 5 7 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54762 +1 1 1 0 0 0 2 3 3 41 54 63 131 129 131 166 165 166
54763 +166 165 166 155 154 155 153 152 153 137 136 137 137 136 137 125 124 125
54764 +125 124 125 137 136 137 137 136 137 125 124 125 37 38 37 4 3 3
54765 +4 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
54768 +4 4 4 4 4 4
54769 +4 3 3 6 6 6 6 6 6 13 16 17 60 73 81 167 166 167
54770 +220 221 221 220 221 221 220 221 221 193 200 203 193 200 203 193 200 203
54771 +205 212 215 220 221 221 220 221 221 244 246 246 205 212 215 125 124 125
54772 +24 26 27 0 0 0 0 0 0 2 2 2 5 5 5 5 5 5
54773 +4 4 4 4 4 4 4 4 4 4 4 5 1 1 2 4 5 7
54774 +4 5 7 4 5 7 1 1 2 3 2 2 4 4 5 4 4 4
54775 +4 4 4 4 4 4 5 5 5 4 4 4 0 0 0 0 0 0
54776 +2 0 0 26 28 28 125 124 125 174 174 174 174 174 174 166 165 166
54777 +156 155 156 153 152 153 137 136 137 137 136 137 131 129 131 137 136 137
54778 +137 136 137 137 136 137 60 74 84 30 32 34 4 0 0 4 0 0
54779 +5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
54782 +4 4 4 4 4 4
54783 +5 5 5 6 6 6 4 0 0 4 0 0 6 6 6 26 28 28
54784 +125 124 125 174 174 174 220 221 221 220 221 221 220 221 221 193 200 203
54785 +205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
54786 +193 200 203 60 74 84 13 16 17 4 0 0 0 0 0 3 3 3
54787 +5 5 5 5 5 5 4 4 4 4 4 4 4 4 5 3 3 3
54788 +1 1 2 3 3 3 4 4 5 4 4 5 4 4 4 4 4 4
54789 +5 5 5 5 5 5 2 2 2 0 0 0 0 0 0 13 16 17
54790 +60 74 84 174 174 174 193 200 203 174 174 174 167 166 167 163 162 163
54791 +153 152 153 153 152 153 137 136 137 137 136 137 153 152 153 137 136 137
54792 +125 124 125 41 54 63 24 26 27 4 0 0 4 0 0 5 5 5
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 4 4 4 4 4 4 4 4 4 4 4 4
54796 +4 4 4 4 4 4
54797 +4 3 3 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
54798 +6 6 6 37 38 37 131 129 131 220 221 221 220 221 221 220 221 221
54799 +193 200 203 193 200 203 220 221 221 205 212 215 220 221 221 244 246 246
54800 +244 246 246 244 246 246 174 174 174 41 54 63 0 0 0 0 0 0
54801 +0 0 0 4 4 4 5 5 5 5 5 5 4 4 4 4 4 5
54802 +4 4 5 4 4 5 4 4 4 4 4 4 6 6 6 6 6 6
54803 +3 3 3 0 0 0 2 0 0 13 16 17 60 73 81 156 155 156
54804 +220 221 221 193 200 203 174 174 174 165 164 165 163 162 163 154 153 154
54805 +153 152 153 153 152 153 158 157 158 163 162 163 137 136 137 60 73 81
54806 +13 16 17 4 0 0 4 0 0 4 3 3 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 4 4 4 4 4 4 4 4 4 4 4 4
54810 +4 4 4 4 4 4
54811 +5 5 5 4 3 3 4 3 3 6 6 6 6 6 6 6 6 6
54812 +6 6 6 6 6 6 6 6 6 37 38 37 167 166 167 244 246 246
54813 +244 246 246 220 221 221 205 212 215 205 212 215 220 221 221 193 200 203
54814 +220 221 221 244 246 246 244 246 246 244 246 246 137 136 137 37 38 37
54815 +3 2 2 0 0 0 1 1 1 5 5 5 5 5 5 4 4 4
54816 +4 4 4 4 4 4 4 4 4 5 5 5 4 4 4 1 1 1
54817 +0 0 0 5 5 5 43 57 68 153 152 153 193 200 203 220 221 221
54818 +177 184 187 174 174 174 167 166 167 166 165 166 158 157 158 157 156 157
54819 +158 157 158 166 165 166 156 155 156 85 115 134 13 16 17 4 0 0
54820 +4 0 0 4 0 0 5 5 5 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
54824 +4 4 4 4 4 4
54825 +5 5 5 4 3 3 6 6 6 6 6 6 4 0 0 6 6 6
54826 +6 6 6 6 6 6 6 6 6 6 6 6 13 16 17 60 73 81
54827 +177 184 187 220 221 221 220 221 221 220 221 221 205 212 215 220 221 221
54828 +220 221 221 205 212 215 220 221 221 244 246 246 244 246 246 205 212 215
54829 +125 124 125 30 32 34 0 0 0 0 0 0 2 2 2 5 5 5
54830 +4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 0 0
54831 +37 38 37 131 129 131 205 212 215 220 221 221 193 200 203 174 174 174
54832 +174 174 174 174 174 174 167 166 167 165 164 165 166 165 166 167 166 167
54833 +158 157 158 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
54834 +4 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
54838 +4 4 4 4 4 4
54839 +4 4 4 5 5 5 4 3 3 4 3 3 6 6 6 6 6 6
54840 +4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
54841 +26 28 28 125 124 125 205 212 215 220 221 221 220 221 221 220 221 221
54842 +205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
54843 +244 246 246 190 197 201 60 74 84 16 19 21 4 0 0 0 0 0
54844 +0 0 0 0 0 0 0 0 0 0 0 0 16 19 21 120 125 127
54845 +177 184 187 220 221 221 205 212 215 177 184 187 174 174 174 177 184 187
54846 +174 174 174 174 174 174 167 166 167 174 174 174 166 165 166 137 136 137
54847 +60 73 81 13 16 17 4 0 0 4 0 0 4 3 3 6 6 6
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 4 4 4 4 4 4 4 4 4 4 4 4
54852 +4 4 4 4 4 4
54853 +5 5 5 4 3 3 5 5 5 4 3 3 6 6 6 4 0 0
54854 +6 6 6 6 6 6 4 0 0 6 6 6 4 0 0 6 6 6
54855 +6 6 6 6 6 6 37 38 37 137 136 137 193 200 203 220 221 221
54856 +220 221 221 205 212 215 220 221 221 205 212 215 205 212 215 220 221 221
54857 +220 221 221 220 221 221 244 246 246 166 165 166 43 57 68 2 2 2
54858 +0 0 0 4 0 0 16 19 21 60 73 81 157 156 157 202 210 214
54859 +220 221 221 193 200 203 177 184 187 177 184 187 177 184 187 174 174 174
54860 +174 174 174 174 174 174 174 174 174 157 156 157 60 74 84 24 26 27
54861 +4 0 0 4 0 0 4 0 0 6 6 6 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 4 4 4 4 4 4 4 4 4 4 4 4
54866 +4 4 4 4 4 4
54867 +4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
54868 +6 6 6 4 0 0 6 6 6 6 6 6 6 6 6 4 0 0
54869 +4 0 0 4 0 0 6 6 6 24 26 27 60 73 81 167 166 167
54870 +220 221 221 220 221 221 220 221 221 205 212 215 205 212 215 205 212 215
54871 +205 212 215 220 221 221 220 221 221 220 221 221 205 212 215 137 136 137
54872 +60 74 84 125 124 125 137 136 137 190 197 201 220 221 221 193 200 203
54873 +177 184 187 177 184 187 177 184 187 174 174 174 174 174 174 177 184 187
54874 +190 197 201 174 174 174 125 124 125 37 38 37 6 6 6 4 0 0
54875 +4 0 0 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 4 4 4 4 4 4 4 4 4 4 4 4
54880 +4 4 4 4 4 4
54881 +4 4 4 4 4 4 5 5 5 5 5 5 4 3 3 6 6 6
54882 +4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 6 6 6
54883 +6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
54884 +125 124 125 193 200 203 244 246 246 220 221 221 205 212 215 205 212 215
54885 +205 212 215 193 200 203 205 212 215 205 212 215 220 221 221 220 221 221
54886 +193 200 203 193 200 203 205 212 215 193 200 203 193 200 203 177 184 187
54887 +190 197 201 190 197 201 174 174 174 190 197 201 193 200 203 190 197 201
54888 +153 152 153 60 73 81 4 0 0 4 0 0 4 0 0 3 2 2
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 4 4 4 4 4 4 4 4 4 4 4 4
54894 +4 4 4 4 4 4
54895 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
54896 +6 6 6 4 3 3 4 3 3 4 3 3 6 6 6 6 6 6
54897 +4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 4 0 0
54898 +4 0 0 26 28 28 131 129 131 220 221 221 244 246 246 220 221 221
54899 +205 212 215 193 200 203 205 212 215 193 200 203 193 200 203 205 212 215
54900 +220 221 221 193 200 203 193 200 203 193 200 203 190 197 201 174 174 174
54901 +174 174 174 190 197 201 193 200 203 193 200 203 167 166 167 125 124 125
54902 +6 6 6 4 0 0 4 0 0 4 3 3 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 4 4 4 4 4 4 4 4 4 4 4 4
54908 +4 4 4 4 4 4
54909 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
54910 +5 5 5 4 3 3 5 5 5 6 6 6 4 3 3 5 5 5
54911 +6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
54912 +4 0 0 4 0 0 6 6 6 41 54 63 158 157 158 220 221 221
54913 +220 221 221 220 221 221 193 200 203 193 200 203 193 200 203 190 197 201
54914 +190 197 201 190 197 201 190 197 201 190 197 201 174 174 174 193 200 203
54915 +193 200 203 220 221 221 174 174 174 125 124 125 37 38 37 4 0 0
54916 +4 0 0 4 3 3 6 6 6 4 4 4 4 4 4 4 4 4
54917 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54918 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54919 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54920 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54921 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54922 +4 4 4 4 4 4
54923 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54924 +4 4 4 5 5 5 4 3 3 4 3 3 4 3 3 5 5 5
54925 +4 3 3 6 6 6 5 5 5 4 3 3 6 6 6 6 6 6
54926 +6 6 6 6 6 6 4 0 0 4 0 0 13 16 17 60 73 81
54927 +174 174 174 220 221 221 220 221 221 205 212 215 190 197 201 174 174 174
54928 +193 200 203 174 174 174 190 197 201 174 174 174 193 200 203 220 221 221
54929 +193 200 203 131 129 131 37 38 37 6 6 6 4 0 0 4 0 0
54930 +6 6 6 6 6 6 4 3 3 5 5 5 4 4 4 4 4 4
54931 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54932 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54933 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54934 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54935 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54936 +4 4 4 4 4 4
54937 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54938 +4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
54939 +5 5 5 4 3 3 4 3 3 5 5 5 4 3 3 4 3 3
54940 +5 5 5 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
54941 +6 6 6 125 124 125 174 174 174 220 221 221 220 221 221 193 200 203
54942 +193 200 203 193 200 203 193 200 203 193 200 203 220 221 221 158 157 158
54943 +60 73 81 6 6 6 4 0 0 4 0 0 5 5 5 6 6 6
54944 +5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
54945 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54946 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54947 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54948 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54949 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54950 +4 4 4 4 4 4
54951 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54952 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54953 +4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
54954 +5 5 5 5 5 5 6 6 6 6 6 6 4 0 0 4 0 0
54955 +4 0 0 4 0 0 26 28 28 125 124 125 174 174 174 193 200 203
54956 +193 200 203 174 174 174 193 200 203 167 166 167 125 124 125 6 6 6
54957 +6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 5 5 5
54958 +4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
54959 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54960 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54961 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54962 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54963 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54964 +4 4 4 4 4 4
54965 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54966 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54967 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
54968 +4 3 3 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
54969 +6 6 6 4 0 0 4 0 0 6 6 6 37 38 37 125 124 125
54970 +153 152 153 131 129 131 125 124 125 37 38 37 6 6 6 6 6 6
54971 +6 6 6 4 0 0 6 6 6 6 6 6 4 3 3 5 5 5
54972 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54973 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54974 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54975 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54976 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54977 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54978 +4 4 4 4 4 4
54979 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54980 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54981 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54982 +4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
54983 +6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
54984 +24 26 27 24 26 27 6 6 6 6 6 6 6 6 6 4 0 0
54985 +6 6 6 6 6 6 4 0 0 6 6 6 5 5 5 4 3 3
54986 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54987 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54988 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54989 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54990 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54991 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54992 +4 4 4 4 4 4
54993 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54994 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54995 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54996 +4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
54997 +4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
54998 +6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
54999 +4 0 0 6 6 6 6 6 6 4 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
55006 +4 4 4 4 4 4
55007 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55008 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55009 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55010 +4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 5 5 5
55011 +5 5 5 5 5 5 4 0 0 6 6 6 4 0 0 6 6 6
55012 +6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 4 0 0
55013 +6 6 6 4 3 3 5 5 5 4 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
55020 +4 4 4 4 4 4
55021 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55022 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55023 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55024 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
55025 +4 3 3 6 6 6 4 3 3 6 6 6 6 6 6 6 6 6
55026 +4 0 0 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
55027 +6 6 6 4 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
55034 +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 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55039 +4 4 4 5 5 5 4 3 3 5 5 5 4 0 0 6 6 6
55040 +6 6 6 4 0 0 6 6 6 6 6 6 4 0 0 6 6 6
55041 +4 3 3 5 5 5 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
55048 +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 4 4 4 4 4 4 4 4 4
55053 +4 4 4 5 5 5 4 3 3 5 5 5 6 6 6 4 3 3
55054 +4 3 3 6 6 6 6 6 6 4 3 3 6 6 6 4 3 3
55055 +5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
55062 +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 4 4 4 4 4 4
55067 +4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 6 6 6
55068 +5 5 5 4 3 3 4 3 3 4 3 3 5 5 5 5 5 5
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 4 4 4 4 4 4 4 4 4 4 4 4
55076 +4 4 4 4 4 4
55077 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55078 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55079 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55080 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55081 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
55082 +5 5 5 4 3 3 5 5 5 5 5 5 4 4 4 4 4 4
55083 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55084 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55085 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55086 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55087 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55088 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55089 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55090 +4 4 4 4 4 4
55091 diff --git a/drivers/video/matrox/matroxfb_DAC1064.c b/drivers/video/matrox/matroxfb_DAC1064.c
55092 index a01147f..5d896f8 100644
55093 --- a/drivers/video/matrox/matroxfb_DAC1064.c
55094 +++ b/drivers/video/matrox/matroxfb_DAC1064.c
55095 @@ -1088,14 +1088,20 @@ static void MGAG100_restore(struct matrox_fb_info *minfo)
55096
55097 #ifdef CONFIG_FB_MATROX_MYSTIQUE
55098 struct matrox_switch matrox_mystique = {
55099 - MGA1064_preinit, MGA1064_reset, MGA1064_init, MGA1064_restore,
55100 + .preinit = MGA1064_preinit,
55101 + .reset = MGA1064_reset,
55102 + .init = MGA1064_init,
55103 + .restore = MGA1064_restore,
55104 };
55105 EXPORT_SYMBOL(matrox_mystique);
55106 #endif
55107
55108 #ifdef CONFIG_FB_MATROX_G
55109 struct matrox_switch matrox_G100 = {
55110 - MGAG100_preinit, MGAG100_reset, MGAG100_init, MGAG100_restore,
55111 + .preinit = MGAG100_preinit,
55112 + .reset = MGAG100_reset,
55113 + .init = MGAG100_init,
55114 + .restore = MGAG100_restore,
55115 };
55116 EXPORT_SYMBOL(matrox_G100);
55117 #endif
55118 diff --git a/drivers/video/matrox/matroxfb_Ti3026.c b/drivers/video/matrox/matroxfb_Ti3026.c
55119 index 195ad7c..09743fc 100644
55120 --- a/drivers/video/matrox/matroxfb_Ti3026.c
55121 +++ b/drivers/video/matrox/matroxfb_Ti3026.c
55122 @@ -738,7 +738,10 @@ static int Ti3026_preinit(struct matrox_fb_info *minfo)
55123 }
55124
55125 struct matrox_switch matrox_millennium = {
55126 - Ti3026_preinit, Ti3026_reset, Ti3026_init, Ti3026_restore
55127 + .preinit = Ti3026_preinit,
55128 + .reset = Ti3026_reset,
55129 + .init = Ti3026_init,
55130 + .restore = Ti3026_restore
55131 };
55132 EXPORT_SYMBOL(matrox_millennium);
55133 #endif
55134 diff --git a/drivers/video/mb862xx/mb862xxfb_accel.c b/drivers/video/mb862xx/mb862xxfb_accel.c
55135 index fe92eed..106e085 100644
55136 --- a/drivers/video/mb862xx/mb862xxfb_accel.c
55137 +++ b/drivers/video/mb862xx/mb862xxfb_accel.c
55138 @@ -312,14 +312,18 @@ void mb862xxfb_init_accel(struct fb_info *info, int xres)
55139 struct mb862xxfb_par *par = info->par;
55140
55141 if (info->var.bits_per_pixel == 32) {
55142 - info->fbops->fb_fillrect = cfb_fillrect;
55143 - info->fbops->fb_copyarea = cfb_copyarea;
55144 - info->fbops->fb_imageblit = cfb_imageblit;
55145 + pax_open_kernel();
55146 + *(void **)&info->fbops->fb_fillrect = cfb_fillrect;
55147 + *(void **)&info->fbops->fb_copyarea = cfb_copyarea;
55148 + *(void **)&info->fbops->fb_imageblit = cfb_imageblit;
55149 + pax_close_kernel();
55150 } else {
55151 outreg(disp, GC_L0EM, 3);
55152 - info->fbops->fb_fillrect = mb86290fb_fillrect;
55153 - info->fbops->fb_copyarea = mb86290fb_copyarea;
55154 - info->fbops->fb_imageblit = mb86290fb_imageblit;
55155 + pax_open_kernel();
55156 + *(void **)&info->fbops->fb_fillrect = mb86290fb_fillrect;
55157 + *(void **)&info->fbops->fb_copyarea = mb86290fb_copyarea;
55158 + *(void **)&info->fbops->fb_imageblit = mb86290fb_imageblit;
55159 + pax_close_kernel();
55160 }
55161 outreg(draw, GDC_REG_DRAW_BASE, 0);
55162 outreg(draw, GDC_REG_MODE_MISC, 0x8000);
55163 diff --git a/drivers/video/nvidia/nvidia.c b/drivers/video/nvidia/nvidia.c
55164 index ff22871..b129bed 100644
55165 --- a/drivers/video/nvidia/nvidia.c
55166 +++ b/drivers/video/nvidia/nvidia.c
55167 @@ -669,19 +669,23 @@ static int nvidiafb_set_par(struct fb_info *info)
55168 info->fix.line_length = (info->var.xres_virtual *
55169 info->var.bits_per_pixel) >> 3;
55170 if (info->var.accel_flags) {
55171 - info->fbops->fb_imageblit = nvidiafb_imageblit;
55172 - info->fbops->fb_fillrect = nvidiafb_fillrect;
55173 - info->fbops->fb_copyarea = nvidiafb_copyarea;
55174 - info->fbops->fb_sync = nvidiafb_sync;
55175 + pax_open_kernel();
55176 + *(void **)&info->fbops->fb_imageblit = nvidiafb_imageblit;
55177 + *(void **)&info->fbops->fb_fillrect = nvidiafb_fillrect;
55178 + *(void **)&info->fbops->fb_copyarea = nvidiafb_copyarea;
55179 + *(void **)&info->fbops->fb_sync = nvidiafb_sync;
55180 + pax_close_kernel();
55181 info->pixmap.scan_align = 4;
55182 info->flags &= ~FBINFO_HWACCEL_DISABLED;
55183 info->flags |= FBINFO_READS_FAST;
55184 NVResetGraphics(info);
55185 } else {
55186 - info->fbops->fb_imageblit = cfb_imageblit;
55187 - info->fbops->fb_fillrect = cfb_fillrect;
55188 - info->fbops->fb_copyarea = cfb_copyarea;
55189 - info->fbops->fb_sync = NULL;
55190 + pax_open_kernel();
55191 + *(void **)&info->fbops->fb_imageblit = cfb_imageblit;
55192 + *(void **)&info->fbops->fb_fillrect = cfb_fillrect;
55193 + *(void **)&info->fbops->fb_copyarea = cfb_copyarea;
55194 + *(void **)&info->fbops->fb_sync = NULL;
55195 + pax_close_kernel();
55196 info->pixmap.scan_align = 1;
55197 info->flags |= FBINFO_HWACCEL_DISABLED;
55198 info->flags &= ~FBINFO_READS_FAST;
55199 @@ -1173,8 +1177,11 @@ static int nvidia_set_fbinfo(struct fb_info *info)
55200 info->pixmap.size = 8 * 1024;
55201 info->pixmap.flags = FB_PIXMAP_SYSTEM;
55202
55203 - if (!hwcur)
55204 - info->fbops->fb_cursor = NULL;
55205 + if (!hwcur) {
55206 + pax_open_kernel();
55207 + *(void **)&info->fbops->fb_cursor = NULL;
55208 + pax_close_kernel();
55209 + }
55210
55211 info->var.accel_flags = (!noaccel);
55212
55213 diff --git a/drivers/video/omap2/dss/display.c b/drivers/video/omap2/dss/display.c
55214 index 669a81f..e216d76 100644
55215 --- a/drivers/video/omap2/dss/display.c
55216 +++ b/drivers/video/omap2/dss/display.c
55217 @@ -137,12 +137,14 @@ int omapdss_register_display(struct omap_dss_device *dssdev)
55218 snprintf(dssdev->alias, sizeof(dssdev->alias),
55219 "display%d", disp_num_counter++);
55220
55221 + pax_open_kernel();
55222 if (drv && drv->get_resolution == NULL)
55223 - drv->get_resolution = omapdss_default_get_resolution;
55224 + *(void **)&drv->get_resolution = omapdss_default_get_resolution;
55225 if (drv && drv->get_recommended_bpp == NULL)
55226 - drv->get_recommended_bpp = omapdss_default_get_recommended_bpp;
55227 + *(void **)&drv->get_recommended_bpp = omapdss_default_get_recommended_bpp;
55228 if (drv && drv->get_timings == NULL)
55229 - drv->get_timings = omapdss_default_get_timings;
55230 + *(void **)&drv->get_timings = omapdss_default_get_timings;
55231 + pax_close_kernel();
55232
55233 mutex_lock(&panel_list_mutex);
55234 list_add_tail(&dssdev->panel_list, &panel_list);
55235 diff --git a/drivers/video/s1d13xxxfb.c b/drivers/video/s1d13xxxfb.c
55236 index 83433cb..71e9b98 100644
55237 --- a/drivers/video/s1d13xxxfb.c
55238 +++ b/drivers/video/s1d13xxxfb.c
55239 @@ -881,8 +881,10 @@ static int s1d13xxxfb_probe(struct platform_device *pdev)
55240
55241 switch(prod_id) {
55242 case S1D13506_PROD_ID: /* activate acceleration */
55243 - s1d13xxxfb_fbops.fb_fillrect = s1d13xxxfb_bitblt_solidfill;
55244 - s1d13xxxfb_fbops.fb_copyarea = s1d13xxxfb_bitblt_copyarea;
55245 + pax_open_kernel();
55246 + *(void **)&s1d13xxxfb_fbops.fb_fillrect = s1d13xxxfb_bitblt_solidfill;
55247 + *(void **)&s1d13xxxfb_fbops.fb_copyarea = s1d13xxxfb_bitblt_copyarea;
55248 + pax_close_kernel();
55249 info->flags = FBINFO_DEFAULT | FBINFO_HWACCEL_YPAN |
55250 FBINFO_HWACCEL_FILLRECT | FBINFO_HWACCEL_COPYAREA;
55251 break;
55252 diff --git a/drivers/video/smscufx.c b/drivers/video/smscufx.c
55253 index d513ed6..90b0de9 100644
55254 --- a/drivers/video/smscufx.c
55255 +++ b/drivers/video/smscufx.c
55256 @@ -1175,7 +1175,9 @@ static int ufx_ops_release(struct fb_info *info, int user)
55257 fb_deferred_io_cleanup(info);
55258 kfree(info->fbdefio);
55259 info->fbdefio = NULL;
55260 - info->fbops->fb_mmap = ufx_ops_mmap;
55261 + pax_open_kernel();
55262 + *(void **)&info->fbops->fb_mmap = ufx_ops_mmap;
55263 + pax_close_kernel();
55264 }
55265
55266 pr_debug("released /dev/fb%d user=%d count=%d",
55267 diff --git a/drivers/video/udlfb.c b/drivers/video/udlfb.c
55268 index 025f14e..20eb4db 100644
55269 --- a/drivers/video/udlfb.c
55270 +++ b/drivers/video/udlfb.c
55271 @@ -623,11 +623,11 @@ static int dlfb_handle_damage(struct dlfb_data *dev, int x, int y,
55272 dlfb_urb_completion(urb);
55273
55274 error:
55275 - atomic_add(bytes_sent, &dev->bytes_sent);
55276 - atomic_add(bytes_identical, &dev->bytes_identical);
55277 - atomic_add(width*height*2, &dev->bytes_rendered);
55278 + atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
55279 + atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
55280 + atomic_add_unchecked(width*height*2, &dev->bytes_rendered);
55281 end_cycles = get_cycles();
55282 - atomic_add(((unsigned int) ((end_cycles - start_cycles)
55283 + atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
55284 >> 10)), /* Kcycles */
55285 &dev->cpu_kcycles_used);
55286
55287 @@ -748,11 +748,11 @@ static void dlfb_dpy_deferred_io(struct fb_info *info,
55288 dlfb_urb_completion(urb);
55289
55290 error:
55291 - atomic_add(bytes_sent, &dev->bytes_sent);
55292 - atomic_add(bytes_identical, &dev->bytes_identical);
55293 - atomic_add(bytes_rendered, &dev->bytes_rendered);
55294 + atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
55295 + atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
55296 + atomic_add_unchecked(bytes_rendered, &dev->bytes_rendered);
55297 end_cycles = get_cycles();
55298 - atomic_add(((unsigned int) ((end_cycles - start_cycles)
55299 + atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
55300 >> 10)), /* Kcycles */
55301 &dev->cpu_kcycles_used);
55302 }
55303 @@ -993,7 +993,9 @@ static int dlfb_ops_release(struct fb_info *info, int user)
55304 fb_deferred_io_cleanup(info);
55305 kfree(info->fbdefio);
55306 info->fbdefio = NULL;
55307 - info->fbops->fb_mmap = dlfb_ops_mmap;
55308 + pax_open_kernel();
55309 + *(void **)&info->fbops->fb_mmap = dlfb_ops_mmap;
55310 + pax_close_kernel();
55311 }
55312
55313 pr_warn("released /dev/fb%d user=%d count=%d\n",
55314 @@ -1376,7 +1378,7 @@ static ssize_t metrics_bytes_rendered_show(struct device *fbdev,
55315 struct fb_info *fb_info = dev_get_drvdata(fbdev);
55316 struct dlfb_data *dev = fb_info->par;
55317 return snprintf(buf, PAGE_SIZE, "%u\n",
55318 - atomic_read(&dev->bytes_rendered));
55319 + atomic_read_unchecked(&dev->bytes_rendered));
55320 }
55321
55322 static ssize_t metrics_bytes_identical_show(struct device *fbdev,
55323 @@ -1384,7 +1386,7 @@ static ssize_t metrics_bytes_identical_show(struct device *fbdev,
55324 struct fb_info *fb_info = dev_get_drvdata(fbdev);
55325 struct dlfb_data *dev = fb_info->par;
55326 return snprintf(buf, PAGE_SIZE, "%u\n",
55327 - atomic_read(&dev->bytes_identical));
55328 + atomic_read_unchecked(&dev->bytes_identical));
55329 }
55330
55331 static ssize_t metrics_bytes_sent_show(struct device *fbdev,
55332 @@ -1392,7 +1394,7 @@ static ssize_t metrics_bytes_sent_show(struct device *fbdev,
55333 struct fb_info *fb_info = dev_get_drvdata(fbdev);
55334 struct dlfb_data *dev = fb_info->par;
55335 return snprintf(buf, PAGE_SIZE, "%u\n",
55336 - atomic_read(&dev->bytes_sent));
55337 + atomic_read_unchecked(&dev->bytes_sent));
55338 }
55339
55340 static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
55341 @@ -1400,7 +1402,7 @@ static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
55342 struct fb_info *fb_info = dev_get_drvdata(fbdev);
55343 struct dlfb_data *dev = fb_info->par;
55344 return snprintf(buf, PAGE_SIZE, "%u\n",
55345 - atomic_read(&dev->cpu_kcycles_used));
55346 + atomic_read_unchecked(&dev->cpu_kcycles_used));
55347 }
55348
55349 static ssize_t edid_show(
55350 @@ -1460,10 +1462,10 @@ static ssize_t metrics_reset_store(struct device *fbdev,
55351 struct fb_info *fb_info = dev_get_drvdata(fbdev);
55352 struct dlfb_data *dev = fb_info->par;
55353
55354 - atomic_set(&dev->bytes_rendered, 0);
55355 - atomic_set(&dev->bytes_identical, 0);
55356 - atomic_set(&dev->bytes_sent, 0);
55357 - atomic_set(&dev->cpu_kcycles_used, 0);
55358 + atomic_set_unchecked(&dev->bytes_rendered, 0);
55359 + atomic_set_unchecked(&dev->bytes_identical, 0);
55360 + atomic_set_unchecked(&dev->bytes_sent, 0);
55361 + atomic_set_unchecked(&dev->cpu_kcycles_used, 0);
55362
55363 return count;
55364 }
55365 diff --git a/drivers/video/uvesafb.c b/drivers/video/uvesafb.c
55366 index 256fba7..6e75516 100644
55367 --- a/drivers/video/uvesafb.c
55368 +++ b/drivers/video/uvesafb.c
55369 @@ -19,6 +19,7 @@
55370 #include <linux/io.h>
55371 #include <linux/mutex.h>
55372 #include <linux/slab.h>
55373 +#include <linux/moduleloader.h>
55374 #include <video/edid.h>
55375 #include <video/uvesafb.h>
55376 #ifdef CONFIG_X86
55377 @@ -565,10 +566,32 @@ static int uvesafb_vbe_getpmi(struct uvesafb_ktask *task,
55378 if ((task->t.regs.eax & 0xffff) != 0x4f || task->t.regs.es < 0xc000) {
55379 par->pmi_setpal = par->ypan = 0;
55380 } else {
55381 +
55382 +#ifdef CONFIG_PAX_KERNEXEC
55383 +#ifdef CONFIG_MODULES
55384 + par->pmi_code = module_alloc_exec((u16)task->t.regs.ecx);
55385 +#endif
55386 + if (!par->pmi_code) {
55387 + par->pmi_setpal = par->ypan = 0;
55388 + return 0;
55389 + }
55390 +#endif
55391 +
55392 par->pmi_base = (u16 *)phys_to_virt(((u32)task->t.regs.es << 4)
55393 + task->t.regs.edi);
55394 +
55395 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
55396 + pax_open_kernel();
55397 + memcpy(par->pmi_code, par->pmi_base, (u16)task->t.regs.ecx);
55398 + pax_close_kernel();
55399 +
55400 + par->pmi_start = ktva_ktla(par->pmi_code + par->pmi_base[1]);
55401 + par->pmi_pal = ktva_ktla(par->pmi_code + par->pmi_base[2]);
55402 +#else
55403 par->pmi_start = (u8 *)par->pmi_base + par->pmi_base[1];
55404 par->pmi_pal = (u8 *)par->pmi_base + par->pmi_base[2];
55405 +#endif
55406 +
55407 printk(KERN_INFO "uvesafb: protected mode interface info at "
55408 "%04x:%04x\n",
55409 (u16)task->t.regs.es, (u16)task->t.regs.edi);
55410 @@ -813,13 +836,14 @@ static int uvesafb_vbe_init(struct fb_info *info)
55411 par->ypan = ypan;
55412
55413 if (par->pmi_setpal || par->ypan) {
55414 +#if !defined(CONFIG_MODULES) || !defined(CONFIG_PAX_KERNEXEC)
55415 if (__supported_pte_mask & _PAGE_NX) {
55416 par->pmi_setpal = par->ypan = 0;
55417 printk(KERN_WARNING "uvesafb: NX protection is active, "
55418 "better not use the PMI.\n");
55419 - } else {
55420 + } else
55421 +#endif
55422 uvesafb_vbe_getpmi(task, par);
55423 - }
55424 }
55425 #else
55426 /* The protected mode interface is not available on non-x86. */
55427 @@ -1453,8 +1477,11 @@ static void uvesafb_init_info(struct fb_info *info, struct vbe_mode_ib *mode)
55428 info->fix.ywrapstep = (par->ypan > 1) ? 1 : 0;
55429
55430 /* Disable blanking if the user requested so. */
55431 - if (!blank)
55432 - info->fbops->fb_blank = NULL;
55433 + if (!blank) {
55434 + pax_open_kernel();
55435 + *(void **)&info->fbops->fb_blank = NULL;
55436 + pax_close_kernel();
55437 + }
55438
55439 /*
55440 * Find out how much IO memory is required for the mode with
55441 @@ -1530,8 +1557,11 @@ static void uvesafb_init_info(struct fb_info *info, struct vbe_mode_ib *mode)
55442 info->flags = FBINFO_FLAG_DEFAULT |
55443 (par->ypan ? FBINFO_HWACCEL_YPAN : 0);
55444
55445 - if (!par->ypan)
55446 - info->fbops->fb_pan_display = NULL;
55447 + if (!par->ypan) {
55448 + pax_open_kernel();
55449 + *(void **)&info->fbops->fb_pan_display = NULL;
55450 + pax_close_kernel();
55451 + }
55452 }
55453
55454 static void uvesafb_init_mtrr(struct fb_info *info)
55455 @@ -1792,6 +1822,11 @@ out_mode:
55456 out:
55457 kfree(par->vbe_modes);
55458
55459 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
55460 + if (par->pmi_code)
55461 + module_free_exec(NULL, par->pmi_code);
55462 +#endif
55463 +
55464 framebuffer_release(info);
55465 return err;
55466 }
55467 @@ -1816,6 +1851,12 @@ static int uvesafb_remove(struct platform_device *dev)
55468 kfree(par->vbe_modes);
55469 kfree(par->vbe_state_orig);
55470 kfree(par->vbe_state_saved);
55471 +
55472 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
55473 + if (par->pmi_code)
55474 + module_free_exec(NULL, par->pmi_code);
55475 +#endif
55476 +
55477 }
55478
55479 framebuffer_release(info);
55480 diff --git a/drivers/video/vesafb.c b/drivers/video/vesafb.c
55481 index 1c7da3b..56ea0bd 100644
55482 --- a/drivers/video/vesafb.c
55483 +++ b/drivers/video/vesafb.c
55484 @@ -9,6 +9,7 @@
55485 */
55486
55487 #include <linux/module.h>
55488 +#include <linux/moduleloader.h>
55489 #include <linux/kernel.h>
55490 #include <linux/errno.h>
55491 #include <linux/string.h>
55492 @@ -52,8 +53,8 @@ static int vram_remap; /* Set amount of memory to be used */
55493 static int vram_total; /* Set total amount of memory */
55494 static int pmi_setpal __read_mostly = 1; /* pmi for palette changes ??? */
55495 static int ypan __read_mostly; /* 0..nothing, 1..ypan, 2..ywrap */
55496 -static void (*pmi_start)(void) __read_mostly;
55497 -static void (*pmi_pal) (void) __read_mostly;
55498 +static void (*pmi_start)(void) __read_only;
55499 +static void (*pmi_pal) (void) __read_only;
55500 static int depth __read_mostly;
55501 static int vga_compat __read_mostly;
55502 /* --------------------------------------------------------------------- */
55503 @@ -234,6 +235,7 @@ static int vesafb_probe(struct platform_device *dev)
55504 unsigned int size_remap;
55505 unsigned int size_total;
55506 char *option = NULL;
55507 + void *pmi_code = NULL;
55508
55509 /* ignore error return of fb_get_options */
55510 fb_get_options("vesafb", &option);
55511 @@ -280,10 +282,6 @@ static int vesafb_probe(struct platform_device *dev)
55512 size_remap = size_total;
55513 vesafb_fix.smem_len = size_remap;
55514
55515 -#ifndef __i386__
55516 - screen_info.vesapm_seg = 0;
55517 -#endif
55518 -
55519 if (!request_mem_region(vesafb_fix.smem_start, size_total, "vesafb")) {
55520 printk(KERN_WARNING
55521 "vesafb: cannot reserve video memory at 0x%lx\n",
55522 @@ -312,9 +310,21 @@ static int vesafb_probe(struct platform_device *dev)
55523 printk(KERN_INFO "vesafb: mode is %dx%dx%d, linelength=%d, pages=%d\n",
55524 vesafb_defined.xres, vesafb_defined.yres, vesafb_defined.bits_per_pixel, vesafb_fix.line_length, screen_info.pages);
55525
55526 +#ifdef __i386__
55527 +
55528 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
55529 + pmi_code = module_alloc_exec(screen_info.vesapm_size);
55530 + if (!pmi_code)
55531 +#elif !defined(CONFIG_PAX_KERNEXEC)
55532 + if (0)
55533 +#endif
55534 +
55535 +#endif
55536 + screen_info.vesapm_seg = 0;
55537 +
55538 if (screen_info.vesapm_seg) {
55539 - printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x\n",
55540 - screen_info.vesapm_seg,screen_info.vesapm_off);
55541 + printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x %04x bytes\n",
55542 + screen_info.vesapm_seg,screen_info.vesapm_off,screen_info.vesapm_size);
55543 }
55544
55545 if (screen_info.vesapm_seg < 0xc000)
55546 @@ -322,9 +332,25 @@ static int vesafb_probe(struct platform_device *dev)
55547
55548 if (ypan || pmi_setpal) {
55549 unsigned short *pmi_base;
55550 +
55551 pmi_base = (unsigned short*)phys_to_virt(((unsigned long)screen_info.vesapm_seg << 4) + screen_info.vesapm_off);
55552 - pmi_start = (void*)((char*)pmi_base + pmi_base[1]);
55553 - pmi_pal = (void*)((char*)pmi_base + pmi_base[2]);
55554 +
55555 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
55556 + pax_open_kernel();
55557 + memcpy(pmi_code, pmi_base, screen_info.vesapm_size);
55558 +#else
55559 + pmi_code = pmi_base;
55560 +#endif
55561 +
55562 + pmi_start = (void*)((char*)pmi_code + pmi_base[1]);
55563 + pmi_pal = (void*)((char*)pmi_code + pmi_base[2]);
55564 +
55565 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
55566 + pmi_start = ktva_ktla(pmi_start);
55567 + pmi_pal = ktva_ktla(pmi_pal);
55568 + pax_close_kernel();
55569 +#endif
55570 +
55571 printk(KERN_INFO "vesafb: pmi: set display start = %p, set palette = %p\n",pmi_start,pmi_pal);
55572 if (pmi_base[3]) {
55573 printk(KERN_INFO "vesafb: pmi: ports = ");
55574 @@ -477,8 +503,11 @@ static int vesafb_probe(struct platform_device *dev)
55575 info->flags = FBINFO_FLAG_DEFAULT | FBINFO_MISC_FIRMWARE |
55576 (ypan ? FBINFO_HWACCEL_YPAN : 0);
55577
55578 - if (!ypan)
55579 - info->fbops->fb_pan_display = NULL;
55580 + if (!ypan) {
55581 + pax_open_kernel();
55582 + *(void **)&info->fbops->fb_pan_display = NULL;
55583 + pax_close_kernel();
55584 + }
55585
55586 if (fb_alloc_cmap(&info->cmap, 256, 0) < 0) {
55587 err = -ENOMEM;
55588 @@ -492,6 +521,11 @@ static int vesafb_probe(struct platform_device *dev)
55589 fb_info(info, "%s frame buffer device\n", info->fix.id);
55590 return 0;
55591 err:
55592 +
55593 +#if defined(__i386__) && defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
55594 + module_free_exec(NULL, pmi_code);
55595 +#endif
55596 +
55597 if (info->screen_base)
55598 iounmap(info->screen_base);
55599 framebuffer_release(info);
55600 diff --git a/drivers/video/via/via_clock.h b/drivers/video/via/via_clock.h
55601 index 88714ae..16c2e11 100644
55602 --- a/drivers/video/via/via_clock.h
55603 +++ b/drivers/video/via/via_clock.h
55604 @@ -56,7 +56,7 @@ struct via_clock {
55605
55606 void (*set_engine_pll_state)(u8 state);
55607 void (*set_engine_pll)(struct via_pll_config config);
55608 -};
55609 +} __no_const;
55610
55611
55612 static inline u32 get_pll_internal_frequency(u32 ref_freq,
55613 diff --git a/drivers/xen/xenfs/xenstored.c b/drivers/xen/xenfs/xenstored.c
55614 index fef20db..d28b1ab 100644
55615 --- a/drivers/xen/xenfs/xenstored.c
55616 +++ b/drivers/xen/xenfs/xenstored.c
55617 @@ -24,7 +24,12 @@ static int xsd_release(struct inode *inode, struct file *file)
55618 static int xsd_kva_open(struct inode *inode, struct file *file)
55619 {
55620 file->private_data = (void *)kasprintf(GFP_KERNEL, "0x%p",
55621 +#ifdef CONFIG_GRKERNSEC_HIDESYM
55622 + NULL);
55623 +#else
55624 xen_store_interface);
55625 +#endif
55626 +
55627 if (!file->private_data)
55628 return -ENOMEM;
55629 return 0;
55630 diff --git a/fs/9p/vfs_addr.c b/fs/9p/vfs_addr.c
55631 index 9ff073f..05cef23 100644
55632 --- a/fs/9p/vfs_addr.c
55633 +++ b/fs/9p/vfs_addr.c
55634 @@ -187,7 +187,7 @@ static int v9fs_vfs_writepage_locked(struct page *page)
55635
55636 retval = v9fs_file_write_internal(inode,
55637 v9inode->writeback_fid,
55638 - (__force const char __user *)buffer,
55639 + (const char __force_user *)buffer,
55640 len, &offset, 0);
55641 if (retval > 0)
55642 retval = 0;
55643 diff --git a/fs/9p/vfs_inode.c b/fs/9p/vfs_inode.c
55644 index 4e65aa9..043dc9a 100644
55645 --- a/fs/9p/vfs_inode.c
55646 +++ b/fs/9p/vfs_inode.c
55647 @@ -1306,7 +1306,7 @@ static void *v9fs_vfs_follow_link(struct dentry *dentry, struct nameidata *nd)
55648 void
55649 v9fs_vfs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
55650 {
55651 - char *s = nd_get_link(nd);
55652 + const char *s = nd_get_link(nd);
55653
55654 p9_debug(P9_DEBUG_VFS, " %s %s\n",
55655 dentry->d_name.name, IS_ERR(s) ? "<error>" : s);
55656 diff --git a/fs/Kconfig.binfmt b/fs/Kconfig.binfmt
55657 index 370b24c..ff0be7b 100644
55658 --- a/fs/Kconfig.binfmt
55659 +++ b/fs/Kconfig.binfmt
55660 @@ -103,7 +103,7 @@ config HAVE_AOUT
55661
55662 config BINFMT_AOUT
55663 tristate "Kernel support for a.out and ECOFF binaries"
55664 - depends on HAVE_AOUT
55665 + depends on HAVE_AOUT && BROKEN
55666 ---help---
55667 A.out (Assembler.OUTput) is a set of formats for libraries and
55668 executables used in the earliest versions of UNIX. Linux used
55669 diff --git a/fs/afs/inode.c b/fs/afs/inode.c
55670 index ce25d75..dc09eeb 100644
55671 --- a/fs/afs/inode.c
55672 +++ b/fs/afs/inode.c
55673 @@ -141,7 +141,7 @@ struct inode *afs_iget_autocell(struct inode *dir, const char *dev_name,
55674 struct afs_vnode *vnode;
55675 struct super_block *sb;
55676 struct inode *inode;
55677 - static atomic_t afs_autocell_ino;
55678 + static atomic_unchecked_t afs_autocell_ino;
55679
55680 _enter("{%x:%u},%*.*s,",
55681 AFS_FS_I(dir)->fid.vid, AFS_FS_I(dir)->fid.vnode,
55682 @@ -154,7 +154,7 @@ struct inode *afs_iget_autocell(struct inode *dir, const char *dev_name,
55683 data.fid.unique = 0;
55684 data.fid.vnode = 0;
55685
55686 - inode = iget5_locked(sb, atomic_inc_return(&afs_autocell_ino),
55687 + inode = iget5_locked(sb, atomic_inc_return_unchecked(&afs_autocell_ino),
55688 afs_iget5_autocell_test, afs_iget5_set,
55689 &data);
55690 if (!inode) {
55691 diff --git a/fs/aio.c b/fs/aio.c
55692 index 062a5f6..e5618e0 100644
55693 --- a/fs/aio.c
55694 +++ b/fs/aio.c
55695 @@ -374,7 +374,7 @@ static int aio_setup_ring(struct kioctx *ctx)
55696 size += sizeof(struct io_event) * nr_events;
55697
55698 nr_pages = PFN_UP(size);
55699 - if (nr_pages < 0)
55700 + if (nr_pages <= 0)
55701 return -EINVAL;
55702
55703 file = aio_private_file(ctx, nr_pages);
55704 diff --git a/fs/anon_inodes.c b/fs/anon_inodes.c
55705 index 2408473..80ef38c 100644
55706 --- a/fs/anon_inodes.c
55707 +++ b/fs/anon_inodes.c
55708 @@ -41,19 +41,8 @@ static const struct dentry_operations anon_inodefs_dentry_operations = {
55709 static struct dentry *anon_inodefs_mount(struct file_system_type *fs_type,
55710 int flags, const char *dev_name, void *data)
55711 {
55712 - struct dentry *root;
55713 - root = mount_pseudo(fs_type, "anon_inode:", NULL,
55714 + return mount_pseudo(fs_type, "anon_inode:", NULL,
55715 &anon_inodefs_dentry_operations, ANON_INODE_FS_MAGIC);
55716 - if (!IS_ERR(root)) {
55717 - struct super_block *s = root->d_sb;
55718 - anon_inode_inode = alloc_anon_inode(s);
55719 - if (IS_ERR(anon_inode_inode)) {
55720 - dput(root);
55721 - deactivate_locked_super(s);
55722 - root = ERR_CAST(anon_inode_inode);
55723 - }
55724 - }
55725 - return root;
55726 }
55727
55728 static struct file_system_type anon_inode_fs_type = {
55729 @@ -175,22 +164,15 @@ EXPORT_SYMBOL_GPL(anon_inode_getfd);
55730
55731 static int __init anon_inode_init(void)
55732 {
55733 - int error;
55734 -
55735 - error = register_filesystem(&anon_inode_fs_type);
55736 - if (error)
55737 - goto err_exit;
55738 anon_inode_mnt = kern_mount(&anon_inode_fs_type);
55739 - if (IS_ERR(anon_inode_mnt)) {
55740 - error = PTR_ERR(anon_inode_mnt);
55741 - goto err_unregister_filesystem;
55742 - }
55743 + if (IS_ERR(anon_inode_mnt))
55744 + panic("anon_inode_init() kernel mount failed (%ld)\n", PTR_ERR(anon_inode_mnt));
55745 +
55746 + anon_inode_inode = alloc_anon_inode(anon_inode_mnt->mnt_sb);
55747 + if (IS_ERR(anon_inode_inode))
55748 + panic("anon_inode_init() inode allocation failed (%ld)\n", PTR_ERR(anon_inode_inode));
55749 +
55750 return 0;
55751 -
55752 -err_unregister_filesystem:
55753 - unregister_filesystem(&anon_inode_fs_type);
55754 -err_exit:
55755 - panic(KERN_ERR "anon_inode_init() failed (%d)\n", error);
55756 }
55757
55758 fs_initcall(anon_inode_init);
55759 diff --git a/fs/attr.c b/fs/attr.c
55760 index 5d4e59d..fd02418 100644
55761 --- a/fs/attr.c
55762 +++ b/fs/attr.c
55763 @@ -102,6 +102,7 @@ int inode_newsize_ok(const struct inode *inode, loff_t offset)
55764 unsigned long limit;
55765
55766 limit = rlimit(RLIMIT_FSIZE);
55767 + gr_learn_resource(current, RLIMIT_FSIZE, (unsigned long)offset, 1);
55768 if (limit != RLIM_INFINITY && offset > limit)
55769 goto out_sig;
55770 if (offset > inode->i_sb->s_maxbytes)
55771 diff --git a/fs/autofs4/waitq.c b/fs/autofs4/waitq.c
55772 index 689e40d..515cac5 100644
55773 --- a/fs/autofs4/waitq.c
55774 +++ b/fs/autofs4/waitq.c
55775 @@ -59,7 +59,7 @@ static int autofs4_write(struct autofs_sb_info *sbi,
55776 {
55777 unsigned long sigpipe, flags;
55778 mm_segment_t fs;
55779 - const char *data = (const char *)addr;
55780 + const char __user *data = (const char __force_user *)addr;
55781 ssize_t wr = 0;
55782
55783 sigpipe = sigismember(&current->pending.signal, SIGPIPE);
55784 @@ -340,6 +340,10 @@ static int validate_request(struct autofs_wait_queue **wait,
55785 return 1;
55786 }
55787
55788 +#ifdef CONFIG_GRKERNSEC_HIDESYM
55789 +static atomic_unchecked_t autofs_dummy_name_id = ATOMIC_INIT(0);
55790 +#endif
55791 +
55792 int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
55793 enum autofs_notify notify)
55794 {
55795 @@ -373,7 +377,12 @@ int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
55796
55797 /* If this is a direct mount request create a dummy name */
55798 if (IS_ROOT(dentry) && autofs_type_trigger(sbi->type))
55799 +#ifdef CONFIG_GRKERNSEC_HIDESYM
55800 + /* this name does get written to userland via autofs4_write() */
55801 + qstr.len = sprintf(name, "%08x", atomic_inc_return_unchecked(&autofs_dummy_name_id));
55802 +#else
55803 qstr.len = sprintf(name, "%p", dentry);
55804 +#endif
55805 else {
55806 qstr.len = autofs4_getpath(sbi, dentry, &name);
55807 if (!qstr.len) {
55808 diff --git a/fs/befs/endian.h b/fs/befs/endian.h
55809 index 2722387..56059b5 100644
55810 --- a/fs/befs/endian.h
55811 +++ b/fs/befs/endian.h
55812 @@ -11,7 +11,7 @@
55813
55814 #include <asm/byteorder.h>
55815
55816 -static inline u64
55817 +static inline u64 __intentional_overflow(-1)
55818 fs64_to_cpu(const struct super_block *sb, fs64 n)
55819 {
55820 if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE)
55821 @@ -29,7 +29,7 @@ cpu_to_fs64(const struct super_block *sb, u64 n)
55822 return (__force fs64)cpu_to_be64(n);
55823 }
55824
55825 -static inline u32
55826 +static inline u32 __intentional_overflow(-1)
55827 fs32_to_cpu(const struct super_block *sb, fs32 n)
55828 {
55829 if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE)
55830 @@ -47,7 +47,7 @@ cpu_to_fs32(const struct super_block *sb, u32 n)
55831 return (__force fs32)cpu_to_be32(n);
55832 }
55833
55834 -static inline u16
55835 +static inline u16 __intentional_overflow(-1)
55836 fs16_to_cpu(const struct super_block *sb, fs16 n)
55837 {
55838 if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE)
55839 diff --git a/fs/binfmt_aout.c b/fs/binfmt_aout.c
55840 index ca0ba15..0fa3257 100644
55841 --- a/fs/binfmt_aout.c
55842 +++ b/fs/binfmt_aout.c
55843 @@ -16,6 +16,7 @@
55844 #include <linux/string.h>
55845 #include <linux/fs.h>
55846 #include <linux/file.h>
55847 +#include <linux/security.h>
55848 #include <linux/stat.h>
55849 #include <linux/fcntl.h>
55850 #include <linux/ptrace.h>
55851 @@ -58,6 +59,8 @@ static int aout_core_dump(struct coredump_params *cprm)
55852 #endif
55853 # define START_STACK(u) ((void __user *)u.start_stack)
55854
55855 + memset(&dump, 0, sizeof(dump));
55856 +
55857 fs = get_fs();
55858 set_fs(KERNEL_DS);
55859 has_dumped = 1;
55860 @@ -68,10 +71,12 @@ static int aout_core_dump(struct coredump_params *cprm)
55861
55862 /* If the size of the dump file exceeds the rlimit, then see what would happen
55863 if we wrote the stack, but not the data area. */
55864 + gr_learn_resource(current, RLIMIT_CORE, (dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE, 1);
55865 if ((dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE > cprm->limit)
55866 dump.u_dsize = 0;
55867
55868 /* Make sure we have enough room to write the stack and data areas. */
55869 + gr_learn_resource(current, RLIMIT_CORE, (dump.u_ssize + 1) * PAGE_SIZE, 1);
55870 if ((dump.u_ssize + 1) * PAGE_SIZE > cprm->limit)
55871 dump.u_ssize = 0;
55872
55873 @@ -232,6 +237,8 @@ static int load_aout_binary(struct linux_binprm * bprm)
55874 rlim = rlimit(RLIMIT_DATA);
55875 if (rlim >= RLIM_INFINITY)
55876 rlim = ~0;
55877 +
55878 + gr_learn_resource(current, RLIMIT_DATA, ex.a_data + ex.a_bss, 1);
55879 if (ex.a_data + ex.a_bss > rlim)
55880 return -ENOMEM;
55881
55882 @@ -264,6 +271,27 @@ static int load_aout_binary(struct linux_binprm * bprm)
55883
55884 install_exec_creds(bprm);
55885
55886 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
55887 + current->mm->pax_flags = 0UL;
55888 +#endif
55889 +
55890 +#ifdef CONFIG_PAX_PAGEEXEC
55891 + if (!(N_FLAGS(ex) & F_PAX_PAGEEXEC)) {
55892 + current->mm->pax_flags |= MF_PAX_PAGEEXEC;
55893 +
55894 +#ifdef CONFIG_PAX_EMUTRAMP
55895 + if (N_FLAGS(ex) & F_PAX_EMUTRAMP)
55896 + current->mm->pax_flags |= MF_PAX_EMUTRAMP;
55897 +#endif
55898 +
55899 +#ifdef CONFIG_PAX_MPROTECT
55900 + if (!(N_FLAGS(ex) & F_PAX_MPROTECT))
55901 + current->mm->pax_flags |= MF_PAX_MPROTECT;
55902 +#endif
55903 +
55904 + }
55905 +#endif
55906 +
55907 if (N_MAGIC(ex) == OMAGIC) {
55908 unsigned long text_addr, map_size;
55909 loff_t pos;
55910 @@ -321,7 +349,7 @@ static int load_aout_binary(struct linux_binprm * bprm)
55911 }
55912
55913 error = vm_mmap(bprm->file, N_DATADDR(ex), ex.a_data,
55914 - PROT_READ | PROT_WRITE | PROT_EXEC,
55915 + PROT_READ | PROT_WRITE,
55916 MAP_FIXED | MAP_PRIVATE | MAP_DENYWRITE | MAP_EXECUTABLE,
55917 fd_offset + ex.a_text);
55918 if (error != N_DATADDR(ex)) {
55919 diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c
55920 index 571a423..eed5754 100644
55921 --- a/fs/binfmt_elf.c
55922 +++ b/fs/binfmt_elf.c
55923 @@ -34,6 +34,7 @@
55924 #include <linux/utsname.h>
55925 #include <linux/coredump.h>
55926 #include <linux/sched.h>
55927 +#include <linux/xattr.h>
55928 #include <asm/uaccess.h>
55929 #include <asm/param.h>
55930 #include <asm/page.h>
55931 @@ -48,7 +49,7 @@
55932 static int load_elf_binary(struct linux_binprm *bprm);
55933 static int load_elf_library(struct file *);
55934 static unsigned long elf_map(struct file *, unsigned long, struct elf_phdr *,
55935 - int, int, unsigned long);
55936 + int, int, unsigned long) __intentional_overflow(-1);
55937
55938 /*
55939 * If we don't support core dumping, then supply a NULL so we
55940 @@ -60,6 +61,14 @@ static int elf_core_dump(struct coredump_params *cprm);
55941 #define elf_core_dump NULL
55942 #endif
55943
55944 +#ifdef CONFIG_PAX_MPROTECT
55945 +static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags);
55946 +#endif
55947 +
55948 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
55949 +static void elf_handle_mmap(struct file *file);
55950 +#endif
55951 +
55952 #if ELF_EXEC_PAGESIZE > PAGE_SIZE
55953 #define ELF_MIN_ALIGN ELF_EXEC_PAGESIZE
55954 #else
55955 @@ -79,6 +88,15 @@ static struct linux_binfmt elf_format = {
55956 .load_binary = load_elf_binary,
55957 .load_shlib = load_elf_library,
55958 .core_dump = elf_core_dump,
55959 +
55960 +#ifdef CONFIG_PAX_MPROTECT
55961 + .handle_mprotect= elf_handle_mprotect,
55962 +#endif
55963 +
55964 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
55965 + .handle_mmap = elf_handle_mmap,
55966 +#endif
55967 +
55968 .min_coredump = ELF_EXEC_PAGESIZE,
55969 };
55970
55971 @@ -86,6 +104,8 @@ static struct linux_binfmt elf_format = {
55972
55973 static int set_brk(unsigned long start, unsigned long end)
55974 {
55975 + unsigned long e = end;
55976 +
55977 start = ELF_PAGEALIGN(start);
55978 end = ELF_PAGEALIGN(end);
55979 if (end > start) {
55980 @@ -94,7 +114,7 @@ static int set_brk(unsigned long start, unsigned long end)
55981 if (BAD_ADDR(addr))
55982 return addr;
55983 }
55984 - current->mm->start_brk = current->mm->brk = end;
55985 + current->mm->start_brk = current->mm->brk = e;
55986 return 0;
55987 }
55988
55989 @@ -155,12 +175,13 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
55990 elf_addr_t __user *u_rand_bytes;
55991 const char *k_platform = ELF_PLATFORM;
55992 const char *k_base_platform = ELF_BASE_PLATFORM;
55993 - unsigned char k_rand_bytes[16];
55994 + u32 k_rand_bytes[4];
55995 int items;
55996 elf_addr_t *elf_info;
55997 int ei_index = 0;
55998 const struct cred *cred = current_cred();
55999 struct vm_area_struct *vma;
56000 + unsigned long saved_auxv[AT_VECTOR_SIZE];
56001
56002 /*
56003 * In some cases (e.g. Hyper-Threading), we want to avoid L1
56004 @@ -202,8 +223,12 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
56005 * Generate 16 random bytes for userspace PRNG seeding.
56006 */
56007 get_random_bytes(k_rand_bytes, sizeof(k_rand_bytes));
56008 - u_rand_bytes = (elf_addr_t __user *)
56009 - STACK_ALLOC(p, sizeof(k_rand_bytes));
56010 + prandom_seed(k_rand_bytes[0] ^ prandom_u32());
56011 + prandom_seed(k_rand_bytes[1] ^ prandom_u32());
56012 + prandom_seed(k_rand_bytes[2] ^ prandom_u32());
56013 + prandom_seed(k_rand_bytes[3] ^ prandom_u32());
56014 + p = STACK_ROUND(p, sizeof(k_rand_bytes));
56015 + u_rand_bytes = (elf_addr_t __user *) p;
56016 if (__copy_to_user(u_rand_bytes, k_rand_bytes, sizeof(k_rand_bytes)))
56017 return -EFAULT;
56018
56019 @@ -318,9 +343,11 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
56020 return -EFAULT;
56021 current->mm->env_end = p;
56022
56023 + memcpy(saved_auxv, elf_info, ei_index * sizeof(elf_addr_t));
56024 +
56025 /* Put the elf_info on the stack in the right place. */
56026 sp = (elf_addr_t __user *)envp + 1;
56027 - if (copy_to_user(sp, elf_info, ei_index * sizeof(elf_addr_t)))
56028 + if (copy_to_user(sp, saved_auxv, ei_index * sizeof(elf_addr_t)))
56029 return -EFAULT;
56030 return 0;
56031 }
56032 @@ -388,15 +415,14 @@ static unsigned long total_mapping_size(struct elf_phdr *cmds, int nr)
56033 an ELF header */
56034
56035 static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
56036 - struct file *interpreter, unsigned long *interp_map_addr,
56037 - unsigned long no_base)
56038 + struct file *interpreter, unsigned long no_base)
56039 {
56040 struct elf_phdr *elf_phdata;
56041 struct elf_phdr *eppnt;
56042 - unsigned long load_addr = 0;
56043 + unsigned long load_addr = 0, pax_task_size = TASK_SIZE;
56044 int load_addr_set = 0;
56045 unsigned long last_bss = 0, elf_bss = 0;
56046 - unsigned long error = ~0UL;
56047 + unsigned long error = -EINVAL;
56048 unsigned long total_size;
56049 int retval, i, size;
56050
56051 @@ -442,6 +468,11 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
56052 goto out_close;
56053 }
56054
56055 +#ifdef CONFIG_PAX_SEGMEXEC
56056 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
56057 + pax_task_size = SEGMEXEC_TASK_SIZE;
56058 +#endif
56059 +
56060 eppnt = elf_phdata;
56061 for (i = 0; i < interp_elf_ex->e_phnum; i++, eppnt++) {
56062 if (eppnt->p_type == PT_LOAD) {
56063 @@ -465,8 +496,6 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
56064 map_addr = elf_map(interpreter, load_addr + vaddr,
56065 eppnt, elf_prot, elf_type, total_size);
56066 total_size = 0;
56067 - if (!*interp_map_addr)
56068 - *interp_map_addr = map_addr;
56069 error = map_addr;
56070 if (BAD_ADDR(map_addr))
56071 goto out_close;
56072 @@ -485,8 +514,8 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
56073 k = load_addr + eppnt->p_vaddr;
56074 if (BAD_ADDR(k) ||
56075 eppnt->p_filesz > eppnt->p_memsz ||
56076 - eppnt->p_memsz > TASK_SIZE ||
56077 - TASK_SIZE - eppnt->p_memsz < k) {
56078 + eppnt->p_memsz > pax_task_size ||
56079 + pax_task_size - eppnt->p_memsz < k) {
56080 error = -ENOMEM;
56081 goto out_close;
56082 }
56083 @@ -525,9 +554,11 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
56084 elf_bss = ELF_PAGESTART(elf_bss + ELF_MIN_ALIGN - 1);
56085
56086 /* Map the last of the bss segment */
56087 - error = vm_brk(elf_bss, last_bss - elf_bss);
56088 - if (BAD_ADDR(error))
56089 - goto out_close;
56090 + if (last_bss > elf_bss) {
56091 + error = vm_brk(elf_bss, last_bss - elf_bss);
56092 + if (BAD_ADDR(error))
56093 + goto out_close;
56094 + }
56095 }
56096
56097 error = load_addr;
56098 @@ -538,6 +569,336 @@ out:
56099 return error;
56100 }
56101
56102 +#ifdef CONFIG_PAX_PT_PAX_FLAGS
56103 +#ifdef CONFIG_PAX_SOFTMODE
56104 +static unsigned long pax_parse_pt_pax_softmode(const struct elf_phdr * const elf_phdata)
56105 +{
56106 + unsigned long pax_flags = 0UL;
56107 +
56108 +#ifdef CONFIG_PAX_PAGEEXEC
56109 + if (elf_phdata->p_flags & PF_PAGEEXEC)
56110 + pax_flags |= MF_PAX_PAGEEXEC;
56111 +#endif
56112 +
56113 +#ifdef CONFIG_PAX_SEGMEXEC
56114 + if (elf_phdata->p_flags & PF_SEGMEXEC)
56115 + pax_flags |= MF_PAX_SEGMEXEC;
56116 +#endif
56117 +
56118 +#ifdef CONFIG_PAX_EMUTRAMP
56119 + if ((elf_phdata->p_flags & PF_EMUTRAMP) && (pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)))
56120 + pax_flags |= MF_PAX_EMUTRAMP;
56121 +#endif
56122 +
56123 +#ifdef CONFIG_PAX_MPROTECT
56124 + if (elf_phdata->p_flags & PF_MPROTECT)
56125 + pax_flags |= MF_PAX_MPROTECT;
56126 +#endif
56127 +
56128 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
56129 + if (randomize_va_space && (elf_phdata->p_flags & PF_RANDMMAP))
56130 + pax_flags |= MF_PAX_RANDMMAP;
56131 +#endif
56132 +
56133 + return pax_flags;
56134 +}
56135 +#endif
56136 +
56137 +static unsigned long pax_parse_pt_pax_hardmode(const struct elf_phdr * const elf_phdata)
56138 +{
56139 + unsigned long pax_flags = 0UL;
56140 +
56141 +#ifdef CONFIG_PAX_PAGEEXEC
56142 + if (!(elf_phdata->p_flags & PF_NOPAGEEXEC))
56143 + pax_flags |= MF_PAX_PAGEEXEC;
56144 +#endif
56145 +
56146 +#ifdef CONFIG_PAX_SEGMEXEC
56147 + if (!(elf_phdata->p_flags & PF_NOSEGMEXEC))
56148 + pax_flags |= MF_PAX_SEGMEXEC;
56149 +#endif
56150 +
56151 +#ifdef CONFIG_PAX_EMUTRAMP
56152 + if (!(elf_phdata->p_flags & PF_NOEMUTRAMP))
56153 + pax_flags |= MF_PAX_EMUTRAMP;
56154 +#endif
56155 +
56156 +#ifdef CONFIG_PAX_MPROTECT
56157 + if (!(elf_phdata->p_flags & PF_NOMPROTECT))
56158 + pax_flags |= MF_PAX_MPROTECT;
56159 +#endif
56160 +
56161 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
56162 + if (randomize_va_space && !(elf_phdata->p_flags & PF_NORANDMMAP))
56163 + pax_flags |= MF_PAX_RANDMMAP;
56164 +#endif
56165 +
56166 + return pax_flags;
56167 +}
56168 +#endif
56169 +
56170 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
56171 +#ifdef CONFIG_PAX_SOFTMODE
56172 +static unsigned long pax_parse_xattr_pax_softmode(unsigned long pax_flags_softmode)
56173 +{
56174 + unsigned long pax_flags = 0UL;
56175 +
56176 +#ifdef CONFIG_PAX_PAGEEXEC
56177 + if (pax_flags_softmode & MF_PAX_PAGEEXEC)
56178 + pax_flags |= MF_PAX_PAGEEXEC;
56179 +#endif
56180 +
56181 +#ifdef CONFIG_PAX_SEGMEXEC
56182 + if (pax_flags_softmode & MF_PAX_SEGMEXEC)
56183 + pax_flags |= MF_PAX_SEGMEXEC;
56184 +#endif
56185 +
56186 +#ifdef CONFIG_PAX_EMUTRAMP
56187 + if ((pax_flags_softmode & MF_PAX_EMUTRAMP) && (pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)))
56188 + pax_flags |= MF_PAX_EMUTRAMP;
56189 +#endif
56190 +
56191 +#ifdef CONFIG_PAX_MPROTECT
56192 + if (pax_flags_softmode & MF_PAX_MPROTECT)
56193 + pax_flags |= MF_PAX_MPROTECT;
56194 +#endif
56195 +
56196 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
56197 + if (randomize_va_space && (pax_flags_softmode & MF_PAX_RANDMMAP))
56198 + pax_flags |= MF_PAX_RANDMMAP;
56199 +#endif
56200 +
56201 + return pax_flags;
56202 +}
56203 +#endif
56204 +
56205 +static unsigned long pax_parse_xattr_pax_hardmode(unsigned long pax_flags_hardmode)
56206 +{
56207 + unsigned long pax_flags = 0UL;
56208 +
56209 +#ifdef CONFIG_PAX_PAGEEXEC
56210 + if (!(pax_flags_hardmode & MF_PAX_PAGEEXEC))
56211 + pax_flags |= MF_PAX_PAGEEXEC;
56212 +#endif
56213 +
56214 +#ifdef CONFIG_PAX_SEGMEXEC
56215 + if (!(pax_flags_hardmode & MF_PAX_SEGMEXEC))
56216 + pax_flags |= MF_PAX_SEGMEXEC;
56217 +#endif
56218 +
56219 +#ifdef CONFIG_PAX_EMUTRAMP
56220 + if (!(pax_flags_hardmode & MF_PAX_EMUTRAMP))
56221 + pax_flags |= MF_PAX_EMUTRAMP;
56222 +#endif
56223 +
56224 +#ifdef CONFIG_PAX_MPROTECT
56225 + if (!(pax_flags_hardmode & MF_PAX_MPROTECT))
56226 + pax_flags |= MF_PAX_MPROTECT;
56227 +#endif
56228 +
56229 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
56230 + if (randomize_va_space && !(pax_flags_hardmode & MF_PAX_RANDMMAP))
56231 + pax_flags |= MF_PAX_RANDMMAP;
56232 +#endif
56233 +
56234 + return pax_flags;
56235 +}
56236 +#endif
56237 +
56238 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
56239 +static unsigned long pax_parse_defaults(void)
56240 +{
56241 + unsigned long pax_flags = 0UL;
56242 +
56243 +#ifdef CONFIG_PAX_SOFTMODE
56244 + if (pax_softmode)
56245 + return pax_flags;
56246 +#endif
56247 +
56248 +#ifdef CONFIG_PAX_PAGEEXEC
56249 + pax_flags |= MF_PAX_PAGEEXEC;
56250 +#endif
56251 +
56252 +#ifdef CONFIG_PAX_SEGMEXEC
56253 + pax_flags |= MF_PAX_SEGMEXEC;
56254 +#endif
56255 +
56256 +#ifdef CONFIG_PAX_MPROTECT
56257 + pax_flags |= MF_PAX_MPROTECT;
56258 +#endif
56259 +
56260 +#ifdef CONFIG_PAX_RANDMMAP
56261 + if (randomize_va_space)
56262 + pax_flags |= MF_PAX_RANDMMAP;
56263 +#endif
56264 +
56265 + return pax_flags;
56266 +}
56267 +
56268 +static unsigned long pax_parse_ei_pax(const struct elfhdr * const elf_ex)
56269 +{
56270 + unsigned long pax_flags = PAX_PARSE_FLAGS_FALLBACK;
56271 +
56272 +#ifdef CONFIG_PAX_EI_PAX
56273 +
56274 +#ifdef CONFIG_PAX_SOFTMODE
56275 + if (pax_softmode)
56276 + return pax_flags;
56277 +#endif
56278 +
56279 + pax_flags = 0UL;
56280 +
56281 +#ifdef CONFIG_PAX_PAGEEXEC
56282 + if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_PAGEEXEC))
56283 + pax_flags |= MF_PAX_PAGEEXEC;
56284 +#endif
56285 +
56286 +#ifdef CONFIG_PAX_SEGMEXEC
56287 + if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_SEGMEXEC))
56288 + pax_flags |= MF_PAX_SEGMEXEC;
56289 +#endif
56290 +
56291 +#ifdef CONFIG_PAX_EMUTRAMP
56292 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && (elf_ex->e_ident[EI_PAX] & EF_PAX_EMUTRAMP))
56293 + pax_flags |= MF_PAX_EMUTRAMP;
56294 +#endif
56295 +
56296 +#ifdef CONFIG_PAX_MPROTECT
56297 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && !(elf_ex->e_ident[EI_PAX] & EF_PAX_MPROTECT))
56298 + pax_flags |= MF_PAX_MPROTECT;
56299 +#endif
56300 +
56301 +#ifdef CONFIG_PAX_ASLR
56302 + if (randomize_va_space && !(elf_ex->e_ident[EI_PAX] & EF_PAX_RANDMMAP))
56303 + pax_flags |= MF_PAX_RANDMMAP;
56304 +#endif
56305 +
56306 +#endif
56307 +
56308 + return pax_flags;
56309 +
56310 +}
56311 +
56312 +static unsigned long pax_parse_pt_pax(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata)
56313 +{
56314 +
56315 +#ifdef CONFIG_PAX_PT_PAX_FLAGS
56316 + unsigned long i;
56317 +
56318 + for (i = 0UL; i < elf_ex->e_phnum; i++)
56319 + if (elf_phdata[i].p_type == PT_PAX_FLAGS) {
56320 + if (((elf_phdata[i].p_flags & PF_PAGEEXEC) && (elf_phdata[i].p_flags & PF_NOPAGEEXEC)) ||
56321 + ((elf_phdata[i].p_flags & PF_SEGMEXEC) && (elf_phdata[i].p_flags & PF_NOSEGMEXEC)) ||
56322 + ((elf_phdata[i].p_flags & PF_EMUTRAMP) && (elf_phdata[i].p_flags & PF_NOEMUTRAMP)) ||
56323 + ((elf_phdata[i].p_flags & PF_MPROTECT) && (elf_phdata[i].p_flags & PF_NOMPROTECT)) ||
56324 + ((elf_phdata[i].p_flags & PF_RANDMMAP) && (elf_phdata[i].p_flags & PF_NORANDMMAP)))
56325 + return PAX_PARSE_FLAGS_FALLBACK;
56326 +
56327 +#ifdef CONFIG_PAX_SOFTMODE
56328 + if (pax_softmode)
56329 + return pax_parse_pt_pax_softmode(&elf_phdata[i]);
56330 + else
56331 +#endif
56332 +
56333 + return pax_parse_pt_pax_hardmode(&elf_phdata[i]);
56334 + break;
56335 + }
56336 +#endif
56337 +
56338 + return PAX_PARSE_FLAGS_FALLBACK;
56339 +}
56340 +
56341 +static unsigned long pax_parse_xattr_pax(struct file * const file)
56342 +{
56343 +
56344 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
56345 + ssize_t xattr_size, i;
56346 + unsigned char xattr_value[sizeof("pemrs") - 1];
56347 + unsigned long pax_flags_hardmode = 0UL, pax_flags_softmode = 0UL;
56348 +
56349 + xattr_size = pax_getxattr(file->f_path.dentry, xattr_value, sizeof xattr_value);
56350 + if (xattr_size < 0 || xattr_size > sizeof xattr_value)
56351 + return PAX_PARSE_FLAGS_FALLBACK;
56352 +
56353 + for (i = 0; i < xattr_size; i++)
56354 + switch (xattr_value[i]) {
56355 + default:
56356 + return PAX_PARSE_FLAGS_FALLBACK;
56357 +
56358 +#define parse_flag(option1, option2, flag) \
56359 + case option1: \
56360 + if (pax_flags_hardmode & MF_PAX_##flag) \
56361 + return PAX_PARSE_FLAGS_FALLBACK;\
56362 + pax_flags_hardmode |= MF_PAX_##flag; \
56363 + break; \
56364 + case option2: \
56365 + if (pax_flags_softmode & MF_PAX_##flag) \
56366 + return PAX_PARSE_FLAGS_FALLBACK;\
56367 + pax_flags_softmode |= MF_PAX_##flag; \
56368 + break;
56369 +
56370 + parse_flag('p', 'P', PAGEEXEC);
56371 + parse_flag('e', 'E', EMUTRAMP);
56372 + parse_flag('m', 'M', MPROTECT);
56373 + parse_flag('r', 'R', RANDMMAP);
56374 + parse_flag('s', 'S', SEGMEXEC);
56375 +
56376 +#undef parse_flag
56377 + }
56378 +
56379 + if (pax_flags_hardmode & pax_flags_softmode)
56380 + return PAX_PARSE_FLAGS_FALLBACK;
56381 +
56382 +#ifdef CONFIG_PAX_SOFTMODE
56383 + if (pax_softmode)
56384 + return pax_parse_xattr_pax_softmode(pax_flags_softmode);
56385 + else
56386 +#endif
56387 +
56388 + return pax_parse_xattr_pax_hardmode(pax_flags_hardmode);
56389 +#else
56390 + return PAX_PARSE_FLAGS_FALLBACK;
56391 +#endif
56392 +
56393 +}
56394 +
56395 +static long pax_parse_pax_flags(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata, struct file * const file)
56396 +{
56397 + unsigned long pax_flags, ei_pax_flags, pt_pax_flags, xattr_pax_flags;
56398 +
56399 + pax_flags = pax_parse_defaults();
56400 + ei_pax_flags = pax_parse_ei_pax(elf_ex);
56401 + pt_pax_flags = pax_parse_pt_pax(elf_ex, elf_phdata);
56402 + xattr_pax_flags = pax_parse_xattr_pax(file);
56403 +
56404 + if (pt_pax_flags != PAX_PARSE_FLAGS_FALLBACK &&
56405 + xattr_pax_flags != PAX_PARSE_FLAGS_FALLBACK &&
56406 + pt_pax_flags != xattr_pax_flags)
56407 + return -EINVAL;
56408 + if (xattr_pax_flags != PAX_PARSE_FLAGS_FALLBACK)
56409 + pax_flags = xattr_pax_flags;
56410 + else if (pt_pax_flags != PAX_PARSE_FLAGS_FALLBACK)
56411 + pax_flags = pt_pax_flags;
56412 + else if (ei_pax_flags != PAX_PARSE_FLAGS_FALLBACK)
56413 + pax_flags = ei_pax_flags;
56414 +
56415 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
56416 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
56417 + if ((__supported_pte_mask & _PAGE_NX))
56418 + pax_flags &= ~MF_PAX_SEGMEXEC;
56419 + else
56420 + pax_flags &= ~MF_PAX_PAGEEXEC;
56421 + }
56422 +#endif
56423 +
56424 + if (0 > pax_check_flags(&pax_flags))
56425 + return -EINVAL;
56426 +
56427 + current->mm->pax_flags = pax_flags;
56428 + return 0;
56429 +}
56430 +#endif
56431 +
56432 /*
56433 * These are the functions used to load ELF style executables and shared
56434 * libraries. There is no binary dependent code anywhere else.
56435 @@ -554,6 +915,11 @@ static unsigned long randomize_stack_top(unsigned long stack_top)
56436 {
56437 unsigned int random_variable = 0;
56438
56439 +#ifdef CONFIG_PAX_RANDUSTACK
56440 + if (current->mm->pax_flags & MF_PAX_RANDMMAP)
56441 + return stack_top - current->mm->delta_stack;
56442 +#endif
56443 +
56444 if ((current->flags & PF_RANDOMIZE) &&
56445 !(current->personality & ADDR_NO_RANDOMIZE)) {
56446 random_variable = get_random_int() & STACK_RND_MASK;
56447 @@ -572,7 +938,7 @@ static int load_elf_binary(struct linux_binprm *bprm)
56448 unsigned long load_addr = 0, load_bias = 0;
56449 int load_addr_set = 0;
56450 char * elf_interpreter = NULL;
56451 - unsigned long error;
56452 + unsigned long error = 0;
56453 struct elf_phdr *elf_ppnt, *elf_phdata;
56454 unsigned long elf_bss, elf_brk;
56455 int retval, i;
56456 @@ -582,12 +948,12 @@ static int load_elf_binary(struct linux_binprm *bprm)
56457 unsigned long start_code, end_code, start_data, end_data;
56458 unsigned long reloc_func_desc __maybe_unused = 0;
56459 int executable_stack = EXSTACK_DEFAULT;
56460 - unsigned long def_flags = 0;
56461 struct pt_regs *regs = current_pt_regs();
56462 struct {
56463 struct elfhdr elf_ex;
56464 struct elfhdr interp_elf_ex;
56465 } *loc;
56466 + unsigned long pax_task_size;
56467
56468 loc = kmalloc(sizeof(*loc), GFP_KERNEL);
56469 if (!loc) {
56470 @@ -723,11 +1089,82 @@ static int load_elf_binary(struct linux_binprm *bprm)
56471 goto out_free_dentry;
56472
56473 /* OK, This is the point of no return */
56474 - current->mm->def_flags = def_flags;
56475 + current->mm->def_flags = 0;
56476
56477 /* Do this immediately, since STACK_TOP as used in setup_arg_pages
56478 may depend on the personality. */
56479 SET_PERSONALITY(loc->elf_ex);
56480 +
56481 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
56482 + current->mm->pax_flags = 0UL;
56483 +#endif
56484 +
56485 +#ifdef CONFIG_PAX_DLRESOLVE
56486 + current->mm->call_dl_resolve = 0UL;
56487 +#endif
56488 +
56489 +#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
56490 + current->mm->call_syscall = 0UL;
56491 +#endif
56492 +
56493 +#ifdef CONFIG_PAX_ASLR
56494 + current->mm->delta_mmap = 0UL;
56495 + current->mm->delta_stack = 0UL;
56496 +#endif
56497 +
56498 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
56499 + if (0 > pax_parse_pax_flags(&loc->elf_ex, elf_phdata, bprm->file)) {
56500 + send_sig(SIGKILL, current, 0);
56501 + goto out_free_dentry;
56502 + }
56503 +#endif
56504 +
56505 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
56506 + pax_set_initial_flags(bprm);
56507 +#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
56508 + if (pax_set_initial_flags_func)
56509 + (pax_set_initial_flags_func)(bprm);
56510 +#endif
56511 +
56512 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
56513 + if ((current->mm->pax_flags & MF_PAX_PAGEEXEC) && !(__supported_pte_mask & _PAGE_NX)) {
56514 + current->mm->context.user_cs_limit = PAGE_SIZE;
56515 + current->mm->def_flags |= VM_PAGEEXEC | VM_NOHUGEPAGE;
56516 + }
56517 +#endif
56518 +
56519 +#ifdef CONFIG_PAX_SEGMEXEC
56520 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
56521 + current->mm->context.user_cs_base = SEGMEXEC_TASK_SIZE;
56522 + current->mm->context.user_cs_limit = TASK_SIZE-SEGMEXEC_TASK_SIZE;
56523 + pax_task_size = SEGMEXEC_TASK_SIZE;
56524 + current->mm->def_flags |= VM_NOHUGEPAGE;
56525 + } else
56526 +#endif
56527 +
56528 + pax_task_size = TASK_SIZE;
56529 +
56530 +#if defined(CONFIG_ARCH_TRACK_EXEC_LIMIT) || defined(CONFIG_PAX_SEGMEXEC)
56531 + if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
56532 + set_user_cs(current->mm->context.user_cs_base, current->mm->context.user_cs_limit, get_cpu());
56533 + put_cpu();
56534 + }
56535 +#endif
56536 +
56537 +#ifdef CONFIG_PAX_ASLR
56538 + if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
56539 + current->mm->delta_mmap = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN)-1)) << PAGE_SHIFT;
56540 + current->mm->delta_stack = (pax_get_random_long() & ((1UL << PAX_DELTA_STACK_LEN)-1)) << PAGE_SHIFT;
56541 + }
56542 +#endif
56543 +
56544 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
56545 + if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
56546 + executable_stack = EXSTACK_DISABLE_X;
56547 + current->personality &= ~READ_IMPLIES_EXEC;
56548 + } else
56549 +#endif
56550 +
56551 if (elf_read_implies_exec(loc->elf_ex, executable_stack))
56552 current->personality |= READ_IMPLIES_EXEC;
56553
56554 @@ -817,6 +1254,20 @@ static int load_elf_binary(struct linux_binprm *bprm)
56555 #else
56556 load_bias = ELF_PAGESTART(ELF_ET_DYN_BASE - vaddr);
56557 #endif
56558 +
56559 +#ifdef CONFIG_PAX_RANDMMAP
56560 + /* PaX: randomize base address at the default exe base if requested */
56561 + if ((current->mm->pax_flags & MF_PAX_RANDMMAP) && elf_interpreter) {
56562 +#ifdef CONFIG_SPARC64
56563 + load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << (PAGE_SHIFT+1);
56564 +#else
56565 + load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << PAGE_SHIFT;
56566 +#endif
56567 + load_bias = ELF_PAGESTART(PAX_ELF_ET_DYN_BASE - vaddr + load_bias);
56568 + elf_flags |= MAP_FIXED;
56569 + }
56570 +#endif
56571 +
56572 }
56573
56574 error = elf_map(bprm->file, load_bias + vaddr, elf_ppnt,
56575 @@ -849,9 +1300,9 @@ static int load_elf_binary(struct linux_binprm *bprm)
56576 * allowed task size. Note that p_filesz must always be
56577 * <= p_memsz so it is only necessary to check p_memsz.
56578 */
56579 - if (BAD_ADDR(k) || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
56580 - elf_ppnt->p_memsz > TASK_SIZE ||
56581 - TASK_SIZE - elf_ppnt->p_memsz < k) {
56582 + if (k >= pax_task_size || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
56583 + elf_ppnt->p_memsz > pax_task_size ||
56584 + pax_task_size - elf_ppnt->p_memsz < k) {
56585 /* set_brk can never work. Avoid overflows. */
56586 send_sig(SIGKILL, current, 0);
56587 retval = -EINVAL;
56588 @@ -890,17 +1341,45 @@ static int load_elf_binary(struct linux_binprm *bprm)
56589 goto out_free_dentry;
56590 }
56591 if (likely(elf_bss != elf_brk) && unlikely(padzero(elf_bss))) {
56592 - send_sig(SIGSEGV, current, 0);
56593 - retval = -EFAULT; /* Nobody gets to see this, but.. */
56594 - goto out_free_dentry;
56595 + /*
56596 + * This bss-zeroing can fail if the ELF
56597 + * file specifies odd protections. So
56598 + * we don't check the return value
56599 + */
56600 }
56601
56602 +#ifdef CONFIG_PAX_RANDMMAP
56603 + if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
56604 + unsigned long start, size, flags;
56605 + vm_flags_t vm_flags;
56606 +
56607 + start = ELF_PAGEALIGN(elf_brk);
56608 + size = PAGE_SIZE + ((pax_get_random_long() & ((1UL << 22) - 1UL)) << 4);
56609 + flags = MAP_FIXED | MAP_PRIVATE;
56610 + vm_flags = VM_DONTEXPAND | VM_DONTDUMP;
56611 +
56612 + down_write(&current->mm->mmap_sem);
56613 + start = get_unmapped_area(NULL, start, PAGE_ALIGN(size), 0, flags);
56614 + retval = -ENOMEM;
56615 + if (!IS_ERR_VALUE(start) && !find_vma_intersection(current->mm, start, start + size + PAGE_SIZE)) {
56616 +// if (current->personality & ADDR_NO_RANDOMIZE)
56617 +// vm_flags |= VM_READ | VM_MAYREAD;
56618 + start = mmap_region(NULL, start, PAGE_ALIGN(size), vm_flags, 0);
56619 + retval = IS_ERR_VALUE(start) ? start : 0;
56620 + }
56621 + up_write(&current->mm->mmap_sem);
56622 + if (retval == 0)
56623 + retval = set_brk(start + size, start + size + PAGE_SIZE);
56624 + if (retval < 0) {
56625 + send_sig(SIGKILL, current, 0);
56626 + goto out_free_dentry;
56627 + }
56628 + }
56629 +#endif
56630 +
56631 if (elf_interpreter) {
56632 - unsigned long interp_map_addr = 0;
56633 -
56634 elf_entry = load_elf_interp(&loc->interp_elf_ex,
56635 interpreter,
56636 - &interp_map_addr,
56637 load_bias);
56638 if (!IS_ERR((void *)elf_entry)) {
56639 /*
56640 @@ -1122,7 +1601,7 @@ static bool always_dump_vma(struct vm_area_struct *vma)
56641 * Decide what to dump of a segment, part, all or none.
56642 */
56643 static unsigned long vma_dump_size(struct vm_area_struct *vma,
56644 - unsigned long mm_flags)
56645 + unsigned long mm_flags, long signr)
56646 {
56647 #define FILTER(type) (mm_flags & (1UL << MMF_DUMP_##type))
56648
56649 @@ -1160,7 +1639,7 @@ static unsigned long vma_dump_size(struct vm_area_struct *vma,
56650 if (vma->vm_file == NULL)
56651 return 0;
56652
56653 - if (FILTER(MAPPED_PRIVATE))
56654 + if (signr == SIGKILL || FILTER(MAPPED_PRIVATE))
56655 goto whole;
56656
56657 /*
56658 @@ -1367,9 +1846,9 @@ static void fill_auxv_note(struct memelfnote *note, struct mm_struct *mm)
56659 {
56660 elf_addr_t *auxv = (elf_addr_t *) mm->saved_auxv;
56661 int i = 0;
56662 - do
56663 + do {
56664 i += 2;
56665 - while (auxv[i - 2] != AT_NULL);
56666 + } while (auxv[i - 2] != AT_NULL);
56667 fill_note(note, "CORE", NT_AUXV, i * sizeof(elf_addr_t), auxv);
56668 }
56669
56670 @@ -1378,7 +1857,7 @@ static void fill_siginfo_note(struct memelfnote *note, user_siginfo_t *csigdata,
56671 {
56672 mm_segment_t old_fs = get_fs();
56673 set_fs(KERNEL_DS);
56674 - copy_siginfo_to_user((user_siginfo_t __user *) csigdata, siginfo);
56675 + copy_siginfo_to_user((user_siginfo_t __force_user *) csigdata, siginfo);
56676 set_fs(old_fs);
56677 fill_note(note, "CORE", NT_SIGINFO, sizeof(*csigdata), csigdata);
56678 }
56679 @@ -2002,14 +2481,14 @@ static void fill_extnum_info(struct elfhdr *elf, struct elf_shdr *shdr4extnum,
56680 }
56681
56682 static size_t elf_core_vma_data_size(struct vm_area_struct *gate_vma,
56683 - unsigned long mm_flags)
56684 + struct coredump_params *cprm)
56685 {
56686 struct vm_area_struct *vma;
56687 size_t size = 0;
56688
56689 for (vma = first_vma(current, gate_vma); vma != NULL;
56690 vma = next_vma(vma, gate_vma))
56691 - size += vma_dump_size(vma, mm_flags);
56692 + size += vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
56693 return size;
56694 }
56695
56696 @@ -2100,7 +2579,7 @@ static int elf_core_dump(struct coredump_params *cprm)
56697
56698 dataoff = offset = roundup(offset, ELF_EXEC_PAGESIZE);
56699
56700 - offset += elf_core_vma_data_size(gate_vma, cprm->mm_flags);
56701 + offset += elf_core_vma_data_size(gate_vma, cprm);
56702 offset += elf_core_extra_data_size();
56703 e_shoff = offset;
56704
56705 @@ -2128,7 +2607,7 @@ static int elf_core_dump(struct coredump_params *cprm)
56706 phdr.p_offset = offset;
56707 phdr.p_vaddr = vma->vm_start;
56708 phdr.p_paddr = 0;
56709 - phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags);
56710 + phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
56711 phdr.p_memsz = vma->vm_end - vma->vm_start;
56712 offset += phdr.p_filesz;
56713 phdr.p_flags = vma->vm_flags & VM_READ ? PF_R : 0;
56714 @@ -2161,7 +2640,7 @@ static int elf_core_dump(struct coredump_params *cprm)
56715 unsigned long addr;
56716 unsigned long end;
56717
56718 - end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags);
56719 + end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
56720
56721 for (addr = vma->vm_start; addr < end; addr += PAGE_SIZE) {
56722 struct page *page;
56723 @@ -2202,6 +2681,167 @@ out:
56724
56725 #endif /* CONFIG_ELF_CORE */
56726
56727 +#ifdef CONFIG_PAX_MPROTECT
56728 +/* PaX: non-PIC ELF libraries need relocations on their executable segments
56729 + * therefore we'll grant them VM_MAYWRITE once during their life. Similarly
56730 + * we'll remove VM_MAYWRITE for good on RELRO segments.
56731 + *
56732 + * The checks favour ld-linux.so behaviour which operates on a per ELF segment
56733 + * basis because we want to allow the common case and not the special ones.
56734 + */
56735 +static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags)
56736 +{
56737 + struct elfhdr elf_h;
56738 + struct elf_phdr elf_p;
56739 + unsigned long i;
56740 + unsigned long oldflags;
56741 + bool is_textrel_rw, is_textrel_rx, is_relro;
56742 +
56743 + if (!(vma->vm_mm->pax_flags & MF_PAX_MPROTECT) || !vma->vm_file)
56744 + return;
56745 +
56746 + oldflags = vma->vm_flags & (VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ);
56747 + newflags &= VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ;
56748 +
56749 +#ifdef CONFIG_PAX_ELFRELOCS
56750 + /* possible TEXTREL */
56751 + is_textrel_rw = !vma->anon_vma && oldflags == (VM_MAYEXEC | VM_MAYREAD | VM_EXEC | VM_READ) && newflags == (VM_WRITE | VM_READ);
56752 + is_textrel_rx = vma->anon_vma && oldflags == (VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_WRITE | VM_READ) && newflags == (VM_EXEC | VM_READ);
56753 +#else
56754 + is_textrel_rw = false;
56755 + is_textrel_rx = false;
56756 +#endif
56757 +
56758 + /* possible RELRO */
56759 + is_relro = vma->anon_vma && oldflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ) && newflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ);
56760 +
56761 + if (!is_textrel_rw && !is_textrel_rx && !is_relro)
56762 + return;
56763 +
56764 + if (sizeof(elf_h) != kernel_read(vma->vm_file, 0UL, (char *)&elf_h, sizeof(elf_h)) ||
56765 + memcmp(elf_h.e_ident, ELFMAG, SELFMAG) ||
56766 +
56767 +#ifdef CONFIG_PAX_ETEXECRELOCS
56768 + ((is_textrel_rw || is_textrel_rx) && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
56769 +#else
56770 + ((is_textrel_rw || is_textrel_rx) && elf_h.e_type != ET_DYN) ||
56771 +#endif
56772 +
56773 + (is_relro && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
56774 + !elf_check_arch(&elf_h) ||
56775 + elf_h.e_phentsize != sizeof(struct elf_phdr) ||
56776 + elf_h.e_phnum > 65536UL / sizeof(struct elf_phdr))
56777 + return;
56778 +
56779 + for (i = 0UL; i < elf_h.e_phnum; i++) {
56780 + if (sizeof(elf_p) != kernel_read(vma->vm_file, elf_h.e_phoff + i*sizeof(elf_p), (char *)&elf_p, sizeof(elf_p)))
56781 + return;
56782 + switch (elf_p.p_type) {
56783 + case PT_DYNAMIC:
56784 + if (!is_textrel_rw && !is_textrel_rx)
56785 + continue;
56786 + i = 0UL;
56787 + while ((i+1) * sizeof(elf_dyn) <= elf_p.p_filesz) {
56788 + elf_dyn dyn;
56789 +
56790 + if (sizeof(dyn) != kernel_read(vma->vm_file, elf_p.p_offset + i*sizeof(dyn), (char *)&dyn, sizeof(dyn)))
56791 + break;
56792 + if (dyn.d_tag == DT_NULL)
56793 + break;
56794 + if (dyn.d_tag == DT_TEXTREL || (dyn.d_tag == DT_FLAGS && (dyn.d_un.d_val & DF_TEXTREL))) {
56795 + gr_log_textrel(vma);
56796 + if (is_textrel_rw)
56797 + vma->vm_flags |= VM_MAYWRITE;
56798 + else
56799 + /* PaX: disallow write access after relocs are done, hopefully noone else needs it... */
56800 + vma->vm_flags &= ~VM_MAYWRITE;
56801 + break;
56802 + }
56803 + i++;
56804 + }
56805 + is_textrel_rw = false;
56806 + is_textrel_rx = false;
56807 + continue;
56808 +
56809 + case PT_GNU_RELRO:
56810 + if (!is_relro)
56811 + continue;
56812 + if ((elf_p.p_offset >> PAGE_SHIFT) == vma->vm_pgoff && ELF_PAGEALIGN(elf_p.p_memsz) == vma->vm_end - vma->vm_start)
56813 + vma->vm_flags &= ~VM_MAYWRITE;
56814 + is_relro = false;
56815 + continue;
56816 +
56817 +#ifdef CONFIG_PAX_PT_PAX_FLAGS
56818 + case PT_PAX_FLAGS: {
56819 + const char *msg_mprotect = "", *msg_emutramp = "";
56820 + char *buffer_lib, *buffer_exe;
56821 +
56822 + if (elf_p.p_flags & PF_NOMPROTECT)
56823 + msg_mprotect = "MPROTECT disabled";
56824 +
56825 +#ifdef CONFIG_PAX_EMUTRAMP
56826 + if (!(vma->vm_mm->pax_flags & MF_PAX_EMUTRAMP) && !(elf_p.p_flags & PF_NOEMUTRAMP))
56827 + msg_emutramp = "EMUTRAMP enabled";
56828 +#endif
56829 +
56830 + if (!msg_mprotect[0] && !msg_emutramp[0])
56831 + continue;
56832 +
56833 + if (!printk_ratelimit())
56834 + continue;
56835 +
56836 + buffer_lib = (char *)__get_free_page(GFP_KERNEL);
56837 + buffer_exe = (char *)__get_free_page(GFP_KERNEL);
56838 + if (buffer_lib && buffer_exe) {
56839 + char *path_lib, *path_exe;
56840 +
56841 + path_lib = pax_get_path(&vma->vm_file->f_path, buffer_lib, PAGE_SIZE);
56842 + path_exe = pax_get_path(&vma->vm_mm->exe_file->f_path, buffer_exe, PAGE_SIZE);
56843 +
56844 + pr_info("PAX: %s wants %s%s%s on %s\n", path_lib, msg_mprotect,
56845 + (msg_mprotect[0] && msg_emutramp[0] ? " and " : ""), msg_emutramp, path_exe);
56846 +
56847 + }
56848 + free_page((unsigned long)buffer_exe);
56849 + free_page((unsigned long)buffer_lib);
56850 + continue;
56851 + }
56852 +#endif
56853 +
56854 + }
56855 + }
56856 +}
56857 +#endif
56858 +
56859 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
56860 +
56861 +extern int grsec_enable_log_rwxmaps;
56862 +
56863 +static void elf_handle_mmap(struct file *file)
56864 +{
56865 + struct elfhdr elf_h;
56866 + struct elf_phdr elf_p;
56867 + unsigned long i;
56868 +
56869 + if (!grsec_enable_log_rwxmaps)
56870 + return;
56871 +
56872 + if (sizeof(elf_h) != kernel_read(file, 0UL, (char *)&elf_h, sizeof(elf_h)) ||
56873 + memcmp(elf_h.e_ident, ELFMAG, SELFMAG) ||
56874 + (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC) || !elf_check_arch(&elf_h) ||
56875 + elf_h.e_phentsize != sizeof(struct elf_phdr) ||
56876 + elf_h.e_phnum > 65536UL / sizeof(struct elf_phdr))
56877 + return;
56878 +
56879 + for (i = 0UL; i < elf_h.e_phnum; i++) {
56880 + if (sizeof(elf_p) != kernel_read(file, elf_h.e_phoff + i*sizeof(elf_p), (char *)&elf_p, sizeof(elf_p)))
56881 + return;
56882 + if (elf_p.p_type == PT_GNU_STACK && (elf_p.p_flags & PF_X))
56883 + gr_log_ptgnustack(file);
56884 + }
56885 +}
56886 +#endif
56887 +
56888 static int __init init_elf_binfmt(void)
56889 {
56890 register_binfmt(&elf_format);
56891 diff --git a/fs/binfmt_flat.c b/fs/binfmt_flat.c
56892 index d50bbe5..af3b649 100644
56893 --- a/fs/binfmt_flat.c
56894 +++ b/fs/binfmt_flat.c
56895 @@ -566,7 +566,9 @@ static int load_flat_file(struct linux_binprm * bprm,
56896 realdatastart = (unsigned long) -ENOMEM;
56897 printk("Unable to allocate RAM for process data, errno %d\n",
56898 (int)-realdatastart);
56899 + down_write(&current->mm->mmap_sem);
56900 vm_munmap(textpos, text_len);
56901 + up_write(&current->mm->mmap_sem);
56902 ret = realdatastart;
56903 goto err;
56904 }
56905 @@ -590,8 +592,10 @@ static int load_flat_file(struct linux_binprm * bprm,
56906 }
56907 if (IS_ERR_VALUE(result)) {
56908 printk("Unable to read data+bss, errno %d\n", (int)-result);
56909 + down_write(&current->mm->mmap_sem);
56910 vm_munmap(textpos, text_len);
56911 vm_munmap(realdatastart, len);
56912 + up_write(&current->mm->mmap_sem);
56913 ret = result;
56914 goto err;
56915 }
56916 @@ -653,8 +657,10 @@ static int load_flat_file(struct linux_binprm * bprm,
56917 }
56918 if (IS_ERR_VALUE(result)) {
56919 printk("Unable to read code+data+bss, errno %d\n",(int)-result);
56920 + down_write(&current->mm->mmap_sem);
56921 vm_munmap(textpos, text_len + data_len + extra +
56922 MAX_SHARED_LIBS * sizeof(unsigned long));
56923 + up_write(&current->mm->mmap_sem);
56924 ret = result;
56925 goto err;
56926 }
56927 diff --git a/fs/bio.c b/fs/bio.c
56928 index 33d79a4..c3c9893 100644
56929 --- a/fs/bio.c
56930 +++ b/fs/bio.c
56931 @@ -1106,7 +1106,7 @@ struct bio *bio_copy_user_iov(struct request_queue *q,
56932 /*
56933 * Overflow, abort
56934 */
56935 - if (end < start)
56936 + if (end < start || end - start > INT_MAX - nr_pages)
56937 return ERR_PTR(-EINVAL);
56938
56939 nr_pages += end - start;
56940 @@ -1240,7 +1240,7 @@ static struct bio *__bio_map_user_iov(struct request_queue *q,
56941 /*
56942 * Overflow, abort
56943 */
56944 - if (end < start)
56945 + if (end < start || end - start > INT_MAX - nr_pages)
56946 return ERR_PTR(-EINVAL);
56947
56948 nr_pages += end - start;
56949 @@ -1502,7 +1502,7 @@ static void bio_copy_kern_endio(struct bio *bio, int err)
56950 const int read = bio_data_dir(bio) == READ;
56951 struct bio_map_data *bmd = bio->bi_private;
56952 int i;
56953 - char *p = bmd->sgvecs[0].iov_base;
56954 + char *p = (char __force_kernel *)bmd->sgvecs[0].iov_base;
56955
56956 bio_for_each_segment_all(bvec, bio, i) {
56957 char *addr = page_address(bvec->bv_page);
56958 diff --git a/fs/block_dev.c b/fs/block_dev.c
56959 index 1e86823..8e34695 100644
56960 --- a/fs/block_dev.c
56961 +++ b/fs/block_dev.c
56962 @@ -637,7 +637,7 @@ static bool bd_may_claim(struct block_device *bdev, struct block_device *whole,
56963 else if (bdev->bd_contains == bdev)
56964 return true; /* is a whole device which isn't held */
56965
56966 - else if (whole->bd_holder == bd_may_claim)
56967 + else if (whole->bd_holder == (void *)bd_may_claim)
56968 return true; /* is a partition of a device that is being partitioned */
56969 else if (whole->bd_holder != NULL)
56970 return false; /* is a partition of a held device */
56971 diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c
56972 index 3de01b4..6547c39 100644
56973 --- a/fs/btrfs/ctree.c
56974 +++ b/fs/btrfs/ctree.c
56975 @@ -1217,9 +1217,12 @@ static noinline int __btrfs_cow_block(struct btrfs_trans_handle *trans,
56976 free_extent_buffer(buf);
56977 add_root_to_dirty_list(root);
56978 } else {
56979 - if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID)
56980 - parent_start = parent->start;
56981 - else
56982 + if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID) {
56983 + if (parent)
56984 + parent_start = parent->start;
56985 + else
56986 + parent_start = 0;
56987 + } else
56988 parent_start = 0;
56989
56990 WARN_ON(trans->transid != btrfs_header_generation(parent));
56991 diff --git a/fs/btrfs/delayed-inode.c b/fs/btrfs/delayed-inode.c
56992 index 8d292fb..bc205c2 100644
56993 --- a/fs/btrfs/delayed-inode.c
56994 +++ b/fs/btrfs/delayed-inode.c
56995 @@ -459,7 +459,7 @@ static int __btrfs_add_delayed_deletion_item(struct btrfs_delayed_node *node,
56996
56997 static void finish_one_item(struct btrfs_delayed_root *delayed_root)
56998 {
56999 - int seq = atomic_inc_return(&delayed_root->items_seq);
57000 + int seq = atomic_inc_return_unchecked(&delayed_root->items_seq);
57001 if ((atomic_dec_return(&delayed_root->items) <
57002 BTRFS_DELAYED_BACKGROUND || seq % BTRFS_DELAYED_BATCH == 0) &&
57003 waitqueue_active(&delayed_root->wait))
57004 @@ -1379,7 +1379,7 @@ void btrfs_assert_delayed_root_empty(struct btrfs_root *root)
57005 static int refs_newer(struct btrfs_delayed_root *delayed_root,
57006 int seq, int count)
57007 {
57008 - int val = atomic_read(&delayed_root->items_seq);
57009 + int val = atomic_read_unchecked(&delayed_root->items_seq);
57010
57011 if (val < seq || val >= seq + count)
57012 return 1;
57013 @@ -1396,7 +1396,7 @@ void btrfs_balance_delayed_items(struct btrfs_root *root)
57014 if (atomic_read(&delayed_root->items) < BTRFS_DELAYED_BACKGROUND)
57015 return;
57016
57017 - seq = atomic_read(&delayed_root->items_seq);
57018 + seq = atomic_read_unchecked(&delayed_root->items_seq);
57019
57020 if (atomic_read(&delayed_root->items) >= BTRFS_DELAYED_WRITEBACK) {
57021 int ret;
57022 diff --git a/fs/btrfs/delayed-inode.h b/fs/btrfs/delayed-inode.h
57023 index a4b38f9..f86a509 100644
57024 --- a/fs/btrfs/delayed-inode.h
57025 +++ b/fs/btrfs/delayed-inode.h
57026 @@ -43,7 +43,7 @@ struct btrfs_delayed_root {
57027 */
57028 struct list_head prepare_list;
57029 atomic_t items; /* for delayed items */
57030 - atomic_t items_seq; /* for delayed items */
57031 + atomic_unchecked_t items_seq; /* for delayed items */
57032 int nodes; /* for delayed nodes */
57033 wait_queue_head_t wait;
57034 };
57035 @@ -87,7 +87,7 @@ static inline void btrfs_init_delayed_root(
57036 struct btrfs_delayed_root *delayed_root)
57037 {
57038 atomic_set(&delayed_root->items, 0);
57039 - atomic_set(&delayed_root->items_seq, 0);
57040 + atomic_set_unchecked(&delayed_root->items_seq, 0);
57041 delayed_root->nodes = 0;
57042 spin_lock_init(&delayed_root->lock);
57043 init_waitqueue_head(&delayed_root->wait);
57044 diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
57045 index 9f831bb..14afde5 100644
57046 --- a/fs/btrfs/ioctl.c
57047 +++ b/fs/btrfs/ioctl.c
57048 @@ -3457,9 +3457,12 @@ static long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
57049 for (i = 0; i < num_types; i++) {
57050 struct btrfs_space_info *tmp;
57051
57052 + /* Don't copy in more than we allocated */
57053 if (!slot_count)
57054 break;
57055
57056 + slot_count--;
57057 +
57058 info = NULL;
57059 rcu_read_lock();
57060 list_for_each_entry_rcu(tmp, &root->fs_info->space_info,
57061 @@ -3481,10 +3484,7 @@ static long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
57062 memcpy(dest, &space, sizeof(space));
57063 dest++;
57064 space_args.total_spaces++;
57065 - slot_count--;
57066 }
57067 - if (!slot_count)
57068 - break;
57069 }
57070 up_read(&info->groups_sem);
57071 }
57072 diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c
57073 index d71a11d..384e2c4 100644
57074 --- a/fs/btrfs/super.c
57075 +++ b/fs/btrfs/super.c
57076 @@ -265,7 +265,7 @@ void __btrfs_abort_transaction(struct btrfs_trans_handle *trans,
57077 function, line, errstr);
57078 return;
57079 }
57080 - ACCESS_ONCE(trans->transaction->aborted) = errno;
57081 + ACCESS_ONCE_RW(trans->transaction->aborted) = errno;
57082 /* Wake up anybody who may be waiting on this transaction */
57083 wake_up(&root->fs_info->transaction_wait);
57084 wake_up(&root->fs_info->transaction_blocked_wait);
57085 diff --git a/fs/buffer.c b/fs/buffer.c
57086 index aeeea65..7651d590 100644
57087 --- a/fs/buffer.c
57088 +++ b/fs/buffer.c
57089 @@ -3428,7 +3428,7 @@ void __init buffer_init(void)
57090 bh_cachep = kmem_cache_create("buffer_head",
57091 sizeof(struct buffer_head), 0,
57092 (SLAB_RECLAIM_ACCOUNT|SLAB_PANIC|
57093 - SLAB_MEM_SPREAD),
57094 + SLAB_MEM_SPREAD|SLAB_NO_SANITIZE),
57095 NULL);
57096
57097 /*
57098 diff --git a/fs/cachefiles/bind.c b/fs/cachefiles/bind.c
57099 index 622f469..e8d2d55 100644
57100 --- a/fs/cachefiles/bind.c
57101 +++ b/fs/cachefiles/bind.c
57102 @@ -39,13 +39,11 @@ int cachefiles_daemon_bind(struct cachefiles_cache *cache, char *args)
57103 args);
57104
57105 /* start by checking things over */
57106 - ASSERT(cache->fstop_percent >= 0 &&
57107 - cache->fstop_percent < cache->fcull_percent &&
57108 + ASSERT(cache->fstop_percent < cache->fcull_percent &&
57109 cache->fcull_percent < cache->frun_percent &&
57110 cache->frun_percent < 100);
57111
57112 - ASSERT(cache->bstop_percent >= 0 &&
57113 - cache->bstop_percent < cache->bcull_percent &&
57114 + ASSERT(cache->bstop_percent < cache->bcull_percent &&
57115 cache->bcull_percent < cache->brun_percent &&
57116 cache->brun_percent < 100);
57117
57118 diff --git a/fs/cachefiles/daemon.c b/fs/cachefiles/daemon.c
57119 index 0a1467b..6a53245 100644
57120 --- a/fs/cachefiles/daemon.c
57121 +++ b/fs/cachefiles/daemon.c
57122 @@ -196,7 +196,7 @@ static ssize_t cachefiles_daemon_read(struct file *file, char __user *_buffer,
57123 if (n > buflen)
57124 return -EMSGSIZE;
57125
57126 - if (copy_to_user(_buffer, buffer, n) != 0)
57127 + if (n > sizeof(buffer) || copy_to_user(_buffer, buffer, n) != 0)
57128 return -EFAULT;
57129
57130 return n;
57131 @@ -222,7 +222,7 @@ static ssize_t cachefiles_daemon_write(struct file *file,
57132 if (test_bit(CACHEFILES_DEAD, &cache->flags))
57133 return -EIO;
57134
57135 - if (datalen < 0 || datalen > PAGE_SIZE - 1)
57136 + if (datalen > PAGE_SIZE - 1)
57137 return -EOPNOTSUPP;
57138
57139 /* drag the command string into the kernel so we can parse it */
57140 @@ -386,7 +386,7 @@ static int cachefiles_daemon_fstop(struct cachefiles_cache *cache, char *args)
57141 if (args[0] != '%' || args[1] != '\0')
57142 return -EINVAL;
57143
57144 - if (fstop < 0 || fstop >= cache->fcull_percent)
57145 + if (fstop >= cache->fcull_percent)
57146 return cachefiles_daemon_range_error(cache, args);
57147
57148 cache->fstop_percent = fstop;
57149 @@ -458,7 +458,7 @@ static int cachefiles_daemon_bstop(struct cachefiles_cache *cache, char *args)
57150 if (args[0] != '%' || args[1] != '\0')
57151 return -EINVAL;
57152
57153 - if (bstop < 0 || bstop >= cache->bcull_percent)
57154 + if (bstop >= cache->bcull_percent)
57155 return cachefiles_daemon_range_error(cache, args);
57156
57157 cache->bstop_percent = bstop;
57158 diff --git a/fs/cachefiles/internal.h b/fs/cachefiles/internal.h
57159 index 5349473..d6c0b93 100644
57160 --- a/fs/cachefiles/internal.h
57161 +++ b/fs/cachefiles/internal.h
57162 @@ -59,7 +59,7 @@ struct cachefiles_cache {
57163 wait_queue_head_t daemon_pollwq; /* poll waitqueue for daemon */
57164 struct rb_root active_nodes; /* active nodes (can't be culled) */
57165 rwlock_t active_lock; /* lock for active_nodes */
57166 - atomic_t gravecounter; /* graveyard uniquifier */
57167 + atomic_unchecked_t gravecounter; /* graveyard uniquifier */
57168 unsigned frun_percent; /* when to stop culling (% files) */
57169 unsigned fcull_percent; /* when to start culling (% files) */
57170 unsigned fstop_percent; /* when to stop allocating (% files) */
57171 @@ -171,19 +171,19 @@ extern int cachefiles_check_in_use(struct cachefiles_cache *cache,
57172 * proc.c
57173 */
57174 #ifdef CONFIG_CACHEFILES_HISTOGRAM
57175 -extern atomic_t cachefiles_lookup_histogram[HZ];
57176 -extern atomic_t cachefiles_mkdir_histogram[HZ];
57177 -extern atomic_t cachefiles_create_histogram[HZ];
57178 +extern atomic_unchecked_t cachefiles_lookup_histogram[HZ];
57179 +extern atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
57180 +extern atomic_unchecked_t cachefiles_create_histogram[HZ];
57181
57182 extern int __init cachefiles_proc_init(void);
57183 extern void cachefiles_proc_cleanup(void);
57184 static inline
57185 -void cachefiles_hist(atomic_t histogram[], unsigned long start_jif)
57186 +void cachefiles_hist(atomic_unchecked_t histogram[], unsigned long start_jif)
57187 {
57188 unsigned long jif = jiffies - start_jif;
57189 if (jif >= HZ)
57190 jif = HZ - 1;
57191 - atomic_inc(&histogram[jif]);
57192 + atomic_inc_unchecked(&histogram[jif]);
57193 }
57194
57195 #else
57196 diff --git a/fs/cachefiles/namei.c b/fs/cachefiles/namei.c
57197 index ca65f39..48921e3 100644
57198 --- a/fs/cachefiles/namei.c
57199 +++ b/fs/cachefiles/namei.c
57200 @@ -317,7 +317,7 @@ try_again:
57201 /* first step is to make up a grave dentry in the graveyard */
57202 sprintf(nbuffer, "%08x%08x",
57203 (uint32_t) get_seconds(),
57204 - (uint32_t) atomic_inc_return(&cache->gravecounter));
57205 + (uint32_t) atomic_inc_return_unchecked(&cache->gravecounter));
57206
57207 /* do the multiway lock magic */
57208 trap = lock_rename(cache->graveyard, dir);
57209 diff --git a/fs/cachefiles/proc.c b/fs/cachefiles/proc.c
57210 index eccd339..4c1d995 100644
57211 --- a/fs/cachefiles/proc.c
57212 +++ b/fs/cachefiles/proc.c
57213 @@ -14,9 +14,9 @@
57214 #include <linux/seq_file.h>
57215 #include "internal.h"
57216
57217 -atomic_t cachefiles_lookup_histogram[HZ];
57218 -atomic_t cachefiles_mkdir_histogram[HZ];
57219 -atomic_t cachefiles_create_histogram[HZ];
57220 +atomic_unchecked_t cachefiles_lookup_histogram[HZ];
57221 +atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
57222 +atomic_unchecked_t cachefiles_create_histogram[HZ];
57223
57224 /*
57225 * display the latency histogram
57226 @@ -35,9 +35,9 @@ static int cachefiles_histogram_show(struct seq_file *m, void *v)
57227 return 0;
57228 default:
57229 index = (unsigned long) v - 3;
57230 - x = atomic_read(&cachefiles_lookup_histogram[index]);
57231 - y = atomic_read(&cachefiles_mkdir_histogram[index]);
57232 - z = atomic_read(&cachefiles_create_histogram[index]);
57233 + x = atomic_read_unchecked(&cachefiles_lookup_histogram[index]);
57234 + y = atomic_read_unchecked(&cachefiles_mkdir_histogram[index]);
57235 + z = atomic_read_unchecked(&cachefiles_create_histogram[index]);
57236 if (x == 0 && y == 0 && z == 0)
57237 return 0;
57238
57239 diff --git a/fs/cachefiles/rdwr.c b/fs/cachefiles/rdwr.c
57240 index ebaff36..7e3ea26 100644
57241 --- a/fs/cachefiles/rdwr.c
57242 +++ b/fs/cachefiles/rdwr.c
57243 @@ -950,7 +950,7 @@ int cachefiles_write_page(struct fscache_storage *op, struct page *page)
57244 old_fs = get_fs();
57245 set_fs(KERNEL_DS);
57246 ret = file->f_op->write(
57247 - file, (const void __user *) data, len, &pos);
57248 + file, (const void __force_user *) data, len, &pos);
57249 set_fs(old_fs);
57250 kunmap(page);
57251 file_end_write(file);
57252 diff --git a/fs/ceph/dir.c b/fs/ceph/dir.c
57253 index 2a0bcae..34ec24e 100644
57254 --- a/fs/ceph/dir.c
57255 +++ b/fs/ceph/dir.c
57256 @@ -240,7 +240,7 @@ static int ceph_readdir(struct file *file, struct dir_context *ctx)
57257 struct ceph_fs_client *fsc = ceph_inode_to_client(inode);
57258 struct ceph_mds_client *mdsc = fsc->mdsc;
57259 unsigned frag = fpos_frag(ctx->pos);
57260 - int off = fpos_off(ctx->pos);
57261 + unsigned int off = fpos_off(ctx->pos);
57262 int err;
57263 u32 ftype;
57264 struct ceph_mds_reply_info_parsed *rinfo;
57265 diff --git a/fs/ceph/super.c b/fs/ceph/super.c
57266 index 6a0951e..03fac6d 100644
57267 --- a/fs/ceph/super.c
57268 +++ b/fs/ceph/super.c
57269 @@ -870,7 +870,7 @@ static int ceph_compare_super(struct super_block *sb, void *data)
57270 /*
57271 * construct our own bdi so we can control readahead, etc.
57272 */
57273 -static atomic_long_t bdi_seq = ATOMIC_LONG_INIT(0);
57274 +static atomic_long_unchecked_t bdi_seq = ATOMIC_LONG_INIT(0);
57275
57276 static int ceph_register_bdi(struct super_block *sb,
57277 struct ceph_fs_client *fsc)
57278 @@ -887,7 +887,7 @@ static int ceph_register_bdi(struct super_block *sb,
57279 default_backing_dev_info.ra_pages;
57280
57281 err = bdi_register(&fsc->backing_dev_info, NULL, "ceph-%ld",
57282 - atomic_long_inc_return(&bdi_seq));
57283 + atomic_long_inc_return_unchecked(&bdi_seq));
57284 if (!err)
57285 sb->s_bdi = &fsc->backing_dev_info;
57286 return err;
57287 diff --git a/fs/cifs/cifs_debug.c b/fs/cifs/cifs_debug.c
57288 index f3ac415..3d2420c 100644
57289 --- a/fs/cifs/cifs_debug.c
57290 +++ b/fs/cifs/cifs_debug.c
57291 @@ -286,8 +286,8 @@ static ssize_t cifs_stats_proc_write(struct file *file,
57292
57293 if (c == '1' || c == 'y' || c == 'Y' || c == '0') {
57294 #ifdef CONFIG_CIFS_STATS2
57295 - atomic_set(&totBufAllocCount, 0);
57296 - atomic_set(&totSmBufAllocCount, 0);
57297 + atomic_set_unchecked(&totBufAllocCount, 0);
57298 + atomic_set_unchecked(&totSmBufAllocCount, 0);
57299 #endif /* CONFIG_CIFS_STATS2 */
57300 spin_lock(&cifs_tcp_ses_lock);
57301 list_for_each(tmp1, &cifs_tcp_ses_list) {
57302 @@ -300,7 +300,7 @@ static ssize_t cifs_stats_proc_write(struct file *file,
57303 tcon = list_entry(tmp3,
57304 struct cifs_tcon,
57305 tcon_list);
57306 - atomic_set(&tcon->num_smbs_sent, 0);
57307 + atomic_set_unchecked(&tcon->num_smbs_sent, 0);
57308 if (server->ops->clear_stats)
57309 server->ops->clear_stats(tcon);
57310 }
57311 @@ -332,8 +332,8 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
57312 smBufAllocCount.counter, cifs_min_small);
57313 #ifdef CONFIG_CIFS_STATS2
57314 seq_printf(m, "Total Large %d Small %d Allocations\n",
57315 - atomic_read(&totBufAllocCount),
57316 - atomic_read(&totSmBufAllocCount));
57317 + atomic_read_unchecked(&totBufAllocCount),
57318 + atomic_read_unchecked(&totSmBufAllocCount));
57319 #endif /* CONFIG_CIFS_STATS2 */
57320
57321 seq_printf(m, "Operations (MIDs): %d\n", atomic_read(&midCount));
57322 @@ -362,7 +362,7 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
57323 if (tcon->need_reconnect)
57324 seq_puts(m, "\tDISCONNECTED ");
57325 seq_printf(m, "\nSMBs: %d",
57326 - atomic_read(&tcon->num_smbs_sent));
57327 + atomic_read_unchecked(&tcon->num_smbs_sent));
57328 if (server->ops->print_stats)
57329 server->ops->print_stats(m, tcon);
57330 }
57331 diff --git a/fs/cifs/cifsfs.c b/fs/cifs/cifsfs.c
57332 index 849f613..eae6dec 100644
57333 --- a/fs/cifs/cifsfs.c
57334 +++ b/fs/cifs/cifsfs.c
57335 @@ -1056,7 +1056,7 @@ cifs_init_request_bufs(void)
57336 */
57337 cifs_req_cachep = kmem_cache_create("cifs_request",
57338 CIFSMaxBufSize + max_hdr_size, 0,
57339 - SLAB_HWCACHE_ALIGN, NULL);
57340 + SLAB_HWCACHE_ALIGN | SLAB_USERCOPY, NULL);
57341 if (cifs_req_cachep == NULL)
57342 return -ENOMEM;
57343
57344 @@ -1083,7 +1083,7 @@ cifs_init_request_bufs(void)
57345 efficient to alloc 1 per page off the slab compared to 17K (5page)
57346 alloc of large cifs buffers even when page debugging is on */
57347 cifs_sm_req_cachep = kmem_cache_create("cifs_small_rq",
57348 - MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN,
57349 + MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN | SLAB_USERCOPY,
57350 NULL);
57351 if (cifs_sm_req_cachep == NULL) {
57352 mempool_destroy(cifs_req_poolp);
57353 @@ -1168,8 +1168,8 @@ init_cifs(void)
57354 atomic_set(&bufAllocCount, 0);
57355 atomic_set(&smBufAllocCount, 0);
57356 #ifdef CONFIG_CIFS_STATS2
57357 - atomic_set(&totBufAllocCount, 0);
57358 - atomic_set(&totSmBufAllocCount, 0);
57359 + atomic_set_unchecked(&totBufAllocCount, 0);
57360 + atomic_set_unchecked(&totSmBufAllocCount, 0);
57361 #endif /* CONFIG_CIFS_STATS2 */
57362
57363 atomic_set(&midCount, 0);
57364 diff --git a/fs/cifs/cifsglob.h b/fs/cifs/cifsglob.h
57365 index 579c6d5..95b6d03353 100644
57366 --- a/fs/cifs/cifsglob.h
57367 +++ b/fs/cifs/cifsglob.h
57368 @@ -797,35 +797,35 @@ struct cifs_tcon {
57369 __u16 Flags; /* optional support bits */
57370 enum statusEnum tidStatus;
57371 #ifdef CONFIG_CIFS_STATS
57372 - atomic_t num_smbs_sent;
57373 + atomic_unchecked_t num_smbs_sent;
57374 union {
57375 struct {
57376 - atomic_t num_writes;
57377 - atomic_t num_reads;
57378 - atomic_t num_flushes;
57379 - atomic_t num_oplock_brks;
57380 - atomic_t num_opens;
57381 - atomic_t num_closes;
57382 - atomic_t num_deletes;
57383 - atomic_t num_mkdirs;
57384 - atomic_t num_posixopens;
57385 - atomic_t num_posixmkdirs;
57386 - atomic_t num_rmdirs;
57387 - atomic_t num_renames;
57388 - atomic_t num_t2renames;
57389 - atomic_t num_ffirst;
57390 - atomic_t num_fnext;
57391 - atomic_t num_fclose;
57392 - atomic_t num_hardlinks;
57393 - atomic_t num_symlinks;
57394 - atomic_t num_locks;
57395 - atomic_t num_acl_get;
57396 - atomic_t num_acl_set;
57397 + atomic_unchecked_t num_writes;
57398 + atomic_unchecked_t num_reads;
57399 + atomic_unchecked_t num_flushes;
57400 + atomic_unchecked_t num_oplock_brks;
57401 + atomic_unchecked_t num_opens;
57402 + atomic_unchecked_t num_closes;
57403 + atomic_unchecked_t num_deletes;
57404 + atomic_unchecked_t num_mkdirs;
57405 + atomic_unchecked_t num_posixopens;
57406 + atomic_unchecked_t num_posixmkdirs;
57407 + atomic_unchecked_t num_rmdirs;
57408 + atomic_unchecked_t num_renames;
57409 + atomic_unchecked_t num_t2renames;
57410 + atomic_unchecked_t num_ffirst;
57411 + atomic_unchecked_t num_fnext;
57412 + atomic_unchecked_t num_fclose;
57413 + atomic_unchecked_t num_hardlinks;
57414 + atomic_unchecked_t num_symlinks;
57415 + atomic_unchecked_t num_locks;
57416 + atomic_unchecked_t num_acl_get;
57417 + atomic_unchecked_t num_acl_set;
57418 } cifs_stats;
57419 #ifdef CONFIG_CIFS_SMB2
57420 struct {
57421 - atomic_t smb2_com_sent[NUMBER_OF_SMB2_COMMANDS];
57422 - atomic_t smb2_com_failed[NUMBER_OF_SMB2_COMMANDS];
57423 + atomic_unchecked_t smb2_com_sent[NUMBER_OF_SMB2_COMMANDS];
57424 + atomic_unchecked_t smb2_com_failed[NUMBER_OF_SMB2_COMMANDS];
57425 } smb2_stats;
57426 #endif /* CONFIG_CIFS_SMB2 */
57427 } stats;
57428 @@ -1155,7 +1155,7 @@ convert_delimiter(char *path, char delim)
57429 }
57430
57431 #ifdef CONFIG_CIFS_STATS
57432 -#define cifs_stats_inc atomic_inc
57433 +#define cifs_stats_inc atomic_inc_unchecked
57434
57435 static inline void cifs_stats_bytes_written(struct cifs_tcon *tcon,
57436 unsigned int bytes)
57437 @@ -1521,8 +1521,8 @@ GLOBAL_EXTERN atomic_t tconInfoReconnectCount;
57438 /* Various Debug counters */
57439 GLOBAL_EXTERN atomic_t bufAllocCount; /* current number allocated */
57440 #ifdef CONFIG_CIFS_STATS2
57441 -GLOBAL_EXTERN atomic_t totBufAllocCount; /* total allocated over all time */
57442 -GLOBAL_EXTERN atomic_t totSmBufAllocCount;
57443 +GLOBAL_EXTERN atomic_unchecked_t totBufAllocCount; /* total allocated over all time */
57444 +GLOBAL_EXTERN atomic_unchecked_t totSmBufAllocCount;
57445 #endif
57446 GLOBAL_EXTERN atomic_t smBufAllocCount;
57447 GLOBAL_EXTERN atomic_t midCount;
57448 diff --git a/fs/cifs/file.c b/fs/cifs/file.c
57449 index a1c9ead..63e4c62 100644
57450 --- a/fs/cifs/file.c
57451 +++ b/fs/cifs/file.c
57452 @@ -1900,10 +1900,14 @@ static int cifs_writepages(struct address_space *mapping,
57453 index = mapping->writeback_index; /* Start from prev offset */
57454 end = -1;
57455 } else {
57456 - index = wbc->range_start >> PAGE_CACHE_SHIFT;
57457 - end = wbc->range_end >> PAGE_CACHE_SHIFT;
57458 - if (wbc->range_start == 0 && wbc->range_end == LLONG_MAX)
57459 + if (wbc->range_start == 0 && wbc->range_end == LLONG_MAX) {
57460 range_whole = true;
57461 + index = 0;
57462 + end = ULONG_MAX;
57463 + } else {
57464 + index = wbc->range_start >> PAGE_CACHE_SHIFT;
57465 + end = wbc->range_end >> PAGE_CACHE_SHIFT;
57466 + }
57467 scanned = true;
57468 }
57469 retry:
57470 diff --git a/fs/cifs/misc.c b/fs/cifs/misc.c
57471 index 2f9f379..43f8025 100644
57472 --- a/fs/cifs/misc.c
57473 +++ b/fs/cifs/misc.c
57474 @@ -170,7 +170,7 @@ cifs_buf_get(void)
57475 memset(ret_buf, 0, buf_size + 3);
57476 atomic_inc(&bufAllocCount);
57477 #ifdef CONFIG_CIFS_STATS2
57478 - atomic_inc(&totBufAllocCount);
57479 + atomic_inc_unchecked(&totBufAllocCount);
57480 #endif /* CONFIG_CIFS_STATS2 */
57481 }
57482
57483 @@ -205,7 +205,7 @@ cifs_small_buf_get(void)
57484 /* memset(ret_buf, 0, sizeof(struct smb_hdr) + 27);*/
57485 atomic_inc(&smBufAllocCount);
57486 #ifdef CONFIG_CIFS_STATS2
57487 - atomic_inc(&totSmBufAllocCount);
57488 + atomic_inc_unchecked(&totSmBufAllocCount);
57489 #endif /* CONFIG_CIFS_STATS2 */
57490
57491 }
57492 diff --git a/fs/cifs/smb1ops.c b/fs/cifs/smb1ops.c
57493 index ffc9ef9..b3c992b 100644
57494 --- a/fs/cifs/smb1ops.c
57495 +++ b/fs/cifs/smb1ops.c
57496 @@ -609,27 +609,27 @@ static void
57497 cifs_clear_stats(struct cifs_tcon *tcon)
57498 {
57499 #ifdef CONFIG_CIFS_STATS
57500 - atomic_set(&tcon->stats.cifs_stats.num_writes, 0);
57501 - atomic_set(&tcon->stats.cifs_stats.num_reads, 0);
57502 - atomic_set(&tcon->stats.cifs_stats.num_flushes, 0);
57503 - atomic_set(&tcon->stats.cifs_stats.num_oplock_brks, 0);
57504 - atomic_set(&tcon->stats.cifs_stats.num_opens, 0);
57505 - atomic_set(&tcon->stats.cifs_stats.num_posixopens, 0);
57506 - atomic_set(&tcon->stats.cifs_stats.num_posixmkdirs, 0);
57507 - atomic_set(&tcon->stats.cifs_stats.num_closes, 0);
57508 - atomic_set(&tcon->stats.cifs_stats.num_deletes, 0);
57509 - atomic_set(&tcon->stats.cifs_stats.num_mkdirs, 0);
57510 - atomic_set(&tcon->stats.cifs_stats.num_rmdirs, 0);
57511 - atomic_set(&tcon->stats.cifs_stats.num_renames, 0);
57512 - atomic_set(&tcon->stats.cifs_stats.num_t2renames, 0);
57513 - atomic_set(&tcon->stats.cifs_stats.num_ffirst, 0);
57514 - atomic_set(&tcon->stats.cifs_stats.num_fnext, 0);
57515 - atomic_set(&tcon->stats.cifs_stats.num_fclose, 0);
57516 - atomic_set(&tcon->stats.cifs_stats.num_hardlinks, 0);
57517 - atomic_set(&tcon->stats.cifs_stats.num_symlinks, 0);
57518 - atomic_set(&tcon->stats.cifs_stats.num_locks, 0);
57519 - atomic_set(&tcon->stats.cifs_stats.num_acl_get, 0);
57520 - atomic_set(&tcon->stats.cifs_stats.num_acl_set, 0);
57521 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_writes, 0);
57522 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_reads, 0);
57523 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_flushes, 0);
57524 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_oplock_brks, 0);
57525 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_opens, 0);
57526 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_posixopens, 0);
57527 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_posixmkdirs, 0);
57528 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_closes, 0);
57529 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_deletes, 0);
57530 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_mkdirs, 0);
57531 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_rmdirs, 0);
57532 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_renames, 0);
57533 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_t2renames, 0);
57534 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_ffirst, 0);
57535 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_fnext, 0);
57536 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_fclose, 0);
57537 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_hardlinks, 0);
57538 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_symlinks, 0);
57539 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_locks, 0);
57540 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_acl_get, 0);
57541 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_acl_set, 0);
57542 #endif
57543 }
57544
57545 @@ -638,36 +638,36 @@ cifs_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
57546 {
57547 #ifdef CONFIG_CIFS_STATS
57548 seq_printf(m, " Oplocks breaks: %d",
57549 - atomic_read(&tcon->stats.cifs_stats.num_oplock_brks));
57550 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_oplock_brks));
57551 seq_printf(m, "\nReads: %d Bytes: %llu",
57552 - atomic_read(&tcon->stats.cifs_stats.num_reads),
57553 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_reads),
57554 (long long)(tcon->bytes_read));
57555 seq_printf(m, "\nWrites: %d Bytes: %llu",
57556 - atomic_read(&tcon->stats.cifs_stats.num_writes),
57557 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_writes),
57558 (long long)(tcon->bytes_written));
57559 seq_printf(m, "\nFlushes: %d",
57560 - atomic_read(&tcon->stats.cifs_stats.num_flushes));
57561 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_flushes));
57562 seq_printf(m, "\nLocks: %d HardLinks: %d Symlinks: %d",
57563 - atomic_read(&tcon->stats.cifs_stats.num_locks),
57564 - atomic_read(&tcon->stats.cifs_stats.num_hardlinks),
57565 - atomic_read(&tcon->stats.cifs_stats.num_symlinks));
57566 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_locks),
57567 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_hardlinks),
57568 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_symlinks));
57569 seq_printf(m, "\nOpens: %d Closes: %d Deletes: %d",
57570 - atomic_read(&tcon->stats.cifs_stats.num_opens),
57571 - atomic_read(&tcon->stats.cifs_stats.num_closes),
57572 - atomic_read(&tcon->stats.cifs_stats.num_deletes));
57573 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_opens),
57574 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_closes),
57575 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_deletes));
57576 seq_printf(m, "\nPosix Opens: %d Posix Mkdirs: %d",
57577 - atomic_read(&tcon->stats.cifs_stats.num_posixopens),
57578 - atomic_read(&tcon->stats.cifs_stats.num_posixmkdirs));
57579 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_posixopens),
57580 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_posixmkdirs));
57581 seq_printf(m, "\nMkdirs: %d Rmdirs: %d",
57582 - atomic_read(&tcon->stats.cifs_stats.num_mkdirs),
57583 - atomic_read(&tcon->stats.cifs_stats.num_rmdirs));
57584 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_mkdirs),
57585 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_rmdirs));
57586 seq_printf(m, "\nRenames: %d T2 Renames %d",
57587 - atomic_read(&tcon->stats.cifs_stats.num_renames),
57588 - atomic_read(&tcon->stats.cifs_stats.num_t2renames));
57589 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_renames),
57590 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_t2renames));
57591 seq_printf(m, "\nFindFirst: %d FNext %d FClose %d",
57592 - atomic_read(&tcon->stats.cifs_stats.num_ffirst),
57593 - atomic_read(&tcon->stats.cifs_stats.num_fnext),
57594 - atomic_read(&tcon->stats.cifs_stats.num_fclose));
57595 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_ffirst),
57596 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_fnext),
57597 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_fclose));
57598 #endif
57599 }
57600
57601 diff --git a/fs/cifs/smb2ops.c b/fs/cifs/smb2ops.c
57602 index 192f51a..539307e 100644
57603 --- a/fs/cifs/smb2ops.c
57604 +++ b/fs/cifs/smb2ops.c
57605 @@ -364,8 +364,8 @@ smb2_clear_stats(struct cifs_tcon *tcon)
57606 #ifdef CONFIG_CIFS_STATS
57607 int i;
57608 for (i = 0; i < NUMBER_OF_SMB2_COMMANDS; i++) {
57609 - atomic_set(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
57610 - atomic_set(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
57611 + atomic_set_unchecked(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
57612 + atomic_set_unchecked(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
57613 }
57614 #endif
57615 }
57616 @@ -405,65 +405,65 @@ static void
57617 smb2_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
57618 {
57619 #ifdef CONFIG_CIFS_STATS
57620 - atomic_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
57621 - atomic_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
57622 + atomic_unchecked_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
57623 + atomic_unchecked_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
57624 seq_printf(m, "\nNegotiates: %d sent %d failed",
57625 - atomic_read(&sent[SMB2_NEGOTIATE_HE]),
57626 - atomic_read(&failed[SMB2_NEGOTIATE_HE]));
57627 + atomic_read_unchecked(&sent[SMB2_NEGOTIATE_HE]),
57628 + atomic_read_unchecked(&failed[SMB2_NEGOTIATE_HE]));
57629 seq_printf(m, "\nSessionSetups: %d sent %d failed",
57630 - atomic_read(&sent[SMB2_SESSION_SETUP_HE]),
57631 - atomic_read(&failed[SMB2_SESSION_SETUP_HE]));
57632 + atomic_read_unchecked(&sent[SMB2_SESSION_SETUP_HE]),
57633 + atomic_read_unchecked(&failed[SMB2_SESSION_SETUP_HE]));
57634 seq_printf(m, "\nLogoffs: %d sent %d failed",
57635 - atomic_read(&sent[SMB2_LOGOFF_HE]),
57636 - atomic_read(&failed[SMB2_LOGOFF_HE]));
57637 + atomic_read_unchecked(&sent[SMB2_LOGOFF_HE]),
57638 + atomic_read_unchecked(&failed[SMB2_LOGOFF_HE]));
57639 seq_printf(m, "\nTreeConnects: %d sent %d failed",
57640 - atomic_read(&sent[SMB2_TREE_CONNECT_HE]),
57641 - atomic_read(&failed[SMB2_TREE_CONNECT_HE]));
57642 + atomic_read_unchecked(&sent[SMB2_TREE_CONNECT_HE]),
57643 + atomic_read_unchecked(&failed[SMB2_TREE_CONNECT_HE]));
57644 seq_printf(m, "\nTreeDisconnects: %d sent %d failed",
57645 - atomic_read(&sent[SMB2_TREE_DISCONNECT_HE]),
57646 - atomic_read(&failed[SMB2_TREE_DISCONNECT_HE]));
57647 + atomic_read_unchecked(&sent[SMB2_TREE_DISCONNECT_HE]),
57648 + atomic_read_unchecked(&failed[SMB2_TREE_DISCONNECT_HE]));
57649 seq_printf(m, "\nCreates: %d sent %d failed",
57650 - atomic_read(&sent[SMB2_CREATE_HE]),
57651 - atomic_read(&failed[SMB2_CREATE_HE]));
57652 + atomic_read_unchecked(&sent[SMB2_CREATE_HE]),
57653 + atomic_read_unchecked(&failed[SMB2_CREATE_HE]));
57654 seq_printf(m, "\nCloses: %d sent %d failed",
57655 - atomic_read(&sent[SMB2_CLOSE_HE]),
57656 - atomic_read(&failed[SMB2_CLOSE_HE]));
57657 + atomic_read_unchecked(&sent[SMB2_CLOSE_HE]),
57658 + atomic_read_unchecked(&failed[SMB2_CLOSE_HE]));
57659 seq_printf(m, "\nFlushes: %d sent %d failed",
57660 - atomic_read(&sent[SMB2_FLUSH_HE]),
57661 - atomic_read(&failed[SMB2_FLUSH_HE]));
57662 + atomic_read_unchecked(&sent[SMB2_FLUSH_HE]),
57663 + atomic_read_unchecked(&failed[SMB2_FLUSH_HE]));
57664 seq_printf(m, "\nReads: %d sent %d failed",
57665 - atomic_read(&sent[SMB2_READ_HE]),
57666 - atomic_read(&failed[SMB2_READ_HE]));
57667 + atomic_read_unchecked(&sent[SMB2_READ_HE]),
57668 + atomic_read_unchecked(&failed[SMB2_READ_HE]));
57669 seq_printf(m, "\nWrites: %d sent %d failed",
57670 - atomic_read(&sent[SMB2_WRITE_HE]),
57671 - atomic_read(&failed[SMB2_WRITE_HE]));
57672 + atomic_read_unchecked(&sent[SMB2_WRITE_HE]),
57673 + atomic_read_unchecked(&failed[SMB2_WRITE_HE]));
57674 seq_printf(m, "\nLocks: %d sent %d failed",
57675 - atomic_read(&sent[SMB2_LOCK_HE]),
57676 - atomic_read(&failed[SMB2_LOCK_HE]));
57677 + atomic_read_unchecked(&sent[SMB2_LOCK_HE]),
57678 + atomic_read_unchecked(&failed[SMB2_LOCK_HE]));
57679 seq_printf(m, "\nIOCTLs: %d sent %d failed",
57680 - atomic_read(&sent[SMB2_IOCTL_HE]),
57681 - atomic_read(&failed[SMB2_IOCTL_HE]));
57682 + atomic_read_unchecked(&sent[SMB2_IOCTL_HE]),
57683 + atomic_read_unchecked(&failed[SMB2_IOCTL_HE]));
57684 seq_printf(m, "\nCancels: %d sent %d failed",
57685 - atomic_read(&sent[SMB2_CANCEL_HE]),
57686 - atomic_read(&failed[SMB2_CANCEL_HE]));
57687 + atomic_read_unchecked(&sent[SMB2_CANCEL_HE]),
57688 + atomic_read_unchecked(&failed[SMB2_CANCEL_HE]));
57689 seq_printf(m, "\nEchos: %d sent %d failed",
57690 - atomic_read(&sent[SMB2_ECHO_HE]),
57691 - atomic_read(&failed[SMB2_ECHO_HE]));
57692 + atomic_read_unchecked(&sent[SMB2_ECHO_HE]),
57693 + atomic_read_unchecked(&failed[SMB2_ECHO_HE]));
57694 seq_printf(m, "\nQueryDirectories: %d sent %d failed",
57695 - atomic_read(&sent[SMB2_QUERY_DIRECTORY_HE]),
57696 - atomic_read(&failed[SMB2_QUERY_DIRECTORY_HE]));
57697 + atomic_read_unchecked(&sent[SMB2_QUERY_DIRECTORY_HE]),
57698 + atomic_read_unchecked(&failed[SMB2_QUERY_DIRECTORY_HE]));
57699 seq_printf(m, "\nChangeNotifies: %d sent %d failed",
57700 - atomic_read(&sent[SMB2_CHANGE_NOTIFY_HE]),
57701 - atomic_read(&failed[SMB2_CHANGE_NOTIFY_HE]));
57702 + atomic_read_unchecked(&sent[SMB2_CHANGE_NOTIFY_HE]),
57703 + atomic_read_unchecked(&failed[SMB2_CHANGE_NOTIFY_HE]));
57704 seq_printf(m, "\nQueryInfos: %d sent %d failed",
57705 - atomic_read(&sent[SMB2_QUERY_INFO_HE]),
57706 - atomic_read(&failed[SMB2_QUERY_INFO_HE]));
57707 + atomic_read_unchecked(&sent[SMB2_QUERY_INFO_HE]),
57708 + atomic_read_unchecked(&failed[SMB2_QUERY_INFO_HE]));
57709 seq_printf(m, "\nSetInfos: %d sent %d failed",
57710 - atomic_read(&sent[SMB2_SET_INFO_HE]),
57711 - atomic_read(&failed[SMB2_SET_INFO_HE]));
57712 + atomic_read_unchecked(&sent[SMB2_SET_INFO_HE]),
57713 + atomic_read_unchecked(&failed[SMB2_SET_INFO_HE]));
57714 seq_printf(m, "\nOplockBreaks: %d sent %d failed",
57715 - atomic_read(&sent[SMB2_OPLOCK_BREAK_HE]),
57716 - atomic_read(&failed[SMB2_OPLOCK_BREAK_HE]));
57717 + atomic_read_unchecked(&sent[SMB2_OPLOCK_BREAK_HE]),
57718 + atomic_read_unchecked(&failed[SMB2_OPLOCK_BREAK_HE]));
57719 #endif
57720 }
57721
57722 diff --git a/fs/cifs/smb2pdu.c b/fs/cifs/smb2pdu.c
57723 index 787e171..31dcd0a 100644
57724 --- a/fs/cifs/smb2pdu.c
57725 +++ b/fs/cifs/smb2pdu.c
57726 @@ -2093,8 +2093,7 @@ SMB2_query_directory(const unsigned int xid, struct cifs_tcon *tcon,
57727 default:
57728 cifs_dbg(VFS, "info level %u isn't supported\n",
57729 srch_inf->info_level);
57730 - rc = -EINVAL;
57731 - goto qdir_exit;
57732 + return -EINVAL;
57733 }
57734
57735 req->FileIndex = cpu_to_le32(index);
57736 diff --git a/fs/coda/cache.c b/fs/coda/cache.c
57737 index 1da168c..8bc7ff6 100644
57738 --- a/fs/coda/cache.c
57739 +++ b/fs/coda/cache.c
57740 @@ -24,7 +24,7 @@
57741 #include "coda_linux.h"
57742 #include "coda_cache.h"
57743
57744 -static atomic_t permission_epoch = ATOMIC_INIT(0);
57745 +static atomic_unchecked_t permission_epoch = ATOMIC_INIT(0);
57746
57747 /* replace or extend an acl cache hit */
57748 void coda_cache_enter(struct inode *inode, int mask)
57749 @@ -32,7 +32,7 @@ void coda_cache_enter(struct inode *inode, int mask)
57750 struct coda_inode_info *cii = ITOC(inode);
57751
57752 spin_lock(&cii->c_lock);
57753 - cii->c_cached_epoch = atomic_read(&permission_epoch);
57754 + cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch);
57755 if (!uid_eq(cii->c_uid, current_fsuid())) {
57756 cii->c_uid = current_fsuid();
57757 cii->c_cached_perm = mask;
57758 @@ -46,14 +46,14 @@ void coda_cache_clear_inode(struct inode *inode)
57759 {
57760 struct coda_inode_info *cii = ITOC(inode);
57761 spin_lock(&cii->c_lock);
57762 - cii->c_cached_epoch = atomic_read(&permission_epoch) - 1;
57763 + cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch) - 1;
57764 spin_unlock(&cii->c_lock);
57765 }
57766
57767 /* remove all acl caches */
57768 void coda_cache_clear_all(struct super_block *sb)
57769 {
57770 - atomic_inc(&permission_epoch);
57771 + atomic_inc_unchecked(&permission_epoch);
57772 }
57773
57774
57775 @@ -66,7 +66,7 @@ int coda_cache_check(struct inode *inode, int mask)
57776 spin_lock(&cii->c_lock);
57777 hit = (mask & cii->c_cached_perm) == mask &&
57778 uid_eq(cii->c_uid, current_fsuid()) &&
57779 - cii->c_cached_epoch == atomic_read(&permission_epoch);
57780 + cii->c_cached_epoch == atomic_read_unchecked(&permission_epoch);
57781 spin_unlock(&cii->c_lock);
57782
57783 return hit;
57784 diff --git a/fs/compat.c b/fs/compat.c
57785 index 6af20de..fec3fbb 100644
57786 --- a/fs/compat.c
57787 +++ b/fs/compat.c
57788 @@ -54,7 +54,7 @@
57789 #include <asm/ioctls.h>
57790 #include "internal.h"
57791
57792 -int compat_log = 1;
57793 +int compat_log = 0;
57794
57795 int compat_printk(const char *fmt, ...)
57796 {
57797 @@ -488,7 +488,7 @@ compat_sys_io_setup(unsigned nr_reqs, u32 __user *ctx32p)
57798
57799 set_fs(KERNEL_DS);
57800 /* The __user pointer cast is valid because of the set_fs() */
57801 - ret = sys_io_setup(nr_reqs, (aio_context_t __user *) &ctx64);
57802 + ret = sys_io_setup(nr_reqs, (aio_context_t __force_user *) &ctx64);
57803 set_fs(oldfs);
57804 /* truncating is ok because it's a user address */
57805 if (!ret)
57806 @@ -546,7 +546,7 @@ ssize_t compat_rw_copy_check_uvector(int type,
57807 goto out;
57808
57809 ret = -EINVAL;
57810 - if (nr_segs > UIO_MAXIOV || nr_segs < 0)
57811 + if (nr_segs > UIO_MAXIOV)
57812 goto out;
57813 if (nr_segs > fast_segs) {
57814 ret = -ENOMEM;
57815 @@ -834,6 +834,7 @@ struct compat_old_linux_dirent {
57816 struct compat_readdir_callback {
57817 struct dir_context ctx;
57818 struct compat_old_linux_dirent __user *dirent;
57819 + struct file * file;
57820 int result;
57821 };
57822
57823 @@ -851,6 +852,10 @@ static int compat_fillonedir(void *__buf, const char *name, int namlen,
57824 buf->result = -EOVERFLOW;
57825 return -EOVERFLOW;
57826 }
57827 +
57828 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
57829 + return 0;
57830 +
57831 buf->result++;
57832 dirent = buf->dirent;
57833 if (!access_ok(VERIFY_WRITE, dirent,
57834 @@ -882,6 +887,7 @@ asmlinkage long compat_sys_old_readdir(unsigned int fd,
57835 if (!f.file)
57836 return -EBADF;
57837
57838 + buf.file = f.file;
57839 error = iterate_dir(f.file, &buf.ctx);
57840 if (buf.result)
57841 error = buf.result;
57842 @@ -901,6 +907,7 @@ struct compat_getdents_callback {
57843 struct dir_context ctx;
57844 struct compat_linux_dirent __user *current_dir;
57845 struct compat_linux_dirent __user *previous;
57846 + struct file * file;
57847 int count;
57848 int error;
57849 };
57850 @@ -922,6 +929,10 @@ static int compat_filldir(void *__buf, const char *name, int namlen,
57851 buf->error = -EOVERFLOW;
57852 return -EOVERFLOW;
57853 }
57854 +
57855 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
57856 + return 0;
57857 +
57858 dirent = buf->previous;
57859 if (dirent) {
57860 if (__put_user(offset, &dirent->d_off))
57861 @@ -967,6 +978,7 @@ asmlinkage long compat_sys_getdents(unsigned int fd,
57862 if (!f.file)
57863 return -EBADF;
57864
57865 + buf.file = f.file;
57866 error = iterate_dir(f.file, &buf.ctx);
57867 if (error >= 0)
57868 error = buf.error;
57869 @@ -987,6 +999,7 @@ struct compat_getdents_callback64 {
57870 struct dir_context ctx;
57871 struct linux_dirent64 __user *current_dir;
57872 struct linux_dirent64 __user *previous;
57873 + struct file * file;
57874 int count;
57875 int error;
57876 };
57877 @@ -1003,6 +1016,10 @@ static int compat_filldir64(void * __buf, const char * name, int namlen, loff_t
57878 buf->error = -EINVAL; /* only used if we fail.. */
57879 if (reclen > buf->count)
57880 return -EINVAL;
57881 +
57882 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
57883 + return 0;
57884 +
57885 dirent = buf->previous;
57886
57887 if (dirent) {
57888 @@ -1052,6 +1069,7 @@ asmlinkage long compat_sys_getdents64(unsigned int fd,
57889 if (!f.file)
57890 return -EBADF;
57891
57892 + buf.file = f.file;
57893 error = iterate_dir(f.file, &buf.ctx);
57894 if (error >= 0)
57895 error = buf.error;
57896 diff --git a/fs/compat_binfmt_elf.c b/fs/compat_binfmt_elf.c
57897 index a81147e..20bf2b5 100644
57898 --- a/fs/compat_binfmt_elf.c
57899 +++ b/fs/compat_binfmt_elf.c
57900 @@ -30,11 +30,13 @@
57901 #undef elf_phdr
57902 #undef elf_shdr
57903 #undef elf_note
57904 +#undef elf_dyn
57905 #undef elf_addr_t
57906 #define elfhdr elf32_hdr
57907 #define elf_phdr elf32_phdr
57908 #define elf_shdr elf32_shdr
57909 #define elf_note elf32_note
57910 +#define elf_dyn Elf32_Dyn
57911 #define elf_addr_t Elf32_Addr
57912
57913 /*
57914 diff --git a/fs/compat_ioctl.c b/fs/compat_ioctl.c
57915 index dc52e13..ec61057 100644
57916 --- a/fs/compat_ioctl.c
57917 +++ b/fs/compat_ioctl.c
57918 @@ -621,7 +621,7 @@ static int serial_struct_ioctl(unsigned fd, unsigned cmd,
57919 return -EFAULT;
57920 if (__get_user(udata, &ss32->iomem_base))
57921 return -EFAULT;
57922 - ss.iomem_base = compat_ptr(udata);
57923 + ss.iomem_base = (unsigned char __force_kernel *)compat_ptr(udata);
57924 if (__get_user(ss.iomem_reg_shift, &ss32->iomem_reg_shift) ||
57925 __get_user(ss.port_high, &ss32->port_high))
57926 return -EFAULT;
57927 @@ -702,8 +702,8 @@ static int do_i2c_rdwr_ioctl(unsigned int fd, unsigned int cmd,
57928 for (i = 0; i < nmsgs; i++) {
57929 if (copy_in_user(&tmsgs[i].addr, &umsgs[i].addr, 3*sizeof(u16)))
57930 return -EFAULT;
57931 - if (get_user(datap, &umsgs[i].buf) ||
57932 - put_user(compat_ptr(datap), &tmsgs[i].buf))
57933 + if (get_user(datap, (u8 __user * __user *)&umsgs[i].buf) ||
57934 + put_user(compat_ptr(datap), (u8 __user * __user *)&tmsgs[i].buf))
57935 return -EFAULT;
57936 }
57937 return sys_ioctl(fd, cmd, (unsigned long)tdata);
57938 @@ -796,7 +796,7 @@ static int compat_ioctl_preallocate(struct file *file,
57939 copy_in_user(&p->l_len, &p32->l_len, sizeof(s64)) ||
57940 copy_in_user(&p->l_sysid, &p32->l_sysid, sizeof(s32)) ||
57941 copy_in_user(&p->l_pid, &p32->l_pid, sizeof(u32)) ||
57942 - copy_in_user(&p->l_pad, &p32->l_pad, 4*sizeof(u32)))
57943 + copy_in_user(p->l_pad, p32->l_pad, 4*sizeof(u32)))
57944 return -EFAULT;
57945
57946 return ioctl_preallocate(file, p);
57947 @@ -1616,8 +1616,8 @@ asmlinkage long compat_sys_ioctl(unsigned int fd, unsigned int cmd,
57948 static int __init init_sys32_ioctl_cmp(const void *p, const void *q)
57949 {
57950 unsigned int a, b;
57951 - a = *(unsigned int *)p;
57952 - b = *(unsigned int *)q;
57953 + a = *(const unsigned int *)p;
57954 + b = *(const unsigned int *)q;
57955 if (a > b)
57956 return 1;
57957 if (a < b)
57958 diff --git a/fs/configfs/dir.c b/fs/configfs/dir.c
57959 index e081acb..911df21 100644
57960 --- a/fs/configfs/dir.c
57961 +++ b/fs/configfs/dir.c
57962 @@ -1548,7 +1548,8 @@ static int configfs_readdir(struct file *file, struct dir_context *ctx)
57963 }
57964 for (p = q->next; p != &parent_sd->s_children; p = p->next) {
57965 struct configfs_dirent *next;
57966 - const char *name;
57967 + const unsigned char * name;
57968 + char d_name[sizeof(next->s_dentry->d_iname)];
57969 int len;
57970 struct inode *inode = NULL;
57971
57972 @@ -1557,7 +1558,12 @@ static int configfs_readdir(struct file *file, struct dir_context *ctx)
57973 continue;
57974
57975 name = configfs_get_name(next);
57976 - len = strlen(name);
57977 + if (next->s_dentry && name == next->s_dentry->d_iname) {
57978 + len = next->s_dentry->d_name.len;
57979 + memcpy(d_name, name, len);
57980 + name = d_name;
57981 + } else
57982 + len = strlen(name);
57983
57984 /*
57985 * We'll have a dentry and an inode for
57986 diff --git a/fs/coredump.c b/fs/coredump.c
57987 index bc3fbcd..6031650 100644
57988 --- a/fs/coredump.c
57989 +++ b/fs/coredump.c
57990 @@ -438,8 +438,8 @@ static void wait_for_dump_helpers(struct file *file)
57991 struct pipe_inode_info *pipe = file->private_data;
57992
57993 pipe_lock(pipe);
57994 - pipe->readers++;
57995 - pipe->writers--;
57996 + atomic_inc(&pipe->readers);
57997 + atomic_dec(&pipe->writers);
57998 wake_up_interruptible_sync(&pipe->wait);
57999 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
58000 pipe_unlock(pipe);
58001 @@ -448,11 +448,11 @@ static void wait_for_dump_helpers(struct file *file)
58002 * We actually want wait_event_freezable() but then we need
58003 * to clear TIF_SIGPENDING and improve dump_interrupted().
58004 */
58005 - wait_event_interruptible(pipe->wait, pipe->readers == 1);
58006 + wait_event_interruptible(pipe->wait, atomic_read(&pipe->readers) == 1);
58007
58008 pipe_lock(pipe);
58009 - pipe->readers--;
58010 - pipe->writers++;
58011 + atomic_dec(&pipe->readers);
58012 + atomic_inc(&pipe->writers);
58013 pipe_unlock(pipe);
58014 }
58015
58016 @@ -499,7 +499,9 @@ void do_coredump(const siginfo_t *siginfo)
58017 struct files_struct *displaced;
58018 bool need_nonrelative = false;
58019 bool core_dumped = false;
58020 - static atomic_t core_dump_count = ATOMIC_INIT(0);
58021 + static atomic_unchecked_t core_dump_count = ATOMIC_INIT(0);
58022 + long signr = siginfo->si_signo;
58023 + int dumpable;
58024 struct coredump_params cprm = {
58025 .siginfo = siginfo,
58026 .regs = signal_pt_regs(),
58027 @@ -512,12 +514,17 @@ void do_coredump(const siginfo_t *siginfo)
58028 .mm_flags = mm->flags,
58029 };
58030
58031 - audit_core_dumps(siginfo->si_signo);
58032 + audit_core_dumps(signr);
58033 +
58034 + dumpable = __get_dumpable(cprm.mm_flags);
58035 +
58036 + if (signr == SIGSEGV || signr == SIGBUS || signr == SIGKILL || signr == SIGILL)
58037 + gr_handle_brute_attach(dumpable);
58038
58039 binfmt = mm->binfmt;
58040 if (!binfmt || !binfmt->core_dump)
58041 goto fail;
58042 - if (!__get_dumpable(cprm.mm_flags))
58043 + if (!dumpable)
58044 goto fail;
58045
58046 cred = prepare_creds();
58047 @@ -536,7 +543,7 @@ void do_coredump(const siginfo_t *siginfo)
58048 need_nonrelative = true;
58049 }
58050
58051 - retval = coredump_wait(siginfo->si_signo, &core_state);
58052 + retval = coredump_wait(signr, &core_state);
58053 if (retval < 0)
58054 goto fail_creds;
58055
58056 @@ -579,7 +586,7 @@ void do_coredump(const siginfo_t *siginfo)
58057 }
58058 cprm.limit = RLIM_INFINITY;
58059
58060 - dump_count = atomic_inc_return(&core_dump_count);
58061 + dump_count = atomic_inc_return_unchecked(&core_dump_count);
58062 if (core_pipe_limit && (core_pipe_limit < dump_count)) {
58063 printk(KERN_WARNING "Pid %d(%s) over core_pipe_limit\n",
58064 task_tgid_vnr(current), current->comm);
58065 @@ -611,6 +618,8 @@ void do_coredump(const siginfo_t *siginfo)
58066 } else {
58067 struct inode *inode;
58068
58069 + gr_learn_resource(current, RLIMIT_CORE, binfmt->min_coredump, 1);
58070 +
58071 if (cprm.limit < binfmt->min_coredump)
58072 goto fail_unlock;
58073
58074 @@ -669,7 +678,7 @@ close_fail:
58075 filp_close(cprm.file, NULL);
58076 fail_dropcount:
58077 if (ispipe)
58078 - atomic_dec(&core_dump_count);
58079 + atomic_dec_unchecked(&core_dump_count);
58080 fail_unlock:
58081 kfree(cn.corename);
58082 coredump_finish(mm, core_dumped);
58083 @@ -690,6 +699,8 @@ int dump_emit(struct coredump_params *cprm, const void *addr, int nr)
58084 struct file *file = cprm->file;
58085 loff_t pos = file->f_pos;
58086 ssize_t n;
58087 +
58088 + gr_learn_resource(current, RLIMIT_CORE, cprm->written + nr, 1);
58089 if (cprm->written + nr > cprm->limit)
58090 return 0;
58091 while (nr) {
58092 diff --git a/fs/dcache.c b/fs/dcache.c
58093 index f7ad6d7..d852932 100644
58094 --- a/fs/dcache.c
58095 +++ b/fs/dcache.c
58096 @@ -1495,7 +1495,7 @@ struct dentry *__d_alloc(struct super_block *sb, const struct qstr *name)
58097 */
58098 dentry->d_iname[DNAME_INLINE_LEN-1] = 0;
58099 if (name->len > DNAME_INLINE_LEN-1) {
58100 - dname = kmalloc(name->len + 1, GFP_KERNEL);
58101 + dname = kmalloc(round_up(name->len + 1, sizeof(unsigned long)), GFP_KERNEL);
58102 if (!dname) {
58103 kmem_cache_free(dentry_cache, dentry);
58104 return NULL;
58105 @@ -3428,7 +3428,8 @@ void __init vfs_caches_init(unsigned long mempages)
58106 mempages -= reserve;
58107
58108 names_cachep = kmem_cache_create("names_cache", PATH_MAX, 0,
58109 - SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
58110 + SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_USERCOPY|
58111 + SLAB_NO_SANITIZE, NULL);
58112
58113 dcache_init();
58114 inode_init();
58115 diff --git a/fs/debugfs/inode.c b/fs/debugfs/inode.c
58116 index 9c0444c..628490c 100644
58117 --- a/fs/debugfs/inode.c
58118 +++ b/fs/debugfs/inode.c
58119 @@ -415,7 +415,11 @@ EXPORT_SYMBOL_GPL(debugfs_create_file);
58120 */
58121 struct dentry *debugfs_create_dir(const char *name, struct dentry *parent)
58122 {
58123 +#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
58124 + return __create_file(name, S_IFDIR | S_IRWXU,
58125 +#else
58126 return __create_file(name, S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO,
58127 +#endif
58128 parent, NULL, NULL);
58129 }
58130 EXPORT_SYMBOL_GPL(debugfs_create_dir);
58131 diff --git a/fs/ecryptfs/inode.c b/fs/ecryptfs/inode.c
58132 index c36c448..fc96710 100644
58133 --- a/fs/ecryptfs/inode.c
58134 +++ b/fs/ecryptfs/inode.c
58135 @@ -675,7 +675,7 @@ static int ecryptfs_readlink_lower(struct dentry *dentry, char **buf,
58136 old_fs = get_fs();
58137 set_fs(get_ds());
58138 rc = lower_dentry->d_inode->i_op->readlink(lower_dentry,
58139 - (char __user *)lower_buf,
58140 + (char __force_user *)lower_buf,
58141 PATH_MAX);
58142 set_fs(old_fs);
58143 if (rc < 0)
58144 diff --git a/fs/ecryptfs/miscdev.c b/fs/ecryptfs/miscdev.c
58145 index e4141f2..d8263e8 100644
58146 --- a/fs/ecryptfs/miscdev.c
58147 +++ b/fs/ecryptfs/miscdev.c
58148 @@ -304,7 +304,7 @@ check_list:
58149 goto out_unlock_msg_ctx;
58150 i = PKT_TYPE_SIZE + PKT_CTR_SIZE;
58151 if (msg_ctx->msg) {
58152 - if (copy_to_user(&buf[i], packet_length, packet_length_size))
58153 + if (packet_length_size > sizeof(packet_length) || copy_to_user(&buf[i], packet_length, packet_length_size))
58154 goto out_unlock_msg_ctx;
58155 i += packet_length_size;
58156 if (copy_to_user(&buf[i], msg_ctx->msg, msg_ctx->msg_size))
58157 diff --git a/fs/exec.c b/fs/exec.c
58158 index 7ea097f..5862cb5 100644
58159 --- a/fs/exec.c
58160 +++ b/fs/exec.c
58161 @@ -55,8 +55,20 @@
58162 #include <linux/pipe_fs_i.h>
58163 #include <linux/oom.h>
58164 #include <linux/compat.h>
58165 +#include <linux/random.h>
58166 +#include <linux/seq_file.h>
58167 +#include <linux/coredump.h>
58168 +#include <linux/mman.h>
58169 +
58170 +#ifdef CONFIG_PAX_REFCOUNT
58171 +#include <linux/kallsyms.h>
58172 +#include <linux/kdebug.h>
58173 +#endif
58174 +
58175 +#include <trace/events/fs.h>
58176
58177 #include <asm/uaccess.h>
58178 +#include <asm/sections.h>
58179 #include <asm/mmu_context.h>
58180 #include <asm/tlb.h>
58181
58182 @@ -66,19 +78,34 @@
58183
58184 #include <trace/events/sched.h>
58185
58186 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
58187 +void __weak pax_set_initial_flags(struct linux_binprm *bprm)
58188 +{
58189 + 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");
58190 +}
58191 +#endif
58192 +
58193 +#ifdef CONFIG_PAX_HOOK_ACL_FLAGS
58194 +void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
58195 +EXPORT_SYMBOL(pax_set_initial_flags_func);
58196 +#endif
58197 +
58198 int suid_dumpable = 0;
58199
58200 static LIST_HEAD(formats);
58201 static DEFINE_RWLOCK(binfmt_lock);
58202
58203 +extern int gr_process_kernel_exec_ban(void);
58204 +extern int gr_process_suid_exec_ban(const struct linux_binprm *bprm);
58205 +
58206 void __register_binfmt(struct linux_binfmt * fmt, int insert)
58207 {
58208 BUG_ON(!fmt);
58209 if (WARN_ON(!fmt->load_binary))
58210 return;
58211 write_lock(&binfmt_lock);
58212 - insert ? list_add(&fmt->lh, &formats) :
58213 - list_add_tail(&fmt->lh, &formats);
58214 + insert ? pax_list_add((struct list_head *)&fmt->lh, &formats) :
58215 + pax_list_add_tail((struct list_head *)&fmt->lh, &formats);
58216 write_unlock(&binfmt_lock);
58217 }
58218
58219 @@ -87,7 +114,7 @@ EXPORT_SYMBOL(__register_binfmt);
58220 void unregister_binfmt(struct linux_binfmt * fmt)
58221 {
58222 write_lock(&binfmt_lock);
58223 - list_del(&fmt->lh);
58224 + pax_list_del((struct list_head *)&fmt->lh);
58225 write_unlock(&binfmt_lock);
58226 }
58227
58228 @@ -181,18 +208,10 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
58229 int write)
58230 {
58231 struct page *page;
58232 - int ret;
58233
58234 -#ifdef CONFIG_STACK_GROWSUP
58235 - if (write) {
58236 - ret = expand_downwards(bprm->vma, pos);
58237 - if (ret < 0)
58238 - return NULL;
58239 - }
58240 -#endif
58241 - ret = get_user_pages(current, bprm->mm, pos,
58242 - 1, write, 1, &page, NULL);
58243 - if (ret <= 0)
58244 + if (0 > expand_downwards(bprm->vma, pos))
58245 + return NULL;
58246 + if (0 >= get_user_pages(current, bprm->mm, pos, 1, write, 1, &page, NULL))
58247 return NULL;
58248
58249 if (write) {
58250 @@ -208,6 +227,17 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
58251 if (size <= ARG_MAX)
58252 return page;
58253
58254 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
58255 + // only allow 512KB for argv+env on suid/sgid binaries
58256 + // to prevent easy ASLR exhaustion
58257 + if (((!uid_eq(bprm->cred->euid, current_euid())) ||
58258 + (!gid_eq(bprm->cred->egid, current_egid()))) &&
58259 + (size > (512 * 1024))) {
58260 + put_page(page);
58261 + return NULL;
58262 + }
58263 +#endif
58264 +
58265 /*
58266 * Limit to 1/4-th the stack size for the argv+env strings.
58267 * This ensures that:
58268 @@ -267,6 +297,11 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
58269 vma->vm_end = STACK_TOP_MAX;
58270 vma->vm_start = vma->vm_end - PAGE_SIZE;
58271 vma->vm_flags = VM_SOFTDIRTY | VM_STACK_FLAGS | VM_STACK_INCOMPLETE_SETUP;
58272 +
58273 +#ifdef CONFIG_PAX_SEGMEXEC
58274 + vma->vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
58275 +#endif
58276 +
58277 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
58278 INIT_LIST_HEAD(&vma->anon_vma_chain);
58279
58280 @@ -277,6 +312,12 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
58281 mm->stack_vm = mm->total_vm = 1;
58282 up_write(&mm->mmap_sem);
58283 bprm->p = vma->vm_end - sizeof(void *);
58284 +
58285 +#ifdef CONFIG_PAX_RANDUSTACK
58286 + if (randomize_va_space)
58287 + bprm->p ^= prandom_u32() & ~PAGE_MASK;
58288 +#endif
58289 +
58290 return 0;
58291 err:
58292 up_write(&mm->mmap_sem);
58293 @@ -397,7 +438,7 @@ struct user_arg_ptr {
58294 } ptr;
58295 };
58296
58297 -static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
58298 +const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
58299 {
58300 const char __user *native;
58301
58302 @@ -406,14 +447,14 @@ static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
58303 compat_uptr_t compat;
58304
58305 if (get_user(compat, argv.ptr.compat + nr))
58306 - return ERR_PTR(-EFAULT);
58307 + return (const char __force_user *)ERR_PTR(-EFAULT);
58308
58309 return compat_ptr(compat);
58310 }
58311 #endif
58312
58313 if (get_user(native, argv.ptr.native + nr))
58314 - return ERR_PTR(-EFAULT);
58315 + return (const char __force_user *)ERR_PTR(-EFAULT);
58316
58317 return native;
58318 }
58319 @@ -432,7 +473,7 @@ static int count(struct user_arg_ptr argv, int max)
58320 if (!p)
58321 break;
58322
58323 - if (IS_ERR(p))
58324 + if (IS_ERR((const char __force_kernel *)p))
58325 return -EFAULT;
58326
58327 if (i >= max)
58328 @@ -467,7 +508,7 @@ static int copy_strings(int argc, struct user_arg_ptr argv,
58329
58330 ret = -EFAULT;
58331 str = get_user_arg_ptr(argv, argc);
58332 - if (IS_ERR(str))
58333 + if (IS_ERR((const char __force_kernel *)str))
58334 goto out;
58335
58336 len = strnlen_user(str, MAX_ARG_STRLEN);
58337 @@ -549,7 +590,7 @@ int copy_strings_kernel(int argc, const char *const *__argv,
58338 int r;
58339 mm_segment_t oldfs = get_fs();
58340 struct user_arg_ptr argv = {
58341 - .ptr.native = (const char __user *const __user *)__argv,
58342 + .ptr.native = (const char __user * const __force_user *)__argv,
58343 };
58344
58345 set_fs(KERNEL_DS);
58346 @@ -584,7 +625,8 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
58347 unsigned long new_end = old_end - shift;
58348 struct mmu_gather tlb;
58349
58350 - BUG_ON(new_start > new_end);
58351 + if (new_start >= new_end || new_start < mmap_min_addr)
58352 + return -ENOMEM;
58353
58354 /*
58355 * ensure there are no vmas between where we want to go
58356 @@ -593,6 +635,10 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
58357 if (vma != find_vma(mm, new_start))
58358 return -EFAULT;
58359
58360 +#ifdef CONFIG_PAX_SEGMEXEC
58361 + BUG_ON(pax_find_mirror_vma(vma));
58362 +#endif
58363 +
58364 /*
58365 * cover the whole range: [new_start, old_end)
58366 */
58367 @@ -673,10 +719,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
58368 stack_top = arch_align_stack(stack_top);
58369 stack_top = PAGE_ALIGN(stack_top);
58370
58371 - if (unlikely(stack_top < mmap_min_addr) ||
58372 - unlikely(vma->vm_end - vma->vm_start >= stack_top - mmap_min_addr))
58373 - return -ENOMEM;
58374 -
58375 stack_shift = vma->vm_end - stack_top;
58376
58377 bprm->p -= stack_shift;
58378 @@ -688,8 +730,28 @@ int setup_arg_pages(struct linux_binprm *bprm,
58379 bprm->exec -= stack_shift;
58380
58381 down_write(&mm->mmap_sem);
58382 +
58383 + /* Move stack pages down in memory. */
58384 + if (stack_shift) {
58385 + ret = shift_arg_pages(vma, stack_shift);
58386 + if (ret)
58387 + goto out_unlock;
58388 + }
58389 +
58390 vm_flags = VM_STACK_FLAGS;
58391
58392 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
58393 + if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
58394 + vm_flags &= ~VM_EXEC;
58395 +
58396 +#ifdef CONFIG_PAX_MPROTECT
58397 + if (mm->pax_flags & MF_PAX_MPROTECT)
58398 + vm_flags &= ~VM_MAYEXEC;
58399 +#endif
58400 +
58401 + }
58402 +#endif
58403 +
58404 /*
58405 * Adjust stack execute permissions; explicitly enable for
58406 * EXSTACK_ENABLE_X, disable for EXSTACK_DISABLE_X and leave alone
58407 @@ -708,13 +770,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
58408 goto out_unlock;
58409 BUG_ON(prev != vma);
58410
58411 - /* Move stack pages down in memory. */
58412 - if (stack_shift) {
58413 - ret = shift_arg_pages(vma, stack_shift);
58414 - if (ret)
58415 - goto out_unlock;
58416 - }
58417 -
58418 /* mprotect_fixup is overkill to remove the temporary stack flags */
58419 vma->vm_flags &= ~VM_STACK_INCOMPLETE_SETUP;
58420
58421 @@ -738,6 +793,27 @@ int setup_arg_pages(struct linux_binprm *bprm,
58422 #endif
58423 current->mm->start_stack = bprm->p;
58424 ret = expand_stack(vma, stack_base);
58425 +
58426 +#if !defined(CONFIG_STACK_GROWSUP) && defined(CONFIG_PAX_RANDMMAP)
58427 + if (!ret && (mm->pax_flags & MF_PAX_RANDMMAP) && STACK_TOP <= 0xFFFFFFFFU && STACK_TOP > vma->vm_end) {
58428 + unsigned long size;
58429 + vm_flags_t vm_flags;
58430 +
58431 + size = STACK_TOP - vma->vm_end;
58432 + vm_flags = VM_NONE | VM_DONTEXPAND | VM_DONTDUMP;
58433 +
58434 + ret = vma->vm_end != mmap_region(NULL, vma->vm_end, size, vm_flags, 0);
58435 +
58436 +#ifdef CONFIG_X86
58437 + if (!ret) {
58438 + size = PAGE_SIZE + mmap_min_addr + ((mm->delta_mmap ^ mm->delta_stack) & (0xFFUL << PAGE_SHIFT));
58439 + ret = 0 != mmap_region(NULL, 0, PAGE_ALIGN(size), vm_flags, 0);
58440 + }
58441 +#endif
58442 +
58443 + }
58444 +#endif
58445 +
58446 if (ret)
58447 ret = -EFAULT;
58448
58449 @@ -774,6 +850,8 @@ struct file *open_exec(const char *name)
58450
58451 fsnotify_open(file);
58452
58453 + trace_open_exec(name);
58454 +
58455 err = deny_write_access(file);
58456 if (err)
58457 goto exit;
58458 @@ -797,7 +875,7 @@ int kernel_read(struct file *file, loff_t offset,
58459 old_fs = get_fs();
58460 set_fs(get_ds());
58461 /* The cast to a user pointer is valid due to the set_fs() */
58462 - result = vfs_read(file, (void __user *)addr, count, &pos);
58463 + result = vfs_read(file, (void __force_user *)addr, count, &pos);
58464 set_fs(old_fs);
58465 return result;
58466 }
58467 @@ -1253,7 +1331,7 @@ static int check_unsafe_exec(struct linux_binprm *bprm)
58468 }
58469 rcu_read_unlock();
58470
58471 - if (p->fs->users > n_fs) {
58472 + if (atomic_read(&p->fs->users) > n_fs) {
58473 bprm->unsafe |= LSM_UNSAFE_SHARE;
58474 } else {
58475 res = -EAGAIN;
58476 @@ -1443,6 +1521,31 @@ static int exec_binprm(struct linux_binprm *bprm)
58477 return ret;
58478 }
58479
58480 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
58481 +static DEFINE_PER_CPU(u64, exec_counter);
58482 +static int __init init_exec_counters(void)
58483 +{
58484 + unsigned int cpu;
58485 +
58486 + for_each_possible_cpu(cpu) {
58487 + per_cpu(exec_counter, cpu) = (u64)cpu;
58488 + }
58489 +
58490 + return 0;
58491 +}
58492 +early_initcall(init_exec_counters);
58493 +static inline void increment_exec_counter(void)
58494 +{
58495 + BUILD_BUG_ON(NR_CPUS > (1 << 16));
58496 + current->exec_id = this_cpu_add_return(exec_counter, 1 << 16);
58497 +}
58498 +#else
58499 +static inline void increment_exec_counter(void) {}
58500 +#endif
58501 +
58502 +extern void gr_handle_exec_args(struct linux_binprm *bprm,
58503 + struct user_arg_ptr argv);
58504 +
58505 /*
58506 * sys_execve() executes a new program.
58507 */
58508 @@ -1450,12 +1553,19 @@ static int do_execve_common(const char *filename,
58509 struct user_arg_ptr argv,
58510 struct user_arg_ptr envp)
58511 {
58512 +#ifdef CONFIG_GRKERNSEC
58513 + struct file *old_exec_file;
58514 + struct acl_subject_label *old_acl;
58515 + struct rlimit old_rlim[RLIM_NLIMITS];
58516 +#endif
58517 struct linux_binprm *bprm;
58518 struct file *file;
58519 struct files_struct *displaced;
58520 bool clear_in_exec;
58521 int retval;
58522
58523 + gr_learn_resource(current, RLIMIT_NPROC, atomic_read(&current_user()->processes), 1);
58524 +
58525 /*
58526 * We move the actual failure in case of RLIMIT_NPROC excess from
58527 * set*uid() to execve() because too many poorly written programs
58528 @@ -1496,12 +1606,22 @@ static int do_execve_common(const char *filename,
58529 if (IS_ERR(file))
58530 goto out_unmark;
58531
58532 + if (gr_ptrace_readexec(file, bprm->unsafe)) {
58533 + retval = -EPERM;
58534 + goto out_file;
58535 + }
58536 +
58537 sched_exec();
58538
58539 bprm->file = file;
58540 bprm->filename = filename;
58541 bprm->interp = filename;
58542
58543 + if (!gr_acl_handle_execve(file->f_path.dentry, file->f_path.mnt)) {
58544 + retval = -EACCES;
58545 + goto out_file;
58546 + }
58547 +
58548 retval = bprm_mm_init(bprm);
58549 if (retval)
58550 goto out_file;
58551 @@ -1518,24 +1638,70 @@ static int do_execve_common(const char *filename,
58552 if (retval < 0)
58553 goto out;
58554
58555 +#ifdef CONFIG_GRKERNSEC
58556 + old_acl = current->acl;
58557 + memcpy(old_rlim, current->signal->rlim, sizeof(old_rlim));
58558 + old_exec_file = current->exec_file;
58559 + get_file(file);
58560 + current->exec_file = file;
58561 +#endif
58562 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
58563 + /* limit suid stack to 8MB
58564 + * we saved the old limits above and will restore them if this exec fails
58565 + */
58566 + if (((!uid_eq(bprm->cred->euid, current_euid())) || (!gid_eq(bprm->cred->egid, current_egid()))) &&
58567 + (old_rlim[RLIMIT_STACK].rlim_cur > (8 * 1024 * 1024)))
58568 + current->signal->rlim[RLIMIT_STACK].rlim_cur = 8 * 1024 * 1024;
58569 +#endif
58570 +
58571 + if (gr_process_kernel_exec_ban() || gr_process_suid_exec_ban(bprm)) {
58572 + retval = -EPERM;
58573 + goto out_fail;
58574 + }
58575 +
58576 + if (!gr_tpe_allow(file)) {
58577 + retval = -EACCES;
58578 + goto out_fail;
58579 + }
58580 +
58581 + if (gr_check_crash_exec(file)) {
58582 + retval = -EACCES;
58583 + goto out_fail;
58584 + }
58585 +
58586 + retval = gr_set_proc_label(file->f_path.dentry, file->f_path.mnt,
58587 + bprm->unsafe);
58588 + if (retval < 0)
58589 + goto out_fail;
58590 +
58591 retval = copy_strings_kernel(1, &bprm->filename, bprm);
58592 if (retval < 0)
58593 - goto out;
58594 + goto out_fail;
58595
58596 bprm->exec = bprm->p;
58597 retval = copy_strings(bprm->envc, envp, bprm);
58598 if (retval < 0)
58599 - goto out;
58600 + goto out_fail;
58601
58602 retval = copy_strings(bprm->argc, argv, bprm);
58603 if (retval < 0)
58604 - goto out;
58605 + goto out_fail;
58606 +
58607 + gr_log_chroot_exec(file->f_path.dentry, file->f_path.mnt);
58608 +
58609 + gr_handle_exec_args(bprm, argv);
58610
58611 retval = exec_binprm(bprm);
58612 if (retval < 0)
58613 - goto out;
58614 + goto out_fail;
58615 +#ifdef CONFIG_GRKERNSEC
58616 + if (old_exec_file)
58617 + fput(old_exec_file);
58618 +#endif
58619
58620 /* execve succeeded */
58621 +
58622 + increment_exec_counter();
58623 current->fs->in_exec = 0;
58624 current->in_execve = 0;
58625 acct_update_integrals(current);
58626 @@ -1545,6 +1711,14 @@ static int do_execve_common(const char *filename,
58627 put_files_struct(displaced);
58628 return retval;
58629
58630 +out_fail:
58631 +#ifdef CONFIG_GRKERNSEC
58632 + current->acl = old_acl;
58633 + memcpy(current->signal->rlim, old_rlim, sizeof(old_rlim));
58634 + fput(current->exec_file);
58635 + current->exec_file = old_exec_file;
58636 +#endif
58637 +
58638 out:
58639 if (bprm->mm) {
58640 acct_arg_size(bprm, 0);
58641 @@ -1699,3 +1873,295 @@ asmlinkage long compat_sys_execve(const char __user * filename,
58642 return error;
58643 }
58644 #endif
58645 +
58646 +int pax_check_flags(unsigned long *flags)
58647 +{
58648 + int retval = 0;
58649 +
58650 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_SEGMEXEC)
58651 + if (*flags & MF_PAX_SEGMEXEC)
58652 + {
58653 + *flags &= ~MF_PAX_SEGMEXEC;
58654 + retval = -EINVAL;
58655 + }
58656 +#endif
58657 +
58658 + if ((*flags & MF_PAX_PAGEEXEC)
58659 +
58660 +#ifdef CONFIG_PAX_PAGEEXEC
58661 + && (*flags & MF_PAX_SEGMEXEC)
58662 +#endif
58663 +
58664 + )
58665 + {
58666 + *flags &= ~MF_PAX_PAGEEXEC;
58667 + retval = -EINVAL;
58668 + }
58669 +
58670 + if ((*flags & MF_PAX_MPROTECT)
58671 +
58672 +#ifdef CONFIG_PAX_MPROTECT
58673 + && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
58674 +#endif
58675 +
58676 + )
58677 + {
58678 + *flags &= ~MF_PAX_MPROTECT;
58679 + retval = -EINVAL;
58680 + }
58681 +
58682 + if ((*flags & MF_PAX_EMUTRAMP)
58683 +
58684 +#ifdef CONFIG_PAX_EMUTRAMP
58685 + && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
58686 +#endif
58687 +
58688 + )
58689 + {
58690 + *flags &= ~MF_PAX_EMUTRAMP;
58691 + retval = -EINVAL;
58692 + }
58693 +
58694 + return retval;
58695 +}
58696 +
58697 +EXPORT_SYMBOL(pax_check_flags);
58698 +
58699 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
58700 +char *pax_get_path(const struct path *path, char *buf, int buflen)
58701 +{
58702 + char *pathname = d_path(path, buf, buflen);
58703 +
58704 + if (IS_ERR(pathname))
58705 + goto toolong;
58706 +
58707 + pathname = mangle_path(buf, pathname, "\t\n\\");
58708 + if (!pathname)
58709 + goto toolong;
58710 +
58711 + *pathname = 0;
58712 + return buf;
58713 +
58714 +toolong:
58715 + return "<path too long>";
58716 +}
58717 +EXPORT_SYMBOL(pax_get_path);
58718 +
58719 +void pax_report_fault(struct pt_regs *regs, void *pc, void *sp)
58720 +{
58721 + struct task_struct *tsk = current;
58722 + struct mm_struct *mm = current->mm;
58723 + char *buffer_exec = (char *)__get_free_page(GFP_KERNEL);
58724 + char *buffer_fault = (char *)__get_free_page(GFP_KERNEL);
58725 + char *path_exec = NULL;
58726 + char *path_fault = NULL;
58727 + unsigned long start = 0UL, end = 0UL, offset = 0UL;
58728 + siginfo_t info = { };
58729 +
58730 + if (buffer_exec && buffer_fault) {
58731 + struct vm_area_struct *vma, *vma_exec = NULL, *vma_fault = NULL;
58732 +
58733 + down_read(&mm->mmap_sem);
58734 + vma = mm->mmap;
58735 + while (vma && (!vma_exec || !vma_fault)) {
58736 + if (vma->vm_file && mm->exe_file == vma->vm_file && (vma->vm_flags & VM_EXEC))
58737 + vma_exec = vma;
58738 + if (vma->vm_start <= (unsigned long)pc && (unsigned long)pc < vma->vm_end)
58739 + vma_fault = vma;
58740 + vma = vma->vm_next;
58741 + }
58742 + if (vma_exec)
58743 + path_exec = pax_get_path(&vma_exec->vm_file->f_path, buffer_exec, PAGE_SIZE);
58744 + if (vma_fault) {
58745 + start = vma_fault->vm_start;
58746 + end = vma_fault->vm_end;
58747 + offset = vma_fault->vm_pgoff << PAGE_SHIFT;
58748 + if (vma_fault->vm_file)
58749 + path_fault = pax_get_path(&vma_fault->vm_file->f_path, buffer_fault, PAGE_SIZE);
58750 + else if ((unsigned long)pc >= mm->start_brk && (unsigned long)pc < mm->brk)
58751 + path_fault = "<heap>";
58752 + else if (vma_fault->vm_flags & (VM_GROWSDOWN | VM_GROWSUP))
58753 + path_fault = "<stack>";
58754 + else
58755 + path_fault = "<anonymous mapping>";
58756 + }
58757 + up_read(&mm->mmap_sem);
58758 + }
58759 + if (tsk->signal->curr_ip)
58760 + printk(KERN_ERR "PAX: From %pI4: execution attempt in: %s, %08lx-%08lx %08lx\n", &tsk->signal->curr_ip, path_fault, start, end, offset);
58761 + else
58762 + printk(KERN_ERR "PAX: execution attempt in: %s, %08lx-%08lx %08lx\n", path_fault, start, end, offset);
58763 + 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),
58764 + from_kuid_munged(&init_user_ns, task_uid(tsk)), from_kuid_munged(&init_user_ns, task_euid(tsk)), pc, sp);
58765 + free_page((unsigned long)buffer_exec);
58766 + free_page((unsigned long)buffer_fault);
58767 + pax_report_insns(regs, pc, sp);
58768 + info.si_signo = SIGKILL;
58769 + info.si_errno = 0;
58770 + info.si_code = SI_KERNEL;
58771 + info.si_pid = 0;
58772 + info.si_uid = 0;
58773 + do_coredump(&info);
58774 +}
58775 +#endif
58776 +
58777 +#ifdef CONFIG_PAX_REFCOUNT
58778 +void pax_report_refcount_overflow(struct pt_regs *regs)
58779 +{
58780 + if (current->signal->curr_ip)
58781 + printk(KERN_ERR "PAX: From %pI4: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
58782 + &current->signal->curr_ip, current->comm, task_pid_nr(current),
58783 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
58784 + else
58785 + printk(KERN_ERR "PAX: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n", current->comm, task_pid_nr(current),
58786 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
58787 + print_symbol(KERN_ERR "PAX: refcount overflow occured at: %s\n", instruction_pointer(regs));
58788 + preempt_disable();
58789 + show_regs(regs);
58790 + preempt_enable();
58791 + force_sig_info(SIGKILL, SEND_SIG_FORCED, current);
58792 +}
58793 +#endif
58794 +
58795 +#ifdef CONFIG_PAX_USERCOPY
58796 +/* 0: not at all, 1: fully, 2: fully inside frame, -1: partially (implies an error) */
58797 +static noinline int check_stack_object(const void *obj, unsigned long len)
58798 +{
58799 + const void * const stack = task_stack_page(current);
58800 + const void * const stackend = stack + THREAD_SIZE;
58801 +
58802 +#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
58803 + const void *frame = NULL;
58804 + const void *oldframe;
58805 +#endif
58806 +
58807 + if (obj + len < obj)
58808 + return -1;
58809 +
58810 + if (obj + len <= stack || stackend <= obj)
58811 + return 0;
58812 +
58813 + if (obj < stack || stackend < obj + len)
58814 + return -1;
58815 +
58816 +#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
58817 + oldframe = __builtin_frame_address(1);
58818 + if (oldframe)
58819 + frame = __builtin_frame_address(2);
58820 + /*
58821 + low ----------------------------------------------> high
58822 + [saved bp][saved ip][args][local vars][saved bp][saved ip]
58823 + ^----------------^
58824 + allow copies only within here
58825 + */
58826 + while (stack <= frame && frame < stackend) {
58827 + /* if obj + len extends past the last frame, this
58828 + check won't pass and the next frame will be 0,
58829 + causing us to bail out and correctly report
58830 + the copy as invalid
58831 + */
58832 + if (obj + len <= frame)
58833 + return obj >= oldframe + 2 * sizeof(void *) ? 2 : -1;
58834 + oldframe = frame;
58835 + frame = *(const void * const *)frame;
58836 + }
58837 + return -1;
58838 +#else
58839 + return 1;
58840 +#endif
58841 +}
58842 +
58843 +static __noreturn void pax_report_usercopy(const void *ptr, unsigned long len, bool to_user, const char *type)
58844 +{
58845 + if (current->signal->curr_ip)
58846 + printk(KERN_ERR "PAX: From %pI4: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
58847 + &current->signal->curr_ip, to_user ? "leak" : "overwrite", to_user ? "from" : "to", ptr, type ? : "unknown", len);
58848 + else
58849 + printk(KERN_ERR "PAX: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
58850 + to_user ? "leak" : "overwrite", to_user ? "from" : "to", ptr, type ? : "unknown", len);
58851 + dump_stack();
58852 + gr_handle_kernel_exploit();
58853 + do_group_exit(SIGKILL);
58854 +}
58855 +#endif
58856 +
58857 +#ifdef CONFIG_PAX_USERCOPY
58858 +static inline bool check_kernel_text_object(unsigned long low, unsigned long high)
58859 +{
58860 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
58861 + unsigned long textlow = ktla_ktva((unsigned long)_stext);
58862 +#ifdef CONFIG_MODULES
58863 + unsigned long texthigh = (unsigned long)MODULES_EXEC_VADDR;
58864 +#else
58865 + unsigned long texthigh = ktla_ktva((unsigned long)_etext);
58866 +#endif
58867 +
58868 +#else
58869 + unsigned long textlow = (unsigned long)_stext;
58870 + unsigned long texthigh = (unsigned long)_etext;
58871 +
58872 +#ifdef CONFIG_X86_64
58873 + /* check against linear mapping as well */
58874 + if (high > (unsigned long)__va(__pa(textlow)) &&
58875 + low < (unsigned long)__va(__pa(texthigh)))
58876 + return true;
58877 +#endif
58878 +
58879 +#endif
58880 +
58881 + if (high <= textlow || low >= texthigh)
58882 + return false;
58883 + else
58884 + return true;
58885 +}
58886 +#endif
58887 +
58888 +void __check_object_size(const void *ptr, unsigned long n, bool to_user)
58889 +{
58890 +
58891 +#ifdef CONFIG_PAX_USERCOPY
58892 + const char *type;
58893 +
58894 + if (!n)
58895 + return;
58896 +
58897 + type = check_heap_object(ptr, n);
58898 + if (!type) {
58899 + int ret = check_stack_object(ptr, n);
58900 + if (ret == 1 || ret == 2)
58901 + return;
58902 + if (ret == 0) {
58903 + if (check_kernel_text_object((unsigned long)ptr, (unsigned long)ptr + n))
58904 + type = "<kernel text>";
58905 + else
58906 + return;
58907 + } else
58908 + type = "<process stack>";
58909 + }
58910 +
58911 + pax_report_usercopy(ptr, n, to_user, type);
58912 +#endif
58913 +
58914 +}
58915 +EXPORT_SYMBOL(__check_object_size);
58916 +
58917 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
58918 +void pax_track_stack(void)
58919 +{
58920 + unsigned long sp = (unsigned long)&sp;
58921 + if (sp < current_thread_info()->lowest_stack &&
58922 + sp > (unsigned long)task_stack_page(current))
58923 + current_thread_info()->lowest_stack = sp;
58924 +}
58925 +EXPORT_SYMBOL(pax_track_stack);
58926 +#endif
58927 +
58928 +#ifdef CONFIG_PAX_SIZE_OVERFLOW
58929 +void report_size_overflow(const char *file, unsigned int line, const char *func, const char *ssa_name)
58930 +{
58931 + printk(KERN_ERR "PAX: size overflow detected in function %s %s:%u %s", func, file, line, ssa_name);
58932 + dump_stack();
58933 + do_group_exit(SIGKILL);
58934 +}
58935 +EXPORT_SYMBOL(report_size_overflow);
58936 +#endif
58937 diff --git a/fs/ext2/balloc.c b/fs/ext2/balloc.c
58938 index 9f9992b..8b59411 100644
58939 --- a/fs/ext2/balloc.c
58940 +++ b/fs/ext2/balloc.c
58941 @@ -1184,10 +1184,10 @@ static int ext2_has_free_blocks(struct ext2_sb_info *sbi)
58942
58943 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
58944 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
58945 - if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
58946 + if (free_blocks < root_blocks + 1 &&
58947 !uid_eq(sbi->s_resuid, current_fsuid()) &&
58948 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
58949 - !in_group_p (sbi->s_resgid))) {
58950 + !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
58951 return 0;
58952 }
58953 return 1;
58954 diff --git a/fs/ext2/xattr.c b/fs/ext2/xattr.c
58955 index 2d7557d..14e38f94 100644
58956 --- a/fs/ext2/xattr.c
58957 +++ b/fs/ext2/xattr.c
58958 @@ -247,7 +247,7 @@ ext2_xattr_list(struct dentry *dentry, char *buffer, size_t buffer_size)
58959 struct buffer_head *bh = NULL;
58960 struct ext2_xattr_entry *entry;
58961 char *end;
58962 - size_t rest = buffer_size;
58963 + size_t rest = buffer_size, total_size = 0;
58964 int error;
58965
58966 ea_idebug(inode, "buffer=%p, buffer_size=%ld",
58967 @@ -305,9 +305,10 @@ bad_block: ext2_error(inode->i_sb, "ext2_xattr_list",
58968 buffer += size;
58969 }
58970 rest -= size;
58971 + total_size += size;
58972 }
58973 }
58974 - error = buffer_size - rest; /* total size */
58975 + error = total_size;
58976
58977 cleanup:
58978 brelse(bh);
58979 diff --git a/fs/ext3/balloc.c b/fs/ext3/balloc.c
58980 index 22548f5..41521d8 100644
58981 --- a/fs/ext3/balloc.c
58982 +++ b/fs/ext3/balloc.c
58983 @@ -1438,10 +1438,10 @@ static int ext3_has_free_blocks(struct ext3_sb_info *sbi, int use_reservation)
58984
58985 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
58986 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
58987 - if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
58988 + if (free_blocks < root_blocks + 1 &&
58989 !use_reservation && !uid_eq(sbi->s_resuid, current_fsuid()) &&
58990 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
58991 - !in_group_p (sbi->s_resgid))) {
58992 + !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
58993 return 0;
58994 }
58995 return 1;
58996 diff --git a/fs/ext3/xattr.c b/fs/ext3/xattr.c
58997 index b1fc963..881228c 100644
58998 --- a/fs/ext3/xattr.c
58999 +++ b/fs/ext3/xattr.c
59000 @@ -330,7 +330,7 @@ static int
59001 ext3_xattr_list_entries(struct dentry *dentry, struct ext3_xattr_entry *entry,
59002 char *buffer, size_t buffer_size)
59003 {
59004 - size_t rest = buffer_size;
59005 + size_t rest = buffer_size, total_size = 0;
59006
59007 for (; !IS_LAST_ENTRY(entry); entry = EXT3_XATTR_NEXT(entry)) {
59008 const struct xattr_handler *handler =
59009 @@ -347,9 +347,10 @@ ext3_xattr_list_entries(struct dentry *dentry, struct ext3_xattr_entry *entry,
59010 buffer += size;
59011 }
59012 rest -= size;
59013 + total_size += size;
59014 }
59015 }
59016 - return buffer_size - rest;
59017 + return total_size;
59018 }
59019
59020 static int
59021 diff --git a/fs/ext4/balloc.c b/fs/ext4/balloc.c
59022 index 6ea7b14..8fa16d9 100644
59023 --- a/fs/ext4/balloc.c
59024 +++ b/fs/ext4/balloc.c
59025 @@ -534,8 +534,8 @@ static int ext4_has_free_clusters(struct ext4_sb_info *sbi,
59026 /* Hm, nope. Are (enough) root reserved clusters available? */
59027 if (uid_eq(sbi->s_resuid, current_fsuid()) ||
59028 (!gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) && in_group_p(sbi->s_resgid)) ||
59029 - capable(CAP_SYS_RESOURCE) ||
59030 - (flags & EXT4_MB_USE_ROOT_BLOCKS)) {
59031 + (flags & EXT4_MB_USE_ROOT_BLOCKS) ||
59032 + capable_nolog(CAP_SYS_RESOURCE)) {
59033
59034 if (free_clusters >= (nclusters + dirty_clusters +
59035 resv_clusters))
59036 diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
59037 index d3a534f..242c50a 100644
59038 --- a/fs/ext4/ext4.h
59039 +++ b/fs/ext4/ext4.h
59040 @@ -1269,19 +1269,19 @@ struct ext4_sb_info {
59041 unsigned long s_mb_last_start;
59042
59043 /* stats for buddy allocator */
59044 - atomic_t s_bal_reqs; /* number of reqs with len > 1 */
59045 - atomic_t s_bal_success; /* we found long enough chunks */
59046 - atomic_t s_bal_allocated; /* in blocks */
59047 - atomic_t s_bal_ex_scanned; /* total extents scanned */
59048 - atomic_t s_bal_goals; /* goal hits */
59049 - atomic_t s_bal_breaks; /* too long searches */
59050 - atomic_t s_bal_2orders; /* 2^order hits */
59051 + atomic_unchecked_t s_bal_reqs; /* number of reqs with len > 1 */
59052 + atomic_unchecked_t s_bal_success; /* we found long enough chunks */
59053 + atomic_unchecked_t s_bal_allocated; /* in blocks */
59054 + atomic_unchecked_t s_bal_ex_scanned; /* total extents scanned */
59055 + atomic_unchecked_t s_bal_goals; /* goal hits */
59056 + atomic_unchecked_t s_bal_breaks; /* too long searches */
59057 + atomic_unchecked_t s_bal_2orders; /* 2^order hits */
59058 spinlock_t s_bal_lock;
59059 unsigned long s_mb_buddies_generated;
59060 unsigned long long s_mb_generation_time;
59061 - atomic_t s_mb_lost_chunks;
59062 - atomic_t s_mb_preallocated;
59063 - atomic_t s_mb_discarded;
59064 + atomic_unchecked_t s_mb_lost_chunks;
59065 + atomic_unchecked_t s_mb_preallocated;
59066 + atomic_unchecked_t s_mb_discarded;
59067 atomic_t s_lock_busy;
59068
59069 /* locality groups */
59070 diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
59071 index 04a5c75..09894fa 100644
59072 --- a/fs/ext4/mballoc.c
59073 +++ b/fs/ext4/mballoc.c
59074 @@ -1880,7 +1880,7 @@ void ext4_mb_simple_scan_group(struct ext4_allocation_context *ac,
59075 BUG_ON(ac->ac_b_ex.fe_len != ac->ac_g_ex.fe_len);
59076
59077 if (EXT4_SB(sb)->s_mb_stats)
59078 - atomic_inc(&EXT4_SB(sb)->s_bal_2orders);
59079 + atomic_inc_unchecked(&EXT4_SB(sb)->s_bal_2orders);
59080
59081 break;
59082 }
59083 @@ -2189,7 +2189,7 @@ repeat:
59084 ac->ac_status = AC_STATUS_CONTINUE;
59085 ac->ac_flags |= EXT4_MB_HINT_FIRST;
59086 cr = 3;
59087 - atomic_inc(&sbi->s_mb_lost_chunks);
59088 + atomic_inc_unchecked(&sbi->s_mb_lost_chunks);
59089 goto repeat;
59090 }
59091 }
59092 @@ -2697,25 +2697,25 @@ int ext4_mb_release(struct super_block *sb)
59093 if (sbi->s_mb_stats) {
59094 ext4_msg(sb, KERN_INFO,
59095 "mballoc: %u blocks %u reqs (%u success)",
59096 - atomic_read(&sbi->s_bal_allocated),
59097 - atomic_read(&sbi->s_bal_reqs),
59098 - atomic_read(&sbi->s_bal_success));
59099 + atomic_read_unchecked(&sbi->s_bal_allocated),
59100 + atomic_read_unchecked(&sbi->s_bal_reqs),
59101 + atomic_read_unchecked(&sbi->s_bal_success));
59102 ext4_msg(sb, KERN_INFO,
59103 "mballoc: %u extents scanned, %u goal hits, "
59104 "%u 2^N hits, %u breaks, %u lost",
59105 - atomic_read(&sbi->s_bal_ex_scanned),
59106 - atomic_read(&sbi->s_bal_goals),
59107 - atomic_read(&sbi->s_bal_2orders),
59108 - atomic_read(&sbi->s_bal_breaks),
59109 - atomic_read(&sbi->s_mb_lost_chunks));
59110 + atomic_read_unchecked(&sbi->s_bal_ex_scanned),
59111 + atomic_read_unchecked(&sbi->s_bal_goals),
59112 + atomic_read_unchecked(&sbi->s_bal_2orders),
59113 + atomic_read_unchecked(&sbi->s_bal_breaks),
59114 + atomic_read_unchecked(&sbi->s_mb_lost_chunks));
59115 ext4_msg(sb, KERN_INFO,
59116 "mballoc: %lu generated and it took %Lu",
59117 sbi->s_mb_buddies_generated,
59118 sbi->s_mb_generation_time);
59119 ext4_msg(sb, KERN_INFO,
59120 "mballoc: %u preallocated, %u discarded",
59121 - atomic_read(&sbi->s_mb_preallocated),
59122 - atomic_read(&sbi->s_mb_discarded));
59123 + atomic_read_unchecked(&sbi->s_mb_preallocated),
59124 + atomic_read_unchecked(&sbi->s_mb_discarded));
59125 }
59126
59127 free_percpu(sbi->s_locality_groups);
59128 @@ -3169,16 +3169,16 @@ static void ext4_mb_collect_stats(struct ext4_allocation_context *ac)
59129 struct ext4_sb_info *sbi = EXT4_SB(ac->ac_sb);
59130
59131 if (sbi->s_mb_stats && ac->ac_g_ex.fe_len > 1) {
59132 - atomic_inc(&sbi->s_bal_reqs);
59133 - atomic_add(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
59134 + atomic_inc_unchecked(&sbi->s_bal_reqs);
59135 + atomic_add_unchecked(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
59136 if (ac->ac_b_ex.fe_len >= ac->ac_o_ex.fe_len)
59137 - atomic_inc(&sbi->s_bal_success);
59138 - atomic_add(ac->ac_found, &sbi->s_bal_ex_scanned);
59139 + atomic_inc_unchecked(&sbi->s_bal_success);
59140 + atomic_add_unchecked(ac->ac_found, &sbi->s_bal_ex_scanned);
59141 if (ac->ac_g_ex.fe_start == ac->ac_b_ex.fe_start &&
59142 ac->ac_g_ex.fe_group == ac->ac_b_ex.fe_group)
59143 - atomic_inc(&sbi->s_bal_goals);
59144 + atomic_inc_unchecked(&sbi->s_bal_goals);
59145 if (ac->ac_found > sbi->s_mb_max_to_scan)
59146 - atomic_inc(&sbi->s_bal_breaks);
59147 + atomic_inc_unchecked(&sbi->s_bal_breaks);
59148 }
59149
59150 if (ac->ac_op == EXT4_MB_HISTORY_ALLOC)
59151 @@ -3583,7 +3583,7 @@ ext4_mb_new_inode_pa(struct ext4_allocation_context *ac)
59152 trace_ext4_mb_new_inode_pa(ac, pa);
59153
59154 ext4_mb_use_inode_pa(ac, pa);
59155 - atomic_add(pa->pa_free, &sbi->s_mb_preallocated);
59156 + atomic_add_unchecked(pa->pa_free, &sbi->s_mb_preallocated);
59157
59158 ei = EXT4_I(ac->ac_inode);
59159 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
59160 @@ -3643,7 +3643,7 @@ ext4_mb_new_group_pa(struct ext4_allocation_context *ac)
59161 trace_ext4_mb_new_group_pa(ac, pa);
59162
59163 ext4_mb_use_group_pa(ac, pa);
59164 - atomic_add(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
59165 + atomic_add_unchecked(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
59166
59167 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
59168 lg = ac->ac_lg;
59169 @@ -3732,7 +3732,7 @@ ext4_mb_release_inode_pa(struct ext4_buddy *e4b, struct buffer_head *bitmap_bh,
59170 * from the bitmap and continue.
59171 */
59172 }
59173 - atomic_add(free, &sbi->s_mb_discarded);
59174 + atomic_add_unchecked(free, &sbi->s_mb_discarded);
59175
59176 return err;
59177 }
59178 @@ -3750,7 +3750,7 @@ ext4_mb_release_group_pa(struct ext4_buddy *e4b,
59179 ext4_get_group_no_and_offset(sb, pa->pa_pstart, &group, &bit);
59180 BUG_ON(group != e4b->bd_group && pa->pa_len != 0);
59181 mb_free_blocks(pa->pa_inode, e4b, bit, pa->pa_len);
59182 - atomic_add(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
59183 + atomic_add_unchecked(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
59184 trace_ext4_mballoc_discard(sb, NULL, group, bit, pa->pa_len);
59185
59186 return 0;
59187 diff --git a/fs/ext4/mmp.c b/fs/ext4/mmp.c
59188 index 04434ad..6404663 100644
59189 --- a/fs/ext4/mmp.c
59190 +++ b/fs/ext4/mmp.c
59191 @@ -113,7 +113,7 @@ static int read_mmp_block(struct super_block *sb, struct buffer_head **bh,
59192 void __dump_mmp_msg(struct super_block *sb, struct mmp_struct *mmp,
59193 const char *function, unsigned int line, const char *msg)
59194 {
59195 - __ext4_warning(sb, function, line, msg);
59196 + __ext4_warning(sb, function, line, "%s", msg);
59197 __ext4_warning(sb, function, line,
59198 "MMP failure info: last update time: %llu, last update "
59199 "node: %s, last update device: %s\n",
59200 diff --git a/fs/ext4/super.c b/fs/ext4/super.c
59201 index 710fed2..a82e4e8 100644
59202 --- a/fs/ext4/super.c
59203 +++ b/fs/ext4/super.c
59204 @@ -1270,7 +1270,7 @@ static ext4_fsblk_t get_sb_block(void **data)
59205 }
59206
59207 #define DEFAULT_JOURNAL_IOPRIO (IOPRIO_PRIO_VALUE(IOPRIO_CLASS_BE, 3))
59208 -static char deprecated_msg[] = "Mount option \"%s\" will be removed by %s\n"
59209 +static const char deprecated_msg[] = "Mount option \"%s\" will be removed by %s\n"
59210 "Contact linux-ext4@vger.kernel.org if you think we should keep it.\n";
59211
59212 #ifdef CONFIG_QUOTA
59213 @@ -2450,7 +2450,7 @@ struct ext4_attr {
59214 int offset;
59215 int deprecated_val;
59216 } u;
59217 -};
59218 +} __do_const;
59219
59220 static int parse_strtoull(const char *buf,
59221 unsigned long long max, unsigned long long *value)
59222 diff --git a/fs/ext4/xattr.c b/fs/ext4/xattr.c
59223 index 1423c48..9c0c6dc 100644
59224 --- a/fs/ext4/xattr.c
59225 +++ b/fs/ext4/xattr.c
59226 @@ -381,7 +381,7 @@ static int
59227 ext4_xattr_list_entries(struct dentry *dentry, struct ext4_xattr_entry *entry,
59228 char *buffer, size_t buffer_size)
59229 {
59230 - size_t rest = buffer_size;
59231 + size_t rest = buffer_size, total_size = 0;
59232
59233 for (; !IS_LAST_ENTRY(entry); entry = EXT4_XATTR_NEXT(entry)) {
59234 const struct xattr_handler *handler =
59235 @@ -398,9 +398,10 @@ ext4_xattr_list_entries(struct dentry *dentry, struct ext4_xattr_entry *entry,
59236 buffer += size;
59237 }
59238 rest -= size;
59239 + total_size += size;
59240 }
59241 }
59242 - return buffer_size - rest;
59243 + return total_size;
59244 }
59245
59246 static int
59247 diff --git a/fs/fcntl.c b/fs/fcntl.c
59248 index ef68665..5deacdc 100644
59249 --- a/fs/fcntl.c
59250 +++ b/fs/fcntl.c
59251 @@ -106,6 +106,11 @@ int __f_setown(struct file *filp, struct pid *pid, enum pid_type type,
59252 if (err)
59253 return err;
59254
59255 + if (gr_handle_chroot_fowner(pid, type))
59256 + return -ENOENT;
59257 + if (gr_check_protected_task_fowner(pid, type))
59258 + return -EACCES;
59259 +
59260 f_modown(filp, pid, type, force);
59261 return 0;
59262 }
59263 diff --git a/fs/fhandle.c b/fs/fhandle.c
59264 index 999ff5c..41f4109 100644
59265 --- a/fs/fhandle.c
59266 +++ b/fs/fhandle.c
59267 @@ -67,8 +67,7 @@ static long do_sys_name_to_handle(struct path *path,
59268 } else
59269 retval = 0;
59270 /* copy the mount id */
59271 - if (copy_to_user(mnt_id, &real_mount(path->mnt)->mnt_id,
59272 - sizeof(*mnt_id)) ||
59273 + if (put_user(real_mount(path->mnt)->mnt_id, mnt_id) ||
59274 copy_to_user(ufh, handle,
59275 sizeof(struct file_handle) + handle_bytes))
59276 retval = -EFAULT;
59277 diff --git a/fs/file.c b/fs/file.c
59278 index 9de2026..8e334ca 100644
59279 --- a/fs/file.c
59280 +++ b/fs/file.c
59281 @@ -16,6 +16,7 @@
59282 #include <linux/slab.h>
59283 #include <linux/vmalloc.h>
59284 #include <linux/file.h>
59285 +#include <linux/security.h>
59286 #include <linux/fdtable.h>
59287 #include <linux/bitops.h>
59288 #include <linux/interrupt.h>
59289 @@ -141,7 +142,7 @@ out:
59290 * Return <0 error code on error; 1 on successful completion.
59291 * The files->file_lock should be held on entry, and will be held on exit.
59292 */
59293 -static int expand_fdtable(struct files_struct *files, int nr)
59294 +static int expand_fdtable(struct files_struct *files, unsigned int nr)
59295 __releases(files->file_lock)
59296 __acquires(files->file_lock)
59297 {
59298 @@ -186,7 +187,7 @@ static int expand_fdtable(struct files_struct *files, int nr)
59299 * expanded and execution may have blocked.
59300 * The files->file_lock should be held on entry, and will be held on exit.
59301 */
59302 -static int expand_files(struct files_struct *files, int nr)
59303 +static int expand_files(struct files_struct *files, unsigned int nr)
59304 {
59305 struct fdtable *fdt;
59306
59307 @@ -828,6 +829,7 @@ int replace_fd(unsigned fd, struct file *file, unsigned flags)
59308 if (!file)
59309 return __close_fd(files, fd);
59310
59311 + gr_learn_resource(current, RLIMIT_NOFILE, fd, 0);
59312 if (fd >= rlimit(RLIMIT_NOFILE))
59313 return -EBADF;
59314
59315 @@ -854,6 +856,7 @@ SYSCALL_DEFINE3(dup3, unsigned int, oldfd, unsigned int, newfd, int, flags)
59316 if (unlikely(oldfd == newfd))
59317 return -EINVAL;
59318
59319 + gr_learn_resource(current, RLIMIT_NOFILE, newfd, 0);
59320 if (newfd >= rlimit(RLIMIT_NOFILE))
59321 return -EBADF;
59322
59323 @@ -909,6 +912,7 @@ SYSCALL_DEFINE1(dup, unsigned int, fildes)
59324 int f_dupfd(unsigned int from, struct file *file, unsigned flags)
59325 {
59326 int err;
59327 + gr_learn_resource(current, RLIMIT_NOFILE, from, 0);
59328 if (from >= rlimit(RLIMIT_NOFILE))
59329 return -EINVAL;
59330 err = alloc_fd(from, flags);
59331 diff --git a/fs/filesystems.c b/fs/filesystems.c
59332 index 92567d9..fcd8cbf 100644
59333 --- a/fs/filesystems.c
59334 +++ b/fs/filesystems.c
59335 @@ -273,7 +273,11 @@ struct file_system_type *get_fs_type(const char *name)
59336 int len = dot ? dot - name : strlen(name);
59337
59338 fs = __get_fs_type(name, len);
59339 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
59340 + if (!fs && (___request_module(true, "grsec_modharden_fs", "fs-%.*s", len, name) == 0))
59341 +#else
59342 if (!fs && (request_module("fs-%.*s", len, name) == 0))
59343 +#endif
59344 fs = __get_fs_type(name, len);
59345
59346 if (dot && fs && !(fs->fs_flags & FS_HAS_SUBTYPE)) {
59347 diff --git a/fs/fs_struct.c b/fs/fs_struct.c
59348 index 7dca743..543d620 100644
59349 --- a/fs/fs_struct.c
59350 +++ b/fs/fs_struct.c
59351 @@ -4,6 +4,7 @@
59352 #include <linux/path.h>
59353 #include <linux/slab.h>
59354 #include <linux/fs_struct.h>
59355 +#include <linux/grsecurity.h>
59356 #include "internal.h"
59357
59358 /*
59359 @@ -19,6 +20,7 @@ void set_fs_root(struct fs_struct *fs, const struct path *path)
59360 write_seqcount_begin(&fs->seq);
59361 old_root = fs->root;
59362 fs->root = *path;
59363 + gr_set_chroot_entries(current, path);
59364 write_seqcount_end(&fs->seq);
59365 spin_unlock(&fs->lock);
59366 if (old_root.dentry)
59367 @@ -67,6 +69,10 @@ void chroot_fs_refs(const struct path *old_root, const struct path *new_root)
59368 int hits = 0;
59369 spin_lock(&fs->lock);
59370 write_seqcount_begin(&fs->seq);
59371 + /* this root replacement is only done by pivot_root,
59372 + leave grsec's chroot tagging alone for this task
59373 + so that a pivoted root isn't treated as a chroot
59374 + */
59375 hits += replace_path(&fs->root, old_root, new_root);
59376 hits += replace_path(&fs->pwd, old_root, new_root);
59377 write_seqcount_end(&fs->seq);
59378 @@ -99,7 +105,8 @@ void exit_fs(struct task_struct *tsk)
59379 task_lock(tsk);
59380 spin_lock(&fs->lock);
59381 tsk->fs = NULL;
59382 - kill = !--fs->users;
59383 + gr_clear_chroot_entries(tsk);
59384 + kill = !atomic_dec_return(&fs->users);
59385 spin_unlock(&fs->lock);
59386 task_unlock(tsk);
59387 if (kill)
59388 @@ -112,7 +119,7 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
59389 struct fs_struct *fs = kmem_cache_alloc(fs_cachep, GFP_KERNEL);
59390 /* We don't need to lock fs - think why ;-) */
59391 if (fs) {
59392 - fs->users = 1;
59393 + atomic_set(&fs->users, 1);
59394 fs->in_exec = 0;
59395 spin_lock_init(&fs->lock);
59396 seqcount_init(&fs->seq);
59397 @@ -121,6 +128,9 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
59398 spin_lock(&old->lock);
59399 fs->root = old->root;
59400 path_get(&fs->root);
59401 + /* instead of calling gr_set_chroot_entries here,
59402 + we call it from every caller of this function
59403 + */
59404 fs->pwd = old->pwd;
59405 path_get(&fs->pwd);
59406 spin_unlock(&old->lock);
59407 @@ -139,8 +149,9 @@ int unshare_fs_struct(void)
59408
59409 task_lock(current);
59410 spin_lock(&fs->lock);
59411 - kill = !--fs->users;
59412 + kill = !atomic_dec_return(&fs->users);
59413 current->fs = new_fs;
59414 + gr_set_chroot_entries(current, &new_fs->root);
59415 spin_unlock(&fs->lock);
59416 task_unlock(current);
59417
59418 @@ -153,13 +164,13 @@ EXPORT_SYMBOL_GPL(unshare_fs_struct);
59419
59420 int current_umask(void)
59421 {
59422 - return current->fs->umask;
59423 + return current->fs->umask | gr_acl_umask();
59424 }
59425 EXPORT_SYMBOL(current_umask);
59426
59427 /* to be mentioned only in INIT_TASK */
59428 struct fs_struct init_fs = {
59429 - .users = 1,
59430 + .users = ATOMIC_INIT(1),
59431 .lock = __SPIN_LOCK_UNLOCKED(init_fs.lock),
59432 .seq = SEQCNT_ZERO(init_fs.seq),
59433 .umask = 0022,
59434 diff --git a/fs/fscache/cookie.c b/fs/fscache/cookie.c
59435 index 29d7feb..303644d 100644
59436 --- a/fs/fscache/cookie.c
59437 +++ b/fs/fscache/cookie.c
59438 @@ -19,7 +19,7 @@
59439
59440 struct kmem_cache *fscache_cookie_jar;
59441
59442 -static atomic_t fscache_object_debug_id = ATOMIC_INIT(0);
59443 +static atomic_unchecked_t fscache_object_debug_id = ATOMIC_INIT(0);
59444
59445 static int fscache_acquire_non_index_cookie(struct fscache_cookie *cookie);
59446 static int fscache_alloc_object(struct fscache_cache *cache,
59447 @@ -69,11 +69,11 @@ struct fscache_cookie *__fscache_acquire_cookie(
59448 parent ? (char *) parent->def->name : "<no-parent>",
59449 def->name, netfs_data, enable);
59450
59451 - fscache_stat(&fscache_n_acquires);
59452 + fscache_stat_unchecked(&fscache_n_acquires);
59453
59454 /* if there's no parent cookie, then we don't create one here either */
59455 if (!parent) {
59456 - fscache_stat(&fscache_n_acquires_null);
59457 + fscache_stat_unchecked(&fscache_n_acquires_null);
59458 _leave(" [no parent]");
59459 return NULL;
59460 }
59461 @@ -88,7 +88,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
59462 /* allocate and initialise a cookie */
59463 cookie = kmem_cache_alloc(fscache_cookie_jar, GFP_KERNEL);
59464 if (!cookie) {
59465 - fscache_stat(&fscache_n_acquires_oom);
59466 + fscache_stat_unchecked(&fscache_n_acquires_oom);
59467 _leave(" [ENOMEM]");
59468 return NULL;
59469 }
59470 @@ -115,13 +115,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
59471
59472 switch (cookie->def->type) {
59473 case FSCACHE_COOKIE_TYPE_INDEX:
59474 - fscache_stat(&fscache_n_cookie_index);
59475 + fscache_stat_unchecked(&fscache_n_cookie_index);
59476 break;
59477 case FSCACHE_COOKIE_TYPE_DATAFILE:
59478 - fscache_stat(&fscache_n_cookie_data);
59479 + fscache_stat_unchecked(&fscache_n_cookie_data);
59480 break;
59481 default:
59482 - fscache_stat(&fscache_n_cookie_special);
59483 + fscache_stat_unchecked(&fscache_n_cookie_special);
59484 break;
59485 }
59486
59487 @@ -135,7 +135,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
59488 } else {
59489 atomic_dec(&parent->n_children);
59490 __fscache_cookie_put(cookie);
59491 - fscache_stat(&fscache_n_acquires_nobufs);
59492 + fscache_stat_unchecked(&fscache_n_acquires_nobufs);
59493 _leave(" = NULL");
59494 return NULL;
59495 }
59496 @@ -144,7 +144,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
59497 }
59498 }
59499
59500 - fscache_stat(&fscache_n_acquires_ok);
59501 + fscache_stat_unchecked(&fscache_n_acquires_ok);
59502 _leave(" = %p", cookie);
59503 return cookie;
59504 }
59505 @@ -213,7 +213,7 @@ static int fscache_acquire_non_index_cookie(struct fscache_cookie *cookie)
59506 cache = fscache_select_cache_for_object(cookie->parent);
59507 if (!cache) {
59508 up_read(&fscache_addremove_sem);
59509 - fscache_stat(&fscache_n_acquires_no_cache);
59510 + fscache_stat_unchecked(&fscache_n_acquires_no_cache);
59511 _leave(" = -ENOMEDIUM [no cache]");
59512 return -ENOMEDIUM;
59513 }
59514 @@ -297,14 +297,14 @@ static int fscache_alloc_object(struct fscache_cache *cache,
59515 object = cache->ops->alloc_object(cache, cookie);
59516 fscache_stat_d(&fscache_n_cop_alloc_object);
59517 if (IS_ERR(object)) {
59518 - fscache_stat(&fscache_n_object_no_alloc);
59519 + fscache_stat_unchecked(&fscache_n_object_no_alloc);
59520 ret = PTR_ERR(object);
59521 goto error;
59522 }
59523
59524 - fscache_stat(&fscache_n_object_alloc);
59525 + fscache_stat_unchecked(&fscache_n_object_alloc);
59526
59527 - object->debug_id = atomic_inc_return(&fscache_object_debug_id);
59528 + object->debug_id = atomic_inc_return_unchecked(&fscache_object_debug_id);
59529
59530 _debug("ALLOC OBJ%x: %s {%lx}",
59531 object->debug_id, cookie->def->name, object->events);
59532 @@ -418,7 +418,7 @@ void __fscache_invalidate(struct fscache_cookie *cookie)
59533
59534 _enter("{%s}", cookie->def->name);
59535
59536 - fscache_stat(&fscache_n_invalidates);
59537 + fscache_stat_unchecked(&fscache_n_invalidates);
59538
59539 /* Only permit invalidation of data files. Invalidating an index will
59540 * require the caller to release all its attachments to the tree rooted
59541 @@ -477,10 +477,10 @@ void __fscache_update_cookie(struct fscache_cookie *cookie)
59542 {
59543 struct fscache_object *object;
59544
59545 - fscache_stat(&fscache_n_updates);
59546 + fscache_stat_unchecked(&fscache_n_updates);
59547
59548 if (!cookie) {
59549 - fscache_stat(&fscache_n_updates_null);
59550 + fscache_stat_unchecked(&fscache_n_updates_null);
59551 _leave(" [no cookie]");
59552 return;
59553 }
59554 @@ -581,12 +581,12 @@ EXPORT_SYMBOL(__fscache_disable_cookie);
59555 */
59556 void __fscache_relinquish_cookie(struct fscache_cookie *cookie, bool retire)
59557 {
59558 - fscache_stat(&fscache_n_relinquishes);
59559 + fscache_stat_unchecked(&fscache_n_relinquishes);
59560 if (retire)
59561 - fscache_stat(&fscache_n_relinquishes_retire);
59562 + fscache_stat_unchecked(&fscache_n_relinquishes_retire);
59563
59564 if (!cookie) {
59565 - fscache_stat(&fscache_n_relinquishes_null);
59566 + fscache_stat_unchecked(&fscache_n_relinquishes_null);
59567 _leave(" [no cookie]");
59568 return;
59569 }
59570 @@ -687,7 +687,7 @@ int __fscache_check_consistency(struct fscache_cookie *cookie)
59571 if (test_bit(FSCACHE_IOERROR, &object->cache->flags))
59572 goto inconsistent;
59573
59574 - op->debug_id = atomic_inc_return(&fscache_op_debug_id);
59575 + op->debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
59576
59577 __fscache_use_cookie(cookie);
59578 if (fscache_submit_op(object, op) < 0)
59579 diff --git a/fs/fscache/internal.h b/fs/fscache/internal.h
59580 index 4226f66..0fb3f45 100644
59581 --- a/fs/fscache/internal.h
59582 +++ b/fs/fscache/internal.h
59583 @@ -133,8 +133,8 @@ extern void fscache_operation_gc(struct work_struct *);
59584 extern int fscache_wait_for_deferred_lookup(struct fscache_cookie *);
59585 extern int fscache_wait_for_operation_activation(struct fscache_object *,
59586 struct fscache_operation *,
59587 - atomic_t *,
59588 - atomic_t *,
59589 + atomic_unchecked_t *,
59590 + atomic_unchecked_t *,
59591 void (*)(struct fscache_operation *));
59592 extern void fscache_invalidate_writes(struct fscache_cookie *);
59593
59594 @@ -153,101 +153,101 @@ extern void fscache_proc_cleanup(void);
59595 * stats.c
59596 */
59597 #ifdef CONFIG_FSCACHE_STATS
59598 -extern atomic_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
59599 -extern atomic_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
59600 +extern atomic_unchecked_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
59601 +extern atomic_unchecked_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
59602
59603 -extern atomic_t fscache_n_op_pend;
59604 -extern atomic_t fscache_n_op_run;
59605 -extern atomic_t fscache_n_op_enqueue;
59606 -extern atomic_t fscache_n_op_deferred_release;
59607 -extern atomic_t fscache_n_op_release;
59608 -extern atomic_t fscache_n_op_gc;
59609 -extern atomic_t fscache_n_op_cancelled;
59610 -extern atomic_t fscache_n_op_rejected;
59611 +extern atomic_unchecked_t fscache_n_op_pend;
59612 +extern atomic_unchecked_t fscache_n_op_run;
59613 +extern atomic_unchecked_t fscache_n_op_enqueue;
59614 +extern atomic_unchecked_t fscache_n_op_deferred_release;
59615 +extern atomic_unchecked_t fscache_n_op_release;
59616 +extern atomic_unchecked_t fscache_n_op_gc;
59617 +extern atomic_unchecked_t fscache_n_op_cancelled;
59618 +extern atomic_unchecked_t fscache_n_op_rejected;
59619
59620 -extern atomic_t fscache_n_attr_changed;
59621 -extern atomic_t fscache_n_attr_changed_ok;
59622 -extern atomic_t fscache_n_attr_changed_nobufs;
59623 -extern atomic_t fscache_n_attr_changed_nomem;
59624 -extern atomic_t fscache_n_attr_changed_calls;
59625 +extern atomic_unchecked_t fscache_n_attr_changed;
59626 +extern atomic_unchecked_t fscache_n_attr_changed_ok;
59627 +extern atomic_unchecked_t fscache_n_attr_changed_nobufs;
59628 +extern atomic_unchecked_t fscache_n_attr_changed_nomem;
59629 +extern atomic_unchecked_t fscache_n_attr_changed_calls;
59630
59631 -extern atomic_t fscache_n_allocs;
59632 -extern atomic_t fscache_n_allocs_ok;
59633 -extern atomic_t fscache_n_allocs_wait;
59634 -extern atomic_t fscache_n_allocs_nobufs;
59635 -extern atomic_t fscache_n_allocs_intr;
59636 -extern atomic_t fscache_n_allocs_object_dead;
59637 -extern atomic_t fscache_n_alloc_ops;
59638 -extern atomic_t fscache_n_alloc_op_waits;
59639 +extern atomic_unchecked_t fscache_n_allocs;
59640 +extern atomic_unchecked_t fscache_n_allocs_ok;
59641 +extern atomic_unchecked_t fscache_n_allocs_wait;
59642 +extern atomic_unchecked_t fscache_n_allocs_nobufs;
59643 +extern atomic_unchecked_t fscache_n_allocs_intr;
59644 +extern atomic_unchecked_t fscache_n_allocs_object_dead;
59645 +extern atomic_unchecked_t fscache_n_alloc_ops;
59646 +extern atomic_unchecked_t fscache_n_alloc_op_waits;
59647
59648 -extern atomic_t fscache_n_retrievals;
59649 -extern atomic_t fscache_n_retrievals_ok;
59650 -extern atomic_t fscache_n_retrievals_wait;
59651 -extern atomic_t fscache_n_retrievals_nodata;
59652 -extern atomic_t fscache_n_retrievals_nobufs;
59653 -extern atomic_t fscache_n_retrievals_intr;
59654 -extern atomic_t fscache_n_retrievals_nomem;
59655 -extern atomic_t fscache_n_retrievals_object_dead;
59656 -extern atomic_t fscache_n_retrieval_ops;
59657 -extern atomic_t fscache_n_retrieval_op_waits;
59658 +extern atomic_unchecked_t fscache_n_retrievals;
59659 +extern atomic_unchecked_t fscache_n_retrievals_ok;
59660 +extern atomic_unchecked_t fscache_n_retrievals_wait;
59661 +extern atomic_unchecked_t fscache_n_retrievals_nodata;
59662 +extern atomic_unchecked_t fscache_n_retrievals_nobufs;
59663 +extern atomic_unchecked_t fscache_n_retrievals_intr;
59664 +extern atomic_unchecked_t fscache_n_retrievals_nomem;
59665 +extern atomic_unchecked_t fscache_n_retrievals_object_dead;
59666 +extern atomic_unchecked_t fscache_n_retrieval_ops;
59667 +extern atomic_unchecked_t fscache_n_retrieval_op_waits;
59668
59669 -extern atomic_t fscache_n_stores;
59670 -extern atomic_t fscache_n_stores_ok;
59671 -extern atomic_t fscache_n_stores_again;
59672 -extern atomic_t fscache_n_stores_nobufs;
59673 -extern atomic_t fscache_n_stores_oom;
59674 -extern atomic_t fscache_n_store_ops;
59675 -extern atomic_t fscache_n_store_calls;
59676 -extern atomic_t fscache_n_store_pages;
59677 -extern atomic_t fscache_n_store_radix_deletes;
59678 -extern atomic_t fscache_n_store_pages_over_limit;
59679 +extern atomic_unchecked_t fscache_n_stores;
59680 +extern atomic_unchecked_t fscache_n_stores_ok;
59681 +extern atomic_unchecked_t fscache_n_stores_again;
59682 +extern atomic_unchecked_t fscache_n_stores_nobufs;
59683 +extern atomic_unchecked_t fscache_n_stores_oom;
59684 +extern atomic_unchecked_t fscache_n_store_ops;
59685 +extern atomic_unchecked_t fscache_n_store_calls;
59686 +extern atomic_unchecked_t fscache_n_store_pages;
59687 +extern atomic_unchecked_t fscache_n_store_radix_deletes;
59688 +extern atomic_unchecked_t fscache_n_store_pages_over_limit;
59689
59690 -extern atomic_t fscache_n_store_vmscan_not_storing;
59691 -extern atomic_t fscache_n_store_vmscan_gone;
59692 -extern atomic_t fscache_n_store_vmscan_busy;
59693 -extern atomic_t fscache_n_store_vmscan_cancelled;
59694 -extern atomic_t fscache_n_store_vmscan_wait;
59695 +extern atomic_unchecked_t fscache_n_store_vmscan_not_storing;
59696 +extern atomic_unchecked_t fscache_n_store_vmscan_gone;
59697 +extern atomic_unchecked_t fscache_n_store_vmscan_busy;
59698 +extern atomic_unchecked_t fscache_n_store_vmscan_cancelled;
59699 +extern atomic_unchecked_t fscache_n_store_vmscan_wait;
59700
59701 -extern atomic_t fscache_n_marks;
59702 -extern atomic_t fscache_n_uncaches;
59703 +extern atomic_unchecked_t fscache_n_marks;
59704 +extern atomic_unchecked_t fscache_n_uncaches;
59705
59706 -extern atomic_t fscache_n_acquires;
59707 -extern atomic_t fscache_n_acquires_null;
59708 -extern atomic_t fscache_n_acquires_no_cache;
59709 -extern atomic_t fscache_n_acquires_ok;
59710 -extern atomic_t fscache_n_acquires_nobufs;
59711 -extern atomic_t fscache_n_acquires_oom;
59712 +extern atomic_unchecked_t fscache_n_acquires;
59713 +extern atomic_unchecked_t fscache_n_acquires_null;
59714 +extern atomic_unchecked_t fscache_n_acquires_no_cache;
59715 +extern atomic_unchecked_t fscache_n_acquires_ok;
59716 +extern atomic_unchecked_t fscache_n_acquires_nobufs;
59717 +extern atomic_unchecked_t fscache_n_acquires_oom;
59718
59719 -extern atomic_t fscache_n_invalidates;
59720 -extern atomic_t fscache_n_invalidates_run;
59721 +extern atomic_unchecked_t fscache_n_invalidates;
59722 +extern atomic_unchecked_t fscache_n_invalidates_run;
59723
59724 -extern atomic_t fscache_n_updates;
59725 -extern atomic_t fscache_n_updates_null;
59726 -extern atomic_t fscache_n_updates_run;
59727 +extern atomic_unchecked_t fscache_n_updates;
59728 +extern atomic_unchecked_t fscache_n_updates_null;
59729 +extern atomic_unchecked_t fscache_n_updates_run;
59730
59731 -extern atomic_t fscache_n_relinquishes;
59732 -extern atomic_t fscache_n_relinquishes_null;
59733 -extern atomic_t fscache_n_relinquishes_waitcrt;
59734 -extern atomic_t fscache_n_relinquishes_retire;
59735 +extern atomic_unchecked_t fscache_n_relinquishes;
59736 +extern atomic_unchecked_t fscache_n_relinquishes_null;
59737 +extern atomic_unchecked_t fscache_n_relinquishes_waitcrt;
59738 +extern atomic_unchecked_t fscache_n_relinquishes_retire;
59739
59740 -extern atomic_t fscache_n_cookie_index;
59741 -extern atomic_t fscache_n_cookie_data;
59742 -extern atomic_t fscache_n_cookie_special;
59743 +extern atomic_unchecked_t fscache_n_cookie_index;
59744 +extern atomic_unchecked_t fscache_n_cookie_data;
59745 +extern atomic_unchecked_t fscache_n_cookie_special;
59746
59747 -extern atomic_t fscache_n_object_alloc;
59748 -extern atomic_t fscache_n_object_no_alloc;
59749 -extern atomic_t fscache_n_object_lookups;
59750 -extern atomic_t fscache_n_object_lookups_negative;
59751 -extern atomic_t fscache_n_object_lookups_positive;
59752 -extern atomic_t fscache_n_object_lookups_timed_out;
59753 -extern atomic_t fscache_n_object_created;
59754 -extern atomic_t fscache_n_object_avail;
59755 -extern atomic_t fscache_n_object_dead;
59756 +extern atomic_unchecked_t fscache_n_object_alloc;
59757 +extern atomic_unchecked_t fscache_n_object_no_alloc;
59758 +extern atomic_unchecked_t fscache_n_object_lookups;
59759 +extern atomic_unchecked_t fscache_n_object_lookups_negative;
59760 +extern atomic_unchecked_t fscache_n_object_lookups_positive;
59761 +extern atomic_unchecked_t fscache_n_object_lookups_timed_out;
59762 +extern atomic_unchecked_t fscache_n_object_created;
59763 +extern atomic_unchecked_t fscache_n_object_avail;
59764 +extern atomic_unchecked_t fscache_n_object_dead;
59765
59766 -extern atomic_t fscache_n_checkaux_none;
59767 -extern atomic_t fscache_n_checkaux_okay;
59768 -extern atomic_t fscache_n_checkaux_update;
59769 -extern atomic_t fscache_n_checkaux_obsolete;
59770 +extern atomic_unchecked_t fscache_n_checkaux_none;
59771 +extern atomic_unchecked_t fscache_n_checkaux_okay;
59772 +extern atomic_unchecked_t fscache_n_checkaux_update;
59773 +extern atomic_unchecked_t fscache_n_checkaux_obsolete;
59774
59775 extern atomic_t fscache_n_cop_alloc_object;
59776 extern atomic_t fscache_n_cop_lookup_object;
59777 @@ -272,6 +272,11 @@ static inline void fscache_stat(atomic_t *stat)
59778 atomic_inc(stat);
59779 }
59780
59781 +static inline void fscache_stat_unchecked(atomic_unchecked_t *stat)
59782 +{
59783 + atomic_inc_unchecked(stat);
59784 +}
59785 +
59786 static inline void fscache_stat_d(atomic_t *stat)
59787 {
59788 atomic_dec(stat);
59789 @@ -284,6 +289,7 @@ extern const struct file_operations fscache_stats_fops;
59790
59791 #define __fscache_stat(stat) (NULL)
59792 #define fscache_stat(stat) do {} while (0)
59793 +#define fscache_stat_unchecked(stat) do {} while (0)
59794 #define fscache_stat_d(stat) do {} while (0)
59795 #endif
59796
59797 diff --git a/fs/fscache/object.c b/fs/fscache/object.c
59798 index 53d35c5..5d68ed4 100644
59799 --- a/fs/fscache/object.c
59800 +++ b/fs/fscache/object.c
59801 @@ -451,7 +451,7 @@ static const struct fscache_state *fscache_look_up_object(struct fscache_object
59802 _debug("LOOKUP \"%s\" in \"%s\"",
59803 cookie->def->name, object->cache->tag->name);
59804
59805 - fscache_stat(&fscache_n_object_lookups);
59806 + fscache_stat_unchecked(&fscache_n_object_lookups);
59807 fscache_stat(&fscache_n_cop_lookup_object);
59808 ret = object->cache->ops->lookup_object(object);
59809 fscache_stat_d(&fscache_n_cop_lookup_object);
59810 @@ -461,7 +461,7 @@ static const struct fscache_state *fscache_look_up_object(struct fscache_object
59811 if (ret == -ETIMEDOUT) {
59812 /* probably stuck behind another object, so move this one to
59813 * the back of the queue */
59814 - fscache_stat(&fscache_n_object_lookups_timed_out);
59815 + fscache_stat_unchecked(&fscache_n_object_lookups_timed_out);
59816 _leave(" [timeout]");
59817 return NO_TRANSIT;
59818 }
59819 @@ -489,7 +489,7 @@ void fscache_object_lookup_negative(struct fscache_object *object)
59820 _enter("{OBJ%x,%s}", object->debug_id, object->state->name);
59821
59822 if (!test_and_set_bit(FSCACHE_OBJECT_IS_LOOKED_UP, &object->flags)) {
59823 - fscache_stat(&fscache_n_object_lookups_negative);
59824 + fscache_stat_unchecked(&fscache_n_object_lookups_negative);
59825
59826 /* Allow write requests to begin stacking up and read requests to begin
59827 * returning ENODATA.
59828 @@ -524,7 +524,7 @@ void fscache_obtained_object(struct fscache_object *object)
59829 /* if we were still looking up, then we must have a positive lookup
59830 * result, in which case there may be data available */
59831 if (!test_and_set_bit(FSCACHE_OBJECT_IS_LOOKED_UP, &object->flags)) {
59832 - fscache_stat(&fscache_n_object_lookups_positive);
59833 + fscache_stat_unchecked(&fscache_n_object_lookups_positive);
59834
59835 /* We do (presumably) have data */
59836 clear_bit_unlock(FSCACHE_COOKIE_NO_DATA_YET, &cookie->flags);
59837 @@ -536,7 +536,7 @@ void fscache_obtained_object(struct fscache_object *object)
59838 clear_bit_unlock(FSCACHE_COOKIE_LOOKING_UP, &cookie->flags);
59839 wake_up_bit(&cookie->flags, FSCACHE_COOKIE_LOOKING_UP);
59840 } else {
59841 - fscache_stat(&fscache_n_object_created);
59842 + fscache_stat_unchecked(&fscache_n_object_created);
59843 }
59844
59845 set_bit(FSCACHE_OBJECT_IS_AVAILABLE, &object->flags);
59846 @@ -572,7 +572,7 @@ static const struct fscache_state *fscache_object_available(struct fscache_objec
59847 fscache_stat_d(&fscache_n_cop_lookup_complete);
59848
59849 fscache_hist(fscache_obj_instantiate_histogram, object->lookup_jif);
59850 - fscache_stat(&fscache_n_object_avail);
59851 + fscache_stat_unchecked(&fscache_n_object_avail);
59852
59853 _leave("");
59854 return transit_to(JUMPSTART_DEPS);
59855 @@ -719,7 +719,7 @@ static const struct fscache_state *fscache_drop_object(struct fscache_object *ob
59856
59857 /* this just shifts the object release to the work processor */
59858 fscache_put_object(object);
59859 - fscache_stat(&fscache_n_object_dead);
59860 + fscache_stat_unchecked(&fscache_n_object_dead);
59861
59862 _leave("");
59863 return transit_to(OBJECT_DEAD);
59864 @@ -884,7 +884,7 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
59865 enum fscache_checkaux result;
59866
59867 if (!object->cookie->def->check_aux) {
59868 - fscache_stat(&fscache_n_checkaux_none);
59869 + fscache_stat_unchecked(&fscache_n_checkaux_none);
59870 return FSCACHE_CHECKAUX_OKAY;
59871 }
59872
59873 @@ -893,17 +893,17 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
59874 switch (result) {
59875 /* entry okay as is */
59876 case FSCACHE_CHECKAUX_OKAY:
59877 - fscache_stat(&fscache_n_checkaux_okay);
59878 + fscache_stat_unchecked(&fscache_n_checkaux_okay);
59879 break;
59880
59881 /* entry requires update */
59882 case FSCACHE_CHECKAUX_NEEDS_UPDATE:
59883 - fscache_stat(&fscache_n_checkaux_update);
59884 + fscache_stat_unchecked(&fscache_n_checkaux_update);
59885 break;
59886
59887 /* entry requires deletion */
59888 case FSCACHE_CHECKAUX_OBSOLETE:
59889 - fscache_stat(&fscache_n_checkaux_obsolete);
59890 + fscache_stat_unchecked(&fscache_n_checkaux_obsolete);
59891 break;
59892
59893 default:
59894 @@ -989,7 +989,7 @@ static const struct fscache_state *fscache_invalidate_object(struct fscache_obje
59895 {
59896 const struct fscache_state *s;
59897
59898 - fscache_stat(&fscache_n_invalidates_run);
59899 + fscache_stat_unchecked(&fscache_n_invalidates_run);
59900 fscache_stat(&fscache_n_cop_invalidate_object);
59901 s = _fscache_invalidate_object(object, event);
59902 fscache_stat_d(&fscache_n_cop_invalidate_object);
59903 @@ -1004,7 +1004,7 @@ static const struct fscache_state *fscache_update_object(struct fscache_object *
59904 {
59905 _enter("{OBJ%x},%d", object->debug_id, event);
59906
59907 - fscache_stat(&fscache_n_updates_run);
59908 + fscache_stat_unchecked(&fscache_n_updates_run);
59909 fscache_stat(&fscache_n_cop_update_object);
59910 object->cache->ops->update_object(object);
59911 fscache_stat_d(&fscache_n_cop_update_object);
59912 diff --git a/fs/fscache/operation.c b/fs/fscache/operation.c
59913 index 318071a..379938b 100644
59914 --- a/fs/fscache/operation.c
59915 +++ b/fs/fscache/operation.c
59916 @@ -17,7 +17,7 @@
59917 #include <linux/slab.h>
59918 #include "internal.h"
59919
59920 -atomic_t fscache_op_debug_id;
59921 +atomic_unchecked_t fscache_op_debug_id;
59922 EXPORT_SYMBOL(fscache_op_debug_id);
59923
59924 /**
59925 @@ -39,7 +39,7 @@ void fscache_enqueue_operation(struct fscache_operation *op)
59926 ASSERTCMP(atomic_read(&op->usage), >, 0);
59927 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_IN_PROGRESS);
59928
59929 - fscache_stat(&fscache_n_op_enqueue);
59930 + fscache_stat_unchecked(&fscache_n_op_enqueue);
59931 switch (op->flags & FSCACHE_OP_TYPE) {
59932 case FSCACHE_OP_ASYNC:
59933 _debug("queue async");
59934 @@ -73,7 +73,7 @@ static void fscache_run_op(struct fscache_object *object,
59935 wake_up_bit(&op->flags, FSCACHE_OP_WAITING);
59936 if (op->processor)
59937 fscache_enqueue_operation(op);
59938 - fscache_stat(&fscache_n_op_run);
59939 + fscache_stat_unchecked(&fscache_n_op_run);
59940 }
59941
59942 /*
59943 @@ -105,11 +105,11 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
59944 if (object->n_in_progress > 0) {
59945 atomic_inc(&op->usage);
59946 list_add_tail(&op->pend_link, &object->pending_ops);
59947 - fscache_stat(&fscache_n_op_pend);
59948 + fscache_stat_unchecked(&fscache_n_op_pend);
59949 } else if (!list_empty(&object->pending_ops)) {
59950 atomic_inc(&op->usage);
59951 list_add_tail(&op->pend_link, &object->pending_ops);
59952 - fscache_stat(&fscache_n_op_pend);
59953 + fscache_stat_unchecked(&fscache_n_op_pend);
59954 fscache_start_operations(object);
59955 } else {
59956 ASSERTCMP(object->n_in_progress, ==, 0);
59957 @@ -125,7 +125,7 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
59958 object->n_exclusive++; /* reads and writes must wait */
59959 atomic_inc(&op->usage);
59960 list_add_tail(&op->pend_link, &object->pending_ops);
59961 - fscache_stat(&fscache_n_op_pend);
59962 + fscache_stat_unchecked(&fscache_n_op_pend);
59963 ret = 0;
59964 } else {
59965 /* If we're in any other state, there must have been an I/O
59966 @@ -212,11 +212,11 @@ int fscache_submit_op(struct fscache_object *object,
59967 if (object->n_exclusive > 0) {
59968 atomic_inc(&op->usage);
59969 list_add_tail(&op->pend_link, &object->pending_ops);
59970 - fscache_stat(&fscache_n_op_pend);
59971 + fscache_stat_unchecked(&fscache_n_op_pend);
59972 } else if (!list_empty(&object->pending_ops)) {
59973 atomic_inc(&op->usage);
59974 list_add_tail(&op->pend_link, &object->pending_ops);
59975 - fscache_stat(&fscache_n_op_pend);
59976 + fscache_stat_unchecked(&fscache_n_op_pend);
59977 fscache_start_operations(object);
59978 } else {
59979 ASSERTCMP(object->n_exclusive, ==, 0);
59980 @@ -228,10 +228,10 @@ int fscache_submit_op(struct fscache_object *object,
59981 object->n_ops++;
59982 atomic_inc(&op->usage);
59983 list_add_tail(&op->pend_link, &object->pending_ops);
59984 - fscache_stat(&fscache_n_op_pend);
59985 + fscache_stat_unchecked(&fscache_n_op_pend);
59986 ret = 0;
59987 } else if (fscache_object_is_dying(object)) {
59988 - fscache_stat(&fscache_n_op_rejected);
59989 + fscache_stat_unchecked(&fscache_n_op_rejected);
59990 op->state = FSCACHE_OP_ST_CANCELLED;
59991 ret = -ENOBUFS;
59992 } else if (!test_bit(FSCACHE_IOERROR, &object->cache->flags)) {
59993 @@ -310,7 +310,7 @@ int fscache_cancel_op(struct fscache_operation *op,
59994 ret = -EBUSY;
59995 if (op->state == FSCACHE_OP_ST_PENDING) {
59996 ASSERT(!list_empty(&op->pend_link));
59997 - fscache_stat(&fscache_n_op_cancelled);
59998 + fscache_stat_unchecked(&fscache_n_op_cancelled);
59999 list_del_init(&op->pend_link);
60000 if (do_cancel)
60001 do_cancel(op);
60002 @@ -342,7 +342,7 @@ void fscache_cancel_all_ops(struct fscache_object *object)
60003 while (!list_empty(&object->pending_ops)) {
60004 op = list_entry(object->pending_ops.next,
60005 struct fscache_operation, pend_link);
60006 - fscache_stat(&fscache_n_op_cancelled);
60007 + fscache_stat_unchecked(&fscache_n_op_cancelled);
60008 list_del_init(&op->pend_link);
60009
60010 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_PENDING);
60011 @@ -414,7 +414,7 @@ void fscache_put_operation(struct fscache_operation *op)
60012 op->state, ==, FSCACHE_OP_ST_CANCELLED);
60013 op->state = FSCACHE_OP_ST_DEAD;
60014
60015 - fscache_stat(&fscache_n_op_release);
60016 + fscache_stat_unchecked(&fscache_n_op_release);
60017
60018 if (op->release) {
60019 op->release(op);
60020 @@ -433,7 +433,7 @@ void fscache_put_operation(struct fscache_operation *op)
60021 * lock, and defer it otherwise */
60022 if (!spin_trylock(&object->lock)) {
60023 _debug("defer put");
60024 - fscache_stat(&fscache_n_op_deferred_release);
60025 + fscache_stat_unchecked(&fscache_n_op_deferred_release);
60026
60027 cache = object->cache;
60028 spin_lock(&cache->op_gc_list_lock);
60029 @@ -486,7 +486,7 @@ void fscache_operation_gc(struct work_struct *work)
60030
60031 _debug("GC DEFERRED REL OBJ%x OP%x",
60032 object->debug_id, op->debug_id);
60033 - fscache_stat(&fscache_n_op_gc);
60034 + fscache_stat_unchecked(&fscache_n_op_gc);
60035
60036 ASSERTCMP(atomic_read(&op->usage), ==, 0);
60037 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_DEAD);
60038 diff --git a/fs/fscache/page.c b/fs/fscache/page.c
60039 index 7f5c658..6c1e164 100644
60040 --- a/fs/fscache/page.c
60041 +++ b/fs/fscache/page.c
60042 @@ -61,7 +61,7 @@ try_again:
60043 val = radix_tree_lookup(&cookie->stores, page->index);
60044 if (!val) {
60045 rcu_read_unlock();
60046 - fscache_stat(&fscache_n_store_vmscan_not_storing);
60047 + fscache_stat_unchecked(&fscache_n_store_vmscan_not_storing);
60048 __fscache_uncache_page(cookie, page);
60049 return true;
60050 }
60051 @@ -91,11 +91,11 @@ try_again:
60052 spin_unlock(&cookie->stores_lock);
60053
60054 if (xpage) {
60055 - fscache_stat(&fscache_n_store_vmscan_cancelled);
60056 - fscache_stat(&fscache_n_store_radix_deletes);
60057 + fscache_stat_unchecked(&fscache_n_store_vmscan_cancelled);
60058 + fscache_stat_unchecked(&fscache_n_store_radix_deletes);
60059 ASSERTCMP(xpage, ==, page);
60060 } else {
60061 - fscache_stat(&fscache_n_store_vmscan_gone);
60062 + fscache_stat_unchecked(&fscache_n_store_vmscan_gone);
60063 }
60064
60065 wake_up_bit(&cookie->flags, 0);
60066 @@ -110,11 +110,11 @@ page_busy:
60067 * sleeping on memory allocation, so we may need to impose a timeout
60068 * too. */
60069 if (!(gfp & __GFP_WAIT) || !(gfp & __GFP_FS)) {
60070 - fscache_stat(&fscache_n_store_vmscan_busy);
60071 + fscache_stat_unchecked(&fscache_n_store_vmscan_busy);
60072 return false;
60073 }
60074
60075 - fscache_stat(&fscache_n_store_vmscan_wait);
60076 + fscache_stat_unchecked(&fscache_n_store_vmscan_wait);
60077 __fscache_wait_on_page_write(cookie, page);
60078 gfp &= ~__GFP_WAIT;
60079 goto try_again;
60080 @@ -140,7 +140,7 @@ static void fscache_end_page_write(struct fscache_object *object,
60081 FSCACHE_COOKIE_STORING_TAG);
60082 if (!radix_tree_tag_get(&cookie->stores, page->index,
60083 FSCACHE_COOKIE_PENDING_TAG)) {
60084 - fscache_stat(&fscache_n_store_radix_deletes);
60085 + fscache_stat_unchecked(&fscache_n_store_radix_deletes);
60086 xpage = radix_tree_delete(&cookie->stores, page->index);
60087 }
60088 spin_unlock(&cookie->stores_lock);
60089 @@ -161,7 +161,7 @@ static void fscache_attr_changed_op(struct fscache_operation *op)
60090
60091 _enter("{OBJ%x OP%x}", object->debug_id, op->debug_id);
60092
60093 - fscache_stat(&fscache_n_attr_changed_calls);
60094 + fscache_stat_unchecked(&fscache_n_attr_changed_calls);
60095
60096 if (fscache_object_is_active(object)) {
60097 fscache_stat(&fscache_n_cop_attr_changed);
60098 @@ -188,11 +188,11 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
60099
60100 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
60101
60102 - fscache_stat(&fscache_n_attr_changed);
60103 + fscache_stat_unchecked(&fscache_n_attr_changed);
60104
60105 op = kzalloc(sizeof(*op), GFP_KERNEL);
60106 if (!op) {
60107 - fscache_stat(&fscache_n_attr_changed_nomem);
60108 + fscache_stat_unchecked(&fscache_n_attr_changed_nomem);
60109 _leave(" = -ENOMEM");
60110 return -ENOMEM;
60111 }
60112 @@ -214,7 +214,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
60113 if (fscache_submit_exclusive_op(object, op) < 0)
60114 goto nobufs;
60115 spin_unlock(&cookie->lock);
60116 - fscache_stat(&fscache_n_attr_changed_ok);
60117 + fscache_stat_unchecked(&fscache_n_attr_changed_ok);
60118 fscache_put_operation(op);
60119 _leave(" = 0");
60120 return 0;
60121 @@ -225,7 +225,7 @@ nobufs:
60122 kfree(op);
60123 if (wake_cookie)
60124 __fscache_wake_unused_cookie(cookie);
60125 - fscache_stat(&fscache_n_attr_changed_nobufs);
60126 + fscache_stat_unchecked(&fscache_n_attr_changed_nobufs);
60127 _leave(" = %d", -ENOBUFS);
60128 return -ENOBUFS;
60129 }
60130 @@ -264,7 +264,7 @@ static struct fscache_retrieval *fscache_alloc_retrieval(
60131 /* allocate a retrieval operation and attempt to submit it */
60132 op = kzalloc(sizeof(*op), GFP_NOIO);
60133 if (!op) {
60134 - fscache_stat(&fscache_n_retrievals_nomem);
60135 + fscache_stat_unchecked(&fscache_n_retrievals_nomem);
60136 return NULL;
60137 }
60138
60139 @@ -294,13 +294,13 @@ int fscache_wait_for_deferred_lookup(struct fscache_cookie *cookie)
60140 return 0;
60141 }
60142
60143 - fscache_stat(&fscache_n_retrievals_wait);
60144 + fscache_stat_unchecked(&fscache_n_retrievals_wait);
60145
60146 jif = jiffies;
60147 if (wait_on_bit(&cookie->flags, FSCACHE_COOKIE_LOOKING_UP,
60148 fscache_wait_bit_interruptible,
60149 TASK_INTERRUPTIBLE) != 0) {
60150 - fscache_stat(&fscache_n_retrievals_intr);
60151 + fscache_stat_unchecked(&fscache_n_retrievals_intr);
60152 _leave(" = -ERESTARTSYS");
60153 return -ERESTARTSYS;
60154 }
60155 @@ -329,8 +329,8 @@ static void fscache_do_cancel_retrieval(struct fscache_operation *_op)
60156 */
60157 int fscache_wait_for_operation_activation(struct fscache_object *object,
60158 struct fscache_operation *op,
60159 - atomic_t *stat_op_waits,
60160 - atomic_t *stat_object_dead,
60161 + atomic_unchecked_t *stat_op_waits,
60162 + atomic_unchecked_t *stat_object_dead,
60163 void (*do_cancel)(struct fscache_operation *))
60164 {
60165 int ret;
60166 @@ -340,7 +340,7 @@ int fscache_wait_for_operation_activation(struct fscache_object *object,
60167
60168 _debug(">>> WT");
60169 if (stat_op_waits)
60170 - fscache_stat(stat_op_waits);
60171 + fscache_stat_unchecked(stat_op_waits);
60172 if (wait_on_bit(&op->flags, FSCACHE_OP_WAITING,
60173 fscache_wait_bit_interruptible,
60174 TASK_INTERRUPTIBLE) != 0) {
60175 @@ -358,7 +358,7 @@ int fscache_wait_for_operation_activation(struct fscache_object *object,
60176 check_if_dead:
60177 if (op->state == FSCACHE_OP_ST_CANCELLED) {
60178 if (stat_object_dead)
60179 - fscache_stat(stat_object_dead);
60180 + fscache_stat_unchecked(stat_object_dead);
60181 _leave(" = -ENOBUFS [cancelled]");
60182 return -ENOBUFS;
60183 }
60184 @@ -366,7 +366,7 @@ check_if_dead:
60185 pr_err("%s() = -ENOBUFS [obj dead %d]\n", __func__, op->state);
60186 fscache_cancel_op(op, do_cancel);
60187 if (stat_object_dead)
60188 - fscache_stat(stat_object_dead);
60189 + fscache_stat_unchecked(stat_object_dead);
60190 return -ENOBUFS;
60191 }
60192 return 0;
60193 @@ -394,7 +394,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
60194
60195 _enter("%p,%p,,,", cookie, page);
60196
60197 - fscache_stat(&fscache_n_retrievals);
60198 + fscache_stat_unchecked(&fscache_n_retrievals);
60199
60200 if (hlist_empty(&cookie->backing_objects))
60201 goto nobufs;
60202 @@ -436,7 +436,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
60203 goto nobufs_unlock_dec;
60204 spin_unlock(&cookie->lock);
60205
60206 - fscache_stat(&fscache_n_retrieval_ops);
60207 + fscache_stat_unchecked(&fscache_n_retrieval_ops);
60208
60209 /* pin the netfs read context in case we need to do the actual netfs
60210 * read because we've encountered a cache read failure */
60211 @@ -467,15 +467,15 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
60212
60213 error:
60214 if (ret == -ENOMEM)
60215 - fscache_stat(&fscache_n_retrievals_nomem);
60216 + fscache_stat_unchecked(&fscache_n_retrievals_nomem);
60217 else if (ret == -ERESTARTSYS)
60218 - fscache_stat(&fscache_n_retrievals_intr);
60219 + fscache_stat_unchecked(&fscache_n_retrievals_intr);
60220 else if (ret == -ENODATA)
60221 - fscache_stat(&fscache_n_retrievals_nodata);
60222 + fscache_stat_unchecked(&fscache_n_retrievals_nodata);
60223 else if (ret < 0)
60224 - fscache_stat(&fscache_n_retrievals_nobufs);
60225 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
60226 else
60227 - fscache_stat(&fscache_n_retrievals_ok);
60228 + fscache_stat_unchecked(&fscache_n_retrievals_ok);
60229
60230 fscache_put_retrieval(op);
60231 _leave(" = %d", ret);
60232 @@ -490,7 +490,7 @@ nobufs_unlock:
60233 __fscache_wake_unused_cookie(cookie);
60234 kfree(op);
60235 nobufs:
60236 - fscache_stat(&fscache_n_retrievals_nobufs);
60237 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
60238 _leave(" = -ENOBUFS");
60239 return -ENOBUFS;
60240 }
60241 @@ -529,7 +529,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
60242
60243 _enter("%p,,%d,,,", cookie, *nr_pages);
60244
60245 - fscache_stat(&fscache_n_retrievals);
60246 + fscache_stat_unchecked(&fscache_n_retrievals);
60247
60248 if (hlist_empty(&cookie->backing_objects))
60249 goto nobufs;
60250 @@ -567,7 +567,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
60251 goto nobufs_unlock_dec;
60252 spin_unlock(&cookie->lock);
60253
60254 - fscache_stat(&fscache_n_retrieval_ops);
60255 + fscache_stat_unchecked(&fscache_n_retrieval_ops);
60256
60257 /* pin the netfs read context in case we need to do the actual netfs
60258 * read because we've encountered a cache read failure */
60259 @@ -598,15 +598,15 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
60260
60261 error:
60262 if (ret == -ENOMEM)
60263 - fscache_stat(&fscache_n_retrievals_nomem);
60264 + fscache_stat_unchecked(&fscache_n_retrievals_nomem);
60265 else if (ret == -ERESTARTSYS)
60266 - fscache_stat(&fscache_n_retrievals_intr);
60267 + fscache_stat_unchecked(&fscache_n_retrievals_intr);
60268 else if (ret == -ENODATA)
60269 - fscache_stat(&fscache_n_retrievals_nodata);
60270 + fscache_stat_unchecked(&fscache_n_retrievals_nodata);
60271 else if (ret < 0)
60272 - fscache_stat(&fscache_n_retrievals_nobufs);
60273 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
60274 else
60275 - fscache_stat(&fscache_n_retrievals_ok);
60276 + fscache_stat_unchecked(&fscache_n_retrievals_ok);
60277
60278 fscache_put_retrieval(op);
60279 _leave(" = %d", ret);
60280 @@ -621,7 +621,7 @@ nobufs_unlock:
60281 if (wake_cookie)
60282 __fscache_wake_unused_cookie(cookie);
60283 nobufs:
60284 - fscache_stat(&fscache_n_retrievals_nobufs);
60285 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
60286 _leave(" = -ENOBUFS");
60287 return -ENOBUFS;
60288 }
60289 @@ -646,7 +646,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
60290
60291 _enter("%p,%p,,,", cookie, page);
60292
60293 - fscache_stat(&fscache_n_allocs);
60294 + fscache_stat_unchecked(&fscache_n_allocs);
60295
60296 if (hlist_empty(&cookie->backing_objects))
60297 goto nobufs;
60298 @@ -680,7 +680,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
60299 goto nobufs_unlock_dec;
60300 spin_unlock(&cookie->lock);
60301
60302 - fscache_stat(&fscache_n_alloc_ops);
60303 + fscache_stat_unchecked(&fscache_n_alloc_ops);
60304
60305 ret = fscache_wait_for_operation_activation(
60306 object, &op->op,
60307 @@ -697,11 +697,11 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
60308
60309 error:
60310 if (ret == -ERESTARTSYS)
60311 - fscache_stat(&fscache_n_allocs_intr);
60312 + fscache_stat_unchecked(&fscache_n_allocs_intr);
60313 else if (ret < 0)
60314 - fscache_stat(&fscache_n_allocs_nobufs);
60315 + fscache_stat_unchecked(&fscache_n_allocs_nobufs);
60316 else
60317 - fscache_stat(&fscache_n_allocs_ok);
60318 + fscache_stat_unchecked(&fscache_n_allocs_ok);
60319
60320 fscache_put_retrieval(op);
60321 _leave(" = %d", ret);
60322 @@ -715,7 +715,7 @@ nobufs_unlock:
60323 if (wake_cookie)
60324 __fscache_wake_unused_cookie(cookie);
60325 nobufs:
60326 - fscache_stat(&fscache_n_allocs_nobufs);
60327 + fscache_stat_unchecked(&fscache_n_allocs_nobufs);
60328 _leave(" = -ENOBUFS");
60329 return -ENOBUFS;
60330 }
60331 @@ -791,7 +791,7 @@ static void fscache_write_op(struct fscache_operation *_op)
60332
60333 spin_lock(&cookie->stores_lock);
60334
60335 - fscache_stat(&fscache_n_store_calls);
60336 + fscache_stat_unchecked(&fscache_n_store_calls);
60337
60338 /* find a page to store */
60339 page = NULL;
60340 @@ -802,7 +802,7 @@ static void fscache_write_op(struct fscache_operation *_op)
60341 page = results[0];
60342 _debug("gang %d [%lx]", n, page->index);
60343 if (page->index > op->store_limit) {
60344 - fscache_stat(&fscache_n_store_pages_over_limit);
60345 + fscache_stat_unchecked(&fscache_n_store_pages_over_limit);
60346 goto superseded;
60347 }
60348
60349 @@ -814,7 +814,7 @@ static void fscache_write_op(struct fscache_operation *_op)
60350 spin_unlock(&cookie->stores_lock);
60351 spin_unlock(&object->lock);
60352
60353 - fscache_stat(&fscache_n_store_pages);
60354 + fscache_stat_unchecked(&fscache_n_store_pages);
60355 fscache_stat(&fscache_n_cop_write_page);
60356 ret = object->cache->ops->write_page(op, page);
60357 fscache_stat_d(&fscache_n_cop_write_page);
60358 @@ -918,7 +918,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
60359 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
60360 ASSERT(PageFsCache(page));
60361
60362 - fscache_stat(&fscache_n_stores);
60363 + fscache_stat_unchecked(&fscache_n_stores);
60364
60365 if (test_bit(FSCACHE_COOKIE_INVALIDATING, &cookie->flags)) {
60366 _leave(" = -ENOBUFS [invalidating]");
60367 @@ -977,7 +977,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
60368 spin_unlock(&cookie->stores_lock);
60369 spin_unlock(&object->lock);
60370
60371 - op->op.debug_id = atomic_inc_return(&fscache_op_debug_id);
60372 + op->op.debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
60373 op->store_limit = object->store_limit;
60374
60375 __fscache_use_cookie(cookie);
60376 @@ -986,8 +986,8 @@ int __fscache_write_page(struct fscache_cookie *cookie,
60377
60378 spin_unlock(&cookie->lock);
60379 radix_tree_preload_end();
60380 - fscache_stat(&fscache_n_store_ops);
60381 - fscache_stat(&fscache_n_stores_ok);
60382 + fscache_stat_unchecked(&fscache_n_store_ops);
60383 + fscache_stat_unchecked(&fscache_n_stores_ok);
60384
60385 /* the work queue now carries its own ref on the object */
60386 fscache_put_operation(&op->op);
60387 @@ -995,14 +995,14 @@ int __fscache_write_page(struct fscache_cookie *cookie,
60388 return 0;
60389
60390 already_queued:
60391 - fscache_stat(&fscache_n_stores_again);
60392 + fscache_stat_unchecked(&fscache_n_stores_again);
60393 already_pending:
60394 spin_unlock(&cookie->stores_lock);
60395 spin_unlock(&object->lock);
60396 spin_unlock(&cookie->lock);
60397 radix_tree_preload_end();
60398 kfree(op);
60399 - fscache_stat(&fscache_n_stores_ok);
60400 + fscache_stat_unchecked(&fscache_n_stores_ok);
60401 _leave(" = 0");
60402 return 0;
60403
60404 @@ -1024,14 +1024,14 @@ nobufs:
60405 kfree(op);
60406 if (wake_cookie)
60407 __fscache_wake_unused_cookie(cookie);
60408 - fscache_stat(&fscache_n_stores_nobufs);
60409 + fscache_stat_unchecked(&fscache_n_stores_nobufs);
60410 _leave(" = -ENOBUFS");
60411 return -ENOBUFS;
60412
60413 nomem_free:
60414 kfree(op);
60415 nomem:
60416 - fscache_stat(&fscache_n_stores_oom);
60417 + fscache_stat_unchecked(&fscache_n_stores_oom);
60418 _leave(" = -ENOMEM");
60419 return -ENOMEM;
60420 }
60421 @@ -1049,7 +1049,7 @@ void __fscache_uncache_page(struct fscache_cookie *cookie, struct page *page)
60422 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
60423 ASSERTCMP(page, !=, NULL);
60424
60425 - fscache_stat(&fscache_n_uncaches);
60426 + fscache_stat_unchecked(&fscache_n_uncaches);
60427
60428 /* cache withdrawal may beat us to it */
60429 if (!PageFsCache(page))
60430 @@ -1100,7 +1100,7 @@ void fscache_mark_page_cached(struct fscache_retrieval *op, struct page *page)
60431 struct fscache_cookie *cookie = op->op.object->cookie;
60432
60433 #ifdef CONFIG_FSCACHE_STATS
60434 - atomic_inc(&fscache_n_marks);
60435 + atomic_inc_unchecked(&fscache_n_marks);
60436 #endif
60437
60438 _debug("- mark %p{%lx}", page, page->index);
60439 diff --git a/fs/fscache/stats.c b/fs/fscache/stats.c
60440 index 40d13c7..ddf52b9 100644
60441 --- a/fs/fscache/stats.c
60442 +++ b/fs/fscache/stats.c
60443 @@ -18,99 +18,99 @@
60444 /*
60445 * operation counters
60446 */
60447 -atomic_t fscache_n_op_pend;
60448 -atomic_t fscache_n_op_run;
60449 -atomic_t fscache_n_op_enqueue;
60450 -atomic_t fscache_n_op_requeue;
60451 -atomic_t fscache_n_op_deferred_release;
60452 -atomic_t fscache_n_op_release;
60453 -atomic_t fscache_n_op_gc;
60454 -atomic_t fscache_n_op_cancelled;
60455 -atomic_t fscache_n_op_rejected;
60456 +atomic_unchecked_t fscache_n_op_pend;
60457 +atomic_unchecked_t fscache_n_op_run;
60458 +atomic_unchecked_t fscache_n_op_enqueue;
60459 +atomic_unchecked_t fscache_n_op_requeue;
60460 +atomic_unchecked_t fscache_n_op_deferred_release;
60461 +atomic_unchecked_t fscache_n_op_release;
60462 +atomic_unchecked_t fscache_n_op_gc;
60463 +atomic_unchecked_t fscache_n_op_cancelled;
60464 +atomic_unchecked_t fscache_n_op_rejected;
60465
60466 -atomic_t fscache_n_attr_changed;
60467 -atomic_t fscache_n_attr_changed_ok;
60468 -atomic_t fscache_n_attr_changed_nobufs;
60469 -atomic_t fscache_n_attr_changed_nomem;
60470 -atomic_t fscache_n_attr_changed_calls;
60471 +atomic_unchecked_t fscache_n_attr_changed;
60472 +atomic_unchecked_t fscache_n_attr_changed_ok;
60473 +atomic_unchecked_t fscache_n_attr_changed_nobufs;
60474 +atomic_unchecked_t fscache_n_attr_changed_nomem;
60475 +atomic_unchecked_t fscache_n_attr_changed_calls;
60476
60477 -atomic_t fscache_n_allocs;
60478 -atomic_t fscache_n_allocs_ok;
60479 -atomic_t fscache_n_allocs_wait;
60480 -atomic_t fscache_n_allocs_nobufs;
60481 -atomic_t fscache_n_allocs_intr;
60482 -atomic_t fscache_n_allocs_object_dead;
60483 -atomic_t fscache_n_alloc_ops;
60484 -atomic_t fscache_n_alloc_op_waits;
60485 +atomic_unchecked_t fscache_n_allocs;
60486 +atomic_unchecked_t fscache_n_allocs_ok;
60487 +atomic_unchecked_t fscache_n_allocs_wait;
60488 +atomic_unchecked_t fscache_n_allocs_nobufs;
60489 +atomic_unchecked_t fscache_n_allocs_intr;
60490 +atomic_unchecked_t fscache_n_allocs_object_dead;
60491 +atomic_unchecked_t fscache_n_alloc_ops;
60492 +atomic_unchecked_t fscache_n_alloc_op_waits;
60493
60494 -atomic_t fscache_n_retrievals;
60495 -atomic_t fscache_n_retrievals_ok;
60496 -atomic_t fscache_n_retrievals_wait;
60497 -atomic_t fscache_n_retrievals_nodata;
60498 -atomic_t fscache_n_retrievals_nobufs;
60499 -atomic_t fscache_n_retrievals_intr;
60500 -atomic_t fscache_n_retrievals_nomem;
60501 -atomic_t fscache_n_retrievals_object_dead;
60502 -atomic_t fscache_n_retrieval_ops;
60503 -atomic_t fscache_n_retrieval_op_waits;
60504 +atomic_unchecked_t fscache_n_retrievals;
60505 +atomic_unchecked_t fscache_n_retrievals_ok;
60506 +atomic_unchecked_t fscache_n_retrievals_wait;
60507 +atomic_unchecked_t fscache_n_retrievals_nodata;
60508 +atomic_unchecked_t fscache_n_retrievals_nobufs;
60509 +atomic_unchecked_t fscache_n_retrievals_intr;
60510 +atomic_unchecked_t fscache_n_retrievals_nomem;
60511 +atomic_unchecked_t fscache_n_retrievals_object_dead;
60512 +atomic_unchecked_t fscache_n_retrieval_ops;
60513 +atomic_unchecked_t fscache_n_retrieval_op_waits;
60514
60515 -atomic_t fscache_n_stores;
60516 -atomic_t fscache_n_stores_ok;
60517 -atomic_t fscache_n_stores_again;
60518 -atomic_t fscache_n_stores_nobufs;
60519 -atomic_t fscache_n_stores_oom;
60520 -atomic_t fscache_n_store_ops;
60521 -atomic_t fscache_n_store_calls;
60522 -atomic_t fscache_n_store_pages;
60523 -atomic_t fscache_n_store_radix_deletes;
60524 -atomic_t fscache_n_store_pages_over_limit;
60525 +atomic_unchecked_t fscache_n_stores;
60526 +atomic_unchecked_t fscache_n_stores_ok;
60527 +atomic_unchecked_t fscache_n_stores_again;
60528 +atomic_unchecked_t fscache_n_stores_nobufs;
60529 +atomic_unchecked_t fscache_n_stores_oom;
60530 +atomic_unchecked_t fscache_n_store_ops;
60531 +atomic_unchecked_t fscache_n_store_calls;
60532 +atomic_unchecked_t fscache_n_store_pages;
60533 +atomic_unchecked_t fscache_n_store_radix_deletes;
60534 +atomic_unchecked_t fscache_n_store_pages_over_limit;
60535
60536 -atomic_t fscache_n_store_vmscan_not_storing;
60537 -atomic_t fscache_n_store_vmscan_gone;
60538 -atomic_t fscache_n_store_vmscan_busy;
60539 -atomic_t fscache_n_store_vmscan_cancelled;
60540 -atomic_t fscache_n_store_vmscan_wait;
60541 +atomic_unchecked_t fscache_n_store_vmscan_not_storing;
60542 +atomic_unchecked_t fscache_n_store_vmscan_gone;
60543 +atomic_unchecked_t fscache_n_store_vmscan_busy;
60544 +atomic_unchecked_t fscache_n_store_vmscan_cancelled;
60545 +atomic_unchecked_t fscache_n_store_vmscan_wait;
60546
60547 -atomic_t fscache_n_marks;
60548 -atomic_t fscache_n_uncaches;
60549 +atomic_unchecked_t fscache_n_marks;
60550 +atomic_unchecked_t fscache_n_uncaches;
60551
60552 -atomic_t fscache_n_acquires;
60553 -atomic_t fscache_n_acquires_null;
60554 -atomic_t fscache_n_acquires_no_cache;
60555 -atomic_t fscache_n_acquires_ok;
60556 -atomic_t fscache_n_acquires_nobufs;
60557 -atomic_t fscache_n_acquires_oom;
60558 +atomic_unchecked_t fscache_n_acquires;
60559 +atomic_unchecked_t fscache_n_acquires_null;
60560 +atomic_unchecked_t fscache_n_acquires_no_cache;
60561 +atomic_unchecked_t fscache_n_acquires_ok;
60562 +atomic_unchecked_t fscache_n_acquires_nobufs;
60563 +atomic_unchecked_t fscache_n_acquires_oom;
60564
60565 -atomic_t fscache_n_invalidates;
60566 -atomic_t fscache_n_invalidates_run;
60567 +atomic_unchecked_t fscache_n_invalidates;
60568 +atomic_unchecked_t fscache_n_invalidates_run;
60569
60570 -atomic_t fscache_n_updates;
60571 -atomic_t fscache_n_updates_null;
60572 -atomic_t fscache_n_updates_run;
60573 +atomic_unchecked_t fscache_n_updates;
60574 +atomic_unchecked_t fscache_n_updates_null;
60575 +atomic_unchecked_t fscache_n_updates_run;
60576
60577 -atomic_t fscache_n_relinquishes;
60578 -atomic_t fscache_n_relinquishes_null;
60579 -atomic_t fscache_n_relinquishes_waitcrt;
60580 -atomic_t fscache_n_relinquishes_retire;
60581 +atomic_unchecked_t fscache_n_relinquishes;
60582 +atomic_unchecked_t fscache_n_relinquishes_null;
60583 +atomic_unchecked_t fscache_n_relinquishes_waitcrt;
60584 +atomic_unchecked_t fscache_n_relinquishes_retire;
60585
60586 -atomic_t fscache_n_cookie_index;
60587 -atomic_t fscache_n_cookie_data;
60588 -atomic_t fscache_n_cookie_special;
60589 +atomic_unchecked_t fscache_n_cookie_index;
60590 +atomic_unchecked_t fscache_n_cookie_data;
60591 +atomic_unchecked_t fscache_n_cookie_special;
60592
60593 -atomic_t fscache_n_object_alloc;
60594 -atomic_t fscache_n_object_no_alloc;
60595 -atomic_t fscache_n_object_lookups;
60596 -atomic_t fscache_n_object_lookups_negative;
60597 -atomic_t fscache_n_object_lookups_positive;
60598 -atomic_t fscache_n_object_lookups_timed_out;
60599 -atomic_t fscache_n_object_created;
60600 -atomic_t fscache_n_object_avail;
60601 -atomic_t fscache_n_object_dead;
60602 +atomic_unchecked_t fscache_n_object_alloc;
60603 +atomic_unchecked_t fscache_n_object_no_alloc;
60604 +atomic_unchecked_t fscache_n_object_lookups;
60605 +atomic_unchecked_t fscache_n_object_lookups_negative;
60606 +atomic_unchecked_t fscache_n_object_lookups_positive;
60607 +atomic_unchecked_t fscache_n_object_lookups_timed_out;
60608 +atomic_unchecked_t fscache_n_object_created;
60609 +atomic_unchecked_t fscache_n_object_avail;
60610 +atomic_unchecked_t fscache_n_object_dead;
60611
60612 -atomic_t fscache_n_checkaux_none;
60613 -atomic_t fscache_n_checkaux_okay;
60614 -atomic_t fscache_n_checkaux_update;
60615 -atomic_t fscache_n_checkaux_obsolete;
60616 +atomic_unchecked_t fscache_n_checkaux_none;
60617 +atomic_unchecked_t fscache_n_checkaux_okay;
60618 +atomic_unchecked_t fscache_n_checkaux_update;
60619 +atomic_unchecked_t fscache_n_checkaux_obsolete;
60620
60621 atomic_t fscache_n_cop_alloc_object;
60622 atomic_t fscache_n_cop_lookup_object;
60623 @@ -138,118 +138,118 @@ static int fscache_stats_show(struct seq_file *m, void *v)
60624 seq_puts(m, "FS-Cache statistics\n");
60625
60626 seq_printf(m, "Cookies: idx=%u dat=%u spc=%u\n",
60627 - atomic_read(&fscache_n_cookie_index),
60628 - atomic_read(&fscache_n_cookie_data),
60629 - atomic_read(&fscache_n_cookie_special));
60630 + atomic_read_unchecked(&fscache_n_cookie_index),
60631 + atomic_read_unchecked(&fscache_n_cookie_data),
60632 + atomic_read_unchecked(&fscache_n_cookie_special));
60633
60634 seq_printf(m, "Objects: alc=%u nal=%u avl=%u ded=%u\n",
60635 - atomic_read(&fscache_n_object_alloc),
60636 - atomic_read(&fscache_n_object_no_alloc),
60637 - atomic_read(&fscache_n_object_avail),
60638 - atomic_read(&fscache_n_object_dead));
60639 + atomic_read_unchecked(&fscache_n_object_alloc),
60640 + atomic_read_unchecked(&fscache_n_object_no_alloc),
60641 + atomic_read_unchecked(&fscache_n_object_avail),
60642 + atomic_read_unchecked(&fscache_n_object_dead));
60643 seq_printf(m, "ChkAux : non=%u ok=%u upd=%u obs=%u\n",
60644 - atomic_read(&fscache_n_checkaux_none),
60645 - atomic_read(&fscache_n_checkaux_okay),
60646 - atomic_read(&fscache_n_checkaux_update),
60647 - atomic_read(&fscache_n_checkaux_obsolete));
60648 + atomic_read_unchecked(&fscache_n_checkaux_none),
60649 + atomic_read_unchecked(&fscache_n_checkaux_okay),
60650 + atomic_read_unchecked(&fscache_n_checkaux_update),
60651 + atomic_read_unchecked(&fscache_n_checkaux_obsolete));
60652
60653 seq_printf(m, "Pages : mrk=%u unc=%u\n",
60654 - atomic_read(&fscache_n_marks),
60655 - atomic_read(&fscache_n_uncaches));
60656 + atomic_read_unchecked(&fscache_n_marks),
60657 + atomic_read_unchecked(&fscache_n_uncaches));
60658
60659 seq_printf(m, "Acquire: n=%u nul=%u noc=%u ok=%u nbf=%u"
60660 " oom=%u\n",
60661 - atomic_read(&fscache_n_acquires),
60662 - atomic_read(&fscache_n_acquires_null),
60663 - atomic_read(&fscache_n_acquires_no_cache),
60664 - atomic_read(&fscache_n_acquires_ok),
60665 - atomic_read(&fscache_n_acquires_nobufs),
60666 - atomic_read(&fscache_n_acquires_oom));
60667 + atomic_read_unchecked(&fscache_n_acquires),
60668 + atomic_read_unchecked(&fscache_n_acquires_null),
60669 + atomic_read_unchecked(&fscache_n_acquires_no_cache),
60670 + atomic_read_unchecked(&fscache_n_acquires_ok),
60671 + atomic_read_unchecked(&fscache_n_acquires_nobufs),
60672 + atomic_read_unchecked(&fscache_n_acquires_oom));
60673
60674 seq_printf(m, "Lookups: n=%u neg=%u pos=%u crt=%u tmo=%u\n",
60675 - atomic_read(&fscache_n_object_lookups),
60676 - atomic_read(&fscache_n_object_lookups_negative),
60677 - atomic_read(&fscache_n_object_lookups_positive),
60678 - atomic_read(&fscache_n_object_created),
60679 - atomic_read(&fscache_n_object_lookups_timed_out));
60680 + atomic_read_unchecked(&fscache_n_object_lookups),
60681 + atomic_read_unchecked(&fscache_n_object_lookups_negative),
60682 + atomic_read_unchecked(&fscache_n_object_lookups_positive),
60683 + atomic_read_unchecked(&fscache_n_object_created),
60684 + atomic_read_unchecked(&fscache_n_object_lookups_timed_out));
60685
60686 seq_printf(m, "Invals : n=%u run=%u\n",
60687 - atomic_read(&fscache_n_invalidates),
60688 - atomic_read(&fscache_n_invalidates_run));
60689 + atomic_read_unchecked(&fscache_n_invalidates),
60690 + atomic_read_unchecked(&fscache_n_invalidates_run));
60691
60692 seq_printf(m, "Updates: n=%u nul=%u run=%u\n",
60693 - atomic_read(&fscache_n_updates),
60694 - atomic_read(&fscache_n_updates_null),
60695 - atomic_read(&fscache_n_updates_run));
60696 + atomic_read_unchecked(&fscache_n_updates),
60697 + atomic_read_unchecked(&fscache_n_updates_null),
60698 + atomic_read_unchecked(&fscache_n_updates_run));
60699
60700 seq_printf(m, "Relinqs: n=%u nul=%u wcr=%u rtr=%u\n",
60701 - atomic_read(&fscache_n_relinquishes),
60702 - atomic_read(&fscache_n_relinquishes_null),
60703 - atomic_read(&fscache_n_relinquishes_waitcrt),
60704 - atomic_read(&fscache_n_relinquishes_retire));
60705 + atomic_read_unchecked(&fscache_n_relinquishes),
60706 + atomic_read_unchecked(&fscache_n_relinquishes_null),
60707 + atomic_read_unchecked(&fscache_n_relinquishes_waitcrt),
60708 + atomic_read_unchecked(&fscache_n_relinquishes_retire));
60709
60710 seq_printf(m, "AttrChg: n=%u ok=%u nbf=%u oom=%u run=%u\n",
60711 - atomic_read(&fscache_n_attr_changed),
60712 - atomic_read(&fscache_n_attr_changed_ok),
60713 - atomic_read(&fscache_n_attr_changed_nobufs),
60714 - atomic_read(&fscache_n_attr_changed_nomem),
60715 - atomic_read(&fscache_n_attr_changed_calls));
60716 + atomic_read_unchecked(&fscache_n_attr_changed),
60717 + atomic_read_unchecked(&fscache_n_attr_changed_ok),
60718 + atomic_read_unchecked(&fscache_n_attr_changed_nobufs),
60719 + atomic_read_unchecked(&fscache_n_attr_changed_nomem),
60720 + atomic_read_unchecked(&fscache_n_attr_changed_calls));
60721
60722 seq_printf(m, "Allocs : n=%u ok=%u wt=%u nbf=%u int=%u\n",
60723 - atomic_read(&fscache_n_allocs),
60724 - atomic_read(&fscache_n_allocs_ok),
60725 - atomic_read(&fscache_n_allocs_wait),
60726 - atomic_read(&fscache_n_allocs_nobufs),
60727 - atomic_read(&fscache_n_allocs_intr));
60728 + atomic_read_unchecked(&fscache_n_allocs),
60729 + atomic_read_unchecked(&fscache_n_allocs_ok),
60730 + atomic_read_unchecked(&fscache_n_allocs_wait),
60731 + atomic_read_unchecked(&fscache_n_allocs_nobufs),
60732 + atomic_read_unchecked(&fscache_n_allocs_intr));
60733 seq_printf(m, "Allocs : ops=%u owt=%u abt=%u\n",
60734 - atomic_read(&fscache_n_alloc_ops),
60735 - atomic_read(&fscache_n_alloc_op_waits),
60736 - atomic_read(&fscache_n_allocs_object_dead));
60737 + atomic_read_unchecked(&fscache_n_alloc_ops),
60738 + atomic_read_unchecked(&fscache_n_alloc_op_waits),
60739 + atomic_read_unchecked(&fscache_n_allocs_object_dead));
60740
60741 seq_printf(m, "Retrvls: n=%u ok=%u wt=%u nod=%u nbf=%u"
60742 " int=%u oom=%u\n",
60743 - atomic_read(&fscache_n_retrievals),
60744 - atomic_read(&fscache_n_retrievals_ok),
60745 - atomic_read(&fscache_n_retrievals_wait),
60746 - atomic_read(&fscache_n_retrievals_nodata),
60747 - atomic_read(&fscache_n_retrievals_nobufs),
60748 - atomic_read(&fscache_n_retrievals_intr),
60749 - atomic_read(&fscache_n_retrievals_nomem));
60750 + atomic_read_unchecked(&fscache_n_retrievals),
60751 + atomic_read_unchecked(&fscache_n_retrievals_ok),
60752 + atomic_read_unchecked(&fscache_n_retrievals_wait),
60753 + atomic_read_unchecked(&fscache_n_retrievals_nodata),
60754 + atomic_read_unchecked(&fscache_n_retrievals_nobufs),
60755 + atomic_read_unchecked(&fscache_n_retrievals_intr),
60756 + atomic_read_unchecked(&fscache_n_retrievals_nomem));
60757 seq_printf(m, "Retrvls: ops=%u owt=%u abt=%u\n",
60758 - atomic_read(&fscache_n_retrieval_ops),
60759 - atomic_read(&fscache_n_retrieval_op_waits),
60760 - atomic_read(&fscache_n_retrievals_object_dead));
60761 + atomic_read_unchecked(&fscache_n_retrieval_ops),
60762 + atomic_read_unchecked(&fscache_n_retrieval_op_waits),
60763 + atomic_read_unchecked(&fscache_n_retrievals_object_dead));
60764
60765 seq_printf(m, "Stores : n=%u ok=%u agn=%u nbf=%u oom=%u\n",
60766 - atomic_read(&fscache_n_stores),
60767 - atomic_read(&fscache_n_stores_ok),
60768 - atomic_read(&fscache_n_stores_again),
60769 - atomic_read(&fscache_n_stores_nobufs),
60770 - atomic_read(&fscache_n_stores_oom));
60771 + atomic_read_unchecked(&fscache_n_stores),
60772 + atomic_read_unchecked(&fscache_n_stores_ok),
60773 + atomic_read_unchecked(&fscache_n_stores_again),
60774 + atomic_read_unchecked(&fscache_n_stores_nobufs),
60775 + atomic_read_unchecked(&fscache_n_stores_oom));
60776 seq_printf(m, "Stores : ops=%u run=%u pgs=%u rxd=%u olm=%u\n",
60777 - atomic_read(&fscache_n_store_ops),
60778 - atomic_read(&fscache_n_store_calls),
60779 - atomic_read(&fscache_n_store_pages),
60780 - atomic_read(&fscache_n_store_radix_deletes),
60781 - atomic_read(&fscache_n_store_pages_over_limit));
60782 + atomic_read_unchecked(&fscache_n_store_ops),
60783 + atomic_read_unchecked(&fscache_n_store_calls),
60784 + atomic_read_unchecked(&fscache_n_store_pages),
60785 + atomic_read_unchecked(&fscache_n_store_radix_deletes),
60786 + atomic_read_unchecked(&fscache_n_store_pages_over_limit));
60787
60788 seq_printf(m, "VmScan : nos=%u gon=%u bsy=%u can=%u wt=%u\n",
60789 - atomic_read(&fscache_n_store_vmscan_not_storing),
60790 - atomic_read(&fscache_n_store_vmscan_gone),
60791 - atomic_read(&fscache_n_store_vmscan_busy),
60792 - atomic_read(&fscache_n_store_vmscan_cancelled),
60793 - atomic_read(&fscache_n_store_vmscan_wait));
60794 + atomic_read_unchecked(&fscache_n_store_vmscan_not_storing),
60795 + atomic_read_unchecked(&fscache_n_store_vmscan_gone),
60796 + atomic_read_unchecked(&fscache_n_store_vmscan_busy),
60797 + atomic_read_unchecked(&fscache_n_store_vmscan_cancelled),
60798 + atomic_read_unchecked(&fscache_n_store_vmscan_wait));
60799
60800 seq_printf(m, "Ops : pend=%u run=%u enq=%u can=%u rej=%u\n",
60801 - atomic_read(&fscache_n_op_pend),
60802 - atomic_read(&fscache_n_op_run),
60803 - atomic_read(&fscache_n_op_enqueue),
60804 - atomic_read(&fscache_n_op_cancelled),
60805 - atomic_read(&fscache_n_op_rejected));
60806 + atomic_read_unchecked(&fscache_n_op_pend),
60807 + atomic_read_unchecked(&fscache_n_op_run),
60808 + atomic_read_unchecked(&fscache_n_op_enqueue),
60809 + atomic_read_unchecked(&fscache_n_op_cancelled),
60810 + atomic_read_unchecked(&fscache_n_op_rejected));
60811 seq_printf(m, "Ops : dfr=%u rel=%u gc=%u\n",
60812 - atomic_read(&fscache_n_op_deferred_release),
60813 - atomic_read(&fscache_n_op_release),
60814 - atomic_read(&fscache_n_op_gc));
60815 + atomic_read_unchecked(&fscache_n_op_deferred_release),
60816 + atomic_read_unchecked(&fscache_n_op_release),
60817 + atomic_read_unchecked(&fscache_n_op_gc));
60818
60819 seq_printf(m, "CacheOp: alo=%d luo=%d luc=%d gro=%d\n",
60820 atomic_read(&fscache_n_cop_alloc_object),
60821 diff --git a/fs/fuse/cuse.c b/fs/fuse/cuse.c
60822 index b96a49b..9bfdc47 100644
60823 --- a/fs/fuse/cuse.c
60824 +++ b/fs/fuse/cuse.c
60825 @@ -606,10 +606,12 @@ static int __init cuse_init(void)
60826 INIT_LIST_HEAD(&cuse_conntbl[i]);
60827
60828 /* inherit and extend fuse_dev_operations */
60829 - cuse_channel_fops = fuse_dev_operations;
60830 - cuse_channel_fops.owner = THIS_MODULE;
60831 - cuse_channel_fops.open = cuse_channel_open;
60832 - cuse_channel_fops.release = cuse_channel_release;
60833 + pax_open_kernel();
60834 + memcpy((void *)&cuse_channel_fops, &fuse_dev_operations, sizeof(fuse_dev_operations));
60835 + *(void **)&cuse_channel_fops.owner = THIS_MODULE;
60836 + *(void **)&cuse_channel_fops.open = cuse_channel_open;
60837 + *(void **)&cuse_channel_fops.release = cuse_channel_release;
60838 + pax_close_kernel();
60839
60840 cuse_class = class_create(THIS_MODULE, "cuse");
60841 if (IS_ERR(cuse_class))
60842 diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c
60843 index fa8cb4b..4acb935 100644
60844 --- a/fs/fuse/dev.c
60845 +++ b/fs/fuse/dev.c
60846 @@ -1323,7 +1323,7 @@ static ssize_t fuse_dev_splice_read(struct file *in, loff_t *ppos,
60847 ret = 0;
60848 pipe_lock(pipe);
60849
60850 - if (!pipe->readers) {
60851 + if (!atomic_read(&pipe->readers)) {
60852 send_sig(SIGPIPE, current, 0);
60853 if (!ret)
60854 ret = -EPIPE;
60855 @@ -1352,7 +1352,7 @@ static ssize_t fuse_dev_splice_read(struct file *in, loff_t *ppos,
60856 page_nr++;
60857 ret += buf->len;
60858
60859 - if (pipe->files)
60860 + if (atomic_read(&pipe->files))
60861 do_wakeup = 1;
60862 }
60863
60864 diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c
60865 index c3eb2c4..98007d4 100644
60866 --- a/fs/fuse/dir.c
60867 +++ b/fs/fuse/dir.c
60868 @@ -1408,7 +1408,7 @@ static char *read_link(struct dentry *dentry)
60869 return link;
60870 }
60871
60872 -static void free_link(char *link)
60873 +static void free_link(const char *link)
60874 {
60875 if (!IS_ERR(link))
60876 free_page((unsigned long) link);
60877 diff --git a/fs/hostfs/hostfs_kern.c b/fs/hostfs/hostfs_kern.c
60878 index db23ce1..9e6cd9d 100644
60879 --- a/fs/hostfs/hostfs_kern.c
60880 +++ b/fs/hostfs/hostfs_kern.c
60881 @@ -895,7 +895,7 @@ static void *hostfs_follow_link(struct dentry *dentry, struct nameidata *nd)
60882
60883 static void hostfs_put_link(struct dentry *dentry, struct nameidata *nd, void *cookie)
60884 {
60885 - char *s = nd_get_link(nd);
60886 + const char *s = nd_get_link(nd);
60887 if (!IS_ERR(s))
60888 __putname(s);
60889 }
60890 diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c
60891 index d19b30a..ef89c36 100644
60892 --- a/fs/hugetlbfs/inode.c
60893 +++ b/fs/hugetlbfs/inode.c
60894 @@ -152,6 +152,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
60895 struct mm_struct *mm = current->mm;
60896 struct vm_area_struct *vma;
60897 struct hstate *h = hstate_file(file);
60898 + unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
60899 struct vm_unmapped_area_info info;
60900
60901 if (len & ~huge_page_mask(h))
60902 @@ -165,17 +166,26 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
60903 return addr;
60904 }
60905
60906 +#ifdef CONFIG_PAX_RANDMMAP
60907 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
60908 +#endif
60909 +
60910 if (addr) {
60911 addr = ALIGN(addr, huge_page_size(h));
60912 vma = find_vma(mm, addr);
60913 - if (TASK_SIZE - len >= addr &&
60914 - (!vma || addr + len <= vma->vm_start))
60915 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
60916 return addr;
60917 }
60918
60919 info.flags = 0;
60920 info.length = len;
60921 info.low_limit = TASK_UNMAPPED_BASE;
60922 +
60923 +#ifdef CONFIG_PAX_RANDMMAP
60924 + if (mm->pax_flags & MF_PAX_RANDMMAP)
60925 + info.low_limit += mm->delta_mmap;
60926 +#endif
60927 +
60928 info.high_limit = TASK_SIZE;
60929 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
60930 info.align_offset = 0;
60931 @@ -908,7 +918,7 @@ static struct file_system_type hugetlbfs_fs_type = {
60932 };
60933 MODULE_ALIAS_FS("hugetlbfs");
60934
60935 -static struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
60936 +struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
60937
60938 static int can_do_hugetlb_shm(void)
60939 {
60940 diff --git a/fs/inode.c b/fs/inode.c
60941 index 4bcdad3..1883822 100644
60942 --- a/fs/inode.c
60943 +++ b/fs/inode.c
60944 @@ -841,8 +841,8 @@ unsigned int get_next_ino(void)
60945
60946 #ifdef CONFIG_SMP
60947 if (unlikely((res & (LAST_INO_BATCH-1)) == 0)) {
60948 - static atomic_t shared_last_ino;
60949 - int next = atomic_add_return(LAST_INO_BATCH, &shared_last_ino);
60950 + static atomic_unchecked_t shared_last_ino;
60951 + int next = atomic_add_return_unchecked(LAST_INO_BATCH, &shared_last_ino);
60952
60953 res = next - LAST_INO_BATCH;
60954 }
60955 diff --git a/fs/jffs2/erase.c b/fs/jffs2/erase.c
60956 index 4a6cf28..d3a29d3 100644
60957 --- a/fs/jffs2/erase.c
60958 +++ b/fs/jffs2/erase.c
60959 @@ -452,7 +452,8 @@ static void jffs2_mark_erased_block(struct jffs2_sb_info *c, struct jffs2_eraseb
60960 struct jffs2_unknown_node marker = {
60961 .magic = cpu_to_je16(JFFS2_MAGIC_BITMASK),
60962 .nodetype = cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
60963 - .totlen = cpu_to_je32(c->cleanmarker_size)
60964 + .totlen = cpu_to_je32(c->cleanmarker_size),
60965 + .hdr_crc = cpu_to_je32(0)
60966 };
60967
60968 jffs2_prealloc_raw_node_refs(c, jeb, 1);
60969 diff --git a/fs/jffs2/wbuf.c b/fs/jffs2/wbuf.c
60970 index a6597d6..41b30ec 100644
60971 --- a/fs/jffs2/wbuf.c
60972 +++ b/fs/jffs2/wbuf.c
60973 @@ -1023,7 +1023,8 @@ static const struct jffs2_unknown_node oob_cleanmarker =
60974 {
60975 .magic = constant_cpu_to_je16(JFFS2_MAGIC_BITMASK),
60976 .nodetype = constant_cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
60977 - .totlen = constant_cpu_to_je32(8)
60978 + .totlen = constant_cpu_to_je32(8),
60979 + .hdr_crc = constant_cpu_to_je32(0)
60980 };
60981
60982 /*
60983 diff --git a/fs/jfs/super.c b/fs/jfs/super.c
60984 index 6669aa2..36b033d 100644
60985 --- a/fs/jfs/super.c
60986 +++ b/fs/jfs/super.c
60987 @@ -882,7 +882,7 @@ static int __init init_jfs_fs(void)
60988
60989 jfs_inode_cachep =
60990 kmem_cache_create("jfs_ip", sizeof(struct jfs_inode_info), 0,
60991 - SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD,
60992 + SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD|SLAB_USERCOPY,
60993 init_once);
60994 if (jfs_inode_cachep == NULL)
60995 return -ENOMEM;
60996 diff --git a/fs/libfs.c b/fs/libfs.c
60997 index a184424..944ddce 100644
60998 --- a/fs/libfs.c
60999 +++ b/fs/libfs.c
61000 @@ -159,6 +159,9 @@ int dcache_readdir(struct file *file, struct dir_context *ctx)
61001
61002 for (p = q->next; p != &dentry->d_subdirs; p = p->next) {
61003 struct dentry *next = list_entry(p, struct dentry, d_u.d_child);
61004 + char d_name[sizeof(next->d_iname)];
61005 + const unsigned char *name;
61006 +
61007 spin_lock_nested(&next->d_lock, DENTRY_D_LOCK_NESTED);
61008 if (!simple_positive(next)) {
61009 spin_unlock(&next->d_lock);
61010 @@ -167,7 +170,12 @@ int dcache_readdir(struct file *file, struct dir_context *ctx)
61011
61012 spin_unlock(&next->d_lock);
61013 spin_unlock(&dentry->d_lock);
61014 - if (!dir_emit(ctx, next->d_name.name, next->d_name.len,
61015 + name = next->d_name.name;
61016 + if (name == next->d_iname) {
61017 + memcpy(d_name, name, next->d_name.len);
61018 + name = d_name;
61019 + }
61020 + if (!dir_emit(ctx, name, next->d_name.len,
61021 next->d_inode->i_ino, dt_type(next->d_inode)))
61022 return 0;
61023 spin_lock(&dentry->d_lock);
61024 @@ -999,7 +1007,7 @@ EXPORT_SYMBOL(noop_fsync);
61025 void kfree_put_link(struct dentry *dentry, struct nameidata *nd,
61026 void *cookie)
61027 {
61028 - char *s = nd_get_link(nd);
61029 + const char *s = nd_get_link(nd);
61030 if (!IS_ERR(s))
61031 kfree(s);
61032 }
61033 diff --git a/fs/lockd/clntproc.c b/fs/lockd/clntproc.c
61034 index acd3947..1f896e2 100644
61035 --- a/fs/lockd/clntproc.c
61036 +++ b/fs/lockd/clntproc.c
61037 @@ -36,11 +36,11 @@ static const struct rpc_call_ops nlmclnt_cancel_ops;
61038 /*
61039 * Cookie counter for NLM requests
61040 */
61041 -static atomic_t nlm_cookie = ATOMIC_INIT(0x1234);
61042 +static atomic_unchecked_t nlm_cookie = ATOMIC_INIT(0x1234);
61043
61044 void nlmclnt_next_cookie(struct nlm_cookie *c)
61045 {
61046 - u32 cookie = atomic_inc_return(&nlm_cookie);
61047 + u32 cookie = atomic_inc_return_unchecked(&nlm_cookie);
61048
61049 memcpy(c->data, &cookie, 4);
61050 c->len=4;
61051 diff --git a/fs/locks.c b/fs/locks.c
61052 index 92a0f0a..45a48f0 100644
61053 --- a/fs/locks.c
61054 +++ b/fs/locks.c
61055 @@ -2219,16 +2219,16 @@ void locks_remove_flock(struct file *filp)
61056 return;
61057
61058 if (filp->f_op->flock) {
61059 - struct file_lock fl = {
61060 + struct file_lock flock = {
61061 .fl_pid = current->tgid,
61062 .fl_file = filp,
61063 .fl_flags = FL_FLOCK,
61064 .fl_type = F_UNLCK,
61065 .fl_end = OFFSET_MAX,
61066 };
61067 - filp->f_op->flock(filp, F_SETLKW, &fl);
61068 - if (fl.fl_ops && fl.fl_ops->fl_release_private)
61069 - fl.fl_ops->fl_release_private(&fl);
61070 + filp->f_op->flock(filp, F_SETLKW, &flock);
61071 + if (flock.fl_ops && flock.fl_ops->fl_release_private)
61072 + flock.fl_ops->fl_release_private(&flock);
61073 }
61074
61075 spin_lock(&inode->i_lock);
61076 diff --git a/fs/mount.h b/fs/mount.h
61077 index b29e42f..5ea7fdf 100644
61078 --- a/fs/mount.h
61079 +++ b/fs/mount.h
61080 @@ -11,7 +11,7 @@ struct mnt_namespace {
61081 u64 seq; /* Sequence number to prevent loops */
61082 wait_queue_head_t poll;
61083 int event;
61084 -};
61085 +} __randomize_layout;
61086
61087 struct mnt_pcp {
61088 int mnt_count;
61089 @@ -57,7 +57,7 @@ struct mount {
61090 int mnt_expiry_mark; /* true if marked for expiry */
61091 int mnt_pinned;
61092 struct path mnt_ex_mountpoint;
61093 -};
61094 +} __randomize_layout;
61095
61096 #define MNT_NS_INTERNAL ERR_PTR(-EINVAL) /* distinct from any mnt_namespace */
61097
61098 diff --git a/fs/namei.c b/fs/namei.c
61099 index 399f637..a24748c 100644
61100 --- a/fs/namei.c
61101 +++ b/fs/namei.c
61102 @@ -319,16 +319,32 @@ int generic_permission(struct inode *inode, int mask)
61103 if (ret != -EACCES)
61104 return ret;
61105
61106 +#ifdef CONFIG_GRKERNSEC
61107 + /* we'll block if we have to log due to a denied capability use */
61108 + if (mask & MAY_NOT_BLOCK)
61109 + return -ECHILD;
61110 +#endif
61111 +
61112 if (S_ISDIR(inode->i_mode)) {
61113 /* DACs are overridable for directories */
61114 - if (inode_capable(inode, CAP_DAC_OVERRIDE))
61115 - return 0;
61116 if (!(mask & MAY_WRITE))
61117 - if (inode_capable(inode, CAP_DAC_READ_SEARCH))
61118 + if (inode_capable_nolog(inode, CAP_DAC_OVERRIDE) ||
61119 + inode_capable(inode, CAP_DAC_READ_SEARCH))
61120 return 0;
61121 + if (inode_capable(inode, CAP_DAC_OVERRIDE))
61122 + return 0;
61123 return -EACCES;
61124 }
61125 /*
61126 + * Searching includes executable on directories, else just read.
61127 + */
61128 + mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
61129 + if (mask == MAY_READ)
61130 + if (inode_capable_nolog(inode, CAP_DAC_OVERRIDE) ||
61131 + inode_capable(inode, CAP_DAC_READ_SEARCH))
61132 + return 0;
61133 +
61134 + /*
61135 * Read/write DACs are always overridable.
61136 * Executable DACs are overridable when there is
61137 * at least one exec bit set.
61138 @@ -337,14 +353,6 @@ int generic_permission(struct inode *inode, int mask)
61139 if (inode_capable(inode, CAP_DAC_OVERRIDE))
61140 return 0;
61141
61142 - /*
61143 - * Searching includes executable on directories, else just read.
61144 - */
61145 - mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
61146 - if (mask == MAY_READ)
61147 - if (inode_capable(inode, CAP_DAC_READ_SEARCH))
61148 - return 0;
61149 -
61150 return -EACCES;
61151 }
61152
61153 @@ -810,7 +818,7 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
61154 {
61155 struct dentry *dentry = link->dentry;
61156 int error;
61157 - char *s;
61158 + const char *s;
61159
61160 BUG_ON(nd->flags & LOOKUP_RCU);
61161
61162 @@ -831,6 +839,12 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
61163 if (error)
61164 goto out_put_nd_path;
61165
61166 + if (gr_handle_follow_link(dentry->d_parent->d_inode,
61167 + dentry->d_inode, dentry, nd->path.mnt)) {
61168 + error = -EACCES;
61169 + goto out_put_nd_path;
61170 + }
61171 +
61172 nd->last_type = LAST_BIND;
61173 *p = dentry->d_inode->i_op->follow_link(dentry, nd);
61174 error = PTR_ERR(*p);
61175 @@ -1579,6 +1593,8 @@ static inline int nested_symlink(struct path *path, struct nameidata *nd)
61176 if (res)
61177 break;
61178 res = walk_component(nd, path, LOOKUP_FOLLOW);
61179 + if (res >= 0 && gr_handle_symlink_owner(&link, nd->inode))
61180 + res = -EACCES;
61181 put_link(nd, &link, cookie);
61182 } while (res > 0);
61183
61184 @@ -1652,7 +1668,7 @@ EXPORT_SYMBOL(full_name_hash);
61185 static inline unsigned long hash_name(const char *name, unsigned int *hashp)
61186 {
61187 unsigned long a, b, adata, bdata, mask, hash, len;
61188 - const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
61189 + static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
61190
61191 hash = a = 0;
61192 len = -sizeof(unsigned long);
61193 @@ -1936,6 +1952,8 @@ static int path_lookupat(int dfd, const char *name,
61194 if (err)
61195 break;
61196 err = lookup_last(nd, &path);
61197 + if (!err && gr_handle_symlink_owner(&link, nd->inode))
61198 + err = -EACCES;
61199 put_link(nd, &link, cookie);
61200 }
61201 }
61202 @@ -1943,6 +1961,13 @@ static int path_lookupat(int dfd, const char *name,
61203 if (!err)
61204 err = complete_walk(nd);
61205
61206 + if (!err && !(nd->flags & LOOKUP_PARENT)) {
61207 + if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
61208 + path_put(&nd->path);
61209 + err = -ENOENT;
61210 + }
61211 + }
61212 +
61213 if (!err && nd->flags & LOOKUP_DIRECTORY) {
61214 if (!d_is_directory(nd->path.dentry)) {
61215 path_put(&nd->path);
61216 @@ -1970,8 +1995,15 @@ static int filename_lookup(int dfd, struct filename *name,
61217 retval = path_lookupat(dfd, name->name,
61218 flags | LOOKUP_REVAL, nd);
61219
61220 - if (likely(!retval))
61221 + if (likely(!retval)) {
61222 audit_inode(name, nd->path.dentry, flags & LOOKUP_PARENT);
61223 + if (name->name[0] != '/' && nd->path.dentry && nd->inode) {
61224 + if (!gr_chroot_fchdir(nd->path.dentry, nd->path.mnt)) {
61225 + path_put(&nd->path);
61226 + return -ENOENT;
61227 + }
61228 + }
61229 + }
61230 return retval;
61231 }
61232
61233 @@ -2545,6 +2577,13 @@ static int may_open(struct path *path, int acc_mode, int flag)
61234 if (flag & O_NOATIME && !inode_owner_or_capable(inode))
61235 return -EPERM;
61236
61237 + if (gr_handle_rofs_blockwrite(dentry, path->mnt, acc_mode))
61238 + return -EPERM;
61239 + if (gr_handle_rawio(inode))
61240 + return -EPERM;
61241 + if (!gr_acl_handle_open(dentry, path->mnt, acc_mode))
61242 + return -EACCES;
61243 +
61244 return 0;
61245 }
61246
61247 @@ -2776,7 +2815,7 @@ looked_up:
61248 * cleared otherwise prior to returning.
61249 */
61250 static int lookup_open(struct nameidata *nd, struct path *path,
61251 - struct file *file,
61252 + struct path *link, struct file *file,
61253 const struct open_flags *op,
61254 bool got_write, int *opened)
61255 {
61256 @@ -2811,6 +2850,17 @@ static int lookup_open(struct nameidata *nd, struct path *path,
61257 /* Negative dentry, just create the file */
61258 if (!dentry->d_inode && (op->open_flag & O_CREAT)) {
61259 umode_t mode = op->mode;
61260 +
61261 + if (link && gr_handle_symlink_owner(link, dir->d_inode)) {
61262 + error = -EACCES;
61263 + goto out_dput;
61264 + }
61265 +
61266 + if (!gr_acl_handle_creat(dentry, dir, nd->path.mnt, op->open_flag, op->acc_mode, mode)) {
61267 + error = -EACCES;
61268 + goto out_dput;
61269 + }
61270 +
61271 if (!IS_POSIXACL(dir->d_inode))
61272 mode &= ~current_umask();
61273 /*
61274 @@ -2832,6 +2882,8 @@ static int lookup_open(struct nameidata *nd, struct path *path,
61275 nd->flags & LOOKUP_EXCL);
61276 if (error)
61277 goto out_dput;
61278 + else
61279 + gr_handle_create(dentry, nd->path.mnt);
61280 }
61281 out_no_open:
61282 path->dentry = dentry;
61283 @@ -2846,7 +2898,7 @@ out_dput:
61284 /*
61285 * Handle the last step of open()
61286 */
61287 -static int do_last(struct nameidata *nd, struct path *path,
61288 +static int do_last(struct nameidata *nd, struct path *path, struct path *link,
61289 struct file *file, const struct open_flags *op,
61290 int *opened, struct filename *name)
61291 {
61292 @@ -2896,6 +2948,15 @@ static int do_last(struct nameidata *nd, struct path *path,
61293 if (error)
61294 return error;
61295
61296 + if (!gr_acl_handle_hidden_file(dir, nd->path.mnt)) {
61297 + error = -ENOENT;
61298 + goto out;
61299 + }
61300 + if (link && gr_handle_symlink_owner(link, nd->inode)) {
61301 + error = -EACCES;
61302 + goto out;
61303 + }
61304 +
61305 audit_inode(name, dir, LOOKUP_PARENT);
61306 error = -EISDIR;
61307 /* trailing slashes? */
61308 @@ -2915,7 +2976,7 @@ retry_lookup:
61309 */
61310 }
61311 mutex_lock(&dir->d_inode->i_mutex);
61312 - error = lookup_open(nd, path, file, op, got_write, opened);
61313 + error = lookup_open(nd, path, link, file, op, got_write, opened);
61314 mutex_unlock(&dir->d_inode->i_mutex);
61315
61316 if (error <= 0) {
61317 @@ -2939,11 +3000,28 @@ retry_lookup:
61318 goto finish_open_created;
61319 }
61320
61321 + if (!gr_acl_handle_hidden_file(path->dentry, nd->path.mnt)) {
61322 + error = -ENOENT;
61323 + goto exit_dput;
61324 + }
61325 + if (link && gr_handle_symlink_owner(link, path->dentry->d_inode)) {
61326 + error = -EACCES;
61327 + goto exit_dput;
61328 + }
61329 +
61330 /*
61331 * create/update audit record if it already exists.
61332 */
61333 - if (d_is_positive(path->dentry))
61334 + if (d_is_positive(path->dentry)) {
61335 + /* only check if O_CREAT is specified, all other checks need to go
61336 + into may_open */
61337 + if (gr_handle_fifo(path->dentry, path->mnt, dir, open_flag, acc_mode)) {
61338 + error = -EACCES;
61339 + goto exit_dput;
61340 + }
61341 +
61342 audit_inode(name, path->dentry, 0);
61343 + }
61344
61345 /*
61346 * If atomic_open() acquired write access it is dropped now due to
61347 @@ -2984,6 +3062,11 @@ finish_lookup:
61348 }
61349 }
61350 BUG_ON(inode != path->dentry->d_inode);
61351 + /* if we're resolving a symlink to another symlink */
61352 + if (link && gr_handle_symlink_owner(link, inode)) {
61353 + error = -EACCES;
61354 + goto out;
61355 + }
61356 return 1;
61357 }
61358
61359 @@ -2993,7 +3076,6 @@ finish_lookup:
61360 save_parent.dentry = nd->path.dentry;
61361 save_parent.mnt = mntget(path->mnt);
61362 nd->path.dentry = path->dentry;
61363 -
61364 }
61365 nd->inode = inode;
61366 /* Why this, you ask? _Now_ we might have grown LOOKUP_JUMPED... */
61367 @@ -3003,7 +3085,18 @@ finish_open:
61368 path_put(&save_parent);
61369 return error;
61370 }
61371 +
61372 + if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
61373 + error = -ENOENT;
61374 + goto out;
61375 + }
61376 + if (link && gr_handle_symlink_owner(link, nd->inode)) {
61377 + error = -EACCES;
61378 + goto out;
61379 + }
61380 +
61381 audit_inode(name, nd->path.dentry, 0);
61382 +
61383 error = -EISDIR;
61384 if ((open_flag & O_CREAT) &&
61385 (d_is_directory(nd->path.dentry) || d_is_autodir(nd->path.dentry)))
61386 @@ -3167,7 +3260,7 @@ static struct file *path_openat(int dfd, struct filename *pathname,
61387 if (unlikely(error))
61388 goto out;
61389
61390 - error = do_last(nd, &path, file, op, &opened, pathname);
61391 + error = do_last(nd, &path, NULL, file, op, &opened, pathname);
61392 while (unlikely(error > 0)) { /* trailing symlink */
61393 struct path link = path;
61394 void *cookie;
61395 @@ -3185,7 +3278,7 @@ static struct file *path_openat(int dfd, struct filename *pathname,
61396 error = follow_link(&link, nd, &cookie);
61397 if (unlikely(error))
61398 break;
61399 - error = do_last(nd, &path, file, op, &opened, pathname);
61400 + error = do_last(nd, &path, &link, file, op, &opened, pathname);
61401 put_link(nd, &link, cookie);
61402 }
61403 out:
61404 @@ -3285,9 +3378,11 @@ struct dentry *kern_path_create(int dfd, const char *pathname,
61405 goto unlock;
61406
61407 error = -EEXIST;
61408 - if (d_is_positive(dentry))
61409 + if (d_is_positive(dentry)) {
61410 + if (!gr_acl_handle_hidden_file(dentry, nd.path.mnt))
61411 + error = -ENOENT;
61412 goto fail;
61413 -
61414 + }
61415 /*
61416 * Special case - lookup gave negative, but... we had foo/bar/
61417 * From the vfs_mknod() POV we just have a negative dentry -
61418 @@ -3339,6 +3434,20 @@ struct dentry *user_path_create(int dfd, const char __user *pathname,
61419 }
61420 EXPORT_SYMBOL(user_path_create);
61421
61422 +static struct dentry *user_path_create_with_name(int dfd, const char __user *pathname, struct path *path, struct filename **to, unsigned int lookup_flags)
61423 +{
61424 + struct filename *tmp = getname(pathname);
61425 + struct dentry *res;
61426 + if (IS_ERR(tmp))
61427 + return ERR_CAST(tmp);
61428 + res = kern_path_create(dfd, tmp->name, path, lookup_flags);
61429 + if (IS_ERR(res))
61430 + putname(tmp);
61431 + else
61432 + *to = tmp;
61433 + return res;
61434 +}
61435 +
61436 int vfs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode, dev_t dev)
61437 {
61438 int error = may_create(dir, dentry);
61439 @@ -3401,6 +3510,17 @@ retry:
61440
61441 if (!IS_POSIXACL(path.dentry->d_inode))
61442 mode &= ~current_umask();
61443 +
61444 + if (gr_handle_chroot_mknod(dentry, path.mnt, mode)) {
61445 + error = -EPERM;
61446 + goto out;
61447 + }
61448 +
61449 + if (!gr_acl_handle_mknod(dentry, path.dentry, path.mnt, mode)) {
61450 + error = -EACCES;
61451 + goto out;
61452 + }
61453 +
61454 error = security_path_mknod(&path, dentry, mode, dev);
61455 if (error)
61456 goto out;
61457 @@ -3417,6 +3537,8 @@ retry:
61458 break;
61459 }
61460 out:
61461 + if (!error)
61462 + gr_handle_create(dentry, path.mnt);
61463 done_path_create(&path, dentry);
61464 if (retry_estale(error, lookup_flags)) {
61465 lookup_flags |= LOOKUP_REVAL;
61466 @@ -3469,9 +3591,16 @@ retry:
61467
61468 if (!IS_POSIXACL(path.dentry->d_inode))
61469 mode &= ~current_umask();
61470 + if (!gr_acl_handle_mkdir(dentry, path.dentry, path.mnt)) {
61471 + error = -EACCES;
61472 + goto out;
61473 + }
61474 error = security_path_mkdir(&path, dentry, mode);
61475 if (!error)
61476 error = vfs_mkdir(path.dentry->d_inode, dentry, mode);
61477 + if (!error)
61478 + gr_handle_create(dentry, path.mnt);
61479 +out:
61480 done_path_create(&path, dentry);
61481 if (retry_estale(error, lookup_flags)) {
61482 lookup_flags |= LOOKUP_REVAL;
61483 @@ -3552,6 +3681,8 @@ static long do_rmdir(int dfd, const char __user *pathname)
61484 struct filename *name;
61485 struct dentry *dentry;
61486 struct nameidata nd;
61487 + ino_t saved_ino = 0;
61488 + dev_t saved_dev = 0;
61489 unsigned int lookup_flags = 0;
61490 retry:
61491 name = user_path_parent(dfd, pathname, &nd, lookup_flags);
61492 @@ -3584,10 +3715,21 @@ retry:
61493 error = -ENOENT;
61494 goto exit3;
61495 }
61496 +
61497 + saved_ino = dentry->d_inode->i_ino;
61498 + saved_dev = gr_get_dev_from_dentry(dentry);
61499 +
61500 + if (!gr_acl_handle_rmdir(dentry, nd.path.mnt)) {
61501 + error = -EACCES;
61502 + goto exit3;
61503 + }
61504 +
61505 error = security_path_rmdir(&nd.path, dentry);
61506 if (error)
61507 goto exit3;
61508 error = vfs_rmdir(nd.path.dentry->d_inode, dentry);
61509 + if (!error && (saved_dev || saved_ino))
61510 + gr_handle_delete(saved_ino, saved_dev);
61511 exit3:
61512 dput(dentry);
61513 exit2:
61514 @@ -3677,6 +3819,8 @@ static long do_unlinkat(int dfd, const char __user *pathname)
61515 struct nameidata nd;
61516 struct inode *inode = NULL;
61517 struct inode *delegated_inode = NULL;
61518 + ino_t saved_ino = 0;
61519 + dev_t saved_dev = 0;
61520 unsigned int lookup_flags = 0;
61521 retry:
61522 name = user_path_parent(dfd, pathname, &nd, lookup_flags);
61523 @@ -3703,10 +3847,22 @@ retry_deleg:
61524 if (d_is_negative(dentry))
61525 goto slashes;
61526 ihold(inode);
61527 +
61528 + if (inode->i_nlink <= 1) {
61529 + saved_ino = inode->i_ino;
61530 + saved_dev = gr_get_dev_from_dentry(dentry);
61531 + }
61532 + if (!gr_acl_handle_unlink(dentry, nd.path.mnt)) {
61533 + error = -EACCES;
61534 + goto exit2;
61535 + }
61536 +
61537 error = security_path_unlink(&nd.path, dentry);
61538 if (error)
61539 goto exit2;
61540 error = vfs_unlink(nd.path.dentry->d_inode, dentry, &delegated_inode);
61541 + if (!error && (saved_ino || saved_dev))
61542 + gr_handle_delete(saved_ino, saved_dev);
61543 exit2:
61544 dput(dentry);
61545 }
61546 @@ -3794,9 +3950,17 @@ retry:
61547 if (IS_ERR(dentry))
61548 goto out_putname;
61549
61550 + if (!gr_acl_handle_symlink(dentry, path.dentry, path.mnt, from)) {
61551 + error = -EACCES;
61552 + goto out;
61553 + }
61554 +
61555 error = security_path_symlink(&path, dentry, from->name);
61556 if (!error)
61557 error = vfs_symlink(path.dentry->d_inode, dentry, from->name);
61558 + if (!error)
61559 + gr_handle_create(dentry, path.mnt);
61560 +out:
61561 done_path_create(&path, dentry);
61562 if (retry_estale(error, lookup_flags)) {
61563 lookup_flags |= LOOKUP_REVAL;
61564 @@ -3899,6 +4063,7 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
61565 struct dentry *new_dentry;
61566 struct path old_path, new_path;
61567 struct inode *delegated_inode = NULL;
61568 + struct filename *to = NULL;
61569 int how = 0;
61570 int error;
61571
61572 @@ -3922,7 +4087,7 @@ retry:
61573 if (error)
61574 return error;
61575
61576 - new_dentry = user_path_create(newdfd, newname, &new_path,
61577 + new_dentry = user_path_create_with_name(newdfd, newname, &new_path, &to,
61578 (how & LOOKUP_REVAL));
61579 error = PTR_ERR(new_dentry);
61580 if (IS_ERR(new_dentry))
61581 @@ -3934,11 +4099,28 @@ retry:
61582 error = may_linkat(&old_path);
61583 if (unlikely(error))
61584 goto out_dput;
61585 +
61586 + if (gr_handle_hardlink(old_path.dentry, old_path.mnt,
61587 + old_path.dentry->d_inode,
61588 + old_path.dentry->d_inode->i_mode, to)) {
61589 + error = -EACCES;
61590 + goto out_dput;
61591 + }
61592 +
61593 + if (!gr_acl_handle_link(new_dentry, new_path.dentry, new_path.mnt,
61594 + old_path.dentry, old_path.mnt, to)) {
61595 + error = -EACCES;
61596 + goto out_dput;
61597 + }
61598 +
61599 error = security_path_link(old_path.dentry, &new_path, new_dentry);
61600 if (error)
61601 goto out_dput;
61602 error = vfs_link(old_path.dentry, new_path.dentry->d_inode, new_dentry, &delegated_inode);
61603 + if (!error)
61604 + gr_handle_create(new_dentry, new_path.mnt);
61605 out_dput:
61606 + putname(to);
61607 done_path_create(&new_path, new_dentry);
61608 if (delegated_inode) {
61609 error = break_deleg_wait(&delegated_inode);
61610 @@ -4225,6 +4407,12 @@ retry_deleg:
61611 if (new_dentry == trap)
61612 goto exit5;
61613
61614 + error = gr_acl_handle_rename(new_dentry, new_dir, newnd.path.mnt,
61615 + old_dentry, old_dir->d_inode, oldnd.path.mnt,
61616 + to);
61617 + if (error)
61618 + goto exit5;
61619 +
61620 error = security_path_rename(&oldnd.path, old_dentry,
61621 &newnd.path, new_dentry);
61622 if (error)
61623 @@ -4232,6 +4420,9 @@ retry_deleg:
61624 error = vfs_rename(old_dir->d_inode, old_dentry,
61625 new_dir->d_inode, new_dentry,
61626 &delegated_inode);
61627 + if (!error)
61628 + gr_handle_rename(old_dir->d_inode, new_dir->d_inode, old_dentry,
61629 + new_dentry, oldnd.path.mnt, new_dentry->d_inode ? 1 : 0);
61630 exit5:
61631 dput(new_dentry);
61632 exit4:
61633 @@ -4268,6 +4459,8 @@ SYSCALL_DEFINE2(rename, const char __user *, oldname, const char __user *, newna
61634
61635 int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const char *link)
61636 {
61637 + char tmpbuf[64];
61638 + const char *newlink;
61639 int len;
61640
61641 len = PTR_ERR(link);
61642 @@ -4277,7 +4470,14 @@ int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const c
61643 len = strlen(link);
61644 if (len > (unsigned) buflen)
61645 len = buflen;
61646 - if (copy_to_user(buffer, link, len))
61647 +
61648 + if (len < sizeof(tmpbuf)) {
61649 + memcpy(tmpbuf, link, len);
61650 + newlink = tmpbuf;
61651 + } else
61652 + newlink = link;
61653 +
61654 + if (copy_to_user(buffer, newlink, len))
61655 len = -EFAULT;
61656 out:
61657 return len;
61658 diff --git a/fs/namespace.c b/fs/namespace.c
61659 index 6d0e54e..4c1f85e 100644
61660 --- a/fs/namespace.c
61661 +++ b/fs/namespace.c
61662 @@ -1339,6 +1339,9 @@ static int do_umount(struct mount *mnt, int flags)
61663 if (!(sb->s_flags & MS_RDONLY))
61664 retval = do_remount_sb(sb, MS_RDONLY, NULL, 0);
61665 up_write(&sb->s_umount);
61666 +
61667 + gr_log_remount(mnt->mnt_devname, retval);
61668 +
61669 return retval;
61670 }
61671
61672 @@ -1361,6 +1364,9 @@ static int do_umount(struct mount *mnt, int flags)
61673 }
61674 unlock_mount_hash();
61675 namespace_unlock();
61676 +
61677 + gr_log_unmount(mnt->mnt_devname, retval);
61678 +
61679 return retval;
61680 }
61681
61682 @@ -1380,7 +1386,7 @@ static inline bool may_mount(void)
61683 * unixes. Our API is identical to OSF/1 to avoid making a mess of AMD
61684 */
61685
61686 -SYSCALL_DEFINE2(umount, char __user *, name, int, flags)
61687 +SYSCALL_DEFINE2(umount, const char __user *, name, int, flags)
61688 {
61689 struct path path;
61690 struct mount *mnt;
61691 @@ -1422,7 +1428,7 @@ out:
61692 /*
61693 * The 2.0 compatible umount. No flags.
61694 */
61695 -SYSCALL_DEFINE1(oldumount, char __user *, name)
61696 +SYSCALL_DEFINE1(oldumount, const char __user *, name)
61697 {
61698 return sys_umount(name, 0);
61699 }
61700 @@ -2426,6 +2432,16 @@ long do_mount(const char *dev_name, const char *dir_name,
61701 MS_NOATIME | MS_NODIRATIME | MS_RELATIME| MS_KERNMOUNT |
61702 MS_STRICTATIME);
61703
61704 + if (gr_handle_rofs_mount(path.dentry, path.mnt, mnt_flags)) {
61705 + retval = -EPERM;
61706 + goto dput_out;
61707 + }
61708 +
61709 + if (gr_handle_chroot_mount(path.dentry, path.mnt, dev_name)) {
61710 + retval = -EPERM;
61711 + goto dput_out;
61712 + }
61713 +
61714 if (flags & MS_REMOUNT)
61715 retval = do_remount(&path, flags & ~MS_REMOUNT, mnt_flags,
61716 data_page);
61717 @@ -2440,6 +2456,9 @@ long do_mount(const char *dev_name, const char *dir_name,
61718 dev_name, data_page);
61719 dput_out:
61720 path_put(&path);
61721 +
61722 + gr_log_mount(dev_name, dir_name, retval);
61723 +
61724 return retval;
61725 }
61726
61727 @@ -2457,7 +2476,7 @@ static void free_mnt_ns(struct mnt_namespace *ns)
61728 * number incrementing at 10Ghz will take 12,427 years to wrap which
61729 * is effectively never, so we can ignore the possibility.
61730 */
61731 -static atomic64_t mnt_ns_seq = ATOMIC64_INIT(1);
61732 +static atomic64_unchecked_t mnt_ns_seq = ATOMIC64_INIT(1);
61733
61734 static struct mnt_namespace *alloc_mnt_ns(struct user_namespace *user_ns)
61735 {
61736 @@ -2472,7 +2491,7 @@ static struct mnt_namespace *alloc_mnt_ns(struct user_namespace *user_ns)
61737 kfree(new_ns);
61738 return ERR_PTR(ret);
61739 }
61740 - new_ns->seq = atomic64_add_return(1, &mnt_ns_seq);
61741 + new_ns->seq = atomic64_inc_return_unchecked(&mnt_ns_seq);
61742 atomic_set(&new_ns->count, 1);
61743 new_ns->root = NULL;
61744 INIT_LIST_HEAD(&new_ns->list);
61745 @@ -2482,7 +2501,7 @@ static struct mnt_namespace *alloc_mnt_ns(struct user_namespace *user_ns)
61746 return new_ns;
61747 }
61748
61749 -struct mnt_namespace *copy_mnt_ns(unsigned long flags, struct mnt_namespace *ns,
61750 +__latent_entropy struct mnt_namespace *copy_mnt_ns(unsigned long flags, struct mnt_namespace *ns,
61751 struct user_namespace *user_ns, struct fs_struct *new_fs)
61752 {
61753 struct mnt_namespace *new_ns;
61754 @@ -2603,8 +2622,8 @@ struct dentry *mount_subtree(struct vfsmount *mnt, const char *name)
61755 }
61756 EXPORT_SYMBOL(mount_subtree);
61757
61758 -SYSCALL_DEFINE5(mount, char __user *, dev_name, char __user *, dir_name,
61759 - char __user *, type, unsigned long, flags, void __user *, data)
61760 +SYSCALL_DEFINE5(mount, const char __user *, dev_name, const char __user *, dir_name,
61761 + const char __user *, type, unsigned long, flags, void __user *, data)
61762 {
61763 int ret;
61764 char *kernel_type;
61765 @@ -2717,6 +2736,11 @@ SYSCALL_DEFINE2(pivot_root, const char __user *, new_root,
61766 if (error)
61767 goto out2;
61768
61769 + if (gr_handle_chroot_pivot()) {
61770 + error = -EPERM;
61771 + goto out2;
61772 + }
61773 +
61774 get_fs_root(current->fs, &root);
61775 old_mp = lock_mount(&old);
61776 error = PTR_ERR(old_mp);
61777 @@ -2983,7 +3007,7 @@ static int mntns_install(struct nsproxy *nsproxy, void *ns)
61778 !ns_capable(current_user_ns(), CAP_SYS_ADMIN))
61779 return -EPERM;
61780
61781 - if (fs->users != 1)
61782 + if (atomic_read(&fs->users) != 1)
61783 return -EINVAL;
61784
61785 get_mnt_ns(mnt_ns);
61786 diff --git a/fs/nfs/callback_xdr.c b/fs/nfs/callback_xdr.c
61787 index f4ccfe6..a5cf064 100644
61788 --- a/fs/nfs/callback_xdr.c
61789 +++ b/fs/nfs/callback_xdr.c
61790 @@ -51,7 +51,7 @@ struct callback_op {
61791 callback_decode_arg_t decode_args;
61792 callback_encode_res_t encode_res;
61793 long res_maxsize;
61794 -};
61795 +} __do_const;
61796
61797 static struct callback_op callback_ops[];
61798
61799 diff --git a/fs/nfs/inode.c b/fs/nfs/inode.c
61800 index 5d94c02..630214f 100644
61801 --- a/fs/nfs/inode.c
61802 +++ b/fs/nfs/inode.c
61803 @@ -1153,16 +1153,16 @@ static int nfs_size_need_update(const struct inode *inode, const struct nfs_fatt
61804 return nfs_size_to_loff_t(fattr->size) > i_size_read(inode);
61805 }
61806
61807 -static atomic_long_t nfs_attr_generation_counter;
61808 +static atomic_long_unchecked_t nfs_attr_generation_counter;
61809
61810 static unsigned long nfs_read_attr_generation_counter(void)
61811 {
61812 - return atomic_long_read(&nfs_attr_generation_counter);
61813 + return atomic_long_read_unchecked(&nfs_attr_generation_counter);
61814 }
61815
61816 unsigned long nfs_inc_attr_generation_counter(void)
61817 {
61818 - return atomic_long_inc_return(&nfs_attr_generation_counter);
61819 + return atomic_long_inc_return_unchecked(&nfs_attr_generation_counter);
61820 }
61821
61822 void nfs_fattr_init(struct nfs_fattr *fattr)
61823 diff --git a/fs/nfs/nfs4proc.c b/fs/nfs/nfs4proc.c
61824 index 0e90bf0..134691e 100644
61825 --- a/fs/nfs/nfs4proc.c
61826 +++ b/fs/nfs/nfs4proc.c
61827 @@ -1070,6 +1070,7 @@ static void nfs4_opendata_free(struct kref *kref)
61828 dput(p->dentry);
61829 nfs_sb_deactive(sb);
61830 nfs_fattr_free_names(&p->f_attr);
61831 + kfree(p->f_attr.mdsthreshold);
61832 kfree(p);
61833 }
61834
61835 @@ -2246,10 +2247,12 @@ static int _nfs4_do_open(struct inode *dir,
61836 }
61837 }
61838
61839 - if (ctx_th && server->attr_bitmask[2] & FATTR4_WORD2_MDSTHRESHOLD) {
61840 - opendata->f_attr.mdsthreshold = pnfs_mdsthreshold_alloc();
61841 - if (!opendata->f_attr.mdsthreshold)
61842 - goto err_free_label;
61843 + if (server->attr_bitmask[2] & FATTR4_WORD2_MDSTHRESHOLD) {
61844 + if (!opendata->f_attr.mdsthreshold) {
61845 + opendata->f_attr.mdsthreshold = pnfs_mdsthreshold_alloc();
61846 + if (!opendata->f_attr.mdsthreshold)
61847 + goto err_free_label;
61848 + }
61849 opendata->o_arg.open_bitmap = &nfs4_pnfs_open_bitmap[0];
61850 }
61851 if (dentry->d_inode != NULL)
61852 @@ -2277,11 +2280,10 @@ static int _nfs4_do_open(struct inode *dir,
61853 if (opendata->file_created)
61854 *opened |= FILE_CREATED;
61855
61856 - if (pnfs_use_threshold(ctx_th, opendata->f_attr.mdsthreshold, server))
61857 + if (pnfs_use_threshold(ctx_th, opendata->f_attr.mdsthreshold, server)) {
61858 *ctx_th = opendata->f_attr.mdsthreshold;
61859 - else
61860 - kfree(opendata->f_attr.mdsthreshold);
61861 - opendata->f_attr.mdsthreshold = NULL;
61862 + opendata->f_attr.mdsthreshold = NULL;
61863 + }
61864
61865 nfs4_label_free(olabel);
61866
61867 @@ -2291,7 +2293,6 @@ static int _nfs4_do_open(struct inode *dir,
61868 err_free_label:
61869 nfs4_label_free(olabel);
61870 err_opendata_put:
61871 - kfree(opendata->f_attr.mdsthreshold);
61872 nfs4_opendata_put(opendata);
61873 err_put_state_owner:
61874 nfs4_put_state_owner(sp);
61875 diff --git a/fs/nfsd/nfs4proc.c b/fs/nfsd/nfs4proc.c
61876 index 419572f..5414a23 100644
61877 --- a/fs/nfsd/nfs4proc.c
61878 +++ b/fs/nfsd/nfs4proc.c
61879 @@ -1168,7 +1168,7 @@ struct nfsd4_operation {
61880 nfsd4op_rsize op_rsize_bop;
61881 stateid_getter op_get_currentstateid;
61882 stateid_setter op_set_currentstateid;
61883 -};
61884 +} __do_const;
61885
61886 static struct nfsd4_operation nfsd4_ops[];
61887
61888 diff --git a/fs/nfsd/nfs4xdr.c b/fs/nfsd/nfs4xdr.c
61889 index ee7237f..e3ae60a 100644
61890 --- a/fs/nfsd/nfs4xdr.c
61891 +++ b/fs/nfsd/nfs4xdr.c
61892 @@ -1523,7 +1523,7 @@ nfsd4_decode_notsupp(struct nfsd4_compoundargs *argp, void *p)
61893
61894 typedef __be32(*nfsd4_dec)(struct nfsd4_compoundargs *argp, void *);
61895
61896 -static nfsd4_dec nfsd4_dec_ops[] = {
61897 +static const nfsd4_dec nfsd4_dec_ops[] = {
61898 [OP_ACCESS] = (nfsd4_dec)nfsd4_decode_access,
61899 [OP_CLOSE] = (nfsd4_dec)nfsd4_decode_close,
61900 [OP_COMMIT] = (nfsd4_dec)nfsd4_decode_commit,
61901 diff --git a/fs/nfsd/nfscache.c b/fs/nfsd/nfscache.c
61902 index b6af150..f6ec5e3 100644
61903 --- a/fs/nfsd/nfscache.c
61904 +++ b/fs/nfsd/nfscache.c
61905 @@ -547,14 +547,17 @@ nfsd_cache_update(struct svc_rqst *rqstp, int cachetype, __be32 *statp)
61906 {
61907 struct svc_cacherep *rp = rqstp->rq_cacherep;
61908 struct kvec *resv = &rqstp->rq_res.head[0], *cachv;
61909 - int len;
61910 + long len;
61911 size_t bufsize = 0;
61912
61913 if (!rp)
61914 return;
61915
61916 - len = resv->iov_len - ((char*)statp - (char*)resv->iov_base);
61917 - len >>= 2;
61918 + if (statp) {
61919 + len = (char*)statp - (char*)resv->iov_base;
61920 + len = resv->iov_len - len;
61921 + len >>= 2;
61922 + }
61923
61924 /* Don't cache excessive amounts of data and XDR failures */
61925 if (!statp || len > (256 >> 2)) {
61926 diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c
61927 index 7eea63c..a35f4fb 100644
61928 --- a/fs/nfsd/vfs.c
61929 +++ b/fs/nfsd/vfs.c
61930 @@ -993,7 +993,7 @@ nfsd_vfs_read(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
61931 } else {
61932 oldfs = get_fs();
61933 set_fs(KERNEL_DS);
61934 - host_err = vfs_readv(file, (struct iovec __user *)vec, vlen, &offset);
61935 + host_err = vfs_readv(file, (struct iovec __force_user *)vec, vlen, &offset);
61936 set_fs(oldfs);
61937 }
61938
61939 @@ -1084,7 +1084,7 @@ nfsd_vfs_write(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
61940
61941 /* Write the data. */
61942 oldfs = get_fs(); set_fs(KERNEL_DS);
61943 - host_err = vfs_writev(file, (struct iovec __user *)vec, vlen, &pos);
61944 + host_err = vfs_writev(file, (struct iovec __force_user *)vec, vlen, &pos);
61945 set_fs(oldfs);
61946 if (host_err < 0)
61947 goto out_nfserr;
61948 @@ -1629,7 +1629,7 @@ nfsd_readlink(struct svc_rqst *rqstp, struct svc_fh *fhp, char *buf, int *lenp)
61949 */
61950
61951 oldfs = get_fs(); set_fs(KERNEL_DS);
61952 - host_err = inode->i_op->readlink(path.dentry, (char __user *)buf, *lenp);
61953 + host_err = inode->i_op->readlink(path.dentry, (char __force_user *)buf, *lenp);
61954 set_fs(oldfs);
61955
61956 if (host_err < 0)
61957 diff --git a/fs/nls/nls_base.c b/fs/nls/nls_base.c
61958 index fea6bd5..8ee9d81 100644
61959 --- a/fs/nls/nls_base.c
61960 +++ b/fs/nls/nls_base.c
61961 @@ -234,20 +234,22 @@ EXPORT_SYMBOL(utf16s_to_utf8s);
61962
61963 int register_nls(struct nls_table * nls)
61964 {
61965 - struct nls_table ** tmp = &tables;
61966 + struct nls_table *tmp = tables;
61967
61968 if (nls->next)
61969 return -EBUSY;
61970
61971 spin_lock(&nls_lock);
61972 - while (*tmp) {
61973 - if (nls == *tmp) {
61974 + while (tmp) {
61975 + if (nls == tmp) {
61976 spin_unlock(&nls_lock);
61977 return -EBUSY;
61978 }
61979 - tmp = &(*tmp)->next;
61980 + tmp = tmp->next;
61981 }
61982 - nls->next = tables;
61983 + pax_open_kernel();
61984 + *(struct nls_table **)&nls->next = tables;
61985 + pax_close_kernel();
61986 tables = nls;
61987 spin_unlock(&nls_lock);
61988 return 0;
61989 @@ -255,12 +257,14 @@ int register_nls(struct nls_table * nls)
61990
61991 int unregister_nls(struct nls_table * nls)
61992 {
61993 - struct nls_table ** tmp = &tables;
61994 + struct nls_table * const * tmp = &tables;
61995
61996 spin_lock(&nls_lock);
61997 while (*tmp) {
61998 if (nls == *tmp) {
61999 - *tmp = nls->next;
62000 + pax_open_kernel();
62001 + *(struct nls_table **)tmp = nls->next;
62002 + pax_close_kernel();
62003 spin_unlock(&nls_lock);
62004 return 0;
62005 }
62006 diff --git a/fs/nls/nls_euc-jp.c b/fs/nls/nls_euc-jp.c
62007 index 7424929..35f6be5 100644
62008 --- a/fs/nls/nls_euc-jp.c
62009 +++ b/fs/nls/nls_euc-jp.c
62010 @@ -561,8 +561,10 @@ static int __init init_nls_euc_jp(void)
62011 p_nls = load_nls("cp932");
62012
62013 if (p_nls) {
62014 - table.charset2upper = p_nls->charset2upper;
62015 - table.charset2lower = p_nls->charset2lower;
62016 + pax_open_kernel();
62017 + *(const unsigned char **)&table.charset2upper = p_nls->charset2upper;
62018 + *(const unsigned char **)&table.charset2lower = p_nls->charset2lower;
62019 + pax_close_kernel();
62020 return register_nls(&table);
62021 }
62022
62023 diff --git a/fs/nls/nls_koi8-ru.c b/fs/nls/nls_koi8-ru.c
62024 index e7bc1d7..06bd4bb 100644
62025 --- a/fs/nls/nls_koi8-ru.c
62026 +++ b/fs/nls/nls_koi8-ru.c
62027 @@ -63,8 +63,10 @@ static int __init init_nls_koi8_ru(void)
62028 p_nls = load_nls("koi8-u");
62029
62030 if (p_nls) {
62031 - table.charset2upper = p_nls->charset2upper;
62032 - table.charset2lower = p_nls->charset2lower;
62033 + pax_open_kernel();
62034 + *(const unsigned char **)&table.charset2upper = p_nls->charset2upper;
62035 + *(const unsigned char **)&table.charset2lower = p_nls->charset2lower;
62036 + pax_close_kernel();
62037 return register_nls(&table);
62038 }
62039
62040 diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c
62041 index 6663511..7668ca4 100644
62042 --- a/fs/notify/fanotify/fanotify_user.c
62043 +++ b/fs/notify/fanotify/fanotify_user.c
62044 @@ -253,8 +253,8 @@ static ssize_t copy_event_to_user(struct fsnotify_group *group,
62045
62046 fd = fanotify_event_metadata.fd;
62047 ret = -EFAULT;
62048 - if (copy_to_user(buf, &fanotify_event_metadata,
62049 - fanotify_event_metadata.event_len))
62050 + if (fanotify_event_metadata.event_len > sizeof fanotify_event_metadata ||
62051 + copy_to_user(buf, &fanotify_event_metadata, fanotify_event_metadata.event_len))
62052 goto out_close_fd;
62053
62054 ret = prepare_for_access_response(group, event, fd);
62055 diff --git a/fs/notify/notification.c b/fs/notify/notification.c
62056 index 7b51b05..5ea5ef6 100644
62057 --- a/fs/notify/notification.c
62058 +++ b/fs/notify/notification.c
62059 @@ -57,7 +57,7 @@ static struct kmem_cache *fsnotify_event_holder_cachep;
62060 * get set to 0 so it will never get 'freed'
62061 */
62062 static struct fsnotify_event *q_overflow_event;
62063 -static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
62064 +static atomic_unchecked_t fsnotify_sync_cookie = ATOMIC_INIT(0);
62065
62066 /**
62067 * fsnotify_get_cookie - return a unique cookie for use in synchronizing events.
62068 @@ -65,7 +65,7 @@ static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
62069 */
62070 u32 fsnotify_get_cookie(void)
62071 {
62072 - return atomic_inc_return(&fsnotify_sync_cookie);
62073 + return atomic_inc_return_unchecked(&fsnotify_sync_cookie);
62074 }
62075 EXPORT_SYMBOL_GPL(fsnotify_get_cookie);
62076
62077 diff --git a/fs/ntfs/dir.c b/fs/ntfs/dir.c
62078 index 9e38daf..5727cae 100644
62079 --- a/fs/ntfs/dir.c
62080 +++ b/fs/ntfs/dir.c
62081 @@ -1310,7 +1310,7 @@ find_next_index_buffer:
62082 ia = (INDEX_ALLOCATION*)(kaddr + (ia_pos & ~PAGE_CACHE_MASK &
62083 ~(s64)(ndir->itype.index.block_size - 1)));
62084 /* Bounds checks. */
62085 - if (unlikely((u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
62086 + if (unlikely(!kaddr || (u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
62087 ntfs_error(sb, "Out of bounds check failed. Corrupt directory "
62088 "inode 0x%lx or driver bug.", vdir->i_ino);
62089 goto err_out;
62090 diff --git a/fs/ntfs/file.c b/fs/ntfs/file.c
62091 index ea4ba9d..1e13d34 100644
62092 --- a/fs/ntfs/file.c
62093 +++ b/fs/ntfs/file.c
62094 @@ -1282,7 +1282,7 @@ static inline size_t ntfs_copy_from_user(struct page **pages,
62095 char *addr;
62096 size_t total = 0;
62097 unsigned len;
62098 - int left;
62099 + unsigned left;
62100
62101 do {
62102 len = PAGE_CACHE_SIZE - ofs;
62103 diff --git a/fs/ntfs/super.c b/fs/ntfs/super.c
62104 index 82650d5..db37dcf 100644
62105 --- a/fs/ntfs/super.c
62106 +++ b/fs/ntfs/super.c
62107 @@ -685,7 +685,7 @@ static struct buffer_head *read_ntfs_boot_sector(struct super_block *sb,
62108 if (!silent)
62109 ntfs_error(sb, "Primary boot sector is invalid.");
62110 } else if (!silent)
62111 - ntfs_error(sb, read_err_str, "primary");
62112 + ntfs_error(sb, read_err_str, "%s", "primary");
62113 if (!(NTFS_SB(sb)->on_errors & ON_ERRORS_RECOVER)) {
62114 if (bh_primary)
62115 brelse(bh_primary);
62116 @@ -701,7 +701,7 @@ static struct buffer_head *read_ntfs_boot_sector(struct super_block *sb,
62117 goto hotfix_primary_boot_sector;
62118 brelse(bh_backup);
62119 } else if (!silent)
62120 - ntfs_error(sb, read_err_str, "backup");
62121 + ntfs_error(sb, read_err_str, "%s", "backup");
62122 /* Try to read NT3.51- backup boot sector. */
62123 if ((bh_backup = sb_bread(sb, nr_blocks >> 1))) {
62124 if (is_boot_sector_ntfs(sb, (NTFS_BOOT_SECTOR*)
62125 @@ -712,7 +712,7 @@ static struct buffer_head *read_ntfs_boot_sector(struct super_block *sb,
62126 "sector.");
62127 brelse(bh_backup);
62128 } else if (!silent)
62129 - ntfs_error(sb, read_err_str, "backup");
62130 + ntfs_error(sb, read_err_str, "%s", "backup");
62131 /* We failed. Cleanup and return. */
62132 if (bh_primary)
62133 brelse(bh_primary);
62134 diff --git a/fs/ocfs2/localalloc.c b/fs/ocfs2/localalloc.c
62135 index cd5496b..26a1055 100644
62136 --- a/fs/ocfs2/localalloc.c
62137 +++ b/fs/ocfs2/localalloc.c
62138 @@ -1278,7 +1278,7 @@ static int ocfs2_local_alloc_slide_window(struct ocfs2_super *osb,
62139 goto bail;
62140 }
62141
62142 - atomic_inc(&osb->alloc_stats.moves);
62143 + atomic_inc_unchecked(&osb->alloc_stats.moves);
62144
62145 bail:
62146 if (handle)
62147 diff --git a/fs/ocfs2/ocfs2.h b/fs/ocfs2/ocfs2.h
62148 index 3a90347..c40bef8 100644
62149 --- a/fs/ocfs2/ocfs2.h
62150 +++ b/fs/ocfs2/ocfs2.h
62151 @@ -235,11 +235,11 @@ enum ocfs2_vol_state
62152
62153 struct ocfs2_alloc_stats
62154 {
62155 - atomic_t moves;
62156 - atomic_t local_data;
62157 - atomic_t bitmap_data;
62158 - atomic_t bg_allocs;
62159 - atomic_t bg_extends;
62160 + atomic_unchecked_t moves;
62161 + atomic_unchecked_t local_data;
62162 + atomic_unchecked_t bitmap_data;
62163 + atomic_unchecked_t bg_allocs;
62164 + atomic_unchecked_t bg_extends;
62165 };
62166
62167 enum ocfs2_local_alloc_state
62168 diff --git a/fs/ocfs2/suballoc.c b/fs/ocfs2/suballoc.c
62169 index 2c91452..77a3cd2 100644
62170 --- a/fs/ocfs2/suballoc.c
62171 +++ b/fs/ocfs2/suballoc.c
62172 @@ -872,7 +872,7 @@ static int ocfs2_reserve_suballoc_bits(struct ocfs2_super *osb,
62173 mlog_errno(status);
62174 goto bail;
62175 }
62176 - atomic_inc(&osb->alloc_stats.bg_extends);
62177 + atomic_inc_unchecked(&osb->alloc_stats.bg_extends);
62178
62179 /* You should never ask for this much metadata */
62180 BUG_ON(bits_wanted >
62181 @@ -2000,7 +2000,7 @@ int ocfs2_claim_metadata(handle_t *handle,
62182 mlog_errno(status);
62183 goto bail;
62184 }
62185 - atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
62186 + atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
62187
62188 *suballoc_loc = res.sr_bg_blkno;
62189 *suballoc_bit_start = res.sr_bit_offset;
62190 @@ -2164,7 +2164,7 @@ int ocfs2_claim_new_inode_at_loc(handle_t *handle,
62191 trace_ocfs2_claim_new_inode_at_loc((unsigned long long)di_blkno,
62192 res->sr_bits);
62193
62194 - atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
62195 + atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
62196
62197 BUG_ON(res->sr_bits != 1);
62198
62199 @@ -2206,7 +2206,7 @@ int ocfs2_claim_new_inode(handle_t *handle,
62200 mlog_errno(status);
62201 goto bail;
62202 }
62203 - atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
62204 + atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
62205
62206 BUG_ON(res.sr_bits != 1);
62207
62208 @@ -2310,7 +2310,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
62209 cluster_start,
62210 num_clusters);
62211 if (!status)
62212 - atomic_inc(&osb->alloc_stats.local_data);
62213 + atomic_inc_unchecked(&osb->alloc_stats.local_data);
62214 } else {
62215 if (min_clusters > (osb->bitmap_cpg - 1)) {
62216 /* The only paths asking for contiguousness
62217 @@ -2336,7 +2336,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
62218 ocfs2_desc_bitmap_to_cluster_off(ac->ac_inode,
62219 res.sr_bg_blkno,
62220 res.sr_bit_offset);
62221 - atomic_inc(&osb->alloc_stats.bitmap_data);
62222 + atomic_inc_unchecked(&osb->alloc_stats.bitmap_data);
62223 *num_clusters = res.sr_bits;
62224 }
62225 }
62226 diff --git a/fs/ocfs2/super.c b/fs/ocfs2/super.c
62227 index c414929..5c9ee542 100644
62228 --- a/fs/ocfs2/super.c
62229 +++ b/fs/ocfs2/super.c
62230 @@ -300,11 +300,11 @@ static int ocfs2_osb_dump(struct ocfs2_super *osb, char *buf, int len)
62231 "%10s => GlobalAllocs: %d LocalAllocs: %d "
62232 "SubAllocs: %d LAWinMoves: %d SAExtends: %d\n",
62233 "Stats",
62234 - atomic_read(&osb->alloc_stats.bitmap_data),
62235 - atomic_read(&osb->alloc_stats.local_data),
62236 - atomic_read(&osb->alloc_stats.bg_allocs),
62237 - atomic_read(&osb->alloc_stats.moves),
62238 - atomic_read(&osb->alloc_stats.bg_extends));
62239 + atomic_read_unchecked(&osb->alloc_stats.bitmap_data),
62240 + atomic_read_unchecked(&osb->alloc_stats.local_data),
62241 + atomic_read_unchecked(&osb->alloc_stats.bg_allocs),
62242 + atomic_read_unchecked(&osb->alloc_stats.moves),
62243 + atomic_read_unchecked(&osb->alloc_stats.bg_extends));
62244
62245 out += snprintf(buf + out, len - out,
62246 "%10s => State: %u Descriptor: %llu Size: %u bits "
62247 @@ -2121,11 +2121,11 @@ static int ocfs2_initialize_super(struct super_block *sb,
62248 spin_lock_init(&osb->osb_xattr_lock);
62249 ocfs2_init_steal_slots(osb);
62250
62251 - atomic_set(&osb->alloc_stats.moves, 0);
62252 - atomic_set(&osb->alloc_stats.local_data, 0);
62253 - atomic_set(&osb->alloc_stats.bitmap_data, 0);
62254 - atomic_set(&osb->alloc_stats.bg_allocs, 0);
62255 - atomic_set(&osb->alloc_stats.bg_extends, 0);
62256 + atomic_set_unchecked(&osb->alloc_stats.moves, 0);
62257 + atomic_set_unchecked(&osb->alloc_stats.local_data, 0);
62258 + atomic_set_unchecked(&osb->alloc_stats.bitmap_data, 0);
62259 + atomic_set_unchecked(&osb->alloc_stats.bg_allocs, 0);
62260 + atomic_set_unchecked(&osb->alloc_stats.bg_extends, 0);
62261
62262 /* Copy the blockcheck stats from the superblock probe */
62263 osb->osb_ecc_stats = *stats;
62264 diff --git a/fs/open.c b/fs/open.c
62265 index 4b3e1ed..1c84599 100644
62266 --- a/fs/open.c
62267 +++ b/fs/open.c
62268 @@ -32,6 +32,8 @@
62269 #include <linux/dnotify.h>
62270 #include <linux/compat.h>
62271
62272 +#define CREATE_TRACE_POINTS
62273 +#include <trace/events/fs.h>
62274 #include "internal.h"
62275
62276 int do_truncate(struct dentry *dentry, loff_t length, unsigned int time_attrs,
62277 @@ -103,6 +105,8 @@ long vfs_truncate(struct path *path, loff_t length)
62278 error = locks_verify_truncate(inode, NULL, length);
62279 if (!error)
62280 error = security_path_truncate(path);
62281 + if (!error && !gr_acl_handle_truncate(path->dentry, path->mnt))
62282 + error = -EACCES;
62283 if (!error)
62284 error = do_truncate(path->dentry, length, 0, NULL);
62285
62286 @@ -187,6 +191,8 @@ static long do_sys_ftruncate(unsigned int fd, loff_t length, int small)
62287 error = locks_verify_truncate(inode, f.file, length);
62288 if (!error)
62289 error = security_path_truncate(&f.file->f_path);
62290 + if (!error && !gr_acl_handle_truncate(f.file->f_path.dentry, f.file->f_path.mnt))
62291 + error = -EACCES;
62292 if (!error)
62293 error = do_truncate(dentry, length, ATTR_MTIME|ATTR_CTIME, f.file);
62294 sb_end_write(inode->i_sb);
62295 @@ -361,6 +367,9 @@ retry:
62296 if (__mnt_is_readonly(path.mnt))
62297 res = -EROFS;
62298
62299 + if (!res && !gr_acl_handle_access(path.dentry, path.mnt, mode))
62300 + res = -EACCES;
62301 +
62302 out_path_release:
62303 path_put(&path);
62304 if (retry_estale(res, lookup_flags)) {
62305 @@ -392,6 +401,8 @@ retry:
62306 if (error)
62307 goto dput_and_out;
62308
62309 + gr_log_chdir(path.dentry, path.mnt);
62310 +
62311 set_fs_pwd(current->fs, &path);
62312
62313 dput_and_out:
62314 @@ -421,6 +432,13 @@ SYSCALL_DEFINE1(fchdir, unsigned int, fd)
62315 goto out_putf;
62316
62317 error = inode_permission(inode, MAY_EXEC | MAY_CHDIR);
62318 +
62319 + if (!error && !gr_chroot_fchdir(f.file->f_path.dentry, f.file->f_path.mnt))
62320 + error = -EPERM;
62321 +
62322 + if (!error)
62323 + gr_log_chdir(f.file->f_path.dentry, f.file->f_path.mnt);
62324 +
62325 if (!error)
62326 set_fs_pwd(current->fs, &f.file->f_path);
62327 out_putf:
62328 @@ -450,7 +468,13 @@ retry:
62329 if (error)
62330 goto dput_and_out;
62331
62332 + if (gr_handle_chroot_chroot(path.dentry, path.mnt))
62333 + goto dput_and_out;
62334 +
62335 set_fs_root(current->fs, &path);
62336 +
62337 + gr_handle_chroot_chdir(&path);
62338 +
62339 error = 0;
62340 dput_and_out:
62341 path_put(&path);
62342 @@ -474,6 +498,16 @@ static int chmod_common(struct path *path, umode_t mode)
62343 return error;
62344 retry_deleg:
62345 mutex_lock(&inode->i_mutex);
62346 +
62347 + if (!gr_acl_handle_chmod(path->dentry, path->mnt, &mode)) {
62348 + error = -EACCES;
62349 + goto out_unlock;
62350 + }
62351 + if (gr_handle_chroot_chmod(path->dentry, path->mnt, mode)) {
62352 + error = -EACCES;
62353 + goto out_unlock;
62354 + }
62355 +
62356 error = security_path_chmod(path, mode);
62357 if (error)
62358 goto out_unlock;
62359 @@ -539,6 +573,9 @@ static int chown_common(struct path *path, uid_t user, gid_t group)
62360 uid = make_kuid(current_user_ns(), user);
62361 gid = make_kgid(current_user_ns(), group);
62362
62363 + if (!gr_acl_handle_chown(path->dentry, path->mnt))
62364 + return -EACCES;
62365 +
62366 newattrs.ia_valid = ATTR_CTIME;
62367 if (user != (uid_t) -1) {
62368 if (!uid_valid(uid))
62369 @@ -990,6 +1027,7 @@ long do_sys_open(int dfd, const char __user *filename, int flags, umode_t mode)
62370 } else {
62371 fsnotify_open(f);
62372 fd_install(fd, f);
62373 + trace_do_sys_open(tmp->name, flags, mode);
62374 }
62375 }
62376 putname(tmp);
62377 diff --git a/fs/pipe.c b/fs/pipe.c
62378 index 0e0752e..7cfdd50 100644
62379 --- a/fs/pipe.c
62380 +++ b/fs/pipe.c
62381 @@ -56,7 +56,7 @@ unsigned int pipe_min_size = PAGE_SIZE;
62382
62383 static void pipe_lock_nested(struct pipe_inode_info *pipe, int subclass)
62384 {
62385 - if (pipe->files)
62386 + if (atomic_read(&pipe->files))
62387 mutex_lock_nested(&pipe->mutex, subclass);
62388 }
62389
62390 @@ -71,7 +71,7 @@ EXPORT_SYMBOL(pipe_lock);
62391
62392 void pipe_unlock(struct pipe_inode_info *pipe)
62393 {
62394 - if (pipe->files)
62395 + if (atomic_read(&pipe->files))
62396 mutex_unlock(&pipe->mutex);
62397 }
62398 EXPORT_SYMBOL(pipe_unlock);
62399 @@ -449,9 +449,9 @@ redo:
62400 }
62401 if (bufs) /* More to do? */
62402 continue;
62403 - if (!pipe->writers)
62404 + if (!atomic_read(&pipe->writers))
62405 break;
62406 - if (!pipe->waiting_writers) {
62407 + if (!atomic_read(&pipe->waiting_writers)) {
62408 /* syscall merging: Usually we must not sleep
62409 * if O_NONBLOCK is set, or if we got some data.
62410 * But if a writer sleeps in kernel space, then
62411 @@ -513,7 +513,7 @@ pipe_write(struct kiocb *iocb, const struct iovec *_iov,
62412 ret = 0;
62413 __pipe_lock(pipe);
62414
62415 - if (!pipe->readers) {
62416 + if (!atomic_read(&pipe->readers)) {
62417 send_sig(SIGPIPE, current, 0);
62418 ret = -EPIPE;
62419 goto out;
62420 @@ -562,7 +562,7 @@ redo1:
62421 for (;;) {
62422 int bufs;
62423
62424 - if (!pipe->readers) {
62425 + if (!atomic_read(&pipe->readers)) {
62426 send_sig(SIGPIPE, current, 0);
62427 if (!ret)
62428 ret = -EPIPE;
62429 @@ -653,9 +653,9 @@ redo2:
62430 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
62431 do_wakeup = 0;
62432 }
62433 - pipe->waiting_writers++;
62434 + atomic_inc(&pipe->waiting_writers);
62435 pipe_wait(pipe);
62436 - pipe->waiting_writers--;
62437 + atomic_dec(&pipe->waiting_writers);
62438 }
62439 out:
62440 __pipe_unlock(pipe);
62441 @@ -709,7 +709,7 @@ pipe_poll(struct file *filp, poll_table *wait)
62442 mask = 0;
62443 if (filp->f_mode & FMODE_READ) {
62444 mask = (nrbufs > 0) ? POLLIN | POLLRDNORM : 0;
62445 - if (!pipe->writers && filp->f_version != pipe->w_counter)
62446 + if (!atomic_read(&pipe->writers) && filp->f_version != pipe->w_counter)
62447 mask |= POLLHUP;
62448 }
62449
62450 @@ -719,7 +719,7 @@ pipe_poll(struct file *filp, poll_table *wait)
62451 * Most Unices do not set POLLERR for FIFOs but on Linux they
62452 * behave exactly like pipes for poll().
62453 */
62454 - if (!pipe->readers)
62455 + if (!atomic_read(&pipe->readers))
62456 mask |= POLLERR;
62457 }
62458
62459 @@ -731,7 +731,7 @@ static void put_pipe_info(struct inode *inode, struct pipe_inode_info *pipe)
62460 int kill = 0;
62461
62462 spin_lock(&inode->i_lock);
62463 - if (!--pipe->files) {
62464 + if (atomic_dec_and_test(&pipe->files)) {
62465 inode->i_pipe = NULL;
62466 kill = 1;
62467 }
62468 @@ -748,11 +748,11 @@ pipe_release(struct inode *inode, struct file *file)
62469
62470 __pipe_lock(pipe);
62471 if (file->f_mode & FMODE_READ)
62472 - pipe->readers--;
62473 + atomic_dec(&pipe->readers);
62474 if (file->f_mode & FMODE_WRITE)
62475 - pipe->writers--;
62476 + atomic_dec(&pipe->writers);
62477
62478 - if (pipe->readers || pipe->writers) {
62479 + if (atomic_read(&pipe->readers) || atomic_read(&pipe->writers)) {
62480 wake_up_interruptible_sync_poll(&pipe->wait, POLLIN | POLLOUT | POLLRDNORM | POLLWRNORM | POLLERR | POLLHUP);
62481 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
62482 kill_fasync(&pipe->fasync_writers, SIGIO, POLL_OUT);
62483 @@ -817,7 +817,7 @@ void free_pipe_info(struct pipe_inode_info *pipe)
62484 kfree(pipe);
62485 }
62486
62487 -static struct vfsmount *pipe_mnt __read_mostly;
62488 +struct vfsmount *pipe_mnt __read_mostly;
62489
62490 /*
62491 * pipefs_dname() is called from d_path().
62492 @@ -847,8 +847,9 @@ static struct inode * get_pipe_inode(void)
62493 goto fail_iput;
62494
62495 inode->i_pipe = pipe;
62496 - pipe->files = 2;
62497 - pipe->readers = pipe->writers = 1;
62498 + atomic_set(&pipe->files, 2);
62499 + atomic_set(&pipe->readers, 1);
62500 + atomic_set(&pipe->writers, 1);
62501 inode->i_fop = &pipefifo_fops;
62502
62503 /*
62504 @@ -1027,17 +1028,17 @@ static int fifo_open(struct inode *inode, struct file *filp)
62505 spin_lock(&inode->i_lock);
62506 if (inode->i_pipe) {
62507 pipe = inode->i_pipe;
62508 - pipe->files++;
62509 + atomic_inc(&pipe->files);
62510 spin_unlock(&inode->i_lock);
62511 } else {
62512 spin_unlock(&inode->i_lock);
62513 pipe = alloc_pipe_info();
62514 if (!pipe)
62515 return -ENOMEM;
62516 - pipe->files = 1;
62517 + atomic_set(&pipe->files, 1);
62518 spin_lock(&inode->i_lock);
62519 if (unlikely(inode->i_pipe)) {
62520 - inode->i_pipe->files++;
62521 + atomic_inc(&inode->i_pipe->files);
62522 spin_unlock(&inode->i_lock);
62523 free_pipe_info(pipe);
62524 pipe = inode->i_pipe;
62525 @@ -1062,10 +1063,10 @@ static int fifo_open(struct inode *inode, struct file *filp)
62526 * opened, even when there is no process writing the FIFO.
62527 */
62528 pipe->r_counter++;
62529 - if (pipe->readers++ == 0)
62530 + if (atomic_inc_return(&pipe->readers) == 1)
62531 wake_up_partner(pipe);
62532
62533 - if (!is_pipe && !pipe->writers) {
62534 + if (!is_pipe && !atomic_read(&pipe->writers)) {
62535 if ((filp->f_flags & O_NONBLOCK)) {
62536 /* suppress POLLHUP until we have
62537 * seen a writer */
62538 @@ -1084,14 +1085,14 @@ static int fifo_open(struct inode *inode, struct file *filp)
62539 * errno=ENXIO when there is no process reading the FIFO.
62540 */
62541 ret = -ENXIO;
62542 - if (!is_pipe && (filp->f_flags & O_NONBLOCK) && !pipe->readers)
62543 + if (!is_pipe && (filp->f_flags & O_NONBLOCK) && !atomic_read(&pipe->readers))
62544 goto err;
62545
62546 pipe->w_counter++;
62547 - if (!pipe->writers++)
62548 + if (atomic_inc_return(&pipe->writers) == 1)
62549 wake_up_partner(pipe);
62550
62551 - if (!is_pipe && !pipe->readers) {
62552 + if (!is_pipe && !atomic_read(&pipe->readers)) {
62553 if (wait_for_partner(pipe, &pipe->r_counter))
62554 goto err_wr;
62555 }
62556 @@ -1105,11 +1106,11 @@ static int fifo_open(struct inode *inode, struct file *filp)
62557 * the process can at least talk to itself.
62558 */
62559
62560 - pipe->readers++;
62561 - pipe->writers++;
62562 + atomic_inc(&pipe->readers);
62563 + atomic_inc(&pipe->writers);
62564 pipe->r_counter++;
62565 pipe->w_counter++;
62566 - if (pipe->readers == 1 || pipe->writers == 1)
62567 + if (atomic_read(&pipe->readers) == 1 || atomic_read(&pipe->writers) == 1)
62568 wake_up_partner(pipe);
62569 break;
62570
62571 @@ -1123,13 +1124,13 @@ static int fifo_open(struct inode *inode, struct file *filp)
62572 return 0;
62573
62574 err_rd:
62575 - if (!--pipe->readers)
62576 + if (atomic_dec_and_test(&pipe->readers))
62577 wake_up_interruptible(&pipe->wait);
62578 ret = -ERESTARTSYS;
62579 goto err;
62580
62581 err_wr:
62582 - if (!--pipe->writers)
62583 + if (atomic_dec_and_test(&pipe->writers))
62584 wake_up_interruptible(&pipe->wait);
62585 ret = -ERESTARTSYS;
62586 goto err;
62587 diff --git a/fs/posix_acl.c b/fs/posix_acl.c
62588 index 8bd2135..eab9adb 100644
62589 --- a/fs/posix_acl.c
62590 +++ b/fs/posix_acl.c
62591 @@ -19,6 +19,7 @@
62592 #include <linux/sched.h>
62593 #include <linux/posix_acl.h>
62594 #include <linux/export.h>
62595 +#include <linux/grsecurity.h>
62596
62597 #include <linux/errno.h>
62598
62599 @@ -183,7 +184,7 @@ posix_acl_equiv_mode(const struct posix_acl *acl, umode_t *mode_p)
62600 }
62601 }
62602 if (mode_p)
62603 - *mode_p = (*mode_p & ~S_IRWXUGO) | mode;
62604 + *mode_p = ((*mode_p & ~S_IRWXUGO) | mode) & ~gr_acl_umask();
62605 return not_equiv;
62606 }
62607
62608 @@ -331,7 +332,7 @@ static int posix_acl_create_masq(struct posix_acl *acl, umode_t *mode_p)
62609 mode &= (group_obj->e_perm << 3) | ~S_IRWXG;
62610 }
62611
62612 - *mode_p = (*mode_p & ~S_IRWXUGO) | mode;
62613 + *mode_p = ((*mode_p & ~S_IRWXUGO) | mode) & ~gr_acl_umask();
62614 return not_equiv;
62615 }
62616
62617 @@ -389,6 +390,8 @@ posix_acl_create(struct posix_acl **acl, gfp_t gfp, umode_t *mode_p)
62618 struct posix_acl *clone = posix_acl_clone(*acl, gfp);
62619 int err = -ENOMEM;
62620 if (clone) {
62621 + *mode_p &= ~gr_acl_umask();
62622 +
62623 err = posix_acl_create_masq(clone, mode_p);
62624 if (err < 0) {
62625 posix_acl_release(clone);
62626 diff --git a/fs/proc/Kconfig b/fs/proc/Kconfig
62627 index 2183fcf..3c32a98 100644
62628 --- a/fs/proc/Kconfig
62629 +++ b/fs/proc/Kconfig
62630 @@ -30,7 +30,7 @@ config PROC_FS
62631
62632 config PROC_KCORE
62633 bool "/proc/kcore support" if !ARM
62634 - depends on PROC_FS && MMU
62635 + depends on PROC_FS && MMU && !GRKERNSEC_PROC_ADD
62636 help
62637 Provides a virtual ELF core file of the live kernel. This can
62638 be read with gdb and other ELF tools. No modifications can be
62639 @@ -38,8 +38,8 @@ config PROC_KCORE
62640
62641 config PROC_VMCORE
62642 bool "/proc/vmcore support"
62643 - depends on PROC_FS && CRASH_DUMP
62644 - default y
62645 + depends on PROC_FS && CRASH_DUMP && !GRKERNSEC
62646 + default n
62647 help
62648 Exports the dump image of crashed kernel in ELF format.
62649
62650 @@ -63,8 +63,8 @@ config PROC_SYSCTL
62651 limited in memory.
62652
62653 config PROC_PAGE_MONITOR
62654 - default y
62655 - depends on PROC_FS && MMU
62656 + default n
62657 + depends on PROC_FS && MMU && !GRKERNSEC
62658 bool "Enable /proc page monitoring" if EXPERT
62659 help
62660 Various /proc files exist to monitor process memory utilization:
62661 diff --git a/fs/proc/array.c b/fs/proc/array.c
62662 index 1bd2077..2f7cfd5 100644
62663 --- a/fs/proc/array.c
62664 +++ b/fs/proc/array.c
62665 @@ -60,6 +60,7 @@
62666 #include <linux/tty.h>
62667 #include <linux/string.h>
62668 #include <linux/mman.h>
62669 +#include <linux/grsecurity.h>
62670 #include <linux/proc_fs.h>
62671 #include <linux/ioport.h>
62672 #include <linux/uaccess.h>
62673 @@ -365,6 +366,21 @@ static void task_cpus_allowed(struct seq_file *m, struct task_struct *task)
62674 seq_putc(m, '\n');
62675 }
62676
62677 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
62678 +static inline void task_pax(struct seq_file *m, struct task_struct *p)
62679 +{
62680 + if (p->mm)
62681 + seq_printf(m, "PaX:\t%c%c%c%c%c\n",
62682 + p->mm->pax_flags & MF_PAX_PAGEEXEC ? 'P' : 'p',
62683 + p->mm->pax_flags & MF_PAX_EMUTRAMP ? 'E' : 'e',
62684 + p->mm->pax_flags & MF_PAX_MPROTECT ? 'M' : 'm',
62685 + p->mm->pax_flags & MF_PAX_RANDMMAP ? 'R' : 'r',
62686 + p->mm->pax_flags & MF_PAX_SEGMEXEC ? 'S' : 's');
62687 + else
62688 + seq_printf(m, "PaX:\t-----\n");
62689 +}
62690 +#endif
62691 +
62692 int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
62693 struct pid *pid, struct task_struct *task)
62694 {
62695 @@ -383,9 +399,24 @@ int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
62696 task_cpus_allowed(m, task);
62697 cpuset_task_status_allowed(m, task);
62698 task_context_switch_counts(m, task);
62699 +
62700 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
62701 + task_pax(m, task);
62702 +#endif
62703 +
62704 +#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
62705 + task_grsec_rbac(m, task);
62706 +#endif
62707 +
62708 return 0;
62709 }
62710
62711 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
62712 +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
62713 + (_mm->pax_flags & MF_PAX_RANDMMAP || \
62714 + _mm->pax_flags & MF_PAX_SEGMEXEC))
62715 +#endif
62716 +
62717 static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
62718 struct pid *pid, struct task_struct *task, int whole)
62719 {
62720 @@ -407,6 +438,13 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
62721 char tcomm[sizeof(task->comm)];
62722 unsigned long flags;
62723
62724 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
62725 + if (current->exec_id != m->exec_id) {
62726 + gr_log_badprocpid("stat");
62727 + return 0;
62728 + }
62729 +#endif
62730 +
62731 state = *get_task_state(task);
62732 vsize = eip = esp = 0;
62733 permitted = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
62734 @@ -478,6 +516,19 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
62735 gtime = task_gtime(task);
62736 }
62737
62738 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
62739 + if (PAX_RAND_FLAGS(mm)) {
62740 + eip = 0;
62741 + esp = 0;
62742 + wchan = 0;
62743 + }
62744 +#endif
62745 +#ifdef CONFIG_GRKERNSEC_HIDESYM
62746 + wchan = 0;
62747 + eip =0;
62748 + esp =0;
62749 +#endif
62750 +
62751 /* scale priority and nice values from timeslices to -20..20 */
62752 /* to make it look like a "normal" Unix priority/nice value */
62753 priority = task_prio(task);
62754 @@ -514,9 +565,15 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
62755 seq_put_decimal_ull(m, ' ', vsize);
62756 seq_put_decimal_ull(m, ' ', mm ? get_mm_rss(mm) : 0);
62757 seq_put_decimal_ull(m, ' ', rsslim);
62758 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
62759 + seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->start_code : 1) : 0));
62760 + seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->end_code : 1) : 0));
62761 + seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 0 : ((permitted && mm) ? mm->start_stack : 0));
62762 +#else
62763 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->start_code : 1) : 0);
62764 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->end_code : 1) : 0);
62765 seq_put_decimal_ull(m, ' ', (permitted && mm) ? mm->start_stack : 0);
62766 +#endif
62767 seq_put_decimal_ull(m, ' ', esp);
62768 seq_put_decimal_ull(m, ' ', eip);
62769 /* The signal information here is obsolete.
62770 @@ -538,7 +595,11 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
62771 seq_put_decimal_ull(m, ' ', cputime_to_clock_t(gtime));
62772 seq_put_decimal_ll(m, ' ', cputime_to_clock_t(cgtime));
62773
62774 - if (mm && permitted) {
62775 + if (mm && permitted
62776 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
62777 + && !PAX_RAND_FLAGS(mm)
62778 +#endif
62779 + ) {
62780 seq_put_decimal_ull(m, ' ', mm->start_data);
62781 seq_put_decimal_ull(m, ' ', mm->end_data);
62782 seq_put_decimal_ull(m, ' ', mm->start_brk);
62783 @@ -576,8 +637,15 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
62784 struct pid *pid, struct task_struct *task)
62785 {
62786 unsigned long size = 0, resident = 0, shared = 0, text = 0, data = 0;
62787 - struct mm_struct *mm = get_task_mm(task);
62788 + struct mm_struct *mm;
62789
62790 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
62791 + if (current->exec_id != m->exec_id) {
62792 + gr_log_badprocpid("statm");
62793 + return 0;
62794 + }
62795 +#endif
62796 + mm = get_task_mm(task);
62797 if (mm) {
62798 size = task_statm(mm, &shared, &text, &data, &resident);
62799 mmput(mm);
62800 @@ -600,6 +668,13 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
62801 return 0;
62802 }
62803
62804 +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
62805 +int proc_pid_ipaddr(struct task_struct *task, char *buffer)
62806 +{
62807 + return sprintf(buffer, "%pI4\n", &task->signal->curr_ip);
62808 +}
62809 +#endif
62810 +
62811 #ifdef CONFIG_CHECKPOINT_RESTORE
62812 static struct pid *
62813 get_children_pid(struct inode *inode, struct pid *pid_prev, loff_t pos)
62814 diff --git a/fs/proc/base.c b/fs/proc/base.c
62815 index b59a34b..68a79e8 100644
62816 --- a/fs/proc/base.c
62817 +++ b/fs/proc/base.c
62818 @@ -113,6 +113,14 @@ struct pid_entry {
62819 union proc_op op;
62820 };
62821
62822 +struct getdents_callback {
62823 + struct linux_dirent __user * current_dir;
62824 + struct linux_dirent __user * previous;
62825 + struct file * file;
62826 + int count;
62827 + int error;
62828 +};
62829 +
62830 #define NOD(NAME, MODE, IOP, FOP, OP) { \
62831 .name = (NAME), \
62832 .len = sizeof(NAME) - 1, \
62833 @@ -210,6 +218,9 @@ static int proc_pid_cmdline(struct task_struct *task, char * buffer)
62834 if (!mm->arg_end)
62835 goto out_mm; /* Shh! No looking before we're done */
62836
62837 + if (gr_acl_handle_procpidmem(task))
62838 + goto out_mm;
62839 +
62840 len = mm->arg_end - mm->arg_start;
62841
62842 if (len > PAGE_SIZE)
62843 @@ -237,12 +248,28 @@ out:
62844 return res;
62845 }
62846
62847 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
62848 +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
62849 + (_mm->pax_flags & MF_PAX_RANDMMAP || \
62850 + _mm->pax_flags & MF_PAX_SEGMEXEC))
62851 +#endif
62852 +
62853 static int proc_pid_auxv(struct task_struct *task, char *buffer)
62854 {
62855 struct mm_struct *mm = mm_access(task, PTRACE_MODE_READ);
62856 int res = PTR_ERR(mm);
62857 if (mm && !IS_ERR(mm)) {
62858 unsigned int nwords = 0;
62859 +
62860 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
62861 + /* allow if we're currently ptracing this task */
62862 + if (PAX_RAND_FLAGS(mm) &&
62863 + (!(task->ptrace & PT_PTRACED) || (task->parent != current))) {
62864 + mmput(mm);
62865 + return 0;
62866 + }
62867 +#endif
62868 +
62869 do {
62870 nwords += 2;
62871 } while (mm->saved_auxv[nwords - 2] != 0); /* AT_NULL */
62872 @@ -256,7 +283,7 @@ static int proc_pid_auxv(struct task_struct *task, char *buffer)
62873 }
62874
62875
62876 -#ifdef CONFIG_KALLSYMS
62877 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
62878 /*
62879 * Provides a wchan file via kallsyms in a proper one-value-per-file format.
62880 * Returns the resolved symbol. If that fails, simply return the address.
62881 @@ -295,7 +322,7 @@ static void unlock_trace(struct task_struct *task)
62882 mutex_unlock(&task->signal->cred_guard_mutex);
62883 }
62884
62885 -#ifdef CONFIG_STACKTRACE
62886 +#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
62887
62888 #define MAX_STACK_TRACE_DEPTH 64
62889
62890 @@ -518,7 +545,7 @@ static int proc_pid_limits(struct task_struct *task, char *buffer)
62891 return count;
62892 }
62893
62894 -#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
62895 +#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
62896 static int proc_pid_syscall(struct task_struct *task, char *buffer)
62897 {
62898 long nr;
62899 @@ -547,7 +574,7 @@ static int proc_pid_syscall(struct task_struct *task, char *buffer)
62900 /************************************************************************/
62901
62902 /* permission checks */
62903 -static int proc_fd_access_allowed(struct inode *inode)
62904 +static int proc_fd_access_allowed(struct inode *inode, unsigned int log)
62905 {
62906 struct task_struct *task;
62907 int allowed = 0;
62908 @@ -557,7 +584,10 @@ static int proc_fd_access_allowed(struct inode *inode)
62909 */
62910 task = get_proc_task(inode);
62911 if (task) {
62912 - allowed = ptrace_may_access(task, PTRACE_MODE_READ);
62913 + if (log)
62914 + allowed = ptrace_may_access(task, PTRACE_MODE_READ);
62915 + else
62916 + allowed = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
62917 put_task_struct(task);
62918 }
62919 return allowed;
62920 @@ -588,10 +618,35 @@ static bool has_pid_permissions(struct pid_namespace *pid,
62921 struct task_struct *task,
62922 int hide_pid_min)
62923 {
62924 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
62925 + return false;
62926 +
62927 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
62928 + rcu_read_lock();
62929 + {
62930 + const struct cred *tmpcred = current_cred();
62931 + const struct cred *cred = __task_cred(task);
62932 +
62933 + if (uid_eq(tmpcred->uid, GLOBAL_ROOT_UID) || uid_eq(tmpcred->uid, cred->uid)
62934 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
62935 + || in_group_p(grsec_proc_gid)
62936 +#endif
62937 + ) {
62938 + rcu_read_unlock();
62939 + return true;
62940 + }
62941 + }
62942 + rcu_read_unlock();
62943 +
62944 + if (!pid->hide_pid)
62945 + return false;
62946 +#endif
62947 +
62948 if (pid->hide_pid < hide_pid_min)
62949 return true;
62950 if (in_group_p(pid->pid_gid))
62951 return true;
62952 +
62953 return ptrace_may_access(task, PTRACE_MODE_READ);
62954 }
62955
62956 @@ -609,7 +664,11 @@ static int proc_pid_permission(struct inode *inode, int mask)
62957 put_task_struct(task);
62958
62959 if (!has_perms) {
62960 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
62961 + {
62962 +#else
62963 if (pid->hide_pid == 2) {
62964 +#endif
62965 /*
62966 * Let's make getdents(), stat(), and open()
62967 * consistent with each other. If a process
62968 @@ -707,6 +766,11 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
62969 if (!task)
62970 return -ESRCH;
62971
62972 + if (gr_acl_handle_procpidmem(task)) {
62973 + put_task_struct(task);
62974 + return -EPERM;
62975 + }
62976 +
62977 mm = mm_access(task, mode);
62978 put_task_struct(task);
62979
62980 @@ -722,6 +786,10 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
62981
62982 file->private_data = mm;
62983
62984 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
62985 + file->f_version = current->exec_id;
62986 +#endif
62987 +
62988 return 0;
62989 }
62990
62991 @@ -743,6 +811,17 @@ static ssize_t mem_rw(struct file *file, char __user *buf,
62992 ssize_t copied;
62993 char *page;
62994
62995 +#ifdef CONFIG_GRKERNSEC
62996 + if (write)
62997 + return -EPERM;
62998 +#endif
62999 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63000 + if (file->f_version != current->exec_id) {
63001 + gr_log_badprocpid("mem");
63002 + return 0;
63003 + }
63004 +#endif
63005 +
63006 if (!mm)
63007 return 0;
63008
63009 @@ -755,7 +834,7 @@ static ssize_t mem_rw(struct file *file, char __user *buf,
63010 goto free;
63011
63012 while (count > 0) {
63013 - int this_len = min_t(int, count, PAGE_SIZE);
63014 + ssize_t this_len = min_t(ssize_t, count, PAGE_SIZE);
63015
63016 if (write && copy_from_user(page, buf, this_len)) {
63017 copied = -EFAULT;
63018 @@ -847,6 +926,13 @@ static ssize_t environ_read(struct file *file, char __user *buf,
63019 if (!mm)
63020 return 0;
63021
63022 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63023 + if (file->f_version != current->exec_id) {
63024 + gr_log_badprocpid("environ");
63025 + return 0;
63026 + }
63027 +#endif
63028 +
63029 page = (char *)__get_free_page(GFP_TEMPORARY);
63030 if (!page)
63031 return -ENOMEM;
63032 @@ -856,7 +942,7 @@ static ssize_t environ_read(struct file *file, char __user *buf,
63033 goto free;
63034 while (count > 0) {
63035 size_t this_len, max_len;
63036 - int retval;
63037 + ssize_t retval;
63038
63039 if (src >= (mm->env_end - mm->env_start))
63040 break;
63041 @@ -1467,7 +1553,7 @@ static void *proc_pid_follow_link(struct dentry *dentry, struct nameidata *nd)
63042 int error = -EACCES;
63043
63044 /* Are we allowed to snoop on the tasks file descriptors? */
63045 - if (!proc_fd_access_allowed(inode))
63046 + if (!proc_fd_access_allowed(inode, 0))
63047 goto out;
63048
63049 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
63050 @@ -1511,8 +1597,18 @@ static int proc_pid_readlink(struct dentry * dentry, char __user * buffer, int b
63051 struct path path;
63052
63053 /* Are we allowed to snoop on the tasks file descriptors? */
63054 - if (!proc_fd_access_allowed(inode))
63055 - goto out;
63056 + /* logging this is needed for learning on chromium to work properly,
63057 + but we don't want to flood the logs from 'ps' which does a readlink
63058 + on /proc/fd/2 of tasks in the listing, nor do we want 'ps' to learn
63059 + CAP_SYS_PTRACE as it's not necessary for its basic functionality
63060 + */
63061 + if (dentry->d_name.name[0] == '2' && dentry->d_name.name[1] == '\0') {
63062 + if (!proc_fd_access_allowed(inode,0))
63063 + goto out;
63064 + } else {
63065 + if (!proc_fd_access_allowed(inode,1))
63066 + goto out;
63067 + }
63068
63069 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
63070 if (error)
63071 @@ -1562,7 +1658,11 @@ struct inode *proc_pid_make_inode(struct super_block * sb, struct task_struct *t
63072 rcu_read_lock();
63073 cred = __task_cred(task);
63074 inode->i_uid = cred->euid;
63075 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
63076 + inode->i_gid = grsec_proc_gid;
63077 +#else
63078 inode->i_gid = cred->egid;
63079 +#endif
63080 rcu_read_unlock();
63081 }
63082 security_task_to_inode(task, inode);
63083 @@ -1598,10 +1698,19 @@ int pid_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
63084 return -ENOENT;
63085 }
63086 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
63087 +#ifdef CONFIG_GRKERNSEC_PROC_USER
63088 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
63089 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
63090 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
63091 +#endif
63092 task_dumpable(task)) {
63093 cred = __task_cred(task);
63094 stat->uid = cred->euid;
63095 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
63096 + stat->gid = grsec_proc_gid;
63097 +#else
63098 stat->gid = cred->egid;
63099 +#endif
63100 }
63101 }
63102 rcu_read_unlock();
63103 @@ -1639,11 +1748,20 @@ int pid_revalidate(struct dentry *dentry, unsigned int flags)
63104
63105 if (task) {
63106 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
63107 +#ifdef CONFIG_GRKERNSEC_PROC_USER
63108 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
63109 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
63110 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
63111 +#endif
63112 task_dumpable(task)) {
63113 rcu_read_lock();
63114 cred = __task_cred(task);
63115 inode->i_uid = cred->euid;
63116 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
63117 + inode->i_gid = grsec_proc_gid;
63118 +#else
63119 inode->i_gid = cred->egid;
63120 +#endif
63121 rcu_read_unlock();
63122 } else {
63123 inode->i_uid = GLOBAL_ROOT_UID;
63124 @@ -2173,6 +2291,9 @@ static struct dentry *proc_pident_lookup(struct inode *dir,
63125 if (!task)
63126 goto out_no_task;
63127
63128 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
63129 + goto out;
63130 +
63131 /*
63132 * Yes, it does not scale. And it should not. Don't add
63133 * new entries into /proc/<tgid>/ without very good reasons.
63134 @@ -2203,6 +2324,9 @@ static int proc_pident_readdir(struct file *file, struct dir_context *ctx,
63135 if (!task)
63136 return -ENOENT;
63137
63138 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
63139 + goto out;
63140 +
63141 if (!dir_emit_dots(file, ctx))
63142 goto out;
63143
63144 @@ -2592,7 +2716,7 @@ static const struct pid_entry tgid_base_stuff[] = {
63145 REG("autogroup", S_IRUGO|S_IWUSR, proc_pid_sched_autogroup_operations),
63146 #endif
63147 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
63148 -#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
63149 +#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
63150 INF("syscall", S_IRUGO, proc_pid_syscall),
63151 #endif
63152 INF("cmdline", S_IRUGO, proc_pid_cmdline),
63153 @@ -2617,10 +2741,10 @@ static const struct pid_entry tgid_base_stuff[] = {
63154 #ifdef CONFIG_SECURITY
63155 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
63156 #endif
63157 -#ifdef CONFIG_KALLSYMS
63158 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
63159 INF("wchan", S_IRUGO, proc_pid_wchan),
63160 #endif
63161 -#ifdef CONFIG_STACKTRACE
63162 +#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
63163 ONE("stack", S_IRUGO, proc_pid_stack),
63164 #endif
63165 #ifdef CONFIG_SCHEDSTATS
63166 @@ -2654,6 +2778,9 @@ static const struct pid_entry tgid_base_stuff[] = {
63167 #ifdef CONFIG_HARDWALL
63168 INF("hardwall", S_IRUGO, proc_pid_hardwall),
63169 #endif
63170 +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
63171 + INF("ipaddr", S_IRUSR, proc_pid_ipaddr),
63172 +#endif
63173 #ifdef CONFIG_USER_NS
63174 REG("uid_map", S_IRUGO|S_IWUSR, proc_uid_map_operations),
63175 REG("gid_map", S_IRUGO|S_IWUSR, proc_gid_map_operations),
63176 @@ -2784,7 +2911,14 @@ static int proc_pid_instantiate(struct inode *dir,
63177 if (!inode)
63178 goto out;
63179
63180 +#ifdef CONFIG_GRKERNSEC_PROC_USER
63181 + inode->i_mode = S_IFDIR|S_IRUSR|S_IXUSR;
63182 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
63183 + inode->i_gid = grsec_proc_gid;
63184 + inode->i_mode = S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP;
63185 +#else
63186 inode->i_mode = S_IFDIR|S_IRUGO|S_IXUGO;
63187 +#endif
63188 inode->i_op = &proc_tgid_base_inode_operations;
63189 inode->i_fop = &proc_tgid_base_operations;
63190 inode->i_flags|=S_IMMUTABLE;
63191 @@ -2822,7 +2956,11 @@ struct dentry *proc_pid_lookup(struct inode *dir, struct dentry * dentry, unsign
63192 if (!task)
63193 goto out;
63194
63195 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
63196 + goto out_put_task;
63197 +
63198 result = proc_pid_instantiate(dir, dentry, task, NULL);
63199 +out_put_task:
63200 put_task_struct(task);
63201 out:
63202 return ERR_PTR(result);
63203 @@ -2928,7 +3066,7 @@ static const struct pid_entry tid_base_stuff[] = {
63204 REG("sched", S_IRUGO|S_IWUSR, proc_pid_sched_operations),
63205 #endif
63206 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
63207 -#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
63208 +#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
63209 INF("syscall", S_IRUGO, proc_pid_syscall),
63210 #endif
63211 INF("cmdline", S_IRUGO, proc_pid_cmdline),
63212 @@ -2955,10 +3093,10 @@ static const struct pid_entry tid_base_stuff[] = {
63213 #ifdef CONFIG_SECURITY
63214 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
63215 #endif
63216 -#ifdef CONFIG_KALLSYMS
63217 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
63218 INF("wchan", S_IRUGO, proc_pid_wchan),
63219 #endif
63220 -#ifdef CONFIG_STACKTRACE
63221 +#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
63222 ONE("stack", S_IRUGO, proc_pid_stack),
63223 #endif
63224 #ifdef CONFIG_SCHEDSTATS
63225 diff --git a/fs/proc/cmdline.c b/fs/proc/cmdline.c
63226 index 82676e3..5f8518a 100644
63227 --- a/fs/proc/cmdline.c
63228 +++ b/fs/proc/cmdline.c
63229 @@ -23,7 +23,11 @@ static const struct file_operations cmdline_proc_fops = {
63230
63231 static int __init proc_cmdline_init(void)
63232 {
63233 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
63234 + proc_create_grsec("cmdline", 0, NULL, &cmdline_proc_fops);
63235 +#else
63236 proc_create("cmdline", 0, NULL, &cmdline_proc_fops);
63237 +#endif
63238 return 0;
63239 }
63240 module_init(proc_cmdline_init);
63241 diff --git a/fs/proc/devices.c b/fs/proc/devices.c
63242 index b143471..bb105e5 100644
63243 --- a/fs/proc/devices.c
63244 +++ b/fs/proc/devices.c
63245 @@ -64,7 +64,11 @@ static const struct file_operations proc_devinfo_operations = {
63246
63247 static int __init proc_devices_init(void)
63248 {
63249 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
63250 + proc_create_grsec("devices", 0, NULL, &proc_devinfo_operations);
63251 +#else
63252 proc_create("devices", 0, NULL, &proc_devinfo_operations);
63253 +#endif
63254 return 0;
63255 }
63256 module_init(proc_devices_init);
63257 diff --git a/fs/proc/fd.c b/fs/proc/fd.c
63258 index 985ea88..d118a0a 100644
63259 --- a/fs/proc/fd.c
63260 +++ b/fs/proc/fd.c
63261 @@ -25,7 +25,8 @@ static int seq_show(struct seq_file *m, void *v)
63262 if (!task)
63263 return -ENOENT;
63264
63265 - files = get_files_struct(task);
63266 + if (!gr_acl_handle_procpidmem(task))
63267 + files = get_files_struct(task);
63268 put_task_struct(task);
63269
63270 if (files) {
63271 @@ -283,11 +284,21 @@ static struct dentry *proc_lookupfd(struct inode *dir, struct dentry *dentry,
63272 */
63273 int proc_fd_permission(struct inode *inode, int mask)
63274 {
63275 + struct task_struct *task;
63276 int rv = generic_permission(inode, mask);
63277 - if (rv == 0)
63278 - return 0;
63279 +
63280 if (task_tgid(current) == proc_pid(inode))
63281 rv = 0;
63282 +
63283 + task = get_proc_task(inode);
63284 + if (task == NULL)
63285 + return rv;
63286 +
63287 + if (gr_acl_handle_procpidmem(task))
63288 + rv = -EACCES;
63289 +
63290 + put_task_struct(task);
63291 +
63292 return rv;
63293 }
63294
63295 diff --git a/fs/proc/inode.c b/fs/proc/inode.c
63296 index 124fc43..8afbb02 100644
63297 --- a/fs/proc/inode.c
63298 +++ b/fs/proc/inode.c
63299 @@ -23,11 +23,17 @@
63300 #include <linux/slab.h>
63301 #include <linux/mount.h>
63302 #include <linux/magic.h>
63303 +#include <linux/grsecurity.h>
63304
63305 #include <asm/uaccess.h>
63306
63307 #include "internal.h"
63308
63309 +#ifdef CONFIG_PROC_SYSCTL
63310 +extern const struct inode_operations proc_sys_inode_operations;
63311 +extern const struct inode_operations proc_sys_dir_operations;
63312 +#endif
63313 +
63314 static void proc_evict_inode(struct inode *inode)
63315 {
63316 struct proc_dir_entry *de;
63317 @@ -55,6 +61,13 @@ static void proc_evict_inode(struct inode *inode)
63318 ns = PROC_I(inode)->ns.ns;
63319 if (ns_ops && ns)
63320 ns_ops->put(ns);
63321 +
63322 +#ifdef CONFIG_PROC_SYSCTL
63323 + if (inode->i_op == &proc_sys_inode_operations ||
63324 + inode->i_op == &proc_sys_dir_operations)
63325 + gr_handle_delete(inode->i_ino, inode->i_sb->s_dev);
63326 +#endif
63327 +
63328 }
63329
63330 static struct kmem_cache * proc_inode_cachep;
63331 @@ -413,7 +426,11 @@ struct inode *proc_get_inode(struct super_block *sb, struct proc_dir_entry *de)
63332 if (de->mode) {
63333 inode->i_mode = de->mode;
63334 inode->i_uid = de->uid;
63335 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
63336 + inode->i_gid = grsec_proc_gid;
63337 +#else
63338 inode->i_gid = de->gid;
63339 +#endif
63340 }
63341 if (de->size)
63342 inode->i_size = de->size;
63343 diff --git a/fs/proc/internal.h b/fs/proc/internal.h
63344 index 651d09a..3d7f0bf 100644
63345 --- a/fs/proc/internal.h
63346 +++ b/fs/proc/internal.h
63347 @@ -48,7 +48,7 @@ struct proc_dir_entry {
63348 spinlock_t pde_unload_lock; /* proc_fops checks and pde_users bumps */
63349 u8 namelen;
63350 char name[];
63351 -};
63352 +} __randomize_layout;
63353
63354 union proc_op {
63355 int (*proc_get_link)(struct dentry *, struct path *);
63356 @@ -67,7 +67,7 @@ struct proc_inode {
63357 struct ctl_table *sysctl_entry;
63358 struct proc_ns ns;
63359 struct inode vfs_inode;
63360 -};
63361 +} __randomize_layout;
63362
63363 /*
63364 * General functions
63365 @@ -155,6 +155,9 @@ extern int proc_pid_status(struct seq_file *, struct pid_namespace *,
63366 struct pid *, struct task_struct *);
63367 extern int proc_pid_statm(struct seq_file *, struct pid_namespace *,
63368 struct pid *, struct task_struct *);
63369 +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
63370 +extern int proc_pid_ipaddr(struct task_struct *task, char *buffer);
63371 +#endif
63372
63373 /*
63374 * base.c
63375 diff --git a/fs/proc/interrupts.c b/fs/proc/interrupts.c
63376 index 05029c0..7ea1987 100644
63377 --- a/fs/proc/interrupts.c
63378 +++ b/fs/proc/interrupts.c
63379 @@ -47,7 +47,11 @@ static const struct file_operations proc_interrupts_operations = {
63380
63381 static int __init proc_interrupts_init(void)
63382 {
63383 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
63384 + proc_create_grsec("interrupts", 0, NULL, &proc_interrupts_operations);
63385 +#else
63386 proc_create("interrupts", 0, NULL, &proc_interrupts_operations);
63387 +#endif
63388 return 0;
63389 }
63390 module_init(proc_interrupts_init);
63391 diff --git a/fs/proc/kcore.c b/fs/proc/kcore.c
63392 index 5ed0e52..a1c1f2e 100644
63393 --- a/fs/proc/kcore.c
63394 +++ b/fs/proc/kcore.c
63395 @@ -483,9 +483,10 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
63396 * the addresses in the elf_phdr on our list.
63397 */
63398 start = kc_offset_to_vaddr(*fpos - elf_buflen);
63399 - if ((tsz = (PAGE_SIZE - (start & ~PAGE_MASK))) > buflen)
63400 + tsz = PAGE_SIZE - (start & ~PAGE_MASK);
63401 + if (tsz > buflen)
63402 tsz = buflen;
63403 -
63404 +
63405 while (buflen) {
63406 struct kcore_list *m;
63407
63408 @@ -514,20 +515,23 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
63409 kfree(elf_buf);
63410 } else {
63411 if (kern_addr_valid(start)) {
63412 - unsigned long n;
63413 + char *elf_buf;
63414 + mm_segment_t oldfs;
63415
63416 - n = copy_to_user(buffer, (char *)start, tsz);
63417 - /*
63418 - * We cannot distinguish between fault on source
63419 - * and fault on destination. When this happens
63420 - * we clear too and hope it will trigger the
63421 - * EFAULT again.
63422 - */
63423 - if (n) {
63424 - if (clear_user(buffer + tsz - n,
63425 - n))
63426 + elf_buf = kmalloc(tsz, GFP_KERNEL);
63427 + if (!elf_buf)
63428 + return -ENOMEM;
63429 + oldfs = get_fs();
63430 + set_fs(KERNEL_DS);
63431 + if (!__copy_from_user(elf_buf, (const void __user *)start, tsz)) {
63432 + set_fs(oldfs);
63433 + if (copy_to_user(buffer, elf_buf, tsz)) {
63434 + kfree(elf_buf);
63435 return -EFAULT;
63436 + }
63437 }
63438 + set_fs(oldfs);
63439 + kfree(elf_buf);
63440 } else {
63441 if (clear_user(buffer, tsz))
63442 return -EFAULT;
63443 @@ -547,6 +551,9 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
63444
63445 static int open_kcore(struct inode *inode, struct file *filp)
63446 {
63447 +#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
63448 + return -EPERM;
63449 +#endif
63450 if (!capable(CAP_SYS_RAWIO))
63451 return -EPERM;
63452 if (kcore_need_update)
63453 diff --git a/fs/proc/meminfo.c b/fs/proc/meminfo.c
63454 index a77d2b2..a9153f0 100644
63455 --- a/fs/proc/meminfo.c
63456 +++ b/fs/proc/meminfo.c
63457 @@ -150,7 +150,7 @@ static int meminfo_proc_show(struct seq_file *m, void *v)
63458 vmi.used >> 10,
63459 vmi.largest_chunk >> 10
63460 #ifdef CONFIG_MEMORY_FAILURE
63461 - ,atomic_long_read(&num_poisoned_pages) << (PAGE_SHIFT - 10)
63462 + ,atomic_long_read_unchecked(&num_poisoned_pages) << (PAGE_SHIFT - 10)
63463 #endif
63464 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
63465 ,K(global_page_state(NR_ANON_TRANSPARENT_HUGEPAGES) *
63466 diff --git a/fs/proc/nommu.c b/fs/proc/nommu.c
63467 index 5f9bc8a..5c35f08 100644
63468 --- a/fs/proc/nommu.c
63469 +++ b/fs/proc/nommu.c
63470 @@ -64,7 +64,7 @@ static int nommu_region_show(struct seq_file *m, struct vm_region *region)
63471
63472 if (file) {
63473 seq_pad(m, ' ');
63474 - seq_path(m, &file->f_path, "");
63475 + seq_path(m, &file->f_path, "\n\\");
63476 }
63477
63478 seq_putc(m, '\n');
63479 diff --git a/fs/proc/proc_net.c b/fs/proc/proc_net.c
63480 index 4677bb7..408e936 100644
63481 --- a/fs/proc/proc_net.c
63482 +++ b/fs/proc/proc_net.c
63483 @@ -23,6 +23,7 @@
63484 #include <linux/nsproxy.h>
63485 #include <net/net_namespace.h>
63486 #include <linux/seq_file.h>
63487 +#include <linux/grsecurity.h>
63488
63489 #include "internal.h"
63490
63491 @@ -109,6 +110,17 @@ static struct net *get_proc_task_net(struct inode *dir)
63492 struct task_struct *task;
63493 struct nsproxy *ns;
63494 struct net *net = NULL;
63495 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
63496 + const struct cred *cred = current_cred();
63497 +#endif
63498 +
63499 +#ifdef CONFIG_GRKERNSEC_PROC_USER
63500 + if (!uid_eq(cred->fsuid, GLOBAL_ROOT_UID))
63501 + return net;
63502 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
63503 + if (!uid_eq(cred->fsuid, GLOBAL_ROOT_UID) && !in_group_p(grsec_proc_gid))
63504 + return net;
63505 +#endif
63506
63507 rcu_read_lock();
63508 task = pid_task(proc_pid(dir), PIDTYPE_PID);
63509 diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c
63510 index 7129046..6914844 100644
63511 --- a/fs/proc/proc_sysctl.c
63512 +++ b/fs/proc/proc_sysctl.c
63513 @@ -11,13 +11,21 @@
63514 #include <linux/namei.h>
63515 #include <linux/mm.h>
63516 #include <linux/module.h>
63517 +#include <linux/nsproxy.h>
63518 +#ifdef CONFIG_GRKERNSEC
63519 +#include <net/net_namespace.h>
63520 +#endif
63521 #include "internal.h"
63522
63523 +extern int gr_handle_chroot_sysctl(const int op);
63524 +extern int gr_handle_sysctl_mod(const char *dirname, const char *name,
63525 + const int op);
63526 +
63527 static const struct dentry_operations proc_sys_dentry_operations;
63528 static const struct file_operations proc_sys_file_operations;
63529 -static const struct inode_operations proc_sys_inode_operations;
63530 +const struct inode_operations proc_sys_inode_operations;
63531 static const struct file_operations proc_sys_dir_file_operations;
63532 -static const struct inode_operations proc_sys_dir_operations;
63533 +const struct inode_operations proc_sys_dir_operations;
63534
63535 void proc_sys_poll_notify(struct ctl_table_poll *poll)
63536 {
63537 @@ -467,6 +475,9 @@ static struct dentry *proc_sys_lookup(struct inode *dir, struct dentry *dentry,
63538
63539 err = NULL;
63540 d_set_d_op(dentry, &proc_sys_dentry_operations);
63541 +
63542 + gr_handle_proc_create(dentry, inode);
63543 +
63544 d_add(dentry, inode);
63545
63546 out:
63547 @@ -482,6 +493,7 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
63548 struct inode *inode = file_inode(filp);
63549 struct ctl_table_header *head = grab_header(inode);
63550 struct ctl_table *table = PROC_I(inode)->sysctl_entry;
63551 + int op = write ? MAY_WRITE : MAY_READ;
63552 ssize_t error;
63553 size_t res;
63554
63555 @@ -493,7 +505,7 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
63556 * and won't be until we finish.
63557 */
63558 error = -EPERM;
63559 - if (sysctl_perm(head, table, write ? MAY_WRITE : MAY_READ))
63560 + if (sysctl_perm(head, table, op))
63561 goto out;
63562
63563 /* if that can happen at all, it should be -EINVAL, not -EISDIR */
63564 @@ -501,6 +513,27 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
63565 if (!table->proc_handler)
63566 goto out;
63567
63568 +#ifdef CONFIG_GRKERNSEC
63569 + error = -EPERM;
63570 + if (gr_handle_chroot_sysctl(op))
63571 + goto out;
63572 + dget(filp->f_path.dentry);
63573 + if (gr_handle_sysctl_mod(filp->f_path.dentry->d_parent->d_name.name, table->procname, op)) {
63574 + dput(filp->f_path.dentry);
63575 + goto out;
63576 + }
63577 + dput(filp->f_path.dentry);
63578 + if (!gr_acl_handle_open(filp->f_path.dentry, filp->f_path.mnt, op))
63579 + goto out;
63580 + if (write) {
63581 + if (current->nsproxy->net_ns != table->extra2) {
63582 + if (!capable(CAP_SYS_ADMIN))
63583 + goto out;
63584 + } else if (!ns_capable(current->nsproxy->net_ns->user_ns, CAP_NET_ADMIN))
63585 + goto out;
63586 + }
63587 +#endif
63588 +
63589 /* careful: calling conventions are nasty here */
63590 res = count;
63591 error = table->proc_handler(table, write, buf, &res, ppos);
63592 @@ -598,6 +631,9 @@ static bool proc_sys_fill_cache(struct file *file,
63593 return false;
63594 } else {
63595 d_set_d_op(child, &proc_sys_dentry_operations);
63596 +
63597 + gr_handle_proc_create(child, inode);
63598 +
63599 d_add(child, inode);
63600 }
63601 } else {
63602 @@ -641,6 +677,9 @@ static int scan(struct ctl_table_header *head, ctl_table *table,
63603 if ((*pos)++ < ctx->pos)
63604 return true;
63605
63606 + if (!gr_acl_handle_hidden_file(file->f_path.dentry, file->f_path.mnt))
63607 + return 0;
63608 +
63609 if (unlikely(S_ISLNK(table->mode)))
63610 res = proc_sys_link_fill_cache(file, ctx, head, table);
63611 else
63612 @@ -734,6 +773,9 @@ static int proc_sys_getattr(struct vfsmount *mnt, struct dentry *dentry, struct
63613 if (IS_ERR(head))
63614 return PTR_ERR(head);
63615
63616 + if (table && !gr_acl_handle_hidden_file(dentry, mnt))
63617 + return -ENOENT;
63618 +
63619 generic_fillattr(inode, stat);
63620 if (table)
63621 stat->mode = (stat->mode & S_IFMT) | table->mode;
63622 @@ -756,13 +798,13 @@ static const struct file_operations proc_sys_dir_file_operations = {
63623 .llseek = generic_file_llseek,
63624 };
63625
63626 -static const struct inode_operations proc_sys_inode_operations = {
63627 +const struct inode_operations proc_sys_inode_operations = {
63628 .permission = proc_sys_permission,
63629 .setattr = proc_sys_setattr,
63630 .getattr = proc_sys_getattr,
63631 };
63632
63633 -static const struct inode_operations proc_sys_dir_operations = {
63634 +const struct inode_operations proc_sys_dir_operations = {
63635 .lookup = proc_sys_lookup,
63636 .permission = proc_sys_permission,
63637 .setattr = proc_sys_setattr,
63638 @@ -839,7 +881,7 @@ static struct ctl_dir *find_subdir(struct ctl_dir *dir,
63639 static struct ctl_dir *new_dir(struct ctl_table_set *set,
63640 const char *name, int namelen)
63641 {
63642 - struct ctl_table *table;
63643 + ctl_table_no_const *table;
63644 struct ctl_dir *new;
63645 struct ctl_node *node;
63646 char *new_name;
63647 @@ -851,7 +893,7 @@ static struct ctl_dir *new_dir(struct ctl_table_set *set,
63648 return NULL;
63649
63650 node = (struct ctl_node *)(new + 1);
63651 - table = (struct ctl_table *)(node + 1);
63652 + table = (ctl_table_no_const *)(node + 1);
63653 new_name = (char *)(table + 2);
63654 memcpy(new_name, name, namelen);
63655 new_name[namelen] = '\0';
63656 @@ -1020,7 +1062,8 @@ static int sysctl_check_table(const char *path, struct ctl_table *table)
63657 static struct ctl_table_header *new_links(struct ctl_dir *dir, struct ctl_table *table,
63658 struct ctl_table_root *link_root)
63659 {
63660 - struct ctl_table *link_table, *entry, *link;
63661 + ctl_table_no_const *link_table, *link;
63662 + struct ctl_table *entry;
63663 struct ctl_table_header *links;
63664 struct ctl_node *node;
63665 char *link_name;
63666 @@ -1043,7 +1086,7 @@ static struct ctl_table_header *new_links(struct ctl_dir *dir, struct ctl_table
63667 return NULL;
63668
63669 node = (struct ctl_node *)(links + 1);
63670 - link_table = (struct ctl_table *)(node + nr_entries);
63671 + link_table = (ctl_table_no_const *)(node + nr_entries);
63672 link_name = (char *)&link_table[nr_entries + 1];
63673
63674 for (link = link_table, entry = table; entry->procname; link++, entry++) {
63675 @@ -1291,8 +1334,8 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
63676 struct ctl_table_header ***subheader, struct ctl_table_set *set,
63677 struct ctl_table *table)
63678 {
63679 - struct ctl_table *ctl_table_arg = NULL;
63680 - struct ctl_table *entry, *files;
63681 + ctl_table_no_const *ctl_table_arg = NULL, *files = NULL;
63682 + struct ctl_table *entry;
63683 int nr_files = 0;
63684 int nr_dirs = 0;
63685 int err = -ENOMEM;
63686 @@ -1304,10 +1347,9 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
63687 nr_files++;
63688 }
63689
63690 - files = table;
63691 /* If there are mixed files and directories we need a new table */
63692 if (nr_dirs && nr_files) {
63693 - struct ctl_table *new;
63694 + ctl_table_no_const *new;
63695 files = kzalloc(sizeof(struct ctl_table) * (nr_files + 1),
63696 GFP_KERNEL);
63697 if (!files)
63698 @@ -1325,7 +1367,7 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
63699 /* Register everything except a directory full of subdirectories */
63700 if (nr_files || !nr_dirs) {
63701 struct ctl_table_header *header;
63702 - header = __register_sysctl_table(set, path, files);
63703 + header = __register_sysctl_table(set, path, files ? files : table);
63704 if (!header) {
63705 kfree(ctl_table_arg);
63706 goto out;
63707 diff --git a/fs/proc/root.c b/fs/proc/root.c
63708 index 87dbcbe..55e1b4d 100644
63709 --- a/fs/proc/root.c
63710 +++ b/fs/proc/root.c
63711 @@ -186,7 +186,15 @@ void __init proc_root_init(void)
63712 #ifdef CONFIG_PROC_DEVICETREE
63713 proc_device_tree_init();
63714 #endif
63715 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
63716 +#ifdef CONFIG_GRKERNSEC_PROC_USER
63717 + proc_mkdir_mode("bus", S_IRUSR | S_IXUSR, NULL);
63718 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
63719 + proc_mkdir_mode("bus", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
63720 +#endif
63721 +#else
63722 proc_mkdir("bus", NULL);
63723 +#endif
63724 proc_sys_init();
63725 }
63726
63727 diff --git a/fs/proc/stat.c b/fs/proc/stat.c
63728 index 1cf86c0..0ee1ca5 100644
63729 --- a/fs/proc/stat.c
63730 +++ b/fs/proc/stat.c
63731 @@ -11,6 +11,7 @@
63732 #include <linux/irqnr.h>
63733 #include <asm/cputime.h>
63734 #include <linux/tick.h>
63735 +#include <linux/grsecurity.h>
63736
63737 #ifndef arch_irq_stat_cpu
63738 #define arch_irq_stat_cpu(cpu) 0
63739 @@ -87,6 +88,18 @@ static int show_stat(struct seq_file *p, void *v)
63740 u64 sum_softirq = 0;
63741 unsigned int per_softirq_sums[NR_SOFTIRQS] = {0};
63742 struct timespec boottime;
63743 + int unrestricted = 1;
63744 +
63745 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
63746 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
63747 + if (!uid_eq(current_uid(), GLOBAL_ROOT_UID)
63748 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
63749 + && !in_group_p(grsec_proc_gid)
63750 +#endif
63751 + )
63752 + unrestricted = 0;
63753 +#endif
63754 +#endif
63755
63756 user = nice = system = idle = iowait =
63757 irq = softirq = steal = 0;
63758 @@ -94,6 +107,7 @@ static int show_stat(struct seq_file *p, void *v)
63759 getboottime(&boottime);
63760 jif = boottime.tv_sec;
63761
63762 + if (unrestricted) {
63763 for_each_possible_cpu(i) {
63764 user += kcpustat_cpu(i).cpustat[CPUTIME_USER];
63765 nice += kcpustat_cpu(i).cpustat[CPUTIME_NICE];
63766 @@ -116,6 +130,7 @@ static int show_stat(struct seq_file *p, void *v)
63767 }
63768 }
63769 sum += arch_irq_stat();
63770 + }
63771
63772 seq_puts(p, "cpu ");
63773 seq_put_decimal_ull(p, ' ', cputime64_to_clock_t(user));
63774 @@ -131,6 +146,7 @@ static int show_stat(struct seq_file *p, void *v)
63775 seq_putc(p, '\n');
63776
63777 for_each_online_cpu(i) {
63778 + if (unrestricted) {
63779 /* Copy values here to work around gcc-2.95.3, gcc-2.96 */
63780 user = kcpustat_cpu(i).cpustat[CPUTIME_USER];
63781 nice = kcpustat_cpu(i).cpustat[CPUTIME_NICE];
63782 @@ -142,6 +158,7 @@ static int show_stat(struct seq_file *p, void *v)
63783 steal = kcpustat_cpu(i).cpustat[CPUTIME_STEAL];
63784 guest = kcpustat_cpu(i).cpustat[CPUTIME_GUEST];
63785 guest_nice = kcpustat_cpu(i).cpustat[CPUTIME_GUEST_NICE];
63786 + }
63787 seq_printf(p, "cpu%d", i);
63788 seq_put_decimal_ull(p, ' ', cputime64_to_clock_t(user));
63789 seq_put_decimal_ull(p, ' ', cputime64_to_clock_t(nice));
63790 @@ -159,7 +176,7 @@ static int show_stat(struct seq_file *p, void *v)
63791
63792 /* sum again ? it could be updated? */
63793 for_each_irq_nr(j)
63794 - seq_put_decimal_ull(p, ' ', kstat_irqs(j));
63795 + seq_put_decimal_ull(p, ' ', unrestricted ? kstat_irqs(j) : 0ULL);
63796
63797 seq_printf(p,
63798 "\nctxt %llu\n"
63799 @@ -167,11 +184,11 @@ static int show_stat(struct seq_file *p, void *v)
63800 "processes %lu\n"
63801 "procs_running %lu\n"
63802 "procs_blocked %lu\n",
63803 - nr_context_switches(),
63804 + unrestricted ? nr_context_switches() : 0ULL,
63805 (unsigned long)jif,
63806 - total_forks,
63807 - nr_running(),
63808 - nr_iowait());
63809 + unrestricted ? total_forks : 0UL,
63810 + unrestricted ? nr_running() : 0UL,
63811 + unrestricted ? nr_iowait() : 0UL);
63812
63813 seq_printf(p, "softirq %llu", (unsigned long long)sum_softirq);
63814
63815 diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
63816 index fb52b54..5fc7c14 100644
63817 --- a/fs/proc/task_mmu.c
63818 +++ b/fs/proc/task_mmu.c
63819 @@ -12,12 +12,19 @@
63820 #include <linux/swap.h>
63821 #include <linux/swapops.h>
63822 #include <linux/mmu_notifier.h>
63823 +#include <linux/grsecurity.h>
63824
63825 #include <asm/elf.h>
63826 #include <asm/uaccess.h>
63827 #include <asm/tlbflush.h>
63828 #include "internal.h"
63829
63830 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63831 +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
63832 + (_mm->pax_flags & MF_PAX_RANDMMAP || \
63833 + _mm->pax_flags & MF_PAX_SEGMEXEC))
63834 +#endif
63835 +
63836 void task_mem(struct seq_file *m, struct mm_struct *mm)
63837 {
63838 unsigned long data, text, lib, swap;
63839 @@ -53,8 +60,13 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
63840 "VmExe:\t%8lu kB\n"
63841 "VmLib:\t%8lu kB\n"
63842 "VmPTE:\t%8lu kB\n"
63843 - "VmSwap:\t%8lu kB\n",
63844 - hiwater_vm << (PAGE_SHIFT-10),
63845 + "VmSwap:\t%8lu kB\n"
63846 +
63847 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
63848 + "CsBase:\t%8lx\nCsLim:\t%8lx\n"
63849 +#endif
63850 +
63851 + ,hiwater_vm << (PAGE_SHIFT-10),
63852 total_vm << (PAGE_SHIFT-10),
63853 mm->locked_vm << (PAGE_SHIFT-10),
63854 mm->pinned_vm << (PAGE_SHIFT-10),
63855 @@ -64,7 +76,19 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
63856 mm->stack_vm << (PAGE_SHIFT-10), text, lib,
63857 (PTRS_PER_PTE * sizeof(pte_t) *
63858 atomic_long_read(&mm->nr_ptes)) >> 10,
63859 - swap << (PAGE_SHIFT-10));
63860 + swap << (PAGE_SHIFT-10)
63861 +
63862 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
63863 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63864 + , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_base
63865 + , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_limit
63866 +#else
63867 + , mm->context.user_cs_base
63868 + , mm->context.user_cs_limit
63869 +#endif
63870 +#endif
63871 +
63872 + );
63873 }
63874
63875 unsigned long task_vsize(struct mm_struct *mm)
63876 @@ -270,13 +294,13 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
63877 pgoff = ((loff_t)vma->vm_pgoff) << PAGE_SHIFT;
63878 }
63879
63880 - /* We don't show the stack guard page in /proc/maps */
63881 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63882 + start = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_start;
63883 + end = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_end;
63884 +#else
63885 start = vma->vm_start;
63886 - if (stack_guard_page_start(vma, start))
63887 - start += PAGE_SIZE;
63888 end = vma->vm_end;
63889 - if (stack_guard_page_end(vma, end))
63890 - end -= PAGE_SIZE;
63891 +#endif
63892
63893 seq_setwidth(m, 25 + sizeof(void *) * 6 - 1);
63894 seq_printf(m, "%08lx-%08lx %c%c%c%c %08llx %02x:%02x %lu ",
63895 @@ -286,7 +310,11 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
63896 flags & VM_WRITE ? 'w' : '-',
63897 flags & VM_EXEC ? 'x' : '-',
63898 flags & VM_MAYSHARE ? 's' : 'p',
63899 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63900 + PAX_RAND_FLAGS(mm) ? 0UL : pgoff,
63901 +#else
63902 pgoff,
63903 +#endif
63904 MAJOR(dev), MINOR(dev), ino);
63905
63906 /*
63907 @@ -295,7 +323,7 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
63908 */
63909 if (file) {
63910 seq_pad(m, ' ');
63911 - seq_path(m, &file->f_path, "\n");
63912 + seq_path(m, &file->f_path, "\n\\");
63913 goto done;
63914 }
63915
63916 @@ -321,8 +349,9 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
63917 * Thread stack in /proc/PID/task/TID/maps or
63918 * the main process stack.
63919 */
63920 - if (!is_pid || (vma->vm_start <= mm->start_stack &&
63921 - vma->vm_end >= mm->start_stack)) {
63922 + if (!is_pid || (vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP)) ||
63923 + (vma->vm_start <= mm->start_stack &&
63924 + vma->vm_end >= mm->start_stack)) {
63925 name = "[stack]";
63926 } else {
63927 /* Thread stack in /proc/PID/maps */
63928 @@ -346,6 +375,13 @@ static int show_map(struct seq_file *m, void *v, int is_pid)
63929 struct proc_maps_private *priv = m->private;
63930 struct task_struct *task = priv->task;
63931
63932 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63933 + if (current->exec_id != m->exec_id) {
63934 + gr_log_badprocpid("maps");
63935 + return 0;
63936 + }
63937 +#endif
63938 +
63939 show_map_vma(m, vma, is_pid);
63940
63941 if (m->count < m->size) /* vma is copied successfully */
63942 @@ -586,12 +622,23 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
63943 .private = &mss,
63944 };
63945
63946 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63947 + if (current->exec_id != m->exec_id) {
63948 + gr_log_badprocpid("smaps");
63949 + return 0;
63950 + }
63951 +#endif
63952 memset(&mss, 0, sizeof mss);
63953 - mss.vma = vma;
63954 - /* mmap_sem is held in m_start */
63955 - if (vma->vm_mm && !is_vm_hugetlb_page(vma))
63956 - walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
63957 -
63958 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63959 + if (!PAX_RAND_FLAGS(vma->vm_mm)) {
63960 +#endif
63961 + mss.vma = vma;
63962 + /* mmap_sem is held in m_start */
63963 + if (vma->vm_mm && !is_vm_hugetlb_page(vma))
63964 + walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
63965 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63966 + }
63967 +#endif
63968 show_map_vma(m, vma, is_pid);
63969
63970 seq_printf(m,
63971 @@ -609,7 +656,11 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
63972 "KernelPageSize: %8lu kB\n"
63973 "MMUPageSize: %8lu kB\n"
63974 "Locked: %8lu kB\n",
63975 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63976 + PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : (vma->vm_end - vma->vm_start) >> 10,
63977 +#else
63978 (vma->vm_end - vma->vm_start) >> 10,
63979 +#endif
63980 mss.resident >> 10,
63981 (unsigned long)(mss.pss >> (10 + PSS_SHIFT)),
63982 mss.shared_clean >> 10,
63983 @@ -1387,6 +1438,13 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
63984 char buffer[64];
63985 int nid;
63986
63987 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63988 + if (current->exec_id != m->exec_id) {
63989 + gr_log_badprocpid("numa_maps");
63990 + return 0;
63991 + }
63992 +#endif
63993 +
63994 if (!mm)
63995 return 0;
63996
63997 @@ -1404,11 +1462,15 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
63998 mpol_to_str(buffer, sizeof(buffer), pol);
63999 mpol_cond_put(pol);
64000
64001 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64002 + seq_printf(m, "%08lx %s", PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : vma->vm_start, buffer);
64003 +#else
64004 seq_printf(m, "%08lx %s", vma->vm_start, buffer);
64005 +#endif
64006
64007 if (file) {
64008 seq_printf(m, " file=");
64009 - seq_path(m, &file->f_path, "\n\t= ");
64010 + seq_path(m, &file->f_path, "\n\t\\= ");
64011 } else if (vma->vm_start <= mm->brk && vma->vm_end >= mm->start_brk) {
64012 seq_printf(m, " heap");
64013 } else {
64014 diff --git a/fs/proc/task_nommu.c b/fs/proc/task_nommu.c
64015 index 678455d..ebd3245 100644
64016 --- a/fs/proc/task_nommu.c
64017 +++ b/fs/proc/task_nommu.c
64018 @@ -51,7 +51,7 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
64019 else
64020 bytes += kobjsize(mm);
64021
64022 - if (current->fs && current->fs->users > 1)
64023 + if (current->fs && atomic_read(&current->fs->users) > 1)
64024 sbytes += kobjsize(current->fs);
64025 else
64026 bytes += kobjsize(current->fs);
64027 @@ -161,7 +161,7 @@ static int nommu_vma_show(struct seq_file *m, struct vm_area_struct *vma,
64028
64029 if (file) {
64030 seq_pad(m, ' ');
64031 - seq_path(m, &file->f_path, "");
64032 + seq_path(m, &file->f_path, "\n\\");
64033 } else if (mm) {
64034 pid_t tid = vm_is_stack(priv->task, vma, is_pid);
64035
64036 diff --git a/fs/proc/vmcore.c b/fs/proc/vmcore.c
64037 index 9100d69..51cd925 100644
64038 --- a/fs/proc/vmcore.c
64039 +++ b/fs/proc/vmcore.c
64040 @@ -105,9 +105,13 @@ static ssize_t read_from_oldmem(char *buf, size_t count,
64041 nr_bytes = count;
64042
64043 /* If pfn is not ram, return zeros for sparse dump files */
64044 - if (pfn_is_ram(pfn) == 0)
64045 - memset(buf, 0, nr_bytes);
64046 - else {
64047 + if (pfn_is_ram(pfn) == 0) {
64048 + if (userbuf) {
64049 + if (clear_user((char __force_user *)buf, nr_bytes))
64050 + return -EFAULT;
64051 + } else
64052 + memset(buf, 0, nr_bytes);
64053 + } else {
64054 tmp = copy_oldmem_page(pfn, buf, nr_bytes,
64055 offset, userbuf);
64056 if (tmp < 0)
64057 @@ -170,7 +174,7 @@ int __weak remap_oldmem_pfn_range(struct vm_area_struct *vma,
64058 static int copy_to(void *target, void *src, size_t size, int userbuf)
64059 {
64060 if (userbuf) {
64061 - if (copy_to_user((char __user *) target, src, size))
64062 + if (copy_to_user((char __force_user *) target, src, size))
64063 return -EFAULT;
64064 } else {
64065 memcpy(target, src, size);
64066 @@ -233,7 +237,7 @@ static ssize_t __read_vmcore(char *buffer, size_t buflen, loff_t *fpos,
64067 if (*fpos < m->offset + m->size) {
64068 tsz = min_t(size_t, m->offset + m->size - *fpos, buflen);
64069 start = m->paddr + *fpos - m->offset;
64070 - tmp = read_from_oldmem(buffer, tsz, &start, userbuf);
64071 + tmp = read_from_oldmem((char __force_kernel *)buffer, tsz, &start, userbuf);
64072 if (tmp < 0)
64073 return tmp;
64074 buflen -= tsz;
64075 @@ -253,7 +257,7 @@ static ssize_t __read_vmcore(char *buffer, size_t buflen, loff_t *fpos,
64076 static ssize_t read_vmcore(struct file *file, char __user *buffer,
64077 size_t buflen, loff_t *fpos)
64078 {
64079 - return __read_vmcore((__force char *) buffer, buflen, fpos, 1);
64080 + return __read_vmcore((__force_kernel char *) buffer, buflen, fpos, 1);
64081 }
64082
64083 /*
64084 diff --git a/fs/qnx6/qnx6.h b/fs/qnx6/qnx6.h
64085 index b00fcc9..e0c6381 100644
64086 --- a/fs/qnx6/qnx6.h
64087 +++ b/fs/qnx6/qnx6.h
64088 @@ -74,7 +74,7 @@ enum {
64089 BYTESEX_BE,
64090 };
64091
64092 -static inline __u64 fs64_to_cpu(struct qnx6_sb_info *sbi, __fs64 n)
64093 +static inline __u64 __intentional_overflow(-1) fs64_to_cpu(struct qnx6_sb_info *sbi, __fs64 n)
64094 {
64095 if (sbi->s_bytesex == BYTESEX_LE)
64096 return le64_to_cpu((__force __le64)n);
64097 @@ -90,7 +90,7 @@ static inline __fs64 cpu_to_fs64(struct qnx6_sb_info *sbi, __u64 n)
64098 return (__force __fs64)cpu_to_be64(n);
64099 }
64100
64101 -static inline __u32 fs32_to_cpu(struct qnx6_sb_info *sbi, __fs32 n)
64102 +static inline __u32 __intentional_overflow(-1) fs32_to_cpu(struct qnx6_sb_info *sbi, __fs32 n)
64103 {
64104 if (sbi->s_bytesex == BYTESEX_LE)
64105 return le32_to_cpu((__force __le32)n);
64106 diff --git a/fs/quota/netlink.c b/fs/quota/netlink.c
64107 index 72d2917..c917c12 100644
64108 --- a/fs/quota/netlink.c
64109 +++ b/fs/quota/netlink.c
64110 @@ -45,7 +45,7 @@ static struct genl_family quota_genl_family = {
64111 void quota_send_warning(struct kqid qid, dev_t dev,
64112 const char warntype)
64113 {
64114 - static atomic_t seq;
64115 + static atomic_unchecked_t seq;
64116 struct sk_buff *skb;
64117 void *msg_head;
64118 int ret;
64119 @@ -61,7 +61,7 @@ void quota_send_warning(struct kqid qid, dev_t dev,
64120 "VFS: Not enough memory to send quota warning.\n");
64121 return;
64122 }
64123 - msg_head = genlmsg_put(skb, 0, atomic_add_return(1, &seq),
64124 + msg_head = genlmsg_put(skb, 0, atomic_add_return_unchecked(1, &seq),
64125 &quota_genl_family, 0, QUOTA_NL_C_WARNING);
64126 if (!msg_head) {
64127 printk(KERN_ERR
64128 diff --git a/fs/read_write.c b/fs/read_write.c
64129 index cfa18df..c110979 100644
64130 --- a/fs/read_write.c
64131 +++ b/fs/read_write.c
64132 @@ -438,7 +438,7 @@ ssize_t __kernel_write(struct file *file, const char *buf, size_t count, loff_t
64133
64134 old_fs = get_fs();
64135 set_fs(get_ds());
64136 - p = (__force const char __user *)buf;
64137 + p = (const char __force_user *)buf;
64138 if (count > MAX_RW_COUNT)
64139 count = MAX_RW_COUNT;
64140 if (file->f_op->write)
64141 diff --git a/fs/readdir.c b/fs/readdir.c
64142 index 5b53d99..a6c3049 100644
64143 --- a/fs/readdir.c
64144 +++ b/fs/readdir.c
64145 @@ -17,6 +17,7 @@
64146 #include <linux/security.h>
64147 #include <linux/syscalls.h>
64148 #include <linux/unistd.h>
64149 +#include <linux/namei.h>
64150
64151 #include <asm/uaccess.h>
64152
64153 @@ -69,6 +70,7 @@ struct old_linux_dirent {
64154 struct readdir_callback {
64155 struct dir_context ctx;
64156 struct old_linux_dirent __user * dirent;
64157 + struct file * file;
64158 int result;
64159 };
64160
64161 @@ -86,6 +88,10 @@ static int fillonedir(void * __buf, const char * name, int namlen, loff_t offset
64162 buf->result = -EOVERFLOW;
64163 return -EOVERFLOW;
64164 }
64165 +
64166 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
64167 + return 0;
64168 +
64169 buf->result++;
64170 dirent = buf->dirent;
64171 if (!access_ok(VERIFY_WRITE, dirent,
64172 @@ -117,6 +123,7 @@ SYSCALL_DEFINE3(old_readdir, unsigned int, fd,
64173 if (!f.file)
64174 return -EBADF;
64175
64176 + buf.file = f.file;
64177 error = iterate_dir(f.file, &buf.ctx);
64178 if (buf.result)
64179 error = buf.result;
64180 @@ -142,6 +149,7 @@ struct getdents_callback {
64181 struct dir_context ctx;
64182 struct linux_dirent __user * current_dir;
64183 struct linux_dirent __user * previous;
64184 + struct file * file;
64185 int count;
64186 int error;
64187 };
64188 @@ -163,6 +171,10 @@ static int filldir(void * __buf, const char * name, int namlen, loff_t offset,
64189 buf->error = -EOVERFLOW;
64190 return -EOVERFLOW;
64191 }
64192 +
64193 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
64194 + return 0;
64195 +
64196 dirent = buf->previous;
64197 if (dirent) {
64198 if (__put_user(offset, &dirent->d_off))
64199 @@ -208,6 +220,7 @@ SYSCALL_DEFINE3(getdents, unsigned int, fd,
64200 if (!f.file)
64201 return -EBADF;
64202
64203 + buf.file = f.file;
64204 error = iterate_dir(f.file, &buf.ctx);
64205 if (error >= 0)
64206 error = buf.error;
64207 @@ -226,6 +239,7 @@ struct getdents_callback64 {
64208 struct dir_context ctx;
64209 struct linux_dirent64 __user * current_dir;
64210 struct linux_dirent64 __user * previous;
64211 + struct file *file;
64212 int count;
64213 int error;
64214 };
64215 @@ -241,6 +255,10 @@ static int filldir64(void * __buf, const char * name, int namlen, loff_t offset,
64216 buf->error = -EINVAL; /* only used if we fail.. */
64217 if (reclen > buf->count)
64218 return -EINVAL;
64219 +
64220 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
64221 + return 0;
64222 +
64223 dirent = buf->previous;
64224 if (dirent) {
64225 if (__put_user(offset, &dirent->d_off))
64226 @@ -288,6 +306,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
64227 if (!f.file)
64228 return -EBADF;
64229
64230 + buf.file = f.file;
64231 error = iterate_dir(f.file, &buf.ctx);
64232 if (error >= 0)
64233 error = buf.error;
64234 diff --git a/fs/reiserfs/do_balan.c b/fs/reiserfs/do_balan.c
64235 index 2b7882b..1c5ef48 100644
64236 --- a/fs/reiserfs/do_balan.c
64237 +++ b/fs/reiserfs/do_balan.c
64238 @@ -2051,7 +2051,7 @@ void do_balance(struct tree_balance *tb, /* tree_balance structure */
64239 return;
64240 }
64241
64242 - atomic_inc(&(fs_generation(tb->tb_sb)));
64243 + atomic_inc_unchecked(&(fs_generation(tb->tb_sb)));
64244 do_balance_starts(tb);
64245
64246 /* balance leaf returns 0 except if combining L R and S into
64247 diff --git a/fs/reiserfs/item_ops.c b/fs/reiserfs/item_ops.c
64248 index ee382ef..f4eb6eb5 100644
64249 --- a/fs/reiserfs/item_ops.c
64250 +++ b/fs/reiserfs/item_ops.c
64251 @@ -725,18 +725,18 @@ static void errcatch_print_vi(struct virtual_item *vi)
64252 }
64253
64254 static struct item_operations errcatch_ops = {
64255 - errcatch_bytes_number,
64256 - errcatch_decrement_key,
64257 - errcatch_is_left_mergeable,
64258 - errcatch_print_item,
64259 - errcatch_check_item,
64260 + .bytes_number = errcatch_bytes_number,
64261 + .decrement_key = errcatch_decrement_key,
64262 + .is_left_mergeable = errcatch_is_left_mergeable,
64263 + .print_item = errcatch_print_item,
64264 + .check_item = errcatch_check_item,
64265
64266 - errcatch_create_vi,
64267 - errcatch_check_left,
64268 - errcatch_check_right,
64269 - errcatch_part_size,
64270 - errcatch_unit_num,
64271 - errcatch_print_vi
64272 + .create_vi = errcatch_create_vi,
64273 + .check_left = errcatch_check_left,
64274 + .check_right = errcatch_check_right,
64275 + .part_size = errcatch_part_size,
64276 + .unit_num = errcatch_unit_num,
64277 + .print_vi = errcatch_print_vi
64278 };
64279
64280 //////////////////////////////////////////////////////////////////////////////
64281 diff --git a/fs/reiserfs/procfs.c b/fs/reiserfs/procfs.c
64282 index a958444..42b2323 100644
64283 --- a/fs/reiserfs/procfs.c
64284 +++ b/fs/reiserfs/procfs.c
64285 @@ -114,7 +114,7 @@ static int show_super(struct seq_file *m, void *unused)
64286 "SMALL_TAILS " : "NO_TAILS ",
64287 replay_only(sb) ? "REPLAY_ONLY " : "",
64288 convert_reiserfs(sb) ? "CONV " : "",
64289 - atomic_read(&r->s_generation_counter),
64290 + atomic_read_unchecked(&r->s_generation_counter),
64291 SF(s_disk_reads), SF(s_disk_writes), SF(s_fix_nodes),
64292 SF(s_do_balance), SF(s_unneeded_left_neighbor),
64293 SF(s_good_search_by_key_reada), SF(s_bmaps),
64294 diff --git a/fs/reiserfs/reiserfs.h b/fs/reiserfs/reiserfs.h
64295 index f8adaee..0eeeeca 100644
64296 --- a/fs/reiserfs/reiserfs.h
64297 +++ b/fs/reiserfs/reiserfs.h
64298 @@ -453,7 +453,7 @@ struct reiserfs_sb_info {
64299 /* Comment? -Hans */
64300 wait_queue_head_t s_wait;
64301 /* To be obsoleted soon by per buffer seals.. -Hans */
64302 - atomic_t s_generation_counter; // increased by one every time the
64303 + atomic_unchecked_t s_generation_counter; // increased by one every time the
64304 // tree gets re-balanced
64305 unsigned long s_properties; /* File system properties. Currently holds
64306 on-disk FS format */
64307 @@ -1982,7 +1982,7 @@ static inline loff_t max_reiserfs_offset(struct inode *inode)
64308 #define REISERFS_USER_MEM 1 /* reiserfs user memory mode */
64309
64310 #define fs_generation(s) (REISERFS_SB(s)->s_generation_counter)
64311 -#define get_generation(s) atomic_read (&fs_generation(s))
64312 +#define get_generation(s) atomic_read_unchecked (&fs_generation(s))
64313 #define FILESYSTEM_CHANGED_TB(tb) (get_generation((tb)->tb_sb) != (tb)->fs_gen)
64314 #define __fs_changed(gen,s) (gen != get_generation (s))
64315 #define fs_changed(gen,s) \
64316 diff --git a/fs/select.c b/fs/select.c
64317 index 467bb1c..cf9d65a 100644
64318 --- a/fs/select.c
64319 +++ b/fs/select.c
64320 @@ -20,6 +20,7 @@
64321 #include <linux/export.h>
64322 #include <linux/slab.h>
64323 #include <linux/poll.h>
64324 +#include <linux/security.h>
64325 #include <linux/personality.h> /* for STICKY_TIMEOUTS */
64326 #include <linux/file.h>
64327 #include <linux/fdtable.h>
64328 @@ -880,6 +881,7 @@ int do_sys_poll(struct pollfd __user *ufds, unsigned int nfds,
64329 struct poll_list *walk = head;
64330 unsigned long todo = nfds;
64331
64332 + gr_learn_resource(current, RLIMIT_NOFILE, nfds, 1);
64333 if (nfds > rlimit(RLIMIT_NOFILE))
64334 return -EINVAL;
64335
64336 diff --git a/fs/seq_file.c b/fs/seq_file.c
64337 index 1d641bb..e600623 100644
64338 --- a/fs/seq_file.c
64339 +++ b/fs/seq_file.c
64340 @@ -10,6 +10,7 @@
64341 #include <linux/seq_file.h>
64342 #include <linux/slab.h>
64343 #include <linux/cred.h>
64344 +#include <linux/sched.h>
64345
64346 #include <asm/uaccess.h>
64347 #include <asm/page.h>
64348 @@ -60,6 +61,9 @@ int seq_open(struct file *file, const struct seq_operations *op)
64349 #ifdef CONFIG_USER_NS
64350 p->user_ns = file->f_cred->user_ns;
64351 #endif
64352 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64353 + p->exec_id = current->exec_id;
64354 +#endif
64355
64356 /*
64357 * Wrappers around seq_open(e.g. swaps_open) need to be
64358 @@ -96,7 +100,7 @@ static int traverse(struct seq_file *m, loff_t offset)
64359 return 0;
64360 }
64361 if (!m->buf) {
64362 - m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
64363 + m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL | GFP_USERCOPY);
64364 if (!m->buf)
64365 return -ENOMEM;
64366 }
64367 @@ -137,7 +141,7 @@ Eoverflow:
64368 m->op->stop(m, p);
64369 kfree(m->buf);
64370 m->count = 0;
64371 - m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
64372 + m->buf = kmalloc(m->size <<= 1, GFP_KERNEL | GFP_USERCOPY);
64373 return !m->buf ? -ENOMEM : -EAGAIN;
64374 }
64375
64376 @@ -153,7 +157,7 @@ Eoverflow:
64377 ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
64378 {
64379 struct seq_file *m = file->private_data;
64380 - size_t copied = 0;
64381 + ssize_t copied = 0;
64382 loff_t pos;
64383 size_t n;
64384 void *p;
64385 @@ -192,7 +196,7 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
64386
64387 /* grab buffer if we didn't have one */
64388 if (!m->buf) {
64389 - m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
64390 + m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL | GFP_USERCOPY);
64391 if (!m->buf)
64392 goto Enomem;
64393 }
64394 @@ -234,7 +238,7 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
64395 m->op->stop(m, p);
64396 kfree(m->buf);
64397 m->count = 0;
64398 - m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
64399 + m->buf = kmalloc(m->size <<= 1, GFP_KERNEL | GFP_USERCOPY);
64400 if (!m->buf)
64401 goto Enomem;
64402 m->version = 0;
64403 @@ -584,7 +588,7 @@ static void single_stop(struct seq_file *p, void *v)
64404 int single_open(struct file *file, int (*show)(struct seq_file *, void *),
64405 void *data)
64406 {
64407 - struct seq_operations *op = kmalloc(sizeof(*op), GFP_KERNEL);
64408 + seq_operations_no_const *op = kzalloc(sizeof(*op), GFP_KERNEL);
64409 int res = -ENOMEM;
64410
64411 if (op) {
64412 diff --git a/fs/splice.c b/fs/splice.c
64413 index 12028fa..a6f2619 100644
64414 --- a/fs/splice.c
64415 +++ b/fs/splice.c
64416 @@ -196,7 +196,7 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
64417 pipe_lock(pipe);
64418
64419 for (;;) {
64420 - if (!pipe->readers) {
64421 + if (!atomic_read(&pipe->readers)) {
64422 send_sig(SIGPIPE, current, 0);
64423 if (!ret)
64424 ret = -EPIPE;
64425 @@ -219,7 +219,7 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
64426 page_nr++;
64427 ret += buf->len;
64428
64429 - if (pipe->files)
64430 + if (atomic_read(&pipe->files))
64431 do_wakeup = 1;
64432
64433 if (!--spd->nr_pages)
64434 @@ -250,9 +250,9 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
64435 do_wakeup = 0;
64436 }
64437
64438 - pipe->waiting_writers++;
64439 + atomic_inc(&pipe->waiting_writers);
64440 pipe_wait(pipe);
64441 - pipe->waiting_writers--;
64442 + atomic_dec(&pipe->waiting_writers);
64443 }
64444
64445 pipe_unlock(pipe);
64446 @@ -583,7 +583,7 @@ static ssize_t kernel_readv(struct file *file, const struct iovec *vec,
64447 old_fs = get_fs();
64448 set_fs(get_ds());
64449 /* The cast to a user pointer is valid due to the set_fs() */
64450 - res = vfs_readv(file, (const struct iovec __user *)vec, vlen, &pos);
64451 + res = vfs_readv(file, (const struct iovec __force_user *)vec, vlen, &pos);
64452 set_fs(old_fs);
64453
64454 return res;
64455 @@ -598,7 +598,7 @@ ssize_t kernel_write(struct file *file, const char *buf, size_t count,
64456 old_fs = get_fs();
64457 set_fs(get_ds());
64458 /* The cast to a user pointer is valid due to the set_fs() */
64459 - res = vfs_write(file, (__force const char __user *)buf, count, &pos);
64460 + res = vfs_write(file, (const char __force_user *)buf, count, &pos);
64461 set_fs(old_fs);
64462
64463 return res;
64464 @@ -651,7 +651,7 @@ ssize_t default_file_splice_read(struct file *in, loff_t *ppos,
64465 goto err;
64466
64467 this_len = min_t(size_t, len, PAGE_CACHE_SIZE - offset);
64468 - vec[i].iov_base = (void __user *) page_address(page);
64469 + vec[i].iov_base = (void __force_user *) page_address(page);
64470 vec[i].iov_len = this_len;
64471 spd.pages[i] = page;
64472 spd.nr_pages++;
64473 @@ -847,7 +847,7 @@ int splice_from_pipe_feed(struct pipe_inode_info *pipe, struct splice_desc *sd,
64474 ops->release(pipe, buf);
64475 pipe->curbuf = (pipe->curbuf + 1) & (pipe->buffers - 1);
64476 pipe->nrbufs--;
64477 - if (pipe->files)
64478 + if (atomic_read(&pipe->files))
64479 sd->need_wakeup = true;
64480 }
64481
64482 @@ -872,10 +872,10 @@ EXPORT_SYMBOL(splice_from_pipe_feed);
64483 int splice_from_pipe_next(struct pipe_inode_info *pipe, struct splice_desc *sd)
64484 {
64485 while (!pipe->nrbufs) {
64486 - if (!pipe->writers)
64487 + if (!atomic_read(&pipe->writers))
64488 return 0;
64489
64490 - if (!pipe->waiting_writers && sd->num_spliced)
64491 + if (!atomic_read(&pipe->waiting_writers) && sd->num_spliced)
64492 return 0;
64493
64494 if (sd->flags & SPLICE_F_NONBLOCK)
64495 @@ -1197,7 +1197,7 @@ ssize_t splice_direct_to_actor(struct file *in, struct splice_desc *sd,
64496 * out of the pipe right after the splice_to_pipe(). So set
64497 * PIPE_READERS appropriately.
64498 */
64499 - pipe->readers = 1;
64500 + atomic_set(&pipe->readers, 1);
64501
64502 current->splice_pipe = pipe;
64503 }
64504 @@ -1493,6 +1493,7 @@ static int get_iovec_page_array(const struct iovec __user *iov,
64505
64506 partial[buffers].offset = off;
64507 partial[buffers].len = plen;
64508 + partial[buffers].private = 0;
64509
64510 off = 0;
64511 len -= plen;
64512 @@ -1795,9 +1796,9 @@ static int ipipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
64513 ret = -ERESTARTSYS;
64514 break;
64515 }
64516 - if (!pipe->writers)
64517 + if (!atomic_read(&pipe->writers))
64518 break;
64519 - if (!pipe->waiting_writers) {
64520 + if (!atomic_read(&pipe->waiting_writers)) {
64521 if (flags & SPLICE_F_NONBLOCK) {
64522 ret = -EAGAIN;
64523 break;
64524 @@ -1829,7 +1830,7 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
64525 pipe_lock(pipe);
64526
64527 while (pipe->nrbufs >= pipe->buffers) {
64528 - if (!pipe->readers) {
64529 + if (!atomic_read(&pipe->readers)) {
64530 send_sig(SIGPIPE, current, 0);
64531 ret = -EPIPE;
64532 break;
64533 @@ -1842,9 +1843,9 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
64534 ret = -ERESTARTSYS;
64535 break;
64536 }
64537 - pipe->waiting_writers++;
64538 + atomic_inc(&pipe->waiting_writers);
64539 pipe_wait(pipe);
64540 - pipe->waiting_writers--;
64541 + atomic_dec(&pipe->waiting_writers);
64542 }
64543
64544 pipe_unlock(pipe);
64545 @@ -1880,14 +1881,14 @@ retry:
64546 pipe_double_lock(ipipe, opipe);
64547
64548 do {
64549 - if (!opipe->readers) {
64550 + if (!atomic_read(&opipe->readers)) {
64551 send_sig(SIGPIPE, current, 0);
64552 if (!ret)
64553 ret = -EPIPE;
64554 break;
64555 }
64556
64557 - if (!ipipe->nrbufs && !ipipe->writers)
64558 + if (!ipipe->nrbufs && !atomic_read(&ipipe->writers))
64559 break;
64560
64561 /*
64562 @@ -1984,7 +1985,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
64563 pipe_double_lock(ipipe, opipe);
64564
64565 do {
64566 - if (!opipe->readers) {
64567 + if (!atomic_read(&opipe->readers)) {
64568 send_sig(SIGPIPE, current, 0);
64569 if (!ret)
64570 ret = -EPIPE;
64571 @@ -2029,7 +2030,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
64572 * return EAGAIN if we have the potential of some data in the
64573 * future, otherwise just return 0
64574 */
64575 - if (!ret && ipipe->waiting_writers && (flags & SPLICE_F_NONBLOCK))
64576 + if (!ret && atomic_read(&ipipe->waiting_writers) && (flags & SPLICE_F_NONBLOCK))
64577 ret = -EAGAIN;
64578
64579 pipe_unlock(ipipe);
64580 diff --git a/fs/stat.c b/fs/stat.c
64581 index ae0c3ce..9ee641c 100644
64582 --- a/fs/stat.c
64583 +++ b/fs/stat.c
64584 @@ -28,8 +28,13 @@ void generic_fillattr(struct inode *inode, struct kstat *stat)
64585 stat->gid = inode->i_gid;
64586 stat->rdev = inode->i_rdev;
64587 stat->size = i_size_read(inode);
64588 - stat->atime = inode->i_atime;
64589 - stat->mtime = inode->i_mtime;
64590 + if (is_sidechannel_device(inode) && !capable_nolog(CAP_MKNOD)) {
64591 + stat->atime = inode->i_ctime;
64592 + stat->mtime = inode->i_ctime;
64593 + } else {
64594 + stat->atime = inode->i_atime;
64595 + stat->mtime = inode->i_mtime;
64596 + }
64597 stat->ctime = inode->i_ctime;
64598 stat->blksize = (1 << inode->i_blkbits);
64599 stat->blocks = inode->i_blocks;
64600 @@ -52,9 +57,16 @@ EXPORT_SYMBOL(generic_fillattr);
64601 int vfs_getattr_nosec(struct path *path, struct kstat *stat)
64602 {
64603 struct inode *inode = path->dentry->d_inode;
64604 + int retval;
64605
64606 - if (inode->i_op->getattr)
64607 - return inode->i_op->getattr(path->mnt, path->dentry, stat);
64608 + if (inode->i_op->getattr) {
64609 + retval = inode->i_op->getattr(path->mnt, path->dentry, stat);
64610 + if (!retval && is_sidechannel_device(inode) && !capable_nolog(CAP_MKNOD)) {
64611 + stat->atime = stat->ctime;
64612 + stat->mtime = stat->ctime;
64613 + }
64614 + return retval;
64615 + }
64616
64617 generic_fillattr(inode, stat);
64618 return 0;
64619 diff --git a/fs/sysfs/dir.c b/fs/sysfs/dir.c
64620 index 5e73d66..4f165fd 100644
64621 --- a/fs/sysfs/dir.c
64622 +++ b/fs/sysfs/dir.c
64623 @@ -40,7 +40,7 @@ static DEFINE_IDA(sysfs_ino_ida);
64624 *
64625 * Returns 31 bit hash of ns + name (so it fits in an off_t )
64626 */
64627 -static unsigned int sysfs_name_hash(const char *name, const void *ns)
64628 +static unsigned int sysfs_name_hash(const unsigned char *name, const void *ns)
64629 {
64630 unsigned long hash = init_name_hash();
64631 unsigned int len = strlen(name);
64632 @@ -676,6 +676,18 @@ static int create_dir(struct kobject *kobj, struct sysfs_dirent *parent_sd,
64633 struct sysfs_dirent *sd;
64634 int rc;
64635
64636 +#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
64637 + const char *parent_name = parent_sd->s_name;
64638 +
64639 + mode = S_IFDIR | S_IRWXU;
64640 +
64641 + if ((!strcmp(parent_name, "") && (!strcmp(name, "devices") || !strcmp(name, "fs"))) ||
64642 + (!strcmp(parent_name, "devices") && !strcmp(name, "system")) ||
64643 + (!strcmp(parent_name, "fs") && (!strcmp(name, "selinux") || !strcmp(name, "fuse") || !strcmp(name, "ecryptfs"))) ||
64644 + (!strcmp(parent_name, "system") && !strcmp(name, "cpu")))
64645 + mode = S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO;
64646 +#endif
64647 +
64648 /* allocate */
64649 sd = sysfs_new_dirent(name, mode, SYSFS_DIR);
64650 if (!sd)
64651 diff --git a/fs/sysfs/file.c b/fs/sysfs/file.c
64652 index 35e7d08..4d6e676 100644
64653 --- a/fs/sysfs/file.c
64654 +++ b/fs/sysfs/file.c
64655 @@ -42,7 +42,7 @@ static DEFINE_MUTEX(sysfs_open_file_mutex);
64656
64657 struct sysfs_open_dirent {
64658 atomic_t refcnt;
64659 - atomic_t event;
64660 + atomic_unchecked_t event;
64661 wait_queue_head_t poll;
64662 struct list_head files; /* goes through sysfs_open_file.list */
64663 };
64664 @@ -112,7 +112,7 @@ static int sysfs_seq_show(struct seq_file *sf, void *v)
64665 return -ENODEV;
64666 }
64667
64668 - of->event = atomic_read(&of->sd->s_attr.open->event);
64669 + of->event = atomic_read_unchecked(&of->sd->s_attr.open->event);
64670
64671 /*
64672 * Lookup @ops and invoke show(). Control may reach here via seq
64673 @@ -365,12 +365,12 @@ static int sysfs_bin_page_mkwrite(struct vm_area_struct *vma,
64674 return ret;
64675 }
64676
64677 -static int sysfs_bin_access(struct vm_area_struct *vma, unsigned long addr,
64678 - void *buf, int len, int write)
64679 +static ssize_t sysfs_bin_access(struct vm_area_struct *vma, unsigned long addr,
64680 + void *buf, size_t len, int write)
64681 {
64682 struct file *file = vma->vm_file;
64683 struct sysfs_open_file *of = sysfs_of(file);
64684 - int ret;
64685 + ssize_t ret;
64686
64687 if (!of->vm_ops)
64688 return -EINVAL;
64689 @@ -564,7 +564,7 @@ static int sysfs_get_open_dirent(struct sysfs_dirent *sd,
64690 return -ENOMEM;
64691
64692 atomic_set(&new_od->refcnt, 0);
64693 - atomic_set(&new_od->event, 1);
64694 + atomic_set_unchecked(&new_od->event, 1);
64695 init_waitqueue_head(&new_od->poll);
64696 INIT_LIST_HEAD(&new_od->files);
64697 goto retry;
64698 @@ -768,7 +768,7 @@ static unsigned int sysfs_poll(struct file *filp, poll_table *wait)
64699
64700 sysfs_put_active(attr_sd);
64701
64702 - if (of->event != atomic_read(&od->event))
64703 + if (of->event != atomic_read_unchecked(&od->event))
64704 goto trigger;
64705
64706 return DEFAULT_POLLMASK;
64707 @@ -787,7 +787,7 @@ void sysfs_notify_dirent(struct sysfs_dirent *sd)
64708 if (!WARN_ON(sysfs_type(sd) != SYSFS_KOBJ_ATTR)) {
64709 od = sd->s_attr.open;
64710 if (od) {
64711 - atomic_inc(&od->event);
64712 + atomic_inc_unchecked(&od->event);
64713 wake_up_interruptible(&od->poll);
64714 }
64715 }
64716 diff --git a/fs/sysfs/symlink.c b/fs/sysfs/symlink.c
64717 index 3ae3f1b..081a26c 100644
64718 --- a/fs/sysfs/symlink.c
64719 +++ b/fs/sysfs/symlink.c
64720 @@ -314,7 +314,7 @@ static void *sysfs_follow_link(struct dentry *dentry, struct nameidata *nd)
64721 static void sysfs_put_link(struct dentry *dentry, struct nameidata *nd,
64722 void *cookie)
64723 {
64724 - char *page = nd_get_link(nd);
64725 + const char *page = nd_get_link(nd);
64726 if (!IS_ERR(page))
64727 free_page((unsigned long)page);
64728 }
64729 diff --git a/fs/sysv/sysv.h b/fs/sysv/sysv.h
64730 index 69d4889..a810bd4 100644
64731 --- a/fs/sysv/sysv.h
64732 +++ b/fs/sysv/sysv.h
64733 @@ -188,7 +188,7 @@ static inline u32 PDP_swab(u32 x)
64734 #endif
64735 }
64736
64737 -static inline __u32 fs32_to_cpu(struct sysv_sb_info *sbi, __fs32 n)
64738 +static inline __u32 __intentional_overflow(-1) fs32_to_cpu(struct sysv_sb_info *sbi, __fs32 n)
64739 {
64740 if (sbi->s_bytesex == BYTESEX_PDP)
64741 return PDP_swab((__force __u32)n);
64742 diff --git a/fs/ubifs/io.c b/fs/ubifs/io.c
64743 index e18b988..f1d4ad0f 100644
64744 --- a/fs/ubifs/io.c
64745 +++ b/fs/ubifs/io.c
64746 @@ -155,7 +155,7 @@ int ubifs_leb_change(struct ubifs_info *c, int lnum, const void *buf, int len)
64747 return err;
64748 }
64749
64750 -int ubifs_leb_unmap(struct ubifs_info *c, int lnum)
64751 +int __intentional_overflow(-1) ubifs_leb_unmap(struct ubifs_info *c, int lnum)
64752 {
64753 int err;
64754
64755 diff --git a/fs/udf/misc.c b/fs/udf/misc.c
64756 index c175b4d..8f36a16 100644
64757 --- a/fs/udf/misc.c
64758 +++ b/fs/udf/misc.c
64759 @@ -289,7 +289,7 @@ void udf_new_tag(char *data, uint16_t ident, uint16_t version, uint16_t snum,
64760
64761 u8 udf_tag_checksum(const struct tag *t)
64762 {
64763 - u8 *data = (u8 *)t;
64764 + const u8 *data = (const u8 *)t;
64765 u8 checksum = 0;
64766 int i;
64767 for (i = 0; i < sizeof(struct tag); ++i)
64768 diff --git a/fs/ufs/swab.h b/fs/ufs/swab.h
64769 index 8d974c4..b82f6ec 100644
64770 --- a/fs/ufs/swab.h
64771 +++ b/fs/ufs/swab.h
64772 @@ -22,7 +22,7 @@ enum {
64773 BYTESEX_BE
64774 };
64775
64776 -static inline u64
64777 +static inline u64 __intentional_overflow(-1)
64778 fs64_to_cpu(struct super_block *sbp, __fs64 n)
64779 {
64780 if (UFS_SB(sbp)->s_bytesex == BYTESEX_LE)
64781 @@ -40,7 +40,7 @@ cpu_to_fs64(struct super_block *sbp, u64 n)
64782 return (__force __fs64)cpu_to_be64(n);
64783 }
64784
64785 -static inline u32
64786 +static inline u32 __intentional_overflow(-1)
64787 fs32_to_cpu(struct super_block *sbp, __fs32 n)
64788 {
64789 if (UFS_SB(sbp)->s_bytesex == BYTESEX_LE)
64790 diff --git a/fs/utimes.c b/fs/utimes.c
64791 index aa138d6..5f3a811 100644
64792 --- a/fs/utimes.c
64793 +++ b/fs/utimes.c
64794 @@ -1,6 +1,7 @@
64795 #include <linux/compiler.h>
64796 #include <linux/file.h>
64797 #include <linux/fs.h>
64798 +#include <linux/security.h>
64799 #include <linux/linkage.h>
64800 #include <linux/mount.h>
64801 #include <linux/namei.h>
64802 @@ -103,6 +104,12 @@ static int utimes_common(struct path *path, struct timespec *times)
64803 }
64804 }
64805 retry_deleg:
64806 +
64807 + if (!gr_acl_handle_utime(path->dentry, path->mnt)) {
64808 + error = -EACCES;
64809 + goto mnt_drop_write_and_out;
64810 + }
64811 +
64812 mutex_lock(&inode->i_mutex);
64813 error = notify_change(path->dentry, &newattrs, &delegated_inode);
64814 mutex_unlock(&inode->i_mutex);
64815 diff --git a/fs/xattr.c b/fs/xattr.c
64816 index 3377dff..f394815 100644
64817 --- a/fs/xattr.c
64818 +++ b/fs/xattr.c
64819 @@ -227,6 +227,27 @@ int vfs_xattr_cmp(struct dentry *dentry, const char *xattr_name,
64820 return rc;
64821 }
64822
64823 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
64824 +ssize_t
64825 +pax_getxattr(struct dentry *dentry, void *value, size_t size)
64826 +{
64827 + struct inode *inode = dentry->d_inode;
64828 + ssize_t error;
64829 +
64830 + error = inode_permission(inode, MAY_EXEC);
64831 + if (error)
64832 + return error;
64833 +
64834 + if (inode->i_op->getxattr)
64835 + error = inode->i_op->getxattr(dentry, XATTR_NAME_PAX_FLAGS, value, size);
64836 + else
64837 + error = -EOPNOTSUPP;
64838 +
64839 + return error;
64840 +}
64841 +EXPORT_SYMBOL(pax_getxattr);
64842 +#endif
64843 +
64844 ssize_t
64845 vfs_getxattr(struct dentry *dentry, const char *name, void *value, size_t size)
64846 {
64847 @@ -319,7 +340,7 @@ EXPORT_SYMBOL_GPL(vfs_removexattr);
64848 * Extended attribute SET operations
64849 */
64850 static long
64851 -setxattr(struct dentry *d, const char __user *name, const void __user *value,
64852 +setxattr(struct path *path, const char __user *name, const void __user *value,
64853 size_t size, int flags)
64854 {
64855 int error;
64856 @@ -355,7 +376,12 @@ setxattr(struct dentry *d, const char __user *name, const void __user *value,
64857 posix_acl_fix_xattr_from_user(kvalue, size);
64858 }
64859
64860 - error = vfs_setxattr(d, kname, kvalue, size, flags);
64861 + if (!gr_acl_handle_setxattr(path->dentry, path->mnt)) {
64862 + error = -EACCES;
64863 + goto out;
64864 + }
64865 +
64866 + error = vfs_setxattr(path->dentry, kname, kvalue, size, flags);
64867 out:
64868 if (vvalue)
64869 vfree(vvalue);
64870 @@ -377,7 +403,7 @@ retry:
64871 return error;
64872 error = mnt_want_write(path.mnt);
64873 if (!error) {
64874 - error = setxattr(path.dentry, name, value, size, flags);
64875 + error = setxattr(&path, name, value, size, flags);
64876 mnt_drop_write(path.mnt);
64877 }
64878 path_put(&path);
64879 @@ -401,7 +427,7 @@ retry:
64880 return error;
64881 error = mnt_want_write(path.mnt);
64882 if (!error) {
64883 - error = setxattr(path.dentry, name, value, size, flags);
64884 + error = setxattr(&path, name, value, size, flags);
64885 mnt_drop_write(path.mnt);
64886 }
64887 path_put(&path);
64888 @@ -416,16 +442,14 @@ SYSCALL_DEFINE5(fsetxattr, int, fd, const char __user *, name,
64889 const void __user *,value, size_t, size, int, flags)
64890 {
64891 struct fd f = fdget(fd);
64892 - struct dentry *dentry;
64893 int error = -EBADF;
64894
64895 if (!f.file)
64896 return error;
64897 - dentry = f.file->f_path.dentry;
64898 - audit_inode(NULL, dentry, 0);
64899 + audit_inode(NULL, f.file->f_path.dentry, 0);
64900 error = mnt_want_write_file(f.file);
64901 if (!error) {
64902 - error = setxattr(dentry, name, value, size, flags);
64903 + error = setxattr(&f.file->f_path, name, value, size, flags);
64904 mnt_drop_write_file(f.file);
64905 }
64906 fdput(f);
64907 @@ -626,7 +650,7 @@ SYSCALL_DEFINE3(flistxattr, int, fd, char __user *, list, size_t, size)
64908 * Extended attribute REMOVE operations
64909 */
64910 static long
64911 -removexattr(struct dentry *d, const char __user *name)
64912 +removexattr(struct path *path, const char __user *name)
64913 {
64914 int error;
64915 char kname[XATTR_NAME_MAX + 1];
64916 @@ -637,7 +661,10 @@ removexattr(struct dentry *d, const char __user *name)
64917 if (error < 0)
64918 return error;
64919
64920 - return vfs_removexattr(d, kname);
64921 + if (!gr_acl_handle_removexattr(path->dentry, path->mnt))
64922 + return -EACCES;
64923 +
64924 + return vfs_removexattr(path->dentry, kname);
64925 }
64926
64927 SYSCALL_DEFINE2(removexattr, const char __user *, pathname,
64928 @@ -652,7 +679,7 @@ retry:
64929 return error;
64930 error = mnt_want_write(path.mnt);
64931 if (!error) {
64932 - error = removexattr(path.dentry, name);
64933 + error = removexattr(&path, name);
64934 mnt_drop_write(path.mnt);
64935 }
64936 path_put(&path);
64937 @@ -675,7 +702,7 @@ retry:
64938 return error;
64939 error = mnt_want_write(path.mnt);
64940 if (!error) {
64941 - error = removexattr(path.dentry, name);
64942 + error = removexattr(&path, name);
64943 mnt_drop_write(path.mnt);
64944 }
64945 path_put(&path);
64946 @@ -689,16 +716,16 @@ retry:
64947 SYSCALL_DEFINE2(fremovexattr, int, fd, const char __user *, name)
64948 {
64949 struct fd f = fdget(fd);
64950 - struct dentry *dentry;
64951 + struct path *path;
64952 int error = -EBADF;
64953
64954 if (!f.file)
64955 return error;
64956 - dentry = f.file->f_path.dentry;
64957 - audit_inode(NULL, dentry, 0);
64958 + path = &f.file->f_path;
64959 + audit_inode(NULL, path->dentry, 0);
64960 error = mnt_want_write_file(f.file);
64961 if (!error) {
64962 - error = removexattr(dentry, name);
64963 + error = removexattr(path, name);
64964 mnt_drop_write_file(f.file);
64965 }
64966 fdput(f);
64967 diff --git a/fs/xattr_acl.c b/fs/xattr_acl.c
64968 index 9fbea87..417b3c2 100644
64969 --- a/fs/xattr_acl.c
64970 +++ b/fs/xattr_acl.c
64971 @@ -10,6 +10,7 @@
64972 #include <linux/posix_acl_xattr.h>
64973 #include <linux/gfp.h>
64974 #include <linux/user_namespace.h>
64975 +#include <linux/grsecurity.h>
64976
64977 /*
64978 * Fix up the uids and gids in posix acl extended attributes in place.
64979 @@ -76,11 +77,12 @@ struct posix_acl *
64980 posix_acl_from_xattr(struct user_namespace *user_ns,
64981 const void *value, size_t size)
64982 {
64983 - posix_acl_xattr_header *header = (posix_acl_xattr_header *)value;
64984 - posix_acl_xattr_entry *entry = (posix_acl_xattr_entry *)(header+1), *end;
64985 + const posix_acl_xattr_header *header = (const posix_acl_xattr_header *)value;
64986 + const posix_acl_xattr_entry *entry = (const posix_acl_xattr_entry *)(header+1), *end;
64987 int count;
64988 struct posix_acl *acl;
64989 struct posix_acl_entry *acl_e;
64990 + umode_t umask = gr_acl_umask();
64991
64992 if (!value)
64993 return NULL;
64994 @@ -106,12 +108,18 @@ posix_acl_from_xattr(struct user_namespace *user_ns,
64995
64996 switch(acl_e->e_tag) {
64997 case ACL_USER_OBJ:
64998 + acl_e->e_perm &= ~((umask & S_IRWXU) >> 6);
64999 + break;
65000 case ACL_GROUP_OBJ:
65001 case ACL_MASK:
65002 + acl_e->e_perm &= ~((umask & S_IRWXG) >> 3);
65003 + break;
65004 case ACL_OTHER:
65005 + acl_e->e_perm &= ~(umask & S_IRWXO);
65006 break;
65007
65008 case ACL_USER:
65009 + acl_e->e_perm &= ~((umask & S_IRWXU) >> 6);
65010 acl_e->e_uid =
65011 make_kuid(user_ns,
65012 le32_to_cpu(entry->e_id));
65013 @@ -119,6 +127,7 @@ posix_acl_from_xattr(struct user_namespace *user_ns,
65014 goto fail;
65015 break;
65016 case ACL_GROUP:
65017 + acl_e->e_perm &= ~((umask & S_IRWXG) >> 3);
65018 acl_e->e_gid =
65019 make_kgid(user_ns,
65020 le32_to_cpu(entry->e_id));
65021 diff --git a/fs/xfs/xfs_bmap.c b/fs/xfs/xfs_bmap.c
65022 index 3b2c14b..de031fe 100644
65023 --- a/fs/xfs/xfs_bmap.c
65024 +++ b/fs/xfs/xfs_bmap.c
65025 @@ -584,7 +584,7 @@ xfs_bmap_validate_ret(
65026
65027 #else
65028 #define xfs_bmap_check_leaf_extents(cur, ip, whichfork) do { } while (0)
65029 -#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap)
65030 +#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap) do { } while (0)
65031 #endif /* DEBUG */
65032
65033 /*
65034 diff --git a/fs/xfs/xfs_dir2_readdir.c b/fs/xfs/xfs_dir2_readdir.c
65035 index c4e50c6..8ba93e3 100644
65036 --- a/fs/xfs/xfs_dir2_readdir.c
65037 +++ b/fs/xfs/xfs_dir2_readdir.c
65038 @@ -160,7 +160,12 @@ xfs_dir2_sf_getdents(
65039 ino = dp->d_ops->sf_get_ino(sfp, sfep);
65040 filetype = dp->d_ops->sf_get_ftype(sfep);
65041 ctx->pos = off & 0x7fffffff;
65042 - if (!dir_emit(ctx, (char *)sfep->name, sfep->namelen, ino,
65043 + if (dp->i_df.if_u1.if_data == dp->i_df.if_u2.if_inline_data) {
65044 + char name[sfep->namelen];
65045 + memcpy(name, sfep->name, sfep->namelen);
65046 + if (!dir_emit(ctx, name, sfep->namelen, ino, xfs_dir3_get_dtype(mp, filetype)))
65047 + return 0;
65048 + } else if (!dir_emit(ctx, (char *)sfep->name, sfep->namelen, ino,
65049 xfs_dir3_get_dtype(mp, filetype)))
65050 return 0;
65051 sfep = dp->d_ops->sf_nextentry(sfp, sfep);
65052 diff --git a/fs/xfs/xfs_ioctl.c b/fs/xfs/xfs_ioctl.c
65053 index 33ad9a7..82c18ba 100644
65054 --- a/fs/xfs/xfs_ioctl.c
65055 +++ b/fs/xfs/xfs_ioctl.c
65056 @@ -126,7 +126,7 @@ xfs_find_handle(
65057 }
65058
65059 error = -EFAULT;
65060 - if (copy_to_user(hreq->ohandle, &handle, hsize) ||
65061 + if (hsize > sizeof handle || copy_to_user(hreq->ohandle, &handle, hsize) ||
65062 copy_to_user(hreq->ohandlen, &hsize, sizeof(__s32)))
65063 goto out_put;
65064
65065 diff --git a/fs/xfs/xfs_iops.c b/fs/xfs/xfs_iops.c
65066 index 104455b..764c512 100644
65067 --- a/fs/xfs/xfs_iops.c
65068 +++ b/fs/xfs/xfs_iops.c
65069 @@ -397,7 +397,7 @@ xfs_vn_put_link(
65070 struct nameidata *nd,
65071 void *p)
65072 {
65073 - char *s = nd_get_link(nd);
65074 + const char *s = nd_get_link(nd);
65075
65076 if (!IS_ERR(s))
65077 kfree(s);
65078 diff --git a/grsecurity/Kconfig b/grsecurity/Kconfig
65079 new file mode 100644
65080 index 0000000..3abaf02
65081 --- /dev/null
65082 +++ b/grsecurity/Kconfig
65083 @@ -0,0 +1,1161 @@
65084 +#
65085 +# grecurity configuration
65086 +#
65087 +menu "Memory Protections"
65088 +depends on GRKERNSEC
65089 +
65090 +config GRKERNSEC_KMEM
65091 + bool "Deny reading/writing to /dev/kmem, /dev/mem, and /dev/port"
65092 + default y if GRKERNSEC_CONFIG_AUTO
65093 + select STRICT_DEVMEM if (X86 || ARM || TILE || S390)
65094 + help
65095 + If you say Y here, /dev/kmem and /dev/mem won't be allowed to
65096 + be written to or read from to modify or leak the contents of the running
65097 + kernel. /dev/port will also not be allowed to be opened, writing to
65098 + /dev/cpu/*/msr will be prevented, and support for kexec will be removed.
65099 + If you have module support disabled, enabling this will close up several
65100 + ways that are currently used to insert malicious code into the running
65101 + kernel.
65102 +
65103 + Even with this feature enabled, we still highly recommend that
65104 + you use the RBAC system, as it is still possible for an attacker to
65105 + modify the running kernel through other more obscure methods.
65106 +
65107 + It is highly recommended that you say Y here if you meet all the
65108 + conditions above.
65109 +
65110 +config GRKERNSEC_VM86
65111 + bool "Restrict VM86 mode"
65112 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
65113 + depends on X86_32
65114 +
65115 + help
65116 + If you say Y here, only processes with CAP_SYS_RAWIO will be able to
65117 + make use of a special execution mode on 32bit x86 processors called
65118 + Virtual 8086 (VM86) mode. XFree86 may need vm86 mode for certain
65119 + video cards and will still work with this option enabled. The purpose
65120 + of the option is to prevent exploitation of emulation errors in
65121 + virtualization of vm86 mode like the one discovered in VMWare in 2009.
65122 + Nearly all users should be able to enable this option.
65123 +
65124 +config GRKERNSEC_IO
65125 + bool "Disable privileged I/O"
65126 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
65127 + depends on X86
65128 + select RTC_CLASS
65129 + select RTC_INTF_DEV
65130 + select RTC_DRV_CMOS
65131 +
65132 + help
65133 + If you say Y here, all ioperm and iopl calls will return an error.
65134 + Ioperm and iopl can be used to modify the running kernel.
65135 + Unfortunately, some programs need this access to operate properly,
65136 + the most notable of which are XFree86 and hwclock. hwclock can be
65137 + remedied by having RTC support in the kernel, so real-time
65138 + clock support is enabled if this option is enabled, to ensure
65139 + that hwclock operates correctly. If hwclock still does not work,
65140 + either update udev or symlink /dev/rtc to /dev/rtc0.
65141 +
65142 + If you're using XFree86 or a version of Xorg from 2012 or earlier,
65143 + you may not be able to boot into a graphical environment with this
65144 + option enabled. In this case, you should use the RBAC system instead.
65145 +
65146 +config GRKERNSEC_JIT_HARDEN
65147 + bool "Harden BPF JIT against spray attacks"
65148 + default y if GRKERNSEC_CONFIG_AUTO
65149 + depends on BPF_JIT && X86
65150 + help
65151 + If you say Y here, the native code generated by the kernel's Berkeley
65152 + Packet Filter (BPF) JIT engine will be hardened against JIT-spraying
65153 + attacks that attempt to fit attacker-beneficial instructions in
65154 + 32bit immediate fields of JIT-generated native instructions. The
65155 + attacker will generally aim to cause an unintended instruction sequence
65156 + of JIT-generated native code to execute by jumping into the middle of
65157 + a generated instruction. This feature effectively randomizes the 32bit
65158 + immediate constants present in the generated code to thwart such attacks.
65159 +
65160 + If you're using KERNEXEC, it's recommended that you enable this option
65161 + to supplement the hardening of the kernel.
65162 +
65163 +config GRKERNSEC_PERF_HARDEN
65164 + bool "Disable unprivileged PERF_EVENTS usage by default"
65165 + default y if GRKERNSEC_CONFIG_AUTO
65166 + depends on PERF_EVENTS
65167 + help
65168 + If you say Y here, the range of acceptable values for the
65169 + /proc/sys/kernel/perf_event_paranoid sysctl will be expanded to allow and
65170 + default to a new value: 3. When the sysctl is set to this value, no
65171 + unprivileged use of the PERF_EVENTS syscall interface will be permitted.
65172 +
65173 + Though PERF_EVENTS can be used legitimately for performance monitoring
65174 + and low-level application profiling, it is forced on regardless of
65175 + configuration, has been at fault for several vulnerabilities, and
65176 + creates new opportunities for side channels and other information leaks.
65177 +
65178 + This feature puts PERF_EVENTS into a secure default state and permits
65179 + the administrator to change out of it temporarily if unprivileged
65180 + application profiling is needed.
65181 +
65182 +config GRKERNSEC_RAND_THREADSTACK
65183 + bool "Insert random gaps between thread stacks"
65184 + default y if GRKERNSEC_CONFIG_AUTO
65185 + depends on PAX_RANDMMAP && !PPC
65186 + help
65187 + If you say Y here, a random-sized gap will be enforced between allocated
65188 + thread stacks. Glibc's NPTL and other threading libraries that
65189 + pass MAP_STACK to the kernel for thread stack allocation are supported.
65190 + The implementation currently provides 8 bits of entropy for the gap.
65191 +
65192 + Many distributions do not compile threaded remote services with the
65193 + -fstack-check argument to GCC, causing the variable-sized stack-based
65194 + allocator, alloca(), to not probe the stack on allocation. This
65195 + permits an unbounded alloca() to skip over any guard page and potentially
65196 + modify another thread's stack reliably. An enforced random gap
65197 + reduces the reliability of such an attack and increases the chance
65198 + that such a read/write to another thread's stack instead lands in
65199 + an unmapped area, causing a crash and triggering grsecurity's
65200 + anti-bruteforcing logic.
65201 +
65202 +config GRKERNSEC_PROC_MEMMAP
65203 + bool "Harden ASLR against information leaks and entropy reduction"
65204 + default y if (GRKERNSEC_CONFIG_AUTO || PAX_NOEXEC || PAX_ASLR)
65205 + depends on PAX_NOEXEC || PAX_ASLR
65206 + help
65207 + If you say Y here, the /proc/<pid>/maps and /proc/<pid>/stat files will
65208 + give no information about the addresses of its mappings if
65209 + PaX features that rely on random addresses are enabled on the task.
65210 + In addition to sanitizing this information and disabling other
65211 + dangerous sources of information, this option causes reads of sensitive
65212 + /proc/<pid> entries where the file descriptor was opened in a different
65213 + task than the one performing the read. Such attempts are logged.
65214 + This option also limits argv/env strings for suid/sgid binaries
65215 + to 512KB to prevent a complete exhaustion of the stack entropy provided
65216 + by ASLR. Finally, it places an 8MB stack resource limit on suid/sgid
65217 + binaries to prevent alternative mmap layouts from being abused.
65218 +
65219 + If you use PaX it is essential that you say Y here as it closes up
65220 + several holes that make full ASLR useless locally.
65221 +
65222 +config GRKERNSEC_BRUTE
65223 + bool "Deter exploit bruteforcing"
65224 + default y if GRKERNSEC_CONFIG_AUTO
65225 + help
65226 + If you say Y here, attempts to bruteforce exploits against forking
65227 + daemons such as apache or sshd, as well as against suid/sgid binaries
65228 + will be deterred. When a child of a forking daemon is killed by PaX
65229 + or crashes due to an illegal instruction or other suspicious signal,
65230 + the parent process will be delayed 30 seconds upon every subsequent
65231 + fork until the administrator is able to assess the situation and
65232 + restart the daemon.
65233 + In the suid/sgid case, the attempt is logged, the user has all their
65234 + existing instances of the suid/sgid binary terminated and will
65235 + be unable to execute any suid/sgid binaries for 15 minutes.
65236 +
65237 + It is recommended that you also enable signal logging in the auditing
65238 + section so that logs are generated when a process triggers a suspicious
65239 + signal.
65240 + If the sysctl option is enabled, a sysctl option with name
65241 + "deter_bruteforce" is created.
65242 +
65243 +config GRKERNSEC_MODHARDEN
65244 + bool "Harden module auto-loading"
65245 + default y if GRKERNSEC_CONFIG_AUTO
65246 + depends on MODULES
65247 + help
65248 + If you say Y here, module auto-loading in response to use of some
65249 + feature implemented by an unloaded module will be restricted to
65250 + root users. Enabling this option helps defend against attacks
65251 + by unprivileged users who abuse the auto-loading behavior to
65252 + cause a vulnerable module to load that is then exploited.
65253 +
65254 + If this option prevents a legitimate use of auto-loading for a
65255 + non-root user, the administrator can execute modprobe manually
65256 + with the exact name of the module mentioned in the alert log.
65257 + Alternatively, the administrator can add the module to the list
65258 + of modules loaded at boot by modifying init scripts.
65259 +
65260 + Modification of init scripts will most likely be needed on
65261 + Ubuntu servers with encrypted home directory support enabled,
65262 + as the first non-root user logging in will cause the ecb(aes),
65263 + ecb(aes)-all, cbc(aes), and cbc(aes)-all modules to be loaded.
65264 +
65265 +config GRKERNSEC_HIDESYM
65266 + bool "Hide kernel symbols"
65267 + default y if GRKERNSEC_CONFIG_AUTO
65268 + select PAX_USERCOPY_SLABS
65269 + help
65270 + If you say Y here, getting information on loaded modules, and
65271 + displaying all kernel symbols through a syscall will be restricted
65272 + to users with CAP_SYS_MODULE. For software compatibility reasons,
65273 + /proc/kallsyms will be restricted to the root user. The RBAC
65274 + system can hide that entry even from root.
65275 +
65276 + This option also prevents leaking of kernel addresses through
65277 + several /proc entries.
65278 +
65279 + Note that this option is only effective provided the following
65280 + conditions are met:
65281 + 1) The kernel using grsecurity is not precompiled by some distribution
65282 + 2) You have also enabled GRKERNSEC_DMESG
65283 + 3) You are using the RBAC system and hiding other files such as your
65284 + kernel image and System.map. Alternatively, enabling this option
65285 + causes the permissions on /boot, /lib/modules, and the kernel
65286 + source directory to change at compile time to prevent
65287 + reading by non-root users.
65288 + If the above conditions are met, this option will aid in providing a
65289 + useful protection against local kernel exploitation of overflows
65290 + and arbitrary read/write vulnerabilities.
65291 +
65292 + It is highly recommended that you enable GRKERNSEC_PERF_HARDEN
65293 + in addition to this feature.
65294 +
65295 +config GRKERNSEC_RANDSTRUCT
65296 + bool "Randomize layout of sensitive kernel structures"
65297 + default y if GRKERNSEC_CONFIG_AUTO
65298 + select GRKERNSEC_HIDESYM
65299 + select MODVERSIONS if MODULES
65300 + help
65301 + If you say Y here, the layouts of a number of sensitive kernel
65302 + structures (task, fs, cred, etc) and all structures composed entirely
65303 + of function pointers (aka "ops" structs) will be randomized at compile-time.
65304 + This can introduce the requirement of an additional infoleak
65305 + vulnerability for exploits targeting these structure types.
65306 +
65307 + Enabling this feature will introduce some performance impact, slightly
65308 + increase memory usage, and prevent the use of forensic tools like
65309 + Volatility against the system (unless the kernel source tree isn't
65310 + cleaned after kernel installation).
65311 +
65312 + The seed used for compilation is located at tools/gcc/randomize_layout_seed.h.
65313 + It remains after a make clean to allow for external modules to be compiled
65314 + with the existing seed and will be removed by a make mrproper or
65315 + make distclean.
65316 +
65317 + Note that the implementation requires gcc 4.6.4. or newer. You may need
65318 + to install the supporting headers explicitly in addition to the normal
65319 + gcc package.
65320 +
65321 +config GRKERNSEC_RANDSTRUCT_PERFORMANCE
65322 + bool "Use cacheline-aware structure randomization"
65323 + depends on GRKERNSEC_RANDSTRUCT
65324 + default y if GRKERNSEC_CONFIG_PRIORITY_PERF
65325 + help
65326 + If you say Y here, the RANDSTRUCT randomization will make a best effort
65327 + at restricting randomization to cacheline-sized groups of elements. It
65328 + will further not randomize bitfields in structures. This reduces the
65329 + performance hit of RANDSTRUCT at the cost of weakened randomization.
65330 +
65331 +config GRKERNSEC_KERN_LOCKOUT
65332 + bool "Active kernel exploit response"
65333 + default y if GRKERNSEC_CONFIG_AUTO
65334 + depends on X86 || ARM || PPC || SPARC
65335 + help
65336 + If you say Y here, when a PaX alert is triggered due to suspicious
65337 + activity in the kernel (from KERNEXEC/UDEREF/USERCOPY)
65338 + or an OOPS occurs due to bad memory accesses, instead of just
65339 + terminating the offending process (and potentially allowing
65340 + a subsequent exploit from the same user), we will take one of two
65341 + actions:
65342 + If the user was root, we will panic the system
65343 + If the user was non-root, we will log the attempt, terminate
65344 + all processes owned by the user, then prevent them from creating
65345 + any new processes until the system is restarted
65346 + This deters repeated kernel exploitation/bruteforcing attempts
65347 + and is useful for later forensics.
65348 +
65349 +config GRKERNSEC_OLD_ARM_USERLAND
65350 + bool "Old ARM userland compatibility"
65351 + depends on ARM && (CPU_V6 || CPU_V6K || CPU_V7)
65352 + help
65353 + If you say Y here, stubs of executable code to perform such operations
65354 + as "compare-exchange" will be placed at fixed locations in the ARM vector
65355 + table. This is unfortunately needed for old ARM userland meant to run
65356 + across a wide range of processors. Without this option enabled,
65357 + the get_tls and data memory barrier stubs will be emulated by the kernel,
65358 + which is enough for Linaro userlands or other userlands designed for v6
65359 + and newer ARM CPUs. It's recommended that you try without this option enabled
65360 + first, and only enable it if your userland does not boot (it will likely fail
65361 + at init time).
65362 +
65363 +endmenu
65364 +menu "Role Based Access Control Options"
65365 +depends on GRKERNSEC
65366 +
65367 +config GRKERNSEC_RBAC_DEBUG
65368 + bool
65369 +
65370 +config GRKERNSEC_NO_RBAC
65371 + bool "Disable RBAC system"
65372 + help
65373 + If you say Y here, the /dev/grsec device will be removed from the kernel,
65374 + preventing the RBAC system from being enabled. You should only say Y
65375 + here if you have no intention of using the RBAC system, so as to prevent
65376 + an attacker with root access from misusing the RBAC system to hide files
65377 + and processes when loadable module support and /dev/[k]mem have been
65378 + locked down.
65379 +
65380 +config GRKERNSEC_ACL_HIDEKERN
65381 + bool "Hide kernel processes"
65382 + help
65383 + If you say Y here, all kernel threads will be hidden to all
65384 + processes but those whose subject has the "view hidden processes"
65385 + flag.
65386 +
65387 +config GRKERNSEC_ACL_MAXTRIES
65388 + int "Maximum tries before password lockout"
65389 + default 3
65390 + help
65391 + This option enforces the maximum number of times a user can attempt
65392 + to authorize themselves with the grsecurity RBAC system before being
65393 + denied the ability to attempt authorization again for a specified time.
65394 + The lower the number, the harder it will be to brute-force a password.
65395 +
65396 +config GRKERNSEC_ACL_TIMEOUT
65397 + int "Time to wait after max password tries, in seconds"
65398 + default 30
65399 + help
65400 + This option specifies the time the user must wait after attempting to
65401 + authorize to the RBAC system with the maximum number of invalid
65402 + passwords. The higher the number, the harder it will be to brute-force
65403 + a password.
65404 +
65405 +endmenu
65406 +menu "Filesystem Protections"
65407 +depends on GRKERNSEC
65408 +
65409 +config GRKERNSEC_PROC
65410 + bool "Proc restrictions"
65411 + default y if GRKERNSEC_CONFIG_AUTO
65412 + help
65413 + If you say Y here, the permissions of the /proc filesystem
65414 + will be altered to enhance system security and privacy. You MUST
65415 + choose either a user only restriction or a user and group restriction.
65416 + Depending upon the option you choose, you can either restrict users to
65417 + see only the processes they themselves run, or choose a group that can
65418 + view all processes and files normally restricted to root if you choose
65419 + the "restrict to user only" option. NOTE: If you're running identd or
65420 + ntpd as a non-root user, you will have to run it as the group you
65421 + specify here.
65422 +
65423 +config GRKERNSEC_PROC_USER
65424 + bool "Restrict /proc to user only"
65425 + depends on GRKERNSEC_PROC
65426 + help
65427 + If you say Y here, non-root users will only be able to view their own
65428 + processes, and restricts them from viewing network-related information,
65429 + and viewing kernel symbol and module information.
65430 +
65431 +config GRKERNSEC_PROC_USERGROUP
65432 + bool "Allow special group"
65433 + default y if GRKERNSEC_CONFIG_AUTO
65434 + depends on GRKERNSEC_PROC && !GRKERNSEC_PROC_USER
65435 + help
65436 + If you say Y here, you will be able to select a group that will be
65437 + able to view all processes and network-related information. If you've
65438 + enabled GRKERNSEC_HIDESYM, kernel and symbol information may still
65439 + remain hidden. This option is useful if you want to run identd as
65440 + a non-root user. The group you select may also be chosen at boot time
65441 + via "grsec_proc_gid=" on the kernel commandline.
65442 +
65443 +config GRKERNSEC_PROC_GID
65444 + int "GID for special group"
65445 + depends on GRKERNSEC_PROC_USERGROUP
65446 + default 1001
65447 +
65448 +config GRKERNSEC_PROC_ADD
65449 + bool "Additional restrictions"
65450 + default y if GRKERNSEC_CONFIG_AUTO
65451 + depends on GRKERNSEC_PROC_USER || GRKERNSEC_PROC_USERGROUP
65452 + help
65453 + If you say Y here, additional restrictions will be placed on
65454 + /proc that keep normal users from viewing device information and
65455 + slabinfo information that could be useful for exploits.
65456 +
65457 +config GRKERNSEC_LINK
65458 + bool "Linking restrictions"
65459 + default y if GRKERNSEC_CONFIG_AUTO
65460 + help
65461 + If you say Y here, /tmp race exploits will be prevented, since users
65462 + will no longer be able to follow symlinks owned by other users in
65463 + world-writable +t directories (e.g. /tmp), unless the owner of the
65464 + symlink is the owner of the directory. users will also not be
65465 + able to hardlink to files they do not own. If the sysctl option is
65466 + enabled, a sysctl option with name "linking_restrictions" is created.
65467 +
65468 +config GRKERNSEC_SYMLINKOWN
65469 + bool "Kernel-enforced SymlinksIfOwnerMatch"
65470 + default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
65471 + help
65472 + Apache's SymlinksIfOwnerMatch option has an inherent race condition
65473 + that prevents it from being used as a security feature. As Apache
65474 + verifies the symlink by performing a stat() against the target of
65475 + the symlink before it is followed, an attacker can setup a symlink
65476 + to point to a same-owned file, then replace the symlink with one
65477 + that targets another user's file just after Apache "validates" the
65478 + symlink -- a classic TOCTOU race. If you say Y here, a complete,
65479 + race-free replacement for Apache's "SymlinksIfOwnerMatch" option
65480 + will be in place for the group you specify. If the sysctl option
65481 + is enabled, a sysctl option with name "enforce_symlinksifowner" is
65482 + created.
65483 +
65484 +config GRKERNSEC_SYMLINKOWN_GID
65485 + int "GID for users with kernel-enforced SymlinksIfOwnerMatch"
65486 + depends on GRKERNSEC_SYMLINKOWN
65487 + default 1006
65488 + help
65489 + Setting this GID determines what group kernel-enforced
65490 + SymlinksIfOwnerMatch will be enabled for. If the sysctl option
65491 + is enabled, a sysctl option with name "symlinkown_gid" is created.
65492 +
65493 +config GRKERNSEC_FIFO
65494 + bool "FIFO restrictions"
65495 + default y if GRKERNSEC_CONFIG_AUTO
65496 + help
65497 + If you say Y here, users will not be able to write to FIFOs they don't
65498 + own in world-writable +t directories (e.g. /tmp), unless the owner of
65499 + the FIFO is the same owner of the directory it's held in. If the sysctl
65500 + option is enabled, a sysctl option with name "fifo_restrictions" is
65501 + created.
65502 +
65503 +config GRKERNSEC_SYSFS_RESTRICT
65504 + bool "Sysfs/debugfs restriction"
65505 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
65506 + depends on SYSFS
65507 + help
65508 + If you say Y here, sysfs (the pseudo-filesystem mounted at /sys) and
65509 + any filesystem normally mounted under it (e.g. debugfs) will be
65510 + mostly accessible only by root. These filesystems generally provide access
65511 + to hardware and debug information that isn't appropriate for unprivileged
65512 + users of the system. Sysfs and debugfs have also become a large source
65513 + of new vulnerabilities, ranging from infoleaks to local compromise.
65514 + There has been very little oversight with an eye toward security involved
65515 + in adding new exporters of information to these filesystems, so their
65516 + use is discouraged.
65517 + For reasons of compatibility, a few directories have been whitelisted
65518 + for access by non-root users:
65519 + /sys/fs/selinux
65520 + /sys/fs/fuse
65521 + /sys/devices/system/cpu
65522 +
65523 +config GRKERNSEC_ROFS
65524 + bool "Runtime read-only mount protection"
65525 + depends on SYSCTL
65526 + help
65527 + If you say Y here, a sysctl option with name "romount_protect" will
65528 + be created. By setting this option to 1 at runtime, filesystems
65529 + will be protected in the following ways:
65530 + * No new writable mounts will be allowed
65531 + * Existing read-only mounts won't be able to be remounted read/write
65532 + * Write operations will be denied on all block devices
65533 + This option acts independently of grsec_lock: once it is set to 1,
65534 + it cannot be turned off. Therefore, please be mindful of the resulting
65535 + behavior if this option is enabled in an init script on a read-only
65536 + filesystem.
65537 + Also be aware that as with other root-focused features, GRKERNSEC_KMEM
65538 + and GRKERNSEC_IO should be enabled and module loading disabled via
65539 + config or at runtime.
65540 + This feature is mainly intended for secure embedded systems.
65541 +
65542 +
65543 +config GRKERNSEC_DEVICE_SIDECHANNEL
65544 + bool "Eliminate stat/notify-based device sidechannels"
65545 + default y if GRKERNSEC_CONFIG_AUTO
65546 + help
65547 + If you say Y here, timing analyses on block or character
65548 + devices like /dev/ptmx using stat or inotify/dnotify/fanotify
65549 + will be thwarted for unprivileged users. If a process without
65550 + CAP_MKNOD stats such a device, the last access and last modify times
65551 + will match the device's create time. No access or modify events
65552 + will be triggered through inotify/dnotify/fanotify for such devices.
65553 + This feature will prevent attacks that may at a minimum
65554 + allow an attacker to determine the administrator's password length.
65555 +
65556 +config GRKERNSEC_CHROOT
65557 + bool "Chroot jail restrictions"
65558 + default y if GRKERNSEC_CONFIG_AUTO
65559 + help
65560 + If you say Y here, you will be able to choose several options that will
65561 + make breaking out of a chrooted jail much more difficult. If you
65562 + encounter no software incompatibilities with the following options, it
65563 + is recommended that you enable each one.
65564 +
65565 + Note that the chroot restrictions are not intended to apply to "chroots"
65566 + to directories that are simple bind mounts of the global root filesystem.
65567 + For several other reasons, a user shouldn't expect any significant
65568 + security by performing such a chroot.
65569 +
65570 +config GRKERNSEC_CHROOT_MOUNT
65571 + bool "Deny mounts"
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
65576 + mount or remount filesystems. If the sysctl option is enabled, a
65577 + sysctl option with name "chroot_deny_mount" is created.
65578 +
65579 +config GRKERNSEC_CHROOT_DOUBLE
65580 + bool "Deny double-chroots"
65581 + default y if GRKERNSEC_CONFIG_AUTO
65582 + depends on GRKERNSEC_CHROOT
65583 + help
65584 + If you say Y here, processes inside a chroot will not be able to chroot
65585 + again outside the chroot. This is a widely used method of breaking
65586 + out of a chroot jail and should not be allowed. If the sysctl
65587 + option is enabled, a sysctl option with name
65588 + "chroot_deny_chroot" is created.
65589 +
65590 +config GRKERNSEC_CHROOT_PIVOT
65591 + bool "Deny pivot_root in chroot"
65592 + default y if GRKERNSEC_CONFIG_AUTO
65593 + depends on GRKERNSEC_CHROOT
65594 + help
65595 + If you say Y here, processes inside a chroot will not be able to use
65596 + a function called pivot_root() that was introduced in Linux 2.3.41. It
65597 + works similar to chroot in that it changes the root filesystem. This
65598 + function could be misused in a chrooted process to attempt to break out
65599 + of the chroot, and therefore should not be allowed. If the sysctl
65600 + option is enabled, a sysctl option with name "chroot_deny_pivot" is
65601 + created.
65602 +
65603 +config GRKERNSEC_CHROOT_CHDIR
65604 + bool "Enforce chdir(\"/\") on all chroots"
65605 + default y if GRKERNSEC_CONFIG_AUTO
65606 + depends on GRKERNSEC_CHROOT
65607 + help
65608 + If you say Y here, the current working directory of all newly-chrooted
65609 + applications will be set to the the root directory of the chroot.
65610 + The man page on chroot(2) states:
65611 + Note that this call does not change the current working
65612 + directory, so that `.' can be outside the tree rooted at
65613 + `/'. In particular, the super-user can escape from a
65614 + `chroot jail' by doing `mkdir foo; chroot foo; cd ..'.
65615 +
65616 + It is recommended that you say Y here, since it's not known to break
65617 + any software. If the sysctl option is enabled, a sysctl option with
65618 + name "chroot_enforce_chdir" is created.
65619 +
65620 +config GRKERNSEC_CHROOT_CHMOD
65621 + bool "Deny (f)chmod +s"
65622 + default y if GRKERNSEC_CONFIG_AUTO
65623 + depends on GRKERNSEC_CHROOT
65624 + help
65625 + If you say Y here, processes inside a chroot will not be able to chmod
65626 + or fchmod files to make them have suid or sgid bits. This protects
65627 + against another published method of breaking a chroot. If the sysctl
65628 + option is enabled, a sysctl option with name "chroot_deny_chmod" is
65629 + created.
65630 +
65631 +config GRKERNSEC_CHROOT_FCHDIR
65632 + bool "Deny fchdir out of chroot"
65633 + default y if GRKERNSEC_CONFIG_AUTO
65634 + depends on GRKERNSEC_CHROOT
65635 + help
65636 + If you say Y here, a well-known method of breaking chroots by fchdir'ing
65637 + to a file descriptor of the chrooting process that points to a directory
65638 + outside the filesystem will be stopped. If the sysctl option
65639 + is enabled, a sysctl option with name "chroot_deny_fchdir" is created.
65640 +
65641 +config GRKERNSEC_CHROOT_MKNOD
65642 + bool "Deny mknod"
65643 + default y if GRKERNSEC_CONFIG_AUTO
65644 + depends on GRKERNSEC_CHROOT
65645 + help
65646 + If you say Y here, processes inside a chroot will not be allowed to
65647 + mknod. The problem with using mknod inside a chroot is that it
65648 + would allow an attacker to create a device entry that is the same
65649 + as one on the physical root of your system, which could range from
65650 + anything from the console device to a device for your harddrive (which
65651 + they could then use to wipe the drive or steal data). It is recommended
65652 + that you say Y here, unless you run into software incompatibilities.
65653 + If the sysctl option is enabled, a sysctl option with name
65654 + "chroot_deny_mknod" is created.
65655 +
65656 +config GRKERNSEC_CHROOT_SHMAT
65657 + bool "Deny shmat() out of chroot"
65658 + default y if GRKERNSEC_CONFIG_AUTO
65659 + depends on GRKERNSEC_CHROOT
65660 + help
65661 + If you say Y here, processes inside a chroot will not be able to attach
65662 + to shared memory segments that were created outside of the chroot jail.
65663 + It is recommended that you say Y here. If the sysctl option is enabled,
65664 + a sysctl option with name "chroot_deny_shmat" is created.
65665 +
65666 +config GRKERNSEC_CHROOT_UNIX
65667 + bool "Deny access to abstract AF_UNIX sockets out of chroot"
65668 + default y if GRKERNSEC_CONFIG_AUTO
65669 + depends on GRKERNSEC_CHROOT
65670 + help
65671 + If you say Y here, processes inside a chroot will not be able to
65672 + connect to abstract (meaning not belonging to a filesystem) Unix
65673 + domain sockets that were bound outside of a chroot. It is recommended
65674 + that you say Y here. If the sysctl option is enabled, a sysctl option
65675 + with name "chroot_deny_unix" is created.
65676 +
65677 +config GRKERNSEC_CHROOT_FINDTASK
65678 + bool "Protect outside processes"
65679 + default y if GRKERNSEC_CONFIG_AUTO
65680 + depends on GRKERNSEC_CHROOT
65681 + help
65682 + If you say Y here, processes inside a chroot will not be able to
65683 + kill, send signals with fcntl, ptrace, capget, getpgid, setpgid,
65684 + getsid, or view any process outside of the chroot. If the sysctl
65685 + option is enabled, a sysctl option with name "chroot_findtask" is
65686 + created.
65687 +
65688 +config GRKERNSEC_CHROOT_NICE
65689 + bool "Restrict priority changes"
65690 + default y if GRKERNSEC_CONFIG_AUTO
65691 + depends on GRKERNSEC_CHROOT
65692 + help
65693 + If you say Y here, processes inside a chroot will not be able to raise
65694 + the priority of processes in the chroot, or alter the priority of
65695 + processes outside the chroot. This provides more security than simply
65696 + removing CAP_SYS_NICE from the process' capability set. If the
65697 + sysctl option is enabled, a sysctl option with name "chroot_restrict_nice"
65698 + is created.
65699 +
65700 +config GRKERNSEC_CHROOT_SYSCTL
65701 + bool "Deny sysctl writes"
65702 + default y if GRKERNSEC_CONFIG_AUTO
65703 + depends on GRKERNSEC_CHROOT
65704 + help
65705 + If you say Y here, an attacker in a chroot will not be able to
65706 + write to sysctl entries, either by sysctl(2) or through a /proc
65707 + interface. It is strongly recommended that you say Y here. If the
65708 + sysctl option is enabled, a sysctl option with name
65709 + "chroot_deny_sysctl" is created.
65710 +
65711 +config GRKERNSEC_CHROOT_CAPS
65712 + bool "Capability restrictions"
65713 + default y if GRKERNSEC_CONFIG_AUTO
65714 + depends on GRKERNSEC_CHROOT
65715 + help
65716 + If you say Y here, the capabilities on all processes within a
65717 + chroot jail will be lowered to stop module insertion, raw i/o,
65718 + system and net admin tasks, rebooting the system, modifying immutable
65719 + files, modifying IPC owned by another, and changing the system time.
65720 + This is left an option because it can break some apps. Disable this
65721 + if your chrooted apps are having problems performing those kinds of
65722 + tasks. If the sysctl option is enabled, a sysctl option with
65723 + name "chroot_caps" is created.
65724 +
65725 +config GRKERNSEC_CHROOT_INITRD
65726 + bool "Exempt initrd tasks from restrictions"
65727 + default y if GRKERNSEC_CONFIG_AUTO
65728 + depends on GRKERNSEC_CHROOT && BLK_DEV_INITRD
65729 + help
65730 + If you say Y here, tasks started prior to init will be exempted from
65731 + grsecurity's chroot restrictions. This option is mainly meant to
65732 + resolve Plymouth's performing privileged operations unnecessarily
65733 + in a chroot.
65734 +
65735 +endmenu
65736 +menu "Kernel Auditing"
65737 +depends on GRKERNSEC
65738 +
65739 +config GRKERNSEC_AUDIT_GROUP
65740 + bool "Single group for auditing"
65741 + help
65742 + If you say Y here, the exec and chdir logging features will only operate
65743 + on a group you specify. This option is recommended if you only want to
65744 + watch certain users instead of having a large amount of logs from the
65745 + entire system. If the sysctl option is enabled, a sysctl option with
65746 + name "audit_group" is created.
65747 +
65748 +config GRKERNSEC_AUDIT_GID
65749 + int "GID for auditing"
65750 + depends on GRKERNSEC_AUDIT_GROUP
65751 + default 1007
65752 +
65753 +config GRKERNSEC_EXECLOG
65754 + bool "Exec logging"
65755 + help
65756 + If you say Y here, all execve() calls will be logged (since the
65757 + other exec*() calls are frontends to execve(), all execution
65758 + will be logged). Useful for shell-servers that like to keep track
65759 + of their users. If the sysctl option is enabled, a sysctl option with
65760 + name "exec_logging" is created.
65761 + WARNING: This option when enabled will produce a LOT of logs, especially
65762 + on an active system.
65763 +
65764 +config GRKERNSEC_RESLOG
65765 + bool "Resource logging"
65766 + default y if GRKERNSEC_CONFIG_AUTO
65767 + help
65768 + If you say Y here, all attempts to overstep resource limits will
65769 + be logged with the resource name, the requested size, and the current
65770 + limit. It is highly recommended that you say Y here. If the sysctl
65771 + option is enabled, a sysctl option with name "resource_logging" is
65772 + created. If the RBAC system is enabled, the sysctl value is ignored.
65773 +
65774 +config GRKERNSEC_CHROOT_EXECLOG
65775 + bool "Log execs within chroot"
65776 + help
65777 + If you say Y here, all executions inside a chroot jail will be logged
65778 + to syslog. This can cause a large amount of logs if certain
65779 + applications (eg. djb's daemontools) are installed on the system, and
65780 + is therefore left as an option. If the sysctl option is enabled, a
65781 + sysctl option with name "chroot_execlog" is created.
65782 +
65783 +config GRKERNSEC_AUDIT_PTRACE
65784 + bool "Ptrace logging"
65785 + help
65786 + If you say Y here, all attempts to attach to a process via ptrace
65787 + will be logged. If the sysctl option is enabled, a sysctl option
65788 + with name "audit_ptrace" is created.
65789 +
65790 +config GRKERNSEC_AUDIT_CHDIR
65791 + bool "Chdir logging"
65792 + help
65793 + If you say Y here, all chdir() calls will be logged. If the sysctl
65794 + option is enabled, a sysctl option with name "audit_chdir" is created.
65795 +
65796 +config GRKERNSEC_AUDIT_MOUNT
65797 + bool "(Un)Mount logging"
65798 + help
65799 + If you say Y here, all mounts and unmounts will be logged. If the
65800 + sysctl option is enabled, a sysctl option with name "audit_mount" is
65801 + created.
65802 +
65803 +config GRKERNSEC_SIGNAL
65804 + bool "Signal logging"
65805 + default y if GRKERNSEC_CONFIG_AUTO
65806 + help
65807 + If you say Y here, certain important signals will be logged, such as
65808 + SIGSEGV, which will as a result inform you of when a error in a program
65809 + occurred, which in some cases could mean a possible exploit attempt.
65810 + If the sysctl option is enabled, a sysctl option with name
65811 + "signal_logging" is created.
65812 +
65813 +config GRKERNSEC_FORKFAIL
65814 + bool "Fork failure logging"
65815 + help
65816 + If you say Y here, all failed fork() attempts will be logged.
65817 + This could suggest a fork bomb, or someone attempting to overstep
65818 + their process limit. If the sysctl option is enabled, a sysctl option
65819 + with name "forkfail_logging" is created.
65820 +
65821 +config GRKERNSEC_TIME
65822 + bool "Time change logging"
65823 + default y if GRKERNSEC_CONFIG_AUTO
65824 + help
65825 + If you say Y here, any changes of the system clock will be logged.
65826 + If the sysctl option is enabled, a sysctl option with name
65827 + "timechange_logging" is created.
65828 +
65829 +config GRKERNSEC_PROC_IPADDR
65830 + bool "/proc/<pid>/ipaddr support"
65831 + default y if GRKERNSEC_CONFIG_AUTO
65832 + help
65833 + If you say Y here, a new entry will be added to each /proc/<pid>
65834 + directory that contains the IP address of the person using the task.
65835 + The IP is carried across local TCP and AF_UNIX stream sockets.
65836 + This information can be useful for IDS/IPSes to perform remote response
65837 + to a local attack. The entry is readable by only the owner of the
65838 + process (and root if he has CAP_DAC_OVERRIDE, which can be removed via
65839 + the RBAC system), and thus does not create privacy concerns.
65840 +
65841 +config GRKERNSEC_RWXMAP_LOG
65842 + bool 'Denied RWX mmap/mprotect logging'
65843 + default y if GRKERNSEC_CONFIG_AUTO
65844 + depends on PAX_MPROTECT && !PAX_EMUPLT && !PAX_EMUSIGRT
65845 + help
65846 + If you say Y here, calls to mmap() and mprotect() with explicit
65847 + usage of PROT_WRITE and PROT_EXEC together will be logged when
65848 + denied by the PAX_MPROTECT feature. This feature will also
65849 + log other problematic scenarios that can occur when PAX_MPROTECT
65850 + is enabled on a binary, like textrels and PT_GNU_STACK. If the
65851 + sysctl option is enabled, a sysctl option with name "rwxmap_logging"
65852 + is created.
65853 +
65854 +endmenu
65855 +
65856 +menu "Executable Protections"
65857 +depends on GRKERNSEC
65858 +
65859 +config GRKERNSEC_DMESG
65860 + bool "Dmesg(8) restriction"
65861 + default y if GRKERNSEC_CONFIG_AUTO
65862 + help
65863 + If you say Y here, non-root users will not be able to use dmesg(8)
65864 + to view the contents of the kernel's circular log buffer.
65865 + The kernel's log buffer often contains kernel addresses and other
65866 + identifying information useful to an attacker in fingerprinting a
65867 + system for a targeted exploit.
65868 + If the sysctl option is enabled, a sysctl option with name "dmesg" is
65869 + created.
65870 +
65871 +config GRKERNSEC_HARDEN_PTRACE
65872 + bool "Deter ptrace-based process snooping"
65873 + default y if GRKERNSEC_CONFIG_AUTO
65874 + help
65875 + If you say Y here, TTY sniffers and other malicious monitoring
65876 + programs implemented through ptrace will be defeated. If you
65877 + have been using the RBAC system, this option has already been
65878 + enabled for several years for all users, with the ability to make
65879 + fine-grained exceptions.
65880 +
65881 + This option only affects the ability of non-root users to ptrace
65882 + processes that are not a descendent of the ptracing process.
65883 + This means that strace ./binary and gdb ./binary will still work,
65884 + but attaching to arbitrary processes will not. If the sysctl
65885 + option is enabled, a sysctl option with name "harden_ptrace" is
65886 + created.
65887 +
65888 +config GRKERNSEC_PTRACE_READEXEC
65889 + bool "Require read access to ptrace sensitive binaries"
65890 + default y if GRKERNSEC_CONFIG_AUTO
65891 + help
65892 + If you say Y here, unprivileged users will not be able to ptrace unreadable
65893 + binaries. This option is useful in environments that
65894 + remove the read bits (e.g. file mode 4711) from suid binaries to
65895 + prevent infoleaking of their contents. This option adds
65896 + consistency to the use of that file mode, as the binary could normally
65897 + be read out when run without privileges while ptracing.
65898 +
65899 + If the sysctl option is enabled, a sysctl option with name "ptrace_readexec"
65900 + is created.
65901 +
65902 +config GRKERNSEC_SETXID
65903 + bool "Enforce consistent multithreaded privileges"
65904 + default y if GRKERNSEC_CONFIG_AUTO
65905 + depends on (X86 || SPARC64 || PPC || ARM || MIPS)
65906 + help
65907 + If you say Y here, a change from a root uid to a non-root uid
65908 + in a multithreaded application will cause the resulting uids,
65909 + gids, supplementary groups, and capabilities in that thread
65910 + to be propagated to the other threads of the process. In most
65911 + cases this is unnecessary, as glibc will emulate this behavior
65912 + on behalf of the application. Other libcs do not act in the
65913 + same way, allowing the other threads of the process to continue
65914 + running with root privileges. If the sysctl option is enabled,
65915 + a sysctl option with name "consistent_setxid" is created.
65916 +
65917 +config GRKERNSEC_HARDEN_IPC
65918 + bool "Disallow access to overly-permissive IPC objects"
65919 + default y if GRKERNSEC_CONFIG_AUTO
65920 + depends on SYSVIPC
65921 + help
65922 + If you say Y here, access to overly-permissive IPC objects (shared
65923 + memory, message queues, and semaphores) will be denied for processes
65924 + given the following criteria beyond normal permission checks:
65925 + 1) If the IPC object is world-accessible and the euid doesn't match
65926 + that of the creator or current uid for the IPC object
65927 + 2) If the IPC object is group-accessible and the egid doesn't
65928 + match that of the creator or current gid for the IPC object
65929 + It's a common error to grant too much permission to these objects,
65930 + with impact ranging from denial of service and information leaking to
65931 + privilege escalation. This feature was developed in response to
65932 + research by Tim Brown:
65933 + http://labs.portcullis.co.uk/whitepapers/memory-squatting-attacks-on-system-v-shared-memory/
65934 + who found hundreds of such insecure usages. Processes with
65935 + CAP_IPC_OWNER are still permitted to access these IPC objects.
65936 + If the sysctl option is enabled, a sysctl option with name
65937 + "harden_ipc" is created.
65938 +
65939 +config GRKERNSEC_TPE
65940 + bool "Trusted Path Execution (TPE)"
65941 + default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
65942 + help
65943 + If you say Y here, you will be able to choose a gid to add to the
65944 + supplementary groups of users you want to mark as "untrusted."
65945 + These users will not be able to execute any files that are not in
65946 + root-owned directories writable only by root. If the sysctl option
65947 + is enabled, a sysctl option with name "tpe" is created.
65948 +
65949 +config GRKERNSEC_TPE_ALL
65950 + bool "Partially restrict all non-root users"
65951 + depends on GRKERNSEC_TPE
65952 + help
65953 + If you say Y here, all non-root users will be covered under
65954 + a weaker TPE restriction. This is separate from, and in addition to,
65955 + the main TPE options that you have selected elsewhere. Thus, if a
65956 + "trusted" GID is chosen, this restriction applies to even that GID.
65957 + Under this restriction, all non-root users will only be allowed to
65958 + execute files in directories they own that are not group or
65959 + world-writable, or in directories owned by root and writable only by
65960 + root. If the sysctl option is enabled, a sysctl option with name
65961 + "tpe_restrict_all" is created.
65962 +
65963 +config GRKERNSEC_TPE_INVERT
65964 + bool "Invert GID option"
65965 + depends on GRKERNSEC_TPE
65966 + help
65967 + If you say Y here, the group you specify in the TPE configuration will
65968 + decide what group TPE restrictions will be *disabled* for. This
65969 + option is useful if you want TPE restrictions to be applied to most
65970 + users on the system. If the sysctl option is enabled, a sysctl option
65971 + with name "tpe_invert" is created. Unlike other sysctl options, this
65972 + entry will default to on for backward-compatibility.
65973 +
65974 +config GRKERNSEC_TPE_GID
65975 + int
65976 + default GRKERNSEC_TPE_UNTRUSTED_GID if (GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT)
65977 + default GRKERNSEC_TPE_TRUSTED_GID if (GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT)
65978 +
65979 +config GRKERNSEC_TPE_UNTRUSTED_GID
65980 + int "GID for TPE-untrusted users"
65981 + depends on GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT
65982 + default 1005
65983 + help
65984 + Setting this GID determines what group TPE restrictions will be
65985 + *enabled* for. If the sysctl option is enabled, a sysctl option
65986 + with name "tpe_gid" is created.
65987 +
65988 +config GRKERNSEC_TPE_TRUSTED_GID
65989 + int "GID for TPE-trusted users"
65990 + depends on GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT
65991 + default 1005
65992 + help
65993 + Setting this GID determines what group TPE restrictions will be
65994 + *disabled* for. If the sysctl option is enabled, a sysctl option
65995 + with name "tpe_gid" is created.
65996 +
65997 +endmenu
65998 +menu "Network Protections"
65999 +depends on GRKERNSEC
66000 +
66001 +config GRKERNSEC_RANDNET
66002 + bool "Larger entropy pools"
66003 + default y if GRKERNSEC_CONFIG_AUTO
66004 + help
66005 + If you say Y here, the entropy pools used for many features of Linux
66006 + and grsecurity will be doubled in size. Since several grsecurity
66007 + features use additional randomness, it is recommended that you say Y
66008 + here. Saying Y here has a similar effect as modifying
66009 + /proc/sys/kernel/random/poolsize.
66010 +
66011 +config GRKERNSEC_BLACKHOLE
66012 + bool "TCP/UDP blackhole and LAST_ACK DoS prevention"
66013 + default y if GRKERNSEC_CONFIG_AUTO
66014 + depends on NET
66015 + help
66016 + If you say Y here, neither TCP resets nor ICMP
66017 + destination-unreachable packets will be sent in response to packets
66018 + sent to ports for which no associated listening process exists.
66019 + This feature supports both IPV4 and IPV6 and exempts the
66020 + loopback interface from blackholing. Enabling this feature
66021 + makes a host more resilient to DoS attacks and reduces network
66022 + visibility against scanners.
66023 +
66024 + The blackhole feature as-implemented is equivalent to the FreeBSD
66025 + blackhole feature, as it prevents RST responses to all packets, not
66026 + just SYNs. Under most application behavior this causes no
66027 + problems, but applications (like haproxy) may not close certain
66028 + connections in a way that cleanly terminates them on the remote
66029 + end, leaving the remote host in LAST_ACK state. Because of this
66030 + side-effect and to prevent intentional LAST_ACK DoSes, this
66031 + feature also adds automatic mitigation against such attacks.
66032 + The mitigation drastically reduces the amount of time a socket
66033 + can spend in LAST_ACK state. If you're using haproxy and not
66034 + all servers it connects to have this option enabled, consider
66035 + disabling this feature on the haproxy host.
66036 +
66037 + If the sysctl option is enabled, two sysctl options with names
66038 + "ip_blackhole" and "lastack_retries" will be created.
66039 + While "ip_blackhole" takes the standard zero/non-zero on/off
66040 + toggle, "lastack_retries" uses the same kinds of values as
66041 + "tcp_retries1" and "tcp_retries2". The default value of 4
66042 + prevents a socket from lasting more than 45 seconds in LAST_ACK
66043 + state.
66044 +
66045 +config GRKERNSEC_NO_SIMULT_CONNECT
66046 + bool "Disable TCP Simultaneous Connect"
66047 + default y if GRKERNSEC_CONFIG_AUTO
66048 + depends on NET
66049 + help
66050 + If you say Y here, a feature by Willy Tarreau will be enabled that
66051 + removes a weakness in Linux's strict implementation of TCP that
66052 + allows two clients to connect to each other without either entering
66053 + a listening state. The weakness allows an attacker to easily prevent
66054 + a client from connecting to a known server provided the source port
66055 + for the connection is guessed correctly.
66056 +
66057 + As the weakness could be used to prevent an antivirus or IPS from
66058 + fetching updates, or prevent an SSL gateway from fetching a CRL,
66059 + it should be eliminated by enabling this option. Though Linux is
66060 + one of few operating systems supporting simultaneous connect, it
66061 + has no legitimate use in practice and is rarely supported by firewalls.
66062 +
66063 +config GRKERNSEC_SOCKET
66064 + bool "Socket restrictions"
66065 + depends on NET
66066 + help
66067 + If you say Y here, you will be able to choose from several options.
66068 + If you assign a GID on your system and add it to the supplementary
66069 + groups of users you want to restrict socket access to, this patch
66070 + will perform up to three things, based on the option(s) you choose.
66071 +
66072 +config GRKERNSEC_SOCKET_ALL
66073 + bool "Deny any sockets to group"
66074 + depends on GRKERNSEC_SOCKET
66075 + help
66076 + If you say Y here, you will be able to choose a GID of whose users will
66077 + be unable to connect to other hosts from your machine or run server
66078 + applications from your machine. If the sysctl option is enabled, a
66079 + sysctl option with name "socket_all" is created.
66080 +
66081 +config GRKERNSEC_SOCKET_ALL_GID
66082 + int "GID to deny all sockets for"
66083 + depends on GRKERNSEC_SOCKET_ALL
66084 + default 1004
66085 + help
66086 + Here you can choose the GID to disable socket access for. Remember to
66087 + add the users you want socket access disabled for to the GID
66088 + specified here. If the sysctl option is enabled, a sysctl option
66089 + with name "socket_all_gid" is created.
66090 +
66091 +config GRKERNSEC_SOCKET_CLIENT
66092 + bool "Deny client sockets to group"
66093 + depends on GRKERNSEC_SOCKET
66094 + help
66095 + If you say Y here, you will be able to choose a GID of whose users will
66096 + be unable to connect to other hosts from your machine, but will be
66097 + able to run servers. If this option is enabled, all users in the group
66098 + you specify will have to use passive mode when initiating ftp transfers
66099 + from the shell on your machine. If the sysctl option is enabled, a
66100 + sysctl option with name "socket_client" is created.
66101 +
66102 +config GRKERNSEC_SOCKET_CLIENT_GID
66103 + int "GID to deny client sockets for"
66104 + depends on GRKERNSEC_SOCKET_CLIENT
66105 + default 1003
66106 + help
66107 + Here you can choose the GID to disable client socket access for.
66108 + Remember to add the users you want client socket access disabled for to
66109 + the GID specified here. If the sysctl option is enabled, a sysctl
66110 + option with name "socket_client_gid" is created.
66111 +
66112 +config GRKERNSEC_SOCKET_SERVER
66113 + bool "Deny server sockets to group"
66114 + depends on GRKERNSEC_SOCKET
66115 + help
66116 + If you say Y here, you will be able to choose a GID of whose users will
66117 + be unable to run server applications from your machine. If the sysctl
66118 + option is enabled, a sysctl option with name "socket_server" is created.
66119 +
66120 +config GRKERNSEC_SOCKET_SERVER_GID
66121 + int "GID to deny server sockets for"
66122 + depends on GRKERNSEC_SOCKET_SERVER
66123 + default 1002
66124 + help
66125 + Here you can choose the GID to disable server socket access for.
66126 + Remember to add the users you want server socket access disabled for to
66127 + the GID specified here. If the sysctl option is enabled, a sysctl
66128 + option with name "socket_server_gid" is created.
66129 +
66130 +endmenu
66131 +
66132 +menu "Physical Protections"
66133 +depends on GRKERNSEC
66134 +
66135 +config GRKERNSEC_DENYUSB
66136 + bool "Deny new USB connections after toggle"
66137 + default y if GRKERNSEC_CONFIG_AUTO
66138 + depends on SYSCTL && USB_SUPPORT
66139 + help
66140 + If you say Y here, a new sysctl option with name "deny_new_usb"
66141 + will be created. Setting its value to 1 will prevent any new
66142 + USB devices from being recognized by the OS. Any attempted USB
66143 + device insertion will be logged. This option is intended to be
66144 + used against custom USB devices designed to exploit vulnerabilities
66145 + in various USB device drivers.
66146 +
66147 + For greatest effectiveness, this sysctl should be set after any
66148 + relevant init scripts. This option is safe to enable in distros
66149 + as each user can choose whether or not to toggle the sysctl.
66150 +
66151 +config GRKERNSEC_DENYUSB_FORCE
66152 + bool "Reject all USB devices not connected at boot"
66153 + select USB
66154 + depends on GRKERNSEC_DENYUSB
66155 + help
66156 + If you say Y here, a variant of GRKERNSEC_DENYUSB will be enabled
66157 + that doesn't involve a sysctl entry. This option should only be
66158 + enabled if you're sure you want to deny all new USB connections
66159 + at runtime and don't want to modify init scripts. This should not
66160 + be enabled by distros. It forces the core USB code to be built
66161 + into the kernel image so that all devices connected at boot time
66162 + can be recognized and new USB device connections can be prevented
66163 + prior to init running.
66164 +
66165 +endmenu
66166 +
66167 +menu "Sysctl Support"
66168 +depends on GRKERNSEC && SYSCTL
66169 +
66170 +config GRKERNSEC_SYSCTL
66171 + bool "Sysctl support"
66172 + default y if GRKERNSEC_CONFIG_AUTO
66173 + help
66174 + If you say Y here, you will be able to change the options that
66175 + grsecurity runs with at bootup, without having to recompile your
66176 + kernel. You can echo values to files in /proc/sys/kernel/grsecurity
66177 + to enable (1) or disable (0) various features. All the sysctl entries
66178 + are mutable until the "grsec_lock" entry is set to a non-zero value.
66179 + All features enabled in the kernel configuration are disabled at boot
66180 + if you do not say Y to the "Turn on features by default" option.
66181 + All options should be set at startup, and the grsec_lock entry should
66182 + be set to a non-zero value after all the options are set.
66183 + *THIS IS EXTREMELY IMPORTANT*
66184 +
66185 +config GRKERNSEC_SYSCTL_DISTRO
66186 + bool "Extra sysctl support for distro makers (READ HELP)"
66187 + depends on GRKERNSEC_SYSCTL && GRKERNSEC_IO
66188 + help
66189 + If you say Y here, additional sysctl options will be created
66190 + for features that affect processes running as root. Therefore,
66191 + it is critical when using this option that the grsec_lock entry be
66192 + enabled after boot. Only distros with prebuilt kernel packages
66193 + with this option enabled that can ensure grsec_lock is enabled
66194 + after boot should use this option.
66195 + *Failure to set grsec_lock after boot makes all grsec features
66196 + this option covers useless*
66197 +
66198 + Currently this option creates the following sysctl entries:
66199 + "Disable Privileged I/O": "disable_priv_io"
66200 +
66201 +config GRKERNSEC_SYSCTL_ON
66202 + bool "Turn on features by default"
66203 + default y if GRKERNSEC_CONFIG_AUTO
66204 + depends on GRKERNSEC_SYSCTL
66205 + help
66206 + If you say Y here, instead of having all features enabled in the
66207 + kernel configuration disabled at boot time, the features will be
66208 + enabled at boot time. It is recommended you say Y here unless
66209 + there is some reason you would want all sysctl-tunable features to
66210 + be disabled by default. As mentioned elsewhere, it is important
66211 + to enable the grsec_lock entry once you have finished modifying
66212 + the sysctl entries.
66213 +
66214 +endmenu
66215 +menu "Logging Options"
66216 +depends on GRKERNSEC
66217 +
66218 +config GRKERNSEC_FLOODTIME
66219 + int "Seconds in between log messages (minimum)"
66220 + default 10
66221 + help
66222 + This option allows you to enforce the number of seconds between
66223 + grsecurity log messages. The default should be suitable for most
66224 + people, however, if you choose to change it, choose a value small enough
66225 + to allow informative logs to be produced, but large enough to
66226 + prevent flooding.
66227 +
66228 + Setting both this value and GRKERNSEC_FLOODBURST to 0 will disable
66229 + any rate limiting on grsecurity log messages.
66230 +
66231 +config GRKERNSEC_FLOODBURST
66232 + int "Number of messages in a burst (maximum)"
66233 + default 6
66234 + help
66235 + This option allows you to choose the maximum number of messages allowed
66236 + within the flood time interval you chose in a separate option. The
66237 + default should be suitable for most people, however if you find that
66238 + many of your logs are being interpreted as flooding, you may want to
66239 + raise this value.
66240 +
66241 + Setting both this value and GRKERNSEC_FLOODTIME to 0 will disable
66242 + any rate limiting on grsecurity log messages.
66243 +
66244 +endmenu
66245 diff --git a/grsecurity/Makefile b/grsecurity/Makefile
66246 new file mode 100644
66247 index 0000000..5307c8a
66248 --- /dev/null
66249 +++ b/grsecurity/Makefile
66250 @@ -0,0 +1,54 @@
66251 +# grsecurity – access control and security hardening for Linux
66252 +# All code in this directory and various hooks located throughout the Linux kernel are
66253 +# Copyright (C) 2001-2014 Bradley Spengler, Open Source Security, Inc.
66254 +# http://www.grsecurity.net spender@grsecurity.net
66255 +#
66256 +# This program is free software; you can redistribute it and/or
66257 +# modify it under the terms of the GNU General Public License version 2
66258 +# as published by the Free Software Foundation.
66259 +#
66260 +# This program is distributed in the hope that it will be useful,
66261 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
66262 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
66263 +# GNU General Public License for more details.
66264 +#
66265 +# You should have received a copy of the GNU General Public License
66266 +# along with this program; if not, write to the Free Software
66267 +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
66268 +
66269 +KBUILD_CFLAGS += -Werror
66270 +
66271 +obj-y = grsec_chdir.o grsec_chroot.o grsec_exec.o grsec_fifo.o grsec_fork.o \
66272 + grsec_mount.o grsec_sig.o grsec_sysctl.o \
66273 + grsec_time.o grsec_tpe.o grsec_link.o grsec_pax.o grsec_ptrace.o \
66274 + grsec_usb.o grsec_ipc.o
66275 +
66276 +obj-$(CONFIG_GRKERNSEC) += grsec_init.o grsum.o gracl.o gracl_segv.o \
66277 + gracl_cap.o gracl_alloc.o gracl_shm.o grsec_mem.o gracl_fs.o \
66278 + gracl_learn.o grsec_log.o gracl_policy.o
66279 +ifdef CONFIG_COMPAT
66280 +obj-$(CONFIG_GRKERNSEC) += gracl_compat.o
66281 +endif
66282 +
66283 +obj-$(CONFIG_GRKERNSEC_RESLOG) += gracl_res.o
66284 +
66285 +ifdef CONFIG_NET
66286 +obj-y += grsec_sock.o
66287 +obj-$(CONFIG_GRKERNSEC) += gracl_ip.o
66288 +endif
66289 +
66290 +ifndef CONFIG_GRKERNSEC
66291 +obj-y += grsec_disabled.o
66292 +endif
66293 +
66294 +ifdef CONFIG_GRKERNSEC_HIDESYM
66295 +extra-y := grsec_hidesym.o
66296 +$(obj)/grsec_hidesym.o:
66297 + @-chmod -f 500 /boot
66298 + @-chmod -f 500 /lib/modules
66299 + @-chmod -f 500 /lib64/modules
66300 + @-chmod -f 500 /lib32/modules
66301 + @-chmod -f 700 .
66302 + @-chmod -f 700 $(objtree)
66303 + @echo ' grsec: protected kernel image paths'
66304 +endif
66305 diff --git a/grsecurity/gracl.c b/grsecurity/gracl.c
66306 new file mode 100644
66307 index 0000000..e56396f
66308 --- /dev/null
66309 +++ b/grsecurity/gracl.c
66310 @@ -0,0 +1,2679 @@
66311 +#include <linux/kernel.h>
66312 +#include <linux/module.h>
66313 +#include <linux/sched.h>
66314 +#include <linux/mm.h>
66315 +#include <linux/file.h>
66316 +#include <linux/fs.h>
66317 +#include <linux/namei.h>
66318 +#include <linux/mount.h>
66319 +#include <linux/tty.h>
66320 +#include <linux/proc_fs.h>
66321 +#include <linux/lglock.h>
66322 +#include <linux/slab.h>
66323 +#include <linux/vmalloc.h>
66324 +#include <linux/types.h>
66325 +#include <linux/sysctl.h>
66326 +#include <linux/netdevice.h>
66327 +#include <linux/ptrace.h>
66328 +#include <linux/gracl.h>
66329 +#include <linux/gralloc.h>
66330 +#include <linux/security.h>
66331 +#include <linux/grinternal.h>
66332 +#include <linux/pid_namespace.h>
66333 +#include <linux/stop_machine.h>
66334 +#include <linux/fdtable.h>
66335 +#include <linux/percpu.h>
66336 +#include <linux/lglock.h>
66337 +#include <linux/hugetlb.h>
66338 +#include <linux/posix-timers.h>
66339 +#include <linux/prefetch.h>
66340 +#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
66341 +#include <linux/magic.h>
66342 +#include <linux/pagemap.h>
66343 +#include "../fs/btrfs/async-thread.h"
66344 +#include "../fs/btrfs/ctree.h"
66345 +#include "../fs/btrfs/btrfs_inode.h"
66346 +#endif
66347 +#include "../fs/mount.h"
66348 +
66349 +#include <asm/uaccess.h>
66350 +#include <asm/errno.h>
66351 +#include <asm/mman.h>
66352 +
66353 +#define FOR_EACH_ROLE_START(role) \
66354 + role = running_polstate.role_list; \
66355 + while (role) {
66356 +
66357 +#define FOR_EACH_ROLE_END(role) \
66358 + role = role->prev; \
66359 + }
66360 +
66361 +extern struct path gr_real_root;
66362 +
66363 +static struct gr_policy_state running_polstate;
66364 +struct gr_policy_state *polstate = &running_polstate;
66365 +extern struct gr_alloc_state *current_alloc_state;
66366 +
66367 +extern char *gr_shared_page[4];
66368 +DEFINE_RWLOCK(gr_inode_lock);
66369 +
66370 +static unsigned int gr_status __read_only = GR_STATUS_INIT;
66371 +
66372 +#ifdef CONFIG_NET
66373 +extern struct vfsmount *sock_mnt;
66374 +#endif
66375 +
66376 +extern struct vfsmount *pipe_mnt;
66377 +extern struct vfsmount *shm_mnt;
66378 +
66379 +#ifdef CONFIG_HUGETLBFS
66380 +extern struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
66381 +#endif
66382 +
66383 +extern u16 acl_sp_role_value;
66384 +extern struct acl_object_label *fakefs_obj_rw;
66385 +extern struct acl_object_label *fakefs_obj_rwx;
66386 +
66387 +int gr_acl_is_enabled(void)
66388 +{
66389 + return (gr_status & GR_READY);
66390 +}
66391 +
66392 +void gr_enable_rbac_system(void)
66393 +{
66394 + pax_open_kernel();
66395 + gr_status |= GR_READY;
66396 + pax_close_kernel();
66397 +}
66398 +
66399 +int gr_rbac_disable(void *unused)
66400 +{
66401 + pax_open_kernel();
66402 + gr_status &= ~GR_READY;
66403 + pax_close_kernel();
66404 +
66405 + return 0;
66406 +}
66407 +
66408 +static inline dev_t __get_dev(const struct dentry *dentry)
66409 +{
66410 +#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
66411 + if (dentry->d_sb->s_magic == BTRFS_SUPER_MAGIC)
66412 + return BTRFS_I(dentry->d_inode)->root->anon_dev;
66413 + else
66414 +#endif
66415 + return dentry->d_sb->s_dev;
66416 +}
66417 +
66418 +dev_t gr_get_dev_from_dentry(struct dentry *dentry)
66419 +{
66420 + return __get_dev(dentry);
66421 +}
66422 +
66423 +static char gr_task_roletype_to_char(struct task_struct *task)
66424 +{
66425 + switch (task->role->roletype &
66426 + (GR_ROLE_DEFAULT | GR_ROLE_USER | GR_ROLE_GROUP |
66427 + GR_ROLE_SPECIAL)) {
66428 + case GR_ROLE_DEFAULT:
66429 + return 'D';
66430 + case GR_ROLE_USER:
66431 + return 'U';
66432 + case GR_ROLE_GROUP:
66433 + return 'G';
66434 + case GR_ROLE_SPECIAL:
66435 + return 'S';
66436 + }
66437 +
66438 + return 'X';
66439 +}
66440 +
66441 +char gr_roletype_to_char(void)
66442 +{
66443 + return gr_task_roletype_to_char(current);
66444 +}
66445 +
66446 +__inline__ int
66447 +gr_acl_tpe_check(void)
66448 +{
66449 + if (unlikely(!(gr_status & GR_READY)))
66450 + return 0;
66451 + if (current->role->roletype & GR_ROLE_TPE)
66452 + return 1;
66453 + else
66454 + return 0;
66455 +}
66456 +
66457 +int
66458 +gr_handle_rawio(const struct inode *inode)
66459 +{
66460 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
66461 + if (inode && (S_ISBLK(inode->i_mode) || (S_ISCHR(inode->i_mode) && imajor(inode) == RAW_MAJOR)) &&
66462 + grsec_enable_chroot_caps && proc_is_chrooted(current) &&
66463 + !capable(CAP_SYS_RAWIO))
66464 + return 1;
66465 +#endif
66466 + return 0;
66467 +}
66468 +
66469 +int
66470 +gr_streq(const char *a, const char *b, const unsigned int lena, const unsigned int lenb)
66471 +{
66472 + if (likely(lena != lenb))
66473 + return 0;
66474 +
66475 + return !memcmp(a, b, lena);
66476 +}
66477 +
66478 +static int prepend(char **buffer, int *buflen, const char *str, int namelen)
66479 +{
66480 + *buflen -= namelen;
66481 + if (*buflen < 0)
66482 + return -ENAMETOOLONG;
66483 + *buffer -= namelen;
66484 + memcpy(*buffer, str, namelen);
66485 + return 0;
66486 +}
66487 +
66488 +static int prepend_name(char **buffer, int *buflen, struct qstr *name)
66489 +{
66490 + return prepend(buffer, buflen, name->name, name->len);
66491 +}
66492 +
66493 +static int prepend_path(const struct path *path, struct path *root,
66494 + char **buffer, int *buflen)
66495 +{
66496 + struct dentry *dentry = path->dentry;
66497 + struct vfsmount *vfsmnt = path->mnt;
66498 + struct mount *mnt = real_mount(vfsmnt);
66499 + bool slash = false;
66500 + int error = 0;
66501 +
66502 + while (dentry != root->dentry || vfsmnt != root->mnt) {
66503 + struct dentry * parent;
66504 +
66505 + if (dentry == vfsmnt->mnt_root || IS_ROOT(dentry)) {
66506 + /* Global root? */
66507 + if (!mnt_has_parent(mnt)) {
66508 + goto out;
66509 + }
66510 + dentry = mnt->mnt_mountpoint;
66511 + mnt = mnt->mnt_parent;
66512 + vfsmnt = &mnt->mnt;
66513 + continue;
66514 + }
66515 + parent = dentry->d_parent;
66516 + prefetch(parent);
66517 + spin_lock(&dentry->d_lock);
66518 + error = prepend_name(buffer, buflen, &dentry->d_name);
66519 + spin_unlock(&dentry->d_lock);
66520 + if (!error)
66521 + error = prepend(buffer, buflen, "/", 1);
66522 + if (error)
66523 + break;
66524 +
66525 + slash = true;
66526 + dentry = parent;
66527 + }
66528 +
66529 +out:
66530 + if (!error && !slash)
66531 + error = prepend(buffer, buflen, "/", 1);
66532 +
66533 + return error;
66534 +}
66535 +
66536 +/* this must be called with mount_lock and rename_lock held */
66537 +
66538 +static char *__our_d_path(const struct path *path, struct path *root,
66539 + char *buf, int buflen)
66540 +{
66541 + char *res = buf + buflen;
66542 + int error;
66543 +
66544 + prepend(&res, &buflen, "\0", 1);
66545 + error = prepend_path(path, root, &res, &buflen);
66546 + if (error)
66547 + return ERR_PTR(error);
66548 +
66549 + return res;
66550 +}
66551 +
66552 +static char *
66553 +gen_full_path(struct path *path, struct path *root, char *buf, int buflen)
66554 +{
66555 + char *retval;
66556 +
66557 + retval = __our_d_path(path, root, buf, buflen);
66558 + if (unlikely(IS_ERR(retval)))
66559 + retval = strcpy(buf, "<path too long>");
66560 + else if (unlikely(retval[1] == '/' && retval[2] == '\0'))
66561 + retval[1] = '\0';
66562 +
66563 + return retval;
66564 +}
66565 +
66566 +static char *
66567 +__d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
66568 + char *buf, int buflen)
66569 +{
66570 + struct path path;
66571 + char *res;
66572 +
66573 + path.dentry = (struct dentry *)dentry;
66574 + path.mnt = (struct vfsmount *)vfsmnt;
66575 +
66576 + /* we can use gr_real_root.dentry, gr_real_root.mnt, because this is only called
66577 + by the RBAC system */
66578 + res = gen_full_path(&path, &gr_real_root, buf, buflen);
66579 +
66580 + return res;
66581 +}
66582 +
66583 +static char *
66584 +d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
66585 + char *buf, int buflen)
66586 +{
66587 + char *res;
66588 + struct path path;
66589 + struct path root;
66590 + struct task_struct *reaper = init_pid_ns.child_reaper;
66591 +
66592 + path.dentry = (struct dentry *)dentry;
66593 + path.mnt = (struct vfsmount *)vfsmnt;
66594 +
66595 + /* we can't use gr_real_root.dentry, gr_real_root.mnt, because they belong only to the RBAC system */
66596 + get_fs_root(reaper->fs, &root);
66597 +
66598 + read_seqlock_excl(&mount_lock);
66599 + write_seqlock(&rename_lock);
66600 + res = gen_full_path(&path, &root, buf, buflen);
66601 + write_sequnlock(&rename_lock);
66602 + read_sequnlock_excl(&mount_lock);
66603 +
66604 + path_put(&root);
66605 + return res;
66606 +}
66607 +
66608 +char *
66609 +gr_to_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
66610 +{
66611 + char *ret;
66612 + read_seqlock_excl(&mount_lock);
66613 + write_seqlock(&rename_lock);
66614 + ret = __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
66615 + PAGE_SIZE);
66616 + write_sequnlock(&rename_lock);
66617 + read_sequnlock_excl(&mount_lock);
66618 + return ret;
66619 +}
66620 +
66621 +static char *
66622 +gr_to_proc_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
66623 +{
66624 + char *ret;
66625 + char *buf;
66626 + int buflen;
66627 +
66628 + read_seqlock_excl(&mount_lock);
66629 + write_seqlock(&rename_lock);
66630 + buf = per_cpu_ptr(gr_shared_page[0], smp_processor_id());
66631 + ret = __d_real_path(dentry, mnt, buf, PAGE_SIZE - 6);
66632 + buflen = (int)(ret - buf);
66633 + if (buflen >= 5)
66634 + prepend(&ret, &buflen, "/proc", 5);
66635 + else
66636 + ret = strcpy(buf, "<path too long>");
66637 + write_sequnlock(&rename_lock);
66638 + read_sequnlock_excl(&mount_lock);
66639 + return ret;
66640 +}
66641 +
66642 +char *
66643 +gr_to_filename_nolock(const struct dentry *dentry, const struct vfsmount *mnt)
66644 +{
66645 + return __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
66646 + PAGE_SIZE);
66647 +}
66648 +
66649 +char *
66650 +gr_to_filename(const struct dentry *dentry, const struct vfsmount *mnt)
66651 +{
66652 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
66653 + PAGE_SIZE);
66654 +}
66655 +
66656 +char *
66657 +gr_to_filename1(const struct dentry *dentry, const struct vfsmount *mnt)
66658 +{
66659 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[1], smp_processor_id()),
66660 + PAGE_SIZE);
66661 +}
66662 +
66663 +char *
66664 +gr_to_filename2(const struct dentry *dentry, const struct vfsmount *mnt)
66665 +{
66666 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[2], smp_processor_id()),
66667 + PAGE_SIZE);
66668 +}
66669 +
66670 +char *
66671 +gr_to_filename3(const struct dentry *dentry, const struct vfsmount *mnt)
66672 +{
66673 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[3], smp_processor_id()),
66674 + PAGE_SIZE);
66675 +}
66676 +
66677 +__inline__ __u32
66678 +to_gr_audit(const __u32 reqmode)
66679 +{
66680 + /* masks off auditable permission flags, then shifts them to create
66681 + auditing flags, and adds the special case of append auditing if
66682 + we're requesting write */
66683 + return (((reqmode & ~GR_AUDITS) << 10) | ((reqmode & GR_WRITE) ? GR_AUDIT_APPEND : 0));
66684 +}
66685 +
66686 +struct acl_role_label *
66687 +__lookup_acl_role_label(const struct gr_policy_state *state, const struct task_struct *task, const uid_t uid,
66688 + const gid_t gid)
66689 +{
66690 + unsigned int index = gr_rhash(uid, GR_ROLE_USER, state->acl_role_set.r_size);
66691 + struct acl_role_label *match;
66692 + struct role_allowed_ip *ipp;
66693 + unsigned int x;
66694 + u32 curr_ip = task->signal->saved_ip;
66695 +
66696 + match = state->acl_role_set.r_hash[index];
66697 +
66698 + while (match) {
66699 + if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_USER)) == (GR_ROLE_DOMAIN | GR_ROLE_USER)) {
66700 + for (x = 0; x < match->domain_child_num; x++) {
66701 + if (match->domain_children[x] == uid)
66702 + goto found;
66703 + }
66704 + } else if (match->uidgid == uid && match->roletype & GR_ROLE_USER)
66705 + break;
66706 + match = match->next;
66707 + }
66708 +found:
66709 + if (match == NULL) {
66710 + try_group:
66711 + index = gr_rhash(gid, GR_ROLE_GROUP, state->acl_role_set.r_size);
66712 + match = state->acl_role_set.r_hash[index];
66713 +
66714 + while (match) {
66715 + if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) == (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) {
66716 + for (x = 0; x < match->domain_child_num; x++) {
66717 + if (match->domain_children[x] == gid)
66718 + goto found2;
66719 + }
66720 + } else if (match->uidgid == gid && match->roletype & GR_ROLE_GROUP)
66721 + break;
66722 + match = match->next;
66723 + }
66724 +found2:
66725 + if (match == NULL)
66726 + match = state->default_role;
66727 + if (match->allowed_ips == NULL)
66728 + return match;
66729 + else {
66730 + for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
66731 + if (likely
66732 + ((ntohl(curr_ip) & ipp->netmask) ==
66733 + (ntohl(ipp->addr) & ipp->netmask)))
66734 + return match;
66735 + }
66736 + match = state->default_role;
66737 + }
66738 + } else if (match->allowed_ips == NULL) {
66739 + return match;
66740 + } else {
66741 + for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
66742 + if (likely
66743 + ((ntohl(curr_ip) & ipp->netmask) ==
66744 + (ntohl(ipp->addr) & ipp->netmask)))
66745 + return match;
66746 + }
66747 + goto try_group;
66748 + }
66749 +
66750 + return match;
66751 +}
66752 +
66753 +static struct acl_role_label *
66754 +lookup_acl_role_label(const struct task_struct *task, const uid_t uid,
66755 + const gid_t gid)
66756 +{
66757 + return __lookup_acl_role_label(&running_polstate, task, uid, gid);
66758 +}
66759 +
66760 +struct acl_subject_label *
66761 +lookup_acl_subj_label(const ino_t ino, const dev_t dev,
66762 + const struct acl_role_label *role)
66763 +{
66764 + unsigned int index = gr_fhash(ino, dev, role->subj_hash_size);
66765 + struct acl_subject_label *match;
66766 +
66767 + match = role->subj_hash[index];
66768 +
66769 + while (match && (match->inode != ino || match->device != dev ||
66770 + (match->mode & GR_DELETED))) {
66771 + match = match->next;
66772 + }
66773 +
66774 + if (match && !(match->mode & GR_DELETED))
66775 + return match;
66776 + else
66777 + return NULL;
66778 +}
66779 +
66780 +struct acl_subject_label *
66781 +lookup_acl_subj_label_deleted(const ino_t ino, const dev_t dev,
66782 + const struct acl_role_label *role)
66783 +{
66784 + unsigned int index = gr_fhash(ino, dev, role->subj_hash_size);
66785 + struct acl_subject_label *match;
66786 +
66787 + match = role->subj_hash[index];
66788 +
66789 + while (match && (match->inode != ino || match->device != dev ||
66790 + !(match->mode & GR_DELETED))) {
66791 + match = match->next;
66792 + }
66793 +
66794 + if (match && (match->mode & GR_DELETED))
66795 + return match;
66796 + else
66797 + return NULL;
66798 +}
66799 +
66800 +static struct acl_object_label *
66801 +lookup_acl_obj_label(const ino_t ino, const dev_t dev,
66802 + const struct acl_subject_label *subj)
66803 +{
66804 + unsigned int index = gr_fhash(ino, dev, subj->obj_hash_size);
66805 + struct acl_object_label *match;
66806 +
66807 + match = subj->obj_hash[index];
66808 +
66809 + while (match && (match->inode != ino || match->device != dev ||
66810 + (match->mode & GR_DELETED))) {
66811 + match = match->next;
66812 + }
66813 +
66814 + if (match && !(match->mode & GR_DELETED))
66815 + return match;
66816 + else
66817 + return NULL;
66818 +}
66819 +
66820 +static struct acl_object_label *
66821 +lookup_acl_obj_label_create(const ino_t ino, const dev_t dev,
66822 + const struct acl_subject_label *subj)
66823 +{
66824 + unsigned int index = gr_fhash(ino, dev, subj->obj_hash_size);
66825 + struct acl_object_label *match;
66826 +
66827 + match = subj->obj_hash[index];
66828 +
66829 + while (match && (match->inode != ino || match->device != dev ||
66830 + !(match->mode & GR_DELETED))) {
66831 + match = match->next;
66832 + }
66833 +
66834 + if (match && (match->mode & GR_DELETED))
66835 + return match;
66836 +
66837 + match = subj->obj_hash[index];
66838 +
66839 + while (match && (match->inode != ino || match->device != dev ||
66840 + (match->mode & GR_DELETED))) {
66841 + match = match->next;
66842 + }
66843 +
66844 + if (match && !(match->mode & GR_DELETED))
66845 + return match;
66846 + else
66847 + return NULL;
66848 +}
66849 +
66850 +struct name_entry *
66851 +__lookup_name_entry(const struct gr_policy_state *state, const char *name)
66852 +{
66853 + unsigned int len = strlen(name);
66854 + unsigned int key = full_name_hash(name, len);
66855 + unsigned int index = key % state->name_set.n_size;
66856 + struct name_entry *match;
66857 +
66858 + match = state->name_set.n_hash[index];
66859 +
66860 + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len)))
66861 + match = match->next;
66862 +
66863 + return match;
66864 +}
66865 +
66866 +static struct name_entry *
66867 +lookup_name_entry(const char *name)
66868 +{
66869 + return __lookup_name_entry(&running_polstate, name);
66870 +}
66871 +
66872 +static struct name_entry *
66873 +lookup_name_entry_create(const char *name)
66874 +{
66875 + unsigned int len = strlen(name);
66876 + unsigned int key = full_name_hash(name, len);
66877 + unsigned int index = key % running_polstate.name_set.n_size;
66878 + struct name_entry *match;
66879 +
66880 + match = running_polstate.name_set.n_hash[index];
66881 +
66882 + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
66883 + !match->deleted))
66884 + match = match->next;
66885 +
66886 + if (match && match->deleted)
66887 + return match;
66888 +
66889 + match = running_polstate.name_set.n_hash[index];
66890 +
66891 + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
66892 + match->deleted))
66893 + match = match->next;
66894 +
66895 + if (match && !match->deleted)
66896 + return match;
66897 + else
66898 + return NULL;
66899 +}
66900 +
66901 +static struct inodev_entry *
66902 +lookup_inodev_entry(const ino_t ino, const dev_t dev)
66903 +{
66904 + unsigned int index = gr_fhash(ino, dev, running_polstate.inodev_set.i_size);
66905 + struct inodev_entry *match;
66906 +
66907 + match = running_polstate.inodev_set.i_hash[index];
66908 +
66909 + while (match && (match->nentry->inode != ino || match->nentry->device != dev))
66910 + match = match->next;
66911 +
66912 + return match;
66913 +}
66914 +
66915 +void
66916 +__insert_inodev_entry(const struct gr_policy_state *state, struct inodev_entry *entry)
66917 +{
66918 + unsigned int index = gr_fhash(entry->nentry->inode, entry->nentry->device,
66919 + state->inodev_set.i_size);
66920 + struct inodev_entry **curr;
66921 +
66922 + entry->prev = NULL;
66923 +
66924 + curr = &state->inodev_set.i_hash[index];
66925 + if (*curr != NULL)
66926 + (*curr)->prev = entry;
66927 +
66928 + entry->next = *curr;
66929 + *curr = entry;
66930 +
66931 + return;
66932 +}
66933 +
66934 +static void
66935 +insert_inodev_entry(struct inodev_entry *entry)
66936 +{
66937 + __insert_inodev_entry(&running_polstate, entry);
66938 +}
66939 +
66940 +void
66941 +insert_acl_obj_label(struct acl_object_label *obj,
66942 + struct acl_subject_label *subj)
66943 +{
66944 + unsigned int index =
66945 + gr_fhash(obj->inode, obj->device, subj->obj_hash_size);
66946 + struct acl_object_label **curr;
66947 +
66948 + obj->prev = NULL;
66949 +
66950 + curr = &subj->obj_hash[index];
66951 + if (*curr != NULL)
66952 + (*curr)->prev = obj;
66953 +
66954 + obj->next = *curr;
66955 + *curr = obj;
66956 +
66957 + return;
66958 +}
66959 +
66960 +void
66961 +insert_acl_subj_label(struct acl_subject_label *obj,
66962 + struct acl_role_label *role)
66963 +{
66964 + unsigned int index = gr_fhash(obj->inode, obj->device, role->subj_hash_size);
66965 + struct acl_subject_label **curr;
66966 +
66967 + obj->prev = NULL;
66968 +
66969 + curr = &role->subj_hash[index];
66970 + if (*curr != NULL)
66971 + (*curr)->prev = obj;
66972 +
66973 + obj->next = *curr;
66974 + *curr = obj;
66975 +
66976 + return;
66977 +}
66978 +
66979 +/* derived from glibc fnmatch() 0: match, 1: no match*/
66980 +
66981 +static int
66982 +glob_match(const char *p, const char *n)
66983 +{
66984 + char c;
66985 +
66986 + while ((c = *p++) != '\0') {
66987 + switch (c) {
66988 + case '?':
66989 + if (*n == '\0')
66990 + return 1;
66991 + else if (*n == '/')
66992 + return 1;
66993 + break;
66994 + case '\\':
66995 + if (*n != c)
66996 + return 1;
66997 + break;
66998 + case '*':
66999 + for (c = *p++; c == '?' || c == '*'; c = *p++) {
67000 + if (*n == '/')
67001 + return 1;
67002 + else if (c == '?') {
67003 + if (*n == '\0')
67004 + return 1;
67005 + else
67006 + ++n;
67007 + }
67008 + }
67009 + if (c == '\0') {
67010 + return 0;
67011 + } else {
67012 + const char *endp;
67013 +
67014 + if ((endp = strchr(n, '/')) == NULL)
67015 + endp = n + strlen(n);
67016 +
67017 + if (c == '[') {
67018 + for (--p; n < endp; ++n)
67019 + if (!glob_match(p, n))
67020 + return 0;
67021 + } else if (c == '/') {
67022 + while (*n != '\0' && *n != '/')
67023 + ++n;
67024 + if (*n == '/' && !glob_match(p, n + 1))
67025 + return 0;
67026 + } else {
67027 + for (--p; n < endp; ++n)
67028 + if (*n == c && !glob_match(p, n))
67029 + return 0;
67030 + }
67031 +
67032 + return 1;
67033 + }
67034 + case '[':
67035 + {
67036 + int not;
67037 + char cold;
67038 +
67039 + if (*n == '\0' || *n == '/')
67040 + return 1;
67041 +
67042 + not = (*p == '!' || *p == '^');
67043 + if (not)
67044 + ++p;
67045 +
67046 + c = *p++;
67047 + for (;;) {
67048 + unsigned char fn = (unsigned char)*n;
67049 +
67050 + if (c == '\0')
67051 + return 1;
67052 + else {
67053 + if (c == fn)
67054 + goto matched;
67055 + cold = c;
67056 + c = *p++;
67057 +
67058 + if (c == '-' && *p != ']') {
67059 + unsigned char cend = *p++;
67060 +
67061 + if (cend == '\0')
67062 + return 1;
67063 +
67064 + if (cold <= fn && fn <= cend)
67065 + goto matched;
67066 +
67067 + c = *p++;
67068 + }
67069 + }
67070 +
67071 + if (c == ']')
67072 + break;
67073 + }
67074 + if (!not)
67075 + return 1;
67076 + break;
67077 + matched:
67078 + while (c != ']') {
67079 + if (c == '\0')
67080 + return 1;
67081 +
67082 + c = *p++;
67083 + }
67084 + if (not)
67085 + return 1;
67086 + }
67087 + break;
67088 + default:
67089 + if (c != *n)
67090 + return 1;
67091 + }
67092 +
67093 + ++n;
67094 + }
67095 +
67096 + if (*n == '\0')
67097 + return 0;
67098 +
67099 + if (*n == '/')
67100 + return 0;
67101 +
67102 + return 1;
67103 +}
67104 +
67105 +static struct acl_object_label *
67106 +chk_glob_label(struct acl_object_label *globbed,
67107 + const struct dentry *dentry, const struct vfsmount *mnt, char **path)
67108 +{
67109 + struct acl_object_label *tmp;
67110 +
67111 + if (*path == NULL)
67112 + *path = gr_to_filename_nolock(dentry, mnt);
67113 +
67114 + tmp = globbed;
67115 +
67116 + while (tmp) {
67117 + if (!glob_match(tmp->filename, *path))
67118 + return tmp;
67119 + tmp = tmp->next;
67120 + }
67121 +
67122 + return NULL;
67123 +}
67124 +
67125 +static struct acl_object_label *
67126 +__full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
67127 + const ino_t curr_ino, const dev_t curr_dev,
67128 + const struct acl_subject_label *subj, char **path, const int checkglob)
67129 +{
67130 + struct acl_subject_label *tmpsubj;
67131 + struct acl_object_label *retval;
67132 + struct acl_object_label *retval2;
67133 +
67134 + tmpsubj = (struct acl_subject_label *) subj;
67135 + read_lock(&gr_inode_lock);
67136 + do {
67137 + retval = lookup_acl_obj_label(curr_ino, curr_dev, tmpsubj);
67138 + if (retval) {
67139 + if (checkglob && retval->globbed) {
67140 + retval2 = chk_glob_label(retval->globbed, orig_dentry, orig_mnt, path);
67141 + if (retval2)
67142 + retval = retval2;
67143 + }
67144 + break;
67145 + }
67146 + } while ((tmpsubj = tmpsubj->parent_subject));
67147 + read_unlock(&gr_inode_lock);
67148 +
67149 + return retval;
67150 +}
67151 +
67152 +static __inline__ struct acl_object_label *
67153 +full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
67154 + struct dentry *curr_dentry,
67155 + const struct acl_subject_label *subj, char **path, const int checkglob)
67156 +{
67157 + int newglob = checkglob;
67158 + ino_t inode;
67159 + dev_t device;
67160 +
67161 + /* if we aren't checking a subdirectory of the original path yet, don't do glob checking
67162 + as we don't want a / * rule to match instead of the / object
67163 + don't do this for create lookups that call this function though, since they're looking up
67164 + on the parent and thus need globbing checks on all paths
67165 + */
67166 + if (orig_dentry == curr_dentry && newglob != GR_CREATE_GLOB)
67167 + newglob = GR_NO_GLOB;
67168 +
67169 + spin_lock(&curr_dentry->d_lock);
67170 + inode = curr_dentry->d_inode->i_ino;
67171 + device = __get_dev(curr_dentry);
67172 + spin_unlock(&curr_dentry->d_lock);
67173 +
67174 + return __full_lookup(orig_dentry, orig_mnt, inode, device, subj, path, newglob);
67175 +}
67176 +
67177 +#ifdef CONFIG_HUGETLBFS
67178 +static inline bool
67179 +is_hugetlbfs_mnt(const struct vfsmount *mnt)
67180 +{
67181 + int i;
67182 + for (i = 0; i < HUGE_MAX_HSTATE; i++) {
67183 + if (unlikely(hugetlbfs_vfsmount[i] == mnt))
67184 + return true;
67185 + }
67186 +
67187 + return false;
67188 +}
67189 +#endif
67190 +
67191 +static struct acl_object_label *
67192 +__chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
67193 + const struct acl_subject_label *subj, char *path, const int checkglob)
67194 +{
67195 + struct dentry *dentry = (struct dentry *) l_dentry;
67196 + struct vfsmount *mnt = (struct vfsmount *) l_mnt;
67197 + struct mount *real_mnt = real_mount(mnt);
67198 + struct acl_object_label *retval;
67199 + struct dentry *parent;
67200 +
67201 + read_seqlock_excl(&mount_lock);
67202 + write_seqlock(&rename_lock);
67203 +
67204 + if (unlikely((mnt == shm_mnt && dentry->d_inode->i_nlink == 0) || mnt == pipe_mnt ||
67205 +#ifdef CONFIG_NET
67206 + mnt == sock_mnt ||
67207 +#endif
67208 +#ifdef CONFIG_HUGETLBFS
67209 + (is_hugetlbfs_mnt(mnt) && dentry->d_inode->i_nlink == 0) ||
67210 +#endif
67211 + /* ignore Eric Biederman */
67212 + IS_PRIVATE(l_dentry->d_inode))) {
67213 + retval = (subj->mode & GR_SHMEXEC) ? fakefs_obj_rwx : fakefs_obj_rw;
67214 + goto out;
67215 + }
67216 +
67217 + for (;;) {
67218 + if (dentry == gr_real_root.dentry && mnt == gr_real_root.mnt)
67219 + break;
67220 +
67221 + if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
67222 + if (!mnt_has_parent(real_mnt))
67223 + break;
67224 +
67225 + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
67226 + if (retval != NULL)
67227 + goto out;
67228 +
67229 + dentry = real_mnt->mnt_mountpoint;
67230 + real_mnt = real_mnt->mnt_parent;
67231 + mnt = &real_mnt->mnt;
67232 + continue;
67233 + }
67234 +
67235 + parent = dentry->d_parent;
67236 + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
67237 + if (retval != NULL)
67238 + goto out;
67239 +
67240 + dentry = parent;
67241 + }
67242 +
67243 + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
67244 +
67245 + /* gr_real_root is pinned so we don't have to hold a reference */
67246 + if (retval == NULL)
67247 + retval = full_lookup(l_dentry, l_mnt, gr_real_root.dentry, subj, &path, checkglob);
67248 +out:
67249 + write_sequnlock(&rename_lock);
67250 + read_sequnlock_excl(&mount_lock);
67251 +
67252 + BUG_ON(retval == NULL);
67253 +
67254 + return retval;
67255 +}
67256 +
67257 +static __inline__ struct acl_object_label *
67258 +chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
67259 + const struct acl_subject_label *subj)
67260 +{
67261 + char *path = NULL;
67262 + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_REG_GLOB);
67263 +}
67264 +
67265 +static __inline__ struct acl_object_label *
67266 +chk_obj_label_noglob(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
67267 + const struct acl_subject_label *subj)
67268 +{
67269 + char *path = NULL;
67270 + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_NO_GLOB);
67271 +}
67272 +
67273 +static __inline__ struct acl_object_label *
67274 +chk_obj_create_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
67275 + const struct acl_subject_label *subj, char *path)
67276 +{
67277 + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_CREATE_GLOB);
67278 +}
67279 +
67280 +struct acl_subject_label *
67281 +chk_subj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
67282 + const struct acl_role_label *role)
67283 +{
67284 + struct dentry *dentry = (struct dentry *) l_dentry;
67285 + struct vfsmount *mnt = (struct vfsmount *) l_mnt;
67286 + struct mount *real_mnt = real_mount(mnt);
67287 + struct acl_subject_label *retval;
67288 + struct dentry *parent;
67289 +
67290 + read_seqlock_excl(&mount_lock);
67291 + write_seqlock(&rename_lock);
67292 +
67293 + for (;;) {
67294 + if (dentry == gr_real_root.dentry && mnt == gr_real_root.mnt)
67295 + break;
67296 + if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
67297 + if (!mnt_has_parent(real_mnt))
67298 + break;
67299 +
67300 + spin_lock(&dentry->d_lock);
67301 + read_lock(&gr_inode_lock);
67302 + retval =
67303 + lookup_acl_subj_label(dentry->d_inode->i_ino,
67304 + __get_dev(dentry), role);
67305 + read_unlock(&gr_inode_lock);
67306 + spin_unlock(&dentry->d_lock);
67307 + if (retval != NULL)
67308 + goto out;
67309 +
67310 + dentry = real_mnt->mnt_mountpoint;
67311 + real_mnt = real_mnt->mnt_parent;
67312 + mnt = &real_mnt->mnt;
67313 + continue;
67314 + }
67315 +
67316 + spin_lock(&dentry->d_lock);
67317 + read_lock(&gr_inode_lock);
67318 + retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
67319 + __get_dev(dentry), role);
67320 + read_unlock(&gr_inode_lock);
67321 + parent = dentry->d_parent;
67322 + spin_unlock(&dentry->d_lock);
67323 +
67324 + if (retval != NULL)
67325 + goto out;
67326 +
67327 + dentry = parent;
67328 + }
67329 +
67330 + spin_lock(&dentry->d_lock);
67331 + read_lock(&gr_inode_lock);
67332 + retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
67333 + __get_dev(dentry), role);
67334 + read_unlock(&gr_inode_lock);
67335 + spin_unlock(&dentry->d_lock);
67336 +
67337 + if (unlikely(retval == NULL)) {
67338 + /* gr_real_root is pinned, we don't need to hold a reference */
67339 + read_lock(&gr_inode_lock);
67340 + retval = lookup_acl_subj_label(gr_real_root.dentry->d_inode->i_ino,
67341 + __get_dev(gr_real_root.dentry), role);
67342 + read_unlock(&gr_inode_lock);
67343 + }
67344 +out:
67345 + write_sequnlock(&rename_lock);
67346 + read_sequnlock_excl(&mount_lock);
67347 +
67348 + BUG_ON(retval == NULL);
67349 +
67350 + return retval;
67351 +}
67352 +
67353 +void
67354 +assign_special_role(const char *rolename)
67355 +{
67356 + struct acl_object_label *obj;
67357 + struct acl_role_label *r;
67358 + struct acl_role_label *assigned = NULL;
67359 + struct task_struct *tsk;
67360 + struct file *filp;
67361 +
67362 + FOR_EACH_ROLE_START(r)
67363 + if (!strcmp(rolename, r->rolename) &&
67364 + (r->roletype & GR_ROLE_SPECIAL)) {
67365 + assigned = r;
67366 + break;
67367 + }
67368 + FOR_EACH_ROLE_END(r)
67369 +
67370 + if (!assigned)
67371 + return;
67372 +
67373 + read_lock(&tasklist_lock);
67374 + read_lock(&grsec_exec_file_lock);
67375 +
67376 + tsk = current->real_parent;
67377 + if (tsk == NULL)
67378 + goto out_unlock;
67379 +
67380 + filp = tsk->exec_file;
67381 + if (filp == NULL)
67382 + goto out_unlock;
67383 +
67384 + tsk->is_writable = 0;
67385 + tsk->inherited = 0;
67386 +
67387 + tsk->acl_sp_role = 1;
67388 + tsk->acl_role_id = ++acl_sp_role_value;
67389 + tsk->role = assigned;
67390 + tsk->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role);
67391 +
67392 + /* ignore additional mmap checks for processes that are writable
67393 + by the default ACL */
67394 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, running_polstate.default_role->root_label);
67395 + if (unlikely(obj->mode & GR_WRITE))
67396 + tsk->is_writable = 1;
67397 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role->root_label);
67398 + if (unlikely(obj->mode & GR_WRITE))
67399 + tsk->is_writable = 1;
67400 +
67401 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
67402 + printk(KERN_ALERT "Assigning special role:%s subject:%s to process (%s:%d)\n", tsk->role->rolename,
67403 + tsk->acl->filename, tsk->comm, task_pid_nr(tsk));
67404 +#endif
67405 +
67406 +out_unlock:
67407 + read_unlock(&grsec_exec_file_lock);
67408 + read_unlock(&tasklist_lock);
67409 + return;
67410 +}
67411 +
67412 +
67413 +static void
67414 +gr_log_learn(const struct dentry *dentry, const struct vfsmount *mnt, const __u32 mode)
67415 +{
67416 + struct task_struct *task = current;
67417 + const struct cred *cred = current_cred();
67418 +
67419 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename, task->role->roletype,
67420 + GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
67421 + task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
67422 + 1UL, 1UL, gr_to_filename(dentry, mnt), (unsigned long) mode, &task->signal->saved_ip);
67423 +
67424 + return;
67425 +}
67426 +
67427 +static void
67428 +gr_log_learn_uid_change(const kuid_t real, const kuid_t effective, const kuid_t fs)
67429 +{
67430 + struct task_struct *task = current;
67431 + const struct cred *cred = current_cred();
67432 +
67433 + security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
67434 + GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
67435 + task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
67436 + 'u', GR_GLOBAL_UID(real), GR_GLOBAL_UID(effective), GR_GLOBAL_UID(fs), &task->signal->saved_ip);
67437 +
67438 + return;
67439 +}
67440 +
67441 +static void
67442 +gr_log_learn_gid_change(const kgid_t real, const kgid_t effective, const kgid_t fs)
67443 +{
67444 + struct task_struct *task = current;
67445 + const struct cred *cred = current_cred();
67446 +
67447 + security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
67448 + GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
67449 + task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
67450 + 'g', GR_GLOBAL_GID(real), GR_GLOBAL_GID(effective), GR_GLOBAL_GID(fs), &task->signal->saved_ip);
67451 +
67452 + return;
67453 +}
67454 +
67455 +static void
67456 +gr_set_proc_res(struct task_struct *task)
67457 +{
67458 + struct acl_subject_label *proc;
67459 + unsigned short i;
67460 +
67461 + proc = task->acl;
67462 +
67463 + if (proc->mode & (GR_LEARN | GR_INHERITLEARN))
67464 + return;
67465 +
67466 + for (i = 0; i < RLIM_NLIMITS; i++) {
67467 + if (!(proc->resmask & (1U << i)))
67468 + continue;
67469 +
67470 + task->signal->rlim[i].rlim_cur = proc->res[i].rlim_cur;
67471 + task->signal->rlim[i].rlim_max = proc->res[i].rlim_max;
67472 +
67473 + if (i == RLIMIT_CPU)
67474 + update_rlimit_cpu(task, proc->res[i].rlim_cur);
67475 + }
67476 +
67477 + return;
67478 +}
67479 +
67480 +/* both of the below must be called with
67481 + rcu_read_lock();
67482 + read_lock(&tasklist_lock);
67483 + read_lock(&grsec_exec_file_lock);
67484 +*/
67485 +
67486 +struct acl_subject_label *__gr_get_subject_for_task(const struct gr_policy_state *state, struct task_struct *task, const char *filename)
67487 +{
67488 + char *tmpname;
67489 + struct acl_subject_label *tmpsubj;
67490 + struct file *filp;
67491 + struct name_entry *nmatch;
67492 +
67493 + filp = task->exec_file;
67494 + if (filp == NULL)
67495 + return NULL;
67496 +
67497 + /* the following is to apply the correct subject
67498 + on binaries running when the RBAC system
67499 + is enabled, when the binaries have been
67500 + replaced or deleted since their execution
67501 + -----
67502 + when the RBAC system starts, the inode/dev
67503 + from exec_file will be one the RBAC system
67504 + is unaware of. It only knows the inode/dev
67505 + of the present file on disk, or the absence
67506 + of it.
67507 + */
67508 +
67509 + if (filename)
67510 + nmatch = __lookup_name_entry(state, filename);
67511 + else {
67512 + preempt_disable();
67513 + tmpname = gr_to_filename_rbac(filp->f_path.dentry, filp->f_path.mnt);
67514 +
67515 + nmatch = __lookup_name_entry(state, tmpname);
67516 + preempt_enable();
67517 + }
67518 + tmpsubj = NULL;
67519 + if (nmatch) {
67520 + if (nmatch->deleted)
67521 + tmpsubj = lookup_acl_subj_label_deleted(nmatch->inode, nmatch->device, task->role);
67522 + else
67523 + tmpsubj = lookup_acl_subj_label(nmatch->inode, nmatch->device, task->role);
67524 + }
67525 + /* this also works for the reload case -- if we don't match a potentially inherited subject
67526 + then we fall back to a normal lookup based on the binary's ino/dev
67527 + */
67528 + if (tmpsubj == NULL)
67529 + tmpsubj = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, task->role);
67530 +
67531 + return tmpsubj;
67532 +}
67533 +
67534 +static struct acl_subject_label *gr_get_subject_for_task(struct task_struct *task, const char *filename)
67535 +{
67536 + return __gr_get_subject_for_task(&running_polstate, task, filename);
67537 +}
67538 +
67539 +void __gr_apply_subject_to_task(const struct gr_policy_state *state, struct task_struct *task, struct acl_subject_label *subj)
67540 +{
67541 + struct acl_object_label *obj;
67542 + struct file *filp;
67543 +
67544 + filp = task->exec_file;
67545 +
67546 + task->acl = subj;
67547 + task->is_writable = 0;
67548 + /* ignore additional mmap checks for processes that are writable
67549 + by the default ACL */
67550 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, state->default_role->root_label);
67551 + if (unlikely(obj->mode & GR_WRITE))
67552 + task->is_writable = 1;
67553 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
67554 + if (unlikely(obj->mode & GR_WRITE))
67555 + task->is_writable = 1;
67556 +
67557 + gr_set_proc_res(task);
67558 +
67559 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
67560 + 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);
67561 +#endif
67562 +}
67563 +
67564 +static void gr_apply_subject_to_task(struct task_struct *task, struct acl_subject_label *subj)
67565 +{
67566 + __gr_apply_subject_to_task(&running_polstate, task, subj);
67567 +}
67568 +
67569 +__u32
67570 +gr_search_file(const struct dentry * dentry, const __u32 mode,
67571 + const struct vfsmount * mnt)
67572 +{
67573 + __u32 retval = mode;
67574 + struct acl_subject_label *curracl;
67575 + struct acl_object_label *currobj;
67576 +
67577 + if (unlikely(!(gr_status & GR_READY)))
67578 + return (mode & ~GR_AUDITS);
67579 +
67580 + curracl = current->acl;
67581 +
67582 + currobj = chk_obj_label(dentry, mnt, curracl);
67583 + retval = currobj->mode & mode;
67584 +
67585 + /* if we're opening a specified transfer file for writing
67586 + (e.g. /dev/initctl), then transfer our role to init
67587 + */
67588 + if (unlikely(currobj->mode & GR_INIT_TRANSFER && retval & GR_WRITE &&
67589 + current->role->roletype & GR_ROLE_PERSIST)) {
67590 + struct task_struct *task = init_pid_ns.child_reaper;
67591 +
67592 + if (task->role != current->role) {
67593 + struct acl_subject_label *subj;
67594 +
67595 + task->acl_sp_role = 0;
67596 + task->acl_role_id = current->acl_role_id;
67597 + task->role = current->role;
67598 + rcu_read_lock();
67599 + read_lock(&grsec_exec_file_lock);
67600 + subj = gr_get_subject_for_task(task, NULL);
67601 + gr_apply_subject_to_task(task, subj);
67602 + read_unlock(&grsec_exec_file_lock);
67603 + rcu_read_unlock();
67604 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_INIT_TRANSFER_MSG);
67605 + }
67606 + }
67607 +
67608 + if (unlikely
67609 + ((curracl->mode & (GR_LEARN | GR_INHERITLEARN)) && !(mode & GR_NOPTRACE)
67610 + && (retval != (mode & ~(GR_AUDITS | GR_SUPPRESS))))) {
67611 + __u32 new_mode = mode;
67612 +
67613 + new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
67614 +
67615 + retval = new_mode;
67616 +
67617 + if (new_mode & GR_EXEC && curracl->mode & GR_INHERITLEARN)
67618 + new_mode |= GR_INHERIT;
67619 +
67620 + if (!(mode & GR_NOLEARN))
67621 + gr_log_learn(dentry, mnt, new_mode);
67622 + }
67623 +
67624 + return retval;
67625 +}
67626 +
67627 +struct acl_object_label *gr_get_create_object(const struct dentry *new_dentry,
67628 + const struct dentry *parent,
67629 + const struct vfsmount *mnt)
67630 +{
67631 + struct name_entry *match;
67632 + struct acl_object_label *matchpo;
67633 + struct acl_subject_label *curracl;
67634 + char *path;
67635 +
67636 + if (unlikely(!(gr_status & GR_READY)))
67637 + return NULL;
67638 +
67639 + preempt_disable();
67640 + path = gr_to_filename_rbac(new_dentry, mnt);
67641 + match = lookup_name_entry_create(path);
67642 +
67643 + curracl = current->acl;
67644 +
67645 + if (match) {
67646 + read_lock(&gr_inode_lock);
67647 + matchpo = lookup_acl_obj_label_create(match->inode, match->device, curracl);
67648 + read_unlock(&gr_inode_lock);
67649 +
67650 + if (matchpo) {
67651 + preempt_enable();
67652 + return matchpo;
67653 + }
67654 + }
67655 +
67656 + // lookup parent
67657 +
67658 + matchpo = chk_obj_create_label(parent, mnt, curracl, path);
67659 +
67660 + preempt_enable();
67661 + return matchpo;
67662 +}
67663 +
67664 +__u32
67665 +gr_check_create(const struct dentry * new_dentry, const struct dentry * parent,
67666 + const struct vfsmount * mnt, const __u32 mode)
67667 +{
67668 + struct acl_object_label *matchpo;
67669 + __u32 retval;
67670 +
67671 + if (unlikely(!(gr_status & GR_READY)))
67672 + return (mode & ~GR_AUDITS);
67673 +
67674 + matchpo = gr_get_create_object(new_dentry, parent, mnt);
67675 +
67676 + retval = matchpo->mode & mode;
67677 +
67678 + if ((retval != (mode & ~(GR_AUDITS | GR_SUPPRESS)))
67679 + && (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
67680 + __u32 new_mode = mode;
67681 +
67682 + new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
67683 +
67684 + gr_log_learn(new_dentry, mnt, new_mode);
67685 + return new_mode;
67686 + }
67687 +
67688 + return retval;
67689 +}
67690 +
67691 +__u32
67692 +gr_check_link(const struct dentry * new_dentry,
67693 + const struct dentry * parent_dentry,
67694 + const struct vfsmount * parent_mnt,
67695 + const struct dentry * old_dentry, const struct vfsmount * old_mnt)
67696 +{
67697 + struct acl_object_label *obj;
67698 + __u32 oldmode, newmode;
67699 + __u32 needmode;
67700 + __u32 checkmodes = GR_FIND | GR_APPEND | GR_WRITE | GR_EXEC | GR_SETID | GR_READ |
67701 + GR_DELETE | GR_INHERIT;
67702 +
67703 + if (unlikely(!(gr_status & GR_READY)))
67704 + return (GR_CREATE | GR_LINK);
67705 +
67706 + obj = chk_obj_label(old_dentry, old_mnt, current->acl);
67707 + oldmode = obj->mode;
67708 +
67709 + obj = gr_get_create_object(new_dentry, parent_dentry, parent_mnt);
67710 + newmode = obj->mode;
67711 +
67712 + needmode = newmode & checkmodes;
67713 +
67714 + // old name for hardlink must have at least the permissions of the new name
67715 + if ((oldmode & needmode) != needmode)
67716 + goto bad;
67717 +
67718 + // if old name had restrictions/auditing, make sure the new name does as well
67719 + needmode = oldmode & (GR_NOPTRACE | GR_PTRACERD | GR_INHERIT | GR_AUDITS);
67720 +
67721 + // don't allow hardlinking of suid/sgid/fcapped files without permission
67722 + if (is_privileged_binary(old_dentry))
67723 + needmode |= GR_SETID;
67724 +
67725 + if ((newmode & needmode) != needmode)
67726 + goto bad;
67727 +
67728 + // enforce minimum permissions
67729 + if ((newmode & (GR_CREATE | GR_LINK)) == (GR_CREATE | GR_LINK))
67730 + return newmode;
67731 +bad:
67732 + needmode = oldmode;
67733 + if (is_privileged_binary(old_dentry))
67734 + needmode |= GR_SETID;
67735 +
67736 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN)) {
67737 + gr_log_learn(old_dentry, old_mnt, needmode | GR_CREATE | GR_LINK);
67738 + return (GR_CREATE | GR_LINK);
67739 + } else if (newmode & GR_SUPPRESS)
67740 + return GR_SUPPRESS;
67741 + else
67742 + return 0;
67743 +}
67744 +
67745 +int
67746 +gr_check_hidden_task(const struct task_struct *task)
67747 +{
67748 + if (unlikely(!(gr_status & GR_READY)))
67749 + return 0;
67750 +
67751 + if (!(task->acl->mode & GR_PROCFIND) && !(current->acl->mode & GR_VIEW))
67752 + return 1;
67753 +
67754 + return 0;
67755 +}
67756 +
67757 +int
67758 +gr_check_protected_task(const struct task_struct *task)
67759 +{
67760 + if (unlikely(!(gr_status & GR_READY) || !task))
67761 + return 0;
67762 +
67763 + if ((task->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
67764 + task->acl != current->acl)
67765 + return 1;
67766 +
67767 + return 0;
67768 +}
67769 +
67770 +int
67771 +gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
67772 +{
67773 + struct task_struct *p;
67774 + int ret = 0;
67775 +
67776 + if (unlikely(!(gr_status & GR_READY) || !pid))
67777 + return ret;
67778 +
67779 + read_lock(&tasklist_lock);
67780 + do_each_pid_task(pid, type, p) {
67781 + if ((p->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
67782 + p->acl != current->acl) {
67783 + ret = 1;
67784 + goto out;
67785 + }
67786 + } while_each_pid_task(pid, type, p);
67787 +out:
67788 + read_unlock(&tasklist_lock);
67789 +
67790 + return ret;
67791 +}
67792 +
67793 +void
67794 +gr_copy_label(struct task_struct *tsk)
67795 +{
67796 + struct task_struct *p = current;
67797 +
67798 + tsk->inherited = p->inherited;
67799 + tsk->acl_sp_role = 0;
67800 + tsk->acl_role_id = p->acl_role_id;
67801 + tsk->acl = p->acl;
67802 + tsk->role = p->role;
67803 + tsk->signal->used_accept = 0;
67804 + tsk->signal->curr_ip = p->signal->curr_ip;
67805 + tsk->signal->saved_ip = p->signal->saved_ip;
67806 + if (p->exec_file)
67807 + get_file(p->exec_file);
67808 + tsk->exec_file = p->exec_file;
67809 + tsk->is_writable = p->is_writable;
67810 + if (unlikely(p->signal->used_accept)) {
67811 + p->signal->curr_ip = 0;
67812 + p->signal->saved_ip = 0;
67813 + }
67814 +
67815 + return;
67816 +}
67817 +
67818 +extern int gr_process_kernel_setuid_ban(struct user_struct *user);
67819 +
67820 +int
67821 +gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs)
67822 +{
67823 + unsigned int i;
67824 + __u16 num;
67825 + uid_t *uidlist;
67826 + uid_t curuid;
67827 + int realok = 0;
67828 + int effectiveok = 0;
67829 + int fsok = 0;
67830 + uid_t globalreal, globaleffective, globalfs;
67831 +
67832 +#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT)
67833 + struct user_struct *user;
67834 +
67835 + if (!uid_valid(real))
67836 + goto skipit;
67837 +
67838 + /* find user based on global namespace */
67839 +
67840 + globalreal = GR_GLOBAL_UID(real);
67841 +
67842 + user = find_user(make_kuid(&init_user_ns, globalreal));
67843 + if (user == NULL)
67844 + goto skipit;
67845 +
67846 + if (gr_process_kernel_setuid_ban(user)) {
67847 + /* for find_user */
67848 + free_uid(user);
67849 + return 1;
67850 + }
67851 +
67852 + /* for find_user */
67853 + free_uid(user);
67854 +
67855 +skipit:
67856 +#endif
67857 +
67858 + if (unlikely(!(gr_status & GR_READY)))
67859 + return 0;
67860 +
67861 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
67862 + gr_log_learn_uid_change(real, effective, fs);
67863 +
67864 + num = current->acl->user_trans_num;
67865 + uidlist = current->acl->user_transitions;
67866 +
67867 + if (uidlist == NULL)
67868 + return 0;
67869 +
67870 + if (!uid_valid(real)) {
67871 + realok = 1;
67872 + globalreal = (uid_t)-1;
67873 + } else {
67874 + globalreal = GR_GLOBAL_UID(real);
67875 + }
67876 + if (!uid_valid(effective)) {
67877 + effectiveok = 1;
67878 + globaleffective = (uid_t)-1;
67879 + } else {
67880 + globaleffective = GR_GLOBAL_UID(effective);
67881 + }
67882 + if (!uid_valid(fs)) {
67883 + fsok = 1;
67884 + globalfs = (uid_t)-1;
67885 + } else {
67886 + globalfs = GR_GLOBAL_UID(fs);
67887 + }
67888 +
67889 + if (current->acl->user_trans_type & GR_ID_ALLOW) {
67890 + for (i = 0; i < num; i++) {
67891 + curuid = uidlist[i];
67892 + if (globalreal == curuid)
67893 + realok = 1;
67894 + if (globaleffective == curuid)
67895 + effectiveok = 1;
67896 + if (globalfs == curuid)
67897 + fsok = 1;
67898 + }
67899 + } else if (current->acl->user_trans_type & GR_ID_DENY) {
67900 + for (i = 0; i < num; i++) {
67901 + curuid = uidlist[i];
67902 + if (globalreal == curuid)
67903 + break;
67904 + if (globaleffective == curuid)
67905 + break;
67906 + if (globalfs == curuid)
67907 + break;
67908 + }
67909 + /* not in deny list */
67910 + if (i == num) {
67911 + realok = 1;
67912 + effectiveok = 1;
67913 + fsok = 1;
67914 + }
67915 + }
67916 +
67917 + if (realok && effectiveok && fsok)
67918 + return 0;
67919 + else {
67920 + gr_log_int(GR_DONT_AUDIT, GR_USRCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : globalfs) : globaleffective) : globalreal);
67921 + return 1;
67922 + }
67923 +}
67924 +
67925 +int
67926 +gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs)
67927 +{
67928 + unsigned int i;
67929 + __u16 num;
67930 + gid_t *gidlist;
67931 + gid_t curgid;
67932 + int realok = 0;
67933 + int effectiveok = 0;
67934 + int fsok = 0;
67935 + gid_t globalreal, globaleffective, globalfs;
67936 +
67937 + if (unlikely(!(gr_status & GR_READY)))
67938 + return 0;
67939 +
67940 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
67941 + gr_log_learn_gid_change(real, effective, fs);
67942 +
67943 + num = current->acl->group_trans_num;
67944 + gidlist = current->acl->group_transitions;
67945 +
67946 + if (gidlist == NULL)
67947 + return 0;
67948 +
67949 + if (!gid_valid(real)) {
67950 + realok = 1;
67951 + globalreal = (gid_t)-1;
67952 + } else {
67953 + globalreal = GR_GLOBAL_GID(real);
67954 + }
67955 + if (!gid_valid(effective)) {
67956 + effectiveok = 1;
67957 + globaleffective = (gid_t)-1;
67958 + } else {
67959 + globaleffective = GR_GLOBAL_GID(effective);
67960 + }
67961 + if (!gid_valid(fs)) {
67962 + fsok = 1;
67963 + globalfs = (gid_t)-1;
67964 + } else {
67965 + globalfs = GR_GLOBAL_GID(fs);
67966 + }
67967 +
67968 + if (current->acl->group_trans_type & GR_ID_ALLOW) {
67969 + for (i = 0; i < num; i++) {
67970 + curgid = gidlist[i];
67971 + if (globalreal == curgid)
67972 + realok = 1;
67973 + if (globaleffective == curgid)
67974 + effectiveok = 1;
67975 + if (globalfs == curgid)
67976 + fsok = 1;
67977 + }
67978 + } else if (current->acl->group_trans_type & GR_ID_DENY) {
67979 + for (i = 0; i < num; i++) {
67980 + curgid = gidlist[i];
67981 + if (globalreal == curgid)
67982 + break;
67983 + if (globaleffective == curgid)
67984 + break;
67985 + if (globalfs == curgid)
67986 + break;
67987 + }
67988 + /* not in deny list */
67989 + if (i == num) {
67990 + realok = 1;
67991 + effectiveok = 1;
67992 + fsok = 1;
67993 + }
67994 + }
67995 +
67996 + if (realok && effectiveok && fsok)
67997 + return 0;
67998 + else {
67999 + gr_log_int(GR_DONT_AUDIT, GR_GRPCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : globalfs) : globaleffective) : globalreal);
68000 + return 1;
68001 + }
68002 +}
68003 +
68004 +extern int gr_acl_is_capable(const int cap);
68005 +
68006 +void
68007 +gr_set_role_label(struct task_struct *task, const kuid_t kuid, const kgid_t kgid)
68008 +{
68009 + struct acl_role_label *role = task->role;
68010 + struct acl_subject_label *subj = NULL;
68011 + struct acl_object_label *obj;
68012 + struct file *filp;
68013 + uid_t uid;
68014 + gid_t gid;
68015 +
68016 + if (unlikely(!(gr_status & GR_READY)))
68017 + return;
68018 +
68019 + uid = GR_GLOBAL_UID(kuid);
68020 + gid = GR_GLOBAL_GID(kgid);
68021 +
68022 + filp = task->exec_file;
68023 +
68024 + /* kernel process, we'll give them the kernel role */
68025 + if (unlikely(!filp)) {
68026 + task->role = running_polstate.kernel_role;
68027 + task->acl = running_polstate.kernel_role->root_label;
68028 + return;
68029 + } else if (!task->role || !(task->role->roletype & GR_ROLE_SPECIAL)) {
68030 + /* save the current ip at time of role lookup so that the proper
68031 + IP will be learned for role_allowed_ip */
68032 + task->signal->saved_ip = task->signal->curr_ip;
68033 + role = lookup_acl_role_label(task, uid, gid);
68034 + }
68035 +
68036 + /* don't change the role if we're not a privileged process */
68037 + if (role && task->role != role &&
68038 + (((role->roletype & GR_ROLE_USER) && !gr_acl_is_capable(CAP_SETUID)) ||
68039 + ((role->roletype & GR_ROLE_GROUP) && !gr_acl_is_capable(CAP_SETGID))))
68040 + return;
68041 +
68042 + /* perform subject lookup in possibly new role
68043 + we can use this result below in the case where role == task->role
68044 + */
68045 + subj = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, role);
68046 +
68047 + /* if we changed uid/gid, but result in the same role
68048 + and are using inheritance, don't lose the inherited subject
68049 + if current subject is other than what normal lookup
68050 + would result in, we arrived via inheritance, don't
68051 + lose subject
68052 + */
68053 + if (role != task->role || (!(task->acl->mode & GR_INHERITLEARN) &&
68054 + (subj == task->acl)))
68055 + task->acl = subj;
68056 +
68057 + /* leave task->inherited unaffected */
68058 +
68059 + task->role = role;
68060 +
68061 + task->is_writable = 0;
68062 +
68063 + /* ignore additional mmap checks for processes that are writable
68064 + by the default ACL */
68065 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, running_polstate.default_role->root_label);
68066 + if (unlikely(obj->mode & GR_WRITE))
68067 + task->is_writable = 1;
68068 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
68069 + if (unlikely(obj->mode & GR_WRITE))
68070 + task->is_writable = 1;
68071 +
68072 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
68073 + 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);
68074 +#endif
68075 +
68076 + gr_set_proc_res(task);
68077 +
68078 + return;
68079 +}
68080 +
68081 +int
68082 +gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
68083 + const int unsafe_flags)
68084 +{
68085 + struct task_struct *task = current;
68086 + struct acl_subject_label *newacl;
68087 + struct acl_object_label *obj;
68088 + __u32 retmode;
68089 +
68090 + if (unlikely(!(gr_status & GR_READY)))
68091 + return 0;
68092 +
68093 + newacl = chk_subj_label(dentry, mnt, task->role);
68094 +
68095 + /* special handling for if we did an strace -f -p <pid> from an admin role, where pid then
68096 + did an exec
68097 + */
68098 + rcu_read_lock();
68099 + read_lock(&tasklist_lock);
68100 + if (task->ptrace && task->parent && ((task->parent->role->roletype & GR_ROLE_GOD) ||
68101 + (task->parent->acl->mode & GR_POVERRIDE))) {
68102 + read_unlock(&tasklist_lock);
68103 + rcu_read_unlock();
68104 + goto skip_check;
68105 + }
68106 + read_unlock(&tasklist_lock);
68107 + rcu_read_unlock();
68108 +
68109 + if (unsafe_flags && !(task->acl->mode & GR_POVERRIDE) && (task->acl != newacl) &&
68110 + !(task->role->roletype & GR_ROLE_GOD) &&
68111 + !gr_search_file(dentry, GR_PTRACERD, mnt) &&
68112 + !(task->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
68113 + if (unsafe_flags & LSM_UNSAFE_SHARE)
68114 + gr_log_fs_generic(GR_DONT_AUDIT, GR_UNSAFESHARE_EXEC_ACL_MSG, dentry, mnt);
68115 + else
68116 + gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_EXEC_ACL_MSG, dentry, mnt);
68117 + return -EACCES;
68118 + }
68119 +
68120 +skip_check:
68121 +
68122 + obj = chk_obj_label(dentry, mnt, task->acl);
68123 + retmode = obj->mode & (GR_INHERIT | GR_AUDIT_INHERIT);
68124 +
68125 + if (!(task->acl->mode & GR_INHERITLEARN) &&
68126 + ((newacl->mode & GR_LEARN) || !(retmode & GR_INHERIT))) {
68127 + if (obj->nested)
68128 + task->acl = obj->nested;
68129 + else
68130 + task->acl = newacl;
68131 + task->inherited = 0;
68132 + } else {
68133 + task->inherited = 1;
68134 + if (retmode & GR_INHERIT && retmode & GR_AUDIT_INHERIT)
68135 + gr_log_str_fs(GR_DO_AUDIT, GR_INHERIT_ACL_MSG, task->acl->filename, dentry, mnt);
68136 + }
68137 +
68138 + task->is_writable = 0;
68139 +
68140 + /* ignore additional mmap checks for processes that are writable
68141 + by the default ACL */
68142 + obj = chk_obj_label(dentry, mnt, running_polstate.default_role->root_label);
68143 + if (unlikely(obj->mode & GR_WRITE))
68144 + task->is_writable = 1;
68145 + obj = chk_obj_label(dentry, mnt, task->role->root_label);
68146 + if (unlikely(obj->mode & GR_WRITE))
68147 + task->is_writable = 1;
68148 +
68149 + gr_set_proc_res(task);
68150 +
68151 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
68152 + 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);
68153 +#endif
68154 + return 0;
68155 +}
68156 +
68157 +/* always called with valid inodev ptr */
68158 +static void
68159 +do_handle_delete(struct inodev_entry *inodev, const ino_t ino, const dev_t dev)
68160 +{
68161 + struct acl_object_label *matchpo;
68162 + struct acl_subject_label *matchps;
68163 + struct acl_subject_label *subj;
68164 + struct acl_role_label *role;
68165 + unsigned int x;
68166 +
68167 + FOR_EACH_ROLE_START(role)
68168 + FOR_EACH_SUBJECT_START(role, subj, x)
68169 + if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
68170 + matchpo->mode |= GR_DELETED;
68171 + FOR_EACH_SUBJECT_END(subj,x)
68172 + FOR_EACH_NESTED_SUBJECT_START(role, subj)
68173 + /* nested subjects aren't in the role's subj_hash table */
68174 + if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
68175 + matchpo->mode |= GR_DELETED;
68176 + FOR_EACH_NESTED_SUBJECT_END(subj)
68177 + if ((matchps = lookup_acl_subj_label(ino, dev, role)) != NULL)
68178 + matchps->mode |= GR_DELETED;
68179 + FOR_EACH_ROLE_END(role)
68180 +
68181 + inodev->nentry->deleted = 1;
68182 +
68183 + return;
68184 +}
68185 +
68186 +void
68187 +gr_handle_delete(const ino_t ino, const dev_t dev)
68188 +{
68189 + struct inodev_entry *inodev;
68190 +
68191 + if (unlikely(!(gr_status & GR_READY)))
68192 + return;
68193 +
68194 + write_lock(&gr_inode_lock);
68195 + inodev = lookup_inodev_entry(ino, dev);
68196 + if (inodev != NULL)
68197 + do_handle_delete(inodev, ino, dev);
68198 + write_unlock(&gr_inode_lock);
68199 +
68200 + return;
68201 +}
68202 +
68203 +static void
68204 +update_acl_obj_label(const ino_t oldinode, const dev_t olddevice,
68205 + const ino_t newinode, const dev_t newdevice,
68206 + struct acl_subject_label *subj)
68207 +{
68208 + unsigned int index = gr_fhash(oldinode, olddevice, subj->obj_hash_size);
68209 + struct acl_object_label *match;
68210 +
68211 + match = subj->obj_hash[index];
68212 +
68213 + while (match && (match->inode != oldinode ||
68214 + match->device != olddevice ||
68215 + !(match->mode & GR_DELETED)))
68216 + match = match->next;
68217 +
68218 + if (match && (match->inode == oldinode)
68219 + && (match->device == olddevice)
68220 + && (match->mode & GR_DELETED)) {
68221 + if (match->prev == NULL) {
68222 + subj->obj_hash[index] = match->next;
68223 + if (match->next != NULL)
68224 + match->next->prev = NULL;
68225 + } else {
68226 + match->prev->next = match->next;
68227 + if (match->next != NULL)
68228 + match->next->prev = match->prev;
68229 + }
68230 + match->prev = NULL;
68231 + match->next = NULL;
68232 + match->inode = newinode;
68233 + match->device = newdevice;
68234 + match->mode &= ~GR_DELETED;
68235 +
68236 + insert_acl_obj_label(match, subj);
68237 + }
68238 +
68239 + return;
68240 +}
68241 +
68242 +static void
68243 +update_acl_subj_label(const ino_t oldinode, const dev_t olddevice,
68244 + const ino_t newinode, const dev_t newdevice,
68245 + struct acl_role_label *role)
68246 +{
68247 + unsigned int index = gr_fhash(oldinode, olddevice, role->subj_hash_size);
68248 + struct acl_subject_label *match;
68249 +
68250 + match = role->subj_hash[index];
68251 +
68252 + while (match && (match->inode != oldinode ||
68253 + match->device != olddevice ||
68254 + !(match->mode & GR_DELETED)))
68255 + match = match->next;
68256 +
68257 + if (match && (match->inode == oldinode)
68258 + && (match->device == olddevice)
68259 + && (match->mode & GR_DELETED)) {
68260 + if (match->prev == NULL) {
68261 + role->subj_hash[index] = match->next;
68262 + if (match->next != NULL)
68263 + match->next->prev = NULL;
68264 + } else {
68265 + match->prev->next = match->next;
68266 + if (match->next != NULL)
68267 + match->next->prev = match->prev;
68268 + }
68269 + match->prev = NULL;
68270 + match->next = NULL;
68271 + match->inode = newinode;
68272 + match->device = newdevice;
68273 + match->mode &= ~GR_DELETED;
68274 +
68275 + insert_acl_subj_label(match, role);
68276 + }
68277 +
68278 + return;
68279 +}
68280 +
68281 +static void
68282 +update_inodev_entry(const ino_t oldinode, const dev_t olddevice,
68283 + const ino_t newinode, const dev_t newdevice)
68284 +{
68285 + unsigned int index = gr_fhash(oldinode, olddevice, running_polstate.inodev_set.i_size);
68286 + struct inodev_entry *match;
68287 +
68288 + match = running_polstate.inodev_set.i_hash[index];
68289 +
68290 + while (match && (match->nentry->inode != oldinode ||
68291 + match->nentry->device != olddevice || !match->nentry->deleted))
68292 + match = match->next;
68293 +
68294 + if (match && (match->nentry->inode == oldinode)
68295 + && (match->nentry->device == olddevice) &&
68296 + match->nentry->deleted) {
68297 + if (match->prev == NULL) {
68298 + running_polstate.inodev_set.i_hash[index] = match->next;
68299 + if (match->next != NULL)
68300 + match->next->prev = NULL;
68301 + } else {
68302 + match->prev->next = match->next;
68303 + if (match->next != NULL)
68304 + match->next->prev = match->prev;
68305 + }
68306 + match->prev = NULL;
68307 + match->next = NULL;
68308 + match->nentry->inode = newinode;
68309 + match->nentry->device = newdevice;
68310 + match->nentry->deleted = 0;
68311 +
68312 + insert_inodev_entry(match);
68313 + }
68314 +
68315 + return;
68316 +}
68317 +
68318 +static void
68319 +__do_handle_create(const struct name_entry *matchn, ino_t ino, dev_t dev)
68320 +{
68321 + struct acl_subject_label *subj;
68322 + struct acl_role_label *role;
68323 + unsigned int x;
68324 +
68325 + FOR_EACH_ROLE_START(role)
68326 + update_acl_subj_label(matchn->inode, matchn->device, ino, dev, role);
68327 +
68328 + FOR_EACH_NESTED_SUBJECT_START(role, subj)
68329 + if ((subj->inode == ino) && (subj->device == dev)) {
68330 + subj->inode = ino;
68331 + subj->device = dev;
68332 + }
68333 + /* nested subjects aren't in the role's subj_hash table */
68334 + update_acl_obj_label(matchn->inode, matchn->device,
68335 + ino, dev, subj);
68336 + FOR_EACH_NESTED_SUBJECT_END(subj)
68337 + FOR_EACH_SUBJECT_START(role, subj, x)
68338 + update_acl_obj_label(matchn->inode, matchn->device,
68339 + ino, dev, subj);
68340 + FOR_EACH_SUBJECT_END(subj,x)
68341 + FOR_EACH_ROLE_END(role)
68342 +
68343 + update_inodev_entry(matchn->inode, matchn->device, ino, dev);
68344 +
68345 + return;
68346 +}
68347 +
68348 +static void
68349 +do_handle_create(const struct name_entry *matchn, const struct dentry *dentry,
68350 + const struct vfsmount *mnt)
68351 +{
68352 + ino_t ino = dentry->d_inode->i_ino;
68353 + dev_t dev = __get_dev(dentry);
68354 +
68355 + __do_handle_create(matchn, ino, dev);
68356 +
68357 + return;
68358 +}
68359 +
68360 +void
68361 +gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
68362 +{
68363 + struct name_entry *matchn;
68364 +
68365 + if (unlikely(!(gr_status & GR_READY)))
68366 + return;
68367 +
68368 + preempt_disable();
68369 + matchn = lookup_name_entry(gr_to_filename_rbac(dentry, mnt));
68370 +
68371 + if (unlikely((unsigned long)matchn)) {
68372 + write_lock(&gr_inode_lock);
68373 + do_handle_create(matchn, dentry, mnt);
68374 + write_unlock(&gr_inode_lock);
68375 + }
68376 + preempt_enable();
68377 +
68378 + return;
68379 +}
68380 +
68381 +void
68382 +gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
68383 +{
68384 + struct name_entry *matchn;
68385 +
68386 + if (unlikely(!(gr_status & GR_READY)))
68387 + return;
68388 +
68389 + preempt_disable();
68390 + matchn = lookup_name_entry(gr_to_proc_filename_rbac(dentry, init_pid_ns.proc_mnt));
68391 +
68392 + if (unlikely((unsigned long)matchn)) {
68393 + write_lock(&gr_inode_lock);
68394 + __do_handle_create(matchn, inode->i_ino, inode->i_sb->s_dev);
68395 + write_unlock(&gr_inode_lock);
68396 + }
68397 + preempt_enable();
68398 +
68399 + return;
68400 +}
68401 +
68402 +void
68403 +gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
68404 + struct dentry *old_dentry,
68405 + struct dentry *new_dentry,
68406 + struct vfsmount *mnt, const __u8 replace)
68407 +{
68408 + struct name_entry *matchn;
68409 + struct inodev_entry *inodev;
68410 + struct inode *inode = new_dentry->d_inode;
68411 + ino_t old_ino = old_dentry->d_inode->i_ino;
68412 + dev_t old_dev = __get_dev(old_dentry);
68413 +
68414 + /* vfs_rename swaps the name and parent link for old_dentry and
68415 + new_dentry
68416 + at this point, old_dentry has the new name, parent link, and inode
68417 + for the renamed file
68418 + if a file is being replaced by a rename, new_dentry has the inode
68419 + and name for the replaced file
68420 + */
68421 +
68422 + if (unlikely(!(gr_status & GR_READY)))
68423 + return;
68424 +
68425 + preempt_disable();
68426 + matchn = lookup_name_entry(gr_to_filename_rbac(old_dentry, mnt));
68427 +
68428 + /* we wouldn't have to check d_inode if it weren't for
68429 + NFS silly-renaming
68430 + */
68431 +
68432 + write_lock(&gr_inode_lock);
68433 + if (unlikely(replace && inode)) {
68434 + ino_t new_ino = inode->i_ino;
68435 + dev_t new_dev = __get_dev(new_dentry);
68436 +
68437 + inodev = lookup_inodev_entry(new_ino, new_dev);
68438 + if (inodev != NULL && ((inode->i_nlink <= 1) || S_ISDIR(inode->i_mode)))
68439 + do_handle_delete(inodev, new_ino, new_dev);
68440 + }
68441 +
68442 + inodev = lookup_inodev_entry(old_ino, old_dev);
68443 + if (inodev != NULL && ((old_dentry->d_inode->i_nlink <= 1) || S_ISDIR(old_dentry->d_inode->i_mode)))
68444 + do_handle_delete(inodev, old_ino, old_dev);
68445 +
68446 + if (unlikely((unsigned long)matchn))
68447 + do_handle_create(matchn, old_dentry, mnt);
68448 +
68449 + write_unlock(&gr_inode_lock);
68450 + preempt_enable();
68451 +
68452 + return;
68453 +}
68454 +
68455 +#if defined(CONFIG_GRKERNSEC_RESLOG) || !defined(CONFIG_GRKERNSEC_NO_RBAC)
68456 +static const unsigned long res_learn_bumps[GR_NLIMITS] = {
68457 + [RLIMIT_CPU] = GR_RLIM_CPU_BUMP,
68458 + [RLIMIT_FSIZE] = GR_RLIM_FSIZE_BUMP,
68459 + [RLIMIT_DATA] = GR_RLIM_DATA_BUMP,
68460 + [RLIMIT_STACK] = GR_RLIM_STACK_BUMP,
68461 + [RLIMIT_CORE] = GR_RLIM_CORE_BUMP,
68462 + [RLIMIT_RSS] = GR_RLIM_RSS_BUMP,
68463 + [RLIMIT_NPROC] = GR_RLIM_NPROC_BUMP,
68464 + [RLIMIT_NOFILE] = GR_RLIM_NOFILE_BUMP,
68465 + [RLIMIT_MEMLOCK] = GR_RLIM_MEMLOCK_BUMP,
68466 + [RLIMIT_AS] = GR_RLIM_AS_BUMP,
68467 + [RLIMIT_LOCKS] = GR_RLIM_LOCKS_BUMP,
68468 + [RLIMIT_SIGPENDING] = GR_RLIM_SIGPENDING_BUMP,
68469 + [RLIMIT_MSGQUEUE] = GR_RLIM_MSGQUEUE_BUMP,
68470 + [RLIMIT_NICE] = GR_RLIM_NICE_BUMP,
68471 + [RLIMIT_RTPRIO] = GR_RLIM_RTPRIO_BUMP,
68472 + [RLIMIT_RTTIME] = GR_RLIM_RTTIME_BUMP
68473 +};
68474 +
68475 +void
68476 +gr_learn_resource(const struct task_struct *task,
68477 + const int res, const unsigned long wanted, const int gt)
68478 +{
68479 + struct acl_subject_label *acl;
68480 + const struct cred *cred;
68481 +
68482 + if (unlikely((gr_status & GR_READY) &&
68483 + task->acl && (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))))
68484 + goto skip_reslog;
68485 +
68486 + gr_log_resource(task, res, wanted, gt);
68487 +skip_reslog:
68488 +
68489 + if (unlikely(!(gr_status & GR_READY) || !wanted || res >= GR_NLIMITS))
68490 + return;
68491 +
68492 + acl = task->acl;
68493 +
68494 + if (likely(!acl || !(acl->mode & (GR_LEARN | GR_INHERITLEARN)) ||
68495 + !(acl->resmask & (1U << (unsigned short) res))))
68496 + return;
68497 +
68498 + if (wanted >= acl->res[res].rlim_cur) {
68499 + unsigned long res_add;
68500 +
68501 + res_add = wanted + res_learn_bumps[res];
68502 +
68503 + acl->res[res].rlim_cur = res_add;
68504 +
68505 + if (wanted > acl->res[res].rlim_max)
68506 + acl->res[res].rlim_max = res_add;
68507 +
68508 + /* only log the subject filename, since resource logging is supported for
68509 + single-subject learning only */
68510 + rcu_read_lock();
68511 + cred = __task_cred(task);
68512 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
68513 + task->role->roletype, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), acl->filename,
68514 + acl->filename, acl->res[res].rlim_cur, acl->res[res].rlim_max,
68515 + "", (unsigned long) res, &task->signal->saved_ip);
68516 + rcu_read_unlock();
68517 + }
68518 +
68519 + return;
68520 +}
68521 +EXPORT_SYMBOL_GPL(gr_learn_resource);
68522 +#endif
68523 +
68524 +#if defined(CONFIG_PAX_HAVE_ACL_FLAGS) && (defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR))
68525 +void
68526 +pax_set_initial_flags(struct linux_binprm *bprm)
68527 +{
68528 + struct task_struct *task = current;
68529 + struct acl_subject_label *proc;
68530 + unsigned long flags;
68531 +
68532 + if (unlikely(!(gr_status & GR_READY)))
68533 + return;
68534 +
68535 + flags = pax_get_flags(task);
68536 +
68537 + proc = task->acl;
68538 +
68539 + if (proc->pax_flags & GR_PAX_DISABLE_PAGEEXEC)
68540 + flags &= ~MF_PAX_PAGEEXEC;
68541 + if (proc->pax_flags & GR_PAX_DISABLE_SEGMEXEC)
68542 + flags &= ~MF_PAX_SEGMEXEC;
68543 + if (proc->pax_flags & GR_PAX_DISABLE_RANDMMAP)
68544 + flags &= ~MF_PAX_RANDMMAP;
68545 + if (proc->pax_flags & GR_PAX_DISABLE_EMUTRAMP)
68546 + flags &= ~MF_PAX_EMUTRAMP;
68547 + if (proc->pax_flags & GR_PAX_DISABLE_MPROTECT)
68548 + flags &= ~MF_PAX_MPROTECT;
68549 +
68550 + if (proc->pax_flags & GR_PAX_ENABLE_PAGEEXEC)
68551 + flags |= MF_PAX_PAGEEXEC;
68552 + if (proc->pax_flags & GR_PAX_ENABLE_SEGMEXEC)
68553 + flags |= MF_PAX_SEGMEXEC;
68554 + if (proc->pax_flags & GR_PAX_ENABLE_RANDMMAP)
68555 + flags |= MF_PAX_RANDMMAP;
68556 + if (proc->pax_flags & GR_PAX_ENABLE_EMUTRAMP)
68557 + flags |= MF_PAX_EMUTRAMP;
68558 + if (proc->pax_flags & GR_PAX_ENABLE_MPROTECT)
68559 + flags |= MF_PAX_MPROTECT;
68560 +
68561 + pax_set_flags(task, flags);
68562 +
68563 + return;
68564 +}
68565 +#endif
68566 +
68567 +int
68568 +gr_handle_proc_ptrace(struct task_struct *task)
68569 +{
68570 + struct file *filp;
68571 + struct task_struct *tmp = task;
68572 + struct task_struct *curtemp = current;
68573 + __u32 retmode;
68574 +
68575 +#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
68576 + if (unlikely(!(gr_status & GR_READY)))
68577 + return 0;
68578 +#endif
68579 +
68580 + read_lock(&tasklist_lock);
68581 + read_lock(&grsec_exec_file_lock);
68582 + filp = task->exec_file;
68583 +
68584 + while (task_pid_nr(tmp) > 0) {
68585 + if (tmp == curtemp)
68586 + break;
68587 + tmp = tmp->real_parent;
68588 + }
68589 +
68590 + if (!filp || (task_pid_nr(tmp) == 0 && ((grsec_enable_harden_ptrace && gr_is_global_nonroot(current_uid()) && !(gr_status & GR_READY)) ||
68591 + ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE))))) {
68592 + read_unlock(&grsec_exec_file_lock);
68593 + read_unlock(&tasklist_lock);
68594 + return 1;
68595 + }
68596 +
68597 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
68598 + if (!(gr_status & GR_READY)) {
68599 + read_unlock(&grsec_exec_file_lock);
68600 + read_unlock(&tasklist_lock);
68601 + return 0;
68602 + }
68603 +#endif
68604 +
68605 + retmode = gr_search_file(filp->f_path.dentry, GR_NOPTRACE, filp->f_path.mnt);
68606 + read_unlock(&grsec_exec_file_lock);
68607 + read_unlock(&tasklist_lock);
68608 +
68609 + if (retmode & GR_NOPTRACE)
68610 + return 1;
68611 +
68612 + if (!(current->acl->mode & GR_POVERRIDE) && !(current->role->roletype & GR_ROLE_GOD)
68613 + && (current->acl != task->acl || (current->acl != current->role->root_label
68614 + && task_pid_nr(current) != task_pid_nr(task))))
68615 + return 1;
68616 +
68617 + return 0;
68618 +}
68619 +
68620 +void task_grsec_rbac(struct seq_file *m, struct task_struct *p)
68621 +{
68622 + if (unlikely(!(gr_status & GR_READY)))
68623 + return;
68624 +
68625 + if (!(current->role->roletype & GR_ROLE_GOD))
68626 + return;
68627 +
68628 + seq_printf(m, "RBAC:\t%.64s:%c:%.950s\n",
68629 + p->role->rolename, gr_task_roletype_to_char(p),
68630 + p->acl->filename);
68631 +}
68632 +
68633 +int
68634 +gr_handle_ptrace(struct task_struct *task, const long request)
68635 +{
68636 + struct task_struct *tmp = task;
68637 + struct task_struct *curtemp = current;
68638 + __u32 retmode;
68639 +
68640 +#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
68641 + if (unlikely(!(gr_status & GR_READY)))
68642 + return 0;
68643 +#endif
68644 + if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
68645 + read_lock(&tasklist_lock);
68646 + while (task_pid_nr(tmp) > 0) {
68647 + if (tmp == curtemp)
68648 + break;
68649 + tmp = tmp->real_parent;
68650 + }
68651 +
68652 + if (task_pid_nr(tmp) == 0 && ((grsec_enable_harden_ptrace && gr_is_global_nonroot(current_uid()) && !(gr_status & GR_READY)) ||
68653 + ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE)))) {
68654 + read_unlock(&tasklist_lock);
68655 + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
68656 + return 1;
68657 + }
68658 + read_unlock(&tasklist_lock);
68659 + }
68660 +
68661 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
68662 + if (!(gr_status & GR_READY))
68663 + return 0;
68664 +#endif
68665 +
68666 + read_lock(&grsec_exec_file_lock);
68667 + if (unlikely(!task->exec_file)) {
68668 + read_unlock(&grsec_exec_file_lock);
68669 + return 0;
68670 + }
68671 +
68672 + retmode = gr_search_file(task->exec_file->f_path.dentry, GR_PTRACERD | GR_NOPTRACE, task->exec_file->f_path.mnt);
68673 + read_unlock(&grsec_exec_file_lock);
68674 +
68675 + if (retmode & GR_NOPTRACE) {
68676 + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
68677 + return 1;
68678 + }
68679 +
68680 + if (retmode & GR_PTRACERD) {
68681 + switch (request) {
68682 + case PTRACE_SEIZE:
68683 + case PTRACE_POKETEXT:
68684 + case PTRACE_POKEDATA:
68685 + case PTRACE_POKEUSR:
68686 +#if !defined(CONFIG_PPC32) && !defined(CONFIG_PPC64) && !defined(CONFIG_PARISC) && !defined(CONFIG_ALPHA) && !defined(CONFIG_IA64)
68687 + case PTRACE_SETREGS:
68688 + case PTRACE_SETFPREGS:
68689 +#endif
68690 +#ifdef CONFIG_X86
68691 + case PTRACE_SETFPXREGS:
68692 +#endif
68693 +#ifdef CONFIG_ALTIVEC
68694 + case PTRACE_SETVRREGS:
68695 +#endif
68696 + return 1;
68697 + default:
68698 + return 0;
68699 + }
68700 + } else if (!(current->acl->mode & GR_POVERRIDE) &&
68701 + !(current->role->roletype & GR_ROLE_GOD) &&
68702 + (current->acl != task->acl)) {
68703 + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
68704 + return 1;
68705 + }
68706 +
68707 + return 0;
68708 +}
68709 +
68710 +static int is_writable_mmap(const struct file *filp)
68711 +{
68712 + struct task_struct *task = current;
68713 + struct acl_object_label *obj, *obj2;
68714 +
68715 + if (gr_status & GR_READY && !(task->acl->mode & GR_OVERRIDE) &&
68716 + !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))) {
68717 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, running_polstate.default_role->root_label);
68718 + obj2 = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt,
68719 + task->role->root_label);
68720 + if (unlikely((obj->mode & GR_WRITE) || (obj2->mode & GR_WRITE))) {
68721 + gr_log_fs_generic(GR_DONT_AUDIT, GR_WRITLIB_ACL_MSG, filp->f_path.dentry, filp->f_path.mnt);
68722 + return 1;
68723 + }
68724 + }
68725 + return 0;
68726 +}
68727 +
68728 +int
68729 +gr_acl_handle_mmap(const struct file *file, const unsigned long prot)
68730 +{
68731 + __u32 mode;
68732 +
68733 + if (unlikely(!file || !(prot & PROT_EXEC)))
68734 + return 1;
68735 +
68736 + if (is_writable_mmap(file))
68737 + return 0;
68738 +
68739 + mode =
68740 + gr_search_file(file->f_path.dentry,
68741 + GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
68742 + file->f_path.mnt);
68743 +
68744 + if (!gr_tpe_allow(file))
68745 + return 0;
68746 +
68747 + if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
68748 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
68749 + return 0;
68750 + } else if (unlikely(!(mode & GR_EXEC))) {
68751 + return 0;
68752 + } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
68753 + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
68754 + return 1;
68755 + }
68756 +
68757 + return 1;
68758 +}
68759 +
68760 +int
68761 +gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
68762 +{
68763 + __u32 mode;
68764 +
68765 + if (unlikely(!file || !(prot & PROT_EXEC)))
68766 + return 1;
68767 +
68768 + if (is_writable_mmap(file))
68769 + return 0;
68770 +
68771 + mode =
68772 + gr_search_file(file->f_path.dentry,
68773 + GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
68774 + file->f_path.mnt);
68775 +
68776 + if (!gr_tpe_allow(file))
68777 + return 0;
68778 +
68779 + if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
68780 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
68781 + return 0;
68782 + } else if (unlikely(!(mode & GR_EXEC))) {
68783 + return 0;
68784 + } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
68785 + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
68786 + return 1;
68787 + }
68788 +
68789 + return 1;
68790 +}
68791 +
68792 +void
68793 +gr_acl_handle_psacct(struct task_struct *task, const long code)
68794 +{
68795 + unsigned long runtime, cputime;
68796 + cputime_t utime, stime;
68797 + unsigned int wday, cday;
68798 + __u8 whr, chr;
68799 + __u8 wmin, cmin;
68800 + __u8 wsec, csec;
68801 + struct timespec timeval;
68802 +
68803 + if (unlikely(!(gr_status & GR_READY) || !task->acl ||
68804 + !(task->acl->mode & GR_PROCACCT)))
68805 + return;
68806 +
68807 + do_posix_clock_monotonic_gettime(&timeval);
68808 + runtime = timeval.tv_sec - task->start_time.tv_sec;
68809 + wday = runtime / (60 * 60 * 24);
68810 + runtime -= wday * (60 * 60 * 24);
68811 + whr = runtime / (60 * 60);
68812 + runtime -= whr * (60 * 60);
68813 + wmin = runtime / 60;
68814 + runtime -= wmin * 60;
68815 + wsec = runtime;
68816 +
68817 + task_cputime(task, &utime, &stime);
68818 + cputime = cputime_to_secs(utime + stime);
68819 + cday = cputime / (60 * 60 * 24);
68820 + cputime -= cday * (60 * 60 * 24);
68821 + chr = cputime / (60 * 60);
68822 + cputime -= chr * (60 * 60);
68823 + cmin = cputime / 60;
68824 + cputime -= cmin * 60;
68825 + csec = cputime;
68826 +
68827 + gr_log_procacct(GR_DO_AUDIT, GR_ACL_PROCACCT_MSG, task, wday, whr, wmin, wsec, cday, chr, cmin, csec, code);
68828 +
68829 + return;
68830 +}
68831 +
68832 +#ifdef CONFIG_TASKSTATS
68833 +int gr_is_taskstats_denied(int pid)
68834 +{
68835 + struct task_struct *task;
68836 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
68837 + const struct cred *cred;
68838 +#endif
68839 + int ret = 0;
68840 +
68841 + /* restrict taskstats viewing to un-chrooted root users
68842 + who have the 'view' subject flag if the RBAC system is enabled
68843 + */
68844 +
68845 + rcu_read_lock();
68846 + read_lock(&tasklist_lock);
68847 + task = find_task_by_vpid(pid);
68848 + if (task) {
68849 +#ifdef CONFIG_GRKERNSEC_CHROOT
68850 + if (proc_is_chrooted(task))
68851 + ret = -EACCES;
68852 +#endif
68853 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
68854 + cred = __task_cred(task);
68855 +#ifdef CONFIG_GRKERNSEC_PROC_USER
68856 + if (gr_is_global_nonroot(cred->uid))
68857 + ret = -EACCES;
68858 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
68859 + if (gr_is_global_nonroot(cred->uid) && !groups_search(cred->group_info, grsec_proc_gid))
68860 + ret = -EACCES;
68861 +#endif
68862 +#endif
68863 + if (gr_status & GR_READY) {
68864 + if (!(task->acl->mode & GR_VIEW))
68865 + ret = -EACCES;
68866 + }
68867 + } else
68868 + ret = -ENOENT;
68869 +
68870 + read_unlock(&tasklist_lock);
68871 + rcu_read_unlock();
68872 +
68873 + return ret;
68874 +}
68875 +#endif
68876 +
68877 +/* AUXV entries are filled via a descendant of search_binary_handler
68878 + after we've already applied the subject for the target
68879 +*/
68880 +int gr_acl_enable_at_secure(void)
68881 +{
68882 + if (unlikely(!(gr_status & GR_READY)))
68883 + return 0;
68884 +
68885 + if (current->acl->mode & GR_ATSECURE)
68886 + return 1;
68887 +
68888 + return 0;
68889 +}
68890 +
68891 +int gr_acl_handle_filldir(const struct file *file, const char *name, const unsigned int namelen, const ino_t ino)
68892 +{
68893 + struct task_struct *task = current;
68894 + struct dentry *dentry = file->f_path.dentry;
68895 + struct vfsmount *mnt = file->f_path.mnt;
68896 + struct acl_object_label *obj, *tmp;
68897 + struct acl_subject_label *subj;
68898 + unsigned int bufsize;
68899 + int is_not_root;
68900 + char *path;
68901 + dev_t dev = __get_dev(dentry);
68902 +
68903 + if (unlikely(!(gr_status & GR_READY)))
68904 + return 1;
68905 +
68906 + if (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))
68907 + return 1;
68908 +
68909 + /* ignore Eric Biederman */
68910 + if (IS_PRIVATE(dentry->d_inode))
68911 + return 1;
68912 +
68913 + subj = task->acl;
68914 + read_lock(&gr_inode_lock);
68915 + do {
68916 + obj = lookup_acl_obj_label(ino, dev, subj);
68917 + if (obj != NULL) {
68918 + read_unlock(&gr_inode_lock);
68919 + return (obj->mode & GR_FIND) ? 1 : 0;
68920 + }
68921 + } while ((subj = subj->parent_subject));
68922 + read_unlock(&gr_inode_lock);
68923 +
68924 + /* this is purely an optimization since we're looking for an object
68925 + for the directory we're doing a readdir on
68926 + if it's possible for any globbed object to match the entry we're
68927 + filling into the directory, then the object we find here will be
68928 + an anchor point with attached globbed objects
68929 + */
68930 + obj = chk_obj_label_noglob(dentry, mnt, task->acl);
68931 + if (obj->globbed == NULL)
68932 + return (obj->mode & GR_FIND) ? 1 : 0;
68933 +
68934 + is_not_root = ((obj->filename[0] == '/') &&
68935 + (obj->filename[1] == '\0')) ? 0 : 1;
68936 + bufsize = PAGE_SIZE - namelen - is_not_root;
68937 +
68938 + /* check bufsize > PAGE_SIZE || bufsize == 0 */
68939 + if (unlikely((bufsize - 1) > (PAGE_SIZE - 1)))
68940 + return 1;
68941 +
68942 + preempt_disable();
68943 + path = d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
68944 + bufsize);
68945 +
68946 + bufsize = strlen(path);
68947 +
68948 + /* if base is "/", don't append an additional slash */
68949 + if (is_not_root)
68950 + *(path + bufsize) = '/';
68951 + memcpy(path + bufsize + is_not_root, name, namelen);
68952 + *(path + bufsize + namelen + is_not_root) = '\0';
68953 +
68954 + tmp = obj->globbed;
68955 + while (tmp) {
68956 + if (!glob_match(tmp->filename, path)) {
68957 + preempt_enable();
68958 + return (tmp->mode & GR_FIND) ? 1 : 0;
68959 + }
68960 + tmp = tmp->next;
68961 + }
68962 + preempt_enable();
68963 + return (obj->mode & GR_FIND) ? 1 : 0;
68964 +}
68965 +
68966 +void gr_put_exec_file(struct task_struct *task)
68967 +{
68968 + struct file *filp;
68969 +
68970 + write_lock(&grsec_exec_file_lock);
68971 + filp = task->exec_file;
68972 + task->exec_file = NULL;
68973 + write_unlock(&grsec_exec_file_lock);
68974 +
68975 + if (filp)
68976 + fput(filp);
68977 +
68978 + return;
68979 +}
68980 +
68981 +
68982 +#ifdef CONFIG_NETFILTER_XT_MATCH_GRADM_MODULE
68983 +EXPORT_SYMBOL_GPL(gr_acl_is_enabled);
68984 +#endif
68985 +#ifdef CONFIG_SECURITY
68986 +EXPORT_SYMBOL_GPL(gr_check_user_change);
68987 +EXPORT_SYMBOL_GPL(gr_check_group_change);
68988 +#endif
68989 +
68990 diff --git a/grsecurity/gracl_alloc.c b/grsecurity/gracl_alloc.c
68991 new file mode 100644
68992 index 0000000..18ffbbd
68993 --- /dev/null
68994 +++ b/grsecurity/gracl_alloc.c
68995 @@ -0,0 +1,105 @@
68996 +#include <linux/kernel.h>
68997 +#include <linux/mm.h>
68998 +#include <linux/slab.h>
68999 +#include <linux/vmalloc.h>
69000 +#include <linux/gracl.h>
69001 +#include <linux/grsecurity.h>
69002 +
69003 +static struct gr_alloc_state __current_alloc_state = { 1, 1, NULL };
69004 +struct gr_alloc_state *current_alloc_state = &__current_alloc_state;
69005 +
69006 +static __inline__ int
69007 +alloc_pop(void)
69008 +{
69009 + if (current_alloc_state->alloc_stack_next == 1)
69010 + return 0;
69011 +
69012 + kfree(current_alloc_state->alloc_stack[current_alloc_state->alloc_stack_next - 2]);
69013 +
69014 + current_alloc_state->alloc_stack_next--;
69015 +
69016 + return 1;
69017 +}
69018 +
69019 +static __inline__ int
69020 +alloc_push(void *buf)
69021 +{
69022 + if (current_alloc_state->alloc_stack_next >= current_alloc_state->alloc_stack_size)
69023 + return 1;
69024 +
69025 + current_alloc_state->alloc_stack[current_alloc_state->alloc_stack_next - 1] = buf;
69026 +
69027 + current_alloc_state->alloc_stack_next++;
69028 +
69029 + return 0;
69030 +}
69031 +
69032 +void *
69033 +acl_alloc(unsigned long len)
69034 +{
69035 + void *ret = NULL;
69036 +
69037 + if (!len || len > PAGE_SIZE)
69038 + goto out;
69039 +
69040 + ret = kmalloc(len, GFP_KERNEL);
69041 +
69042 + if (ret) {
69043 + if (alloc_push(ret)) {
69044 + kfree(ret);
69045 + ret = NULL;
69046 + }
69047 + }
69048 +
69049 +out:
69050 + return ret;
69051 +}
69052 +
69053 +void *
69054 +acl_alloc_num(unsigned long num, unsigned long len)
69055 +{
69056 + if (!len || (num > (PAGE_SIZE / len)))
69057 + return NULL;
69058 +
69059 + return acl_alloc(num * len);
69060 +}
69061 +
69062 +void
69063 +acl_free_all(void)
69064 +{
69065 + if (!current_alloc_state->alloc_stack)
69066 + return;
69067 +
69068 + while (alloc_pop()) ;
69069 +
69070 + if (current_alloc_state->alloc_stack) {
69071 + if ((current_alloc_state->alloc_stack_size * sizeof (void *)) <= PAGE_SIZE)
69072 + kfree(current_alloc_state->alloc_stack);
69073 + else
69074 + vfree(current_alloc_state->alloc_stack);
69075 + }
69076 +
69077 + current_alloc_state->alloc_stack = NULL;
69078 + current_alloc_state->alloc_stack_size = 1;
69079 + current_alloc_state->alloc_stack_next = 1;
69080 +
69081 + return;
69082 +}
69083 +
69084 +int
69085 +acl_alloc_stack_init(unsigned long size)
69086 +{
69087 + if ((size * sizeof (void *)) <= PAGE_SIZE)
69088 + current_alloc_state->alloc_stack =
69089 + (void **) kmalloc(size * sizeof (void *), GFP_KERNEL);
69090 + else
69091 + current_alloc_state->alloc_stack = (void **) vmalloc(size * sizeof (void *));
69092 +
69093 + current_alloc_state->alloc_stack_size = size;
69094 + current_alloc_state->alloc_stack_next = 1;
69095 +
69096 + if (!current_alloc_state->alloc_stack)
69097 + return 0;
69098 + else
69099 + return 1;
69100 +}
69101 diff --git a/grsecurity/gracl_cap.c b/grsecurity/gracl_cap.c
69102 new file mode 100644
69103 index 0000000..bdd51ea
69104 --- /dev/null
69105 +++ b/grsecurity/gracl_cap.c
69106 @@ -0,0 +1,110 @@
69107 +#include <linux/kernel.h>
69108 +#include <linux/module.h>
69109 +#include <linux/sched.h>
69110 +#include <linux/gracl.h>
69111 +#include <linux/grsecurity.h>
69112 +#include <linux/grinternal.h>
69113 +
69114 +extern const char *captab_log[];
69115 +extern int captab_log_entries;
69116 +
69117 +int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
69118 +{
69119 + struct acl_subject_label *curracl;
69120 + kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
69121 + kernel_cap_t cap_audit = __cap_empty_set;
69122 +
69123 + if (!gr_acl_is_enabled())
69124 + return 1;
69125 +
69126 + curracl = task->acl;
69127 +
69128 + cap_drop = curracl->cap_lower;
69129 + cap_mask = curracl->cap_mask;
69130 + cap_audit = curracl->cap_invert_audit;
69131 +
69132 + while ((curracl = curracl->parent_subject)) {
69133 + /* if the cap isn't specified in the current computed mask but is specified in the
69134 + current level subject, and is lowered in the current level subject, then add
69135 + it to the set of dropped capabilities
69136 + otherwise, add the current level subject's mask to the current computed mask
69137 + */
69138 + if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
69139 + cap_raise(cap_mask, cap);
69140 + if (cap_raised(curracl->cap_lower, cap))
69141 + cap_raise(cap_drop, cap);
69142 + if (cap_raised(curracl->cap_invert_audit, cap))
69143 + cap_raise(cap_audit, cap);
69144 + }
69145 + }
69146 +
69147 + if (!cap_raised(cap_drop, cap)) {
69148 + if (cap_raised(cap_audit, cap))
69149 + gr_log_cap(GR_DO_AUDIT, GR_CAP_ACL_MSG2, task, captab_log[cap]);
69150 + return 1;
69151 + }
69152 +
69153 + curracl = task->acl;
69154 +
69155 + if ((curracl->mode & (GR_LEARN | GR_INHERITLEARN))
69156 + && cap_raised(cred->cap_effective, cap)) {
69157 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
69158 + task->role->roletype, GR_GLOBAL_UID(cred->uid),
69159 + GR_GLOBAL_GID(cred->gid), task->exec_file ?
69160 + gr_to_filename(task->exec_file->f_path.dentry,
69161 + task->exec_file->f_path.mnt) : curracl->filename,
69162 + curracl->filename, 0UL,
69163 + 0UL, "", (unsigned long) cap, &task->signal->saved_ip);
69164 + return 1;
69165 + }
69166 +
69167 + if ((cap >= 0) && (cap < captab_log_entries) && cap_raised(cred->cap_effective, cap) && !cap_raised(cap_audit, cap))
69168 + gr_log_cap(GR_DONT_AUDIT, GR_CAP_ACL_MSG, task, captab_log[cap]);
69169 +
69170 + return 0;
69171 +}
69172 +
69173 +int
69174 +gr_acl_is_capable(const int cap)
69175 +{
69176 + return gr_task_acl_is_capable(current, current_cred(), cap);
69177 +}
69178 +
69179 +int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap)
69180 +{
69181 + struct acl_subject_label *curracl;
69182 + kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
69183 +
69184 + if (!gr_acl_is_enabled())
69185 + return 1;
69186 +
69187 + curracl = task->acl;
69188 +
69189 + cap_drop = curracl->cap_lower;
69190 + cap_mask = curracl->cap_mask;
69191 +
69192 + while ((curracl = curracl->parent_subject)) {
69193 + /* if the cap isn't specified in the current computed mask but is specified in the
69194 + current level subject, and is lowered in the current level subject, then add
69195 + it to the set of dropped capabilities
69196 + otherwise, add the current level subject's mask to the current computed mask
69197 + */
69198 + if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
69199 + cap_raise(cap_mask, cap);
69200 + if (cap_raised(curracl->cap_lower, cap))
69201 + cap_raise(cap_drop, cap);
69202 + }
69203 + }
69204 +
69205 + if (!cap_raised(cap_drop, cap))
69206 + return 1;
69207 +
69208 + return 0;
69209 +}
69210 +
69211 +int
69212 +gr_acl_is_capable_nolog(const int cap)
69213 +{
69214 + return gr_task_acl_is_capable_nolog(current, cap);
69215 +}
69216 +
69217 diff --git a/grsecurity/gracl_compat.c b/grsecurity/gracl_compat.c
69218 new file mode 100644
69219 index 0000000..ca25605
69220 --- /dev/null
69221 +++ b/grsecurity/gracl_compat.c
69222 @@ -0,0 +1,270 @@
69223 +#include <linux/kernel.h>
69224 +#include <linux/gracl.h>
69225 +#include <linux/compat.h>
69226 +#include <linux/gracl_compat.h>
69227 +
69228 +#include <asm/uaccess.h>
69229 +
69230 +int copy_gr_arg_wrapper_compat(const char *buf, struct gr_arg_wrapper *uwrap)
69231 +{
69232 + struct gr_arg_wrapper_compat uwrapcompat;
69233 +
69234 + if (copy_from_user(&uwrapcompat, buf, sizeof(uwrapcompat)))
69235 + return -EFAULT;
69236 +
69237 + if (((uwrapcompat.version != GRSECURITY_VERSION) &&
69238 + (uwrapcompat.version != 0x2901)) ||
69239 + (uwrapcompat.size != sizeof(struct gr_arg_compat)))
69240 + return -EINVAL;
69241 +
69242 + uwrap->arg = compat_ptr(uwrapcompat.arg);
69243 + uwrap->version = uwrapcompat.version;
69244 + uwrap->size = sizeof(struct gr_arg);
69245 +
69246 + return 0;
69247 +}
69248 +
69249 +int copy_gr_arg_compat(const struct gr_arg __user *buf, struct gr_arg *arg)
69250 +{
69251 + struct gr_arg_compat argcompat;
69252 +
69253 + if (copy_from_user(&argcompat, buf, sizeof(argcompat)))
69254 + return -EFAULT;
69255 +
69256 + arg->role_db.r_table = compat_ptr(argcompat.role_db.r_table);
69257 + arg->role_db.num_pointers = argcompat.role_db.num_pointers;
69258 + arg->role_db.num_roles = argcompat.role_db.num_roles;
69259 + arg->role_db.num_domain_children = argcompat.role_db.num_domain_children;
69260 + arg->role_db.num_subjects = argcompat.role_db.num_subjects;
69261 + arg->role_db.num_objects = argcompat.role_db.num_objects;
69262 +
69263 + memcpy(&arg->pw, &argcompat.pw, sizeof(arg->pw));
69264 + memcpy(&arg->salt, &argcompat.salt, sizeof(arg->salt));
69265 + memcpy(&arg->sum, &argcompat.sum, sizeof(arg->sum));
69266 + memcpy(&arg->sp_role, &argcompat.sp_role, sizeof(arg->sp_role));
69267 + arg->sprole_pws = compat_ptr(argcompat.sprole_pws);
69268 + arg->segv_device = argcompat.segv_device;
69269 + arg->segv_inode = argcompat.segv_inode;
69270 + arg->segv_uid = argcompat.segv_uid;
69271 + arg->num_sprole_pws = argcompat.num_sprole_pws;
69272 + arg->mode = argcompat.mode;
69273 +
69274 + return 0;
69275 +}
69276 +
69277 +int copy_acl_object_label_compat(struct acl_object_label *obj, const struct acl_object_label *userp)
69278 +{
69279 + struct acl_object_label_compat objcompat;
69280 +
69281 + if (copy_from_user(&objcompat, userp, sizeof(objcompat)))
69282 + return -EFAULT;
69283 +
69284 + obj->filename = compat_ptr(objcompat.filename);
69285 + obj->inode = objcompat.inode;
69286 + obj->device = objcompat.device;
69287 + obj->mode = objcompat.mode;
69288 +
69289 + obj->nested = compat_ptr(objcompat.nested);
69290 + obj->globbed = compat_ptr(objcompat.globbed);
69291 +
69292 + obj->prev = compat_ptr(objcompat.prev);
69293 + obj->next = compat_ptr(objcompat.next);
69294 +
69295 + return 0;
69296 +}
69297 +
69298 +int copy_acl_subject_label_compat(struct acl_subject_label *subj, const struct acl_subject_label *userp)
69299 +{
69300 + unsigned int i;
69301 + struct acl_subject_label_compat subjcompat;
69302 +
69303 + if (copy_from_user(&subjcompat, userp, sizeof(subjcompat)))
69304 + return -EFAULT;
69305 +
69306 + subj->filename = compat_ptr(subjcompat.filename);
69307 + subj->inode = subjcompat.inode;
69308 + subj->device = subjcompat.device;
69309 + subj->mode = subjcompat.mode;
69310 + subj->cap_mask = subjcompat.cap_mask;
69311 + subj->cap_lower = subjcompat.cap_lower;
69312 + subj->cap_invert_audit = subjcompat.cap_invert_audit;
69313 +
69314 + for (i = 0; i < GR_NLIMITS; i++) {
69315 + if (subjcompat.res[i].rlim_cur == COMPAT_RLIM_INFINITY)
69316 + subj->res[i].rlim_cur = RLIM_INFINITY;
69317 + else
69318 + subj->res[i].rlim_cur = subjcompat.res[i].rlim_cur;
69319 + if (subjcompat.res[i].rlim_max == COMPAT_RLIM_INFINITY)
69320 + subj->res[i].rlim_max = RLIM_INFINITY;
69321 + else
69322 + subj->res[i].rlim_max = subjcompat.res[i].rlim_max;
69323 + }
69324 + subj->resmask = subjcompat.resmask;
69325 +
69326 + subj->user_trans_type = subjcompat.user_trans_type;
69327 + subj->group_trans_type = subjcompat.group_trans_type;
69328 + subj->user_transitions = compat_ptr(subjcompat.user_transitions);
69329 + subj->group_transitions = compat_ptr(subjcompat.group_transitions);
69330 + subj->user_trans_num = subjcompat.user_trans_num;
69331 + subj->group_trans_num = subjcompat.group_trans_num;
69332 +
69333 + memcpy(&subj->sock_families, &subjcompat.sock_families, sizeof(subj->sock_families));
69334 + memcpy(&subj->ip_proto, &subjcompat.ip_proto, sizeof(subj->ip_proto));
69335 + subj->ip_type = subjcompat.ip_type;
69336 + subj->ips = compat_ptr(subjcompat.ips);
69337 + subj->ip_num = subjcompat.ip_num;
69338 + subj->inaddr_any_override = subjcompat.inaddr_any_override;
69339 +
69340 + subj->crashes = subjcompat.crashes;
69341 + subj->expires = subjcompat.expires;
69342 +
69343 + subj->parent_subject = compat_ptr(subjcompat.parent_subject);
69344 + subj->hash = compat_ptr(subjcompat.hash);
69345 + subj->prev = compat_ptr(subjcompat.prev);
69346 + subj->next = compat_ptr(subjcompat.next);
69347 +
69348 + subj->obj_hash = compat_ptr(subjcompat.obj_hash);
69349 + subj->obj_hash_size = subjcompat.obj_hash_size;
69350 + subj->pax_flags = subjcompat.pax_flags;
69351 +
69352 + return 0;
69353 +}
69354 +
69355 +int copy_acl_role_label_compat(struct acl_role_label *role, const struct acl_role_label *userp)
69356 +{
69357 + struct acl_role_label_compat rolecompat;
69358 +
69359 + if (copy_from_user(&rolecompat, userp, sizeof(rolecompat)))
69360 + return -EFAULT;
69361 +
69362 + role->rolename = compat_ptr(rolecompat.rolename);
69363 + role->uidgid = rolecompat.uidgid;
69364 + role->roletype = rolecompat.roletype;
69365 +
69366 + role->auth_attempts = rolecompat.auth_attempts;
69367 + role->expires = rolecompat.expires;
69368 +
69369 + role->root_label = compat_ptr(rolecompat.root_label);
69370 + role->hash = compat_ptr(rolecompat.hash);
69371 +
69372 + role->prev = compat_ptr(rolecompat.prev);
69373 + role->next = compat_ptr(rolecompat.next);
69374 +
69375 + role->transitions = compat_ptr(rolecompat.transitions);
69376 + role->allowed_ips = compat_ptr(rolecompat.allowed_ips);
69377 + role->domain_children = compat_ptr(rolecompat.domain_children);
69378 + role->domain_child_num = rolecompat.domain_child_num;
69379 +
69380 + role->umask = rolecompat.umask;
69381 +
69382 + role->subj_hash = compat_ptr(rolecompat.subj_hash);
69383 + role->subj_hash_size = rolecompat.subj_hash_size;
69384 +
69385 + return 0;
69386 +}
69387 +
69388 +int copy_role_allowed_ip_compat(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp)
69389 +{
69390 + struct role_allowed_ip_compat roleip_compat;
69391 +
69392 + if (copy_from_user(&roleip_compat, userp, sizeof(roleip_compat)))
69393 + return -EFAULT;
69394 +
69395 + roleip->addr = roleip_compat.addr;
69396 + roleip->netmask = roleip_compat.netmask;
69397 +
69398 + roleip->prev = compat_ptr(roleip_compat.prev);
69399 + roleip->next = compat_ptr(roleip_compat.next);
69400 +
69401 + return 0;
69402 +}
69403 +
69404 +int copy_role_transition_compat(struct role_transition *trans, const struct role_transition *userp)
69405 +{
69406 + struct role_transition_compat trans_compat;
69407 +
69408 + if (copy_from_user(&trans_compat, userp, sizeof(trans_compat)))
69409 + return -EFAULT;
69410 +
69411 + trans->rolename = compat_ptr(trans_compat.rolename);
69412 +
69413 + trans->prev = compat_ptr(trans_compat.prev);
69414 + trans->next = compat_ptr(trans_compat.next);
69415 +
69416 + return 0;
69417 +
69418 +}
69419 +
69420 +int copy_gr_hash_struct_compat(struct gr_hash_struct *hash, const struct gr_hash_struct *userp)
69421 +{
69422 + struct gr_hash_struct_compat hash_compat;
69423 +
69424 + if (copy_from_user(&hash_compat, userp, sizeof(hash_compat)))
69425 + return -EFAULT;
69426 +
69427 + hash->table = compat_ptr(hash_compat.table);
69428 + hash->nametable = compat_ptr(hash_compat.nametable);
69429 + hash->first = compat_ptr(hash_compat.first);
69430 +
69431 + hash->table_size = hash_compat.table_size;
69432 + hash->used_size = hash_compat.used_size;
69433 +
69434 + hash->type = hash_compat.type;
69435 +
69436 + return 0;
69437 +}
69438 +
69439 +int copy_pointer_from_array_compat(void *ptr, unsigned long idx, const void *userp)
69440 +{
69441 + compat_uptr_t ptrcompat;
69442 +
69443 + if (copy_from_user(&ptrcompat, userp + (idx * sizeof(ptrcompat)), sizeof(ptrcompat)))
69444 + return -EFAULT;
69445 +
69446 + *(void **)ptr = compat_ptr(ptrcompat);
69447 +
69448 + return 0;
69449 +}
69450 +
69451 +int copy_acl_ip_label_compat(struct acl_ip_label *ip, const struct acl_ip_label *userp)
69452 +{
69453 + struct acl_ip_label_compat ip_compat;
69454 +
69455 + if (copy_from_user(&ip_compat, userp, sizeof(ip_compat)))
69456 + return -EFAULT;
69457 +
69458 + ip->iface = compat_ptr(ip_compat.iface);
69459 + ip->addr = ip_compat.addr;
69460 + ip->netmask = ip_compat.netmask;
69461 + ip->low = ip_compat.low;
69462 + ip->high = ip_compat.high;
69463 + ip->mode = ip_compat.mode;
69464 + ip->type = ip_compat.type;
69465 +
69466 + memcpy(&ip->proto, &ip_compat.proto, sizeof(ip->proto));
69467 +
69468 + ip->prev = compat_ptr(ip_compat.prev);
69469 + ip->next = compat_ptr(ip_compat.next);
69470 +
69471 + return 0;
69472 +}
69473 +
69474 +int copy_sprole_pw_compat(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp)
69475 +{
69476 + struct sprole_pw_compat pw_compat;
69477 +
69478 + if (copy_from_user(&pw_compat, (const void *)userp + (sizeof(pw_compat) * idx), sizeof(pw_compat)))
69479 + return -EFAULT;
69480 +
69481 + pw->rolename = compat_ptr(pw_compat.rolename);
69482 + memcpy(&pw->salt, pw_compat.salt, sizeof(pw->salt));
69483 + memcpy(&pw->sum, pw_compat.sum, sizeof(pw->sum));
69484 +
69485 + return 0;
69486 +}
69487 +
69488 +size_t get_gr_arg_wrapper_size_compat(void)
69489 +{
69490 + return sizeof(struct gr_arg_wrapper_compat);
69491 +}
69492 +
69493 diff --git a/grsecurity/gracl_fs.c b/grsecurity/gracl_fs.c
69494 new file mode 100644
69495 index 0000000..a89b1f4
69496 --- /dev/null
69497 +++ b/grsecurity/gracl_fs.c
69498 @@ -0,0 +1,437 @@
69499 +#include <linux/kernel.h>
69500 +#include <linux/sched.h>
69501 +#include <linux/types.h>
69502 +#include <linux/fs.h>
69503 +#include <linux/file.h>
69504 +#include <linux/stat.h>
69505 +#include <linux/grsecurity.h>
69506 +#include <linux/grinternal.h>
69507 +#include <linux/gracl.h>
69508 +
69509 +umode_t
69510 +gr_acl_umask(void)
69511 +{
69512 + if (unlikely(!gr_acl_is_enabled()))
69513 + return 0;
69514 +
69515 + return current->role->umask;
69516 +}
69517 +
69518 +__u32
69519 +gr_acl_handle_hidden_file(const struct dentry * dentry,
69520 + const struct vfsmount * mnt)
69521 +{
69522 + __u32 mode;
69523 +
69524 + if (unlikely(d_is_negative(dentry)))
69525 + return GR_FIND;
69526 +
69527 + mode =
69528 + gr_search_file(dentry, GR_FIND | GR_AUDIT_FIND | GR_SUPPRESS, mnt);
69529 +
69530 + if (unlikely(mode & GR_FIND && mode & GR_AUDIT_FIND)) {
69531 + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
69532 + return mode;
69533 + } else if (unlikely(!(mode & GR_FIND) && !(mode & GR_SUPPRESS))) {
69534 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
69535 + return 0;
69536 + } else if (unlikely(!(mode & GR_FIND)))
69537 + return 0;
69538 +
69539 + return GR_FIND;
69540 +}
69541 +
69542 +__u32
69543 +gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
69544 + int acc_mode)
69545 +{
69546 + __u32 reqmode = GR_FIND;
69547 + __u32 mode;
69548 +
69549 + if (unlikely(d_is_negative(dentry)))
69550 + return reqmode;
69551 +
69552 + if (acc_mode & MAY_APPEND)
69553 + reqmode |= GR_APPEND;
69554 + else if (acc_mode & MAY_WRITE)
69555 + reqmode |= GR_WRITE;
69556 + if ((acc_mode & MAY_READ) && !S_ISDIR(dentry->d_inode->i_mode))
69557 + reqmode |= GR_READ;
69558 +
69559 + mode =
69560 + gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
69561 + mnt);
69562 +
69563 + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
69564 + gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
69565 + reqmode & GR_READ ? " reading" : "",
69566 + reqmode & GR_WRITE ? " writing" : reqmode &
69567 + GR_APPEND ? " appending" : "");
69568 + return reqmode;
69569 + } else
69570 + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
69571 + {
69572 + gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
69573 + reqmode & GR_READ ? " reading" : "",
69574 + reqmode & GR_WRITE ? " writing" : reqmode &
69575 + GR_APPEND ? " appending" : "");
69576 + return 0;
69577 + } else if (unlikely((mode & reqmode) != reqmode))
69578 + return 0;
69579 +
69580 + return reqmode;
69581 +}
69582 +
69583 +__u32
69584 +gr_acl_handle_creat(const struct dentry * dentry,
69585 + const struct dentry * p_dentry,
69586 + const struct vfsmount * p_mnt, int open_flags, int acc_mode,
69587 + const int imode)
69588 +{
69589 + __u32 reqmode = GR_WRITE | GR_CREATE;
69590 + __u32 mode;
69591 +
69592 + if (acc_mode & MAY_APPEND)
69593 + reqmode |= GR_APPEND;
69594 + // if a directory was required or the directory already exists, then
69595 + // don't count this open as a read
69596 + if ((acc_mode & MAY_READ) &&
69597 + !((open_flags & O_DIRECTORY) || (dentry->d_inode && S_ISDIR(dentry->d_inode->i_mode))))
69598 + reqmode |= GR_READ;
69599 + if ((open_flags & O_CREAT) &&
69600 + ((imode & S_ISUID) || ((imode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
69601 + reqmode |= GR_SETID;
69602 +
69603 + mode =
69604 + gr_check_create(dentry, p_dentry, p_mnt,
69605 + reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
69606 +
69607 + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
69608 + gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
69609 + reqmode & GR_READ ? " reading" : "",
69610 + reqmode & GR_WRITE ? " writing" : reqmode &
69611 + GR_APPEND ? " appending" : "");
69612 + return reqmode;
69613 + } else
69614 + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
69615 + {
69616 + gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
69617 + reqmode & GR_READ ? " reading" : "",
69618 + reqmode & GR_WRITE ? " writing" : reqmode &
69619 + GR_APPEND ? " appending" : "");
69620 + return 0;
69621 + } else if (unlikely((mode & reqmode) != reqmode))
69622 + return 0;
69623 +
69624 + return reqmode;
69625 +}
69626 +
69627 +__u32
69628 +gr_acl_handle_access(const struct dentry * dentry, const struct vfsmount * mnt,
69629 + const int fmode)
69630 +{
69631 + __u32 mode, reqmode = GR_FIND;
69632 +
69633 + if ((fmode & S_IXOTH) && !S_ISDIR(dentry->d_inode->i_mode))
69634 + reqmode |= GR_EXEC;
69635 + if (fmode & S_IWOTH)
69636 + reqmode |= GR_WRITE;
69637 + if (fmode & S_IROTH)
69638 + reqmode |= GR_READ;
69639 +
69640 + mode =
69641 + gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
69642 + mnt);
69643 +
69644 + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
69645 + gr_log_fs_rbac_mode3(GR_DO_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
69646 + reqmode & GR_READ ? " reading" : "",
69647 + reqmode & GR_WRITE ? " writing" : "",
69648 + reqmode & GR_EXEC ? " executing" : "");
69649 + return reqmode;
69650 + } else
69651 + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
69652 + {
69653 + gr_log_fs_rbac_mode3(GR_DONT_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
69654 + reqmode & GR_READ ? " reading" : "",
69655 + reqmode & GR_WRITE ? " writing" : "",
69656 + reqmode & GR_EXEC ? " executing" : "");
69657 + return 0;
69658 + } else if (unlikely((mode & reqmode) != reqmode))
69659 + return 0;
69660 +
69661 + return reqmode;
69662 +}
69663 +
69664 +static __u32 generic_fs_handler(const struct dentry *dentry, const struct vfsmount *mnt, __u32 reqmode, const char *fmt)
69665 +{
69666 + __u32 mode;
69667 +
69668 + mode = gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS, mnt);
69669 +
69670 + if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
69671 + gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, dentry, mnt);
69672 + return mode;
69673 + } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
69674 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, dentry, mnt);
69675 + return 0;
69676 + } else if (unlikely((mode & (reqmode)) != (reqmode)))
69677 + return 0;
69678 +
69679 + return (reqmode);
69680 +}
69681 +
69682 +__u32
69683 +gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
69684 +{
69685 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_RMDIR_ACL_MSG);
69686 +}
69687 +
69688 +__u32
69689 +gr_acl_handle_unlink(const struct dentry *dentry, const struct vfsmount *mnt)
69690 +{
69691 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_UNLINK_ACL_MSG);
69692 +}
69693 +
69694 +__u32
69695 +gr_acl_handle_truncate(const struct dentry *dentry, const struct vfsmount *mnt)
69696 +{
69697 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_TRUNCATE_ACL_MSG);
69698 +}
69699 +
69700 +__u32
69701 +gr_acl_handle_utime(const struct dentry *dentry, const struct vfsmount *mnt)
69702 +{
69703 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_ATIME_ACL_MSG);
69704 +}
69705 +
69706 +__u32
69707 +gr_acl_handle_chmod(const struct dentry *dentry, const struct vfsmount *mnt,
69708 + umode_t *modeptr)
69709 +{
69710 + umode_t mode;
69711 +
69712 + *modeptr &= ~gr_acl_umask();
69713 + mode = *modeptr;
69714 +
69715 + if (unlikely(dentry->d_inode && S_ISSOCK(dentry->d_inode->i_mode)))
69716 + return 1;
69717 +
69718 + if (unlikely(dentry->d_inode && !S_ISDIR(dentry->d_inode->i_mode) &&
69719 + ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))) {
69720 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_SETID,
69721 + GR_CHMOD_ACL_MSG);
69722 + } else {
69723 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHMOD_ACL_MSG);
69724 + }
69725 +}
69726 +
69727 +__u32
69728 +gr_acl_handle_chown(const struct dentry *dentry, const struct vfsmount *mnt)
69729 +{
69730 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHOWN_ACL_MSG);
69731 +}
69732 +
69733 +__u32
69734 +gr_acl_handle_setxattr(const struct dentry *dentry, const struct vfsmount *mnt)
69735 +{
69736 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_SETXATTR_ACL_MSG);
69737 +}
69738 +
69739 +__u32
69740 +gr_acl_handle_removexattr(const struct dentry *dentry, const struct vfsmount *mnt)
69741 +{
69742 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_REMOVEXATTR_ACL_MSG);
69743 +}
69744 +
69745 +__u32
69746 +gr_acl_handle_execve(const struct dentry *dentry, const struct vfsmount *mnt)
69747 +{
69748 + return generic_fs_handler(dentry, mnt, GR_EXEC, GR_EXEC_ACL_MSG);
69749 +}
69750 +
69751 +__u32
69752 +gr_acl_handle_unix(const struct dentry *dentry, const struct vfsmount *mnt)
69753 +{
69754 + return generic_fs_handler(dentry, mnt, GR_READ | GR_WRITE,
69755 + GR_UNIXCONNECT_ACL_MSG);
69756 +}
69757 +
69758 +/* hardlinks require at minimum create and link permission,
69759 + any additional privilege required is based on the
69760 + privilege of the file being linked to
69761 +*/
69762 +__u32
69763 +gr_acl_handle_link(const struct dentry * new_dentry,
69764 + const struct dentry * parent_dentry,
69765 + const struct vfsmount * parent_mnt,
69766 + const struct dentry * old_dentry,
69767 + const struct vfsmount * old_mnt, const struct filename *to)
69768 +{
69769 + __u32 mode;
69770 + __u32 needmode = GR_CREATE | GR_LINK;
69771 + __u32 needaudit = GR_AUDIT_CREATE | GR_AUDIT_LINK;
69772 +
69773 + mode =
69774 + gr_check_link(new_dentry, parent_dentry, parent_mnt, old_dentry,
69775 + old_mnt);
69776 +
69777 + if (unlikely(((mode & needmode) == needmode) && (mode & needaudit))) {
69778 + gr_log_fs_rbac_str(GR_DO_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to->name);
69779 + return mode;
69780 + } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
69781 + gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to->name);
69782 + return 0;
69783 + } else if (unlikely((mode & needmode) != needmode))
69784 + return 0;
69785 +
69786 + return 1;
69787 +}
69788 +
69789 +__u32
69790 +gr_acl_handle_symlink(const struct dentry * new_dentry,
69791 + const struct dentry * parent_dentry,
69792 + const struct vfsmount * parent_mnt, const struct filename *from)
69793 +{
69794 + __u32 needmode = GR_WRITE | GR_CREATE;
69795 + __u32 mode;
69796 +
69797 + mode =
69798 + gr_check_create(new_dentry, parent_dentry, parent_mnt,
69799 + GR_CREATE | GR_AUDIT_CREATE |
69800 + GR_WRITE | GR_AUDIT_WRITE | GR_SUPPRESS);
69801 +
69802 + if (unlikely(mode & GR_WRITE && mode & GR_AUDITS)) {
69803 + gr_log_fs_str_rbac(GR_DO_AUDIT, GR_SYMLINK_ACL_MSG, from->name, new_dentry, parent_mnt);
69804 + return mode;
69805 + } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
69806 + gr_log_fs_str_rbac(GR_DONT_AUDIT, GR_SYMLINK_ACL_MSG, from->name, new_dentry, parent_mnt);
69807 + return 0;
69808 + } else if (unlikely((mode & needmode) != needmode))
69809 + return 0;
69810 +
69811 + return (GR_WRITE | GR_CREATE);
69812 +}
69813 +
69814 +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)
69815 +{
69816 + __u32 mode;
69817 +
69818 + mode = gr_check_create(new_dentry, parent_dentry, parent_mnt, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
69819 +
69820 + if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
69821 + gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, new_dentry, parent_mnt);
69822 + return mode;
69823 + } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
69824 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, new_dentry, parent_mnt);
69825 + return 0;
69826 + } else if (unlikely((mode & (reqmode)) != (reqmode)))
69827 + return 0;
69828 +
69829 + return (reqmode);
69830 +}
69831 +
69832 +__u32
69833 +gr_acl_handle_mknod(const struct dentry * new_dentry,
69834 + const struct dentry * parent_dentry,
69835 + const struct vfsmount * parent_mnt,
69836 + const int mode)
69837 +{
69838 + __u32 reqmode = GR_WRITE | GR_CREATE;
69839 + if (unlikely((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
69840 + reqmode |= GR_SETID;
69841 +
69842 + return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
69843 + reqmode, GR_MKNOD_ACL_MSG);
69844 +}
69845 +
69846 +__u32
69847 +gr_acl_handle_mkdir(const struct dentry *new_dentry,
69848 + const struct dentry *parent_dentry,
69849 + const struct vfsmount *parent_mnt)
69850 +{
69851 + return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
69852 + GR_WRITE | GR_CREATE, GR_MKDIR_ACL_MSG);
69853 +}
69854 +
69855 +#define RENAME_CHECK_SUCCESS(old, new) \
69856 + (((old & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)) && \
69857 + ((new & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)))
69858 +
69859 +int
69860 +gr_acl_handle_rename(struct dentry *new_dentry,
69861 + struct dentry *parent_dentry,
69862 + const struct vfsmount *parent_mnt,
69863 + struct dentry *old_dentry,
69864 + struct inode *old_parent_inode,
69865 + struct vfsmount *old_mnt, const struct filename *newname)
69866 +{
69867 + __u32 comp1, comp2;
69868 + int error = 0;
69869 +
69870 + if (unlikely(!gr_acl_is_enabled()))
69871 + return 0;
69872 +
69873 + if (d_is_negative(new_dentry)) {
69874 + comp1 = gr_check_create(new_dentry, parent_dentry, parent_mnt,
69875 + GR_READ | GR_WRITE | GR_CREATE | GR_AUDIT_READ |
69876 + GR_AUDIT_WRITE | GR_AUDIT_CREATE | GR_SUPPRESS);
69877 + comp2 = gr_search_file(old_dentry, GR_READ | GR_WRITE |
69878 + GR_DELETE | GR_AUDIT_DELETE |
69879 + GR_AUDIT_READ | GR_AUDIT_WRITE |
69880 + GR_SUPPRESS, old_mnt);
69881 + } else {
69882 + comp1 = gr_search_file(new_dentry, GR_READ | GR_WRITE |
69883 + GR_CREATE | GR_DELETE |
69884 + GR_AUDIT_CREATE | GR_AUDIT_DELETE |
69885 + GR_AUDIT_READ | GR_AUDIT_WRITE |
69886 + GR_SUPPRESS, parent_mnt);
69887 + comp2 =
69888 + gr_search_file(old_dentry,
69889 + GR_READ | GR_WRITE | GR_AUDIT_READ |
69890 + GR_DELETE | GR_AUDIT_DELETE |
69891 + GR_AUDIT_WRITE | GR_SUPPRESS, old_mnt);
69892 + }
69893 +
69894 + if (RENAME_CHECK_SUCCESS(comp1, comp2) &&
69895 + ((comp1 & GR_AUDITS) || (comp2 & GR_AUDITS)))
69896 + gr_log_fs_rbac_str(GR_DO_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname->name);
69897 + else if (!RENAME_CHECK_SUCCESS(comp1, comp2) && !(comp1 & GR_SUPPRESS)
69898 + && !(comp2 & GR_SUPPRESS)) {
69899 + gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname->name);
69900 + error = -EACCES;
69901 + } else if (unlikely(!RENAME_CHECK_SUCCESS(comp1, comp2)))
69902 + error = -EACCES;
69903 +
69904 + return error;
69905 +}
69906 +
69907 +void
69908 +gr_acl_handle_exit(void)
69909 +{
69910 + u16 id;
69911 + char *rolename;
69912 +
69913 + if (unlikely(current->acl_sp_role && gr_acl_is_enabled() &&
69914 + !(current->role->roletype & GR_ROLE_PERSIST))) {
69915 + id = current->acl_role_id;
69916 + rolename = current->role->rolename;
69917 + gr_set_acls(1);
69918 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLEL_ACL_MSG, rolename, id);
69919 + }
69920 +
69921 + gr_put_exec_file(current);
69922 + return;
69923 +}
69924 +
69925 +int
69926 +gr_acl_handle_procpidmem(const struct task_struct *task)
69927 +{
69928 + if (unlikely(!gr_acl_is_enabled()))
69929 + return 0;
69930 +
69931 + if (task != current && task->acl->mode & GR_PROTPROCFD)
69932 + return -EACCES;
69933 +
69934 + return 0;
69935 +}
69936 diff --git a/grsecurity/gracl_ip.c b/grsecurity/gracl_ip.c
69937 new file mode 100644
69938 index 0000000..f056b81
69939 --- /dev/null
69940 +++ b/grsecurity/gracl_ip.c
69941 @@ -0,0 +1,386 @@
69942 +#include <linux/kernel.h>
69943 +#include <asm/uaccess.h>
69944 +#include <asm/errno.h>
69945 +#include <net/sock.h>
69946 +#include <linux/file.h>
69947 +#include <linux/fs.h>
69948 +#include <linux/net.h>
69949 +#include <linux/in.h>
69950 +#include <linux/skbuff.h>
69951 +#include <linux/ip.h>
69952 +#include <linux/udp.h>
69953 +#include <linux/types.h>
69954 +#include <linux/sched.h>
69955 +#include <linux/netdevice.h>
69956 +#include <linux/inetdevice.h>
69957 +#include <linux/gracl.h>
69958 +#include <linux/grsecurity.h>
69959 +#include <linux/grinternal.h>
69960 +
69961 +#define GR_BIND 0x01
69962 +#define GR_CONNECT 0x02
69963 +#define GR_INVERT 0x04
69964 +#define GR_BINDOVERRIDE 0x08
69965 +#define GR_CONNECTOVERRIDE 0x10
69966 +#define GR_SOCK_FAMILY 0x20
69967 +
69968 +static const char * gr_protocols[IPPROTO_MAX] = {
69969 + "ip", "icmp", "igmp", "ggp", "ipencap", "st", "tcp", "cbt",
69970 + "egp", "igp", "bbn-rcc", "nvp", "pup", "argus", "emcon", "xnet",
69971 + "chaos", "udp", "mux", "dcn", "hmp", "prm", "xns-idp", "trunk-1",
69972 + "trunk-2", "leaf-1", "leaf-2", "rdp", "irtp", "iso-tp4", "netblt", "mfe-nsp",
69973 + "merit-inp", "sep", "3pc", "idpr", "xtp", "ddp", "idpr-cmtp", "tp++",
69974 + "il", "ipv6", "sdrp", "ipv6-route", "ipv6-frag", "idrp", "rsvp", "gre",
69975 + "mhrp", "bna", "ipv6-crypt", "ipv6-auth", "i-nlsp", "swipe", "narp", "mobile",
69976 + "tlsp", "skip", "ipv6-icmp", "ipv6-nonxt", "ipv6-opts", "unknown:61", "cftp", "unknown:63",
69977 + "sat-expak", "kryptolan", "rvd", "ippc", "unknown:68", "sat-mon", "visa", "ipcv",
69978 + "cpnx", "cphb", "wsn", "pvp", "br-sat-mon", "sun-nd", "wb-mon", "wb-expak",
69979 + "iso-ip", "vmtp", "secure-vmtp", "vines", "ttp", "nfsnet-igp", "dgp", "tcf",
69980 + "eigrp", "ospf", "sprite-rpc", "larp", "mtp", "ax.25", "ipip", "micp",
69981 + "scc-sp", "etherip", "encap", "unknown:99", "gmtp", "ifmp", "pnni", "pim",
69982 + "aris", "scps", "qnx", "a/n", "ipcomp", "snp", "compaq-peer", "ipx-in-ip",
69983 + "vrrp", "pgm", "unknown:114", "l2tp", "ddx", "iatp", "stp", "srp",
69984 + "uti", "smp", "sm", "ptp", "isis", "fire", "crtp", "crdup",
69985 + "sscopmce", "iplt", "sps", "pipe", "sctp", "fc", "unkown:134", "unknown:135",
69986 + "unknown:136", "unknown:137", "unknown:138", "unknown:139", "unknown:140", "unknown:141", "unknown:142", "unknown:143",
69987 + "unknown:144", "unknown:145", "unknown:146", "unknown:147", "unknown:148", "unknown:149", "unknown:150", "unknown:151",
69988 + "unknown:152", "unknown:153", "unknown:154", "unknown:155", "unknown:156", "unknown:157", "unknown:158", "unknown:159",
69989 + "unknown:160", "unknown:161", "unknown:162", "unknown:163", "unknown:164", "unknown:165", "unknown:166", "unknown:167",
69990 + "unknown:168", "unknown:169", "unknown:170", "unknown:171", "unknown:172", "unknown:173", "unknown:174", "unknown:175",
69991 + "unknown:176", "unknown:177", "unknown:178", "unknown:179", "unknown:180", "unknown:181", "unknown:182", "unknown:183",
69992 + "unknown:184", "unknown:185", "unknown:186", "unknown:187", "unknown:188", "unknown:189", "unknown:190", "unknown:191",
69993 + "unknown:192", "unknown:193", "unknown:194", "unknown:195", "unknown:196", "unknown:197", "unknown:198", "unknown:199",
69994 + "unknown:200", "unknown:201", "unknown:202", "unknown:203", "unknown:204", "unknown:205", "unknown:206", "unknown:207",
69995 + "unknown:208", "unknown:209", "unknown:210", "unknown:211", "unknown:212", "unknown:213", "unknown:214", "unknown:215",
69996 + "unknown:216", "unknown:217", "unknown:218", "unknown:219", "unknown:220", "unknown:221", "unknown:222", "unknown:223",
69997 + "unknown:224", "unknown:225", "unknown:226", "unknown:227", "unknown:228", "unknown:229", "unknown:230", "unknown:231",
69998 + "unknown:232", "unknown:233", "unknown:234", "unknown:235", "unknown:236", "unknown:237", "unknown:238", "unknown:239",
69999 + "unknown:240", "unknown:241", "unknown:242", "unknown:243", "unknown:244", "unknown:245", "unknown:246", "unknown:247",
70000 + "unknown:248", "unknown:249", "unknown:250", "unknown:251", "unknown:252", "unknown:253", "unknown:254", "unknown:255",
70001 + };
70002 +
70003 +static const char * gr_socktypes[SOCK_MAX] = {
70004 + "unknown:0", "stream", "dgram", "raw", "rdm", "seqpacket", "unknown:6",
70005 + "unknown:7", "unknown:8", "unknown:9", "packet"
70006 + };
70007 +
70008 +static const char * gr_sockfamilies[AF_MAX+1] = {
70009 + "unspec", "unix", "inet", "ax25", "ipx", "appletalk", "netrom", "bridge", "atmpvc", "x25",
70010 + "inet6", "rose", "decnet", "netbeui", "security", "key", "netlink", "packet", "ash",
70011 + "econet", "atmsvc", "rds", "sna", "irda", "ppox", "wanpipe", "llc", "fam_27", "fam_28",
70012 + "tipc", "bluetooth", "iucv", "rxrpc", "isdn", "phonet", "ieee802154", "ciaf"
70013 + };
70014 +
70015 +const char *
70016 +gr_proto_to_name(unsigned char proto)
70017 +{
70018 + return gr_protocols[proto];
70019 +}
70020 +
70021 +const char *
70022 +gr_socktype_to_name(unsigned char type)
70023 +{
70024 + return gr_socktypes[type];
70025 +}
70026 +
70027 +const char *
70028 +gr_sockfamily_to_name(unsigned char family)
70029 +{
70030 + return gr_sockfamilies[family];
70031 +}
70032 +
70033 +extern const struct net_proto_family __rcu *net_families[NPROTO] __read_mostly;
70034 +
70035 +int
70036 +gr_search_socket(const int domain, const int type, const int protocol)
70037 +{
70038 + struct acl_subject_label *curr;
70039 + const struct cred *cred = current_cred();
70040 +
70041 + if (unlikely(!gr_acl_is_enabled()))
70042 + goto exit;
70043 +
70044 + if ((domain < 0) || (type < 0) || (protocol < 0) ||
70045 + (domain >= AF_MAX) || (type >= SOCK_MAX) || (protocol >= IPPROTO_MAX))
70046 + goto exit; // let the kernel handle it
70047 +
70048 + curr = current->acl;
70049 +
70050 + if (curr->sock_families[domain / 32] & (1U << (domain % 32))) {
70051 + /* the family is allowed, if this is PF_INET allow it only if
70052 + the extra sock type/protocol checks pass */
70053 + if (domain == PF_INET)
70054 + goto inet_check;
70055 + goto exit;
70056 + } else {
70057 + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
70058 + __u32 fakeip = 0;
70059 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
70060 + current->role->roletype, GR_GLOBAL_UID(cred->uid),
70061 + GR_GLOBAL_GID(cred->gid), current->exec_file ?
70062 + gr_to_filename(current->exec_file->f_path.dentry,
70063 + current->exec_file->f_path.mnt) :
70064 + curr->filename, curr->filename,
70065 + &fakeip, domain, 0, 0, GR_SOCK_FAMILY,
70066 + &current->signal->saved_ip);
70067 + goto exit;
70068 + }
70069 + goto exit_fail;
70070 + }
70071 +
70072 +inet_check:
70073 + /* the rest of this checking is for IPv4 only */
70074 + if (!curr->ips)
70075 + goto exit;
70076 +
70077 + if ((curr->ip_type & (1U << type)) &&
70078 + (curr->ip_proto[protocol / 32] & (1U << (protocol % 32))))
70079 + goto exit;
70080 +
70081 + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
70082 + /* we don't place acls on raw sockets , and sometimes
70083 + dgram/ip sockets are opened for ioctl and not
70084 + bind/connect, so we'll fake a bind learn log */
70085 + if (type == SOCK_RAW || type == SOCK_PACKET) {
70086 + __u32 fakeip = 0;
70087 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
70088 + current->role->roletype, GR_GLOBAL_UID(cred->uid),
70089 + GR_GLOBAL_GID(cred->gid), current->exec_file ?
70090 + gr_to_filename(current->exec_file->f_path.dentry,
70091 + current->exec_file->f_path.mnt) :
70092 + curr->filename, curr->filename,
70093 + &fakeip, 0, type,
70094 + protocol, GR_CONNECT, &current->signal->saved_ip);
70095 + } else if ((type == SOCK_DGRAM) && (protocol == IPPROTO_IP)) {
70096 + __u32 fakeip = 0;
70097 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
70098 + current->role->roletype, GR_GLOBAL_UID(cred->uid),
70099 + GR_GLOBAL_GID(cred->gid), current->exec_file ?
70100 + gr_to_filename(current->exec_file->f_path.dentry,
70101 + current->exec_file->f_path.mnt) :
70102 + curr->filename, curr->filename,
70103 + &fakeip, 0, type,
70104 + protocol, GR_BIND, &current->signal->saved_ip);
70105 + }
70106 + /* we'll log when they use connect or bind */
70107 + goto exit;
70108 + }
70109 +
70110 +exit_fail:
70111 + if (domain == PF_INET)
70112 + gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(domain),
70113 + gr_socktype_to_name(type), gr_proto_to_name(protocol));
70114 + else if (rcu_access_pointer(net_families[domain]) != NULL)
70115 + gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(domain),
70116 + gr_socktype_to_name(type), protocol);
70117 +
70118 + return 0;
70119 +exit:
70120 + return 1;
70121 +}
70122 +
70123 +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)
70124 +{
70125 + if ((ip->mode & mode) &&
70126 + (ip_port >= ip->low) &&
70127 + (ip_port <= ip->high) &&
70128 + ((ntohl(ip_addr) & our_netmask) ==
70129 + (ntohl(our_addr) & our_netmask))
70130 + && (ip->proto[protocol / 32] & (1U << (protocol % 32)))
70131 + && (ip->type & (1U << type))) {
70132 + if (ip->mode & GR_INVERT)
70133 + return 2; // specifically denied
70134 + else
70135 + return 1; // allowed
70136 + }
70137 +
70138 + return 0; // not specifically allowed, may continue parsing
70139 +}
70140 +
70141 +static int
70142 +gr_search_connectbind(const int full_mode, struct sock *sk,
70143 + struct sockaddr_in *addr, const int type)
70144 +{
70145 + char iface[IFNAMSIZ] = {0};
70146 + struct acl_subject_label *curr;
70147 + struct acl_ip_label *ip;
70148 + struct inet_sock *isk;
70149 + struct net_device *dev;
70150 + struct in_device *idev;
70151 + unsigned long i;
70152 + int ret;
70153 + int mode = full_mode & (GR_BIND | GR_CONNECT);
70154 + __u32 ip_addr = 0;
70155 + __u32 our_addr;
70156 + __u32 our_netmask;
70157 + char *p;
70158 + __u16 ip_port = 0;
70159 + const struct cred *cred = current_cred();
70160 +
70161 + if (unlikely(!gr_acl_is_enabled() || sk->sk_family != PF_INET))
70162 + return 0;
70163 +
70164 + curr = current->acl;
70165 + isk = inet_sk(sk);
70166 +
70167 + /* INADDR_ANY overriding for binds, inaddr_any_override is already in network order */
70168 + if ((full_mode & GR_BINDOVERRIDE) && addr->sin_addr.s_addr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0)
70169 + addr->sin_addr.s_addr = curr->inaddr_any_override;
70170 + if ((full_mode & GR_CONNECT) && isk->inet_saddr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0) {
70171 + struct sockaddr_in saddr;
70172 + int err;
70173 +
70174 + saddr.sin_family = AF_INET;
70175 + saddr.sin_addr.s_addr = curr->inaddr_any_override;
70176 + saddr.sin_port = isk->inet_sport;
70177 +
70178 + err = security_socket_bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
70179 + if (err)
70180 + return err;
70181 +
70182 + err = sk->sk_socket->ops->bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
70183 + if (err)
70184 + return err;
70185 + }
70186 +
70187 + if (!curr->ips)
70188 + return 0;
70189 +
70190 + ip_addr = addr->sin_addr.s_addr;
70191 + ip_port = ntohs(addr->sin_port);
70192 +
70193 + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
70194 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
70195 + current->role->roletype, GR_GLOBAL_UID(cred->uid),
70196 + GR_GLOBAL_GID(cred->gid), current->exec_file ?
70197 + gr_to_filename(current->exec_file->f_path.dentry,
70198 + current->exec_file->f_path.mnt) :
70199 + curr->filename, curr->filename,
70200 + &ip_addr, ip_port, type,
70201 + sk->sk_protocol, mode, &current->signal->saved_ip);
70202 + return 0;
70203 + }
70204 +
70205 + for (i = 0; i < curr->ip_num; i++) {
70206 + ip = *(curr->ips + i);
70207 + if (ip->iface != NULL) {
70208 + strncpy(iface, ip->iface, IFNAMSIZ - 1);
70209 + p = strchr(iface, ':');
70210 + if (p != NULL)
70211 + *p = '\0';
70212 + dev = dev_get_by_name(sock_net(sk), iface);
70213 + if (dev == NULL)
70214 + continue;
70215 + idev = in_dev_get(dev);
70216 + if (idev == NULL) {
70217 + dev_put(dev);
70218 + continue;
70219 + }
70220 + rcu_read_lock();
70221 + for_ifa(idev) {
70222 + if (!strcmp(ip->iface, ifa->ifa_label)) {
70223 + our_addr = ifa->ifa_address;
70224 + our_netmask = 0xffffffff;
70225 + ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
70226 + if (ret == 1) {
70227 + rcu_read_unlock();
70228 + in_dev_put(idev);
70229 + dev_put(dev);
70230 + return 0;
70231 + } else if (ret == 2) {
70232 + rcu_read_unlock();
70233 + in_dev_put(idev);
70234 + dev_put(dev);
70235 + goto denied;
70236 + }
70237 + }
70238 + } endfor_ifa(idev);
70239 + rcu_read_unlock();
70240 + in_dev_put(idev);
70241 + dev_put(dev);
70242 + } else {
70243 + our_addr = ip->addr;
70244 + our_netmask = ip->netmask;
70245 + ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
70246 + if (ret == 1)
70247 + return 0;
70248 + else if (ret == 2)
70249 + goto denied;
70250 + }
70251 + }
70252 +
70253 +denied:
70254 + if (mode == GR_BIND)
70255 + 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));
70256 + else if (mode == GR_CONNECT)
70257 + 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));
70258 +
70259 + return -EACCES;
70260 +}
70261 +
70262 +int
70263 +gr_search_connect(struct socket *sock, struct sockaddr_in *addr)
70264 +{
70265 + /* always allow disconnection of dgram sockets with connect */
70266 + if (addr->sin_family == AF_UNSPEC)
70267 + return 0;
70268 + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sock->sk, addr, sock->type);
70269 +}
70270 +
70271 +int
70272 +gr_search_bind(struct socket *sock, struct sockaddr_in *addr)
70273 +{
70274 + return gr_search_connectbind(GR_BIND | GR_BINDOVERRIDE, sock->sk, addr, sock->type);
70275 +}
70276 +
70277 +int gr_search_listen(struct socket *sock)
70278 +{
70279 + struct sock *sk = sock->sk;
70280 + struct sockaddr_in addr;
70281 +
70282 + addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
70283 + addr.sin_port = inet_sk(sk)->inet_sport;
70284 +
70285 + return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
70286 +}
70287 +
70288 +int gr_search_accept(struct socket *sock)
70289 +{
70290 + struct sock *sk = sock->sk;
70291 + struct sockaddr_in addr;
70292 +
70293 + addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
70294 + addr.sin_port = inet_sk(sk)->inet_sport;
70295 +
70296 + return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
70297 +}
70298 +
70299 +int
70300 +gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr)
70301 +{
70302 + if (addr)
70303 + return gr_search_connectbind(GR_CONNECT, sk, addr, SOCK_DGRAM);
70304 + else {
70305 + struct sockaddr_in sin;
70306 + const struct inet_sock *inet = inet_sk(sk);
70307 +
70308 + sin.sin_addr.s_addr = inet->inet_daddr;
70309 + sin.sin_port = inet->inet_dport;
70310 +
70311 + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
70312 + }
70313 +}
70314 +
70315 +int
70316 +gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb)
70317 +{
70318 + struct sockaddr_in sin;
70319 +
70320 + if (unlikely(skb->len < sizeof (struct udphdr)))
70321 + return 0; // skip this packet
70322 +
70323 + sin.sin_addr.s_addr = ip_hdr(skb)->saddr;
70324 + sin.sin_port = udp_hdr(skb)->source;
70325 +
70326 + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
70327 +}
70328 diff --git a/grsecurity/gracl_learn.c b/grsecurity/gracl_learn.c
70329 new file mode 100644
70330 index 0000000..25f54ef
70331 --- /dev/null
70332 +++ b/grsecurity/gracl_learn.c
70333 @@ -0,0 +1,207 @@
70334 +#include <linux/kernel.h>
70335 +#include <linux/mm.h>
70336 +#include <linux/sched.h>
70337 +#include <linux/poll.h>
70338 +#include <linux/string.h>
70339 +#include <linux/file.h>
70340 +#include <linux/types.h>
70341 +#include <linux/vmalloc.h>
70342 +#include <linux/grinternal.h>
70343 +
70344 +extern ssize_t write_grsec_handler(struct file * file, const char __user * buf,
70345 + size_t count, loff_t *ppos);
70346 +extern int gr_acl_is_enabled(void);
70347 +
70348 +static DECLARE_WAIT_QUEUE_HEAD(learn_wait);
70349 +static int gr_learn_attached;
70350 +
70351 +/* use a 512k buffer */
70352 +#define LEARN_BUFFER_SIZE (512 * 1024)
70353 +
70354 +static DEFINE_SPINLOCK(gr_learn_lock);
70355 +static DEFINE_MUTEX(gr_learn_user_mutex);
70356 +
70357 +/* we need to maintain two buffers, so that the kernel context of grlearn
70358 + uses a semaphore around the userspace copying, and the other kernel contexts
70359 + use a spinlock when copying into the buffer, since they cannot sleep
70360 +*/
70361 +static char *learn_buffer;
70362 +static char *learn_buffer_user;
70363 +static int learn_buffer_len;
70364 +static int learn_buffer_user_len;
70365 +
70366 +static ssize_t
70367 +read_learn(struct file *file, char __user * buf, size_t count, loff_t * ppos)
70368 +{
70369 + DECLARE_WAITQUEUE(wait, current);
70370 + ssize_t retval = 0;
70371 +
70372 + add_wait_queue(&learn_wait, &wait);
70373 + set_current_state(TASK_INTERRUPTIBLE);
70374 + do {
70375 + mutex_lock(&gr_learn_user_mutex);
70376 + spin_lock(&gr_learn_lock);
70377 + if (learn_buffer_len)
70378 + break;
70379 + spin_unlock(&gr_learn_lock);
70380 + mutex_unlock(&gr_learn_user_mutex);
70381 + if (file->f_flags & O_NONBLOCK) {
70382 + retval = -EAGAIN;
70383 + goto out;
70384 + }
70385 + if (signal_pending(current)) {
70386 + retval = -ERESTARTSYS;
70387 + goto out;
70388 + }
70389 +
70390 + schedule();
70391 + } while (1);
70392 +
70393 + memcpy(learn_buffer_user, learn_buffer, learn_buffer_len);
70394 + learn_buffer_user_len = learn_buffer_len;
70395 + retval = learn_buffer_len;
70396 + learn_buffer_len = 0;
70397 +
70398 + spin_unlock(&gr_learn_lock);
70399 +
70400 + if (copy_to_user(buf, learn_buffer_user, learn_buffer_user_len))
70401 + retval = -EFAULT;
70402 +
70403 + mutex_unlock(&gr_learn_user_mutex);
70404 +out:
70405 + set_current_state(TASK_RUNNING);
70406 + remove_wait_queue(&learn_wait, &wait);
70407 + return retval;
70408 +}
70409 +
70410 +static unsigned int
70411 +poll_learn(struct file * file, poll_table * wait)
70412 +{
70413 + poll_wait(file, &learn_wait, wait);
70414 +
70415 + if (learn_buffer_len)
70416 + return (POLLIN | POLLRDNORM);
70417 +
70418 + return 0;
70419 +}
70420 +
70421 +void
70422 +gr_clear_learn_entries(void)
70423 +{
70424 + char *tmp;
70425 +
70426 + mutex_lock(&gr_learn_user_mutex);
70427 + spin_lock(&gr_learn_lock);
70428 + tmp = learn_buffer;
70429 + learn_buffer = NULL;
70430 + spin_unlock(&gr_learn_lock);
70431 + if (tmp)
70432 + vfree(tmp);
70433 + if (learn_buffer_user != NULL) {
70434 + vfree(learn_buffer_user);
70435 + learn_buffer_user = NULL;
70436 + }
70437 + learn_buffer_len = 0;
70438 + mutex_unlock(&gr_learn_user_mutex);
70439 +
70440 + return;
70441 +}
70442 +
70443 +void
70444 +gr_add_learn_entry(const char *fmt, ...)
70445 +{
70446 + va_list args;
70447 + unsigned int len;
70448 +
70449 + if (!gr_learn_attached)
70450 + return;
70451 +
70452 + spin_lock(&gr_learn_lock);
70453 +
70454 + /* leave a gap at the end so we know when it's "full" but don't have to
70455 + compute the exact length of the string we're trying to append
70456 + */
70457 + if (learn_buffer_len > LEARN_BUFFER_SIZE - 16384) {
70458 + spin_unlock(&gr_learn_lock);
70459 + wake_up_interruptible(&learn_wait);
70460 + return;
70461 + }
70462 + if (learn_buffer == NULL) {
70463 + spin_unlock(&gr_learn_lock);
70464 + return;
70465 + }
70466 +
70467 + va_start(args, fmt);
70468 + len = vsnprintf(learn_buffer + learn_buffer_len, LEARN_BUFFER_SIZE - learn_buffer_len, fmt, args);
70469 + va_end(args);
70470 +
70471 + learn_buffer_len += len + 1;
70472 +
70473 + spin_unlock(&gr_learn_lock);
70474 + wake_up_interruptible(&learn_wait);
70475 +
70476 + return;
70477 +}
70478 +
70479 +static int
70480 +open_learn(struct inode *inode, struct file *file)
70481 +{
70482 + if (file->f_mode & FMODE_READ && gr_learn_attached)
70483 + return -EBUSY;
70484 + if (file->f_mode & FMODE_READ) {
70485 + int retval = 0;
70486 + mutex_lock(&gr_learn_user_mutex);
70487 + if (learn_buffer == NULL)
70488 + learn_buffer = vmalloc(LEARN_BUFFER_SIZE);
70489 + if (learn_buffer_user == NULL)
70490 + learn_buffer_user = vmalloc(LEARN_BUFFER_SIZE);
70491 + if (learn_buffer == NULL) {
70492 + retval = -ENOMEM;
70493 + goto out_error;
70494 + }
70495 + if (learn_buffer_user == NULL) {
70496 + retval = -ENOMEM;
70497 + goto out_error;
70498 + }
70499 + learn_buffer_len = 0;
70500 + learn_buffer_user_len = 0;
70501 + gr_learn_attached = 1;
70502 +out_error:
70503 + mutex_unlock(&gr_learn_user_mutex);
70504 + return retval;
70505 + }
70506 + return 0;
70507 +}
70508 +
70509 +static int
70510 +close_learn(struct inode *inode, struct file *file)
70511 +{
70512 + if (file->f_mode & FMODE_READ) {
70513 + char *tmp = NULL;
70514 + mutex_lock(&gr_learn_user_mutex);
70515 + spin_lock(&gr_learn_lock);
70516 + tmp = learn_buffer;
70517 + learn_buffer = NULL;
70518 + spin_unlock(&gr_learn_lock);
70519 + if (tmp)
70520 + vfree(tmp);
70521 + if (learn_buffer_user != NULL) {
70522 + vfree(learn_buffer_user);
70523 + learn_buffer_user = NULL;
70524 + }
70525 + learn_buffer_len = 0;
70526 + learn_buffer_user_len = 0;
70527 + gr_learn_attached = 0;
70528 + mutex_unlock(&gr_learn_user_mutex);
70529 + }
70530 +
70531 + return 0;
70532 +}
70533 +
70534 +const struct file_operations grsec_fops = {
70535 + .read = read_learn,
70536 + .write = write_grsec_handler,
70537 + .open = open_learn,
70538 + .release = close_learn,
70539 + .poll = poll_learn,
70540 +};
70541 diff --git a/grsecurity/gracl_policy.c b/grsecurity/gracl_policy.c
70542 new file mode 100644
70543 index 0000000..361a099
70544 --- /dev/null
70545 +++ b/grsecurity/gracl_policy.c
70546 @@ -0,0 +1,1782 @@
70547 +#include <linux/kernel.h>
70548 +#include <linux/module.h>
70549 +#include <linux/sched.h>
70550 +#include <linux/mm.h>
70551 +#include <linux/file.h>
70552 +#include <linux/fs.h>
70553 +#include <linux/namei.h>
70554 +#include <linux/mount.h>
70555 +#include <linux/tty.h>
70556 +#include <linux/proc_fs.h>
70557 +#include <linux/lglock.h>
70558 +#include <linux/slab.h>
70559 +#include <linux/vmalloc.h>
70560 +#include <linux/types.h>
70561 +#include <linux/sysctl.h>
70562 +#include <linux/netdevice.h>
70563 +#include <linux/ptrace.h>
70564 +#include <linux/gracl.h>
70565 +#include <linux/gralloc.h>
70566 +#include <linux/security.h>
70567 +#include <linux/grinternal.h>
70568 +#include <linux/pid_namespace.h>
70569 +#include <linux/stop_machine.h>
70570 +#include <linux/fdtable.h>
70571 +#include <linux/percpu.h>
70572 +#include <linux/lglock.h>
70573 +#include <linux/hugetlb.h>
70574 +#include <linux/posix-timers.h>
70575 +#include "../fs/mount.h"
70576 +
70577 +#include <asm/uaccess.h>
70578 +#include <asm/errno.h>
70579 +#include <asm/mman.h>
70580 +
70581 +extern struct gr_policy_state *polstate;
70582 +
70583 +#define FOR_EACH_ROLE_START(role) \
70584 + role = polstate->role_list; \
70585 + while (role) {
70586 +
70587 +#define FOR_EACH_ROLE_END(role) \
70588 + role = role->prev; \
70589 + }
70590 +
70591 +struct path gr_real_root;
70592 +
70593 +extern struct gr_alloc_state *current_alloc_state;
70594 +
70595 +u16 acl_sp_role_value;
70596 +
70597 +static DEFINE_MUTEX(gr_dev_mutex);
70598 +
70599 +extern int chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum);
70600 +extern void gr_clear_learn_entries(void);
70601 +
70602 +static struct gr_arg gr_usermode;
70603 +static unsigned char gr_system_salt[GR_SALT_LEN];
70604 +static unsigned char gr_system_sum[GR_SHA_LEN];
70605 +
70606 +static unsigned int gr_auth_attempts = 0;
70607 +static unsigned long gr_auth_expires = 0UL;
70608 +
70609 +struct acl_object_label *fakefs_obj_rw;
70610 +struct acl_object_label *fakefs_obj_rwx;
70611 +
70612 +extern int gr_init_uidset(void);
70613 +extern void gr_free_uidset(void);
70614 +extern void gr_remove_uid(uid_t uid);
70615 +extern int gr_find_uid(uid_t uid);
70616 +
70617 +extern struct acl_subject_label *__gr_get_subject_for_task(const struct gr_policy_state *state, struct task_struct *task, const char *filename);
70618 +extern void __gr_apply_subject_to_task(struct gr_policy_state *state, struct task_struct *task, struct acl_subject_label *subj);
70619 +extern int gr_streq(const char *a, const char *b, const unsigned int lena, const unsigned int lenb);
70620 +extern void __insert_inodev_entry(const struct gr_policy_state *state, struct inodev_entry *entry);
70621 +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);
70622 +extern void insert_acl_obj_label(struct acl_object_label *obj, struct acl_subject_label *subj);
70623 +extern void insert_acl_subj_label(struct acl_subject_label *obj, struct acl_role_label *role);
70624 +extern struct name_entry * __lookup_name_entry(const struct gr_policy_state *state, const char *name);
70625 +extern char *gr_to_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt);
70626 +extern struct acl_subject_label *lookup_acl_subj_label(const ino_t ino, const dev_t dev, const struct acl_role_label *role);
70627 +extern struct acl_subject_label *lookup_acl_subj_label_deleted(const ino_t ino, const dev_t dev, const struct acl_role_label *role);
70628 +extern void assign_special_role(const char *rolename);
70629 +extern struct acl_subject_label *chk_subj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt, const struct acl_role_label *role);
70630 +extern int gr_rbac_disable(void *unused);
70631 +extern void gr_enable_rbac_system(void);
70632 +
70633 +static int copy_acl_object_label_normal(struct acl_object_label *obj, const struct acl_object_label *userp)
70634 +{
70635 + if (copy_from_user(obj, userp, sizeof(struct acl_object_label)))
70636 + return -EFAULT;
70637 +
70638 + return 0;
70639 +}
70640 +
70641 +static int copy_acl_ip_label_normal(struct acl_ip_label *ip, const struct acl_ip_label *userp)
70642 +{
70643 + if (copy_from_user(ip, userp, sizeof(struct acl_ip_label)))
70644 + return -EFAULT;
70645 +
70646 + return 0;
70647 +}
70648 +
70649 +static int copy_acl_subject_label_normal(struct acl_subject_label *subj, const struct acl_subject_label *userp)
70650 +{
70651 + if (copy_from_user(subj, userp, sizeof(struct acl_subject_label)))
70652 + return -EFAULT;
70653 +
70654 + return 0;
70655 +}
70656 +
70657 +static int copy_acl_role_label_normal(struct acl_role_label *role, const struct acl_role_label *userp)
70658 +{
70659 + if (copy_from_user(role, userp, sizeof(struct acl_role_label)))
70660 + return -EFAULT;
70661 +
70662 + return 0;
70663 +}
70664 +
70665 +static int copy_role_allowed_ip_normal(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp)
70666 +{
70667 + if (copy_from_user(roleip, userp, sizeof(struct role_allowed_ip)))
70668 + return -EFAULT;
70669 +
70670 + return 0;
70671 +}
70672 +
70673 +static int copy_sprole_pw_normal(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp)
70674 +{
70675 + if (copy_from_user(pw, userp + idx, sizeof(struct sprole_pw)))
70676 + return -EFAULT;
70677 +
70678 + return 0;
70679 +}
70680 +
70681 +static int copy_gr_hash_struct_normal(struct gr_hash_struct *hash, const struct gr_hash_struct *userp)
70682 +{
70683 + if (copy_from_user(hash, userp, sizeof(struct gr_hash_struct)))
70684 + return -EFAULT;
70685 +
70686 + return 0;
70687 +}
70688 +
70689 +static int copy_role_transition_normal(struct role_transition *trans, const struct role_transition *userp)
70690 +{
70691 + if (copy_from_user(trans, userp, sizeof(struct role_transition)))
70692 + return -EFAULT;
70693 +
70694 + return 0;
70695 +}
70696 +
70697 +int copy_pointer_from_array_normal(void *ptr, unsigned long idx, const void *userp)
70698 +{
70699 + if (copy_from_user(ptr, userp + (idx * sizeof(void *)), sizeof(void *)))
70700 + return -EFAULT;
70701 +
70702 + return 0;
70703 +}
70704 +
70705 +static int copy_gr_arg_wrapper_normal(const char __user *buf, struct gr_arg_wrapper *uwrap)
70706 +{
70707 + if (copy_from_user(uwrap, buf, sizeof (struct gr_arg_wrapper)))
70708 + return -EFAULT;
70709 +
70710 + if (((uwrap->version != GRSECURITY_VERSION) &&
70711 + (uwrap->version != 0x2901)) ||
70712 + (uwrap->size != sizeof(struct gr_arg)))
70713 + return -EINVAL;
70714 +
70715 + return 0;
70716 +}
70717 +
70718 +static int copy_gr_arg_normal(const struct gr_arg __user *buf, struct gr_arg *arg)
70719 +{
70720 + if (copy_from_user(arg, buf, sizeof (struct gr_arg)))
70721 + return -EFAULT;
70722 +
70723 + return 0;
70724 +}
70725 +
70726 +static size_t get_gr_arg_wrapper_size_normal(void)
70727 +{
70728 + return sizeof(struct gr_arg_wrapper);
70729 +}
70730 +
70731 +#ifdef CONFIG_COMPAT
70732 +extern int copy_gr_arg_wrapper_compat(const char *buf, struct gr_arg_wrapper *uwrap);
70733 +extern int copy_gr_arg_compat(const struct gr_arg __user *buf, struct gr_arg *arg);
70734 +extern int copy_acl_object_label_compat(struct acl_object_label *obj, const struct acl_object_label *userp);
70735 +extern int copy_acl_subject_label_compat(struct acl_subject_label *subj, const struct acl_subject_label *userp);
70736 +extern int copy_acl_role_label_compat(struct acl_role_label *role, const struct acl_role_label *userp);
70737 +extern int copy_role_allowed_ip_compat(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp);
70738 +extern int copy_role_transition_compat(struct role_transition *trans, const struct role_transition *userp);
70739 +extern int copy_gr_hash_struct_compat(struct gr_hash_struct *hash, const struct gr_hash_struct *userp);
70740 +extern int copy_pointer_from_array_compat(void *ptr, unsigned long idx, const void *userp);
70741 +extern int copy_acl_ip_label_compat(struct acl_ip_label *ip, const struct acl_ip_label *userp);
70742 +extern int copy_sprole_pw_compat(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp);
70743 +extern size_t get_gr_arg_wrapper_size_compat(void);
70744 +
70745 +int (* copy_gr_arg_wrapper)(const char *buf, struct gr_arg_wrapper *uwrap) __read_only;
70746 +int (* copy_gr_arg)(const struct gr_arg *buf, struct gr_arg *arg) __read_only;
70747 +int (* copy_acl_object_label)(struct acl_object_label *obj, const struct acl_object_label *userp) __read_only;
70748 +int (* copy_acl_subject_label)(struct acl_subject_label *subj, const struct acl_subject_label *userp) __read_only;
70749 +int (* copy_acl_role_label)(struct acl_role_label *role, const struct acl_role_label *userp) __read_only;
70750 +int (* copy_acl_ip_label)(struct acl_ip_label *ip, const struct acl_ip_label *userp) __read_only;
70751 +int (* copy_pointer_from_array)(void *ptr, unsigned long idx, const void *userp) __read_only;
70752 +int (* copy_sprole_pw)(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp) __read_only;
70753 +int (* copy_gr_hash_struct)(struct gr_hash_struct *hash, const struct gr_hash_struct *userp) __read_only;
70754 +int (* copy_role_transition)(struct role_transition *trans, const struct role_transition *userp) __read_only;
70755 +int (* copy_role_allowed_ip)(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp) __read_only;
70756 +size_t (* get_gr_arg_wrapper_size)(void) __read_only;
70757 +
70758 +#else
70759 +#define copy_gr_arg_wrapper copy_gr_arg_wrapper_normal
70760 +#define copy_gr_arg copy_gr_arg_normal
70761 +#define copy_gr_hash_struct copy_gr_hash_struct_normal
70762 +#define copy_acl_object_label copy_acl_object_label_normal
70763 +#define copy_acl_subject_label copy_acl_subject_label_normal
70764 +#define copy_acl_role_label copy_acl_role_label_normal
70765 +#define copy_acl_ip_label copy_acl_ip_label_normal
70766 +#define copy_pointer_from_array copy_pointer_from_array_normal
70767 +#define copy_sprole_pw copy_sprole_pw_normal
70768 +#define copy_role_transition copy_role_transition_normal
70769 +#define copy_role_allowed_ip copy_role_allowed_ip_normal
70770 +#define get_gr_arg_wrapper_size get_gr_arg_wrapper_size_normal
70771 +#endif
70772 +
70773 +static struct acl_subject_label *
70774 +lookup_subject_map(const struct acl_subject_label *userp)
70775 +{
70776 + unsigned int index = gr_shash(userp, polstate->subj_map_set.s_size);
70777 + struct subject_map *match;
70778 +
70779 + match = polstate->subj_map_set.s_hash[index];
70780 +
70781 + while (match && match->user != userp)
70782 + match = match->next;
70783 +
70784 + if (match != NULL)
70785 + return match->kernel;
70786 + else
70787 + return NULL;
70788 +}
70789 +
70790 +static void
70791 +insert_subj_map_entry(struct subject_map *subjmap)
70792 +{
70793 + unsigned int index = gr_shash(subjmap->user, polstate->subj_map_set.s_size);
70794 + struct subject_map **curr;
70795 +
70796 + subjmap->prev = NULL;
70797 +
70798 + curr = &polstate->subj_map_set.s_hash[index];
70799 + if (*curr != NULL)
70800 + (*curr)->prev = subjmap;
70801 +
70802 + subjmap->next = *curr;
70803 + *curr = subjmap;
70804 +
70805 + return;
70806 +}
70807 +
70808 +static void
70809 +__insert_acl_role_label(struct acl_role_label *role, uid_t uidgid)
70810 +{
70811 + unsigned int index =
70812 + gr_rhash(uidgid, role->roletype & (GR_ROLE_USER | GR_ROLE_GROUP), polstate->acl_role_set.r_size);
70813 + struct acl_role_label **curr;
70814 + struct acl_role_label *tmp, *tmp2;
70815 +
70816 + curr = &polstate->acl_role_set.r_hash[index];
70817 +
70818 + /* simple case, slot is empty, just set it to our role */
70819 + if (*curr == NULL) {
70820 + *curr = role;
70821 + } else {
70822 + /* example:
70823 + 1 -> 2 -> 3 (adding 2 -> 3 to here)
70824 + 2 -> 3
70825 + */
70826 + /* first check to see if we can already be reached via this slot */
70827 + tmp = *curr;
70828 + while (tmp && tmp != role)
70829 + tmp = tmp->next;
70830 + if (tmp == role) {
70831 + /* we don't need to add ourselves to this slot's chain */
70832 + return;
70833 + }
70834 + /* we need to add ourselves to this chain, two cases */
70835 + if (role->next == NULL) {
70836 + /* simple case, append the current chain to our role */
70837 + role->next = *curr;
70838 + *curr = role;
70839 + } else {
70840 + /* 1 -> 2 -> 3 -> 4
70841 + 2 -> 3 -> 4
70842 + 3 -> 4 (adding 1 -> 2 -> 3 -> 4 to here)
70843 + */
70844 + /* trickier case: walk our role's chain until we find
70845 + the role for the start of the current slot's chain */
70846 + tmp = role;
70847 + tmp2 = *curr;
70848 + while (tmp->next && tmp->next != tmp2)
70849 + tmp = tmp->next;
70850 + if (tmp->next == tmp2) {
70851 + /* from example above, we found 3, so just
70852 + replace this slot's chain with ours */
70853 + *curr = role;
70854 + } else {
70855 + /* we didn't find a subset of our role's chain
70856 + in the current slot's chain, so append their
70857 + chain to ours, and set us as the first role in
70858 + the slot's chain
70859 +
70860 + we could fold this case with the case above,
70861 + but making it explicit for clarity
70862 + */
70863 + tmp->next = tmp2;
70864 + *curr = role;
70865 + }
70866 + }
70867 + }
70868 +
70869 + return;
70870 +}
70871 +
70872 +static void
70873 +insert_acl_role_label(struct acl_role_label *role)
70874 +{
70875 + int i;
70876 +
70877 + if (polstate->role_list == NULL) {
70878 + polstate->role_list = role;
70879 + role->prev = NULL;
70880 + } else {
70881 + role->prev = polstate->role_list;
70882 + polstate->role_list = role;
70883 + }
70884 +
70885 + /* used for hash chains */
70886 + role->next = NULL;
70887 +
70888 + if (role->roletype & GR_ROLE_DOMAIN) {
70889 + for (i = 0; i < role->domain_child_num; i++)
70890 + __insert_acl_role_label(role, role->domain_children[i]);
70891 + } else
70892 + __insert_acl_role_label(role, role->uidgid);
70893 +}
70894 +
70895 +static int
70896 +insert_name_entry(char *name, const ino_t inode, const dev_t device, __u8 deleted)
70897 +{
70898 + struct name_entry **curr, *nentry;
70899 + struct inodev_entry *ientry;
70900 + unsigned int len = strlen(name);
70901 + unsigned int key = full_name_hash(name, len);
70902 + unsigned int index = key % polstate->name_set.n_size;
70903 +
70904 + curr = &polstate->name_set.n_hash[index];
70905 +
70906 + while (*curr && ((*curr)->key != key || !gr_streq((*curr)->name, name, (*curr)->len, len)))
70907 + curr = &((*curr)->next);
70908 +
70909 + if (*curr != NULL)
70910 + return 1;
70911 +
70912 + nentry = acl_alloc(sizeof (struct name_entry));
70913 + if (nentry == NULL)
70914 + return 0;
70915 + ientry = acl_alloc(sizeof (struct inodev_entry));
70916 + if (ientry == NULL)
70917 + return 0;
70918 + ientry->nentry = nentry;
70919 +
70920 + nentry->key = key;
70921 + nentry->name = name;
70922 + nentry->inode = inode;
70923 + nentry->device = device;
70924 + nentry->len = len;
70925 + nentry->deleted = deleted;
70926 +
70927 + nentry->prev = NULL;
70928 + curr = &polstate->name_set.n_hash[index];
70929 + if (*curr != NULL)
70930 + (*curr)->prev = nentry;
70931 + nentry->next = *curr;
70932 + *curr = nentry;
70933 +
70934 + /* insert us into the table searchable by inode/dev */
70935 + __insert_inodev_entry(polstate, ientry);
70936 +
70937 + return 1;
70938 +}
70939 +
70940 +/* allocating chained hash tables, so optimal size is where lambda ~ 1 */
70941 +
70942 +static void *
70943 +create_table(__u32 * len, int elementsize)
70944 +{
70945 + unsigned int table_sizes[] = {
70946 + 7, 13, 31, 61, 127, 251, 509, 1021, 2039, 4093, 8191, 16381,
70947 + 32749, 65521, 131071, 262139, 524287, 1048573, 2097143,
70948 + 4194301, 8388593, 16777213, 33554393, 67108859
70949 + };
70950 + void *newtable = NULL;
70951 + unsigned int pwr = 0;
70952 +
70953 + while ((pwr < ((sizeof (table_sizes) / sizeof (table_sizes[0])) - 1)) &&
70954 + table_sizes[pwr] <= *len)
70955 + pwr++;
70956 +
70957 + if (table_sizes[pwr] <= *len || (table_sizes[pwr] > ULONG_MAX / elementsize))
70958 + return newtable;
70959 +
70960 + if ((table_sizes[pwr] * elementsize) <= PAGE_SIZE)
70961 + newtable =
70962 + kmalloc(table_sizes[pwr] * elementsize, GFP_KERNEL);
70963 + else
70964 + newtable = vmalloc(table_sizes[pwr] * elementsize);
70965 +
70966 + *len = table_sizes[pwr];
70967 +
70968 + return newtable;
70969 +}
70970 +
70971 +static int
70972 +init_variables(const struct gr_arg *arg, bool reload)
70973 +{
70974 + struct task_struct *reaper = init_pid_ns.child_reaper;
70975 + unsigned int stacksize;
70976 +
70977 + polstate->subj_map_set.s_size = arg->role_db.num_subjects;
70978 + polstate->acl_role_set.r_size = arg->role_db.num_roles + arg->role_db.num_domain_children;
70979 + polstate->name_set.n_size = arg->role_db.num_objects;
70980 + polstate->inodev_set.i_size = arg->role_db.num_objects;
70981 +
70982 + if (!polstate->subj_map_set.s_size || !polstate->acl_role_set.r_size ||
70983 + !polstate->name_set.n_size || !polstate->inodev_set.i_size)
70984 + return 1;
70985 +
70986 + if (!reload) {
70987 + if (!gr_init_uidset())
70988 + return 1;
70989 + }
70990 +
70991 + /* set up the stack that holds allocation info */
70992 +
70993 + stacksize = arg->role_db.num_pointers + 5;
70994 +
70995 + if (!acl_alloc_stack_init(stacksize))
70996 + return 1;
70997 +
70998 + if (!reload) {
70999 + /* grab reference for the real root dentry and vfsmount */
71000 + get_fs_root(reaper->fs, &gr_real_root);
71001 +
71002 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
71003 + 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);
71004 +#endif
71005 +
71006 + fakefs_obj_rw = kzalloc(sizeof(struct acl_object_label), GFP_KERNEL);
71007 + if (fakefs_obj_rw == NULL)
71008 + return 1;
71009 + fakefs_obj_rw->mode = GR_FIND | GR_READ | GR_WRITE;
71010 +
71011 + fakefs_obj_rwx = kzalloc(sizeof(struct acl_object_label), GFP_KERNEL);
71012 + if (fakefs_obj_rwx == NULL)
71013 + return 1;
71014 + fakefs_obj_rwx->mode = GR_FIND | GR_READ | GR_WRITE | GR_EXEC;
71015 + }
71016 +
71017 + polstate->subj_map_set.s_hash =
71018 + (struct subject_map **) create_table(&polstate->subj_map_set.s_size, sizeof(void *));
71019 + polstate->acl_role_set.r_hash =
71020 + (struct acl_role_label **) create_table(&polstate->acl_role_set.r_size, sizeof(void *));
71021 + polstate->name_set.n_hash = (struct name_entry **) create_table(&polstate->name_set.n_size, sizeof(void *));
71022 + polstate->inodev_set.i_hash =
71023 + (struct inodev_entry **) create_table(&polstate->inodev_set.i_size, sizeof(void *));
71024 +
71025 + if (!polstate->subj_map_set.s_hash || !polstate->acl_role_set.r_hash ||
71026 + !polstate->name_set.n_hash || !polstate->inodev_set.i_hash)
71027 + return 1;
71028 +
71029 + memset(polstate->subj_map_set.s_hash, 0,
71030 + sizeof(struct subject_map *) * polstate->subj_map_set.s_size);
71031 + memset(polstate->acl_role_set.r_hash, 0,
71032 + sizeof (struct acl_role_label *) * polstate->acl_role_set.r_size);
71033 + memset(polstate->name_set.n_hash, 0,
71034 + sizeof (struct name_entry *) * polstate->name_set.n_size);
71035 + memset(polstate->inodev_set.i_hash, 0,
71036 + sizeof (struct inodev_entry *) * polstate->inodev_set.i_size);
71037 +
71038 + return 0;
71039 +}
71040 +
71041 +/* free information not needed after startup
71042 + currently contains user->kernel pointer mappings for subjects
71043 +*/
71044 +
71045 +static void
71046 +free_init_variables(void)
71047 +{
71048 + __u32 i;
71049 +
71050 + if (polstate->subj_map_set.s_hash) {
71051 + for (i = 0; i < polstate->subj_map_set.s_size; i++) {
71052 + if (polstate->subj_map_set.s_hash[i]) {
71053 + kfree(polstate->subj_map_set.s_hash[i]);
71054 + polstate->subj_map_set.s_hash[i] = NULL;
71055 + }
71056 + }
71057 +
71058 + if ((polstate->subj_map_set.s_size * sizeof (struct subject_map *)) <=
71059 + PAGE_SIZE)
71060 + kfree(polstate->subj_map_set.s_hash);
71061 + else
71062 + vfree(polstate->subj_map_set.s_hash);
71063 + }
71064 +
71065 + return;
71066 +}
71067 +
71068 +static void
71069 +free_variables(bool reload)
71070 +{
71071 + struct acl_subject_label *s;
71072 + struct acl_role_label *r;
71073 + struct task_struct *task, *task2;
71074 + unsigned int x;
71075 +
71076 + if (!reload) {
71077 + gr_clear_learn_entries();
71078 +
71079 + read_lock(&tasklist_lock);
71080 + do_each_thread(task2, task) {
71081 + task->acl_sp_role = 0;
71082 + task->acl_role_id = 0;
71083 + task->inherited = 0;
71084 + task->acl = NULL;
71085 + task->role = NULL;
71086 + } while_each_thread(task2, task);
71087 + read_unlock(&tasklist_lock);
71088 +
71089 + kfree(fakefs_obj_rw);
71090 + fakefs_obj_rw = NULL;
71091 + kfree(fakefs_obj_rwx);
71092 + fakefs_obj_rwx = NULL;
71093 +
71094 + /* release the reference to the real root dentry and vfsmount */
71095 + path_put(&gr_real_root);
71096 + memset(&gr_real_root, 0, sizeof(gr_real_root));
71097 + }
71098 +
71099 + /* free all object hash tables */
71100 +
71101 + FOR_EACH_ROLE_START(r)
71102 + if (r->subj_hash == NULL)
71103 + goto next_role;
71104 + FOR_EACH_SUBJECT_START(r, s, x)
71105 + if (s->obj_hash == NULL)
71106 + break;
71107 + if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
71108 + kfree(s->obj_hash);
71109 + else
71110 + vfree(s->obj_hash);
71111 + FOR_EACH_SUBJECT_END(s, x)
71112 + FOR_EACH_NESTED_SUBJECT_START(r, s)
71113 + if (s->obj_hash == NULL)
71114 + break;
71115 + if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
71116 + kfree(s->obj_hash);
71117 + else
71118 + vfree(s->obj_hash);
71119 + FOR_EACH_NESTED_SUBJECT_END(s)
71120 + if ((r->subj_hash_size * sizeof (struct acl_subject_label *)) <= PAGE_SIZE)
71121 + kfree(r->subj_hash);
71122 + else
71123 + vfree(r->subj_hash);
71124 + r->subj_hash = NULL;
71125 +next_role:
71126 + FOR_EACH_ROLE_END(r)
71127 +
71128 + acl_free_all();
71129 +
71130 + if (polstate->acl_role_set.r_hash) {
71131 + if ((polstate->acl_role_set.r_size * sizeof (struct acl_role_label *)) <=
71132 + PAGE_SIZE)
71133 + kfree(polstate->acl_role_set.r_hash);
71134 + else
71135 + vfree(polstate->acl_role_set.r_hash);
71136 + }
71137 + if (polstate->name_set.n_hash) {
71138 + if ((polstate->name_set.n_size * sizeof (struct name_entry *)) <=
71139 + PAGE_SIZE)
71140 + kfree(polstate->name_set.n_hash);
71141 + else
71142 + vfree(polstate->name_set.n_hash);
71143 + }
71144 +
71145 + if (polstate->inodev_set.i_hash) {
71146 + if ((polstate->inodev_set.i_size * sizeof (struct inodev_entry *)) <=
71147 + PAGE_SIZE)
71148 + kfree(polstate->inodev_set.i_hash);
71149 + else
71150 + vfree(polstate->inodev_set.i_hash);
71151 + }
71152 +
71153 + if (!reload)
71154 + gr_free_uidset();
71155 +
71156 + memset(&polstate->name_set, 0, sizeof (struct name_db));
71157 + memset(&polstate->inodev_set, 0, sizeof (struct inodev_db));
71158 + memset(&polstate->acl_role_set, 0, sizeof (struct acl_role_db));
71159 + memset(&polstate->subj_map_set, 0, sizeof (struct acl_subj_map_db));
71160 +
71161 + polstate->default_role = NULL;
71162 + polstate->kernel_role = NULL;
71163 + polstate->role_list = NULL;
71164 +
71165 + return;
71166 +}
71167 +
71168 +static struct acl_subject_label *
71169 +do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role, int *already_copied);
71170 +
71171 +static int alloc_and_copy_string(char **name, unsigned int maxlen)
71172 +{
71173 + unsigned int len = strnlen_user(*name, maxlen);
71174 + char *tmp;
71175 +
71176 + if (!len || len >= maxlen)
71177 + return -EINVAL;
71178 +
71179 + if ((tmp = (char *) acl_alloc(len)) == NULL)
71180 + return -ENOMEM;
71181 +
71182 + if (copy_from_user(tmp, *name, len))
71183 + return -EFAULT;
71184 +
71185 + tmp[len-1] = '\0';
71186 + *name = tmp;
71187 +
71188 + return 0;
71189 +}
71190 +
71191 +static int
71192 +copy_user_glob(struct acl_object_label *obj)
71193 +{
71194 + struct acl_object_label *g_tmp, **guser;
71195 + int error;
71196 +
71197 + if (obj->globbed == NULL)
71198 + return 0;
71199 +
71200 + guser = &obj->globbed;
71201 + while (*guser) {
71202 + g_tmp = (struct acl_object_label *)
71203 + acl_alloc(sizeof (struct acl_object_label));
71204 + if (g_tmp == NULL)
71205 + return -ENOMEM;
71206 +
71207 + if (copy_acl_object_label(g_tmp, *guser))
71208 + return -EFAULT;
71209 +
71210 + error = alloc_and_copy_string(&g_tmp->filename, PATH_MAX);
71211 + if (error)
71212 + return error;
71213 +
71214 + *guser = g_tmp;
71215 + guser = &(g_tmp->next);
71216 + }
71217 +
71218 + return 0;
71219 +}
71220 +
71221 +static int
71222 +copy_user_objs(struct acl_object_label *userp, struct acl_subject_label *subj,
71223 + struct acl_role_label *role)
71224 +{
71225 + struct acl_object_label *o_tmp;
71226 + int ret;
71227 +
71228 + while (userp) {
71229 + if ((o_tmp = (struct acl_object_label *)
71230 + acl_alloc(sizeof (struct acl_object_label))) == NULL)
71231 + return -ENOMEM;
71232 +
71233 + if (copy_acl_object_label(o_tmp, userp))
71234 + return -EFAULT;
71235 +
71236 + userp = o_tmp->prev;
71237 +
71238 + ret = alloc_and_copy_string(&o_tmp->filename, PATH_MAX);
71239 + if (ret)
71240 + return ret;
71241 +
71242 + insert_acl_obj_label(o_tmp, subj);
71243 + if (!insert_name_entry(o_tmp->filename, o_tmp->inode,
71244 + o_tmp->device, (o_tmp->mode & GR_DELETED) ? 1 : 0))
71245 + return -ENOMEM;
71246 +
71247 + ret = copy_user_glob(o_tmp);
71248 + if (ret)
71249 + return ret;
71250 +
71251 + if (o_tmp->nested) {
71252 + int already_copied;
71253 +
71254 + o_tmp->nested = do_copy_user_subj(o_tmp->nested, role, &already_copied);
71255 + if (IS_ERR(o_tmp->nested))
71256 + return PTR_ERR(o_tmp->nested);
71257 +
71258 + /* insert into nested subject list if we haven't copied this one yet
71259 + to prevent duplicate entries */
71260 + if (!already_copied) {
71261 + o_tmp->nested->next = role->hash->first;
71262 + role->hash->first = o_tmp->nested;
71263 + }
71264 + }
71265 + }
71266 +
71267 + return 0;
71268 +}
71269 +
71270 +static __u32
71271 +count_user_subjs(struct acl_subject_label *userp)
71272 +{
71273 + struct acl_subject_label s_tmp;
71274 + __u32 num = 0;
71275 +
71276 + while (userp) {
71277 + if (copy_acl_subject_label(&s_tmp, userp))
71278 + break;
71279 +
71280 + userp = s_tmp.prev;
71281 + }
71282 +
71283 + return num;
71284 +}
71285 +
71286 +static int
71287 +copy_user_allowedips(struct acl_role_label *rolep)
71288 +{
71289 + struct role_allowed_ip *ruserip, *rtmp = NULL, *rlast;
71290 +
71291 + ruserip = rolep->allowed_ips;
71292 +
71293 + while (ruserip) {
71294 + rlast = rtmp;
71295 +
71296 + if ((rtmp = (struct role_allowed_ip *)
71297 + acl_alloc(sizeof (struct role_allowed_ip))) == NULL)
71298 + return -ENOMEM;
71299 +
71300 + if (copy_role_allowed_ip(rtmp, ruserip))
71301 + return -EFAULT;
71302 +
71303 + ruserip = rtmp->prev;
71304 +
71305 + if (!rlast) {
71306 + rtmp->prev = NULL;
71307 + rolep->allowed_ips = rtmp;
71308 + } else {
71309 + rlast->next = rtmp;
71310 + rtmp->prev = rlast;
71311 + }
71312 +
71313 + if (!ruserip)
71314 + rtmp->next = NULL;
71315 + }
71316 +
71317 + return 0;
71318 +}
71319 +
71320 +static int
71321 +copy_user_transitions(struct acl_role_label *rolep)
71322 +{
71323 + struct role_transition *rusertp, *rtmp = NULL, *rlast;
71324 + int error;
71325 +
71326 + rusertp = rolep->transitions;
71327 +
71328 + while (rusertp) {
71329 + rlast = rtmp;
71330 +
71331 + if ((rtmp = (struct role_transition *)
71332 + acl_alloc(sizeof (struct role_transition))) == NULL)
71333 + return -ENOMEM;
71334 +
71335 + if (copy_role_transition(rtmp, rusertp))
71336 + return -EFAULT;
71337 +
71338 + rusertp = rtmp->prev;
71339 +
71340 + error = alloc_and_copy_string(&rtmp->rolename, GR_SPROLE_LEN);
71341 + if (error)
71342 + return error;
71343 +
71344 + if (!rlast) {
71345 + rtmp->prev = NULL;
71346 + rolep->transitions = rtmp;
71347 + } else {
71348 + rlast->next = rtmp;
71349 + rtmp->prev = rlast;
71350 + }
71351 +
71352 + if (!rusertp)
71353 + rtmp->next = NULL;
71354 + }
71355 +
71356 + return 0;
71357 +}
71358 +
71359 +static __u32 count_user_objs(const struct acl_object_label __user *userp)
71360 +{
71361 + struct acl_object_label o_tmp;
71362 + __u32 num = 0;
71363 +
71364 + while (userp) {
71365 + if (copy_acl_object_label(&o_tmp, userp))
71366 + break;
71367 +
71368 + userp = o_tmp.prev;
71369 + num++;
71370 + }
71371 +
71372 + return num;
71373 +}
71374 +
71375 +static struct acl_subject_label *
71376 +do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role, int *already_copied)
71377 +{
71378 + struct acl_subject_label *s_tmp = NULL, *s_tmp2;
71379 + __u32 num_objs;
71380 + struct acl_ip_label **i_tmp, *i_utmp2;
71381 + struct gr_hash_struct ghash;
71382 + struct subject_map *subjmap;
71383 + unsigned int i_num;
71384 + int err;
71385 +
71386 + if (already_copied != NULL)
71387 + *already_copied = 0;
71388 +
71389 + s_tmp = lookup_subject_map(userp);
71390 +
71391 + /* we've already copied this subject into the kernel, just return
71392 + the reference to it, and don't copy it over again
71393 + */
71394 + if (s_tmp) {
71395 + if (already_copied != NULL)
71396 + *already_copied = 1;
71397 + return(s_tmp);
71398 + }
71399 +
71400 + if ((s_tmp = (struct acl_subject_label *)
71401 + acl_alloc(sizeof (struct acl_subject_label))) == NULL)
71402 + return ERR_PTR(-ENOMEM);
71403 +
71404 + subjmap = (struct subject_map *)kmalloc(sizeof (struct subject_map), GFP_KERNEL);
71405 + if (subjmap == NULL)
71406 + return ERR_PTR(-ENOMEM);
71407 +
71408 + subjmap->user = userp;
71409 + subjmap->kernel = s_tmp;
71410 + insert_subj_map_entry(subjmap);
71411 +
71412 + if (copy_acl_subject_label(s_tmp, userp))
71413 + return ERR_PTR(-EFAULT);
71414 +
71415 + err = alloc_and_copy_string(&s_tmp->filename, PATH_MAX);
71416 + if (err)
71417 + return ERR_PTR(err);
71418 +
71419 + if (!strcmp(s_tmp->filename, "/"))
71420 + role->root_label = s_tmp;
71421 +
71422 + if (copy_gr_hash_struct(&ghash, s_tmp->hash))
71423 + return ERR_PTR(-EFAULT);
71424 +
71425 + /* copy user and group transition tables */
71426 +
71427 + if (s_tmp->user_trans_num) {
71428 + uid_t *uidlist;
71429 +
71430 + uidlist = (uid_t *)acl_alloc_num(s_tmp->user_trans_num, sizeof(uid_t));
71431 + if (uidlist == NULL)
71432 + return ERR_PTR(-ENOMEM);
71433 + if (copy_from_user(uidlist, s_tmp->user_transitions, s_tmp->user_trans_num * sizeof(uid_t)))
71434 + return ERR_PTR(-EFAULT);
71435 +
71436 + s_tmp->user_transitions = uidlist;
71437 + }
71438 +
71439 + if (s_tmp->group_trans_num) {
71440 + gid_t *gidlist;
71441 +
71442 + gidlist = (gid_t *)acl_alloc_num(s_tmp->group_trans_num, sizeof(gid_t));
71443 + if (gidlist == NULL)
71444 + return ERR_PTR(-ENOMEM);
71445 + if (copy_from_user(gidlist, s_tmp->group_transitions, s_tmp->group_trans_num * sizeof(gid_t)))
71446 + return ERR_PTR(-EFAULT);
71447 +
71448 + s_tmp->group_transitions = gidlist;
71449 + }
71450 +
71451 + /* set up object hash table */
71452 + num_objs = count_user_objs(ghash.first);
71453 +
71454 + s_tmp->obj_hash_size = num_objs;
71455 + s_tmp->obj_hash =
71456 + (struct acl_object_label **)
71457 + create_table(&(s_tmp->obj_hash_size), sizeof(void *));
71458 +
71459 + if (!s_tmp->obj_hash)
71460 + return ERR_PTR(-ENOMEM);
71461 +
71462 + memset(s_tmp->obj_hash, 0,
71463 + s_tmp->obj_hash_size *
71464 + sizeof (struct acl_object_label *));
71465 +
71466 + /* add in objects */
71467 + err = copy_user_objs(ghash.first, s_tmp, role);
71468 +
71469 + if (err)
71470 + return ERR_PTR(err);
71471 +
71472 + /* set pointer for parent subject */
71473 + if (s_tmp->parent_subject) {
71474 + s_tmp2 = do_copy_user_subj(s_tmp->parent_subject, role, NULL);
71475 +
71476 + if (IS_ERR(s_tmp2))
71477 + return s_tmp2;
71478 +
71479 + s_tmp->parent_subject = s_tmp2;
71480 + }
71481 +
71482 + /* add in ip acls */
71483 +
71484 + if (!s_tmp->ip_num) {
71485 + s_tmp->ips = NULL;
71486 + goto insert;
71487 + }
71488 +
71489 + i_tmp =
71490 + (struct acl_ip_label **) acl_alloc_num(s_tmp->ip_num,
71491 + sizeof (struct acl_ip_label *));
71492 +
71493 + if (!i_tmp)
71494 + return ERR_PTR(-ENOMEM);
71495 +
71496 + for (i_num = 0; i_num < s_tmp->ip_num; i_num++) {
71497 + *(i_tmp + i_num) =
71498 + (struct acl_ip_label *)
71499 + acl_alloc(sizeof (struct acl_ip_label));
71500 + if (!*(i_tmp + i_num))
71501 + return ERR_PTR(-ENOMEM);
71502 +
71503 + if (copy_pointer_from_array(&i_utmp2, i_num, s_tmp->ips))
71504 + return ERR_PTR(-EFAULT);
71505 +
71506 + if (copy_acl_ip_label(*(i_tmp + i_num), i_utmp2))
71507 + return ERR_PTR(-EFAULT);
71508 +
71509 + if ((*(i_tmp + i_num))->iface == NULL)
71510 + continue;
71511 +
71512 + err = alloc_and_copy_string(&(*(i_tmp + i_num))->iface, IFNAMSIZ);
71513 + if (err)
71514 + return ERR_PTR(err);
71515 + }
71516 +
71517 + s_tmp->ips = i_tmp;
71518 +
71519 +insert:
71520 + if (!insert_name_entry(s_tmp->filename, s_tmp->inode,
71521 + s_tmp->device, (s_tmp->mode & GR_DELETED) ? 1 : 0))
71522 + return ERR_PTR(-ENOMEM);
71523 +
71524 + return s_tmp;
71525 +}
71526 +
71527 +static int
71528 +copy_user_subjs(struct acl_subject_label *userp, struct acl_role_label *role)
71529 +{
71530 + struct acl_subject_label s_pre;
71531 + struct acl_subject_label * ret;
71532 + int err;
71533 +
71534 + while (userp) {
71535 + if (copy_acl_subject_label(&s_pre, userp))
71536 + return -EFAULT;
71537 +
71538 + ret = do_copy_user_subj(userp, role, NULL);
71539 +
71540 + err = PTR_ERR(ret);
71541 + if (IS_ERR(ret))
71542 + return err;
71543 +
71544 + insert_acl_subj_label(ret, role);
71545 +
71546 + userp = s_pre.prev;
71547 + }
71548 +
71549 + return 0;
71550 +}
71551 +
71552 +static int
71553 +copy_user_acl(struct gr_arg *arg)
71554 +{
71555 + struct acl_role_label *r_tmp = NULL, **r_utmp, *r_utmp2;
71556 + struct acl_subject_label *subj_list;
71557 + struct sprole_pw *sptmp;
71558 + struct gr_hash_struct *ghash;
71559 + uid_t *domainlist;
71560 + unsigned int r_num;
71561 + int err = 0;
71562 + __u16 i;
71563 + __u32 num_subjs;
71564 +
71565 + /* we need a default and kernel role */
71566 + if (arg->role_db.num_roles < 2)
71567 + return -EINVAL;
71568 +
71569 + /* copy special role authentication info from userspace */
71570 +
71571 + polstate->num_sprole_pws = arg->num_sprole_pws;
71572 + polstate->acl_special_roles = (struct sprole_pw **) acl_alloc_num(polstate->num_sprole_pws, sizeof(struct sprole_pw *));
71573 +
71574 + if (!polstate->acl_special_roles && polstate->num_sprole_pws)
71575 + return -ENOMEM;
71576 +
71577 + for (i = 0; i < polstate->num_sprole_pws; i++) {
71578 + sptmp = (struct sprole_pw *) acl_alloc(sizeof(struct sprole_pw));
71579 + if (!sptmp)
71580 + return -ENOMEM;
71581 + if (copy_sprole_pw(sptmp, i, arg->sprole_pws))
71582 + return -EFAULT;
71583 +
71584 + err = alloc_and_copy_string((char **)&sptmp->rolename, GR_SPROLE_LEN);
71585 + if (err)
71586 + return err;
71587 +
71588 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
71589 + printk(KERN_ALERT "Copying special role %s\n", sptmp->rolename);
71590 +#endif
71591 +
71592 + polstate->acl_special_roles[i] = sptmp;
71593 + }
71594 +
71595 + r_utmp = (struct acl_role_label **) arg->role_db.r_table;
71596 +
71597 + for (r_num = 0; r_num < arg->role_db.num_roles; r_num++) {
71598 + r_tmp = acl_alloc(sizeof (struct acl_role_label));
71599 +
71600 + if (!r_tmp)
71601 + return -ENOMEM;
71602 +
71603 + if (copy_pointer_from_array(&r_utmp2, r_num, r_utmp))
71604 + return -EFAULT;
71605 +
71606 + if (copy_acl_role_label(r_tmp, r_utmp2))
71607 + return -EFAULT;
71608 +
71609 + err = alloc_and_copy_string(&r_tmp->rolename, GR_SPROLE_LEN);
71610 + if (err)
71611 + return err;
71612 +
71613 + if (!strcmp(r_tmp->rolename, "default")
71614 + && (r_tmp->roletype & GR_ROLE_DEFAULT)) {
71615 + polstate->default_role = r_tmp;
71616 + } else if (!strcmp(r_tmp->rolename, ":::kernel:::")) {
71617 + polstate->kernel_role = r_tmp;
71618 + }
71619 +
71620 + if ((ghash = (struct gr_hash_struct *) acl_alloc(sizeof(struct gr_hash_struct))) == NULL)
71621 + return -ENOMEM;
71622 +
71623 + if (copy_gr_hash_struct(ghash, r_tmp->hash))
71624 + return -EFAULT;
71625 +
71626 + r_tmp->hash = ghash;
71627 +
71628 + num_subjs = count_user_subjs(r_tmp->hash->first);
71629 +
71630 + r_tmp->subj_hash_size = num_subjs;
71631 + r_tmp->subj_hash =
71632 + (struct acl_subject_label **)
71633 + create_table(&(r_tmp->subj_hash_size), sizeof(void *));
71634 +
71635 + if (!r_tmp->subj_hash)
71636 + return -ENOMEM;
71637 +
71638 + err = copy_user_allowedips(r_tmp);
71639 + if (err)
71640 + return err;
71641 +
71642 + /* copy domain info */
71643 + if (r_tmp->domain_children != NULL) {
71644 + domainlist = acl_alloc_num(r_tmp->domain_child_num, sizeof(uid_t));
71645 + if (domainlist == NULL)
71646 + return -ENOMEM;
71647 +
71648 + if (copy_from_user(domainlist, r_tmp->domain_children, r_tmp->domain_child_num * sizeof(uid_t)))
71649 + return -EFAULT;
71650 +
71651 + r_tmp->domain_children = domainlist;
71652 + }
71653 +
71654 + err = copy_user_transitions(r_tmp);
71655 + if (err)
71656 + return err;
71657 +
71658 + memset(r_tmp->subj_hash, 0,
71659 + r_tmp->subj_hash_size *
71660 + sizeof (struct acl_subject_label *));
71661 +
71662 + /* acquire the list of subjects, then NULL out
71663 + the list prior to parsing the subjects for this role,
71664 + as during this parsing the list is replaced with a list
71665 + of *nested* subjects for the role
71666 + */
71667 + subj_list = r_tmp->hash->first;
71668 +
71669 + /* set nested subject list to null */
71670 + r_tmp->hash->first = NULL;
71671 +
71672 + err = copy_user_subjs(subj_list, r_tmp);
71673 +
71674 + if (err)
71675 + return err;
71676 +
71677 + insert_acl_role_label(r_tmp);
71678 + }
71679 +
71680 + if (polstate->default_role == NULL || polstate->kernel_role == NULL)
71681 + return -EINVAL;
71682 +
71683 + return err;
71684 +}
71685 +
71686 +static int gracl_reload_apply_policies(void *reload)
71687 +{
71688 + struct gr_reload_state *reload_state = (struct gr_reload_state *)reload;
71689 + struct task_struct *task, *task2;
71690 + struct acl_role_label *role, *rtmp;
71691 + struct acl_subject_label *subj;
71692 + const struct cred *cred;
71693 + int role_applied;
71694 + int ret = 0;
71695 +
71696 + memcpy(&reload_state->oldpolicy, reload_state->oldpolicy_ptr, sizeof(struct gr_policy_state));
71697 + memcpy(&reload_state->oldalloc, reload_state->oldalloc_ptr, sizeof(struct gr_alloc_state));
71698 +
71699 + /* first make sure we'll be able to apply the new policy cleanly */
71700 + do_each_thread(task2, task) {
71701 + if (task->exec_file == NULL)
71702 + continue;
71703 + role_applied = 0;
71704 + if (!reload_state->oldmode && task->role->roletype & GR_ROLE_SPECIAL) {
71705 + /* preserve special roles */
71706 + FOR_EACH_ROLE_START(role)
71707 + if ((role->roletype & GR_ROLE_SPECIAL) && !strcmp(task->role->rolename, role->rolename)) {
71708 + rtmp = task->role;
71709 + task->role = role;
71710 + role_applied = 1;
71711 + break;
71712 + }
71713 + FOR_EACH_ROLE_END(role)
71714 + }
71715 + if (!role_applied) {
71716 + cred = __task_cred(task);
71717 + rtmp = task->role;
71718 + task->role = __lookup_acl_role_label(polstate, task, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid));
71719 + }
71720 + /* this handles non-nested inherited subjects, nested subjects will still
71721 + be dropped currently */
71722 + subj = __gr_get_subject_for_task(polstate, task, task->acl->filename);
71723 + task->tmpacl = __gr_get_subject_for_task(polstate, task, NULL);
71724 + /* change the role back so that we've made no modifications to the policy */
71725 + task->role = rtmp;
71726 +
71727 + if (subj == NULL || task->tmpacl == NULL) {
71728 + ret = -EINVAL;
71729 + goto out;
71730 + }
71731 + } while_each_thread(task2, task);
71732 +
71733 + /* now actually apply the policy */
71734 +
71735 + do_each_thread(task2, task) {
71736 + if (task->exec_file) {
71737 + role_applied = 0;
71738 + if (!reload_state->oldmode && task->role->roletype & GR_ROLE_SPECIAL) {
71739 + /* preserve special roles */
71740 + FOR_EACH_ROLE_START(role)
71741 + if ((role->roletype & GR_ROLE_SPECIAL) && !strcmp(task->role->rolename, role->rolename)) {
71742 + task->role = role;
71743 + role_applied = 1;
71744 + break;
71745 + }
71746 + FOR_EACH_ROLE_END(role)
71747 + }
71748 + if (!role_applied) {
71749 + cred = __task_cred(task);
71750 + task->role = __lookup_acl_role_label(polstate, task, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid));
71751 + }
71752 + /* this handles non-nested inherited subjects, nested subjects will still
71753 + be dropped currently */
71754 + if (!reload_state->oldmode && task->inherited)
71755 + subj = __gr_get_subject_for_task(polstate, task, task->acl->filename);
71756 + else {
71757 + /* looked up and tagged to the task previously */
71758 + subj = task->tmpacl;
71759 + }
71760 + /* subj will be non-null */
71761 + __gr_apply_subject_to_task(polstate, task, subj);
71762 + if (reload_state->oldmode) {
71763 + task->acl_role_id = 0;
71764 + task->acl_sp_role = 0;
71765 + task->inherited = 0;
71766 + }
71767 + } else {
71768 + // it's a kernel process
71769 + task->role = polstate->kernel_role;
71770 + task->acl = polstate->kernel_role->root_label;
71771 +#ifdef CONFIG_GRKERNSEC_ACL_HIDEKERN
71772 + task->acl->mode &= ~GR_PROCFIND;
71773 +#endif
71774 + }
71775 + } while_each_thread(task2, task);
71776 +
71777 + memcpy(reload_state->oldpolicy_ptr, &reload_state->newpolicy, sizeof(struct gr_policy_state));
71778 + memcpy(reload_state->oldalloc_ptr, &reload_state->newalloc, sizeof(struct gr_alloc_state));
71779 +
71780 +out:
71781 +
71782 + return ret;
71783 +}
71784 +
71785 +static int gracl_reload(struct gr_arg *args, unsigned char oldmode)
71786 +{
71787 + struct gr_reload_state new_reload_state = { };
71788 + int err;
71789 +
71790 + new_reload_state.oldpolicy_ptr = polstate;
71791 + new_reload_state.oldalloc_ptr = current_alloc_state;
71792 + new_reload_state.oldmode = oldmode;
71793 +
71794 + current_alloc_state = &new_reload_state.newalloc;
71795 + polstate = &new_reload_state.newpolicy;
71796 +
71797 + /* everything relevant is now saved off, copy in the new policy */
71798 + if (init_variables(args, true)) {
71799 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_INITF_ACL_MSG, GR_VERSION);
71800 + err = -ENOMEM;
71801 + goto error;
71802 + }
71803 +
71804 + err = copy_user_acl(args);
71805 + free_init_variables();
71806 + if (err)
71807 + goto error;
71808 + /* the new policy is copied in, with the old policy available via saved_state
71809 + first go through applying roles, making sure to preserve special roles
71810 + then apply new subjects, making sure to preserve inherited and nested subjects,
71811 + though currently only inherited subjects will be preserved
71812 + */
71813 + err = stop_machine(gracl_reload_apply_policies, &new_reload_state, NULL);
71814 + if (err)
71815 + goto error;
71816 +
71817 + /* we've now applied the new policy, so restore the old policy state to free it */
71818 + polstate = &new_reload_state.oldpolicy;
71819 + current_alloc_state = &new_reload_state.oldalloc;
71820 + free_variables(true);
71821 +
71822 + /* oldpolicy/oldalloc_ptr point to the new policy/alloc states as they were copied
71823 + to running_polstate/current_alloc_state inside stop_machine
71824 + */
71825 + err = 0;
71826 + goto out;
71827 +error:
71828 + /* on error of loading the new policy, we'll just keep the previous
71829 + policy set around
71830 + */
71831 + free_variables(true);
71832 +
71833 + /* doesn't affect runtime, but maintains consistent state */
71834 +out:
71835 + polstate = new_reload_state.oldpolicy_ptr;
71836 + current_alloc_state = new_reload_state.oldalloc_ptr;
71837 +
71838 + return err;
71839 +}
71840 +
71841 +static int
71842 +gracl_init(struct gr_arg *args)
71843 +{
71844 + int error = 0;
71845 +
71846 + memcpy(&gr_system_salt, args->salt, sizeof(gr_system_salt));
71847 + memcpy(&gr_system_sum, args->sum, sizeof(gr_system_sum));
71848 +
71849 + if (init_variables(args, false)) {
71850 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_INITF_ACL_MSG, GR_VERSION);
71851 + error = -ENOMEM;
71852 + goto out;
71853 + }
71854 +
71855 + error = copy_user_acl(args);
71856 + free_init_variables();
71857 + if (error)
71858 + goto out;
71859 +
71860 + error = gr_set_acls(0);
71861 + if (error)
71862 + goto out;
71863 +
71864 + gr_enable_rbac_system();
71865 +
71866 + return 0;
71867 +
71868 +out:
71869 + free_variables(false);
71870 + return error;
71871 +}
71872 +
71873 +static int
71874 +lookup_special_role_auth(__u16 mode, const char *rolename, unsigned char **salt,
71875 + unsigned char **sum)
71876 +{
71877 + struct acl_role_label *r;
71878 + struct role_allowed_ip *ipp;
71879 + struct role_transition *trans;
71880 + unsigned int i;
71881 + int found = 0;
71882 + u32 curr_ip = current->signal->curr_ip;
71883 +
71884 + current->signal->saved_ip = curr_ip;
71885 +
71886 + /* check transition table */
71887 +
71888 + for (trans = current->role->transitions; trans; trans = trans->next) {
71889 + if (!strcmp(rolename, trans->rolename)) {
71890 + found = 1;
71891 + break;
71892 + }
71893 + }
71894 +
71895 + if (!found)
71896 + return 0;
71897 +
71898 + /* handle special roles that do not require authentication
71899 + and check ip */
71900 +
71901 + FOR_EACH_ROLE_START(r)
71902 + if (!strcmp(rolename, r->rolename) &&
71903 + (r->roletype & GR_ROLE_SPECIAL)) {
71904 + found = 0;
71905 + if (r->allowed_ips != NULL) {
71906 + for (ipp = r->allowed_ips; ipp; ipp = ipp->next) {
71907 + if ((ntohl(curr_ip) & ipp->netmask) ==
71908 + (ntohl(ipp->addr) & ipp->netmask))
71909 + found = 1;
71910 + }
71911 + } else
71912 + found = 2;
71913 + if (!found)
71914 + return 0;
71915 +
71916 + if (((mode == GR_SPROLE) && (r->roletype & GR_ROLE_NOPW)) ||
71917 + ((mode == GR_SPROLEPAM) && (r->roletype & GR_ROLE_PAM))) {
71918 + *salt = NULL;
71919 + *sum = NULL;
71920 + return 1;
71921 + }
71922 + }
71923 + FOR_EACH_ROLE_END(r)
71924 +
71925 + for (i = 0; i < polstate->num_sprole_pws; i++) {
71926 + if (!strcmp(rolename, polstate->acl_special_roles[i]->rolename)) {
71927 + *salt = polstate->acl_special_roles[i]->salt;
71928 + *sum = polstate->acl_special_roles[i]->sum;
71929 + return 1;
71930 + }
71931 + }
71932 +
71933 + return 0;
71934 +}
71935 +
71936 +int gr_check_secure_terminal(struct task_struct *task)
71937 +{
71938 + struct task_struct *p, *p2, *p3;
71939 + struct files_struct *files;
71940 + struct fdtable *fdt;
71941 + struct file *our_file = NULL, *file;
71942 + int i;
71943 +
71944 + if (task->signal->tty == NULL)
71945 + return 1;
71946 +
71947 + files = get_files_struct(task);
71948 + if (files != NULL) {
71949 + rcu_read_lock();
71950 + fdt = files_fdtable(files);
71951 + for (i=0; i < fdt->max_fds; i++) {
71952 + file = fcheck_files(files, i);
71953 + if (file && (our_file == NULL) && (file->private_data == task->signal->tty)) {
71954 + get_file(file);
71955 + our_file = file;
71956 + }
71957 + }
71958 + rcu_read_unlock();
71959 + put_files_struct(files);
71960 + }
71961 +
71962 + if (our_file == NULL)
71963 + return 1;
71964 +
71965 + read_lock(&tasklist_lock);
71966 + do_each_thread(p2, p) {
71967 + files = get_files_struct(p);
71968 + if (files == NULL ||
71969 + (p->signal && p->signal->tty == task->signal->tty)) {
71970 + if (files != NULL)
71971 + put_files_struct(files);
71972 + continue;
71973 + }
71974 + rcu_read_lock();
71975 + fdt = files_fdtable(files);
71976 + for (i=0; i < fdt->max_fds; i++) {
71977 + file = fcheck_files(files, i);
71978 + if (file && S_ISCHR(file->f_path.dentry->d_inode->i_mode) &&
71979 + file->f_path.dentry->d_inode->i_rdev == our_file->f_path.dentry->d_inode->i_rdev) {
71980 + p3 = task;
71981 + while (task_pid_nr(p3) > 0) {
71982 + if (p3 == p)
71983 + break;
71984 + p3 = p3->real_parent;
71985 + }
71986 + if (p3 == p)
71987 + break;
71988 + gr_log_ttysniff(GR_DONT_AUDIT_GOOD, GR_TTYSNIFF_ACL_MSG, p);
71989 + gr_handle_alertkill(p);
71990 + rcu_read_unlock();
71991 + put_files_struct(files);
71992 + read_unlock(&tasklist_lock);
71993 + fput(our_file);
71994 + return 0;
71995 + }
71996 + }
71997 + rcu_read_unlock();
71998 + put_files_struct(files);
71999 + } while_each_thread(p2, p);
72000 + read_unlock(&tasklist_lock);
72001 +
72002 + fput(our_file);
72003 + return 1;
72004 +}
72005 +
72006 +ssize_t
72007 +write_grsec_handler(struct file *file, const char __user * buf, size_t count, loff_t *ppos)
72008 +{
72009 + struct gr_arg_wrapper uwrap;
72010 + unsigned char *sprole_salt = NULL;
72011 + unsigned char *sprole_sum = NULL;
72012 + int error = 0;
72013 + int error2 = 0;
72014 + size_t req_count = 0;
72015 + unsigned char oldmode = 0;
72016 +
72017 + mutex_lock(&gr_dev_mutex);
72018 +
72019 + if (gr_acl_is_enabled() && !(current->acl->mode & GR_KERNELAUTH)) {
72020 + error = -EPERM;
72021 + goto out;
72022 + }
72023 +
72024 +#ifdef CONFIG_COMPAT
72025 + pax_open_kernel();
72026 + if (is_compat_task()) {
72027 + copy_gr_arg_wrapper = &copy_gr_arg_wrapper_compat;
72028 + copy_gr_arg = &copy_gr_arg_compat;
72029 + copy_acl_object_label = &copy_acl_object_label_compat;
72030 + copy_acl_subject_label = &copy_acl_subject_label_compat;
72031 + copy_acl_role_label = &copy_acl_role_label_compat;
72032 + copy_acl_ip_label = &copy_acl_ip_label_compat;
72033 + copy_role_allowed_ip = &copy_role_allowed_ip_compat;
72034 + copy_role_transition = &copy_role_transition_compat;
72035 + copy_sprole_pw = &copy_sprole_pw_compat;
72036 + copy_gr_hash_struct = &copy_gr_hash_struct_compat;
72037 + copy_pointer_from_array = &copy_pointer_from_array_compat;
72038 + get_gr_arg_wrapper_size = &get_gr_arg_wrapper_size_compat;
72039 + } else {
72040 + copy_gr_arg_wrapper = &copy_gr_arg_wrapper_normal;
72041 + copy_gr_arg = &copy_gr_arg_normal;
72042 + copy_acl_object_label = &copy_acl_object_label_normal;
72043 + copy_acl_subject_label = &copy_acl_subject_label_normal;
72044 + copy_acl_role_label = &copy_acl_role_label_normal;
72045 + copy_acl_ip_label = &copy_acl_ip_label_normal;
72046 + copy_role_allowed_ip = &copy_role_allowed_ip_normal;
72047 + copy_role_transition = &copy_role_transition_normal;
72048 + copy_sprole_pw = &copy_sprole_pw_normal;
72049 + copy_gr_hash_struct = &copy_gr_hash_struct_normal;
72050 + copy_pointer_from_array = &copy_pointer_from_array_normal;
72051 + get_gr_arg_wrapper_size = &get_gr_arg_wrapper_size_normal;
72052 + }
72053 + pax_close_kernel();
72054 +#endif
72055 +
72056 + req_count = get_gr_arg_wrapper_size();
72057 +
72058 + if (count != req_count) {
72059 + gr_log_int_int(GR_DONT_AUDIT_GOOD, GR_DEV_ACL_MSG, (int)count, (int)req_count);
72060 + error = -EINVAL;
72061 + goto out;
72062 + }
72063 +
72064 +
72065 + if (gr_auth_expires && time_after_eq(get_seconds(), gr_auth_expires)) {
72066 + gr_auth_expires = 0;
72067 + gr_auth_attempts = 0;
72068 + }
72069 +
72070 + error = copy_gr_arg_wrapper(buf, &uwrap);
72071 + if (error)
72072 + goto out;
72073 +
72074 + error = copy_gr_arg(uwrap.arg, &gr_usermode);
72075 + if (error)
72076 + goto out;
72077 +
72078 + if (gr_usermode.mode != GR_SPROLE && gr_usermode.mode != GR_SPROLEPAM &&
72079 + gr_auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
72080 + time_after(gr_auth_expires, get_seconds())) {
72081 + error = -EBUSY;
72082 + goto out;
72083 + }
72084 +
72085 + /* if non-root trying to do anything other than use a special role,
72086 + do not attempt authentication, do not count towards authentication
72087 + locking
72088 + */
72089 +
72090 + if (gr_usermode.mode != GR_SPROLE && gr_usermode.mode != GR_STATUS &&
72091 + gr_usermode.mode != GR_UNSPROLE && gr_usermode.mode != GR_SPROLEPAM &&
72092 + gr_is_global_nonroot(current_uid())) {
72093 + error = -EPERM;
72094 + goto out;
72095 + }
72096 +
72097 + /* ensure pw and special role name are null terminated */
72098 +
72099 + gr_usermode.pw[GR_PW_LEN - 1] = '\0';
72100 + gr_usermode.sp_role[GR_SPROLE_LEN - 1] = '\0';
72101 +
72102 + /* Okay.
72103 + * We have our enough of the argument structure..(we have yet
72104 + * to copy_from_user the tables themselves) . Copy the tables
72105 + * only if we need them, i.e. for loading operations. */
72106 +
72107 + switch (gr_usermode.mode) {
72108 + case GR_STATUS:
72109 + if (gr_acl_is_enabled()) {
72110 + error = 1;
72111 + if (!gr_check_secure_terminal(current))
72112 + error = 3;
72113 + } else
72114 + error = 2;
72115 + goto out;
72116 + case GR_SHUTDOWN:
72117 + if (gr_acl_is_enabled() && !(chkpw(&gr_usermode, (unsigned char *)&gr_system_salt, (unsigned char *)&gr_system_sum))) {
72118 + stop_machine(gr_rbac_disable, NULL, NULL);
72119 + free_variables(false);
72120 + memset(&gr_usermode, 0, sizeof(gr_usermode));
72121 + memset(&gr_system_salt, 0, sizeof(gr_system_salt));
72122 + memset(&gr_system_sum, 0, sizeof(gr_system_sum));
72123 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTS_ACL_MSG);
72124 + } else if (gr_acl_is_enabled()) {
72125 + gr_log_noargs(GR_DONT_AUDIT, GR_SHUTF_ACL_MSG);
72126 + error = -EPERM;
72127 + } else {
72128 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTI_ACL_MSG);
72129 + error = -EAGAIN;
72130 + }
72131 + break;
72132 + case GR_ENABLE:
72133 + if (!gr_acl_is_enabled() && !(error2 = gracl_init(&gr_usermode)))
72134 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_ENABLE_ACL_MSG, GR_VERSION);
72135 + else {
72136 + if (gr_acl_is_enabled())
72137 + error = -EAGAIN;
72138 + else
72139 + error = error2;
72140 + gr_log_str(GR_DONT_AUDIT, GR_ENABLEF_ACL_MSG, GR_VERSION);
72141 + }
72142 + break;
72143 + case GR_OLDRELOAD:
72144 + oldmode = 1;
72145 + case GR_RELOAD:
72146 + if (!gr_acl_is_enabled()) {
72147 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOADI_ACL_MSG, GR_VERSION);
72148 + error = -EAGAIN;
72149 + } else if (!(chkpw(&gr_usermode, (unsigned char *)&gr_system_salt, (unsigned char *)&gr_system_sum))) {
72150 + error2 = gracl_reload(&gr_usermode, oldmode);
72151 + if (!error2)
72152 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOAD_ACL_MSG, GR_VERSION);
72153 + else {
72154 + gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
72155 + error = error2;
72156 + }
72157 + } else {
72158 + gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
72159 + error = -EPERM;
72160 + }
72161 + break;
72162 + case GR_SEGVMOD:
72163 + if (unlikely(!gr_acl_is_enabled())) {
72164 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODI_ACL_MSG);
72165 + error = -EAGAIN;
72166 + break;
72167 + }
72168 +
72169 + if (!(chkpw(&gr_usermode, (unsigned char *)&gr_system_salt, (unsigned char *)&gr_system_sum))) {
72170 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODS_ACL_MSG);
72171 + if (gr_usermode.segv_device && gr_usermode.segv_inode) {
72172 + struct acl_subject_label *segvacl;
72173 + segvacl =
72174 + lookup_acl_subj_label(gr_usermode.segv_inode,
72175 + gr_usermode.segv_device,
72176 + current->role);
72177 + if (segvacl) {
72178 + segvacl->crashes = 0;
72179 + segvacl->expires = 0;
72180 + }
72181 + } else if (gr_find_uid(gr_usermode.segv_uid) >= 0) {
72182 + gr_remove_uid(gr_usermode.segv_uid);
72183 + }
72184 + } else {
72185 + gr_log_noargs(GR_DONT_AUDIT, GR_SEGVMODF_ACL_MSG);
72186 + error = -EPERM;
72187 + }
72188 + break;
72189 + case GR_SPROLE:
72190 + case GR_SPROLEPAM:
72191 + if (unlikely(!gr_acl_is_enabled())) {
72192 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SPROLEI_ACL_MSG);
72193 + error = -EAGAIN;
72194 + break;
72195 + }
72196 +
72197 + if (current->role->expires && time_after_eq(get_seconds(), current->role->expires)) {
72198 + current->role->expires = 0;
72199 + current->role->auth_attempts = 0;
72200 + }
72201 +
72202 + if (current->role->auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
72203 + time_after(current->role->expires, get_seconds())) {
72204 + error = -EBUSY;
72205 + goto out;
72206 + }
72207 +
72208 + if (lookup_special_role_auth
72209 + (gr_usermode.mode, gr_usermode.sp_role, &sprole_salt, &sprole_sum)
72210 + && ((!sprole_salt && !sprole_sum)
72211 + || !(chkpw(&gr_usermode, sprole_salt, sprole_sum)))) {
72212 + char *p = "";
72213 + assign_special_role(gr_usermode.sp_role);
72214 + read_lock(&tasklist_lock);
72215 + if (current->real_parent)
72216 + p = current->real_parent->role->rolename;
72217 + read_unlock(&tasklist_lock);
72218 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLES_ACL_MSG,
72219 + p, acl_sp_role_value);
72220 + } else {
72221 + gr_log_str(GR_DONT_AUDIT, GR_SPROLEF_ACL_MSG, gr_usermode.sp_role);
72222 + error = -EPERM;
72223 + if(!(current->role->auth_attempts++))
72224 + current->role->expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
72225 +
72226 + goto out;
72227 + }
72228 + break;
72229 + case GR_UNSPROLE:
72230 + if (unlikely(!gr_acl_is_enabled())) {
72231 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_UNSPROLEI_ACL_MSG);
72232 + error = -EAGAIN;
72233 + break;
72234 + }
72235 +
72236 + if (current->role->roletype & GR_ROLE_SPECIAL) {
72237 + char *p = "";
72238 + int i = 0;
72239 +
72240 + read_lock(&tasklist_lock);
72241 + if (current->real_parent) {
72242 + p = current->real_parent->role->rolename;
72243 + i = current->real_parent->acl_role_id;
72244 + }
72245 + read_unlock(&tasklist_lock);
72246 +
72247 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_UNSPROLES_ACL_MSG, p, i);
72248 + gr_set_acls(1);
72249 + } else {
72250 + error = -EPERM;
72251 + goto out;
72252 + }
72253 + break;
72254 + default:
72255 + gr_log_int(GR_DONT_AUDIT, GR_INVMODE_ACL_MSG, gr_usermode.mode);
72256 + error = -EINVAL;
72257 + break;
72258 + }
72259 +
72260 + if (error != -EPERM)
72261 + goto out;
72262 +
72263 + if(!(gr_auth_attempts++))
72264 + gr_auth_expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
72265 +
72266 + out:
72267 + mutex_unlock(&gr_dev_mutex);
72268 +
72269 + if (!error)
72270 + error = req_count;
72271 +
72272 + return error;
72273 +}
72274 +
72275 +int
72276 +gr_set_acls(const int type)
72277 +{
72278 + struct task_struct *task, *task2;
72279 + struct acl_role_label *role = current->role;
72280 + struct acl_subject_label *subj;
72281 + __u16 acl_role_id = current->acl_role_id;
72282 + const struct cred *cred;
72283 + int ret;
72284 +
72285 + rcu_read_lock();
72286 + read_lock(&tasklist_lock);
72287 + read_lock(&grsec_exec_file_lock);
72288 + do_each_thread(task2, task) {
72289 + /* check to see if we're called from the exit handler,
72290 + if so, only replace ACLs that have inherited the admin
72291 + ACL */
72292 +
72293 + if (type && (task->role != role ||
72294 + task->acl_role_id != acl_role_id))
72295 + continue;
72296 +
72297 + task->acl_role_id = 0;
72298 + task->acl_sp_role = 0;
72299 + task->inherited = 0;
72300 +
72301 + if (task->exec_file) {
72302 + cred = __task_cred(task);
72303 + task->role = __lookup_acl_role_label(polstate, task, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid));
72304 + subj = __gr_get_subject_for_task(polstate, task, NULL);
72305 + if (subj == NULL) {
72306 + ret = -EINVAL;
72307 + read_unlock(&grsec_exec_file_lock);
72308 + read_unlock(&tasklist_lock);
72309 + rcu_read_unlock();
72310 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_DEFACL_MSG, task->comm, task_pid_nr(task));
72311 + return ret;
72312 + }
72313 + __gr_apply_subject_to_task(polstate, task, subj);
72314 + } else {
72315 + // it's a kernel process
72316 + task->role = polstate->kernel_role;
72317 + task->acl = polstate->kernel_role->root_label;
72318 +#ifdef CONFIG_GRKERNSEC_ACL_HIDEKERN
72319 + task->acl->mode &= ~GR_PROCFIND;
72320 +#endif
72321 + }
72322 + } while_each_thread(task2, task);
72323 + read_unlock(&grsec_exec_file_lock);
72324 + read_unlock(&tasklist_lock);
72325 + rcu_read_unlock();
72326 +
72327 + return 0;
72328 +}
72329 diff --git a/grsecurity/gracl_res.c b/grsecurity/gracl_res.c
72330 new file mode 100644
72331 index 0000000..39645c9
72332 --- /dev/null
72333 +++ b/grsecurity/gracl_res.c
72334 @@ -0,0 +1,68 @@
72335 +#include <linux/kernel.h>
72336 +#include <linux/sched.h>
72337 +#include <linux/gracl.h>
72338 +#include <linux/grinternal.h>
72339 +
72340 +static const char *restab_log[] = {
72341 + [RLIMIT_CPU] = "RLIMIT_CPU",
72342 + [RLIMIT_FSIZE] = "RLIMIT_FSIZE",
72343 + [RLIMIT_DATA] = "RLIMIT_DATA",
72344 + [RLIMIT_STACK] = "RLIMIT_STACK",
72345 + [RLIMIT_CORE] = "RLIMIT_CORE",
72346 + [RLIMIT_RSS] = "RLIMIT_RSS",
72347 + [RLIMIT_NPROC] = "RLIMIT_NPROC",
72348 + [RLIMIT_NOFILE] = "RLIMIT_NOFILE",
72349 + [RLIMIT_MEMLOCK] = "RLIMIT_MEMLOCK",
72350 + [RLIMIT_AS] = "RLIMIT_AS",
72351 + [RLIMIT_LOCKS] = "RLIMIT_LOCKS",
72352 + [RLIMIT_SIGPENDING] = "RLIMIT_SIGPENDING",
72353 + [RLIMIT_MSGQUEUE] = "RLIMIT_MSGQUEUE",
72354 + [RLIMIT_NICE] = "RLIMIT_NICE",
72355 + [RLIMIT_RTPRIO] = "RLIMIT_RTPRIO",
72356 + [RLIMIT_RTTIME] = "RLIMIT_RTTIME",
72357 + [GR_CRASH_RES] = "RLIMIT_CRASH"
72358 +};
72359 +
72360 +void
72361 +gr_log_resource(const struct task_struct *task,
72362 + const int res, const unsigned long wanted, const int gt)
72363 +{
72364 + const struct cred *cred;
72365 + unsigned long rlim;
72366 +
72367 + if (!gr_acl_is_enabled() && !grsec_resource_logging)
72368 + return;
72369 +
72370 + // not yet supported resource
72371 + if (unlikely(!restab_log[res]))
72372 + return;
72373 +
72374 + if (res == RLIMIT_CPU || res == RLIMIT_RTTIME)
72375 + rlim = task_rlimit_max(task, res);
72376 + else
72377 + rlim = task_rlimit(task, res);
72378 +
72379 + if (likely((rlim == RLIM_INFINITY) || (gt && wanted <= rlim) || (!gt && wanted < rlim)))
72380 + return;
72381 +
72382 + rcu_read_lock();
72383 + cred = __task_cred(task);
72384 +
72385 + if (res == RLIMIT_NPROC &&
72386 + (cap_raised(cred->cap_effective, CAP_SYS_ADMIN) ||
72387 + cap_raised(cred->cap_effective, CAP_SYS_RESOURCE)))
72388 + goto out_rcu_unlock;
72389 + else if (res == RLIMIT_MEMLOCK &&
72390 + cap_raised(cred->cap_effective, CAP_IPC_LOCK))
72391 + goto out_rcu_unlock;
72392 + else if (res == RLIMIT_NICE && cap_raised(cred->cap_effective, CAP_SYS_NICE))
72393 + goto out_rcu_unlock;
72394 + rcu_read_unlock();
72395 +
72396 + gr_log_res_ulong2_str(GR_DONT_AUDIT, GR_RESOURCE_MSG, task, wanted, restab_log[res], rlim);
72397 +
72398 + return;
72399 +out_rcu_unlock:
72400 + rcu_read_unlock();
72401 + return;
72402 +}
72403 diff --git a/grsecurity/gracl_segv.c b/grsecurity/gracl_segv.c
72404 new file mode 100644
72405 index 0000000..2040e61
72406 --- /dev/null
72407 +++ b/grsecurity/gracl_segv.c
72408 @@ -0,0 +1,313 @@
72409 +#include <linux/kernel.h>
72410 +#include <linux/mm.h>
72411 +#include <asm/uaccess.h>
72412 +#include <asm/errno.h>
72413 +#include <asm/mman.h>
72414 +#include <net/sock.h>
72415 +#include <linux/file.h>
72416 +#include <linux/fs.h>
72417 +#include <linux/net.h>
72418 +#include <linux/in.h>
72419 +#include <linux/slab.h>
72420 +#include <linux/types.h>
72421 +#include <linux/sched.h>
72422 +#include <linux/timer.h>
72423 +#include <linux/gracl.h>
72424 +#include <linux/grsecurity.h>
72425 +#include <linux/grinternal.h>
72426 +#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
72427 +#include <linux/magic.h>
72428 +#include <linux/pagemap.h>
72429 +#include "../fs/btrfs/async-thread.h"
72430 +#include "../fs/btrfs/ctree.h"
72431 +#include "../fs/btrfs/btrfs_inode.h"
72432 +#endif
72433 +
72434 +static struct crash_uid *uid_set;
72435 +static unsigned short uid_used;
72436 +static DEFINE_SPINLOCK(gr_uid_lock);
72437 +extern rwlock_t gr_inode_lock;
72438 +extern struct acl_subject_label *
72439 + lookup_acl_subj_label(const ino_t inode, const dev_t dev,
72440 + struct acl_role_label *role);
72441 +
72442 +static inline dev_t __get_dev(const struct dentry *dentry)
72443 +{
72444 +#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
72445 + if (dentry->d_sb->s_magic == BTRFS_SUPER_MAGIC)
72446 + return BTRFS_I(dentry->d_inode)->root->anon_dev;
72447 + else
72448 +#endif
72449 + return dentry->d_sb->s_dev;
72450 +}
72451 +
72452 +int
72453 +gr_init_uidset(void)
72454 +{
72455 + uid_set =
72456 + kmalloc(GR_UIDTABLE_MAX * sizeof (struct crash_uid), GFP_KERNEL);
72457 + uid_used = 0;
72458 +
72459 + return uid_set ? 1 : 0;
72460 +}
72461 +
72462 +void
72463 +gr_free_uidset(void)
72464 +{
72465 + if (uid_set) {
72466 + struct crash_uid *tmpset;
72467 + spin_lock(&gr_uid_lock);
72468 + tmpset = uid_set;
72469 + uid_set = NULL;
72470 + uid_used = 0;
72471 + spin_unlock(&gr_uid_lock);
72472 + if (tmpset)
72473 + kfree(tmpset);
72474 + }
72475 +
72476 + return;
72477 +}
72478 +
72479 +int
72480 +gr_find_uid(const uid_t uid)
72481 +{
72482 + struct crash_uid *tmp = uid_set;
72483 + uid_t buid;
72484 + int low = 0, high = uid_used - 1, mid;
72485 +
72486 + while (high >= low) {
72487 + mid = (low + high) >> 1;
72488 + buid = tmp[mid].uid;
72489 + if (buid == uid)
72490 + return mid;
72491 + if (buid > uid)
72492 + high = mid - 1;
72493 + if (buid < uid)
72494 + low = mid + 1;
72495 + }
72496 +
72497 + return -1;
72498 +}
72499 +
72500 +static __inline__ void
72501 +gr_insertsort(void)
72502 +{
72503 + unsigned short i, j;
72504 + struct crash_uid index;
72505 +
72506 + for (i = 1; i < uid_used; i++) {
72507 + index = uid_set[i];
72508 + j = i;
72509 + while ((j > 0) && uid_set[j - 1].uid > index.uid) {
72510 + uid_set[j] = uid_set[j - 1];
72511 + j--;
72512 + }
72513 + uid_set[j] = index;
72514 + }
72515 +
72516 + return;
72517 +}
72518 +
72519 +static __inline__ void
72520 +gr_insert_uid(const kuid_t kuid, const unsigned long expires)
72521 +{
72522 + int loc;
72523 + uid_t uid = GR_GLOBAL_UID(kuid);
72524 +
72525 + if (uid_used == GR_UIDTABLE_MAX)
72526 + return;
72527 +
72528 + loc = gr_find_uid(uid);
72529 +
72530 + if (loc >= 0) {
72531 + uid_set[loc].expires = expires;
72532 + return;
72533 + }
72534 +
72535 + uid_set[uid_used].uid = uid;
72536 + uid_set[uid_used].expires = expires;
72537 + uid_used++;
72538 +
72539 + gr_insertsort();
72540 +
72541 + return;
72542 +}
72543 +
72544 +void
72545 +gr_remove_uid(const unsigned short loc)
72546 +{
72547 + unsigned short i;
72548 +
72549 + for (i = loc + 1; i < uid_used; i++)
72550 + uid_set[i - 1] = uid_set[i];
72551 +
72552 + uid_used--;
72553 +
72554 + return;
72555 +}
72556 +
72557 +int
72558 +gr_check_crash_uid(const kuid_t kuid)
72559 +{
72560 + int loc;
72561 + int ret = 0;
72562 + uid_t uid;
72563 +
72564 + if (unlikely(!gr_acl_is_enabled()))
72565 + return 0;
72566 +
72567 + uid = GR_GLOBAL_UID(kuid);
72568 +
72569 + spin_lock(&gr_uid_lock);
72570 + loc = gr_find_uid(uid);
72571 +
72572 + if (loc < 0)
72573 + goto out_unlock;
72574 +
72575 + if (time_before_eq(uid_set[loc].expires, get_seconds()))
72576 + gr_remove_uid(loc);
72577 + else
72578 + ret = 1;
72579 +
72580 +out_unlock:
72581 + spin_unlock(&gr_uid_lock);
72582 + return ret;
72583 +}
72584 +
72585 +static __inline__ int
72586 +proc_is_setxid(const struct cred *cred)
72587 +{
72588 + if (!uid_eq(cred->uid, cred->euid) || !uid_eq(cred->uid, cred->suid) ||
72589 + !uid_eq(cred->uid, cred->fsuid))
72590 + return 1;
72591 + if (!gid_eq(cred->gid, cred->egid) || !gid_eq(cred->gid, cred->sgid) ||
72592 + !gid_eq(cred->gid, cred->fsgid))
72593 + return 1;
72594 +
72595 + return 0;
72596 +}
72597 +
72598 +extern int gr_fake_force_sig(int sig, struct task_struct *t);
72599 +
72600 +void
72601 +gr_handle_crash(struct task_struct *task, const int sig)
72602 +{
72603 + struct acl_subject_label *curr;
72604 + struct task_struct *tsk, *tsk2;
72605 + const struct cred *cred;
72606 + const struct cred *cred2;
72607 +
72608 + if (sig != SIGSEGV && sig != SIGKILL && sig != SIGBUS && sig != SIGILL)
72609 + return;
72610 +
72611 + if (unlikely(!gr_acl_is_enabled()))
72612 + return;
72613 +
72614 + curr = task->acl;
72615 +
72616 + if (!(curr->resmask & (1U << GR_CRASH_RES)))
72617 + return;
72618 +
72619 + if (time_before_eq(curr->expires, get_seconds())) {
72620 + curr->expires = 0;
72621 + curr->crashes = 0;
72622 + }
72623 +
72624 + curr->crashes++;
72625 +
72626 + if (!curr->expires)
72627 + curr->expires = get_seconds() + curr->res[GR_CRASH_RES].rlim_max;
72628 +
72629 + if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
72630 + time_after(curr->expires, get_seconds())) {
72631 + rcu_read_lock();
72632 + cred = __task_cred(task);
72633 + if (gr_is_global_nonroot(cred->uid) && proc_is_setxid(cred)) {
72634 + gr_log_crash1(GR_DONT_AUDIT, GR_SEGVSTART_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
72635 + spin_lock(&gr_uid_lock);
72636 + gr_insert_uid(cred->uid, curr->expires);
72637 + spin_unlock(&gr_uid_lock);
72638 + curr->expires = 0;
72639 + curr->crashes = 0;
72640 + read_lock(&tasklist_lock);
72641 + do_each_thread(tsk2, tsk) {
72642 + cred2 = __task_cred(tsk);
72643 + if (tsk != task && uid_eq(cred2->uid, cred->uid))
72644 + gr_fake_force_sig(SIGKILL, tsk);
72645 + } while_each_thread(tsk2, tsk);
72646 + read_unlock(&tasklist_lock);
72647 + } else {
72648 + gr_log_crash2(GR_DONT_AUDIT, GR_SEGVNOSUID_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
72649 + read_lock(&tasklist_lock);
72650 + read_lock(&grsec_exec_file_lock);
72651 + do_each_thread(tsk2, tsk) {
72652 + if (likely(tsk != task)) {
72653 + // if this thread has the same subject as the one that triggered
72654 + // RES_CRASH and it's the same binary, kill it
72655 + if (tsk->acl == task->acl && gr_is_same_file(tsk->exec_file, task->exec_file))
72656 + gr_fake_force_sig(SIGKILL, tsk);
72657 + }
72658 + } while_each_thread(tsk2, tsk);
72659 + read_unlock(&grsec_exec_file_lock);
72660 + read_unlock(&tasklist_lock);
72661 + }
72662 + rcu_read_unlock();
72663 + }
72664 +
72665 + return;
72666 +}
72667 +
72668 +int
72669 +gr_check_crash_exec(const struct file *filp)
72670 +{
72671 + struct acl_subject_label *curr;
72672 +
72673 + if (unlikely(!gr_acl_is_enabled()))
72674 + return 0;
72675 +
72676 + read_lock(&gr_inode_lock);
72677 + curr = lookup_acl_subj_label(filp->f_path.dentry->d_inode->i_ino,
72678 + __get_dev(filp->f_path.dentry),
72679 + current->role);
72680 + read_unlock(&gr_inode_lock);
72681 +
72682 + if (!curr || !(curr->resmask & (1U << GR_CRASH_RES)) ||
72683 + (!curr->crashes && !curr->expires))
72684 + return 0;
72685 +
72686 + if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
72687 + time_after(curr->expires, get_seconds()))
72688 + return 1;
72689 + else if (time_before_eq(curr->expires, get_seconds())) {
72690 + curr->crashes = 0;
72691 + curr->expires = 0;
72692 + }
72693 +
72694 + return 0;
72695 +}
72696 +
72697 +void
72698 +gr_handle_alertkill(struct task_struct *task)
72699 +{
72700 + struct acl_subject_label *curracl;
72701 + __u32 curr_ip;
72702 + struct task_struct *p, *p2;
72703 +
72704 + if (unlikely(!gr_acl_is_enabled()))
72705 + return;
72706 +
72707 + curracl = task->acl;
72708 + curr_ip = task->signal->curr_ip;
72709 +
72710 + if ((curracl->mode & GR_KILLIPPROC) && curr_ip) {
72711 + read_lock(&tasklist_lock);
72712 + do_each_thread(p2, p) {
72713 + if (p->signal->curr_ip == curr_ip)
72714 + gr_fake_force_sig(SIGKILL, p);
72715 + } while_each_thread(p2, p);
72716 + read_unlock(&tasklist_lock);
72717 + } else if (curracl->mode & GR_KILLPROC)
72718 + gr_fake_force_sig(SIGKILL, task);
72719 +
72720 + return;
72721 +}
72722 diff --git a/grsecurity/gracl_shm.c b/grsecurity/gracl_shm.c
72723 new file mode 100644
72724 index 0000000..98011b0
72725 --- /dev/null
72726 +++ b/grsecurity/gracl_shm.c
72727 @@ -0,0 +1,40 @@
72728 +#include <linux/kernel.h>
72729 +#include <linux/mm.h>
72730 +#include <linux/sched.h>
72731 +#include <linux/file.h>
72732 +#include <linux/ipc.h>
72733 +#include <linux/gracl.h>
72734 +#include <linux/grsecurity.h>
72735 +#include <linux/grinternal.h>
72736 +
72737 +int
72738 +gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
72739 + const time_t shm_createtime, const kuid_t cuid, const int shmid)
72740 +{
72741 + struct task_struct *task;
72742 +
72743 + if (!gr_acl_is_enabled())
72744 + return 1;
72745 +
72746 + rcu_read_lock();
72747 + read_lock(&tasklist_lock);
72748 +
72749 + task = find_task_by_vpid(shm_cprid);
72750 +
72751 + if (unlikely(!task))
72752 + task = find_task_by_vpid(shm_lapid);
72753 +
72754 + if (unlikely(task && (time_before_eq((unsigned long)task->start_time.tv_sec, (unsigned long)shm_createtime) ||
72755 + (task_pid_nr(task) == shm_lapid)) &&
72756 + (task->acl->mode & GR_PROTSHM) &&
72757 + (task->acl != current->acl))) {
72758 + read_unlock(&tasklist_lock);
72759 + rcu_read_unlock();
72760 + gr_log_int3(GR_DONT_AUDIT, GR_SHMAT_ACL_MSG, GR_GLOBAL_UID(cuid), shm_cprid, shmid);
72761 + return 0;
72762 + }
72763 + read_unlock(&tasklist_lock);
72764 + rcu_read_unlock();
72765 +
72766 + return 1;
72767 +}
72768 diff --git a/grsecurity/grsec_chdir.c b/grsecurity/grsec_chdir.c
72769 new file mode 100644
72770 index 0000000..bc0be01
72771 --- /dev/null
72772 +++ b/grsecurity/grsec_chdir.c
72773 @@ -0,0 +1,19 @@
72774 +#include <linux/kernel.h>
72775 +#include <linux/sched.h>
72776 +#include <linux/fs.h>
72777 +#include <linux/file.h>
72778 +#include <linux/grsecurity.h>
72779 +#include <linux/grinternal.h>
72780 +
72781 +void
72782 +gr_log_chdir(const struct dentry *dentry, const struct vfsmount *mnt)
72783 +{
72784 +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
72785 + if ((grsec_enable_chdir && grsec_enable_group &&
72786 + in_group_p(grsec_audit_gid)) || (grsec_enable_chdir &&
72787 + !grsec_enable_group)) {
72788 + gr_log_fs_generic(GR_DO_AUDIT, GR_CHDIR_AUDIT_MSG, dentry, mnt);
72789 + }
72790 +#endif
72791 + return;
72792 +}
72793 diff --git a/grsecurity/grsec_chroot.c b/grsecurity/grsec_chroot.c
72794 new file mode 100644
72795 index 0000000..651d6c2
72796 --- /dev/null
72797 +++ b/grsecurity/grsec_chroot.c
72798 @@ -0,0 +1,370 @@
72799 +#include <linux/kernel.h>
72800 +#include <linux/module.h>
72801 +#include <linux/sched.h>
72802 +#include <linux/file.h>
72803 +#include <linux/fs.h>
72804 +#include <linux/mount.h>
72805 +#include <linux/types.h>
72806 +#include "../fs/mount.h"
72807 +#include <linux/grsecurity.h>
72808 +#include <linux/grinternal.h>
72809 +
72810 +#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
72811 +int gr_init_ran;
72812 +#endif
72813 +
72814 +void gr_set_chroot_entries(struct task_struct *task, const struct path *path)
72815 +{
72816 +#ifdef CONFIG_GRKERNSEC
72817 + if (task_pid_nr(task) > 1 && path->dentry != init_task.fs->root.dentry &&
72818 + path->dentry != task->nsproxy->mnt_ns->root->mnt.mnt_root
72819 +#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
72820 + && gr_init_ran
72821 +#endif
72822 + )
72823 + task->gr_is_chrooted = 1;
72824 + else {
72825 +#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
72826 + if (task_pid_nr(task) == 1 && !gr_init_ran)
72827 + gr_init_ran = 1;
72828 +#endif
72829 + task->gr_is_chrooted = 0;
72830 + }
72831 +
72832 + task->gr_chroot_dentry = path->dentry;
72833 +#endif
72834 + return;
72835 +}
72836 +
72837 +void gr_clear_chroot_entries(struct task_struct *task)
72838 +{
72839 +#ifdef CONFIG_GRKERNSEC
72840 + task->gr_is_chrooted = 0;
72841 + task->gr_chroot_dentry = NULL;
72842 +#endif
72843 + return;
72844 +}
72845 +
72846 +int
72847 +gr_handle_chroot_unix(const pid_t pid)
72848 +{
72849 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
72850 + struct task_struct *p;
72851 +
72852 + if (unlikely(!grsec_enable_chroot_unix))
72853 + return 1;
72854 +
72855 + if (likely(!proc_is_chrooted(current)))
72856 + return 1;
72857 +
72858 + rcu_read_lock();
72859 + read_lock(&tasklist_lock);
72860 + p = find_task_by_vpid_unrestricted(pid);
72861 + if (unlikely(p && !have_same_root(current, p))) {
72862 + read_unlock(&tasklist_lock);
72863 + rcu_read_unlock();
72864 + gr_log_noargs(GR_DONT_AUDIT, GR_UNIX_CHROOT_MSG);
72865 + return 0;
72866 + }
72867 + read_unlock(&tasklist_lock);
72868 + rcu_read_unlock();
72869 +#endif
72870 + return 1;
72871 +}
72872 +
72873 +int
72874 +gr_handle_chroot_nice(void)
72875 +{
72876 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
72877 + if (grsec_enable_chroot_nice && proc_is_chrooted(current)) {
72878 + gr_log_noargs(GR_DONT_AUDIT, GR_NICE_CHROOT_MSG);
72879 + return -EPERM;
72880 + }
72881 +#endif
72882 + return 0;
72883 +}
72884 +
72885 +int
72886 +gr_handle_chroot_setpriority(struct task_struct *p, const int niceval)
72887 +{
72888 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
72889 + if (grsec_enable_chroot_nice && (niceval < task_nice(p))
72890 + && proc_is_chrooted(current)) {
72891 + gr_log_str_int(GR_DONT_AUDIT, GR_PRIORITY_CHROOT_MSG, p->comm, task_pid_nr(p));
72892 + return -EACCES;
72893 + }
72894 +#endif
72895 + return 0;
72896 +}
72897 +
72898 +int
72899 +gr_handle_chroot_fowner(struct pid *pid, enum pid_type type)
72900 +{
72901 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
72902 + struct task_struct *p;
72903 + int ret = 0;
72904 + if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || !pid)
72905 + return ret;
72906 +
72907 + read_lock(&tasklist_lock);
72908 + do_each_pid_task(pid, type, p) {
72909 + if (!have_same_root(current, p)) {
72910 + ret = 1;
72911 + goto out;
72912 + }
72913 + } while_each_pid_task(pid, type, p);
72914 +out:
72915 + read_unlock(&tasklist_lock);
72916 + return ret;
72917 +#endif
72918 + return 0;
72919 +}
72920 +
72921 +int
72922 +gr_pid_is_chrooted(struct task_struct *p)
72923 +{
72924 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
72925 + if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || p == NULL)
72926 + return 0;
72927 +
72928 + if ((p->exit_state & (EXIT_ZOMBIE | EXIT_DEAD)) ||
72929 + !have_same_root(current, p)) {
72930 + return 1;
72931 + }
72932 +#endif
72933 + return 0;
72934 +}
72935 +
72936 +EXPORT_SYMBOL_GPL(gr_pid_is_chrooted);
72937 +
72938 +#if defined(CONFIG_GRKERNSEC_CHROOT_DOUBLE) || defined(CONFIG_GRKERNSEC_CHROOT_FCHDIR)
72939 +int gr_is_outside_chroot(const struct dentry *u_dentry, const struct vfsmount *u_mnt)
72940 +{
72941 + struct path path, currentroot;
72942 + int ret = 0;
72943 +
72944 + path.dentry = (struct dentry *)u_dentry;
72945 + path.mnt = (struct vfsmount *)u_mnt;
72946 + get_fs_root(current->fs, &currentroot);
72947 + if (path_is_under(&path, &currentroot))
72948 + ret = 1;
72949 + path_put(&currentroot);
72950 +
72951 + return ret;
72952 +}
72953 +#endif
72954 +
72955 +int
72956 +gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt)
72957 +{
72958 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
72959 + if (!grsec_enable_chroot_fchdir)
72960 + return 1;
72961 +
72962 + if (!proc_is_chrooted(current))
72963 + return 1;
72964 + else if (!gr_is_outside_chroot(u_dentry, u_mnt)) {
72965 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_FCHDIR_MSG, u_dentry, u_mnt);
72966 + return 0;
72967 + }
72968 +#endif
72969 + return 1;
72970 +}
72971 +
72972 +int
72973 +gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
72974 + const time_t shm_createtime)
72975 +{
72976 +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
72977 + struct task_struct *p;
72978 + time_t starttime;
72979 +
72980 + if (unlikely(!grsec_enable_chroot_shmat))
72981 + return 1;
72982 +
72983 + if (likely(!proc_is_chrooted(current)))
72984 + return 1;
72985 +
72986 + rcu_read_lock();
72987 + read_lock(&tasklist_lock);
72988 +
72989 + if ((p = find_task_by_vpid_unrestricted(shm_cprid))) {
72990 + starttime = p->start_time.tv_sec;
72991 + if (time_before_eq((unsigned long)starttime, (unsigned long)shm_createtime)) {
72992 + if (have_same_root(current, p)) {
72993 + goto allow;
72994 + } else {
72995 + read_unlock(&tasklist_lock);
72996 + rcu_read_unlock();
72997 + gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
72998 + return 0;
72999 + }
73000 + }
73001 + /* creator exited, pid reuse, fall through to next check */
73002 + }
73003 + if ((p = find_task_by_vpid_unrestricted(shm_lapid))) {
73004 + if (unlikely(!have_same_root(current, p))) {
73005 + read_unlock(&tasklist_lock);
73006 + rcu_read_unlock();
73007 + gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
73008 + return 0;
73009 + }
73010 + }
73011 +
73012 +allow:
73013 + read_unlock(&tasklist_lock);
73014 + rcu_read_unlock();
73015 +#endif
73016 + return 1;
73017 +}
73018 +
73019 +void
73020 +gr_log_chroot_exec(const struct dentry *dentry, const struct vfsmount *mnt)
73021 +{
73022 +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
73023 + if (grsec_enable_chroot_execlog && proc_is_chrooted(current))
73024 + gr_log_fs_generic(GR_DO_AUDIT, GR_EXEC_CHROOT_MSG, dentry, mnt);
73025 +#endif
73026 + return;
73027 +}
73028 +
73029 +int
73030 +gr_handle_chroot_mknod(const struct dentry *dentry,
73031 + const struct vfsmount *mnt, const int mode)
73032 +{
73033 +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
73034 + if (grsec_enable_chroot_mknod && !S_ISFIFO(mode) && !S_ISREG(mode) &&
73035 + proc_is_chrooted(current)) {
73036 + gr_log_fs_generic(GR_DONT_AUDIT, GR_MKNOD_CHROOT_MSG, dentry, mnt);
73037 + return -EPERM;
73038 + }
73039 +#endif
73040 + return 0;
73041 +}
73042 +
73043 +int
73044 +gr_handle_chroot_mount(const struct dentry *dentry,
73045 + const struct vfsmount *mnt, const char *dev_name)
73046 +{
73047 +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
73048 + if (grsec_enable_chroot_mount && proc_is_chrooted(current)) {
73049 + gr_log_str_fs(GR_DONT_AUDIT, GR_MOUNT_CHROOT_MSG, dev_name ? dev_name : "none", dentry, mnt);
73050 + return -EPERM;
73051 + }
73052 +#endif
73053 + return 0;
73054 +}
73055 +
73056 +int
73057 +gr_handle_chroot_pivot(void)
73058 +{
73059 +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
73060 + if (grsec_enable_chroot_pivot && proc_is_chrooted(current)) {
73061 + gr_log_noargs(GR_DONT_AUDIT, GR_PIVOT_CHROOT_MSG);
73062 + return -EPERM;
73063 + }
73064 +#endif
73065 + return 0;
73066 +}
73067 +
73068 +int
73069 +gr_handle_chroot_chroot(const struct dentry *dentry, const struct vfsmount *mnt)
73070 +{
73071 +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
73072 + if (grsec_enable_chroot_double && proc_is_chrooted(current) &&
73073 + !gr_is_outside_chroot(dentry, mnt)) {
73074 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_CHROOT_MSG, dentry, mnt);
73075 + return -EPERM;
73076 + }
73077 +#endif
73078 + return 0;
73079 +}
73080 +
73081 +extern const char *captab_log[];
73082 +extern int captab_log_entries;
73083 +
73084 +int
73085 +gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
73086 +{
73087 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
73088 + if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
73089 + kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
73090 + if (cap_raised(chroot_caps, cap)) {
73091 + if (cap_raised(cred->cap_effective, cap) && cap < captab_log_entries) {
73092 + gr_log_cap(GR_DONT_AUDIT, GR_CAP_CHROOT_MSG, task, captab_log[cap]);
73093 + }
73094 + return 0;
73095 + }
73096 + }
73097 +#endif
73098 + return 1;
73099 +}
73100 +
73101 +int
73102 +gr_chroot_is_capable(const int cap)
73103 +{
73104 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
73105 + return gr_task_chroot_is_capable(current, current_cred(), cap);
73106 +#endif
73107 + return 1;
73108 +}
73109 +
73110 +int
73111 +gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap)
73112 +{
73113 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
73114 + if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
73115 + kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
73116 + if (cap_raised(chroot_caps, cap)) {
73117 + return 0;
73118 + }
73119 + }
73120 +#endif
73121 + return 1;
73122 +}
73123 +
73124 +int
73125 +gr_chroot_is_capable_nolog(const int cap)
73126 +{
73127 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
73128 + return gr_task_chroot_is_capable_nolog(current, cap);
73129 +#endif
73130 + return 1;
73131 +}
73132 +
73133 +int
73134 +gr_handle_chroot_sysctl(const int op)
73135 +{
73136 +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
73137 + if (grsec_enable_chroot_sysctl && (op & MAY_WRITE) &&
73138 + proc_is_chrooted(current))
73139 + return -EACCES;
73140 +#endif
73141 + return 0;
73142 +}
73143 +
73144 +void
73145 +gr_handle_chroot_chdir(const struct path *path)
73146 +{
73147 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
73148 + if (grsec_enable_chroot_chdir)
73149 + set_fs_pwd(current->fs, path);
73150 +#endif
73151 + return;
73152 +}
73153 +
73154 +int
73155 +gr_handle_chroot_chmod(const struct dentry *dentry,
73156 + const struct vfsmount *mnt, const int mode)
73157 +{
73158 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
73159 + /* allow chmod +s on directories, but not files */
73160 + if (grsec_enable_chroot_chmod && !S_ISDIR(dentry->d_inode->i_mode) &&
73161 + ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))) &&
73162 + proc_is_chrooted(current)) {
73163 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHMOD_CHROOT_MSG, dentry, mnt);
73164 + return -EPERM;
73165 + }
73166 +#endif
73167 + return 0;
73168 +}
73169 diff --git a/grsecurity/grsec_disabled.c b/grsecurity/grsec_disabled.c
73170 new file mode 100644
73171 index 0000000..4d6fce8
73172 --- /dev/null
73173 +++ b/grsecurity/grsec_disabled.c
73174 @@ -0,0 +1,433 @@
73175 +#include <linux/kernel.h>
73176 +#include <linux/module.h>
73177 +#include <linux/sched.h>
73178 +#include <linux/file.h>
73179 +#include <linux/fs.h>
73180 +#include <linux/kdev_t.h>
73181 +#include <linux/net.h>
73182 +#include <linux/in.h>
73183 +#include <linux/ip.h>
73184 +#include <linux/skbuff.h>
73185 +#include <linux/sysctl.h>
73186 +
73187 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
73188 +void
73189 +pax_set_initial_flags(struct linux_binprm *bprm)
73190 +{
73191 + return;
73192 +}
73193 +#endif
73194 +
73195 +#ifdef CONFIG_SYSCTL
73196 +__u32
73197 +gr_handle_sysctl(const struct ctl_table * table, const int op)
73198 +{
73199 + return 0;
73200 +}
73201 +#endif
73202 +
73203 +#ifdef CONFIG_TASKSTATS
73204 +int gr_is_taskstats_denied(int pid)
73205 +{
73206 + return 0;
73207 +}
73208 +#endif
73209 +
73210 +int
73211 +gr_acl_is_enabled(void)
73212 +{
73213 + return 0;
73214 +}
73215 +
73216 +void
73217 +gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
73218 +{
73219 + return;
73220 +}
73221 +
73222 +int
73223 +gr_handle_rawio(const struct inode *inode)
73224 +{
73225 + return 0;
73226 +}
73227 +
73228 +void
73229 +gr_acl_handle_psacct(struct task_struct *task, const long code)
73230 +{
73231 + return;
73232 +}
73233 +
73234 +int
73235 +gr_handle_ptrace(struct task_struct *task, const long request)
73236 +{
73237 + return 0;
73238 +}
73239 +
73240 +int
73241 +gr_handle_proc_ptrace(struct task_struct *task)
73242 +{
73243 + return 0;
73244 +}
73245 +
73246 +int
73247 +gr_set_acls(const int type)
73248 +{
73249 + return 0;
73250 +}
73251 +
73252 +int
73253 +gr_check_hidden_task(const struct task_struct *tsk)
73254 +{
73255 + return 0;
73256 +}
73257 +
73258 +int
73259 +gr_check_protected_task(const struct task_struct *task)
73260 +{
73261 + return 0;
73262 +}
73263 +
73264 +int
73265 +gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
73266 +{
73267 + return 0;
73268 +}
73269 +
73270 +void
73271 +gr_copy_label(struct task_struct *tsk)
73272 +{
73273 + return;
73274 +}
73275 +
73276 +void
73277 +gr_set_pax_flags(struct task_struct *task)
73278 +{
73279 + return;
73280 +}
73281 +
73282 +int
73283 +gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
73284 + const int unsafe_share)
73285 +{
73286 + return 0;
73287 +}
73288 +
73289 +void
73290 +gr_handle_delete(const ino_t ino, const dev_t dev)
73291 +{
73292 + return;
73293 +}
73294 +
73295 +void
73296 +gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
73297 +{
73298 + return;
73299 +}
73300 +
73301 +void
73302 +gr_handle_crash(struct task_struct *task, const int sig)
73303 +{
73304 + return;
73305 +}
73306 +
73307 +int
73308 +gr_check_crash_exec(const struct file *filp)
73309 +{
73310 + return 0;
73311 +}
73312 +
73313 +int
73314 +gr_check_crash_uid(const kuid_t uid)
73315 +{
73316 + return 0;
73317 +}
73318 +
73319 +void
73320 +gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
73321 + struct dentry *old_dentry,
73322 + struct dentry *new_dentry,
73323 + struct vfsmount *mnt, const __u8 replace)
73324 +{
73325 + return;
73326 +}
73327 +
73328 +int
73329 +gr_search_socket(const int family, const int type, const int protocol)
73330 +{
73331 + return 1;
73332 +}
73333 +
73334 +int
73335 +gr_search_connectbind(const int mode, const struct socket *sock,
73336 + const struct sockaddr_in *addr)
73337 +{
73338 + return 0;
73339 +}
73340 +
73341 +void
73342 +gr_handle_alertkill(struct task_struct *task)
73343 +{
73344 + return;
73345 +}
73346 +
73347 +__u32
73348 +gr_acl_handle_execve(const struct dentry * dentry, const struct vfsmount * mnt)
73349 +{
73350 + return 1;
73351 +}
73352 +
73353 +__u32
73354 +gr_acl_handle_hidden_file(const struct dentry * dentry,
73355 + const struct vfsmount * mnt)
73356 +{
73357 + return 1;
73358 +}
73359 +
73360 +__u32
73361 +gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
73362 + int acc_mode)
73363 +{
73364 + return 1;
73365 +}
73366 +
73367 +__u32
73368 +gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
73369 +{
73370 + return 1;
73371 +}
73372 +
73373 +__u32
73374 +gr_acl_handle_unlink(const struct dentry * dentry, const struct vfsmount * mnt)
73375 +{
73376 + return 1;
73377 +}
73378 +
73379 +int
73380 +gr_acl_handle_mmap(const struct file *file, const unsigned long prot,
73381 + unsigned int *vm_flags)
73382 +{
73383 + return 1;
73384 +}
73385 +
73386 +__u32
73387 +gr_acl_handle_truncate(const struct dentry * dentry,
73388 + const struct vfsmount * mnt)
73389 +{
73390 + return 1;
73391 +}
73392 +
73393 +__u32
73394 +gr_acl_handle_utime(const struct dentry * dentry, const struct vfsmount * mnt)
73395 +{
73396 + return 1;
73397 +}
73398 +
73399 +__u32
73400 +gr_acl_handle_access(const struct dentry * dentry,
73401 + const struct vfsmount * mnt, const int fmode)
73402 +{
73403 + return 1;
73404 +}
73405 +
73406 +__u32
73407 +gr_acl_handle_chmod(const struct dentry * dentry, const struct vfsmount * mnt,
73408 + umode_t *mode)
73409 +{
73410 + return 1;
73411 +}
73412 +
73413 +__u32
73414 +gr_acl_handle_chown(const struct dentry * dentry, const struct vfsmount * mnt)
73415 +{
73416 + return 1;
73417 +}
73418 +
73419 +__u32
73420 +gr_acl_handle_setxattr(const struct dentry * dentry, const struct vfsmount * mnt)
73421 +{
73422 + return 1;
73423 +}
73424 +
73425 +__u32
73426 +gr_acl_handle_removexattr(const struct dentry * dentry, const struct vfsmount * mnt)
73427 +{
73428 + return 1;
73429 +}
73430 +
73431 +void
73432 +grsecurity_init(void)
73433 +{
73434 + return;
73435 +}
73436 +
73437 +umode_t gr_acl_umask(void)
73438 +{
73439 + return 0;
73440 +}
73441 +
73442 +__u32
73443 +gr_acl_handle_mknod(const struct dentry * new_dentry,
73444 + const struct dentry * parent_dentry,
73445 + const struct vfsmount * parent_mnt,
73446 + const int mode)
73447 +{
73448 + return 1;
73449 +}
73450 +
73451 +__u32
73452 +gr_acl_handle_mkdir(const struct dentry * new_dentry,
73453 + const struct dentry * parent_dentry,
73454 + const struct vfsmount * parent_mnt)
73455 +{
73456 + return 1;
73457 +}
73458 +
73459 +__u32
73460 +gr_acl_handle_symlink(const struct dentry * new_dentry,
73461 + const struct dentry * parent_dentry,
73462 + const struct vfsmount * parent_mnt, const struct filename *from)
73463 +{
73464 + return 1;
73465 +}
73466 +
73467 +__u32
73468 +gr_acl_handle_link(const struct dentry * new_dentry,
73469 + const struct dentry * parent_dentry,
73470 + const struct vfsmount * parent_mnt,
73471 + const struct dentry * old_dentry,
73472 + const struct vfsmount * old_mnt, const struct filename *to)
73473 +{
73474 + return 1;
73475 +}
73476 +
73477 +int
73478 +gr_acl_handle_rename(const struct dentry *new_dentry,
73479 + const struct dentry *parent_dentry,
73480 + const struct vfsmount *parent_mnt,
73481 + const struct dentry *old_dentry,
73482 + const struct inode *old_parent_inode,
73483 + const struct vfsmount *old_mnt, const struct filename *newname)
73484 +{
73485 + return 0;
73486 +}
73487 +
73488 +int
73489 +gr_acl_handle_filldir(const struct file *file, const char *name,
73490 + const int namelen, const ino_t ino)
73491 +{
73492 + return 1;
73493 +}
73494 +
73495 +int
73496 +gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
73497 + const time_t shm_createtime, const kuid_t cuid, const int shmid)
73498 +{
73499 + return 1;
73500 +}
73501 +
73502 +int
73503 +gr_search_bind(const struct socket *sock, const struct sockaddr_in *addr)
73504 +{
73505 + return 0;
73506 +}
73507 +
73508 +int
73509 +gr_search_accept(const struct socket *sock)
73510 +{
73511 + return 0;
73512 +}
73513 +
73514 +int
73515 +gr_search_listen(const struct socket *sock)
73516 +{
73517 + return 0;
73518 +}
73519 +
73520 +int
73521 +gr_search_connect(const struct socket *sock, const struct sockaddr_in *addr)
73522 +{
73523 + return 0;
73524 +}
73525 +
73526 +__u32
73527 +gr_acl_handle_unix(const struct dentry * dentry, const struct vfsmount * mnt)
73528 +{
73529 + return 1;
73530 +}
73531 +
73532 +__u32
73533 +gr_acl_handle_creat(const struct dentry * dentry,
73534 + const struct dentry * p_dentry,
73535 + const struct vfsmount * p_mnt, int open_flags, int acc_mode,
73536 + const int imode)
73537 +{
73538 + return 1;
73539 +}
73540 +
73541 +void
73542 +gr_acl_handle_exit(void)
73543 +{
73544 + return;
73545 +}
73546 +
73547 +int
73548 +gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
73549 +{
73550 + return 1;
73551 +}
73552 +
73553 +void
73554 +gr_set_role_label(const kuid_t uid, const kgid_t gid)
73555 +{
73556 + return;
73557 +}
73558 +
73559 +int
73560 +gr_acl_handle_procpidmem(const struct task_struct *task)
73561 +{
73562 + return 0;
73563 +}
73564 +
73565 +int
73566 +gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb)
73567 +{
73568 + return 0;
73569 +}
73570 +
73571 +int
73572 +gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr)
73573 +{
73574 + return 0;
73575 +}
73576 +
73577 +int
73578 +gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs)
73579 +{
73580 + return 0;
73581 +}
73582 +
73583 +int
73584 +gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs)
73585 +{
73586 + return 0;
73587 +}
73588 +
73589 +int gr_acl_enable_at_secure(void)
73590 +{
73591 + return 0;
73592 +}
73593 +
73594 +dev_t gr_get_dev_from_dentry(struct dentry *dentry)
73595 +{
73596 + return dentry->d_sb->s_dev;
73597 +}
73598 +
73599 +void gr_put_exec_file(struct task_struct *task)
73600 +{
73601 + return;
73602 +}
73603 +
73604 +#ifdef CONFIG_SECURITY
73605 +EXPORT_SYMBOL_GPL(gr_check_user_change);
73606 +EXPORT_SYMBOL_GPL(gr_check_group_change);
73607 +#endif
73608 diff --git a/grsecurity/grsec_exec.c b/grsecurity/grsec_exec.c
73609 new file mode 100644
73610 index 0000000..f35f454
73611 --- /dev/null
73612 +++ b/grsecurity/grsec_exec.c
73613 @@ -0,0 +1,187 @@
73614 +#include <linux/kernel.h>
73615 +#include <linux/sched.h>
73616 +#include <linux/file.h>
73617 +#include <linux/binfmts.h>
73618 +#include <linux/fs.h>
73619 +#include <linux/types.h>
73620 +#include <linux/grdefs.h>
73621 +#include <linux/grsecurity.h>
73622 +#include <linux/grinternal.h>
73623 +#include <linux/capability.h>
73624 +#include <linux/module.h>
73625 +#include <linux/compat.h>
73626 +
73627 +#include <asm/uaccess.h>
73628 +
73629 +#ifdef CONFIG_GRKERNSEC_EXECLOG
73630 +static char gr_exec_arg_buf[132];
73631 +static DEFINE_MUTEX(gr_exec_arg_mutex);
73632 +#endif
73633 +
73634 +struct user_arg_ptr {
73635 +#ifdef CONFIG_COMPAT
73636 + bool is_compat;
73637 +#endif
73638 + union {
73639 + const char __user *const __user *native;
73640 +#ifdef CONFIG_COMPAT
73641 + const compat_uptr_t __user *compat;
73642 +#endif
73643 + } ptr;
73644 +};
73645 +
73646 +extern const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr);
73647 +
73648 +void
73649 +gr_handle_exec_args(struct linux_binprm *bprm, struct user_arg_ptr argv)
73650 +{
73651 +#ifdef CONFIG_GRKERNSEC_EXECLOG
73652 + char *grarg = gr_exec_arg_buf;
73653 + unsigned int i, x, execlen = 0;
73654 + char c;
73655 +
73656 + if (!((grsec_enable_execlog && grsec_enable_group &&
73657 + in_group_p(grsec_audit_gid))
73658 + || (grsec_enable_execlog && !grsec_enable_group)))
73659 + return;
73660 +
73661 + mutex_lock(&gr_exec_arg_mutex);
73662 + memset(grarg, 0, sizeof(gr_exec_arg_buf));
73663 +
73664 + for (i = 0; i < bprm->argc && execlen < 128; i++) {
73665 + const char __user *p;
73666 + unsigned int len;
73667 +
73668 + p = get_user_arg_ptr(argv, i);
73669 + if (IS_ERR(p))
73670 + goto log;
73671 +
73672 + len = strnlen_user(p, 128 - execlen);
73673 + if (len > 128 - execlen)
73674 + len = 128 - execlen;
73675 + else if (len > 0)
73676 + len--;
73677 + if (copy_from_user(grarg + execlen, p, len))
73678 + goto log;
73679 +
73680 + /* rewrite unprintable characters */
73681 + for (x = 0; x < len; x++) {
73682 + c = *(grarg + execlen + x);
73683 + if (c < 32 || c > 126)
73684 + *(grarg + execlen + x) = ' ';
73685 + }
73686 +
73687 + execlen += len;
73688 + *(grarg + execlen) = ' ';
73689 + *(grarg + execlen + 1) = '\0';
73690 + execlen++;
73691 + }
73692 +
73693 + log:
73694 + gr_log_fs_str(GR_DO_AUDIT, GR_EXEC_AUDIT_MSG, bprm->file->f_path.dentry,
73695 + bprm->file->f_path.mnt, grarg);
73696 + mutex_unlock(&gr_exec_arg_mutex);
73697 +#endif
73698 + return;
73699 +}
73700 +
73701 +#ifdef CONFIG_GRKERNSEC
73702 +extern int gr_acl_is_capable(const int cap);
73703 +extern int gr_acl_is_capable_nolog(const int cap);
73704 +extern int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
73705 +extern int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap);
73706 +extern int gr_chroot_is_capable(const int cap);
73707 +extern int gr_chroot_is_capable_nolog(const int cap);
73708 +extern int gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
73709 +extern int gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap);
73710 +#endif
73711 +
73712 +const char *captab_log[] = {
73713 + "CAP_CHOWN",
73714 + "CAP_DAC_OVERRIDE",
73715 + "CAP_DAC_READ_SEARCH",
73716 + "CAP_FOWNER",
73717 + "CAP_FSETID",
73718 + "CAP_KILL",
73719 + "CAP_SETGID",
73720 + "CAP_SETUID",
73721 + "CAP_SETPCAP",
73722 + "CAP_LINUX_IMMUTABLE",
73723 + "CAP_NET_BIND_SERVICE",
73724 + "CAP_NET_BROADCAST",
73725 + "CAP_NET_ADMIN",
73726 + "CAP_NET_RAW",
73727 + "CAP_IPC_LOCK",
73728 + "CAP_IPC_OWNER",
73729 + "CAP_SYS_MODULE",
73730 + "CAP_SYS_RAWIO",
73731 + "CAP_SYS_CHROOT",
73732 + "CAP_SYS_PTRACE",
73733 + "CAP_SYS_PACCT",
73734 + "CAP_SYS_ADMIN",
73735 + "CAP_SYS_BOOT",
73736 + "CAP_SYS_NICE",
73737 + "CAP_SYS_RESOURCE",
73738 + "CAP_SYS_TIME",
73739 + "CAP_SYS_TTY_CONFIG",
73740 + "CAP_MKNOD",
73741 + "CAP_LEASE",
73742 + "CAP_AUDIT_WRITE",
73743 + "CAP_AUDIT_CONTROL",
73744 + "CAP_SETFCAP",
73745 + "CAP_MAC_OVERRIDE",
73746 + "CAP_MAC_ADMIN",
73747 + "CAP_SYSLOG",
73748 + "CAP_WAKE_ALARM"
73749 +};
73750 +
73751 +int captab_log_entries = sizeof(captab_log)/sizeof(captab_log[0]);
73752 +
73753 +int gr_is_capable(const int cap)
73754 +{
73755 +#ifdef CONFIG_GRKERNSEC
73756 + if (gr_acl_is_capable(cap) && gr_chroot_is_capable(cap))
73757 + return 1;
73758 + return 0;
73759 +#else
73760 + return 1;
73761 +#endif
73762 +}
73763 +
73764 +int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
73765 +{
73766 +#ifdef CONFIG_GRKERNSEC
73767 + if (gr_task_acl_is_capable(task, cred, cap) && gr_task_chroot_is_capable(task, cred, cap))
73768 + return 1;
73769 + return 0;
73770 +#else
73771 + return 1;
73772 +#endif
73773 +}
73774 +
73775 +int gr_is_capable_nolog(const int cap)
73776 +{
73777 +#ifdef CONFIG_GRKERNSEC
73778 + if (gr_acl_is_capable_nolog(cap) && gr_chroot_is_capable_nolog(cap))
73779 + return 1;
73780 + return 0;
73781 +#else
73782 + return 1;
73783 +#endif
73784 +}
73785 +
73786 +int gr_task_is_capable_nolog(const struct task_struct *task, const int cap)
73787 +{
73788 +#ifdef CONFIG_GRKERNSEC
73789 + if (gr_task_acl_is_capable_nolog(task, cap) && gr_task_chroot_is_capable_nolog(task, cap))
73790 + return 1;
73791 + return 0;
73792 +#else
73793 + return 1;
73794 +#endif
73795 +}
73796 +
73797 +EXPORT_SYMBOL_GPL(gr_is_capable);
73798 +EXPORT_SYMBOL_GPL(gr_is_capable_nolog);
73799 +EXPORT_SYMBOL_GPL(gr_task_is_capable);
73800 +EXPORT_SYMBOL_GPL(gr_task_is_capable_nolog);
73801 diff --git a/grsecurity/grsec_fifo.c b/grsecurity/grsec_fifo.c
73802 new file mode 100644
73803 index 0000000..06cc6ea
73804 --- /dev/null
73805 +++ b/grsecurity/grsec_fifo.c
73806 @@ -0,0 +1,24 @@
73807 +#include <linux/kernel.h>
73808 +#include <linux/sched.h>
73809 +#include <linux/fs.h>
73810 +#include <linux/file.h>
73811 +#include <linux/grinternal.h>
73812 +
73813 +int
73814 +gr_handle_fifo(const struct dentry *dentry, const struct vfsmount *mnt,
73815 + const struct dentry *dir, const int flag, const int acc_mode)
73816 +{
73817 +#ifdef CONFIG_GRKERNSEC_FIFO
73818 + const struct cred *cred = current_cred();
73819 +
73820 + if (grsec_enable_fifo && S_ISFIFO(dentry->d_inode->i_mode) &&
73821 + !(flag & O_EXCL) && (dir->d_inode->i_mode & S_ISVTX) &&
73822 + !uid_eq(dentry->d_inode->i_uid, dir->d_inode->i_uid) &&
73823 + !uid_eq(cred->fsuid, dentry->d_inode->i_uid)) {
73824 + if (!inode_permission(dentry->d_inode, acc_mode))
73825 + 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));
73826 + return -EACCES;
73827 + }
73828 +#endif
73829 + return 0;
73830 +}
73831 diff --git a/grsecurity/grsec_fork.c b/grsecurity/grsec_fork.c
73832 new file mode 100644
73833 index 0000000..8ca18bf
73834 --- /dev/null
73835 +++ b/grsecurity/grsec_fork.c
73836 @@ -0,0 +1,23 @@
73837 +#include <linux/kernel.h>
73838 +#include <linux/sched.h>
73839 +#include <linux/grsecurity.h>
73840 +#include <linux/grinternal.h>
73841 +#include <linux/errno.h>
73842 +
73843 +void
73844 +gr_log_forkfail(const int retval)
73845 +{
73846 +#ifdef CONFIG_GRKERNSEC_FORKFAIL
73847 + if (grsec_enable_forkfail && (retval == -EAGAIN || retval == -ENOMEM)) {
73848 + switch (retval) {
73849 + case -EAGAIN:
73850 + gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "EAGAIN");
73851 + break;
73852 + case -ENOMEM:
73853 + gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "ENOMEM");
73854 + break;
73855 + }
73856 + }
73857 +#endif
73858 + return;
73859 +}
73860 diff --git a/grsecurity/grsec_init.c b/grsecurity/grsec_init.c
73861 new file mode 100644
73862 index 0000000..ae6c028
73863 --- /dev/null
73864 +++ b/grsecurity/grsec_init.c
73865 @@ -0,0 +1,272 @@
73866 +#include <linux/kernel.h>
73867 +#include <linux/sched.h>
73868 +#include <linux/mm.h>
73869 +#include <linux/gracl.h>
73870 +#include <linux/slab.h>
73871 +#include <linux/vmalloc.h>
73872 +#include <linux/percpu.h>
73873 +#include <linux/module.h>
73874 +
73875 +int grsec_enable_ptrace_readexec;
73876 +int grsec_enable_setxid;
73877 +int grsec_enable_symlinkown;
73878 +kgid_t grsec_symlinkown_gid;
73879 +int grsec_enable_brute;
73880 +int grsec_enable_link;
73881 +int grsec_enable_dmesg;
73882 +int grsec_enable_harden_ptrace;
73883 +int grsec_enable_harden_ipc;
73884 +int grsec_enable_fifo;
73885 +int grsec_enable_execlog;
73886 +int grsec_enable_signal;
73887 +int grsec_enable_forkfail;
73888 +int grsec_enable_audit_ptrace;
73889 +int grsec_enable_time;
73890 +int grsec_enable_group;
73891 +kgid_t grsec_audit_gid;
73892 +int grsec_enable_chdir;
73893 +int grsec_enable_mount;
73894 +int grsec_enable_rofs;
73895 +int grsec_deny_new_usb;
73896 +int grsec_enable_chroot_findtask;
73897 +int grsec_enable_chroot_mount;
73898 +int grsec_enable_chroot_shmat;
73899 +int grsec_enable_chroot_fchdir;
73900 +int grsec_enable_chroot_double;
73901 +int grsec_enable_chroot_pivot;
73902 +int grsec_enable_chroot_chdir;
73903 +int grsec_enable_chroot_chmod;
73904 +int grsec_enable_chroot_mknod;
73905 +int grsec_enable_chroot_nice;
73906 +int grsec_enable_chroot_execlog;
73907 +int grsec_enable_chroot_caps;
73908 +int grsec_enable_chroot_sysctl;
73909 +int grsec_enable_chroot_unix;
73910 +int grsec_enable_tpe;
73911 +kgid_t grsec_tpe_gid;
73912 +int grsec_enable_blackhole;
73913 +#ifdef CONFIG_IPV6_MODULE
73914 +EXPORT_SYMBOL_GPL(grsec_enable_blackhole);
73915 +#endif
73916 +int grsec_lastack_retries;
73917 +int grsec_enable_tpe_all;
73918 +int grsec_enable_tpe_invert;
73919 +int grsec_enable_socket_all;
73920 +kgid_t grsec_socket_all_gid;
73921 +int grsec_enable_socket_client;
73922 +kgid_t grsec_socket_client_gid;
73923 +int grsec_enable_socket_server;
73924 +kgid_t grsec_socket_server_gid;
73925 +int grsec_resource_logging;
73926 +int grsec_disable_privio;
73927 +int grsec_enable_log_rwxmaps;
73928 +int grsec_lock;
73929 +
73930 +DEFINE_SPINLOCK(grsec_alert_lock);
73931 +unsigned long grsec_alert_wtime = 0;
73932 +unsigned long grsec_alert_fyet = 0;
73933 +
73934 +DEFINE_SPINLOCK(grsec_audit_lock);
73935 +
73936 +DEFINE_RWLOCK(grsec_exec_file_lock);
73937 +
73938 +char *gr_shared_page[4];
73939 +
73940 +char *gr_alert_log_fmt;
73941 +char *gr_audit_log_fmt;
73942 +char *gr_alert_log_buf;
73943 +char *gr_audit_log_buf;
73944 +
73945 +void __init
73946 +grsecurity_init(void)
73947 +{
73948 + int j;
73949 + /* create the per-cpu shared pages */
73950 +
73951 +#ifdef CONFIG_X86
73952 + memset((char *)(0x41a + PAGE_OFFSET), 0, 36);
73953 +#endif
73954 +
73955 + for (j = 0; j < 4; j++) {
73956 + gr_shared_page[j] = (char *)__alloc_percpu(PAGE_SIZE, __alignof__(unsigned long long));
73957 + if (gr_shared_page[j] == NULL) {
73958 + panic("Unable to allocate grsecurity shared page");
73959 + return;
73960 + }
73961 + }
73962 +
73963 + /* allocate log buffers */
73964 + gr_alert_log_fmt = kmalloc(512, GFP_KERNEL);
73965 + if (!gr_alert_log_fmt) {
73966 + panic("Unable to allocate grsecurity alert log format buffer");
73967 + return;
73968 + }
73969 + gr_audit_log_fmt = kmalloc(512, GFP_KERNEL);
73970 + if (!gr_audit_log_fmt) {
73971 + panic("Unable to allocate grsecurity audit log format buffer");
73972 + return;
73973 + }
73974 + gr_alert_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
73975 + if (!gr_alert_log_buf) {
73976 + panic("Unable to allocate grsecurity alert log buffer");
73977 + return;
73978 + }
73979 + gr_audit_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
73980 + if (!gr_audit_log_buf) {
73981 + panic("Unable to allocate grsecurity audit log buffer");
73982 + return;
73983 + }
73984 +
73985 +#ifdef CONFIG_GRKERNSEC_IO
73986 +#if !defined(CONFIG_GRKERNSEC_SYSCTL_DISTRO)
73987 + grsec_disable_privio = 1;
73988 +#elif defined(CONFIG_GRKERNSEC_SYSCTL_ON)
73989 + grsec_disable_privio = 1;
73990 +#else
73991 + grsec_disable_privio = 0;
73992 +#endif
73993 +#endif
73994 +
73995 +#ifdef CONFIG_GRKERNSEC_TPE_INVERT
73996 + /* for backward compatibility, tpe_invert always defaults to on if
73997 + enabled in the kernel
73998 + */
73999 + grsec_enable_tpe_invert = 1;
74000 +#endif
74001 +
74002 +#if !defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_SYSCTL_ON)
74003 +#ifndef CONFIG_GRKERNSEC_SYSCTL
74004 + grsec_lock = 1;
74005 +#endif
74006 +
74007 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
74008 + grsec_enable_log_rwxmaps = 1;
74009 +#endif
74010 +#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
74011 + grsec_enable_group = 1;
74012 + grsec_audit_gid = KGIDT_INIT(CONFIG_GRKERNSEC_AUDIT_GID);
74013 +#endif
74014 +#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
74015 + grsec_enable_ptrace_readexec = 1;
74016 +#endif
74017 +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
74018 + grsec_enable_chdir = 1;
74019 +#endif
74020 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
74021 + grsec_enable_harden_ptrace = 1;
74022 +#endif
74023 +#ifdef CONFIG_GRKERNSEC_HARDEN_IPC
74024 + grsec_enable_harden_ipc = 1;
74025 +#endif
74026 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
74027 + grsec_enable_mount = 1;
74028 +#endif
74029 +#ifdef CONFIG_GRKERNSEC_LINK
74030 + grsec_enable_link = 1;
74031 +#endif
74032 +#ifdef CONFIG_GRKERNSEC_BRUTE
74033 + grsec_enable_brute = 1;
74034 +#endif
74035 +#ifdef CONFIG_GRKERNSEC_DMESG
74036 + grsec_enable_dmesg = 1;
74037 +#endif
74038 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
74039 + grsec_enable_blackhole = 1;
74040 + grsec_lastack_retries = 4;
74041 +#endif
74042 +#ifdef CONFIG_GRKERNSEC_FIFO
74043 + grsec_enable_fifo = 1;
74044 +#endif
74045 +#ifdef CONFIG_GRKERNSEC_EXECLOG
74046 + grsec_enable_execlog = 1;
74047 +#endif
74048 +#ifdef CONFIG_GRKERNSEC_SETXID
74049 + grsec_enable_setxid = 1;
74050 +#endif
74051 +#ifdef CONFIG_GRKERNSEC_SIGNAL
74052 + grsec_enable_signal = 1;
74053 +#endif
74054 +#ifdef CONFIG_GRKERNSEC_FORKFAIL
74055 + grsec_enable_forkfail = 1;
74056 +#endif
74057 +#ifdef CONFIG_GRKERNSEC_TIME
74058 + grsec_enable_time = 1;
74059 +#endif
74060 +#ifdef CONFIG_GRKERNSEC_RESLOG
74061 + grsec_resource_logging = 1;
74062 +#endif
74063 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
74064 + grsec_enable_chroot_findtask = 1;
74065 +#endif
74066 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
74067 + grsec_enable_chroot_unix = 1;
74068 +#endif
74069 +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
74070 + grsec_enable_chroot_mount = 1;
74071 +#endif
74072 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
74073 + grsec_enable_chroot_fchdir = 1;
74074 +#endif
74075 +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
74076 + grsec_enable_chroot_shmat = 1;
74077 +#endif
74078 +#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
74079 + grsec_enable_audit_ptrace = 1;
74080 +#endif
74081 +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
74082 + grsec_enable_chroot_double = 1;
74083 +#endif
74084 +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
74085 + grsec_enable_chroot_pivot = 1;
74086 +#endif
74087 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
74088 + grsec_enable_chroot_chdir = 1;
74089 +#endif
74090 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
74091 + grsec_enable_chroot_chmod = 1;
74092 +#endif
74093 +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
74094 + grsec_enable_chroot_mknod = 1;
74095 +#endif
74096 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
74097 + grsec_enable_chroot_nice = 1;
74098 +#endif
74099 +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
74100 + grsec_enable_chroot_execlog = 1;
74101 +#endif
74102 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
74103 + grsec_enable_chroot_caps = 1;
74104 +#endif
74105 +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
74106 + grsec_enable_chroot_sysctl = 1;
74107 +#endif
74108 +#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
74109 + grsec_enable_symlinkown = 1;
74110 + grsec_symlinkown_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SYMLINKOWN_GID);
74111 +#endif
74112 +#ifdef CONFIG_GRKERNSEC_TPE
74113 + grsec_enable_tpe = 1;
74114 + grsec_tpe_gid = KGIDT_INIT(CONFIG_GRKERNSEC_TPE_GID);
74115 +#ifdef CONFIG_GRKERNSEC_TPE_ALL
74116 + grsec_enable_tpe_all = 1;
74117 +#endif
74118 +#endif
74119 +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
74120 + grsec_enable_socket_all = 1;
74121 + grsec_socket_all_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_ALL_GID);
74122 +#endif
74123 +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
74124 + grsec_enable_socket_client = 1;
74125 + grsec_socket_client_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_CLIENT_GID);
74126 +#endif
74127 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
74128 + grsec_enable_socket_server = 1;
74129 + grsec_socket_server_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_SERVER_GID);
74130 +#endif
74131 +#endif
74132 +#ifdef CONFIG_GRKERNSEC_DENYUSB_FORCE
74133 + grsec_deny_new_usb = 1;
74134 +#endif
74135 +
74136 + return;
74137 +}
74138 diff --git a/grsecurity/grsec_ipc.c b/grsecurity/grsec_ipc.c
74139 new file mode 100644
74140 index 0000000..1773300
74141 --- /dev/null
74142 +++ b/grsecurity/grsec_ipc.c
74143 @@ -0,0 +1,48 @@
74144 +#include <linux/kernel.h>
74145 +#include <linux/mm.h>
74146 +#include <linux/sched.h>
74147 +#include <linux/file.h>
74148 +#include <linux/ipc.h>
74149 +#include <linux/ipc_namespace.h>
74150 +#include <linux/grsecurity.h>
74151 +#include <linux/grinternal.h>
74152 +
74153 +int
74154 +gr_ipc_permitted(struct ipc_namespace *ns, struct kern_ipc_perm *ipcp, int requested_mode, int granted_mode)
74155 +{
74156 +#ifdef CONFIG_GRKERNSEC_HARDEN_IPC
74157 + int write;
74158 + int orig_granted_mode;
74159 + kuid_t euid;
74160 + kgid_t egid;
74161 +
74162 + if (!grsec_enable_harden_ipc)
74163 + return 1;
74164 +
74165 + euid = current_euid();
74166 + egid = current_egid();
74167 +
74168 + write = requested_mode & 00002;
74169 + orig_granted_mode = ipcp->mode;
74170 +
74171 + if (uid_eq(euid, ipcp->cuid) || uid_eq(euid, ipcp->uid))
74172 + orig_granted_mode >>= 6;
74173 + else {
74174 + /* if likely wrong permissions, lock to user */
74175 + if (orig_granted_mode & 0007)
74176 + orig_granted_mode = 0;
74177 + /* otherwise do a egid-only check */
74178 + else if (gid_eq(egid, ipcp->cgid) || gid_eq(egid, ipcp->gid))
74179 + orig_granted_mode >>= 3;
74180 + /* otherwise, no access */
74181 + else
74182 + orig_granted_mode = 0;
74183 + }
74184 + if (!(requested_mode & ~granted_mode & 0007) && (requested_mode & ~orig_granted_mode & 0007) &&
74185 + !ns_capable_nolog(ns->user_ns, CAP_IPC_OWNER)) {
74186 + gr_log_str_int(GR_DONT_AUDIT, GR_IPC_DENIED_MSG, write ? "write" : "read", GR_GLOBAL_UID(ipcp->cuid));
74187 + return 0;
74188 + }
74189 +#endif
74190 + return 1;
74191 +}
74192 diff --git a/grsecurity/grsec_link.c b/grsecurity/grsec_link.c
74193 new file mode 100644
74194 index 0000000..5e05e20
74195 --- /dev/null
74196 +++ b/grsecurity/grsec_link.c
74197 @@ -0,0 +1,58 @@
74198 +#include <linux/kernel.h>
74199 +#include <linux/sched.h>
74200 +#include <linux/fs.h>
74201 +#include <linux/file.h>
74202 +#include <linux/grinternal.h>
74203 +
74204 +int gr_handle_symlink_owner(const struct path *link, const struct inode *target)
74205 +{
74206 +#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
74207 + const struct inode *link_inode = link->dentry->d_inode;
74208 +
74209 + if (grsec_enable_symlinkown && in_group_p(grsec_symlinkown_gid) &&
74210 + /* ignore root-owned links, e.g. /proc/self */
74211 + gr_is_global_nonroot(link_inode->i_uid) && target &&
74212 + !uid_eq(link_inode->i_uid, target->i_uid)) {
74213 + gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINKOWNER_MSG, link->dentry, link->mnt, link_inode->i_uid, target->i_uid);
74214 + return 1;
74215 + }
74216 +#endif
74217 + return 0;
74218 +}
74219 +
74220 +int
74221 +gr_handle_follow_link(const struct inode *parent,
74222 + const struct inode *inode,
74223 + const struct dentry *dentry, const struct vfsmount *mnt)
74224 +{
74225 +#ifdef CONFIG_GRKERNSEC_LINK
74226 + const struct cred *cred = current_cred();
74227 +
74228 + if (grsec_enable_link && S_ISLNK(inode->i_mode) &&
74229 + (parent->i_mode & S_ISVTX) && !uid_eq(parent->i_uid, inode->i_uid) &&
74230 + (parent->i_mode & S_IWOTH) && !uid_eq(cred->fsuid, inode->i_uid)) {
74231 + gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid);
74232 + return -EACCES;
74233 + }
74234 +#endif
74235 + return 0;
74236 +}
74237 +
74238 +int
74239 +gr_handle_hardlink(const struct dentry *dentry,
74240 + const struct vfsmount *mnt,
74241 + struct inode *inode, const int mode, const struct filename *to)
74242 +{
74243 +#ifdef CONFIG_GRKERNSEC_LINK
74244 + const struct cred *cred = current_cred();
74245 +
74246 + if (grsec_enable_link && !uid_eq(cred->fsuid, inode->i_uid) &&
74247 + (!S_ISREG(mode) || is_privileged_binary(dentry) ||
74248 + (inode_permission(inode, MAY_READ | MAY_WRITE))) &&
74249 + !capable(CAP_FOWNER) && gr_is_global_nonroot(cred->uid)) {
74250 + gr_log_fs_int2_str(GR_DONT_AUDIT, GR_HARDLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid, to->name);
74251 + return -EPERM;
74252 + }
74253 +#endif
74254 + return 0;
74255 +}
74256 diff --git a/grsecurity/grsec_log.c b/grsecurity/grsec_log.c
74257 new file mode 100644
74258 index 0000000..dbe0a6b
74259 --- /dev/null
74260 +++ b/grsecurity/grsec_log.c
74261 @@ -0,0 +1,341 @@
74262 +#include <linux/kernel.h>
74263 +#include <linux/sched.h>
74264 +#include <linux/file.h>
74265 +#include <linux/tty.h>
74266 +#include <linux/fs.h>
74267 +#include <linux/mm.h>
74268 +#include <linux/grinternal.h>
74269 +
74270 +#ifdef CONFIG_TREE_PREEMPT_RCU
74271 +#define DISABLE_PREEMPT() preempt_disable()
74272 +#define ENABLE_PREEMPT() preempt_enable()
74273 +#else
74274 +#define DISABLE_PREEMPT()
74275 +#define ENABLE_PREEMPT()
74276 +#endif
74277 +
74278 +#define BEGIN_LOCKS(x) \
74279 + DISABLE_PREEMPT(); \
74280 + rcu_read_lock(); \
74281 + read_lock(&tasklist_lock); \
74282 + read_lock(&grsec_exec_file_lock); \
74283 + if (x != GR_DO_AUDIT) \
74284 + spin_lock(&grsec_alert_lock); \
74285 + else \
74286 + spin_lock(&grsec_audit_lock)
74287 +
74288 +#define END_LOCKS(x) \
74289 + if (x != GR_DO_AUDIT) \
74290 + spin_unlock(&grsec_alert_lock); \
74291 + else \
74292 + spin_unlock(&grsec_audit_lock); \
74293 + read_unlock(&grsec_exec_file_lock); \
74294 + read_unlock(&tasklist_lock); \
74295 + rcu_read_unlock(); \
74296 + ENABLE_PREEMPT(); \
74297 + if (x == GR_DONT_AUDIT) \
74298 + gr_handle_alertkill(current)
74299 +
74300 +enum {
74301 + FLOODING,
74302 + NO_FLOODING
74303 +};
74304 +
74305 +extern char *gr_alert_log_fmt;
74306 +extern char *gr_audit_log_fmt;
74307 +extern char *gr_alert_log_buf;
74308 +extern char *gr_audit_log_buf;
74309 +
74310 +static int gr_log_start(int audit)
74311 +{
74312 + char *loglevel = (audit == GR_DO_AUDIT) ? KERN_INFO : KERN_ALERT;
74313 + char *fmt = (audit == GR_DO_AUDIT) ? gr_audit_log_fmt : gr_alert_log_fmt;
74314 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
74315 +#if (CONFIG_GRKERNSEC_FLOODTIME > 0 && CONFIG_GRKERNSEC_FLOODBURST > 0)
74316 + unsigned long curr_secs = get_seconds();
74317 +
74318 + if (audit == GR_DO_AUDIT)
74319 + goto set_fmt;
74320 +
74321 + if (!grsec_alert_wtime || time_after(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)) {
74322 + grsec_alert_wtime = curr_secs;
74323 + grsec_alert_fyet = 0;
74324 + } else if (time_before_eq(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)
74325 + && (grsec_alert_fyet < CONFIG_GRKERNSEC_FLOODBURST)) {
74326 + grsec_alert_fyet++;
74327 + } else if (grsec_alert_fyet == CONFIG_GRKERNSEC_FLOODBURST) {
74328 + grsec_alert_wtime = curr_secs;
74329 + grsec_alert_fyet++;
74330 + printk(KERN_ALERT "grsec: more alerts, logging disabled for %d seconds\n", CONFIG_GRKERNSEC_FLOODTIME);
74331 + return FLOODING;
74332 + }
74333 + else return FLOODING;
74334 +
74335 +set_fmt:
74336 +#endif
74337 + memset(buf, 0, PAGE_SIZE);
74338 + if (current->signal->curr_ip && gr_acl_is_enabled()) {
74339 + sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: (%.64s:%c:%.950s) ");
74340 + snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
74341 + } else if (current->signal->curr_ip) {
74342 + sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: ");
74343 + snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip);
74344 + } else if (gr_acl_is_enabled()) {
74345 + sprintf(fmt, "%s%s", loglevel, "grsec: (%.64s:%c:%.950s) ");
74346 + snprintf(buf, PAGE_SIZE - 1, fmt, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
74347 + } else {
74348 + sprintf(fmt, "%s%s", loglevel, "grsec: ");
74349 + strcpy(buf, fmt);
74350 + }
74351 +
74352 + return NO_FLOODING;
74353 +}
74354 +
74355 +static void gr_log_middle(int audit, const char *msg, va_list ap)
74356 + __attribute__ ((format (printf, 2, 0)));
74357 +
74358 +static void gr_log_middle(int audit, const char *msg, va_list ap)
74359 +{
74360 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
74361 + unsigned int len = strlen(buf);
74362 +
74363 + vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
74364 +
74365 + return;
74366 +}
74367 +
74368 +static void gr_log_middle_varargs(int audit, const char *msg, ...)
74369 + __attribute__ ((format (printf, 2, 3)));
74370 +
74371 +static void gr_log_middle_varargs(int audit, const char *msg, ...)
74372 +{
74373 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
74374 + unsigned int len = strlen(buf);
74375 + va_list ap;
74376 +
74377 + va_start(ap, msg);
74378 + vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
74379 + va_end(ap);
74380 +
74381 + return;
74382 +}
74383 +
74384 +static void gr_log_end(int audit, int append_default)
74385 +{
74386 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
74387 + if (append_default) {
74388 + struct task_struct *task = current;
74389 + struct task_struct *parent = task->real_parent;
74390 + const struct cred *cred = __task_cred(task);
74391 + const struct cred *pcred = __task_cred(parent);
74392 + unsigned int len = strlen(buf);
74393 +
74394 + 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));
74395 + }
74396 +
74397 + printk("%s\n", buf);
74398 +
74399 + return;
74400 +}
74401 +
74402 +void gr_log_varargs(int audit, const char *msg, int argtypes, ...)
74403 +{
74404 + int logtype;
74405 + char *result = (audit == GR_DO_AUDIT) ? "successful" : "denied";
74406 + char *str1 = NULL, *str2 = NULL, *str3 = NULL;
74407 + void *voidptr = NULL;
74408 + int num1 = 0, num2 = 0;
74409 + unsigned long ulong1 = 0, ulong2 = 0;
74410 + struct dentry *dentry = NULL;
74411 + struct vfsmount *mnt = NULL;
74412 + struct file *file = NULL;
74413 + struct task_struct *task = NULL;
74414 + struct vm_area_struct *vma = NULL;
74415 + const struct cred *cred, *pcred;
74416 + va_list ap;
74417 +
74418 + BEGIN_LOCKS(audit);
74419 + logtype = gr_log_start(audit);
74420 + if (logtype == FLOODING) {
74421 + END_LOCKS(audit);
74422 + return;
74423 + }
74424 + va_start(ap, argtypes);
74425 + switch (argtypes) {
74426 + case GR_TTYSNIFF:
74427 + task = va_arg(ap, struct task_struct *);
74428 + 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));
74429 + break;
74430 + case GR_SYSCTL_HIDDEN:
74431 + str1 = va_arg(ap, char *);
74432 + gr_log_middle_varargs(audit, msg, result, str1);
74433 + break;
74434 + case GR_RBAC:
74435 + dentry = va_arg(ap, struct dentry *);
74436 + mnt = va_arg(ap, struct vfsmount *);
74437 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt));
74438 + break;
74439 + case GR_RBAC_STR:
74440 + dentry = va_arg(ap, struct dentry *);
74441 + mnt = va_arg(ap, struct vfsmount *);
74442 + str1 = va_arg(ap, char *);
74443 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1);
74444 + break;
74445 + case GR_STR_RBAC:
74446 + str1 = va_arg(ap, char *);
74447 + dentry = va_arg(ap, struct dentry *);
74448 + mnt = va_arg(ap, struct vfsmount *);
74449 + gr_log_middle_varargs(audit, msg, result, str1, gr_to_filename(dentry, mnt));
74450 + break;
74451 + case GR_RBAC_MODE2:
74452 + dentry = va_arg(ap, struct dentry *);
74453 + mnt = va_arg(ap, struct vfsmount *);
74454 + str1 = va_arg(ap, char *);
74455 + str2 = va_arg(ap, char *);
74456 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2);
74457 + break;
74458 + case GR_RBAC_MODE3:
74459 + dentry = va_arg(ap, struct dentry *);
74460 + mnt = va_arg(ap, struct vfsmount *);
74461 + str1 = va_arg(ap, char *);
74462 + str2 = va_arg(ap, char *);
74463 + str3 = va_arg(ap, char *);
74464 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2, str3);
74465 + break;
74466 + case GR_FILENAME:
74467 + dentry = va_arg(ap, struct dentry *);
74468 + mnt = va_arg(ap, struct vfsmount *);
74469 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt));
74470 + break;
74471 + case GR_STR_FILENAME:
74472 + str1 = va_arg(ap, char *);
74473 + dentry = va_arg(ap, struct dentry *);
74474 + mnt = va_arg(ap, struct vfsmount *);
74475 + gr_log_middle_varargs(audit, msg, str1, gr_to_filename(dentry, mnt));
74476 + break;
74477 + case GR_FILENAME_STR:
74478 + dentry = va_arg(ap, struct dentry *);
74479 + mnt = va_arg(ap, struct vfsmount *);
74480 + str1 = va_arg(ap, char *);
74481 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), str1);
74482 + break;
74483 + case GR_FILENAME_TWO_INT:
74484 + dentry = va_arg(ap, struct dentry *);
74485 + mnt = va_arg(ap, struct vfsmount *);
74486 + num1 = va_arg(ap, int);
74487 + num2 = va_arg(ap, int);
74488 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2);
74489 + break;
74490 + case GR_FILENAME_TWO_INT_STR:
74491 + dentry = va_arg(ap, struct dentry *);
74492 + mnt = va_arg(ap, struct vfsmount *);
74493 + num1 = va_arg(ap, int);
74494 + num2 = va_arg(ap, int);
74495 + str1 = va_arg(ap, char *);
74496 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2, str1);
74497 + break;
74498 + case GR_TEXTREL:
74499 + file = va_arg(ap, struct file *);
74500 + ulong1 = va_arg(ap, unsigned long);
74501 + ulong2 = va_arg(ap, unsigned long);
74502 + gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>", ulong1, ulong2);
74503 + break;
74504 + case GR_PTRACE:
74505 + task = va_arg(ap, struct task_struct *);
74506 + 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));
74507 + break;
74508 + case GR_RESOURCE:
74509 + task = va_arg(ap, struct task_struct *);
74510 + cred = __task_cred(task);
74511 + pcred = __task_cred(task->real_parent);
74512 + ulong1 = va_arg(ap, unsigned long);
74513 + str1 = va_arg(ap, char *);
74514 + ulong2 = va_arg(ap, unsigned long);
74515 + 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));
74516 + break;
74517 + case GR_CAP:
74518 + task = va_arg(ap, struct task_struct *);
74519 + cred = __task_cred(task);
74520 + pcred = __task_cred(task->real_parent);
74521 + str1 = va_arg(ap, char *);
74522 + 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));
74523 + break;
74524 + case GR_SIG:
74525 + str1 = va_arg(ap, char *);
74526 + voidptr = va_arg(ap, void *);
74527 + gr_log_middle_varargs(audit, msg, str1, voidptr);
74528 + break;
74529 + case GR_SIG2:
74530 + task = va_arg(ap, struct task_struct *);
74531 + cred = __task_cred(task);
74532 + pcred = __task_cred(task->real_parent);
74533 + num1 = va_arg(ap, int);
74534 + 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));
74535 + break;
74536 + case GR_CRASH1:
74537 + task = va_arg(ap, struct task_struct *);
74538 + cred = __task_cred(task);
74539 + pcred = __task_cred(task->real_parent);
74540 + ulong1 = va_arg(ap, unsigned long);
74541 + 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);
74542 + break;
74543 + case GR_CRASH2:
74544 + task = va_arg(ap, struct task_struct *);
74545 + cred = __task_cred(task);
74546 + pcred = __task_cred(task->real_parent);
74547 + ulong1 = va_arg(ap, unsigned long);
74548 + 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);
74549 + break;
74550 + case GR_RWXMAP:
74551 + file = va_arg(ap, struct file *);
74552 + gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>");
74553 + break;
74554 + case GR_RWXMAPVMA:
74555 + vma = va_arg(ap, struct vm_area_struct *);
74556 + if (vma->vm_file)
74557 + str1 = gr_to_filename(vma->vm_file->f_path.dentry, vma->vm_file->f_path.mnt);
74558 + else if (vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP))
74559 + str1 = "<stack>";
74560 + else if (vma->vm_start <= current->mm->brk &&
74561 + vma->vm_end >= current->mm->start_brk)
74562 + str1 = "<heap>";
74563 + else
74564 + str1 = "<anonymous mapping>";
74565 + gr_log_middle_varargs(audit, msg, str1);
74566 + break;
74567 + case GR_PSACCT:
74568 + {
74569 + unsigned int wday, cday;
74570 + __u8 whr, chr;
74571 + __u8 wmin, cmin;
74572 + __u8 wsec, csec;
74573 + char cur_tty[64] = { 0 };
74574 + char parent_tty[64] = { 0 };
74575 +
74576 + task = va_arg(ap, struct task_struct *);
74577 + wday = va_arg(ap, unsigned int);
74578 + cday = va_arg(ap, unsigned int);
74579 + whr = va_arg(ap, int);
74580 + chr = va_arg(ap, int);
74581 + wmin = va_arg(ap, int);
74582 + cmin = va_arg(ap, int);
74583 + wsec = va_arg(ap, int);
74584 + csec = va_arg(ap, int);
74585 + ulong1 = va_arg(ap, unsigned long);
74586 + cred = __task_cred(task);
74587 + pcred = __task_cred(task->real_parent);
74588 +
74589 + 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));
74590 + }
74591 + break;
74592 + default:
74593 + gr_log_middle(audit, msg, ap);
74594 + }
74595 + va_end(ap);
74596 + // these don't need DEFAULTSECARGS printed on the end
74597 + if (argtypes == GR_CRASH1 || argtypes == GR_CRASH2)
74598 + gr_log_end(audit, 0);
74599 + else
74600 + gr_log_end(audit, 1);
74601 + END_LOCKS(audit);
74602 +}
74603 diff --git a/grsecurity/grsec_mem.c b/grsecurity/grsec_mem.c
74604 new file mode 100644
74605 index 0000000..0e39d8c
74606 --- /dev/null
74607 +++ b/grsecurity/grsec_mem.c
74608 @@ -0,0 +1,48 @@
74609 +#include <linux/kernel.h>
74610 +#include <linux/sched.h>
74611 +#include <linux/mm.h>
74612 +#include <linux/mman.h>
74613 +#include <linux/module.h>
74614 +#include <linux/grinternal.h>
74615 +
74616 +void gr_handle_msr_write(void)
74617 +{
74618 + gr_log_noargs(GR_DONT_AUDIT, GR_MSRWRITE_MSG);
74619 + return;
74620 +}
74621 +EXPORT_SYMBOL_GPL(gr_handle_msr_write);
74622 +
74623 +void
74624 +gr_handle_ioperm(void)
74625 +{
74626 + gr_log_noargs(GR_DONT_AUDIT, GR_IOPERM_MSG);
74627 + return;
74628 +}
74629 +
74630 +void
74631 +gr_handle_iopl(void)
74632 +{
74633 + gr_log_noargs(GR_DONT_AUDIT, GR_IOPL_MSG);
74634 + return;
74635 +}
74636 +
74637 +void
74638 +gr_handle_mem_readwrite(u64 from, u64 to)
74639 +{
74640 + gr_log_two_u64(GR_DONT_AUDIT, GR_MEM_READWRITE_MSG, from, to);
74641 + return;
74642 +}
74643 +
74644 +void
74645 +gr_handle_vm86(void)
74646 +{
74647 + gr_log_noargs(GR_DONT_AUDIT, GR_VM86_MSG);
74648 + return;
74649 +}
74650 +
74651 +void
74652 +gr_log_badprocpid(const char *entry)
74653 +{
74654 + gr_log_str(GR_DONT_AUDIT, GR_BADPROCPID_MSG, entry);
74655 + return;
74656 +}
74657 diff --git a/grsecurity/grsec_mount.c b/grsecurity/grsec_mount.c
74658 new file mode 100644
74659 index 0000000..cd9e124
74660 --- /dev/null
74661 +++ b/grsecurity/grsec_mount.c
74662 @@ -0,0 +1,65 @@
74663 +#include <linux/kernel.h>
74664 +#include <linux/sched.h>
74665 +#include <linux/mount.h>
74666 +#include <linux/major.h>
74667 +#include <linux/grsecurity.h>
74668 +#include <linux/grinternal.h>
74669 +
74670 +void
74671 +gr_log_remount(const char *devname, const int retval)
74672 +{
74673 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
74674 + if (grsec_enable_mount && (retval >= 0))
74675 + gr_log_str(GR_DO_AUDIT, GR_REMOUNT_AUDIT_MSG, devname ? devname : "none");
74676 +#endif
74677 + return;
74678 +}
74679 +
74680 +void
74681 +gr_log_unmount(const char *devname, const int retval)
74682 +{
74683 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
74684 + if (grsec_enable_mount && (retval >= 0))
74685 + gr_log_str(GR_DO_AUDIT, GR_UNMOUNT_AUDIT_MSG, devname ? devname : "none");
74686 +#endif
74687 + return;
74688 +}
74689 +
74690 +void
74691 +gr_log_mount(const char *from, const char *to, const int retval)
74692 +{
74693 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
74694 + if (grsec_enable_mount && (retval >= 0))
74695 + gr_log_str_str(GR_DO_AUDIT, GR_MOUNT_AUDIT_MSG, from ? from : "none", to);
74696 +#endif
74697 + return;
74698 +}
74699 +
74700 +int
74701 +gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags)
74702 +{
74703 +#ifdef CONFIG_GRKERNSEC_ROFS
74704 + if (grsec_enable_rofs && !(mnt_flags & MNT_READONLY)) {
74705 + gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_MOUNT_MSG, dentry, mnt);
74706 + return -EPERM;
74707 + } else
74708 + return 0;
74709 +#endif
74710 + return 0;
74711 +}
74712 +
74713 +int
74714 +gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode)
74715 +{
74716 +#ifdef CONFIG_GRKERNSEC_ROFS
74717 + struct inode *inode = dentry->d_inode;
74718 +
74719 + if (grsec_enable_rofs && (acc_mode & MAY_WRITE) &&
74720 + inode && (S_ISBLK(inode->i_mode) || (S_ISCHR(inode->i_mode) && imajor(inode) == RAW_MAJOR))) {
74721 + gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_BLOCKWRITE_MSG, dentry, mnt);
74722 + return -EPERM;
74723 + } else
74724 + return 0;
74725 +#endif
74726 + return 0;
74727 +}
74728 diff --git a/grsecurity/grsec_pax.c b/grsecurity/grsec_pax.c
74729 new file mode 100644
74730 index 0000000..6ee9d50
74731 --- /dev/null
74732 +++ b/grsecurity/grsec_pax.c
74733 @@ -0,0 +1,45 @@
74734 +#include <linux/kernel.h>
74735 +#include <linux/sched.h>
74736 +#include <linux/mm.h>
74737 +#include <linux/file.h>
74738 +#include <linux/grinternal.h>
74739 +#include <linux/grsecurity.h>
74740 +
74741 +void
74742 +gr_log_textrel(struct vm_area_struct * vma)
74743 +{
74744 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
74745 + if (grsec_enable_log_rwxmaps)
74746 + gr_log_textrel_ulong_ulong(GR_DONT_AUDIT, GR_TEXTREL_AUDIT_MSG, vma->vm_file, vma->vm_start, vma->vm_pgoff);
74747 +#endif
74748 + return;
74749 +}
74750 +
74751 +void gr_log_ptgnustack(struct file *file)
74752 +{
74753 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
74754 + if (grsec_enable_log_rwxmaps)
74755 + gr_log_rwxmap(GR_DONT_AUDIT, GR_PTGNUSTACK_MSG, file);
74756 +#endif
74757 + return;
74758 +}
74759 +
74760 +void
74761 +gr_log_rwxmmap(struct file *file)
74762 +{
74763 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
74764 + if (grsec_enable_log_rwxmaps)
74765 + gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMMAP_MSG, file);
74766 +#endif
74767 + return;
74768 +}
74769 +
74770 +void
74771 +gr_log_rwxmprotect(struct vm_area_struct *vma)
74772 +{
74773 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
74774 + if (grsec_enable_log_rwxmaps)
74775 + gr_log_rwxmap_vma(GR_DONT_AUDIT, GR_RWXMPROTECT_MSG, vma);
74776 +#endif
74777 + return;
74778 +}
74779 diff --git a/grsecurity/grsec_ptrace.c b/grsecurity/grsec_ptrace.c
74780 new file mode 100644
74781 index 0000000..f7f29aa
74782 --- /dev/null
74783 +++ b/grsecurity/grsec_ptrace.c
74784 @@ -0,0 +1,30 @@
74785 +#include <linux/kernel.h>
74786 +#include <linux/sched.h>
74787 +#include <linux/grinternal.h>
74788 +#include <linux/security.h>
74789 +
74790 +void
74791 +gr_audit_ptrace(struct task_struct *task)
74792 +{
74793 +#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
74794 + if (grsec_enable_audit_ptrace)
74795 + gr_log_ptrace(GR_DO_AUDIT, GR_PTRACE_AUDIT_MSG, task);
74796 +#endif
74797 + return;
74798 +}
74799 +
74800 +int
74801 +gr_ptrace_readexec(struct file *file, int unsafe_flags)
74802 +{
74803 +#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
74804 + const struct dentry *dentry = file->f_path.dentry;
74805 + const struct vfsmount *mnt = file->f_path.mnt;
74806 +
74807 + if (grsec_enable_ptrace_readexec && (unsafe_flags & LSM_UNSAFE_PTRACE) &&
74808 + (inode_permission(dentry->d_inode, MAY_READ) || !gr_acl_handle_open(dentry, mnt, MAY_READ))) {
74809 + gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_READEXEC_MSG, dentry, mnt);
74810 + return -EACCES;
74811 + }
74812 +#endif
74813 + return 0;
74814 +}
74815 diff --git a/grsecurity/grsec_sig.c b/grsecurity/grsec_sig.c
74816 new file mode 100644
74817 index 0000000..3860c7e
74818 --- /dev/null
74819 +++ b/grsecurity/grsec_sig.c
74820 @@ -0,0 +1,236 @@
74821 +#include <linux/kernel.h>
74822 +#include <linux/sched.h>
74823 +#include <linux/fs.h>
74824 +#include <linux/delay.h>
74825 +#include <linux/grsecurity.h>
74826 +#include <linux/grinternal.h>
74827 +#include <linux/hardirq.h>
74828 +
74829 +char *signames[] = {
74830 + [SIGSEGV] = "Segmentation fault",
74831 + [SIGILL] = "Illegal instruction",
74832 + [SIGABRT] = "Abort",
74833 + [SIGBUS] = "Invalid alignment/Bus error"
74834 +};
74835 +
74836 +void
74837 +gr_log_signal(const int sig, const void *addr, const struct task_struct *t)
74838 +{
74839 +#ifdef CONFIG_GRKERNSEC_SIGNAL
74840 + if (grsec_enable_signal && ((sig == SIGSEGV) || (sig == SIGILL) ||
74841 + (sig == SIGABRT) || (sig == SIGBUS))) {
74842 + if (task_pid_nr(t) == task_pid_nr(current)) {
74843 + gr_log_sig_addr(GR_DONT_AUDIT_GOOD, GR_UNISIGLOG_MSG, signames[sig], addr);
74844 + } else {
74845 + gr_log_sig_task(GR_DONT_AUDIT_GOOD, GR_DUALSIGLOG_MSG, t, sig);
74846 + }
74847 + }
74848 +#endif
74849 + return;
74850 +}
74851 +
74852 +int
74853 +gr_handle_signal(const struct task_struct *p, const int sig)
74854 +{
74855 +#ifdef CONFIG_GRKERNSEC
74856 + /* ignore the 0 signal for protected task checks */
74857 + if (task_pid_nr(current) > 1 && sig && gr_check_protected_task(p)) {
74858 + gr_log_sig_task(GR_DONT_AUDIT, GR_SIG_ACL_MSG, p, sig);
74859 + return -EPERM;
74860 + } else if (gr_pid_is_chrooted((struct task_struct *)p)) {
74861 + return -EPERM;
74862 + }
74863 +#endif
74864 + return 0;
74865 +}
74866 +
74867 +#ifdef CONFIG_GRKERNSEC
74868 +extern int specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t);
74869 +
74870 +int gr_fake_force_sig(int sig, struct task_struct *t)
74871 +{
74872 + unsigned long int flags;
74873 + int ret, blocked, ignored;
74874 + struct k_sigaction *action;
74875 +
74876 + spin_lock_irqsave(&t->sighand->siglock, flags);
74877 + action = &t->sighand->action[sig-1];
74878 + ignored = action->sa.sa_handler == SIG_IGN;
74879 + blocked = sigismember(&t->blocked, sig);
74880 + if (blocked || ignored) {
74881 + action->sa.sa_handler = SIG_DFL;
74882 + if (blocked) {
74883 + sigdelset(&t->blocked, sig);
74884 + recalc_sigpending_and_wake(t);
74885 + }
74886 + }
74887 + if (action->sa.sa_handler == SIG_DFL)
74888 + t->signal->flags &= ~SIGNAL_UNKILLABLE;
74889 + ret = specific_send_sig_info(sig, SEND_SIG_PRIV, t);
74890 +
74891 + spin_unlock_irqrestore(&t->sighand->siglock, flags);
74892 +
74893 + return ret;
74894 +}
74895 +#endif
74896 +
74897 +#define GR_USER_BAN_TIME (15 * 60)
74898 +#define GR_DAEMON_BRUTE_TIME (30 * 60)
74899 +
74900 +void gr_handle_brute_attach(int dumpable)
74901 +{
74902 +#ifdef CONFIG_GRKERNSEC_BRUTE
74903 + struct task_struct *p = current;
74904 + kuid_t uid = GLOBAL_ROOT_UID;
74905 + int daemon = 0;
74906 +
74907 + if (!grsec_enable_brute)
74908 + return;
74909 +
74910 + rcu_read_lock();
74911 + read_lock(&tasklist_lock);
74912 + read_lock(&grsec_exec_file_lock);
74913 + if (p->real_parent && gr_is_same_file(p->real_parent->exec_file, p->exec_file)) {
74914 + p->real_parent->brute_expires = get_seconds() + GR_DAEMON_BRUTE_TIME;
74915 + p->real_parent->brute = 1;
74916 + daemon = 1;
74917 + } else {
74918 + const struct cred *cred = __task_cred(p), *cred2;
74919 + struct task_struct *tsk, *tsk2;
74920 +
74921 + if (dumpable != SUID_DUMP_USER && gr_is_global_nonroot(cred->uid)) {
74922 + struct user_struct *user;
74923 +
74924 + uid = cred->uid;
74925 +
74926 + /* this is put upon execution past expiration */
74927 + user = find_user(uid);
74928 + if (user == NULL)
74929 + goto unlock;
74930 + user->suid_banned = 1;
74931 + user->suid_ban_expires = get_seconds() + GR_USER_BAN_TIME;
74932 + if (user->suid_ban_expires == ~0UL)
74933 + user->suid_ban_expires--;
74934 +
74935 + /* only kill other threads of the same binary, from the same user */
74936 + do_each_thread(tsk2, tsk) {
74937 + cred2 = __task_cred(tsk);
74938 + if (tsk != p && uid_eq(cred2->uid, uid) && gr_is_same_file(tsk->exec_file, p->exec_file))
74939 + gr_fake_force_sig(SIGKILL, tsk);
74940 + } while_each_thread(tsk2, tsk);
74941 + }
74942 + }
74943 +unlock:
74944 + read_unlock(&grsec_exec_file_lock);
74945 + read_unlock(&tasklist_lock);
74946 + rcu_read_unlock();
74947 +
74948 + if (gr_is_global_nonroot(uid))
74949 + 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);
74950 + else if (daemon)
74951 + gr_log_noargs(GR_DONT_AUDIT, GR_BRUTE_DAEMON_MSG);
74952 +
74953 +#endif
74954 + return;
74955 +}
74956 +
74957 +void gr_handle_brute_check(void)
74958 +{
74959 +#ifdef CONFIG_GRKERNSEC_BRUTE
74960 + struct task_struct *p = current;
74961 +
74962 + if (unlikely(p->brute)) {
74963 + if (!grsec_enable_brute)
74964 + p->brute = 0;
74965 + else if (time_before(get_seconds(), p->brute_expires))
74966 + msleep(30 * 1000);
74967 + }
74968 +#endif
74969 + return;
74970 +}
74971 +
74972 +void gr_handle_kernel_exploit(void)
74973 +{
74974 +#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
74975 + const struct cred *cred;
74976 + struct task_struct *tsk, *tsk2;
74977 + struct user_struct *user;
74978 + kuid_t uid;
74979 +
74980 + if (in_irq() || in_serving_softirq() || in_nmi())
74981 + panic("grsec: halting the system due to suspicious kernel crash caused in interrupt context");
74982 +
74983 + uid = current_uid();
74984 +
74985 + if (gr_is_global_root(uid))
74986 + panic("grsec: halting the system due to suspicious kernel crash caused by root");
74987 + else {
74988 + /* kill all the processes of this user, hold a reference
74989 + to their creds struct, and prevent them from creating
74990 + another process until system reset
74991 + */
74992 + printk(KERN_ALERT "grsec: banning user with uid %u until system restart for suspicious kernel crash\n",
74993 + GR_GLOBAL_UID(uid));
74994 + /* we intentionally leak this ref */
74995 + user = get_uid(current->cred->user);
74996 + if (user)
74997 + user->kernel_banned = 1;
74998 +
74999 + /* kill all processes of this user */
75000 + read_lock(&tasklist_lock);
75001 + do_each_thread(tsk2, tsk) {
75002 + cred = __task_cred(tsk);
75003 + if (uid_eq(cred->uid, uid))
75004 + gr_fake_force_sig(SIGKILL, tsk);
75005 + } while_each_thread(tsk2, tsk);
75006 + read_unlock(&tasklist_lock);
75007 + }
75008 +#endif
75009 +}
75010 +
75011 +#ifdef CONFIG_GRKERNSEC_BRUTE
75012 +static bool suid_ban_expired(struct user_struct *user)
75013 +{
75014 + if (user->suid_ban_expires != ~0UL && time_after_eq(get_seconds(), user->suid_ban_expires)) {
75015 + user->suid_banned = 0;
75016 + user->suid_ban_expires = 0;
75017 + free_uid(user);
75018 + return true;
75019 + }
75020 +
75021 + return false;
75022 +}
75023 +#endif
75024 +
75025 +int gr_process_kernel_exec_ban(void)
75026 +{
75027 +#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
75028 + if (unlikely(current->cred->user->kernel_banned))
75029 + return -EPERM;
75030 +#endif
75031 + return 0;
75032 +}
75033 +
75034 +int gr_process_kernel_setuid_ban(struct user_struct *user)
75035 +{
75036 +#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
75037 + if (unlikely(user->kernel_banned))
75038 + gr_fake_force_sig(SIGKILL, current);
75039 +#endif
75040 + return 0;
75041 +}
75042 +
75043 +int gr_process_suid_exec_ban(const struct linux_binprm *bprm)
75044 +{
75045 +#ifdef CONFIG_GRKERNSEC_BRUTE
75046 + struct user_struct *user = current->cred->user;
75047 + if (unlikely(user->suid_banned)) {
75048 + if (suid_ban_expired(user))
75049 + return 0;
75050 + /* disallow execution of suid binaries only */
75051 + else if (!uid_eq(bprm->cred->euid, current->cred->uid))
75052 + return -EPERM;
75053 + }
75054 +#endif
75055 + return 0;
75056 +}
75057 diff --git a/grsecurity/grsec_sock.c b/grsecurity/grsec_sock.c
75058 new file mode 100644
75059 index 0000000..c0aef3a
75060 --- /dev/null
75061 +++ b/grsecurity/grsec_sock.c
75062 @@ -0,0 +1,244 @@
75063 +#include <linux/kernel.h>
75064 +#include <linux/module.h>
75065 +#include <linux/sched.h>
75066 +#include <linux/file.h>
75067 +#include <linux/net.h>
75068 +#include <linux/in.h>
75069 +#include <linux/ip.h>
75070 +#include <net/sock.h>
75071 +#include <net/inet_sock.h>
75072 +#include <linux/grsecurity.h>
75073 +#include <linux/grinternal.h>
75074 +#include <linux/gracl.h>
75075 +
75076 +extern int gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb);
75077 +extern int gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr);
75078 +
75079 +EXPORT_SYMBOL_GPL(gr_search_udp_recvmsg);
75080 +EXPORT_SYMBOL_GPL(gr_search_udp_sendmsg);
75081 +
75082 +#ifdef CONFIG_UNIX_MODULE
75083 +EXPORT_SYMBOL_GPL(gr_acl_handle_unix);
75084 +EXPORT_SYMBOL_GPL(gr_acl_handle_mknod);
75085 +EXPORT_SYMBOL_GPL(gr_handle_chroot_unix);
75086 +EXPORT_SYMBOL_GPL(gr_handle_create);
75087 +#endif
75088 +
75089 +#ifdef CONFIG_GRKERNSEC
75090 +#define gr_conn_table_size 32749
75091 +struct conn_table_entry {
75092 + struct conn_table_entry *next;
75093 + struct signal_struct *sig;
75094 +};
75095 +
75096 +struct conn_table_entry *gr_conn_table[gr_conn_table_size];
75097 +DEFINE_SPINLOCK(gr_conn_table_lock);
75098 +
75099 +extern const char * gr_socktype_to_name(unsigned char type);
75100 +extern const char * gr_proto_to_name(unsigned char proto);
75101 +extern const char * gr_sockfamily_to_name(unsigned char family);
75102 +
75103 +static __inline__ int
75104 +conn_hash(__u32 saddr, __u32 daddr, __u16 sport, __u16 dport, unsigned int size)
75105 +{
75106 + return ((daddr + saddr + (sport << 8) + (dport << 16)) % size);
75107 +}
75108 +
75109 +static __inline__ int
75110 +conn_match(const struct signal_struct *sig, __u32 saddr, __u32 daddr,
75111 + __u16 sport, __u16 dport)
75112 +{
75113 + if (unlikely(sig->gr_saddr == saddr && sig->gr_daddr == daddr &&
75114 + sig->gr_sport == sport && sig->gr_dport == dport))
75115 + return 1;
75116 + else
75117 + return 0;
75118 +}
75119 +
75120 +static void gr_add_to_task_ip_table_nolock(struct signal_struct *sig, struct conn_table_entry *newent)
75121 +{
75122 + struct conn_table_entry **match;
75123 + unsigned int index;
75124 +
75125 + index = conn_hash(sig->gr_saddr, sig->gr_daddr,
75126 + sig->gr_sport, sig->gr_dport,
75127 + gr_conn_table_size);
75128 +
75129 + newent->sig = sig;
75130 +
75131 + match = &gr_conn_table[index];
75132 + newent->next = *match;
75133 + *match = newent;
75134 +
75135 + return;
75136 +}
75137 +
75138 +static void gr_del_task_from_ip_table_nolock(struct signal_struct *sig)
75139 +{
75140 + struct conn_table_entry *match, *last = NULL;
75141 + unsigned int index;
75142 +
75143 + index = conn_hash(sig->gr_saddr, sig->gr_daddr,
75144 + sig->gr_sport, sig->gr_dport,
75145 + gr_conn_table_size);
75146 +
75147 + match = gr_conn_table[index];
75148 + while (match && !conn_match(match->sig,
75149 + sig->gr_saddr, sig->gr_daddr, sig->gr_sport,
75150 + sig->gr_dport)) {
75151 + last = match;
75152 + match = match->next;
75153 + }
75154 +
75155 + if (match) {
75156 + if (last)
75157 + last->next = match->next;
75158 + else
75159 + gr_conn_table[index] = NULL;
75160 + kfree(match);
75161 + }
75162 +
75163 + return;
75164 +}
75165 +
75166 +static struct signal_struct * gr_lookup_task_ip_table(__u32 saddr, __u32 daddr,
75167 + __u16 sport, __u16 dport)
75168 +{
75169 + struct conn_table_entry *match;
75170 + unsigned int index;
75171 +
75172 + index = conn_hash(saddr, daddr, sport, dport, gr_conn_table_size);
75173 +
75174 + match = gr_conn_table[index];
75175 + while (match && !conn_match(match->sig, saddr, daddr, sport, dport))
75176 + match = match->next;
75177 +
75178 + if (match)
75179 + return match->sig;
75180 + else
75181 + return NULL;
75182 +}
75183 +
75184 +#endif
75185 +
75186 +void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet)
75187 +{
75188 +#ifdef CONFIG_GRKERNSEC
75189 + struct signal_struct *sig = task->signal;
75190 + struct conn_table_entry *newent;
75191 +
75192 + newent = kmalloc(sizeof(struct conn_table_entry), GFP_ATOMIC);
75193 + if (newent == NULL)
75194 + return;
75195 + /* no bh lock needed since we are called with bh disabled */
75196 + spin_lock(&gr_conn_table_lock);
75197 + gr_del_task_from_ip_table_nolock(sig);
75198 + sig->gr_saddr = inet->inet_rcv_saddr;
75199 + sig->gr_daddr = inet->inet_daddr;
75200 + sig->gr_sport = inet->inet_sport;
75201 + sig->gr_dport = inet->inet_dport;
75202 + gr_add_to_task_ip_table_nolock(sig, newent);
75203 + spin_unlock(&gr_conn_table_lock);
75204 +#endif
75205 + return;
75206 +}
75207 +
75208 +void gr_del_task_from_ip_table(struct task_struct *task)
75209 +{
75210 +#ifdef CONFIG_GRKERNSEC
75211 + spin_lock_bh(&gr_conn_table_lock);
75212 + gr_del_task_from_ip_table_nolock(task->signal);
75213 + spin_unlock_bh(&gr_conn_table_lock);
75214 +#endif
75215 + return;
75216 +}
75217 +
75218 +void
75219 +gr_attach_curr_ip(const struct sock *sk)
75220 +{
75221 +#ifdef CONFIG_GRKERNSEC
75222 + struct signal_struct *p, *set;
75223 + const struct inet_sock *inet = inet_sk(sk);
75224 +
75225 + if (unlikely(sk->sk_protocol != IPPROTO_TCP))
75226 + return;
75227 +
75228 + set = current->signal;
75229 +
75230 + spin_lock_bh(&gr_conn_table_lock);
75231 + p = gr_lookup_task_ip_table(inet->inet_daddr, inet->inet_rcv_saddr,
75232 + inet->inet_dport, inet->inet_sport);
75233 + if (unlikely(p != NULL)) {
75234 + set->curr_ip = p->curr_ip;
75235 + set->used_accept = 1;
75236 + gr_del_task_from_ip_table_nolock(p);
75237 + spin_unlock_bh(&gr_conn_table_lock);
75238 + return;
75239 + }
75240 + spin_unlock_bh(&gr_conn_table_lock);
75241 +
75242 + set->curr_ip = inet->inet_daddr;
75243 + set->used_accept = 1;
75244 +#endif
75245 + return;
75246 +}
75247 +
75248 +int
75249 +gr_handle_sock_all(const int family, const int type, const int protocol)
75250 +{
75251 +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
75252 + if (grsec_enable_socket_all && in_group_p(grsec_socket_all_gid) &&
75253 + (family != AF_UNIX)) {
75254 + if (family == AF_INET)
75255 + gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), gr_proto_to_name(protocol));
75256 + else
75257 + gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), protocol);
75258 + return -EACCES;
75259 + }
75260 +#endif
75261 + return 0;
75262 +}
75263 +
75264 +int
75265 +gr_handle_sock_server(const struct sockaddr *sck)
75266 +{
75267 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
75268 + if (grsec_enable_socket_server &&
75269 + in_group_p(grsec_socket_server_gid) &&
75270 + sck && (sck->sa_family != AF_UNIX) &&
75271 + (sck->sa_family != AF_LOCAL)) {
75272 + gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
75273 + return -EACCES;
75274 + }
75275 +#endif
75276 + return 0;
75277 +}
75278 +
75279 +int
75280 +gr_handle_sock_server_other(const struct sock *sck)
75281 +{
75282 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
75283 + if (grsec_enable_socket_server &&
75284 + in_group_p(grsec_socket_server_gid) &&
75285 + sck && (sck->sk_family != AF_UNIX) &&
75286 + (sck->sk_family != AF_LOCAL)) {
75287 + gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
75288 + return -EACCES;
75289 + }
75290 +#endif
75291 + return 0;
75292 +}
75293 +
75294 +int
75295 +gr_handle_sock_client(const struct sockaddr *sck)
75296 +{
75297 +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
75298 + if (grsec_enable_socket_client && in_group_p(grsec_socket_client_gid) &&
75299 + sck && (sck->sa_family != AF_UNIX) &&
75300 + (sck->sa_family != AF_LOCAL)) {
75301 + gr_log_noargs(GR_DONT_AUDIT, GR_CONNECT_MSG);
75302 + return -EACCES;
75303 + }
75304 +#endif
75305 + return 0;
75306 +}
75307 diff --git a/grsecurity/grsec_sysctl.c b/grsecurity/grsec_sysctl.c
75308 new file mode 100644
75309 index 0000000..8159888
75310 --- /dev/null
75311 +++ b/grsecurity/grsec_sysctl.c
75312 @@ -0,0 +1,479 @@
75313 +#include <linux/kernel.h>
75314 +#include <linux/sched.h>
75315 +#include <linux/sysctl.h>
75316 +#include <linux/grsecurity.h>
75317 +#include <linux/grinternal.h>
75318 +
75319 +int
75320 +gr_handle_sysctl_mod(const char *dirname, const char *name, const int op)
75321 +{
75322 +#ifdef CONFIG_GRKERNSEC_SYSCTL
75323 + if (dirname == NULL || name == NULL)
75324 + return 0;
75325 + if (!strcmp(dirname, "grsecurity") && grsec_lock && (op & MAY_WRITE)) {
75326 + gr_log_str(GR_DONT_AUDIT, GR_SYSCTL_MSG, name);
75327 + return -EACCES;
75328 + }
75329 +#endif
75330 + return 0;
75331 +}
75332 +
75333 +#if defined(CONFIG_GRKERNSEC_ROFS) || defined(CONFIG_GRKERNSEC_DENYUSB)
75334 +static int __maybe_unused __read_only one = 1;
75335 +#endif
75336 +
75337 +#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS) || \
75338 + defined(CONFIG_GRKERNSEC_DENYUSB)
75339 +struct ctl_table grsecurity_table[] = {
75340 +#ifdef CONFIG_GRKERNSEC_SYSCTL
75341 +#ifdef CONFIG_GRKERNSEC_SYSCTL_DISTRO
75342 +#ifdef CONFIG_GRKERNSEC_IO
75343 + {
75344 + .procname = "disable_priv_io",
75345 + .data = &grsec_disable_privio,
75346 + .maxlen = sizeof(int),
75347 + .mode = 0600,
75348 + .proc_handler = &proc_dointvec,
75349 + },
75350 +#endif
75351 +#endif
75352 +#ifdef CONFIG_GRKERNSEC_LINK
75353 + {
75354 + .procname = "linking_restrictions",
75355 + .data = &grsec_enable_link,
75356 + .maxlen = sizeof(int),
75357 + .mode = 0600,
75358 + .proc_handler = &proc_dointvec,
75359 + },
75360 +#endif
75361 +#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
75362 + {
75363 + .procname = "enforce_symlinksifowner",
75364 + .data = &grsec_enable_symlinkown,
75365 + .maxlen = sizeof(int),
75366 + .mode = 0600,
75367 + .proc_handler = &proc_dointvec,
75368 + },
75369 + {
75370 + .procname = "symlinkown_gid",
75371 + .data = &grsec_symlinkown_gid,
75372 + .maxlen = sizeof(int),
75373 + .mode = 0600,
75374 + .proc_handler = &proc_dointvec,
75375 + },
75376 +#endif
75377 +#ifdef CONFIG_GRKERNSEC_BRUTE
75378 + {
75379 + .procname = "deter_bruteforce",
75380 + .data = &grsec_enable_brute,
75381 + .maxlen = sizeof(int),
75382 + .mode = 0600,
75383 + .proc_handler = &proc_dointvec,
75384 + },
75385 +#endif
75386 +#ifdef CONFIG_GRKERNSEC_FIFO
75387 + {
75388 + .procname = "fifo_restrictions",
75389 + .data = &grsec_enable_fifo,
75390 + .maxlen = sizeof(int),
75391 + .mode = 0600,
75392 + .proc_handler = &proc_dointvec,
75393 + },
75394 +#endif
75395 +#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
75396 + {
75397 + .procname = "ptrace_readexec",
75398 + .data = &grsec_enable_ptrace_readexec,
75399 + .maxlen = sizeof(int),
75400 + .mode = 0600,
75401 + .proc_handler = &proc_dointvec,
75402 + },
75403 +#endif
75404 +#ifdef CONFIG_GRKERNSEC_SETXID
75405 + {
75406 + .procname = "consistent_setxid",
75407 + .data = &grsec_enable_setxid,
75408 + .maxlen = sizeof(int),
75409 + .mode = 0600,
75410 + .proc_handler = &proc_dointvec,
75411 + },
75412 +#endif
75413 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
75414 + {
75415 + .procname = "ip_blackhole",
75416 + .data = &grsec_enable_blackhole,
75417 + .maxlen = sizeof(int),
75418 + .mode = 0600,
75419 + .proc_handler = &proc_dointvec,
75420 + },
75421 + {
75422 + .procname = "lastack_retries",
75423 + .data = &grsec_lastack_retries,
75424 + .maxlen = sizeof(int),
75425 + .mode = 0600,
75426 + .proc_handler = &proc_dointvec,
75427 + },
75428 +#endif
75429 +#ifdef CONFIG_GRKERNSEC_EXECLOG
75430 + {
75431 + .procname = "exec_logging",
75432 + .data = &grsec_enable_execlog,
75433 + .maxlen = sizeof(int),
75434 + .mode = 0600,
75435 + .proc_handler = &proc_dointvec,
75436 + },
75437 +#endif
75438 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
75439 + {
75440 + .procname = "rwxmap_logging",
75441 + .data = &grsec_enable_log_rwxmaps,
75442 + .maxlen = sizeof(int),
75443 + .mode = 0600,
75444 + .proc_handler = &proc_dointvec,
75445 + },
75446 +#endif
75447 +#ifdef CONFIG_GRKERNSEC_SIGNAL
75448 + {
75449 + .procname = "signal_logging",
75450 + .data = &grsec_enable_signal,
75451 + .maxlen = sizeof(int),
75452 + .mode = 0600,
75453 + .proc_handler = &proc_dointvec,
75454 + },
75455 +#endif
75456 +#ifdef CONFIG_GRKERNSEC_FORKFAIL
75457 + {
75458 + .procname = "forkfail_logging",
75459 + .data = &grsec_enable_forkfail,
75460 + .maxlen = sizeof(int),
75461 + .mode = 0600,
75462 + .proc_handler = &proc_dointvec,
75463 + },
75464 +#endif
75465 +#ifdef CONFIG_GRKERNSEC_TIME
75466 + {
75467 + .procname = "timechange_logging",
75468 + .data = &grsec_enable_time,
75469 + .maxlen = sizeof(int),
75470 + .mode = 0600,
75471 + .proc_handler = &proc_dointvec,
75472 + },
75473 +#endif
75474 +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
75475 + {
75476 + .procname = "chroot_deny_shmat",
75477 + .data = &grsec_enable_chroot_shmat,
75478 + .maxlen = sizeof(int),
75479 + .mode = 0600,
75480 + .proc_handler = &proc_dointvec,
75481 + },
75482 +#endif
75483 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
75484 + {
75485 + .procname = "chroot_deny_unix",
75486 + .data = &grsec_enable_chroot_unix,
75487 + .maxlen = sizeof(int),
75488 + .mode = 0600,
75489 + .proc_handler = &proc_dointvec,
75490 + },
75491 +#endif
75492 +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
75493 + {
75494 + .procname = "chroot_deny_mount",
75495 + .data = &grsec_enable_chroot_mount,
75496 + .maxlen = sizeof(int),
75497 + .mode = 0600,
75498 + .proc_handler = &proc_dointvec,
75499 + },
75500 +#endif
75501 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
75502 + {
75503 + .procname = "chroot_deny_fchdir",
75504 + .data = &grsec_enable_chroot_fchdir,
75505 + .maxlen = sizeof(int),
75506 + .mode = 0600,
75507 + .proc_handler = &proc_dointvec,
75508 + },
75509 +#endif
75510 +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
75511 + {
75512 + .procname = "chroot_deny_chroot",
75513 + .data = &grsec_enable_chroot_double,
75514 + .maxlen = sizeof(int),
75515 + .mode = 0600,
75516 + .proc_handler = &proc_dointvec,
75517 + },
75518 +#endif
75519 +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
75520 + {
75521 + .procname = "chroot_deny_pivot",
75522 + .data = &grsec_enable_chroot_pivot,
75523 + .maxlen = sizeof(int),
75524 + .mode = 0600,
75525 + .proc_handler = &proc_dointvec,
75526 + },
75527 +#endif
75528 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
75529 + {
75530 + .procname = "chroot_enforce_chdir",
75531 + .data = &grsec_enable_chroot_chdir,
75532 + .maxlen = sizeof(int),
75533 + .mode = 0600,
75534 + .proc_handler = &proc_dointvec,
75535 + },
75536 +#endif
75537 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
75538 + {
75539 + .procname = "chroot_deny_chmod",
75540 + .data = &grsec_enable_chroot_chmod,
75541 + .maxlen = sizeof(int),
75542 + .mode = 0600,
75543 + .proc_handler = &proc_dointvec,
75544 + },
75545 +#endif
75546 +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
75547 + {
75548 + .procname = "chroot_deny_mknod",
75549 + .data = &grsec_enable_chroot_mknod,
75550 + .maxlen = sizeof(int),
75551 + .mode = 0600,
75552 + .proc_handler = &proc_dointvec,
75553 + },
75554 +#endif
75555 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
75556 + {
75557 + .procname = "chroot_restrict_nice",
75558 + .data = &grsec_enable_chroot_nice,
75559 + .maxlen = sizeof(int),
75560 + .mode = 0600,
75561 + .proc_handler = &proc_dointvec,
75562 + },
75563 +#endif
75564 +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
75565 + {
75566 + .procname = "chroot_execlog",
75567 + .data = &grsec_enable_chroot_execlog,
75568 + .maxlen = sizeof(int),
75569 + .mode = 0600,
75570 + .proc_handler = &proc_dointvec,
75571 + },
75572 +#endif
75573 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
75574 + {
75575 + .procname = "chroot_caps",
75576 + .data = &grsec_enable_chroot_caps,
75577 + .maxlen = sizeof(int),
75578 + .mode = 0600,
75579 + .proc_handler = &proc_dointvec,
75580 + },
75581 +#endif
75582 +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
75583 + {
75584 + .procname = "chroot_deny_sysctl",
75585 + .data = &grsec_enable_chroot_sysctl,
75586 + .maxlen = sizeof(int),
75587 + .mode = 0600,
75588 + .proc_handler = &proc_dointvec,
75589 + },
75590 +#endif
75591 +#ifdef CONFIG_GRKERNSEC_TPE
75592 + {
75593 + .procname = "tpe",
75594 + .data = &grsec_enable_tpe,
75595 + .maxlen = sizeof(int),
75596 + .mode = 0600,
75597 + .proc_handler = &proc_dointvec,
75598 + },
75599 + {
75600 + .procname = "tpe_gid",
75601 + .data = &grsec_tpe_gid,
75602 + .maxlen = sizeof(int),
75603 + .mode = 0600,
75604 + .proc_handler = &proc_dointvec,
75605 + },
75606 +#endif
75607 +#ifdef CONFIG_GRKERNSEC_TPE_INVERT
75608 + {
75609 + .procname = "tpe_invert",
75610 + .data = &grsec_enable_tpe_invert,
75611 + .maxlen = sizeof(int),
75612 + .mode = 0600,
75613 + .proc_handler = &proc_dointvec,
75614 + },
75615 +#endif
75616 +#ifdef CONFIG_GRKERNSEC_TPE_ALL
75617 + {
75618 + .procname = "tpe_restrict_all",
75619 + .data = &grsec_enable_tpe_all,
75620 + .maxlen = sizeof(int),
75621 + .mode = 0600,
75622 + .proc_handler = &proc_dointvec,
75623 + },
75624 +#endif
75625 +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
75626 + {
75627 + .procname = "socket_all",
75628 + .data = &grsec_enable_socket_all,
75629 + .maxlen = sizeof(int),
75630 + .mode = 0600,
75631 + .proc_handler = &proc_dointvec,
75632 + },
75633 + {
75634 + .procname = "socket_all_gid",
75635 + .data = &grsec_socket_all_gid,
75636 + .maxlen = sizeof(int),
75637 + .mode = 0600,
75638 + .proc_handler = &proc_dointvec,
75639 + },
75640 +#endif
75641 +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
75642 + {
75643 + .procname = "socket_client",
75644 + .data = &grsec_enable_socket_client,
75645 + .maxlen = sizeof(int),
75646 + .mode = 0600,
75647 + .proc_handler = &proc_dointvec,
75648 + },
75649 + {
75650 + .procname = "socket_client_gid",
75651 + .data = &grsec_socket_client_gid,
75652 + .maxlen = sizeof(int),
75653 + .mode = 0600,
75654 + .proc_handler = &proc_dointvec,
75655 + },
75656 +#endif
75657 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
75658 + {
75659 + .procname = "socket_server",
75660 + .data = &grsec_enable_socket_server,
75661 + .maxlen = sizeof(int),
75662 + .mode = 0600,
75663 + .proc_handler = &proc_dointvec,
75664 + },
75665 + {
75666 + .procname = "socket_server_gid",
75667 + .data = &grsec_socket_server_gid,
75668 + .maxlen = sizeof(int),
75669 + .mode = 0600,
75670 + .proc_handler = &proc_dointvec,
75671 + },
75672 +#endif
75673 +#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
75674 + {
75675 + .procname = "audit_group",
75676 + .data = &grsec_enable_group,
75677 + .maxlen = sizeof(int),
75678 + .mode = 0600,
75679 + .proc_handler = &proc_dointvec,
75680 + },
75681 + {
75682 + .procname = "audit_gid",
75683 + .data = &grsec_audit_gid,
75684 + .maxlen = sizeof(int),
75685 + .mode = 0600,
75686 + .proc_handler = &proc_dointvec,
75687 + },
75688 +#endif
75689 +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
75690 + {
75691 + .procname = "audit_chdir",
75692 + .data = &grsec_enable_chdir,
75693 + .maxlen = sizeof(int),
75694 + .mode = 0600,
75695 + .proc_handler = &proc_dointvec,
75696 + },
75697 +#endif
75698 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
75699 + {
75700 + .procname = "audit_mount",
75701 + .data = &grsec_enable_mount,
75702 + .maxlen = sizeof(int),
75703 + .mode = 0600,
75704 + .proc_handler = &proc_dointvec,
75705 + },
75706 +#endif
75707 +#ifdef CONFIG_GRKERNSEC_DMESG
75708 + {
75709 + .procname = "dmesg",
75710 + .data = &grsec_enable_dmesg,
75711 + .maxlen = sizeof(int),
75712 + .mode = 0600,
75713 + .proc_handler = &proc_dointvec,
75714 + },
75715 +#endif
75716 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
75717 + {
75718 + .procname = "chroot_findtask",
75719 + .data = &grsec_enable_chroot_findtask,
75720 + .maxlen = sizeof(int),
75721 + .mode = 0600,
75722 + .proc_handler = &proc_dointvec,
75723 + },
75724 +#endif
75725 +#ifdef CONFIG_GRKERNSEC_RESLOG
75726 + {
75727 + .procname = "resource_logging",
75728 + .data = &grsec_resource_logging,
75729 + .maxlen = sizeof(int),
75730 + .mode = 0600,
75731 + .proc_handler = &proc_dointvec,
75732 + },
75733 +#endif
75734 +#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
75735 + {
75736 + .procname = "audit_ptrace",
75737 + .data = &grsec_enable_audit_ptrace,
75738 + .maxlen = sizeof(int),
75739 + .mode = 0600,
75740 + .proc_handler = &proc_dointvec,
75741 + },
75742 +#endif
75743 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
75744 + {
75745 + .procname = "harden_ptrace",
75746 + .data = &grsec_enable_harden_ptrace,
75747 + .maxlen = sizeof(int),
75748 + .mode = 0600,
75749 + .proc_handler = &proc_dointvec,
75750 + },
75751 +#endif
75752 +#ifdef CONFIG_GRKERNSEC_HARDEN_IPC
75753 + {
75754 + .procname = "harden_ipc",
75755 + .data = &grsec_enable_harden_ipc,
75756 + .maxlen = sizeof(int),
75757 + .mode = 0600,
75758 + .proc_handler = &proc_dointvec,
75759 + },
75760 +#endif
75761 + {
75762 + .procname = "grsec_lock",
75763 + .data = &grsec_lock,
75764 + .maxlen = sizeof(int),
75765 + .mode = 0600,
75766 + .proc_handler = &proc_dointvec,
75767 + },
75768 +#endif
75769 +#ifdef CONFIG_GRKERNSEC_ROFS
75770 + {
75771 + .procname = "romount_protect",
75772 + .data = &grsec_enable_rofs,
75773 + .maxlen = sizeof(int),
75774 + .mode = 0600,
75775 + .proc_handler = &proc_dointvec_minmax,
75776 + .extra1 = &one,
75777 + .extra2 = &one,
75778 + },
75779 +#endif
75780 +#if defined(CONFIG_GRKERNSEC_DENYUSB) && !defined(CONFIG_GRKERNSEC_DENYUSB_FORCE)
75781 + {
75782 + .procname = "deny_new_usb",
75783 + .data = &grsec_deny_new_usb,
75784 + .maxlen = sizeof(int),
75785 + .mode = 0600,
75786 + .proc_handler = &proc_dointvec,
75787 + },
75788 +#endif
75789 + { }
75790 +};
75791 +#endif
75792 diff --git a/grsecurity/grsec_time.c b/grsecurity/grsec_time.c
75793 new file mode 100644
75794 index 0000000..61b514e
75795 --- /dev/null
75796 +++ b/grsecurity/grsec_time.c
75797 @@ -0,0 +1,16 @@
75798 +#include <linux/kernel.h>
75799 +#include <linux/sched.h>
75800 +#include <linux/grinternal.h>
75801 +#include <linux/module.h>
75802 +
75803 +void
75804 +gr_log_timechange(void)
75805 +{
75806 +#ifdef CONFIG_GRKERNSEC_TIME
75807 + if (grsec_enable_time)
75808 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_TIME_MSG);
75809 +#endif
75810 + return;
75811 +}
75812 +
75813 +EXPORT_SYMBOL_GPL(gr_log_timechange);
75814 diff --git a/grsecurity/grsec_tpe.c b/grsecurity/grsec_tpe.c
75815 new file mode 100644
75816 index 0000000..ee57dcf
75817 --- /dev/null
75818 +++ b/grsecurity/grsec_tpe.c
75819 @@ -0,0 +1,73 @@
75820 +#include <linux/kernel.h>
75821 +#include <linux/sched.h>
75822 +#include <linux/file.h>
75823 +#include <linux/fs.h>
75824 +#include <linux/grinternal.h>
75825 +
75826 +extern int gr_acl_tpe_check(void);
75827 +
75828 +int
75829 +gr_tpe_allow(const struct file *file)
75830 +{
75831 +#ifdef CONFIG_GRKERNSEC
75832 + struct inode *inode = file->f_path.dentry->d_parent->d_inode;
75833 + const struct cred *cred = current_cred();
75834 + char *msg = NULL;
75835 + char *msg2 = NULL;
75836 +
75837 + // never restrict root
75838 + if (gr_is_global_root(cred->uid))
75839 + return 1;
75840 +
75841 + if (grsec_enable_tpe) {
75842 +#ifdef CONFIG_GRKERNSEC_TPE_INVERT
75843 + if (grsec_enable_tpe_invert && !in_group_p(grsec_tpe_gid))
75844 + msg = "not being in trusted group";
75845 + else if (!grsec_enable_tpe_invert && in_group_p(grsec_tpe_gid))
75846 + msg = "being in untrusted group";
75847 +#else
75848 + if (in_group_p(grsec_tpe_gid))
75849 + msg = "being in untrusted group";
75850 +#endif
75851 + }
75852 + if (!msg && gr_acl_tpe_check())
75853 + msg = "being in untrusted role";
75854 +
75855 + // not in any affected group/role
75856 + if (!msg)
75857 + goto next_check;
75858 +
75859 + if (gr_is_global_nonroot(inode->i_uid))
75860 + msg2 = "file in non-root-owned directory";
75861 + else if (inode->i_mode & S_IWOTH)
75862 + msg2 = "file in world-writable directory";
75863 + else if (inode->i_mode & S_IWGRP)
75864 + msg2 = "file in group-writable directory";
75865 +
75866 + if (msg && msg2) {
75867 + char fullmsg[70] = {0};
75868 + snprintf(fullmsg, sizeof(fullmsg)-1, "%s and %s", msg, msg2);
75869 + gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, fullmsg, file->f_path.dentry, file->f_path.mnt);
75870 + return 0;
75871 + }
75872 + msg = NULL;
75873 +next_check:
75874 +#ifdef CONFIG_GRKERNSEC_TPE_ALL
75875 + if (!grsec_enable_tpe || !grsec_enable_tpe_all)
75876 + return 1;
75877 +
75878 + if (gr_is_global_nonroot(inode->i_uid) && !uid_eq(inode->i_uid, cred->uid))
75879 + msg = "directory not owned by user";
75880 + else if (inode->i_mode & S_IWOTH)
75881 + msg = "file in world-writable directory";
75882 + else if (inode->i_mode & S_IWGRP)
75883 + msg = "file in group-writable directory";
75884 +
75885 + if (msg) {
75886 + gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, msg, file->f_path.dentry, file->f_path.mnt);
75887 + return 0;
75888 + }
75889 +#endif
75890 +#endif
75891 + return 1;
75892 +}
75893 diff --git a/grsecurity/grsec_usb.c b/grsecurity/grsec_usb.c
75894 new file mode 100644
75895 index 0000000..ae02d8e
75896 --- /dev/null
75897 +++ b/grsecurity/grsec_usb.c
75898 @@ -0,0 +1,15 @@
75899 +#include <linux/kernel.h>
75900 +#include <linux/grinternal.h>
75901 +#include <linux/module.h>
75902 +
75903 +int gr_handle_new_usb(void)
75904 +{
75905 +#ifdef CONFIG_GRKERNSEC_DENYUSB
75906 + if (grsec_deny_new_usb) {
75907 + printk(KERN_ALERT "grsec: denied insert of new USB device\n");
75908 + return 1;
75909 + }
75910 +#endif
75911 + return 0;
75912 +}
75913 +EXPORT_SYMBOL_GPL(gr_handle_new_usb);
75914 diff --git a/grsecurity/grsum.c b/grsecurity/grsum.c
75915 new file mode 100644
75916 index 0000000..9f7b1ac
75917 --- /dev/null
75918 +++ b/grsecurity/grsum.c
75919 @@ -0,0 +1,61 @@
75920 +#include <linux/err.h>
75921 +#include <linux/kernel.h>
75922 +#include <linux/sched.h>
75923 +#include <linux/mm.h>
75924 +#include <linux/scatterlist.h>
75925 +#include <linux/crypto.h>
75926 +#include <linux/gracl.h>
75927 +
75928 +
75929 +#if !defined(CONFIG_CRYPTO) || defined(CONFIG_CRYPTO_MODULE) || !defined(CONFIG_CRYPTO_SHA256) || defined(CONFIG_CRYPTO_SHA256_MODULE)
75930 +#error "crypto and sha256 must be built into the kernel"
75931 +#endif
75932 +
75933 +int
75934 +chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum)
75935 +{
75936 + char *p;
75937 + struct crypto_hash *tfm;
75938 + struct hash_desc desc;
75939 + struct scatterlist sg;
75940 + unsigned char temp_sum[GR_SHA_LEN];
75941 + volatile int retval = 0;
75942 + volatile int dummy = 0;
75943 + unsigned int i;
75944 +
75945 + sg_init_table(&sg, 1);
75946 +
75947 + tfm = crypto_alloc_hash("sha256", 0, CRYPTO_ALG_ASYNC);
75948 + if (IS_ERR(tfm)) {
75949 + /* should never happen, since sha256 should be built in */
75950 + return 1;
75951 + }
75952 +
75953 + desc.tfm = tfm;
75954 + desc.flags = 0;
75955 +
75956 + crypto_hash_init(&desc);
75957 +
75958 + p = salt;
75959 + sg_set_buf(&sg, p, GR_SALT_LEN);
75960 + crypto_hash_update(&desc, &sg, sg.length);
75961 +
75962 + p = entry->pw;
75963 + sg_set_buf(&sg, p, strlen(p));
75964 +
75965 + crypto_hash_update(&desc, &sg, sg.length);
75966 +
75967 + crypto_hash_final(&desc, temp_sum);
75968 +
75969 + memset(entry->pw, 0, GR_PW_LEN);
75970 +
75971 + for (i = 0; i < GR_SHA_LEN; i++)
75972 + if (sum[i] != temp_sum[i])
75973 + retval = 1;
75974 + else
75975 + dummy = 1; // waste a cycle
75976 +
75977 + crypto_free_hash(tfm);
75978 +
75979 + return retval;
75980 +}
75981 diff --git a/include/asm-generic/4level-fixup.h b/include/asm-generic/4level-fixup.h
75982 index 77ff547..181834f 100644
75983 --- a/include/asm-generic/4level-fixup.h
75984 +++ b/include/asm-generic/4level-fixup.h
75985 @@ -13,8 +13,10 @@
75986 #define pmd_alloc(mm, pud, address) \
75987 ((unlikely(pgd_none(*(pud))) && __pmd_alloc(mm, pud, address))? \
75988 NULL: pmd_offset(pud, address))
75989 +#define pmd_alloc_kernel(mm, pud, address) pmd_alloc((mm), (pud), (address))
75990
75991 #define pud_alloc(mm, pgd, address) (pgd)
75992 +#define pud_alloc_kernel(mm, pgd, address) pud_alloc((mm), (pgd), (address))
75993 #define pud_offset(pgd, start) (pgd)
75994 #define pud_none(pud) 0
75995 #define pud_bad(pud) 0
75996 diff --git a/include/asm-generic/atomic-long.h b/include/asm-generic/atomic-long.h
75997 index b7babf0..97f4c4f 100644
75998 --- a/include/asm-generic/atomic-long.h
75999 +++ b/include/asm-generic/atomic-long.h
76000 @@ -22,6 +22,12 @@
76001
76002 typedef atomic64_t atomic_long_t;
76003
76004 +#ifdef CONFIG_PAX_REFCOUNT
76005 +typedef atomic64_unchecked_t atomic_long_unchecked_t;
76006 +#else
76007 +typedef atomic64_t atomic_long_unchecked_t;
76008 +#endif
76009 +
76010 #define ATOMIC_LONG_INIT(i) ATOMIC64_INIT(i)
76011
76012 static inline long atomic_long_read(atomic_long_t *l)
76013 @@ -31,6 +37,15 @@ static inline long atomic_long_read(atomic_long_t *l)
76014 return (long)atomic64_read(v);
76015 }
76016
76017 +#ifdef CONFIG_PAX_REFCOUNT
76018 +static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
76019 +{
76020 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
76021 +
76022 + return (long)atomic64_read_unchecked(v);
76023 +}
76024 +#endif
76025 +
76026 static inline void atomic_long_set(atomic_long_t *l, long i)
76027 {
76028 atomic64_t *v = (atomic64_t *)l;
76029 @@ -38,6 +53,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
76030 atomic64_set(v, i);
76031 }
76032
76033 +#ifdef CONFIG_PAX_REFCOUNT
76034 +static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
76035 +{
76036 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
76037 +
76038 + atomic64_set_unchecked(v, i);
76039 +}
76040 +#endif
76041 +
76042 static inline void atomic_long_inc(atomic_long_t *l)
76043 {
76044 atomic64_t *v = (atomic64_t *)l;
76045 @@ -45,6 +69,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
76046 atomic64_inc(v);
76047 }
76048
76049 +#ifdef CONFIG_PAX_REFCOUNT
76050 +static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
76051 +{
76052 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
76053 +
76054 + atomic64_inc_unchecked(v);
76055 +}
76056 +#endif
76057 +
76058 static inline void atomic_long_dec(atomic_long_t *l)
76059 {
76060 atomic64_t *v = (atomic64_t *)l;
76061 @@ -52,6 +85,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
76062 atomic64_dec(v);
76063 }
76064
76065 +#ifdef CONFIG_PAX_REFCOUNT
76066 +static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
76067 +{
76068 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
76069 +
76070 + atomic64_dec_unchecked(v);
76071 +}
76072 +#endif
76073 +
76074 static inline void atomic_long_add(long i, atomic_long_t *l)
76075 {
76076 atomic64_t *v = (atomic64_t *)l;
76077 @@ -59,6 +101,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
76078 atomic64_add(i, v);
76079 }
76080
76081 +#ifdef CONFIG_PAX_REFCOUNT
76082 +static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
76083 +{
76084 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
76085 +
76086 + atomic64_add_unchecked(i, v);
76087 +}
76088 +#endif
76089 +
76090 static inline void atomic_long_sub(long i, atomic_long_t *l)
76091 {
76092 atomic64_t *v = (atomic64_t *)l;
76093 @@ -66,6 +117,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
76094 atomic64_sub(i, v);
76095 }
76096
76097 +#ifdef CONFIG_PAX_REFCOUNT
76098 +static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
76099 +{
76100 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
76101 +
76102 + atomic64_sub_unchecked(i, v);
76103 +}
76104 +#endif
76105 +
76106 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
76107 {
76108 atomic64_t *v = (atomic64_t *)l;
76109 @@ -94,13 +154,22 @@ static inline int atomic_long_add_negative(long i, atomic_long_t *l)
76110 return atomic64_add_negative(i, v);
76111 }
76112
76113 -static inline long atomic_long_add_return(long i, atomic_long_t *l)
76114 +static inline long __intentional_overflow(-1) atomic_long_add_return(long i, atomic_long_t *l)
76115 {
76116 atomic64_t *v = (atomic64_t *)l;
76117
76118 return (long)atomic64_add_return(i, v);
76119 }
76120
76121 +#ifdef CONFIG_PAX_REFCOUNT
76122 +static inline long atomic_long_add_return_unchecked(long i, atomic_long_unchecked_t *l)
76123 +{
76124 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
76125 +
76126 + return (long)atomic64_add_return_unchecked(i, v);
76127 +}
76128 +#endif
76129 +
76130 static inline long atomic_long_sub_return(long i, atomic_long_t *l)
76131 {
76132 atomic64_t *v = (atomic64_t *)l;
76133 @@ -115,6 +184,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
76134 return (long)atomic64_inc_return(v);
76135 }
76136
76137 +#ifdef CONFIG_PAX_REFCOUNT
76138 +static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
76139 +{
76140 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
76141 +
76142 + return (long)atomic64_inc_return_unchecked(v);
76143 +}
76144 +#endif
76145 +
76146 static inline long atomic_long_dec_return(atomic_long_t *l)
76147 {
76148 atomic64_t *v = (atomic64_t *)l;
76149 @@ -140,6 +218,12 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
76150
76151 typedef atomic_t atomic_long_t;
76152
76153 +#ifdef CONFIG_PAX_REFCOUNT
76154 +typedef atomic_unchecked_t atomic_long_unchecked_t;
76155 +#else
76156 +typedef atomic_t atomic_long_unchecked_t;
76157 +#endif
76158 +
76159 #define ATOMIC_LONG_INIT(i) ATOMIC_INIT(i)
76160 static inline long atomic_long_read(atomic_long_t *l)
76161 {
76162 @@ -148,6 +232,15 @@ static inline long atomic_long_read(atomic_long_t *l)
76163 return (long)atomic_read(v);
76164 }
76165
76166 +#ifdef CONFIG_PAX_REFCOUNT
76167 +static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
76168 +{
76169 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
76170 +
76171 + return (long)atomic_read_unchecked(v);
76172 +}
76173 +#endif
76174 +
76175 static inline void atomic_long_set(atomic_long_t *l, long i)
76176 {
76177 atomic_t *v = (atomic_t *)l;
76178 @@ -155,6 +248,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
76179 atomic_set(v, i);
76180 }
76181
76182 +#ifdef CONFIG_PAX_REFCOUNT
76183 +static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
76184 +{
76185 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
76186 +
76187 + atomic_set_unchecked(v, i);
76188 +}
76189 +#endif
76190 +
76191 static inline void atomic_long_inc(atomic_long_t *l)
76192 {
76193 atomic_t *v = (atomic_t *)l;
76194 @@ -162,6 +264,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
76195 atomic_inc(v);
76196 }
76197
76198 +#ifdef CONFIG_PAX_REFCOUNT
76199 +static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
76200 +{
76201 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
76202 +
76203 + atomic_inc_unchecked(v);
76204 +}
76205 +#endif
76206 +
76207 static inline void atomic_long_dec(atomic_long_t *l)
76208 {
76209 atomic_t *v = (atomic_t *)l;
76210 @@ -169,6 +280,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
76211 atomic_dec(v);
76212 }
76213
76214 +#ifdef CONFIG_PAX_REFCOUNT
76215 +static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
76216 +{
76217 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
76218 +
76219 + atomic_dec_unchecked(v);
76220 +}
76221 +#endif
76222 +
76223 static inline void atomic_long_add(long i, atomic_long_t *l)
76224 {
76225 atomic_t *v = (atomic_t *)l;
76226 @@ -176,6 +296,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
76227 atomic_add(i, v);
76228 }
76229
76230 +#ifdef CONFIG_PAX_REFCOUNT
76231 +static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
76232 +{
76233 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
76234 +
76235 + atomic_add_unchecked(i, v);
76236 +}
76237 +#endif
76238 +
76239 static inline void atomic_long_sub(long i, atomic_long_t *l)
76240 {
76241 atomic_t *v = (atomic_t *)l;
76242 @@ -183,6 +312,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
76243 atomic_sub(i, v);
76244 }
76245
76246 +#ifdef CONFIG_PAX_REFCOUNT
76247 +static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
76248 +{
76249 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
76250 +
76251 + atomic_sub_unchecked(i, v);
76252 +}
76253 +#endif
76254 +
76255 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
76256 {
76257 atomic_t *v = (atomic_t *)l;
76258 @@ -218,6 +356,16 @@ static inline long atomic_long_add_return(long i, atomic_long_t *l)
76259 return (long)atomic_add_return(i, v);
76260 }
76261
76262 +#ifdef CONFIG_PAX_REFCOUNT
76263 +static inline long atomic_long_add_return_unchecked(long i, atomic_long_unchecked_t *l)
76264 +{
76265 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
76266 +
76267 + return (long)atomic_add_return_unchecked(i, v);
76268 +}
76269 +
76270 +#endif
76271 +
76272 static inline long atomic_long_sub_return(long i, atomic_long_t *l)
76273 {
76274 atomic_t *v = (atomic_t *)l;
76275 @@ -232,6 +380,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
76276 return (long)atomic_inc_return(v);
76277 }
76278
76279 +#ifdef CONFIG_PAX_REFCOUNT
76280 +static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
76281 +{
76282 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
76283 +
76284 + return (long)atomic_inc_return_unchecked(v);
76285 +}
76286 +#endif
76287 +
76288 static inline long atomic_long_dec_return(atomic_long_t *l)
76289 {
76290 atomic_t *v = (atomic_t *)l;
76291 @@ -255,4 +412,57 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
76292
76293 #endif /* BITS_PER_LONG == 64 */
76294
76295 +#ifdef CONFIG_PAX_REFCOUNT
76296 +static inline void pax_refcount_needs_these_functions(void)
76297 +{
76298 + atomic_read_unchecked((atomic_unchecked_t *)NULL);
76299 + atomic_set_unchecked((atomic_unchecked_t *)NULL, 0);
76300 + atomic_add_unchecked(0, (atomic_unchecked_t *)NULL);
76301 + atomic_sub_unchecked(0, (atomic_unchecked_t *)NULL);
76302 + atomic_inc_unchecked((atomic_unchecked_t *)NULL);
76303 + (void)atomic_inc_and_test_unchecked((atomic_unchecked_t *)NULL);
76304 + atomic_inc_return_unchecked((atomic_unchecked_t *)NULL);
76305 + atomic_add_return_unchecked(0, (atomic_unchecked_t *)NULL);
76306 + atomic_dec_unchecked((atomic_unchecked_t *)NULL);
76307 + atomic_cmpxchg_unchecked((atomic_unchecked_t *)NULL, 0, 0);
76308 + (void)atomic_xchg_unchecked((atomic_unchecked_t *)NULL, 0);
76309 +#ifdef CONFIG_X86
76310 + atomic_clear_mask_unchecked(0, NULL);
76311 + atomic_set_mask_unchecked(0, NULL);
76312 +#endif
76313 +
76314 + atomic_long_read_unchecked((atomic_long_unchecked_t *)NULL);
76315 + atomic_long_set_unchecked((atomic_long_unchecked_t *)NULL, 0);
76316 + atomic_long_add_unchecked(0, (atomic_long_unchecked_t *)NULL);
76317 + atomic_long_sub_unchecked(0, (atomic_long_unchecked_t *)NULL);
76318 + atomic_long_inc_unchecked((atomic_long_unchecked_t *)NULL);
76319 + atomic_long_add_return_unchecked(0, (atomic_long_unchecked_t *)NULL);
76320 + atomic_long_inc_return_unchecked((atomic_long_unchecked_t *)NULL);
76321 + atomic_long_dec_unchecked((atomic_long_unchecked_t *)NULL);
76322 +}
76323 +#else
76324 +#define atomic_read_unchecked(v) atomic_read(v)
76325 +#define atomic_set_unchecked(v, i) atomic_set((v), (i))
76326 +#define atomic_add_unchecked(i, v) atomic_add((i), (v))
76327 +#define atomic_sub_unchecked(i, v) atomic_sub((i), (v))
76328 +#define atomic_inc_unchecked(v) atomic_inc(v)
76329 +#define atomic_inc_and_test_unchecked(v) atomic_inc_and_test(v)
76330 +#define atomic_inc_return_unchecked(v) atomic_inc_return(v)
76331 +#define atomic_add_return_unchecked(i, v) atomic_add_return((i), (v))
76332 +#define atomic_dec_unchecked(v) atomic_dec(v)
76333 +#define atomic_cmpxchg_unchecked(v, o, n) atomic_cmpxchg((v), (o), (n))
76334 +#define atomic_xchg_unchecked(v, i) atomic_xchg((v), (i))
76335 +#define atomic_clear_mask_unchecked(mask, v) atomic_clear_mask((mask), (v))
76336 +#define atomic_set_mask_unchecked(mask, v) atomic_set_mask((mask), (v))
76337 +
76338 +#define atomic_long_read_unchecked(v) atomic_long_read(v)
76339 +#define atomic_long_set_unchecked(v, i) atomic_long_set((v), (i))
76340 +#define atomic_long_add_unchecked(i, v) atomic_long_add((i), (v))
76341 +#define atomic_long_sub_unchecked(i, v) atomic_long_sub((i), (v))
76342 +#define atomic_long_inc_unchecked(v) atomic_long_inc(v)
76343 +#define atomic_long_add_return_unchecked(i, v) atomic_long_add_return((i), (v))
76344 +#define atomic_long_inc_return_unchecked(v) atomic_long_inc_return(v)
76345 +#define atomic_long_dec_unchecked(v) atomic_long_dec(v)
76346 +#endif
76347 +
76348 #endif /* _ASM_GENERIC_ATOMIC_LONG_H */
76349 diff --git a/include/asm-generic/atomic.h b/include/asm-generic/atomic.h
76350 index 33bd2de..f31bff97 100644
76351 --- a/include/asm-generic/atomic.h
76352 +++ b/include/asm-generic/atomic.h
76353 @@ -153,7 +153,7 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
76354 * Atomically clears the bits set in @mask from @v
76355 */
76356 #ifndef atomic_clear_mask
76357 -static inline void atomic_clear_mask(unsigned long mask, atomic_t *v)
76358 +static inline void atomic_clear_mask(unsigned int mask, atomic_t *v)
76359 {
76360 unsigned long flags;
76361
76362 diff --git a/include/asm-generic/atomic64.h b/include/asm-generic/atomic64.h
76363 index b18ce4f..2ee2843 100644
76364 --- a/include/asm-generic/atomic64.h
76365 +++ b/include/asm-generic/atomic64.h
76366 @@ -16,6 +16,8 @@ typedef struct {
76367 long long counter;
76368 } atomic64_t;
76369
76370 +typedef atomic64_t atomic64_unchecked_t;
76371 +
76372 #define ATOMIC64_INIT(i) { (i) }
76373
76374 extern long long atomic64_read(const atomic64_t *v);
76375 @@ -39,4 +41,14 @@ extern int atomic64_add_unless(atomic64_t *v, long long a, long long u);
76376 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
76377 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
76378
76379 +#define atomic64_read_unchecked(v) atomic64_read(v)
76380 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
76381 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
76382 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
76383 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
76384 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
76385 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
76386 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
76387 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
76388 +
76389 #endif /* _ASM_GENERIC_ATOMIC64_H */
76390 diff --git a/include/asm-generic/bitops/__fls.h b/include/asm-generic/bitops/__fls.h
76391 index a60a7cc..0fe12f2 100644
76392 --- a/include/asm-generic/bitops/__fls.h
76393 +++ b/include/asm-generic/bitops/__fls.h
76394 @@ -9,7 +9,7 @@
76395 *
76396 * Undefined if no set bit exists, so code should check against 0 first.
76397 */
76398 -static __always_inline unsigned long __fls(unsigned long word)
76399 +static __always_inline unsigned long __intentional_overflow(-1) __fls(unsigned long word)
76400 {
76401 int num = BITS_PER_LONG - 1;
76402
76403 diff --git a/include/asm-generic/bitops/fls.h b/include/asm-generic/bitops/fls.h
76404 index 0576d1f..dad6c71 100644
76405 --- a/include/asm-generic/bitops/fls.h
76406 +++ b/include/asm-generic/bitops/fls.h
76407 @@ -9,7 +9,7 @@
76408 * Note fls(0) = 0, fls(1) = 1, fls(0x80000000) = 32.
76409 */
76410
76411 -static __always_inline int fls(int x)
76412 +static __always_inline int __intentional_overflow(-1) fls(int x)
76413 {
76414 int r = 32;
76415
76416 diff --git a/include/asm-generic/bitops/fls64.h b/include/asm-generic/bitops/fls64.h
76417 index b097cf8..3d40e14 100644
76418 --- a/include/asm-generic/bitops/fls64.h
76419 +++ b/include/asm-generic/bitops/fls64.h
76420 @@ -15,7 +15,7 @@
76421 * at position 64.
76422 */
76423 #if BITS_PER_LONG == 32
76424 -static __always_inline int fls64(__u64 x)
76425 +static __always_inline int __intentional_overflow(-1) fls64(__u64 x)
76426 {
76427 __u32 h = x >> 32;
76428 if (h)
76429 @@ -23,7 +23,7 @@ static __always_inline int fls64(__u64 x)
76430 return fls(x);
76431 }
76432 #elif BITS_PER_LONG == 64
76433 -static __always_inline int fls64(__u64 x)
76434 +static __always_inline int __intentional_overflow(-1) fls64(__u64 x)
76435 {
76436 if (x == 0)
76437 return 0;
76438 diff --git a/include/asm-generic/cache.h b/include/asm-generic/cache.h
76439 index 1bfcfe5..e04c5c9 100644
76440 --- a/include/asm-generic/cache.h
76441 +++ b/include/asm-generic/cache.h
76442 @@ -6,7 +6,7 @@
76443 * cache lines need to provide their own cache.h.
76444 */
76445
76446 -#define L1_CACHE_SHIFT 5
76447 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
76448 +#define L1_CACHE_SHIFT 5UL
76449 +#define L1_CACHE_BYTES (1UL << L1_CACHE_SHIFT)
76450
76451 #endif /* __ASM_GENERIC_CACHE_H */
76452 diff --git a/include/asm-generic/emergency-restart.h b/include/asm-generic/emergency-restart.h
76453 index 0d68a1e..b74a761 100644
76454 --- a/include/asm-generic/emergency-restart.h
76455 +++ b/include/asm-generic/emergency-restart.h
76456 @@ -1,7 +1,7 @@
76457 #ifndef _ASM_GENERIC_EMERGENCY_RESTART_H
76458 #define _ASM_GENERIC_EMERGENCY_RESTART_H
76459
76460 -static inline void machine_emergency_restart(void)
76461 +static inline __noreturn void machine_emergency_restart(void)
76462 {
76463 machine_restart(NULL);
76464 }
76465 diff --git a/include/asm-generic/kmap_types.h b/include/asm-generic/kmap_types.h
76466 index 90f99c7..00ce236 100644
76467 --- a/include/asm-generic/kmap_types.h
76468 +++ b/include/asm-generic/kmap_types.h
76469 @@ -2,9 +2,9 @@
76470 #define _ASM_GENERIC_KMAP_TYPES_H
76471
76472 #ifdef __WITH_KM_FENCE
76473 -# define KM_TYPE_NR 41
76474 +# define KM_TYPE_NR 42
76475 #else
76476 -# define KM_TYPE_NR 20
76477 +# define KM_TYPE_NR 21
76478 #endif
76479
76480 #endif
76481 diff --git a/include/asm-generic/local.h b/include/asm-generic/local.h
76482 index 9ceb03b..62b0b8f 100644
76483 --- a/include/asm-generic/local.h
76484 +++ b/include/asm-generic/local.h
76485 @@ -23,24 +23,37 @@ typedef struct
76486 atomic_long_t a;
76487 } local_t;
76488
76489 +typedef struct {
76490 + atomic_long_unchecked_t a;
76491 +} local_unchecked_t;
76492 +
76493 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
76494
76495 #define local_read(l) atomic_long_read(&(l)->a)
76496 +#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
76497 #define local_set(l,i) atomic_long_set((&(l)->a),(i))
76498 +#define local_set_unchecked(l,i) atomic_long_set_unchecked((&(l)->a),(i))
76499 #define local_inc(l) atomic_long_inc(&(l)->a)
76500 +#define local_inc_unchecked(l) atomic_long_inc_unchecked(&(l)->a)
76501 #define local_dec(l) atomic_long_dec(&(l)->a)
76502 +#define local_dec_unchecked(l) atomic_long_dec_unchecked(&(l)->a)
76503 #define local_add(i,l) atomic_long_add((i),(&(l)->a))
76504 +#define local_add_unchecked(i,l) atomic_long_add_unchecked((i),(&(l)->a))
76505 #define local_sub(i,l) atomic_long_sub((i),(&(l)->a))
76506 +#define local_sub_unchecked(i,l) atomic_long_sub_unchecked((i),(&(l)->a))
76507
76508 #define local_sub_and_test(i, l) atomic_long_sub_and_test((i), (&(l)->a))
76509 #define local_dec_and_test(l) atomic_long_dec_and_test(&(l)->a)
76510 #define local_inc_and_test(l) atomic_long_inc_and_test(&(l)->a)
76511 #define local_add_negative(i, l) atomic_long_add_negative((i), (&(l)->a))
76512 #define local_add_return(i, l) atomic_long_add_return((i), (&(l)->a))
76513 +#define local_add_return_unchecked(i, l) atomic_long_add_return_unchecked((i), (&(l)->a))
76514 #define local_sub_return(i, l) atomic_long_sub_return((i), (&(l)->a))
76515 #define local_inc_return(l) atomic_long_inc_return(&(l)->a)
76516 +#define local_dec_return(l) atomic_long_dec_return(&(l)->a)
76517
76518 #define local_cmpxchg(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
76519 +#define local_cmpxchg_unchecked(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
76520 #define local_xchg(l, n) atomic_long_xchg((&(l)->a), (n))
76521 #define local_add_unless(l, _a, u) atomic_long_add_unless((&(l)->a), (_a), (u))
76522 #define local_inc_not_zero(l) atomic_long_inc_not_zero(&(l)->a)
76523 diff --git a/include/asm-generic/pgtable-nopmd.h b/include/asm-generic/pgtable-nopmd.h
76524 index 725612b..9cc513a 100644
76525 --- a/include/asm-generic/pgtable-nopmd.h
76526 +++ b/include/asm-generic/pgtable-nopmd.h
76527 @@ -1,14 +1,19 @@
76528 #ifndef _PGTABLE_NOPMD_H
76529 #define _PGTABLE_NOPMD_H
76530
76531 -#ifndef __ASSEMBLY__
76532 -
76533 #include <asm-generic/pgtable-nopud.h>
76534
76535 -struct mm_struct;
76536 -
76537 #define __PAGETABLE_PMD_FOLDED
76538
76539 +#define PMD_SHIFT PUD_SHIFT
76540 +#define PTRS_PER_PMD 1
76541 +#define PMD_SIZE (_AC(1,UL) << PMD_SHIFT)
76542 +#define PMD_MASK (~(PMD_SIZE-1))
76543 +
76544 +#ifndef __ASSEMBLY__
76545 +
76546 +struct mm_struct;
76547 +
76548 /*
76549 * Having the pmd type consist of a pud gets the size right, and allows
76550 * us to conceptually access the pud entry that this pmd is folded into
76551 @@ -16,11 +21,6 @@ struct mm_struct;
76552 */
76553 typedef struct { pud_t pud; } pmd_t;
76554
76555 -#define PMD_SHIFT PUD_SHIFT
76556 -#define PTRS_PER_PMD 1
76557 -#define PMD_SIZE (1UL << PMD_SHIFT)
76558 -#define PMD_MASK (~(PMD_SIZE-1))
76559 -
76560 /*
76561 * The "pud_xxx()" functions here are trivial for a folded two-level
76562 * setup: the pmd is never bad, and a pmd always exists (as it's folded
76563 diff --git a/include/asm-generic/pgtable-nopud.h b/include/asm-generic/pgtable-nopud.h
76564 index 810431d..0ec4804f 100644
76565 --- a/include/asm-generic/pgtable-nopud.h
76566 +++ b/include/asm-generic/pgtable-nopud.h
76567 @@ -1,10 +1,15 @@
76568 #ifndef _PGTABLE_NOPUD_H
76569 #define _PGTABLE_NOPUD_H
76570
76571 -#ifndef __ASSEMBLY__
76572 -
76573 #define __PAGETABLE_PUD_FOLDED
76574
76575 +#define PUD_SHIFT PGDIR_SHIFT
76576 +#define PTRS_PER_PUD 1
76577 +#define PUD_SIZE (_AC(1,UL) << PUD_SHIFT)
76578 +#define PUD_MASK (~(PUD_SIZE-1))
76579 +
76580 +#ifndef __ASSEMBLY__
76581 +
76582 /*
76583 * Having the pud type consist of a pgd gets the size right, and allows
76584 * us to conceptually access the pgd entry that this pud is folded into
76585 @@ -12,11 +17,6 @@
76586 */
76587 typedef struct { pgd_t pgd; } pud_t;
76588
76589 -#define PUD_SHIFT PGDIR_SHIFT
76590 -#define PTRS_PER_PUD 1
76591 -#define PUD_SIZE (1UL << PUD_SHIFT)
76592 -#define PUD_MASK (~(PUD_SIZE-1))
76593 -
76594 /*
76595 * The "pgd_xxx()" functions here are trivial for a folded two-level
76596 * setup: the pud is never bad, and a pud always exists (as it's folded
76597 @@ -29,6 +29,7 @@ static inline void pgd_clear(pgd_t *pgd) { }
76598 #define pud_ERROR(pud) (pgd_ERROR((pud).pgd))
76599
76600 #define pgd_populate(mm, pgd, pud) do { } while (0)
76601 +#define pgd_populate_kernel(mm, pgd, pud) do { } while (0)
76602 /*
76603 * (puds are folded into pgds so this doesn't get actually called,
76604 * but the define is needed for a generic inline function.)
76605 diff --git a/include/asm-generic/pgtable.h b/include/asm-generic/pgtable.h
76606 index 8e4f41d..c5e9afd 100644
76607 --- a/include/asm-generic/pgtable.h
76608 +++ b/include/asm-generic/pgtable.h
76609 @@ -748,6 +748,22 @@ static inline pmd_t pmd_mknuma(pmd_t pmd)
76610 }
76611 #endif /* CONFIG_NUMA_BALANCING */
76612
76613 +#ifndef __HAVE_ARCH_PAX_OPEN_KERNEL
76614 +#ifdef CONFIG_PAX_KERNEXEC
76615 +#error KERNEXEC requires pax_open_kernel
76616 +#else
76617 +static inline unsigned long pax_open_kernel(void) { return 0; }
76618 +#endif
76619 +#endif
76620 +
76621 +#ifndef __HAVE_ARCH_PAX_CLOSE_KERNEL
76622 +#ifdef CONFIG_PAX_KERNEXEC
76623 +#error KERNEXEC requires pax_close_kernel
76624 +#else
76625 +static inline unsigned long pax_close_kernel(void) { return 0; }
76626 +#endif
76627 +#endif
76628 +
76629 #endif /* CONFIG_MMU */
76630
76631 #endif /* !__ASSEMBLY__ */
76632 diff --git a/include/asm-generic/uaccess.h b/include/asm-generic/uaccess.h
76633 index dc1269c..48a4f51 100644
76634 --- a/include/asm-generic/uaccess.h
76635 +++ b/include/asm-generic/uaccess.h
76636 @@ -343,4 +343,20 @@ clear_user(void __user *to, unsigned long n)
76637 return __clear_user(to, n);
76638 }
76639
76640 +#ifndef __HAVE_ARCH_PAX_OPEN_USERLAND
76641 +#ifdef CONFIG_PAX_MEMORY_UDEREF
76642 +#error UDEREF requires pax_open_userland
76643 +#else
76644 +static inline unsigned long pax_open_userland(void) { return 0; }
76645 +#endif
76646 +#endif
76647 +
76648 +#ifndef __HAVE_ARCH_PAX_CLOSE_USERLAND
76649 +#ifdef CONFIG_PAX_MEMORY_UDEREF
76650 +#error UDEREF requires pax_close_userland
76651 +#else
76652 +static inline unsigned long pax_close_userland(void) { return 0; }
76653 +#endif
76654 +#endif
76655 +
76656 #endif /* __ASM_GENERIC_UACCESS_H */
76657 diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
76658 index bc2121f..2f41f9a 100644
76659 --- a/include/asm-generic/vmlinux.lds.h
76660 +++ b/include/asm-generic/vmlinux.lds.h
76661 @@ -232,6 +232,7 @@
76662 .rodata : AT(ADDR(.rodata) - LOAD_OFFSET) { \
76663 VMLINUX_SYMBOL(__start_rodata) = .; \
76664 *(.rodata) *(.rodata.*) \
76665 + *(.data..read_only) \
76666 *(__vermagic) /* Kernel version magic */ \
76667 . = ALIGN(8); \
76668 VMLINUX_SYMBOL(__start___tracepoints_ptrs) = .; \
76669 @@ -716,17 +717,18 @@
76670 * section in the linker script will go there too. @phdr should have
76671 * a leading colon.
76672 *
76673 - * Note that this macros defines __per_cpu_load as an absolute symbol.
76674 + * Note that this macros defines per_cpu_load as an absolute symbol.
76675 * If there is no need to put the percpu section at a predetermined
76676 * address, use PERCPU_SECTION.
76677 */
76678 #define PERCPU_VADDR(cacheline, vaddr, phdr) \
76679 - VMLINUX_SYMBOL(__per_cpu_load) = .; \
76680 - .data..percpu vaddr : AT(VMLINUX_SYMBOL(__per_cpu_load) \
76681 + per_cpu_load = .; \
76682 + .data..percpu vaddr : AT(VMLINUX_SYMBOL(per_cpu_load) \
76683 - LOAD_OFFSET) { \
76684 + VMLINUX_SYMBOL(__per_cpu_load) = . + per_cpu_load; \
76685 PERCPU_INPUT(cacheline) \
76686 } phdr \
76687 - . = VMLINUX_SYMBOL(__per_cpu_load) + SIZEOF(.data..percpu);
76688 + . = VMLINUX_SYMBOL(per_cpu_load) + SIZEOF(.data..percpu);
76689
76690 /**
76691 * PERCPU_SECTION - define output section for percpu area, simple version
76692 diff --git a/include/crypto/algapi.h b/include/crypto/algapi.h
76693 index e73c19e..5b89e00 100644
76694 --- a/include/crypto/algapi.h
76695 +++ b/include/crypto/algapi.h
76696 @@ -34,7 +34,7 @@ struct crypto_type {
76697 unsigned int maskclear;
76698 unsigned int maskset;
76699 unsigned int tfmsize;
76700 -};
76701 +} __do_const;
76702
76703 struct crypto_instance {
76704 struct crypto_alg alg;
76705 diff --git a/include/drm/drmP.h b/include/drm/drmP.h
76706 index 1d4a920..da65658 100644
76707 --- a/include/drm/drmP.h
76708 +++ b/include/drm/drmP.h
76709 @@ -66,6 +66,7 @@
76710 #include <linux/workqueue.h>
76711 #include <linux/poll.h>
76712 #include <asm/pgalloc.h>
76713 +#include <asm/local.h>
76714 #include <drm/drm.h>
76715 #include <drm/drm_sarea.h>
76716 #include <drm/drm_vma_manager.h>
76717 @@ -278,10 +279,12 @@ do { \
76718 * \param cmd command.
76719 * \param arg argument.
76720 */
76721 -typedef int drm_ioctl_t(struct drm_device *dev, void *data,
76722 +typedef int (* const drm_ioctl_t)(struct drm_device *dev, void *data,
76723 + struct drm_file *file_priv);
76724 +typedef int (* drm_ioctl_no_const_t)(struct drm_device *dev, void *data,
76725 struct drm_file *file_priv);
76726
76727 -typedef int drm_ioctl_compat_t(struct file *filp, unsigned int cmd,
76728 +typedef int (* const drm_ioctl_compat_t)(struct file *filp, unsigned int cmd,
76729 unsigned long arg);
76730
76731 #define DRM_IOCTL_NR(n) _IOC_NR(n)
76732 @@ -297,10 +300,10 @@ typedef int drm_ioctl_compat_t(struct file *filp, unsigned int cmd,
76733 struct drm_ioctl_desc {
76734 unsigned int cmd;
76735 int flags;
76736 - drm_ioctl_t *func;
76737 + drm_ioctl_t func;
76738 unsigned int cmd_drv;
76739 const char *name;
76740 -};
76741 +} __do_const;
76742
76743 /**
76744 * Creates a driver or general drm_ioctl_desc array entry for the given
76745 @@ -1013,7 +1016,8 @@ struct drm_info_list {
76746 int (*show)(struct seq_file*, void*); /** show callback */
76747 u32 driver_features; /**< Required driver features for this entry */
76748 void *data;
76749 -};
76750 +} __do_const;
76751 +typedef struct drm_info_list __no_const drm_info_list_no_const;
76752
76753 /**
76754 * debugfs node structure. This structure represents a debugfs file.
76755 @@ -1097,7 +1101,7 @@ struct drm_device {
76756
76757 /** \name Usage Counters */
76758 /*@{ */
76759 - int open_count; /**< Outstanding files open */
76760 + local_t open_count; /**< Outstanding files open */
76761 atomic_t ioctl_count; /**< Outstanding IOCTLs pending */
76762 atomic_t vma_count; /**< Outstanding vma areas open */
76763 int buf_use; /**< Buffers in use -- cannot alloc */
76764 diff --git a/include/drm/drm_crtc_helper.h b/include/drm/drm_crtc_helper.h
76765 index ef6ad3a..be34b16 100644
76766 --- a/include/drm/drm_crtc_helper.h
76767 +++ b/include/drm/drm_crtc_helper.h
76768 @@ -109,7 +109,7 @@ struct drm_encoder_helper_funcs {
76769 struct drm_connector *connector);
76770 /* disable encoder when not in use - more explicit than dpms off */
76771 void (*disable)(struct drm_encoder *encoder);
76772 -};
76773 +} __no_const;
76774
76775 /**
76776 * drm_connector_helper_funcs - helper operations for connectors
76777 diff --git a/include/drm/i915_pciids.h b/include/drm/i915_pciids.h
76778 index 940ece4..8cb727f 100644
76779 --- a/include/drm/i915_pciids.h
76780 +++ b/include/drm/i915_pciids.h
76781 @@ -37,7 +37,7 @@
76782 */
76783 #define INTEL_VGA_DEVICE(id, info) { \
76784 0x8086, id, \
76785 - ~0, ~0, \
76786 + PCI_ANY_ID, PCI_ANY_ID, \
76787 0x030000, 0xff0000, \
76788 (unsigned long) info }
76789
76790 diff --git a/include/drm/ttm/ttm_memory.h b/include/drm/ttm/ttm_memory.h
76791 index 72dcbe8..8db58d7 100644
76792 --- a/include/drm/ttm/ttm_memory.h
76793 +++ b/include/drm/ttm/ttm_memory.h
76794 @@ -48,7 +48,7 @@
76795
76796 struct ttm_mem_shrink {
76797 int (*do_shrink) (struct ttm_mem_shrink *);
76798 -};
76799 +} __no_const;
76800
76801 /**
76802 * struct ttm_mem_global - Global memory accounting structure.
76803 diff --git a/include/drm/ttm/ttm_page_alloc.h b/include/drm/ttm/ttm_page_alloc.h
76804 index d1f61bf..2239439 100644
76805 --- a/include/drm/ttm/ttm_page_alloc.h
76806 +++ b/include/drm/ttm/ttm_page_alloc.h
76807 @@ -78,6 +78,7 @@ void ttm_dma_page_alloc_fini(void);
76808 */
76809 extern int ttm_dma_page_alloc_debugfs(struct seq_file *m, void *data);
76810
76811 +struct device;
76812 extern int ttm_dma_populate(struct ttm_dma_tt *ttm_dma, struct device *dev);
76813 extern void ttm_dma_unpopulate(struct ttm_dma_tt *ttm_dma, struct device *dev);
76814
76815 diff --git a/include/keys/asymmetric-subtype.h b/include/keys/asymmetric-subtype.h
76816 index 4b840e8..155d235 100644
76817 --- a/include/keys/asymmetric-subtype.h
76818 +++ b/include/keys/asymmetric-subtype.h
76819 @@ -37,7 +37,7 @@ struct asymmetric_key_subtype {
76820 /* Verify the signature on a key of this subtype (optional) */
76821 int (*verify_signature)(const struct key *key,
76822 const struct public_key_signature *sig);
76823 -};
76824 +} __do_const;
76825
76826 /**
76827 * asymmetric_key_subtype - Get the subtype from an asymmetric key
76828 diff --git a/include/linux/atmdev.h b/include/linux/atmdev.h
76829 index c1da539..1dcec55 100644
76830 --- a/include/linux/atmdev.h
76831 +++ b/include/linux/atmdev.h
76832 @@ -28,7 +28,7 @@ struct compat_atm_iobuf {
76833 #endif
76834
76835 struct k_atm_aal_stats {
76836 -#define __HANDLE_ITEM(i) atomic_t i
76837 +#define __HANDLE_ITEM(i) atomic_unchecked_t i
76838 __AAL_STAT_ITEMS
76839 #undef __HANDLE_ITEM
76840 };
76841 @@ -200,7 +200,7 @@ struct atmdev_ops { /* only send is required */
76842 int (*change_qos)(struct atm_vcc *vcc,struct atm_qos *qos,int flags);
76843 int (*proc_read)(struct atm_dev *dev,loff_t *pos,char *page);
76844 struct module *owner;
76845 -};
76846 +} __do_const ;
76847
76848 struct atmphy_ops {
76849 int (*start)(struct atm_dev *dev);
76850 diff --git a/include/linux/audit.h b/include/linux/audit.h
76851 index bf1ef22..2a55e1b 100644
76852 --- a/include/linux/audit.h
76853 +++ b/include/linux/audit.h
76854 @@ -195,7 +195,7 @@ static inline void audit_ptrace(struct task_struct *t)
76855 extern unsigned int audit_serial(void);
76856 extern int auditsc_get_stamp(struct audit_context *ctx,
76857 struct timespec *t, unsigned int *serial);
76858 -extern int audit_set_loginuid(kuid_t loginuid);
76859 +extern int __intentional_overflow(-1) audit_set_loginuid(kuid_t loginuid);
76860
76861 static inline kuid_t audit_get_loginuid(struct task_struct *tsk)
76862 {
76863 diff --git a/include/linux/binfmts.h b/include/linux/binfmts.h
76864 index fd8bf32..49a5f5c 100644
76865 --- a/include/linux/binfmts.h
76866 +++ b/include/linux/binfmts.h
76867 @@ -45,7 +45,7 @@ struct linux_binprm {
76868 unsigned interp_data;
76869 unsigned long loader, exec;
76870 char tcomm[TASK_COMM_LEN];
76871 -};
76872 +} __randomize_layout;
76873
76874 #define BINPRM_FLAGS_ENFORCE_NONDUMP_BIT 0
76875 #define BINPRM_FLAGS_ENFORCE_NONDUMP (1 << BINPRM_FLAGS_ENFORCE_NONDUMP_BIT)
76876 @@ -74,8 +74,10 @@ struct linux_binfmt {
76877 int (*load_binary)(struct linux_binprm *);
76878 int (*load_shlib)(struct file *);
76879 int (*core_dump)(struct coredump_params *cprm);
76880 + void (*handle_mprotect)(struct vm_area_struct *vma, unsigned long newflags);
76881 + void (*handle_mmap)(struct file *);
76882 unsigned long min_coredump; /* minimal dump size */
76883 -};
76884 +} __do_const __randomize_layout;
76885
76886 extern void __register_binfmt(struct linux_binfmt *fmt, int insert);
76887
76888 diff --git a/include/linux/bitops.h b/include/linux/bitops.h
76889 index be5fd38..d71192a 100644
76890 --- a/include/linux/bitops.h
76891 +++ b/include/linux/bitops.h
76892 @@ -102,7 +102,7 @@ static inline __u64 ror64(__u64 word, unsigned int shift)
76893 * @word: value to rotate
76894 * @shift: bits to roll
76895 */
76896 -static inline __u32 rol32(__u32 word, unsigned int shift)
76897 +static inline __u32 __intentional_overflow(-1) rol32(__u32 word, unsigned int shift)
76898 {
76899 return (word << shift) | (word >> (32 - shift));
76900 }
76901 @@ -112,7 +112,7 @@ static inline __u32 rol32(__u32 word, unsigned int shift)
76902 * @word: value to rotate
76903 * @shift: bits to roll
76904 */
76905 -static inline __u32 ror32(__u32 word, unsigned int shift)
76906 +static inline __u32 __intentional_overflow(-1) ror32(__u32 word, unsigned int shift)
76907 {
76908 return (word >> shift) | (word << (32 - shift));
76909 }
76910 @@ -168,7 +168,7 @@ static inline __s32 sign_extend32(__u32 value, int index)
76911 return (__s32)(value << shift) >> shift;
76912 }
76913
76914 -static inline unsigned fls_long(unsigned long l)
76915 +static inline unsigned __intentional_overflow(-1) fls_long(unsigned long l)
76916 {
76917 if (sizeof(l) == 4)
76918 return fls(l);
76919 diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
76920 index 1b135d4..59fc876 100644
76921 --- a/include/linux/blkdev.h
76922 +++ b/include/linux/blkdev.h
76923 @@ -1578,7 +1578,7 @@ struct block_device_operations {
76924 /* this callback is with swap_lock and sometimes page table lock held */
76925 void (*swap_slot_free_notify) (struct block_device *, unsigned long);
76926 struct module *owner;
76927 -};
76928 +} __do_const;
76929
76930 extern int __blkdev_driver_ioctl(struct block_device *, fmode_t, unsigned int,
76931 unsigned long);
76932 diff --git a/include/linux/blktrace_api.h b/include/linux/blktrace_api.h
76933 index afc1343..9735539 100644
76934 --- a/include/linux/blktrace_api.h
76935 +++ b/include/linux/blktrace_api.h
76936 @@ -25,7 +25,7 @@ struct blk_trace {
76937 struct dentry *dropped_file;
76938 struct dentry *msg_file;
76939 struct list_head running_list;
76940 - atomic_t dropped;
76941 + atomic_unchecked_t dropped;
76942 };
76943
76944 extern int blk_trace_ioctl(struct block_device *, unsigned, char __user *);
76945 diff --git a/include/linux/cache.h b/include/linux/cache.h
76946 index 4c57065..40346da 100644
76947 --- a/include/linux/cache.h
76948 +++ b/include/linux/cache.h
76949 @@ -16,6 +16,14 @@
76950 #define __read_mostly
76951 #endif
76952
76953 +#ifndef __read_only
76954 +#ifdef CONFIG_PAX_KERNEXEC
76955 +#error KERNEXEC requires __read_only
76956 +#else
76957 +#define __read_only __read_mostly
76958 +#endif
76959 +#endif
76960 +
76961 #ifndef ____cacheline_aligned
76962 #define ____cacheline_aligned __attribute__((__aligned__(SMP_CACHE_BYTES)))
76963 #endif
76964 diff --git a/include/linux/capability.h b/include/linux/capability.h
76965 index a6ee1f9..e1ca49d 100644
76966 --- a/include/linux/capability.h
76967 +++ b/include/linux/capability.h
76968 @@ -212,8 +212,13 @@ extern bool capable(int cap);
76969 extern bool ns_capable(struct user_namespace *ns, int cap);
76970 extern bool inode_capable(const struct inode *inode, int cap);
76971 extern bool file_ns_capable(const struct file *file, struct user_namespace *ns, int cap);
76972 +extern bool capable_nolog(int cap);
76973 +extern bool ns_capable_nolog(struct user_namespace *ns, int cap);
76974 +extern bool inode_capable_nolog(const struct inode *inode, int cap);
76975
76976 /* audit system wants to get cap info from files as well */
76977 extern int get_vfs_caps_from_disk(const struct dentry *dentry, struct cpu_vfs_cap_data *cpu_caps);
76978
76979 +extern int is_privileged_binary(const struct dentry *dentry);
76980 +
76981 #endif /* !_LINUX_CAPABILITY_H */
76982 diff --git a/include/linux/cdrom.h b/include/linux/cdrom.h
76983 index 8609d57..86e4d79 100644
76984 --- a/include/linux/cdrom.h
76985 +++ b/include/linux/cdrom.h
76986 @@ -87,7 +87,6 @@ struct cdrom_device_ops {
76987
76988 /* driver specifications */
76989 const int capability; /* capability flags */
76990 - int n_minors; /* number of active minor devices */
76991 /* handle uniform packets for scsi type devices (scsi,atapi) */
76992 int (*generic_packet) (struct cdrom_device_info *,
76993 struct packet_command *);
76994 diff --git a/include/linux/cleancache.h b/include/linux/cleancache.h
76995 index 4ce9056..86caac6 100644
76996 --- a/include/linux/cleancache.h
76997 +++ b/include/linux/cleancache.h
76998 @@ -31,7 +31,7 @@ struct cleancache_ops {
76999 void (*invalidate_page)(int, struct cleancache_filekey, pgoff_t);
77000 void (*invalidate_inode)(int, struct cleancache_filekey);
77001 void (*invalidate_fs)(int);
77002 -};
77003 +} __no_const;
77004
77005 extern struct cleancache_ops *
77006 cleancache_register_ops(struct cleancache_ops *ops);
77007 diff --git a/include/linux/clk-provider.h b/include/linux/clk-provider.h
77008 index 7e59253..d6e4cae 100644
77009 --- a/include/linux/clk-provider.h
77010 +++ b/include/linux/clk-provider.h
77011 @@ -141,6 +141,7 @@ struct clk_ops {
77012 unsigned long);
77013 void (*init)(struct clk_hw *hw);
77014 };
77015 +typedef struct clk_ops __no_const clk_ops_no_const;
77016
77017 /**
77018 * struct clk_init_data - holds init data that's common to all clocks and is
77019 diff --git a/include/linux/compat.h b/include/linux/compat.h
77020 index 19f6003..90b64f4 100644
77021 --- a/include/linux/compat.h
77022 +++ b/include/linux/compat.h
77023 @@ -313,7 +313,7 @@ compat_sys_get_robust_list(int pid, compat_uptr_t __user *head_ptr,
77024 compat_size_t __user *len_ptr);
77025
77026 asmlinkage long compat_sys_ipc(u32, int, int, u32, compat_uptr_t, u32);
77027 -asmlinkage long compat_sys_shmat(int shmid, compat_uptr_t shmaddr, int shmflg);
77028 +asmlinkage long compat_sys_shmat(int shmid, compat_uptr_t shmaddr, int shmflg) __intentional_overflow(0);
77029 asmlinkage long compat_sys_semctl(int semid, int semnum, int cmd, int arg);
77030 asmlinkage long compat_sys_msgsnd(int msqid, compat_uptr_t msgp,
77031 compat_ssize_t msgsz, int msgflg);
77032 @@ -420,7 +420,7 @@ extern int compat_ptrace_request(struct task_struct *child,
77033 extern long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
77034 compat_ulong_t addr, compat_ulong_t data);
77035 asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
77036 - compat_long_t addr, compat_long_t data);
77037 + compat_ulong_t addr, compat_ulong_t data);
77038
77039 asmlinkage long compat_sys_lookup_dcookie(u32, u32, char __user *, compat_size_t);
77040 /*
77041 diff --git a/include/linux/compiler-gcc4.h b/include/linux/compiler-gcc4.h
77042 index 2507fd2..55203f8 100644
77043 --- a/include/linux/compiler-gcc4.h
77044 +++ b/include/linux/compiler-gcc4.h
77045 @@ -39,9 +39,34 @@
77046 # define __compiletime_warning(message) __attribute__((warning(message)))
77047 # define __compiletime_error(message) __attribute__((error(message)))
77048 #endif /* __CHECKER__ */
77049 +
77050 +#define __alloc_size(...) __attribute((alloc_size(__VA_ARGS__)))
77051 +#define __bos(ptr, arg) __builtin_object_size((ptr), (arg))
77052 +#define __bos0(ptr) __bos((ptr), 0)
77053 +#define __bos1(ptr) __bos((ptr), 1)
77054 #endif /* GCC_VERSION >= 40300 */
77055
77056 #if GCC_VERSION >= 40500
77057 +
77058 +#ifdef RANDSTRUCT_PLUGIN
77059 +#define __randomize_layout __attribute__((randomize_layout))
77060 +#define __no_randomize_layout __attribute__((no_randomize_layout))
77061 +#endif
77062 +
77063 +#ifdef CONSTIFY_PLUGIN
77064 +#define __no_const __attribute__((no_const))
77065 +#define __do_const __attribute__((do_const))
77066 +#endif
77067 +
77068 +#ifdef SIZE_OVERFLOW_PLUGIN
77069 +#define __size_overflow(...) __attribute__((size_overflow(__VA_ARGS__)))
77070 +#define __intentional_overflow(...) __attribute__((intentional_overflow(__VA_ARGS__)))
77071 +#endif
77072 +
77073 +#ifdef LATENT_ENTROPY_PLUGIN
77074 +#define __latent_entropy __attribute__((latent_entropy))
77075 +#endif
77076 +
77077 /*
77078 * Mark a position in code as unreachable. This can be used to
77079 * suppress control flow warnings after asm blocks that transfer
77080 diff --git a/include/linux/compiler.h b/include/linux/compiler.h
77081 index 92669cd..cc564c0 100644
77082 --- a/include/linux/compiler.h
77083 +++ b/include/linux/compiler.h
77084 @@ -5,11 +5,14 @@
77085
77086 #ifdef __CHECKER__
77087 # define __user __attribute__((noderef, address_space(1)))
77088 +# define __force_user __force __user
77089 # define __kernel __attribute__((address_space(0)))
77090 +# define __force_kernel __force __kernel
77091 # define __safe __attribute__((safe))
77092 # define __force __attribute__((force))
77093 # define __nocast __attribute__((nocast))
77094 # define __iomem __attribute__((noderef, address_space(2)))
77095 +# define __force_iomem __force __iomem
77096 # define __must_hold(x) __attribute__((context(x,1,1)))
77097 # define __acquires(x) __attribute__((context(x,0,1)))
77098 # define __releases(x) __attribute__((context(x,1,0)))
77099 @@ -17,20 +20,37 @@
77100 # define __release(x) __context__(x,-1)
77101 # define __cond_lock(x,c) ((c) ? ({ __acquire(x); 1; }) : 0)
77102 # define __percpu __attribute__((noderef, address_space(3)))
77103 +# define __force_percpu __force __percpu
77104 #ifdef CONFIG_SPARSE_RCU_POINTER
77105 # define __rcu __attribute__((noderef, address_space(4)))
77106 +# define __force_rcu __force __rcu
77107 #else
77108 # define __rcu
77109 +# define __force_rcu
77110 #endif
77111 extern void __chk_user_ptr(const volatile void __user *);
77112 extern void __chk_io_ptr(const volatile void __iomem *);
77113 #else
77114 -# define __user
77115 -# define __kernel
77116 +# ifdef CHECKER_PLUGIN
77117 +//# define __user
77118 +//# define __force_user
77119 +//# define __kernel
77120 +//# define __force_kernel
77121 +# else
77122 +# ifdef STRUCTLEAK_PLUGIN
77123 +# define __user __attribute__((user))
77124 +# else
77125 +# define __user
77126 +# endif
77127 +# define __force_user
77128 +# define __kernel
77129 +# define __force_kernel
77130 +# endif
77131 # define __safe
77132 # define __force
77133 # define __nocast
77134 # define __iomem
77135 +# define __force_iomem
77136 # define __chk_user_ptr(x) (void)0
77137 # define __chk_io_ptr(x) (void)0
77138 # define __builtin_warning(x, y...) (1)
77139 @@ -41,7 +61,9 @@ extern void __chk_io_ptr(const volatile void __iomem *);
77140 # define __release(x) (void)0
77141 # define __cond_lock(x,c) (c)
77142 # define __percpu
77143 +# define __force_percpu
77144 # define __rcu
77145 +# define __force_rcu
77146 #endif
77147
77148 /* Indirect macros required for expanded argument pasting, eg. __LINE__. */
77149 @@ -275,6 +297,34 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
77150 # define __attribute_const__ /* unimplemented */
77151 #endif
77152
77153 +#ifndef __randomize_layout
77154 +# define __randomize_layout
77155 +#endif
77156 +
77157 +#ifndef __no_randomize_layout
77158 +# define __no_randomize_layout
77159 +#endif
77160 +
77161 +#ifndef __no_const
77162 +# define __no_const
77163 +#endif
77164 +
77165 +#ifndef __do_const
77166 +# define __do_const
77167 +#endif
77168 +
77169 +#ifndef __size_overflow
77170 +# define __size_overflow(...)
77171 +#endif
77172 +
77173 +#ifndef __intentional_overflow
77174 +# define __intentional_overflow(...)
77175 +#endif
77176 +
77177 +#ifndef __latent_entropy
77178 +# define __latent_entropy
77179 +#endif
77180 +
77181 /*
77182 * Tell gcc if a function is cold. The compiler will assume any path
77183 * directly leading to the call is unlikely.
77184 @@ -284,6 +334,22 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
77185 #define __cold
77186 #endif
77187
77188 +#ifndef __alloc_size
77189 +#define __alloc_size(...)
77190 +#endif
77191 +
77192 +#ifndef __bos
77193 +#define __bos(ptr, arg)
77194 +#endif
77195 +
77196 +#ifndef __bos0
77197 +#define __bos0(ptr)
77198 +#endif
77199 +
77200 +#ifndef __bos1
77201 +#define __bos1(ptr)
77202 +#endif
77203 +
77204 /* Simple shorthand for a section definition */
77205 #ifndef __section
77206 # define __section(S) __attribute__ ((__section__(#S)))
77207 @@ -349,7 +415,8 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
77208 * use is to mediate communication between process-level code and irq/NMI
77209 * handlers, all running on the same CPU.
77210 */
77211 -#define ACCESS_ONCE(x) (*(volatile typeof(x) *)&(x))
77212 +#define ACCESS_ONCE(x) (*(volatile const typeof(x) *)&(x))
77213 +#define ACCESS_ONCE_RW(x) (*(volatile typeof(x) *)&(x))
77214
77215 /* Ignore/forbid kprobes attach on very low level functions marked by this attribute: */
77216 #ifdef CONFIG_KPROBES
77217 diff --git a/include/linux/completion.h b/include/linux/completion.h
77218 index 5d5aaae..0ea9b84 100644
77219 --- a/include/linux/completion.h
77220 +++ b/include/linux/completion.h
77221 @@ -90,16 +90,16 @@ static inline void reinit_completion(struct completion *x)
77222
77223 extern void wait_for_completion(struct completion *);
77224 extern void wait_for_completion_io(struct completion *);
77225 -extern int wait_for_completion_interruptible(struct completion *x);
77226 -extern int wait_for_completion_killable(struct completion *x);
77227 +extern int wait_for_completion_interruptible(struct completion *x) __intentional_overflow(-1);
77228 +extern int wait_for_completion_killable(struct completion *x) __intentional_overflow(-1);
77229 extern unsigned long wait_for_completion_timeout(struct completion *x,
77230 - unsigned long timeout);
77231 + unsigned long timeout) __intentional_overflow(-1);
77232 extern unsigned long wait_for_completion_io_timeout(struct completion *x,
77233 - unsigned long timeout);
77234 + unsigned long timeout) __intentional_overflow(-1);
77235 extern long wait_for_completion_interruptible_timeout(
77236 - struct completion *x, unsigned long timeout);
77237 + struct completion *x, unsigned long timeout) __intentional_overflow(-1);
77238 extern long wait_for_completion_killable_timeout(
77239 - struct completion *x, unsigned long timeout);
77240 + struct completion *x, unsigned long timeout) __intentional_overflow(-1);
77241 extern bool try_wait_for_completion(struct completion *x);
77242 extern bool completion_done(struct completion *x);
77243
77244 diff --git a/include/linux/configfs.h b/include/linux/configfs.h
77245 index 34025df..d94bbbc 100644
77246 --- a/include/linux/configfs.h
77247 +++ b/include/linux/configfs.h
77248 @@ -125,7 +125,7 @@ struct configfs_attribute {
77249 const char *ca_name;
77250 struct module *ca_owner;
77251 umode_t ca_mode;
77252 -};
77253 +} __do_const;
77254
77255 /*
77256 * Users often need to create attribute structures for their configurable
77257 diff --git a/include/linux/cpufreq.h b/include/linux/cpufreq.h
77258 index dc196bb..c55a50f 100644
77259 --- a/include/linux/cpufreq.h
77260 +++ b/include/linux/cpufreq.h
77261 @@ -189,6 +189,7 @@ struct global_attr {
77262 ssize_t (*store)(struct kobject *a, struct attribute *b,
77263 const char *c, size_t count);
77264 };
77265 +typedef struct global_attr __no_const global_attr_no_const;
77266
77267 #define define_one_global_ro(_name) \
77268 static struct global_attr _name = \
77269 @@ -225,7 +226,7 @@ struct cpufreq_driver {
77270 int (*suspend) (struct cpufreq_policy *policy);
77271 int (*resume) (struct cpufreq_policy *policy);
77272 struct freq_attr **attr;
77273 -};
77274 +} __do_const;
77275
77276 /* flags */
77277 #define CPUFREQ_STICKY (1 << 0) /* driver isn't removed even if
77278 diff --git a/include/linux/cpuidle.h b/include/linux/cpuidle.h
77279 index 50fcbb0..9d2dbd9 100644
77280 --- a/include/linux/cpuidle.h
77281 +++ b/include/linux/cpuidle.h
77282 @@ -50,7 +50,8 @@ struct cpuidle_state {
77283 int index);
77284
77285 int (*enter_dead) (struct cpuidle_device *dev, int index);
77286 -};
77287 +} __do_const;
77288 +typedef struct cpuidle_state __no_const cpuidle_state_no_const;
77289
77290 /* Idle State Flags */
77291 #define CPUIDLE_FLAG_TIME_VALID (0x01) /* is residency time measurable? */
77292 @@ -192,7 +193,7 @@ struct cpuidle_governor {
77293 void (*reflect) (struct cpuidle_device *dev, int index);
77294
77295 struct module *owner;
77296 -};
77297 +} __do_const;
77298
77299 #ifdef CONFIG_CPU_IDLE
77300 extern int cpuidle_register_governor(struct cpuidle_governor *gov);
77301 diff --git a/include/linux/cpumask.h b/include/linux/cpumask.h
77302 index d08e4d2..95fad61 100644
77303 --- a/include/linux/cpumask.h
77304 +++ b/include/linux/cpumask.h
77305 @@ -118,17 +118,17 @@ static inline unsigned int cpumask_first(const struct cpumask *srcp)
77306 }
77307
77308 /* Valid inputs for n are -1 and 0. */
77309 -static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
77310 +static inline unsigned int __intentional_overflow(-1) cpumask_next(int n, const struct cpumask *srcp)
77311 {
77312 return n+1;
77313 }
77314
77315 -static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
77316 +static inline unsigned int __intentional_overflow(-1) cpumask_next_zero(int n, const struct cpumask *srcp)
77317 {
77318 return n+1;
77319 }
77320
77321 -static inline unsigned int cpumask_next_and(int n,
77322 +static inline unsigned int __intentional_overflow(-1) cpumask_next_and(int n,
77323 const struct cpumask *srcp,
77324 const struct cpumask *andp)
77325 {
77326 @@ -167,7 +167,7 @@ static inline unsigned int cpumask_first(const struct cpumask *srcp)
77327 *
77328 * Returns >= nr_cpu_ids if no further cpus set.
77329 */
77330 -static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
77331 +static inline unsigned int __intentional_overflow(-1) cpumask_next(int n, const struct cpumask *srcp)
77332 {
77333 /* -1 is a legal arg here. */
77334 if (n != -1)
77335 @@ -182,7 +182,7 @@ static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
77336 *
77337 * Returns >= nr_cpu_ids if no further cpus unset.
77338 */
77339 -static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
77340 +static inline unsigned int __intentional_overflow(-1) cpumask_next_zero(int n, const struct cpumask *srcp)
77341 {
77342 /* -1 is a legal arg here. */
77343 if (n != -1)
77344 @@ -190,7 +190,7 @@ static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
77345 return find_next_zero_bit(cpumask_bits(srcp), nr_cpumask_bits, n+1);
77346 }
77347
77348 -int cpumask_next_and(int n, const struct cpumask *, const struct cpumask *);
77349 +int cpumask_next_and(int n, const struct cpumask *, const struct cpumask *) __intentional_overflow(-1);
77350 int cpumask_any_but(const struct cpumask *mask, unsigned int cpu);
77351
77352 /**
77353 diff --git a/include/linux/cred.h b/include/linux/cred.h
77354 index 04421e8..117e17a 100644
77355 --- a/include/linux/cred.h
77356 +++ b/include/linux/cred.h
77357 @@ -35,7 +35,7 @@ struct group_info {
77358 int nblocks;
77359 kgid_t small_block[NGROUPS_SMALL];
77360 kgid_t *blocks[0];
77361 -};
77362 +} __randomize_layout;
77363
77364 /**
77365 * get_group_info - Get a reference to a group info structure
77366 @@ -136,7 +136,7 @@ struct cred {
77367 struct user_namespace *user_ns; /* user_ns the caps and keyrings are relative to. */
77368 struct group_info *group_info; /* supplementary groups for euid/fsgid */
77369 struct rcu_head rcu; /* RCU deletion hook */
77370 -};
77371 +} __randomize_layout;
77372
77373 extern void __put_cred(struct cred *);
77374 extern void exit_creds(struct task_struct *);
77375 @@ -194,6 +194,9 @@ static inline void validate_creds_for_do_exit(struct task_struct *tsk)
77376 static inline void validate_process_creds(void)
77377 {
77378 }
77379 +static inline void validate_task_creds(struct task_struct *task)
77380 +{
77381 +}
77382 #endif
77383
77384 /**
77385 diff --git a/include/linux/crypto.h b/include/linux/crypto.h
77386 index b92eadf..b4ecdc1 100644
77387 --- a/include/linux/crypto.h
77388 +++ b/include/linux/crypto.h
77389 @@ -373,7 +373,7 @@ struct cipher_tfm {
77390 const u8 *key, unsigned int keylen);
77391 void (*cit_encrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
77392 void (*cit_decrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
77393 -};
77394 +} __no_const;
77395
77396 struct hash_tfm {
77397 int (*init)(struct hash_desc *desc);
77398 @@ -394,13 +394,13 @@ struct compress_tfm {
77399 int (*cot_decompress)(struct crypto_tfm *tfm,
77400 const u8 *src, unsigned int slen,
77401 u8 *dst, unsigned int *dlen);
77402 -};
77403 +} __no_const;
77404
77405 struct rng_tfm {
77406 int (*rng_gen_random)(struct crypto_rng *tfm, u8 *rdata,
77407 unsigned int dlen);
77408 int (*rng_reset)(struct crypto_rng *tfm, u8 *seed, unsigned int slen);
77409 -};
77410 +} __no_const;
77411
77412 #define crt_ablkcipher crt_u.ablkcipher
77413 #define crt_aead crt_u.aead
77414 diff --git a/include/linux/ctype.h b/include/linux/ctype.h
77415 index 653589e..4ef254a 100644
77416 --- a/include/linux/ctype.h
77417 +++ b/include/linux/ctype.h
77418 @@ -56,7 +56,7 @@ static inline unsigned char __toupper(unsigned char c)
77419 * Fast implementation of tolower() for internal usage. Do not use in your
77420 * code.
77421 */
77422 -static inline char _tolower(const char c)
77423 +static inline unsigned char _tolower(const unsigned char c)
77424 {
77425 return c | 0x20;
77426 }
77427 diff --git a/include/linux/dcache.h b/include/linux/dcache.h
77428 index bf72e9a..4ca7927 100644
77429 --- a/include/linux/dcache.h
77430 +++ b/include/linux/dcache.h
77431 @@ -133,7 +133,7 @@ struct dentry {
77432 } d_u;
77433 struct list_head d_subdirs; /* our children */
77434 struct hlist_node d_alias; /* inode alias list */
77435 -};
77436 +} __randomize_layout;
77437
77438 /*
77439 * dentry->d_lock spinlock nesting subclasses:
77440 diff --git a/include/linux/decompress/mm.h b/include/linux/decompress/mm.h
77441 index 7925bf0..d5143d2 100644
77442 --- a/include/linux/decompress/mm.h
77443 +++ b/include/linux/decompress/mm.h
77444 @@ -77,7 +77,7 @@ static void free(void *where)
77445 * warnings when not needed (indeed large_malloc / large_free are not
77446 * needed by inflate */
77447
77448 -#define malloc(a) kmalloc(a, GFP_KERNEL)
77449 +#define malloc(a) kmalloc((a), GFP_KERNEL)
77450 #define free(a) kfree(a)
77451
77452 #define large_malloc(a) vmalloc(a)
77453 diff --git a/include/linux/devfreq.h b/include/linux/devfreq.h
77454 index d48dc00..211ee54 100644
77455 --- a/include/linux/devfreq.h
77456 +++ b/include/linux/devfreq.h
77457 @@ -114,7 +114,7 @@ struct devfreq_governor {
77458 int (*get_target_freq)(struct devfreq *this, unsigned long *freq);
77459 int (*event_handler)(struct devfreq *devfreq,
77460 unsigned int event, void *data);
77461 -};
77462 +} __do_const;
77463
77464 /**
77465 * struct devfreq - Device devfreq structure
77466 diff --git a/include/linux/device.h b/include/linux/device.h
77467 index 952b010..d5b7691 100644
77468 --- a/include/linux/device.h
77469 +++ b/include/linux/device.h
77470 @@ -310,7 +310,7 @@ struct subsys_interface {
77471 struct list_head node;
77472 int (*add_dev)(struct device *dev, struct subsys_interface *sif);
77473 int (*remove_dev)(struct device *dev, struct subsys_interface *sif);
77474 -};
77475 +} __do_const;
77476
77477 int subsys_interface_register(struct subsys_interface *sif);
77478 void subsys_interface_unregister(struct subsys_interface *sif);
77479 @@ -506,7 +506,7 @@ struct device_type {
77480 void (*release)(struct device *dev);
77481
77482 const struct dev_pm_ops *pm;
77483 -};
77484 +} __do_const;
77485
77486 /* interface for exporting device attributes */
77487 struct device_attribute {
77488 @@ -516,11 +516,12 @@ struct device_attribute {
77489 ssize_t (*store)(struct device *dev, struct device_attribute *attr,
77490 const char *buf, size_t count);
77491 };
77492 +typedef struct device_attribute __no_const device_attribute_no_const;
77493
77494 struct dev_ext_attribute {
77495 struct device_attribute attr;
77496 void *var;
77497 -};
77498 +} __do_const;
77499
77500 ssize_t device_show_ulong(struct device *dev, struct device_attribute *attr,
77501 char *buf);
77502 diff --git a/include/linux/dma-mapping.h b/include/linux/dma-mapping.h
77503 index fd4aee2..1f28db9 100644
77504 --- a/include/linux/dma-mapping.h
77505 +++ b/include/linux/dma-mapping.h
77506 @@ -54,7 +54,7 @@ struct dma_map_ops {
77507 u64 (*get_required_mask)(struct device *dev);
77508 #endif
77509 int is_phys;
77510 -};
77511 +} __do_const;
77512
77513 #define DMA_BIT_MASK(n) (((n) == 64) ? ~0ULL : ((1ULL<<(n))-1))
77514
77515 diff --git a/include/linux/dmaengine.h b/include/linux/dmaengine.h
77516 index 41cf0c3..f3b771c 100644
77517 --- a/include/linux/dmaengine.h
77518 +++ b/include/linux/dmaengine.h
77519 @@ -1114,9 +1114,9 @@ struct dma_pinned_list {
77520 struct dma_pinned_list *dma_pin_iovec_pages(struct iovec *iov, size_t len);
77521 void dma_unpin_iovec_pages(struct dma_pinned_list* pinned_list);
77522
77523 -dma_cookie_t dma_memcpy_to_iovec(struct dma_chan *chan, struct iovec *iov,
77524 +dma_cookie_t __intentional_overflow(0) dma_memcpy_to_iovec(struct dma_chan *chan, struct iovec *iov,
77525 struct dma_pinned_list *pinned_list, unsigned char *kdata, size_t len);
77526 -dma_cookie_t dma_memcpy_pg_to_iovec(struct dma_chan *chan, struct iovec *iov,
77527 +dma_cookie_t __intentional_overflow(0) dma_memcpy_pg_to_iovec(struct dma_chan *chan, struct iovec *iov,
77528 struct dma_pinned_list *pinned_list, struct page *page,
77529 unsigned int offset, size_t len);
77530
77531 diff --git a/include/linux/efi.h b/include/linux/efi.h
77532 index 11ce678..7b8c69c 100644
77533 --- a/include/linux/efi.h
77534 +++ b/include/linux/efi.h
77535 @@ -764,6 +764,7 @@ struct efivar_operations {
77536 efi_set_variable_t *set_variable;
77537 efi_query_variable_store_t *query_variable_store;
77538 };
77539 +typedef struct efivar_operations __no_const efivar_operations_no_const;
77540
77541 struct efivars {
77542 /*
77543 diff --git a/include/linux/elf.h b/include/linux/elf.h
77544 index 67a5fa7..b817372 100644
77545 --- a/include/linux/elf.h
77546 +++ b/include/linux/elf.h
77547 @@ -24,6 +24,7 @@ extern Elf32_Dyn _DYNAMIC [];
77548 #define elf_note elf32_note
77549 #define elf_addr_t Elf32_Off
77550 #define Elf_Half Elf32_Half
77551 +#define elf_dyn Elf32_Dyn
77552
77553 #else
77554
77555 @@ -34,6 +35,7 @@ extern Elf64_Dyn _DYNAMIC [];
77556 #define elf_note elf64_note
77557 #define elf_addr_t Elf64_Off
77558 #define Elf_Half Elf64_Half
77559 +#define elf_dyn Elf64_Dyn
77560
77561 #endif
77562
77563 diff --git a/include/linux/err.h b/include/linux/err.h
77564 index 15f92e0..e825a8e 100644
77565 --- a/include/linux/err.h
77566 +++ b/include/linux/err.h
77567 @@ -19,12 +19,12 @@
77568
77569 #define IS_ERR_VALUE(x) unlikely((x) >= (unsigned long)-MAX_ERRNO)
77570
77571 -static inline void * __must_check ERR_PTR(long error)
77572 +static inline void * __must_check __intentional_overflow(-1) ERR_PTR(long error)
77573 {
77574 return (void *) error;
77575 }
77576
77577 -static inline long __must_check PTR_ERR(__force const void *ptr)
77578 +static inline long __must_check __intentional_overflow(-1) PTR_ERR(__force const void *ptr)
77579 {
77580 return (long) ptr;
77581 }
77582 diff --git a/include/linux/extcon.h b/include/linux/extcon.h
77583 index 21c59af..6057a03 100644
77584 --- a/include/linux/extcon.h
77585 +++ b/include/linux/extcon.h
77586 @@ -135,7 +135,7 @@ struct extcon_dev {
77587 /* /sys/class/extcon/.../mutually_exclusive/... */
77588 struct attribute_group attr_g_muex;
77589 struct attribute **attrs_muex;
77590 - struct device_attribute *d_attrs_muex;
77591 + device_attribute_no_const *d_attrs_muex;
77592 };
77593
77594 /**
77595 diff --git a/include/linux/fb.h b/include/linux/fb.h
77596 index 70c4836..ff3daec 100644
77597 --- a/include/linux/fb.h
77598 +++ b/include/linux/fb.h
77599 @@ -304,7 +304,7 @@ struct fb_ops {
77600 /* called at KDB enter and leave time to prepare the console */
77601 int (*fb_debug_enter)(struct fb_info *info);
77602 int (*fb_debug_leave)(struct fb_info *info);
77603 -};
77604 +} __do_const;
77605
77606 #ifdef CONFIG_FB_TILEBLITTING
77607 #define FB_TILE_CURSOR_NONE 0
77608 diff --git a/include/linux/fdtable.h b/include/linux/fdtable.h
77609 index 085197b..0fa6f0b 100644
77610 --- a/include/linux/fdtable.h
77611 +++ b/include/linux/fdtable.h
77612 @@ -95,7 +95,7 @@ struct files_struct *get_files_struct(struct task_struct *);
77613 void put_files_struct(struct files_struct *fs);
77614 void reset_files_struct(struct files_struct *);
77615 int unshare_files(struct files_struct **);
77616 -struct files_struct *dup_fd(struct files_struct *, int *);
77617 +struct files_struct *dup_fd(struct files_struct *, int *) __latent_entropy;
77618 void do_close_on_exec(struct files_struct *);
77619 int iterate_fd(struct files_struct *, unsigned,
77620 int (*)(const void *, struct file *, unsigned),
77621 diff --git a/include/linux/frontswap.h b/include/linux/frontswap.h
77622 index 8293262..2b3b8bd 100644
77623 --- a/include/linux/frontswap.h
77624 +++ b/include/linux/frontswap.h
77625 @@ -11,7 +11,7 @@ struct frontswap_ops {
77626 int (*load)(unsigned, pgoff_t, struct page *);
77627 void (*invalidate_page)(unsigned, pgoff_t);
77628 void (*invalidate_area)(unsigned);
77629 -};
77630 +} __no_const;
77631
77632 extern bool frontswap_enabled;
77633 extern struct frontswap_ops *
77634 diff --git a/include/linux/fs.h b/include/linux/fs.h
77635 index 121f11f..0f2a863 100644
77636 --- a/include/linux/fs.h
77637 +++ b/include/linux/fs.h
77638 @@ -423,7 +423,7 @@ struct address_space {
77639 spinlock_t private_lock; /* for use by the address_space */
77640 struct list_head private_list; /* ditto */
77641 void *private_data; /* ditto */
77642 -} __attribute__((aligned(sizeof(long))));
77643 +} __attribute__((aligned(sizeof(long)))) __randomize_layout;
77644 /*
77645 * On most architectures that alignment is already the case; but
77646 * must be enforced here for CRIS, to let the least significant bit
77647 @@ -466,7 +466,7 @@ struct block_device {
77648 int bd_fsfreeze_count;
77649 /* Mutex for freeze */
77650 struct mutex bd_fsfreeze_mutex;
77651 -};
77652 +} __randomize_layout;
77653
77654 /*
77655 * Radix-tree tags, for tagging dirty and writeback pages within the pagecache
77656 @@ -610,7 +610,7 @@ struct inode {
77657 atomic_t i_readcount; /* struct files open RO */
77658 #endif
77659 void *i_private; /* fs or device private pointer */
77660 -};
77661 +} __randomize_layout;
77662
77663 static inline int inode_unhashed(struct inode *inode)
77664 {
77665 @@ -808,7 +808,7 @@ struct file {
77666 #ifdef CONFIG_DEBUG_WRITECOUNT
77667 unsigned long f_mnt_write_state;
77668 #endif
77669 -};
77670 +} __randomize_layout;
77671
77672 struct file_handle {
77673 __u32 handle_bytes;
77674 @@ -978,7 +978,7 @@ struct file_lock {
77675 int state; /* state of grant or error if -ve */
77676 } afs;
77677 } fl_u;
77678 -};
77679 +} __randomize_layout;
77680
77681 /* The following constant reflects the upper bound of the file/locking space */
77682 #ifndef OFFSET_MAX
77683 @@ -1325,7 +1325,7 @@ struct super_block {
77684 struct list_lru s_dentry_lru ____cacheline_aligned_in_smp;
77685 struct list_lru s_inode_lru ____cacheline_aligned_in_smp;
77686 struct rcu_head rcu;
77687 -};
77688 +} __randomize_layout;
77689
77690 extern struct timespec current_fs_time(struct super_block *sb);
77691
77692 @@ -1547,7 +1547,8 @@ struct file_operations {
77693 long (*fallocate)(struct file *file, int mode, loff_t offset,
77694 loff_t len);
77695 int (*show_fdinfo)(struct seq_file *m, struct file *f);
77696 -};
77697 +} __do_const __randomize_layout;
77698 +typedef struct file_operations __no_const file_operations_no_const;
77699
77700 struct inode_operations {
77701 struct dentry * (*lookup) (struct inode *,struct dentry *, unsigned int);
77702 @@ -2808,4 +2809,14 @@ static inline bool dir_relax(struct inode *inode)
77703 return !IS_DEADDIR(inode);
77704 }
77705
77706 +static inline bool is_sidechannel_device(const struct inode *inode)
77707 +{
77708 +#ifdef CONFIG_GRKERNSEC_DEVICE_SIDECHANNEL
77709 + umode_t mode = inode->i_mode;
77710 + return ((S_ISCHR(mode) || S_ISBLK(mode)) && (mode & (S_IROTH | S_IWOTH)));
77711 +#else
77712 + return false;
77713 +#endif
77714 +}
77715 +
77716 #endif /* _LINUX_FS_H */
77717 diff --git a/include/linux/fs_struct.h b/include/linux/fs_struct.h
77718 index 0efc3e6..fd23610 100644
77719 --- a/include/linux/fs_struct.h
77720 +++ b/include/linux/fs_struct.h
77721 @@ -6,13 +6,13 @@
77722 #include <linux/seqlock.h>
77723
77724 struct fs_struct {
77725 - int users;
77726 + atomic_t users;
77727 spinlock_t lock;
77728 seqcount_t seq;
77729 int umask;
77730 int in_exec;
77731 struct path root, pwd;
77732 -};
77733 +} __randomize_layout;
77734
77735 extern struct kmem_cache *fs_cachep;
77736
77737 diff --git a/include/linux/fscache-cache.h b/include/linux/fscache-cache.h
77738 index 7714849..a4a5c7a 100644
77739 --- a/include/linux/fscache-cache.h
77740 +++ b/include/linux/fscache-cache.h
77741 @@ -113,7 +113,7 @@ struct fscache_operation {
77742 fscache_operation_release_t release;
77743 };
77744
77745 -extern atomic_t fscache_op_debug_id;
77746 +extern atomic_unchecked_t fscache_op_debug_id;
77747 extern void fscache_op_work_func(struct work_struct *work);
77748
77749 extern void fscache_enqueue_operation(struct fscache_operation *);
77750 @@ -135,7 +135,7 @@ static inline void fscache_operation_init(struct fscache_operation *op,
77751 INIT_WORK(&op->work, fscache_op_work_func);
77752 atomic_set(&op->usage, 1);
77753 op->state = FSCACHE_OP_ST_INITIALISED;
77754 - op->debug_id = atomic_inc_return(&fscache_op_debug_id);
77755 + op->debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
77756 op->processor = processor;
77757 op->release = release;
77758 INIT_LIST_HEAD(&op->pend_link);
77759 diff --git a/include/linux/fscache.h b/include/linux/fscache.h
77760 index 115bb81..e7b812b 100644
77761 --- a/include/linux/fscache.h
77762 +++ b/include/linux/fscache.h
77763 @@ -152,7 +152,7 @@ struct fscache_cookie_def {
77764 * - this is mandatory for any object that may have data
77765 */
77766 void (*now_uncached)(void *cookie_netfs_data);
77767 -};
77768 +} __do_const;
77769
77770 /*
77771 * fscache cached network filesystem type
77772 diff --git a/include/linux/fsnotify.h b/include/linux/fsnotify.h
77773 index 1c804b0..1432c2b 100644
77774 --- a/include/linux/fsnotify.h
77775 +++ b/include/linux/fsnotify.h
77776 @@ -195,6 +195,9 @@ static inline void fsnotify_access(struct file *file)
77777 struct inode *inode = file_inode(file);
77778 __u32 mask = FS_ACCESS;
77779
77780 + if (is_sidechannel_device(inode))
77781 + return;
77782 +
77783 if (S_ISDIR(inode->i_mode))
77784 mask |= FS_ISDIR;
77785
77786 @@ -213,6 +216,9 @@ static inline void fsnotify_modify(struct file *file)
77787 struct inode *inode = file_inode(file);
77788 __u32 mask = FS_MODIFY;
77789
77790 + if (is_sidechannel_device(inode))
77791 + return;
77792 +
77793 if (S_ISDIR(inode->i_mode))
77794 mask |= FS_ISDIR;
77795
77796 @@ -315,7 +321,7 @@ static inline void fsnotify_change(struct dentry *dentry, unsigned int ia_valid)
77797 */
77798 static inline const unsigned char *fsnotify_oldname_init(const unsigned char *name)
77799 {
77800 - return kstrdup(name, GFP_KERNEL);
77801 + return (const unsigned char *)kstrdup((const char *)name, GFP_KERNEL);
77802 }
77803
77804 /*
77805 diff --git a/include/linux/genhd.h b/include/linux/genhd.h
77806 index 9f3c275..8bdff5d 100644
77807 --- a/include/linux/genhd.h
77808 +++ b/include/linux/genhd.h
77809 @@ -194,7 +194,7 @@ struct gendisk {
77810 struct kobject *slave_dir;
77811
77812 struct timer_rand_state *random;
77813 - atomic_t sync_io; /* RAID */
77814 + atomic_unchecked_t sync_io; /* RAID */
77815 struct disk_events *ev;
77816 #ifdef CONFIG_BLK_DEV_INTEGRITY
77817 struct blk_integrity *integrity;
77818 @@ -435,7 +435,7 @@ extern void disk_flush_events(struct gendisk *disk, unsigned int mask);
77819 extern unsigned int disk_clear_events(struct gendisk *disk, unsigned int mask);
77820
77821 /* drivers/char/random.c */
77822 -extern void add_disk_randomness(struct gendisk *disk);
77823 +extern void add_disk_randomness(struct gendisk *disk) __latent_entropy;
77824 extern void rand_initialize_disk(struct gendisk *disk);
77825
77826 static inline sector_t get_start_sect(struct block_device *bdev)
77827 diff --git a/include/linux/genl_magic_func.h b/include/linux/genl_magic_func.h
77828 index c0894dd..2fbf10c 100644
77829 --- a/include/linux/genl_magic_func.h
77830 +++ b/include/linux/genl_magic_func.h
77831 @@ -246,7 +246,7 @@ const char *CONCAT_(GENL_MAGIC_FAMILY, _genl_cmd_to_str)(__u8 cmd)
77832 },
77833
77834 #define ZZZ_genl_ops CONCAT_(GENL_MAGIC_FAMILY, _genl_ops)
77835 -static struct genl_ops ZZZ_genl_ops[] __read_mostly = {
77836 +static struct genl_ops ZZZ_genl_ops[] = {
77837 #include GENL_MAGIC_INCLUDE_FILE
77838 };
77839
77840 diff --git a/include/linux/gfp.h b/include/linux/gfp.h
77841 index 9b4dd49..61fd41d 100644
77842 --- a/include/linux/gfp.h
77843 +++ b/include/linux/gfp.h
77844 @@ -35,6 +35,13 @@ struct vm_area_struct;
77845 #define ___GFP_NO_KSWAPD 0x400000u
77846 #define ___GFP_OTHER_NODE 0x800000u
77847 #define ___GFP_WRITE 0x1000000u
77848 +
77849 +#ifdef CONFIG_PAX_USERCOPY_SLABS
77850 +#define ___GFP_USERCOPY 0x2000000u
77851 +#else
77852 +#define ___GFP_USERCOPY 0
77853 +#endif
77854 +
77855 /* If the above are modified, __GFP_BITS_SHIFT may need updating */
77856
77857 /*
77858 @@ -92,6 +99,7 @@ struct vm_area_struct;
77859 #define __GFP_OTHER_NODE ((__force gfp_t)___GFP_OTHER_NODE) /* On behalf of other node */
77860 #define __GFP_KMEMCG ((__force gfp_t)___GFP_KMEMCG) /* Allocation comes from a memcg-accounted resource */
77861 #define __GFP_WRITE ((__force gfp_t)___GFP_WRITE) /* Allocator intends to dirty page */
77862 +#define __GFP_USERCOPY ((__force gfp_t)___GFP_USERCOPY)/* Allocator intends to copy page to/from userland */
77863
77864 /*
77865 * This may seem redundant, but it's a way of annotating false positives vs.
77866 @@ -99,7 +107,7 @@ struct vm_area_struct;
77867 */
77868 #define __GFP_NOTRACK_FALSE_POSITIVE (__GFP_NOTRACK)
77869
77870 -#define __GFP_BITS_SHIFT 25 /* Room for N __GFP_FOO bits */
77871 +#define __GFP_BITS_SHIFT 26 /* Room for N __GFP_FOO bits */
77872 #define __GFP_BITS_MASK ((__force gfp_t)((1 << __GFP_BITS_SHIFT) - 1))
77873
77874 /* This equals 0, but use constants in case they ever change */
77875 @@ -153,6 +161,8 @@ struct vm_area_struct;
77876 /* 4GB DMA on some platforms */
77877 #define GFP_DMA32 __GFP_DMA32
77878
77879 +#define GFP_USERCOPY __GFP_USERCOPY
77880 +
77881 /* Convert GFP flags to their corresponding migrate type */
77882 static inline int allocflags_to_migratetype(gfp_t gfp_flags)
77883 {
77884 diff --git a/include/linux/gracl.h b/include/linux/gracl.h
77885 new file mode 100644
77886 index 0000000..edb2cb6
77887 --- /dev/null
77888 +++ b/include/linux/gracl.h
77889 @@ -0,0 +1,340 @@
77890 +#ifndef GR_ACL_H
77891 +#define GR_ACL_H
77892 +
77893 +#include <linux/grdefs.h>
77894 +#include <linux/resource.h>
77895 +#include <linux/capability.h>
77896 +#include <linux/dcache.h>
77897 +#include <asm/resource.h>
77898 +
77899 +/* Major status information */
77900 +
77901 +#define GR_VERSION "grsecurity 3.0"
77902 +#define GRSECURITY_VERSION 0x3000
77903 +
77904 +enum {
77905 + GR_SHUTDOWN = 0,
77906 + GR_ENABLE = 1,
77907 + GR_SPROLE = 2,
77908 + GR_OLDRELOAD = 3,
77909 + GR_SEGVMOD = 4,
77910 + GR_STATUS = 5,
77911 + GR_UNSPROLE = 6,
77912 + GR_PASSSET = 7,
77913 + GR_SPROLEPAM = 8,
77914 + GR_RELOAD = 9,
77915 +};
77916 +
77917 +/* Password setup definitions
77918 + * kernel/grhash.c */
77919 +enum {
77920 + GR_PW_LEN = 128,
77921 + GR_SALT_LEN = 16,
77922 + GR_SHA_LEN = 32,
77923 +};
77924 +
77925 +enum {
77926 + GR_SPROLE_LEN = 64,
77927 +};
77928 +
77929 +enum {
77930 + GR_NO_GLOB = 0,
77931 + GR_REG_GLOB,
77932 + GR_CREATE_GLOB
77933 +};
77934 +
77935 +#define GR_NLIMITS 32
77936 +
77937 +/* Begin Data Structures */
77938 +
77939 +struct sprole_pw {
77940 + unsigned char *rolename;
77941 + unsigned char salt[GR_SALT_LEN];
77942 + unsigned char sum[GR_SHA_LEN]; /* 256-bit SHA hash of the password */
77943 +};
77944 +
77945 +struct name_entry {
77946 + __u32 key;
77947 + ino_t inode;
77948 + dev_t device;
77949 + char *name;
77950 + __u16 len;
77951 + __u8 deleted;
77952 + struct name_entry *prev;
77953 + struct name_entry *next;
77954 +};
77955 +
77956 +struct inodev_entry {
77957 + struct name_entry *nentry;
77958 + struct inodev_entry *prev;
77959 + struct inodev_entry *next;
77960 +};
77961 +
77962 +struct acl_role_db {
77963 + struct acl_role_label **r_hash;
77964 + __u32 r_size;
77965 +};
77966 +
77967 +struct inodev_db {
77968 + struct inodev_entry **i_hash;
77969 + __u32 i_size;
77970 +};
77971 +
77972 +struct name_db {
77973 + struct name_entry **n_hash;
77974 + __u32 n_size;
77975 +};
77976 +
77977 +struct crash_uid {
77978 + uid_t uid;
77979 + unsigned long expires;
77980 +};
77981 +
77982 +struct gr_hash_struct {
77983 + void **table;
77984 + void **nametable;
77985 + void *first;
77986 + __u32 table_size;
77987 + __u32 used_size;
77988 + int type;
77989 +};
77990 +
77991 +/* Userspace Grsecurity ACL data structures */
77992 +
77993 +struct acl_subject_label {
77994 + char *filename;
77995 + ino_t inode;
77996 + dev_t device;
77997 + __u32 mode;
77998 + kernel_cap_t cap_mask;
77999 + kernel_cap_t cap_lower;
78000 + kernel_cap_t cap_invert_audit;
78001 +
78002 + struct rlimit res[GR_NLIMITS];
78003 + __u32 resmask;
78004 +
78005 + __u8 user_trans_type;
78006 + __u8 group_trans_type;
78007 + uid_t *user_transitions;
78008 + gid_t *group_transitions;
78009 + __u16 user_trans_num;
78010 + __u16 group_trans_num;
78011 +
78012 + __u32 sock_families[2];
78013 + __u32 ip_proto[8];
78014 + __u32 ip_type;
78015 + struct acl_ip_label **ips;
78016 + __u32 ip_num;
78017 + __u32 inaddr_any_override;
78018 +
78019 + __u32 crashes;
78020 + unsigned long expires;
78021 +
78022 + struct acl_subject_label *parent_subject;
78023 + struct gr_hash_struct *hash;
78024 + struct acl_subject_label *prev;
78025 + struct acl_subject_label *next;
78026 +
78027 + struct acl_object_label **obj_hash;
78028 + __u32 obj_hash_size;
78029 + __u16 pax_flags;
78030 +};
78031 +
78032 +struct role_allowed_ip {
78033 + __u32 addr;
78034 + __u32 netmask;
78035 +
78036 + struct role_allowed_ip *prev;
78037 + struct role_allowed_ip *next;
78038 +};
78039 +
78040 +struct role_transition {
78041 + char *rolename;
78042 +
78043 + struct role_transition *prev;
78044 + struct role_transition *next;
78045 +};
78046 +
78047 +struct acl_role_label {
78048 + char *rolename;
78049 + uid_t uidgid;
78050 + __u16 roletype;
78051 +
78052 + __u16 auth_attempts;
78053 + unsigned long expires;
78054 +
78055 + struct acl_subject_label *root_label;
78056 + struct gr_hash_struct *hash;
78057 +
78058 + struct acl_role_label *prev;
78059 + struct acl_role_label *next;
78060 +
78061 + struct role_transition *transitions;
78062 + struct role_allowed_ip *allowed_ips;
78063 + uid_t *domain_children;
78064 + __u16 domain_child_num;
78065 +
78066 + umode_t umask;
78067 +
78068 + struct acl_subject_label **subj_hash;
78069 + __u32 subj_hash_size;
78070 +};
78071 +
78072 +struct user_acl_role_db {
78073 + struct acl_role_label **r_table;
78074 + __u32 num_pointers; /* Number of allocations to track */
78075 + __u32 num_roles; /* Number of roles */
78076 + __u32 num_domain_children; /* Number of domain children */
78077 + __u32 num_subjects; /* Number of subjects */
78078 + __u32 num_objects; /* Number of objects */
78079 +};
78080 +
78081 +struct acl_object_label {
78082 + char *filename;
78083 + ino_t inode;
78084 + dev_t device;
78085 + __u32 mode;
78086 +
78087 + struct acl_subject_label *nested;
78088 + struct acl_object_label *globbed;
78089 +
78090 + /* next two structures not used */
78091 +
78092 + struct acl_object_label *prev;
78093 + struct acl_object_label *next;
78094 +};
78095 +
78096 +struct acl_ip_label {
78097 + char *iface;
78098 + __u32 addr;
78099 + __u32 netmask;
78100 + __u16 low, high;
78101 + __u8 mode;
78102 + __u32 type;
78103 + __u32 proto[8];
78104 +
78105 + /* next two structures not used */
78106 +
78107 + struct acl_ip_label *prev;
78108 + struct acl_ip_label *next;
78109 +};
78110 +
78111 +struct gr_arg {
78112 + struct user_acl_role_db role_db;
78113 + unsigned char pw[GR_PW_LEN];
78114 + unsigned char salt[GR_SALT_LEN];
78115 + unsigned char sum[GR_SHA_LEN];
78116 + unsigned char sp_role[GR_SPROLE_LEN];
78117 + struct sprole_pw *sprole_pws;
78118 + dev_t segv_device;
78119 + ino_t segv_inode;
78120 + uid_t segv_uid;
78121 + __u16 num_sprole_pws;
78122 + __u16 mode;
78123 +};
78124 +
78125 +struct gr_arg_wrapper {
78126 + struct gr_arg *arg;
78127 + __u32 version;
78128 + __u32 size;
78129 +};
78130 +
78131 +struct subject_map {
78132 + struct acl_subject_label *user;
78133 + struct acl_subject_label *kernel;
78134 + struct subject_map *prev;
78135 + struct subject_map *next;
78136 +};
78137 +
78138 +struct acl_subj_map_db {
78139 + struct subject_map **s_hash;
78140 + __u32 s_size;
78141 +};
78142 +
78143 +struct gr_policy_state {
78144 + struct sprole_pw **acl_special_roles;
78145 + __u16 num_sprole_pws;
78146 + struct acl_role_label *kernel_role;
78147 + struct acl_role_label *role_list;
78148 + struct acl_role_label *default_role;
78149 + struct acl_role_db acl_role_set;
78150 + struct acl_subj_map_db subj_map_set;
78151 + struct name_db name_set;
78152 + struct inodev_db inodev_set;
78153 +};
78154 +
78155 +struct gr_alloc_state {
78156 + unsigned long alloc_stack_next;
78157 + unsigned long alloc_stack_size;
78158 + void **alloc_stack;
78159 +};
78160 +
78161 +struct gr_reload_state {
78162 + struct gr_policy_state oldpolicy;
78163 + struct gr_alloc_state oldalloc;
78164 + struct gr_policy_state newpolicy;
78165 + struct gr_alloc_state newalloc;
78166 + struct gr_policy_state *oldpolicy_ptr;
78167 + struct gr_alloc_state *oldalloc_ptr;
78168 + unsigned char oldmode;
78169 +};
78170 +
78171 +/* End Data Structures Section */
78172 +
78173 +/* Hash functions generated by empirical testing by Brad Spengler
78174 + Makes good use of the low bits of the inode. Generally 0-1 times
78175 + in loop for successful match. 0-3 for unsuccessful match.
78176 + Shift/add algorithm with modulus of table size and an XOR*/
78177 +
78178 +static __inline__ unsigned int
78179 +gr_rhash(const uid_t uid, const __u16 type, const unsigned int sz)
78180 +{
78181 + return ((((uid + type) << (16 + type)) ^ uid) % sz);
78182 +}
78183 +
78184 + static __inline__ unsigned int
78185 +gr_shash(const struct acl_subject_label *userp, const unsigned int sz)
78186 +{
78187 + return ((const unsigned long)userp % sz);
78188 +}
78189 +
78190 +static __inline__ unsigned int
78191 +gr_fhash(const ino_t ino, const dev_t dev, const unsigned int sz)
78192 +{
78193 + return (((ino + dev) ^ ((ino << 13) + (ino << 23) + (dev << 9))) % sz);
78194 +}
78195 +
78196 +static __inline__ unsigned int
78197 +gr_nhash(const char *name, const __u16 len, const unsigned int sz)
78198 +{
78199 + return full_name_hash((const unsigned char *)name, len) % sz;
78200 +}
78201 +
78202 +#define FOR_EACH_SUBJECT_START(role,subj,iter) \
78203 + subj = NULL; \
78204 + iter = 0; \
78205 + while (iter < role->subj_hash_size) { \
78206 + if (subj == NULL) \
78207 + subj = role->subj_hash[iter]; \
78208 + if (subj == NULL) { \
78209 + iter++; \
78210 + continue; \
78211 + }
78212 +
78213 +#define FOR_EACH_SUBJECT_END(subj,iter) \
78214 + subj = subj->next; \
78215 + if (subj == NULL) \
78216 + iter++; \
78217 + }
78218 +
78219 +
78220 +#define FOR_EACH_NESTED_SUBJECT_START(role,subj) \
78221 + subj = role->hash->first; \
78222 + while (subj != NULL) {
78223 +
78224 +#define FOR_EACH_NESTED_SUBJECT_END(subj) \
78225 + subj = subj->next; \
78226 + }
78227 +
78228 +#endif
78229 +
78230 diff --git a/include/linux/gracl_compat.h b/include/linux/gracl_compat.h
78231 new file mode 100644
78232 index 0000000..33ebd1f
78233 --- /dev/null
78234 +++ b/include/linux/gracl_compat.h
78235 @@ -0,0 +1,156 @@
78236 +#ifndef GR_ACL_COMPAT_H
78237 +#define GR_ACL_COMPAT_H
78238 +
78239 +#include <linux/resource.h>
78240 +#include <asm/resource.h>
78241 +
78242 +struct sprole_pw_compat {
78243 + compat_uptr_t rolename;
78244 + unsigned char salt[GR_SALT_LEN];
78245 + unsigned char sum[GR_SHA_LEN];
78246 +};
78247 +
78248 +struct gr_hash_struct_compat {
78249 + compat_uptr_t table;
78250 + compat_uptr_t nametable;
78251 + compat_uptr_t first;
78252 + __u32 table_size;
78253 + __u32 used_size;
78254 + int type;
78255 +};
78256 +
78257 +struct acl_subject_label_compat {
78258 + compat_uptr_t filename;
78259 + compat_ino_t inode;
78260 + __u32 device;
78261 + __u32 mode;
78262 + kernel_cap_t cap_mask;
78263 + kernel_cap_t cap_lower;
78264 + kernel_cap_t cap_invert_audit;
78265 +
78266 + struct compat_rlimit res[GR_NLIMITS];
78267 + __u32 resmask;
78268 +
78269 + __u8 user_trans_type;
78270 + __u8 group_trans_type;
78271 + compat_uptr_t user_transitions;
78272 + compat_uptr_t group_transitions;
78273 + __u16 user_trans_num;
78274 + __u16 group_trans_num;
78275 +
78276 + __u32 sock_families[2];
78277 + __u32 ip_proto[8];
78278 + __u32 ip_type;
78279 + compat_uptr_t ips;
78280 + __u32 ip_num;
78281 + __u32 inaddr_any_override;
78282 +
78283 + __u32 crashes;
78284 + compat_ulong_t expires;
78285 +
78286 + compat_uptr_t parent_subject;
78287 + compat_uptr_t hash;
78288 + compat_uptr_t prev;
78289 + compat_uptr_t next;
78290 +
78291 + compat_uptr_t obj_hash;
78292 + __u32 obj_hash_size;
78293 + __u16 pax_flags;
78294 +};
78295 +
78296 +struct role_allowed_ip_compat {
78297 + __u32 addr;
78298 + __u32 netmask;
78299 +
78300 + compat_uptr_t prev;
78301 + compat_uptr_t next;
78302 +};
78303 +
78304 +struct role_transition_compat {
78305 + compat_uptr_t rolename;
78306 +
78307 + compat_uptr_t prev;
78308 + compat_uptr_t next;
78309 +};
78310 +
78311 +struct acl_role_label_compat {
78312 + compat_uptr_t rolename;
78313 + uid_t uidgid;
78314 + __u16 roletype;
78315 +
78316 + __u16 auth_attempts;
78317 + compat_ulong_t expires;
78318 +
78319 + compat_uptr_t root_label;
78320 + compat_uptr_t hash;
78321 +
78322 + compat_uptr_t prev;
78323 + compat_uptr_t next;
78324 +
78325 + compat_uptr_t transitions;
78326 + compat_uptr_t allowed_ips;
78327 + compat_uptr_t domain_children;
78328 + __u16 domain_child_num;
78329 +
78330 + umode_t umask;
78331 +
78332 + compat_uptr_t subj_hash;
78333 + __u32 subj_hash_size;
78334 +};
78335 +
78336 +struct user_acl_role_db_compat {
78337 + compat_uptr_t r_table;
78338 + __u32 num_pointers;
78339 + __u32 num_roles;
78340 + __u32 num_domain_children;
78341 + __u32 num_subjects;
78342 + __u32 num_objects;
78343 +};
78344 +
78345 +struct acl_object_label_compat {
78346 + compat_uptr_t filename;
78347 + compat_ino_t inode;
78348 + __u32 device;
78349 + __u32 mode;
78350 +
78351 + compat_uptr_t nested;
78352 + compat_uptr_t globbed;
78353 +
78354 + compat_uptr_t prev;
78355 + compat_uptr_t next;
78356 +};
78357 +
78358 +struct acl_ip_label_compat {
78359 + compat_uptr_t iface;
78360 + __u32 addr;
78361 + __u32 netmask;
78362 + __u16 low, high;
78363 + __u8 mode;
78364 + __u32 type;
78365 + __u32 proto[8];
78366 +
78367 + compat_uptr_t prev;
78368 + compat_uptr_t next;
78369 +};
78370 +
78371 +struct gr_arg_compat {
78372 + struct user_acl_role_db_compat role_db;
78373 + unsigned char pw[GR_PW_LEN];
78374 + unsigned char salt[GR_SALT_LEN];
78375 + unsigned char sum[GR_SHA_LEN];
78376 + unsigned char sp_role[GR_SPROLE_LEN];
78377 + compat_uptr_t sprole_pws;
78378 + __u32 segv_device;
78379 + compat_ino_t segv_inode;
78380 + uid_t segv_uid;
78381 + __u16 num_sprole_pws;
78382 + __u16 mode;
78383 +};
78384 +
78385 +struct gr_arg_wrapper_compat {
78386 + compat_uptr_t arg;
78387 + __u32 version;
78388 + __u32 size;
78389 +};
78390 +
78391 +#endif
78392 diff --git a/include/linux/gralloc.h b/include/linux/gralloc.h
78393 new file mode 100644
78394 index 0000000..323ecf2
78395 --- /dev/null
78396 +++ b/include/linux/gralloc.h
78397 @@ -0,0 +1,9 @@
78398 +#ifndef __GRALLOC_H
78399 +#define __GRALLOC_H
78400 +
78401 +void acl_free_all(void);
78402 +int acl_alloc_stack_init(unsigned long size);
78403 +void *acl_alloc(unsigned long len);
78404 +void *acl_alloc_num(unsigned long num, unsigned long len);
78405 +
78406 +#endif
78407 diff --git a/include/linux/grdefs.h b/include/linux/grdefs.h
78408 new file mode 100644
78409 index 0000000..be66033
78410 --- /dev/null
78411 +++ b/include/linux/grdefs.h
78412 @@ -0,0 +1,140 @@
78413 +#ifndef GRDEFS_H
78414 +#define GRDEFS_H
78415 +
78416 +/* Begin grsecurity status declarations */
78417 +
78418 +enum {
78419 + GR_READY = 0x01,
78420 + GR_STATUS_INIT = 0x00 // disabled state
78421 +};
78422 +
78423 +/* Begin ACL declarations */
78424 +
78425 +/* Role flags */
78426 +
78427 +enum {
78428 + GR_ROLE_USER = 0x0001,
78429 + GR_ROLE_GROUP = 0x0002,
78430 + GR_ROLE_DEFAULT = 0x0004,
78431 + GR_ROLE_SPECIAL = 0x0008,
78432 + GR_ROLE_AUTH = 0x0010,
78433 + GR_ROLE_NOPW = 0x0020,
78434 + GR_ROLE_GOD = 0x0040,
78435 + GR_ROLE_LEARN = 0x0080,
78436 + GR_ROLE_TPE = 0x0100,
78437 + GR_ROLE_DOMAIN = 0x0200,
78438 + GR_ROLE_PAM = 0x0400,
78439 + GR_ROLE_PERSIST = 0x0800
78440 +};
78441 +
78442 +/* ACL Subject and Object mode flags */
78443 +enum {
78444 + GR_DELETED = 0x80000000
78445 +};
78446 +
78447 +/* ACL Object-only mode flags */
78448 +enum {
78449 + GR_READ = 0x00000001,
78450 + GR_APPEND = 0x00000002,
78451 + GR_WRITE = 0x00000004,
78452 + GR_EXEC = 0x00000008,
78453 + GR_FIND = 0x00000010,
78454 + GR_INHERIT = 0x00000020,
78455 + GR_SETID = 0x00000040,
78456 + GR_CREATE = 0x00000080,
78457 + GR_DELETE = 0x00000100,
78458 + GR_LINK = 0x00000200,
78459 + GR_AUDIT_READ = 0x00000400,
78460 + GR_AUDIT_APPEND = 0x00000800,
78461 + GR_AUDIT_WRITE = 0x00001000,
78462 + GR_AUDIT_EXEC = 0x00002000,
78463 + GR_AUDIT_FIND = 0x00004000,
78464 + GR_AUDIT_INHERIT= 0x00008000,
78465 + GR_AUDIT_SETID = 0x00010000,
78466 + GR_AUDIT_CREATE = 0x00020000,
78467 + GR_AUDIT_DELETE = 0x00040000,
78468 + GR_AUDIT_LINK = 0x00080000,
78469 + GR_PTRACERD = 0x00100000,
78470 + GR_NOPTRACE = 0x00200000,
78471 + GR_SUPPRESS = 0x00400000,
78472 + GR_NOLEARN = 0x00800000,
78473 + GR_INIT_TRANSFER= 0x01000000
78474 +};
78475 +
78476 +#define GR_AUDITS (GR_AUDIT_READ | GR_AUDIT_WRITE | GR_AUDIT_APPEND | GR_AUDIT_EXEC | \
78477 + GR_AUDIT_FIND | GR_AUDIT_INHERIT | GR_AUDIT_SETID | \
78478 + GR_AUDIT_CREATE | GR_AUDIT_DELETE | GR_AUDIT_LINK)
78479 +
78480 +/* ACL subject-only mode flags */
78481 +enum {
78482 + GR_KILL = 0x00000001,
78483 + GR_VIEW = 0x00000002,
78484 + GR_PROTECTED = 0x00000004,
78485 + GR_LEARN = 0x00000008,
78486 + GR_OVERRIDE = 0x00000010,
78487 + /* just a placeholder, this mode is only used in userspace */
78488 + GR_DUMMY = 0x00000020,
78489 + GR_PROTSHM = 0x00000040,
78490 + GR_KILLPROC = 0x00000080,
78491 + GR_KILLIPPROC = 0x00000100,
78492 + /* just a placeholder, this mode is only used in userspace */
78493 + GR_NOTROJAN = 0x00000200,
78494 + GR_PROTPROCFD = 0x00000400,
78495 + GR_PROCACCT = 0x00000800,
78496 + GR_RELAXPTRACE = 0x00001000,
78497 + //GR_NESTED = 0x00002000,
78498 + GR_INHERITLEARN = 0x00004000,
78499 + GR_PROCFIND = 0x00008000,
78500 + GR_POVERRIDE = 0x00010000,
78501 + GR_KERNELAUTH = 0x00020000,
78502 + GR_ATSECURE = 0x00040000,
78503 + GR_SHMEXEC = 0x00080000
78504 +};
78505 +
78506 +enum {
78507 + GR_PAX_ENABLE_SEGMEXEC = 0x0001,
78508 + GR_PAX_ENABLE_PAGEEXEC = 0x0002,
78509 + GR_PAX_ENABLE_MPROTECT = 0x0004,
78510 + GR_PAX_ENABLE_RANDMMAP = 0x0008,
78511 + GR_PAX_ENABLE_EMUTRAMP = 0x0010,
78512 + GR_PAX_DISABLE_SEGMEXEC = 0x0100,
78513 + GR_PAX_DISABLE_PAGEEXEC = 0x0200,
78514 + GR_PAX_DISABLE_MPROTECT = 0x0400,
78515 + GR_PAX_DISABLE_RANDMMAP = 0x0800,
78516 + GR_PAX_DISABLE_EMUTRAMP = 0x1000,
78517 +};
78518 +
78519 +enum {
78520 + GR_ID_USER = 0x01,
78521 + GR_ID_GROUP = 0x02,
78522 +};
78523 +
78524 +enum {
78525 + GR_ID_ALLOW = 0x01,
78526 + GR_ID_DENY = 0x02,
78527 +};
78528 +
78529 +#define GR_CRASH_RES 31
78530 +#define GR_UIDTABLE_MAX 500
78531 +
78532 +/* begin resource learning section */
78533 +enum {
78534 + GR_RLIM_CPU_BUMP = 60,
78535 + GR_RLIM_FSIZE_BUMP = 50000,
78536 + GR_RLIM_DATA_BUMP = 10000,
78537 + GR_RLIM_STACK_BUMP = 1000,
78538 + GR_RLIM_CORE_BUMP = 10000,
78539 + GR_RLIM_RSS_BUMP = 500000,
78540 + GR_RLIM_NPROC_BUMP = 1,
78541 + GR_RLIM_NOFILE_BUMP = 5,
78542 + GR_RLIM_MEMLOCK_BUMP = 50000,
78543 + GR_RLIM_AS_BUMP = 500000,
78544 + GR_RLIM_LOCKS_BUMP = 2,
78545 + GR_RLIM_SIGPENDING_BUMP = 5,
78546 + GR_RLIM_MSGQUEUE_BUMP = 10000,
78547 + GR_RLIM_NICE_BUMP = 1,
78548 + GR_RLIM_RTPRIO_BUMP = 1,
78549 + GR_RLIM_RTTIME_BUMP = 1000000
78550 +};
78551 +
78552 +#endif
78553 diff --git a/include/linux/grinternal.h b/include/linux/grinternal.h
78554 new file mode 100644
78555 index 0000000..d25522e
78556 --- /dev/null
78557 +++ b/include/linux/grinternal.h
78558 @@ -0,0 +1,229 @@
78559 +#ifndef __GRINTERNAL_H
78560 +#define __GRINTERNAL_H
78561 +
78562 +#ifdef CONFIG_GRKERNSEC
78563 +
78564 +#include <linux/fs.h>
78565 +#include <linux/mnt_namespace.h>
78566 +#include <linux/nsproxy.h>
78567 +#include <linux/gracl.h>
78568 +#include <linux/grdefs.h>
78569 +#include <linux/grmsg.h>
78570 +
78571 +void gr_add_learn_entry(const char *fmt, ...)
78572 + __attribute__ ((format (printf, 1, 2)));
78573 +__u32 gr_search_file(const struct dentry *dentry, const __u32 mode,
78574 + const struct vfsmount *mnt);
78575 +__u32 gr_check_create(const struct dentry *new_dentry,
78576 + const struct dentry *parent,
78577 + const struct vfsmount *mnt, const __u32 mode);
78578 +int gr_check_protected_task(const struct task_struct *task);
78579 +__u32 to_gr_audit(const __u32 reqmode);
78580 +int gr_set_acls(const int type);
78581 +int gr_acl_is_enabled(void);
78582 +char gr_roletype_to_char(void);
78583 +
78584 +void gr_handle_alertkill(struct task_struct *task);
78585 +char *gr_to_filename(const struct dentry *dentry,
78586 + const struct vfsmount *mnt);
78587 +char *gr_to_filename1(const struct dentry *dentry,
78588 + const struct vfsmount *mnt);
78589 +char *gr_to_filename2(const struct dentry *dentry,
78590 + const struct vfsmount *mnt);
78591 +char *gr_to_filename3(const struct dentry *dentry,
78592 + const struct vfsmount *mnt);
78593 +
78594 +extern int grsec_enable_ptrace_readexec;
78595 +extern int grsec_enable_harden_ptrace;
78596 +extern int grsec_enable_link;
78597 +extern int grsec_enable_fifo;
78598 +extern int grsec_enable_execve;
78599 +extern int grsec_enable_shm;
78600 +extern int grsec_enable_execlog;
78601 +extern int grsec_enable_signal;
78602 +extern int grsec_enable_audit_ptrace;
78603 +extern int grsec_enable_forkfail;
78604 +extern int grsec_enable_time;
78605 +extern int grsec_enable_rofs;
78606 +extern int grsec_deny_new_usb;
78607 +extern int grsec_enable_chroot_shmat;
78608 +extern int grsec_enable_chroot_mount;
78609 +extern int grsec_enable_chroot_double;
78610 +extern int grsec_enable_chroot_pivot;
78611 +extern int grsec_enable_chroot_chdir;
78612 +extern int grsec_enable_chroot_chmod;
78613 +extern int grsec_enable_chroot_mknod;
78614 +extern int grsec_enable_chroot_fchdir;
78615 +extern int grsec_enable_chroot_nice;
78616 +extern int grsec_enable_chroot_execlog;
78617 +extern int grsec_enable_chroot_caps;
78618 +extern int grsec_enable_chroot_sysctl;
78619 +extern int grsec_enable_chroot_unix;
78620 +extern int grsec_enable_symlinkown;
78621 +extern kgid_t grsec_symlinkown_gid;
78622 +extern int grsec_enable_tpe;
78623 +extern kgid_t grsec_tpe_gid;
78624 +extern int grsec_enable_tpe_all;
78625 +extern int grsec_enable_tpe_invert;
78626 +extern int grsec_enable_socket_all;
78627 +extern kgid_t grsec_socket_all_gid;
78628 +extern int grsec_enable_socket_client;
78629 +extern kgid_t grsec_socket_client_gid;
78630 +extern int grsec_enable_socket_server;
78631 +extern kgid_t grsec_socket_server_gid;
78632 +extern kgid_t grsec_audit_gid;
78633 +extern int grsec_enable_group;
78634 +extern int grsec_enable_log_rwxmaps;
78635 +extern int grsec_enable_mount;
78636 +extern int grsec_enable_chdir;
78637 +extern int grsec_resource_logging;
78638 +extern int grsec_enable_blackhole;
78639 +extern int grsec_lastack_retries;
78640 +extern int grsec_enable_brute;
78641 +extern int grsec_enable_harden_ipc;
78642 +extern int grsec_lock;
78643 +
78644 +extern spinlock_t grsec_alert_lock;
78645 +extern unsigned long grsec_alert_wtime;
78646 +extern unsigned long grsec_alert_fyet;
78647 +
78648 +extern spinlock_t grsec_audit_lock;
78649 +
78650 +extern rwlock_t grsec_exec_file_lock;
78651 +
78652 +#define gr_task_fullpath(tsk) ((tsk)->exec_file ? \
78653 + gr_to_filename2((tsk)->exec_file->f_path.dentry, \
78654 + (tsk)->exec_file->f_path.mnt) : "/")
78655 +
78656 +#define gr_parent_task_fullpath(tsk) ((tsk)->real_parent->exec_file ? \
78657 + gr_to_filename3((tsk)->real_parent->exec_file->f_path.dentry, \
78658 + (tsk)->real_parent->exec_file->f_path.mnt) : "/")
78659 +
78660 +#define gr_task_fullpath0(tsk) ((tsk)->exec_file ? \
78661 + gr_to_filename((tsk)->exec_file->f_path.dentry, \
78662 + (tsk)->exec_file->f_path.mnt) : "/")
78663 +
78664 +#define gr_parent_task_fullpath0(tsk) ((tsk)->real_parent->exec_file ? \
78665 + gr_to_filename1((tsk)->real_parent->exec_file->f_path.dentry, \
78666 + (tsk)->real_parent->exec_file->f_path.mnt) : "/")
78667 +
78668 +#define proc_is_chrooted(tsk_a) ((tsk_a)->gr_is_chrooted)
78669 +
78670 +#define have_same_root(tsk_a,tsk_b) ((tsk_a)->gr_chroot_dentry == (tsk_b)->gr_chroot_dentry)
78671 +
78672 +static inline bool gr_is_same_file(const struct file *file1, const struct file *file2)
78673 +{
78674 + if (file1 && file2) {
78675 + const struct inode *inode1 = file1->f_path.dentry->d_inode;
78676 + const struct inode *inode2 = file2->f_path.dentry->d_inode;
78677 + if (inode1->i_ino == inode2->i_ino && inode1->i_sb->s_dev == inode2->i_sb->s_dev)
78678 + return true;
78679 + }
78680 +
78681 + return false;
78682 +}
78683 +
78684 +#define GR_CHROOT_CAPS {{ \
78685 + CAP_TO_MASK(CAP_LINUX_IMMUTABLE) | CAP_TO_MASK(CAP_NET_ADMIN) | \
78686 + CAP_TO_MASK(CAP_SYS_MODULE) | CAP_TO_MASK(CAP_SYS_RAWIO) | \
78687 + CAP_TO_MASK(CAP_SYS_PACCT) | CAP_TO_MASK(CAP_SYS_ADMIN) | \
78688 + CAP_TO_MASK(CAP_SYS_BOOT) | CAP_TO_MASK(CAP_SYS_TIME) | \
78689 + CAP_TO_MASK(CAP_NET_RAW) | CAP_TO_MASK(CAP_SYS_TTY_CONFIG) | \
78690 + CAP_TO_MASK(CAP_IPC_OWNER) | CAP_TO_MASK(CAP_SETFCAP), \
78691 + CAP_TO_MASK(CAP_SYSLOG) | CAP_TO_MASK(CAP_MAC_ADMIN) }}
78692 +
78693 +#define security_learn(normal_msg,args...) \
78694 +({ \
78695 + read_lock(&grsec_exec_file_lock); \
78696 + gr_add_learn_entry(normal_msg "\n", ## args); \
78697 + read_unlock(&grsec_exec_file_lock); \
78698 +})
78699 +
78700 +enum {
78701 + GR_DO_AUDIT,
78702 + GR_DONT_AUDIT,
78703 + /* used for non-audit messages that we shouldn't kill the task on */
78704 + GR_DONT_AUDIT_GOOD
78705 +};
78706 +
78707 +enum {
78708 + GR_TTYSNIFF,
78709 + GR_RBAC,
78710 + GR_RBAC_STR,
78711 + GR_STR_RBAC,
78712 + GR_RBAC_MODE2,
78713 + GR_RBAC_MODE3,
78714 + GR_FILENAME,
78715 + GR_SYSCTL_HIDDEN,
78716 + GR_NOARGS,
78717 + GR_ONE_INT,
78718 + GR_ONE_INT_TWO_STR,
78719 + GR_ONE_STR,
78720 + GR_STR_INT,
78721 + GR_TWO_STR_INT,
78722 + GR_TWO_INT,
78723 + GR_TWO_U64,
78724 + GR_THREE_INT,
78725 + GR_FIVE_INT_TWO_STR,
78726 + GR_TWO_STR,
78727 + GR_THREE_STR,
78728 + GR_FOUR_STR,
78729 + GR_STR_FILENAME,
78730 + GR_FILENAME_STR,
78731 + GR_FILENAME_TWO_INT,
78732 + GR_FILENAME_TWO_INT_STR,
78733 + GR_TEXTREL,
78734 + GR_PTRACE,
78735 + GR_RESOURCE,
78736 + GR_CAP,
78737 + GR_SIG,
78738 + GR_SIG2,
78739 + GR_CRASH1,
78740 + GR_CRASH2,
78741 + GR_PSACCT,
78742 + GR_RWXMAP,
78743 + GR_RWXMAPVMA
78744 +};
78745 +
78746 +#define gr_log_hidden_sysctl(audit, msg, str) gr_log_varargs(audit, msg, GR_SYSCTL_HIDDEN, str)
78747 +#define gr_log_ttysniff(audit, msg, task) gr_log_varargs(audit, msg, GR_TTYSNIFF, task)
78748 +#define gr_log_fs_rbac_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_RBAC, dentry, mnt)
78749 +#define gr_log_fs_rbac_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_RBAC_STR, dentry, mnt, str)
78750 +#define gr_log_fs_str_rbac(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_RBAC, str, dentry, mnt)
78751 +#define gr_log_fs_rbac_mode2(audit, msg, dentry, mnt, str1, str2) gr_log_varargs(audit, msg, GR_RBAC_MODE2, dentry, mnt, str1, str2)
78752 +#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)
78753 +#define gr_log_fs_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_FILENAME, dentry, mnt)
78754 +#define gr_log_noargs(audit, msg) gr_log_varargs(audit, msg, GR_NOARGS)
78755 +#define gr_log_int(audit, msg, num) gr_log_varargs(audit, msg, GR_ONE_INT, num)
78756 +#define gr_log_int_str2(audit, msg, num, str1, str2) gr_log_varargs(audit, msg, GR_ONE_INT_TWO_STR, num, str1, str2)
78757 +#define gr_log_str(audit, msg, str) gr_log_varargs(audit, msg, GR_ONE_STR, str)
78758 +#define gr_log_str_int(audit, msg, str, num) gr_log_varargs(audit, msg, GR_STR_INT, str, num)
78759 +#define gr_log_int_int(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_INT, num1, num2)
78760 +#define gr_log_two_u64(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_U64, num1, num2)
78761 +#define gr_log_int3(audit, msg, num1, num2, num3) gr_log_varargs(audit, msg, GR_THREE_INT, num1, num2, num3)
78762 +#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)
78763 +#define gr_log_str_str(audit, msg, str1, str2) gr_log_varargs(audit, msg, GR_TWO_STR, str1, str2)
78764 +#define gr_log_str2_int(audit, msg, str1, str2, num) gr_log_varargs(audit, msg, GR_TWO_STR_INT, str1, str2, num)
78765 +#define gr_log_str3(audit, msg, str1, str2, str3) gr_log_varargs(audit, msg, GR_THREE_STR, str1, str2, str3)
78766 +#define gr_log_str4(audit, msg, str1, str2, str3, str4) gr_log_varargs(audit, msg, GR_FOUR_STR, str1, str2, str3, str4)
78767 +#define gr_log_str_fs(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_FILENAME, str, dentry, mnt)
78768 +#define gr_log_fs_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_FILENAME_STR, dentry, mnt, str)
78769 +#define gr_log_fs_int2(audit, msg, dentry, mnt, num1, num2) gr_log_varargs(audit, msg, GR_FILENAME_TWO_INT, dentry, mnt, num1, num2)
78770 +#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)
78771 +#define gr_log_textrel_ulong_ulong(audit, msg, file, ulong1, ulong2) gr_log_varargs(audit, msg, GR_TEXTREL, file, ulong1, ulong2)
78772 +#define gr_log_ptrace(audit, msg, task) gr_log_varargs(audit, msg, GR_PTRACE, task)
78773 +#define gr_log_res_ulong2_str(audit, msg, task, ulong1, str, ulong2) gr_log_varargs(audit, msg, GR_RESOURCE, task, ulong1, str, ulong2)
78774 +#define gr_log_cap(audit, msg, task, str) gr_log_varargs(audit, msg, GR_CAP, task, str)
78775 +#define gr_log_sig_addr(audit, msg, str, addr) gr_log_varargs(audit, msg, GR_SIG, str, addr)
78776 +#define gr_log_sig_task(audit, msg, task, num) gr_log_varargs(audit, msg, GR_SIG2, task, num)
78777 +#define gr_log_crash1(audit, msg, task, ulong) gr_log_varargs(audit, msg, GR_CRASH1, task, ulong)
78778 +#define gr_log_crash2(audit, msg, task, ulong1) gr_log_varargs(audit, msg, GR_CRASH2, task, ulong1)
78779 +#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)
78780 +#define gr_log_rwxmap(audit, msg, str) gr_log_varargs(audit, msg, GR_RWXMAP, str)
78781 +#define gr_log_rwxmap_vma(audit, msg, str) gr_log_varargs(audit, msg, GR_RWXMAPVMA, str)
78782 +
78783 +void gr_log_varargs(int audit, const char *msg, int argtypes, ...);
78784 +
78785 +#endif
78786 +
78787 +#endif
78788 diff --git a/include/linux/grmsg.h b/include/linux/grmsg.h
78789 new file mode 100644
78790 index 0000000..ba93581
78791 --- /dev/null
78792 +++ b/include/linux/grmsg.h
78793 @@ -0,0 +1,116 @@
78794 +#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"
78795 +#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"
78796 +#define GR_PTRACE_ACL_MSG "denied ptrace of %.950s(%.16s:%d) by "
78797 +#define GR_STOPMOD_MSG "denied modification of module state by "
78798 +#define GR_ROFS_BLOCKWRITE_MSG "denied write to block device %.950s by "
78799 +#define GR_ROFS_MOUNT_MSG "denied writable mount of %.950s by "
78800 +#define GR_IOPERM_MSG "denied use of ioperm() by "
78801 +#define GR_IOPL_MSG "denied use of iopl() by "
78802 +#define GR_SHMAT_ACL_MSG "denied attach of shared memory of UID %u, PID %d, ID %u by "
78803 +#define GR_UNIX_CHROOT_MSG "denied connect() to abstract AF_UNIX socket outside of chroot by "
78804 +#define GR_SHMAT_CHROOT_MSG "denied attach of shared memory outside of chroot by "
78805 +#define GR_MEM_READWRITE_MSG "denied access of range %Lx -> %Lx in /dev/mem by "
78806 +#define GR_SYMLINK_MSG "not following symlink %.950s owned by %d.%d by "
78807 +#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"
78808 +#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"
78809 +#define GR_HIDDEN_ACL_MSG "%s access to hidden file %.950s by "
78810 +#define GR_OPEN_ACL_MSG "%s open of %.950s for%s%s by "
78811 +#define GR_CREATE_ACL_MSG "%s create of %.950s for%s%s by "
78812 +#define GR_FIFO_MSG "denied writing FIFO %.950s of %d.%d by "
78813 +#define GR_MKNOD_CHROOT_MSG "denied mknod of %.950s from chroot by "
78814 +#define GR_MKNOD_ACL_MSG "%s mknod of %.950s by "
78815 +#define GR_UNIXCONNECT_ACL_MSG "%s connect() to the unix domain socket %.950s by "
78816 +#define GR_TTYSNIFF_ACL_MSG "terminal being sniffed by IP:%pI4 %.480s[%.16s:%d], parent %.480s[%.16s:%d] against "
78817 +#define GR_MKDIR_ACL_MSG "%s mkdir of %.950s by "
78818 +#define GR_RMDIR_ACL_MSG "%s rmdir of %.950s by "
78819 +#define GR_UNLINK_ACL_MSG "%s unlink of %.950s by "
78820 +#define GR_SYMLINK_ACL_MSG "%s symlink from %.480s to %.480s by "
78821 +#define GR_HARDLINK_MSG "denied hardlink of %.930s (owned by %d.%d) to %.30s for "
78822 +#define GR_LINK_ACL_MSG "%s link of %.480s to %.480s by "
78823 +#define GR_INHERIT_ACL_MSG "successful inherit of %.480s's ACL for %.480s by "
78824 +#define GR_RENAME_ACL_MSG "%s rename of %.480s to %.480s by "
78825 +#define GR_UNSAFESHARE_EXEC_ACL_MSG "denied exec with cloned fs of %.950s by "
78826 +#define GR_PTRACE_EXEC_ACL_MSG "denied ptrace of %.950s by "
78827 +#define GR_EXEC_ACL_MSG "%s execution of %.950s by "
78828 +#define GR_EXEC_TPE_MSG "denied untrusted exec (due to %.70s) of %.950s by "
78829 +#define GR_SEGVSTART_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning uid %u from login for %lu seconds"
78830 +#define GR_SEGVNOSUID_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning execution for %lu seconds"
78831 +#define GR_MOUNT_CHROOT_MSG "denied mount of %.256s as %.930s from chroot by "
78832 +#define GR_PIVOT_CHROOT_MSG "denied pivot_root from chroot by "
78833 +#define GR_TRUNCATE_ACL_MSG "%s truncate of %.950s by "
78834 +#define GR_ATIME_ACL_MSG "%s access time change of %.950s by "
78835 +#define GR_ACCESS_ACL_MSG "%s access of %.950s for%s%s%s by "
78836 +#define GR_CHROOT_CHROOT_MSG "denied double chroot to %.950s by "
78837 +#define GR_CHMOD_CHROOT_MSG "denied chmod +s of %.950s by "
78838 +#define GR_CHMOD_ACL_MSG "%s chmod of %.950s by "
78839 +#define GR_CHROOT_FCHDIR_MSG "denied fchdir outside of chroot to %.950s by "
78840 +#define GR_CHOWN_ACL_MSG "%s chown of %.950s by "
78841 +#define GR_SETXATTR_ACL_MSG "%s setting extended attribute of %.950s by "
78842 +#define GR_REMOVEXATTR_ACL_MSG "%s removing extended attribute of %.950s by "
78843 +#define GR_WRITLIB_ACL_MSG "denied load of writable library %.950s by "
78844 +#define GR_INITF_ACL_MSG "init_variables() failed %s by "
78845 +#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"
78846 +#define GR_DEV_ACL_MSG "/dev/grsec: %d bytes sent %d required, being fed garbage by "
78847 +#define GR_SHUTS_ACL_MSG "shutdown auth success for "
78848 +#define GR_SHUTF_ACL_MSG "shutdown auth failure for "
78849 +#define GR_SHUTI_ACL_MSG "ignoring shutdown for disabled RBAC system for "
78850 +#define GR_SEGVMODS_ACL_MSG "segvmod auth success for "
78851 +#define GR_SEGVMODF_ACL_MSG "segvmod auth failure for "
78852 +#define GR_SEGVMODI_ACL_MSG "ignoring segvmod for disabled RBAC system for "
78853 +#define GR_ENABLE_ACL_MSG "%s RBAC system loaded by "
78854 +#define GR_ENABLEF_ACL_MSG "unable to load %s for "
78855 +#define GR_RELOADI_ACL_MSG "ignoring reload request for disabled RBAC system"
78856 +#define GR_RELOAD_ACL_MSG "%s RBAC system reloaded by "
78857 +#define GR_RELOADF_ACL_MSG "failed reload of %s for "
78858 +#define GR_SPROLEI_ACL_MSG "ignoring change to special role for disabled RBAC system for "
78859 +#define GR_SPROLES_ACL_MSG "successful change to special role %s (id %d) by "
78860 +#define GR_SPROLEL_ACL_MSG "special role %s (id %d) exited by "
78861 +#define GR_SPROLEF_ACL_MSG "special role %s failure for "
78862 +#define GR_UNSPROLEI_ACL_MSG "ignoring unauth of special role for disabled RBAC system for "
78863 +#define GR_UNSPROLES_ACL_MSG "successful unauth of special role %s (id %d) by "
78864 +#define GR_INVMODE_ACL_MSG "invalid mode %d by "
78865 +#define GR_PRIORITY_CHROOT_MSG "denied priority change of process (%.16s:%d) by "
78866 +#define GR_FAILFORK_MSG "failed fork with errno %s by "
78867 +#define GR_NICE_CHROOT_MSG "denied priority change by "
78868 +#define GR_UNISIGLOG_MSG "%.32s occurred at %p in "
78869 +#define GR_DUALSIGLOG_MSG "signal %d sent to " DEFAULTSECMSG " by "
78870 +#define GR_SIG_ACL_MSG "denied send of signal %d to protected task " DEFAULTSECMSG " by "
78871 +#define GR_SYSCTL_MSG "denied modification of grsecurity sysctl value : %.32s by "
78872 +#define GR_SYSCTL_ACL_MSG "%s sysctl of %.950s for%s%s by "
78873 +#define GR_TIME_MSG "time set by "
78874 +#define GR_DEFACL_MSG "fatal: unable to find subject for (%.16s:%d), loaded by "
78875 +#define GR_MMAP_ACL_MSG "%s executable mmap of %.950s by "
78876 +#define GR_MPROTECT_ACL_MSG "%s executable mprotect of %.950s by "
78877 +#define GR_SOCK_MSG "denied socket(%.16s,%.16s,%.16s) by "
78878 +#define GR_SOCK_NOINET_MSG "denied socket(%.16s,%.16s,%d) by "
78879 +#define GR_BIND_MSG "denied bind() by "
78880 +#define GR_CONNECT_MSG "denied connect() by "
78881 +#define GR_BIND_ACL_MSG "denied bind() to %pI4 port %u sock type %.16s protocol %.16s by "
78882 +#define GR_CONNECT_ACL_MSG "denied connect() to %pI4 port %u sock type %.16s protocol %.16s by "
78883 +#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"
78884 +#define GR_EXEC_CHROOT_MSG "exec of %.980s within chroot by process "
78885 +#define GR_CAP_ACL_MSG "use of %s denied for "
78886 +#define GR_CAP_CHROOT_MSG "use of %s in chroot denied for "
78887 +#define GR_CAP_ACL_MSG2 "use of %s permitted for "
78888 +#define GR_USRCHANGE_ACL_MSG "change to uid %u denied for "
78889 +#define GR_GRPCHANGE_ACL_MSG "change to gid %u denied for "
78890 +#define GR_REMOUNT_AUDIT_MSG "remount of %.256s by "
78891 +#define GR_UNMOUNT_AUDIT_MSG "unmount of %.256s by "
78892 +#define GR_MOUNT_AUDIT_MSG "mount of %.256s to %.256s by "
78893 +#define GR_CHDIR_AUDIT_MSG "chdir to %.980s by "
78894 +#define GR_EXEC_AUDIT_MSG "exec of %.930s (%.128s) by "
78895 +#define GR_RESOURCE_MSG "denied resource overstep by requesting %lu for %.16s against limit %lu for "
78896 +#define GR_RWXMMAP_MSG "denied RWX mmap of %.950s by "
78897 +#define GR_RWXMPROTECT_MSG "denied RWX mprotect of %.950s by "
78898 +#define GR_TEXTREL_AUDIT_MSG "denied text relocation in %.950s, VMA:0x%08lx 0x%08lx by "
78899 +#define GR_PTGNUSTACK_MSG "denied marking stack executable as requested by PT_GNU_STACK marking in %.950s by "
78900 +#define GR_VM86_MSG "denied use of vm86 by "
78901 +#define GR_PTRACE_AUDIT_MSG "process %.950s(%.16s:%d) attached to via ptrace by "
78902 +#define GR_PTRACE_READEXEC_MSG "denied ptrace of unreadable binary %.950s by "
78903 +#define GR_INIT_TRANSFER_MSG "persistent special role transferred privilege to init by "
78904 +#define GR_BADPROCPID_MSG "denied read of sensitive /proc/pid/%s entry via fd passed across exec by "
78905 +#define GR_SYMLINKOWNER_MSG "denied following symlink %.950s since symlink owner %u does not match target owner %u, by "
78906 +#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 "
78907 +#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 "
78908 +#define GR_IPC_DENIED_MSG "denied %s of overly-permissive IPC object with creator uid %u by "
78909 +#define GR_MSRWRITE_MSG "denied write to CPU MSR by "
78910 diff --git a/include/linux/grsecurity.h b/include/linux/grsecurity.h
78911 new file mode 100644
78912 index 0000000..8108301
78913 --- /dev/null
78914 +++ b/include/linux/grsecurity.h
78915 @@ -0,0 +1,246 @@
78916 +#ifndef GR_SECURITY_H
78917 +#define GR_SECURITY_H
78918 +#include <linux/fs.h>
78919 +#include <linux/fs_struct.h>
78920 +#include <linux/binfmts.h>
78921 +#include <linux/gracl.h>
78922 +
78923 +/* notify of brain-dead configs */
78924 +#if defined(CONFIG_GRKERNSEC_PROC_USER) && defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
78925 +#error "CONFIG_GRKERNSEC_PROC_USER and CONFIG_GRKERNSEC_PROC_USERGROUP cannot both be enabled."
78926 +#endif
78927 +#if defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_PAGEEXEC) && !defined(CONFIG_PAX_SEGMEXEC) && !defined(CONFIG_PAX_KERNEXEC)
78928 +#error "CONFIG_PAX_NOEXEC enabled, but PAGEEXEC, SEGMEXEC, and KERNEXEC are disabled."
78929 +#endif
78930 +#if defined(CONFIG_PAX_ASLR) && !defined(CONFIG_PAX_RANDKSTACK) && !defined(CONFIG_PAX_RANDUSTACK) && !defined(CONFIG_PAX_RANDMMAP)
78931 +#error "CONFIG_PAX_ASLR enabled, but RANDKSTACK, RANDUSTACK, and RANDMMAP are disabled."
78932 +#endif
78933 +#if defined(CONFIG_PAX) && !defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_ASLR)
78934 +#error "CONFIG_PAX enabled, but no PaX options are enabled."
78935 +#endif
78936 +
78937 +int gr_handle_new_usb(void);
78938 +
78939 +void gr_handle_brute_attach(int dumpable);
78940 +void gr_handle_brute_check(void);
78941 +void gr_handle_kernel_exploit(void);
78942 +
78943 +char gr_roletype_to_char(void);
78944 +
78945 +int gr_acl_enable_at_secure(void);
78946 +
78947 +int gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs);
78948 +int gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs);
78949 +
78950 +void gr_del_task_from_ip_table(struct task_struct *p);
78951 +
78952 +int gr_pid_is_chrooted(struct task_struct *p);
78953 +int gr_handle_chroot_fowner(struct pid *pid, enum pid_type type);
78954 +int gr_handle_chroot_nice(void);
78955 +int gr_handle_chroot_sysctl(const int op);
78956 +int gr_handle_chroot_setpriority(struct task_struct *p,
78957 + const int niceval);
78958 +int gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt);
78959 +int gr_handle_chroot_chroot(const struct dentry *dentry,
78960 + const struct vfsmount *mnt);
78961 +void gr_handle_chroot_chdir(const struct path *path);
78962 +int gr_handle_chroot_chmod(const struct dentry *dentry,
78963 + const struct vfsmount *mnt, const int mode);
78964 +int gr_handle_chroot_mknod(const struct dentry *dentry,
78965 + const struct vfsmount *mnt, const int mode);
78966 +int gr_handle_chroot_mount(const struct dentry *dentry,
78967 + const struct vfsmount *mnt,
78968 + const char *dev_name);
78969 +int gr_handle_chroot_pivot(void);
78970 +int gr_handle_chroot_unix(const pid_t pid);
78971 +
78972 +int gr_handle_rawio(const struct inode *inode);
78973 +
78974 +void gr_handle_ioperm(void);
78975 +void gr_handle_iopl(void);
78976 +void gr_handle_msr_write(void);
78977 +
78978 +umode_t gr_acl_umask(void);
78979 +
78980 +int gr_tpe_allow(const struct file *file);
78981 +
78982 +void gr_set_chroot_entries(struct task_struct *task, const struct path *path);
78983 +void gr_clear_chroot_entries(struct task_struct *task);
78984 +
78985 +void gr_log_forkfail(const int retval);
78986 +void gr_log_timechange(void);
78987 +void gr_log_signal(const int sig, const void *addr, const struct task_struct *t);
78988 +void gr_log_chdir(const struct dentry *dentry,
78989 + const struct vfsmount *mnt);
78990 +void gr_log_chroot_exec(const struct dentry *dentry,
78991 + const struct vfsmount *mnt);
78992 +void gr_log_remount(const char *devname, const int retval);
78993 +void gr_log_unmount(const char *devname, const int retval);
78994 +void gr_log_mount(const char *from, const char *to, const int retval);
78995 +void gr_log_textrel(struct vm_area_struct *vma);
78996 +void gr_log_ptgnustack(struct file *file);
78997 +void gr_log_rwxmmap(struct file *file);
78998 +void gr_log_rwxmprotect(struct vm_area_struct *vma);
78999 +
79000 +int gr_handle_follow_link(const struct inode *parent,
79001 + const struct inode *inode,
79002 + const struct dentry *dentry,
79003 + const struct vfsmount *mnt);
79004 +int gr_handle_fifo(const struct dentry *dentry,
79005 + const struct vfsmount *mnt,
79006 + const struct dentry *dir, const int flag,
79007 + const int acc_mode);
79008 +int gr_handle_hardlink(const struct dentry *dentry,
79009 + const struct vfsmount *mnt,
79010 + struct inode *inode,
79011 + const int mode, const struct filename *to);
79012 +
79013 +int gr_is_capable(const int cap);
79014 +int gr_is_capable_nolog(const int cap);
79015 +int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
79016 +int gr_task_is_capable_nolog(const struct task_struct *task, const int cap);
79017 +
79018 +void gr_copy_label(struct task_struct *tsk);
79019 +void gr_handle_crash(struct task_struct *task, const int sig);
79020 +int gr_handle_signal(const struct task_struct *p, const int sig);
79021 +int gr_check_crash_uid(const kuid_t uid);
79022 +int gr_check_protected_task(const struct task_struct *task);
79023 +int gr_check_protected_task_fowner(struct pid *pid, enum pid_type type);
79024 +int gr_acl_handle_mmap(const struct file *file,
79025 + const unsigned long prot);
79026 +int gr_acl_handle_mprotect(const struct file *file,
79027 + const unsigned long prot);
79028 +int gr_check_hidden_task(const struct task_struct *tsk);
79029 +__u32 gr_acl_handle_truncate(const struct dentry *dentry,
79030 + const struct vfsmount *mnt);
79031 +__u32 gr_acl_handle_utime(const struct dentry *dentry,
79032 + const struct vfsmount *mnt);
79033 +__u32 gr_acl_handle_access(const struct dentry *dentry,
79034 + const struct vfsmount *mnt, const int fmode);
79035 +__u32 gr_acl_handle_chmod(const struct dentry *dentry,
79036 + const struct vfsmount *mnt, umode_t *mode);
79037 +__u32 gr_acl_handle_chown(const struct dentry *dentry,
79038 + const struct vfsmount *mnt);
79039 +__u32 gr_acl_handle_setxattr(const struct dentry *dentry,
79040 + const struct vfsmount *mnt);
79041 +__u32 gr_acl_handle_removexattr(const struct dentry *dentry,
79042 + const struct vfsmount *mnt);
79043 +int gr_handle_ptrace(struct task_struct *task, const long request);
79044 +int gr_handle_proc_ptrace(struct task_struct *task);
79045 +__u32 gr_acl_handle_execve(const struct dentry *dentry,
79046 + const struct vfsmount *mnt);
79047 +int gr_check_crash_exec(const struct file *filp);
79048 +int gr_acl_is_enabled(void);
79049 +void gr_set_role_label(struct task_struct *task, const kuid_t uid,
79050 + const kgid_t gid);
79051 +int gr_set_proc_label(const struct dentry *dentry,
79052 + const struct vfsmount *mnt,
79053 + const int unsafe_flags);
79054 +__u32 gr_acl_handle_hidden_file(const struct dentry *dentry,
79055 + const struct vfsmount *mnt);
79056 +__u32 gr_acl_handle_open(const struct dentry *dentry,
79057 + const struct vfsmount *mnt, int acc_mode);
79058 +__u32 gr_acl_handle_creat(const struct dentry *dentry,
79059 + const struct dentry *p_dentry,
79060 + const struct vfsmount *p_mnt,
79061 + int open_flags, int acc_mode, const int imode);
79062 +void gr_handle_create(const struct dentry *dentry,
79063 + const struct vfsmount *mnt);
79064 +void gr_handle_proc_create(const struct dentry *dentry,
79065 + const struct inode *inode);
79066 +__u32 gr_acl_handle_mknod(const struct dentry *new_dentry,
79067 + const struct dentry *parent_dentry,
79068 + const struct vfsmount *parent_mnt,
79069 + const int mode);
79070 +__u32 gr_acl_handle_mkdir(const struct dentry *new_dentry,
79071 + const struct dentry *parent_dentry,
79072 + const struct vfsmount *parent_mnt);
79073 +__u32 gr_acl_handle_rmdir(const struct dentry *dentry,
79074 + const struct vfsmount *mnt);
79075 +void gr_handle_delete(const ino_t ino, const dev_t dev);
79076 +__u32 gr_acl_handle_unlink(const struct dentry *dentry,
79077 + const struct vfsmount *mnt);
79078 +__u32 gr_acl_handle_symlink(const struct dentry *new_dentry,
79079 + const struct dentry *parent_dentry,
79080 + const struct vfsmount *parent_mnt,
79081 + const struct filename *from);
79082 +__u32 gr_acl_handle_link(const struct dentry *new_dentry,
79083 + const struct dentry *parent_dentry,
79084 + const struct vfsmount *parent_mnt,
79085 + const struct dentry *old_dentry,
79086 + const struct vfsmount *old_mnt, const struct filename *to);
79087 +int gr_handle_symlink_owner(const struct path *link, const struct inode *target);
79088 +int gr_acl_handle_rename(struct dentry *new_dentry,
79089 + struct dentry *parent_dentry,
79090 + const struct vfsmount *parent_mnt,
79091 + struct dentry *old_dentry,
79092 + struct inode *old_parent_inode,
79093 + struct vfsmount *old_mnt, const struct filename *newname);
79094 +void gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
79095 + struct dentry *old_dentry,
79096 + struct dentry *new_dentry,
79097 + struct vfsmount *mnt, const __u8 replace);
79098 +__u32 gr_check_link(const struct dentry *new_dentry,
79099 + const struct dentry *parent_dentry,
79100 + const struct vfsmount *parent_mnt,
79101 + const struct dentry *old_dentry,
79102 + const struct vfsmount *old_mnt);
79103 +int gr_acl_handle_filldir(const struct file *file, const char *name,
79104 + const unsigned int namelen, const ino_t ino);
79105 +
79106 +__u32 gr_acl_handle_unix(const struct dentry *dentry,
79107 + const struct vfsmount *mnt);
79108 +void gr_acl_handle_exit(void);
79109 +void gr_acl_handle_psacct(struct task_struct *task, const long code);
79110 +int gr_acl_handle_procpidmem(const struct task_struct *task);
79111 +int gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags);
79112 +int gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode);
79113 +void gr_audit_ptrace(struct task_struct *task);
79114 +dev_t gr_get_dev_from_dentry(struct dentry *dentry);
79115 +void gr_put_exec_file(struct task_struct *task);
79116 +
79117 +int gr_ptrace_readexec(struct file *file, int unsafe_flags);
79118 +
79119 +#if defined(CONFIG_GRKERNSEC) && (defined(CONFIG_GRKERNSEC_RESLOG) || !defined(CONFIG_GRKERNSEC_NO_RBAC))
79120 +extern void gr_learn_resource(const struct task_struct *task, const int res,
79121 + const unsigned long wanted, const int gt);
79122 +#else
79123 +static inline void gr_learn_resource(const struct task_struct *task, const int res,
79124 + const unsigned long wanted, const int gt)
79125 +{
79126 +}
79127 +#endif
79128 +
79129 +#ifdef CONFIG_GRKERNSEC_RESLOG
79130 +extern void gr_log_resource(const struct task_struct *task, const int res,
79131 + const unsigned long wanted, const int gt);
79132 +#else
79133 +static inline void gr_log_resource(const struct task_struct *task, const int res,
79134 + const unsigned long wanted, const int gt)
79135 +{
79136 +}
79137 +#endif
79138 +
79139 +#ifdef CONFIG_GRKERNSEC
79140 +void task_grsec_rbac(struct seq_file *m, struct task_struct *p);
79141 +void gr_handle_vm86(void);
79142 +void gr_handle_mem_readwrite(u64 from, u64 to);
79143 +
79144 +void gr_log_badprocpid(const char *entry);
79145 +
79146 +extern int grsec_enable_dmesg;
79147 +extern int grsec_disable_privio;
79148 +
79149 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
79150 +extern kgid_t grsec_proc_gid;
79151 +#endif
79152 +
79153 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
79154 +extern int grsec_enable_chroot_findtask;
79155 +#endif
79156 +#ifdef CONFIG_GRKERNSEC_SETXID
79157 +extern int grsec_enable_setxid;
79158 +#endif
79159 +#endif
79160 +
79161 +#endif
79162 diff --git a/include/linux/grsock.h b/include/linux/grsock.h
79163 new file mode 100644
79164 index 0000000..e7ffaaf
79165 --- /dev/null
79166 +++ b/include/linux/grsock.h
79167 @@ -0,0 +1,19 @@
79168 +#ifndef __GRSOCK_H
79169 +#define __GRSOCK_H
79170 +
79171 +extern void gr_attach_curr_ip(const struct sock *sk);
79172 +extern int gr_handle_sock_all(const int family, const int type,
79173 + const int protocol);
79174 +extern int gr_handle_sock_server(const struct sockaddr *sck);
79175 +extern int gr_handle_sock_server_other(const struct sock *sck);
79176 +extern int gr_handle_sock_client(const struct sockaddr *sck);
79177 +extern int gr_search_connect(struct socket * sock,
79178 + struct sockaddr_in * addr);
79179 +extern int gr_search_bind(struct socket * sock,
79180 + struct sockaddr_in * addr);
79181 +extern int gr_search_listen(struct socket * sock);
79182 +extern int gr_search_accept(struct socket * sock);
79183 +extern int gr_search_socket(const int domain, const int type,
79184 + const int protocol);
79185 +
79186 +#endif
79187 diff --git a/include/linux/highmem.h b/include/linux/highmem.h
79188 index 7fb31da..08b5114 100644
79189 --- a/include/linux/highmem.h
79190 +++ b/include/linux/highmem.h
79191 @@ -189,6 +189,18 @@ static inline void clear_highpage(struct page *page)
79192 kunmap_atomic(kaddr);
79193 }
79194
79195 +static inline void sanitize_highpage(struct page *page)
79196 +{
79197 + void *kaddr;
79198 + unsigned long flags;
79199 +
79200 + local_irq_save(flags);
79201 + kaddr = kmap_atomic(page);
79202 + clear_page(kaddr);
79203 + kunmap_atomic(kaddr);
79204 + local_irq_restore(flags);
79205 +}
79206 +
79207 static inline void zero_user_segments(struct page *page,
79208 unsigned start1, unsigned end1,
79209 unsigned start2, unsigned end2)
79210 diff --git a/include/linux/hwmon-sysfs.h b/include/linux/hwmon-sysfs.h
79211 index 1c7b89a..7dda400 100644
79212 --- a/include/linux/hwmon-sysfs.h
79213 +++ b/include/linux/hwmon-sysfs.h
79214 @@ -25,7 +25,8 @@
79215 struct sensor_device_attribute{
79216 struct device_attribute dev_attr;
79217 int index;
79218 -};
79219 +} __do_const;
79220 +typedef struct sensor_device_attribute __no_const sensor_device_attribute_no_const;
79221 #define to_sensor_dev_attr(_dev_attr) \
79222 container_of(_dev_attr, struct sensor_device_attribute, dev_attr)
79223
79224 @@ -41,7 +42,8 @@ struct sensor_device_attribute_2 {
79225 struct device_attribute dev_attr;
79226 u8 index;
79227 u8 nr;
79228 -};
79229 +} __do_const;
79230 +typedef struct sensor_device_attribute_2 __no_const sensor_device_attribute_2_no_const;
79231 #define to_sensor_dev_attr_2(_dev_attr) \
79232 container_of(_dev_attr, struct sensor_device_attribute_2, dev_attr)
79233
79234 diff --git a/include/linux/i2c.h b/include/linux/i2c.h
79235 index d9c8dbd3..def6e5a 100644
79236 --- a/include/linux/i2c.h
79237 +++ b/include/linux/i2c.h
79238 @@ -364,6 +364,7 @@ struct i2c_algorithm {
79239 /* To determine what the adapter supports */
79240 u32 (*functionality) (struct i2c_adapter *);
79241 };
79242 +typedef struct i2c_algorithm __no_const i2c_algorithm_no_const;
79243
79244 /**
79245 * struct i2c_bus_recovery_info - I2C bus recovery information
79246 diff --git a/include/linux/i2o.h b/include/linux/i2o.h
79247 index d23c3c2..eb63c81 100644
79248 --- a/include/linux/i2o.h
79249 +++ b/include/linux/i2o.h
79250 @@ -565,7 +565,7 @@ struct i2o_controller {
79251 struct i2o_device *exec; /* Executive */
79252 #if BITS_PER_LONG == 64
79253 spinlock_t context_list_lock; /* lock for context_list */
79254 - atomic_t context_list_counter; /* needed for unique contexts */
79255 + atomic_unchecked_t context_list_counter; /* needed for unique contexts */
79256 struct list_head context_list; /* list of context id's
79257 and pointers */
79258 #endif
79259 diff --git a/include/linux/if_pppox.h b/include/linux/if_pppox.h
79260 index aff7ad8..3942bbd 100644
79261 --- a/include/linux/if_pppox.h
79262 +++ b/include/linux/if_pppox.h
79263 @@ -76,7 +76,7 @@ struct pppox_proto {
79264 int (*ioctl)(struct socket *sock, unsigned int cmd,
79265 unsigned long arg);
79266 struct module *owner;
79267 -};
79268 +} __do_const;
79269
79270 extern int register_pppox_proto(int proto_num, const struct pppox_proto *pp);
79271 extern void unregister_pppox_proto(int proto_num);
79272 diff --git a/include/linux/init.h b/include/linux/init.h
79273 index 8e68a64..3f977a0 100644
79274 --- a/include/linux/init.h
79275 +++ b/include/linux/init.h
79276 @@ -37,9 +37,17 @@
79277 * section.
79278 */
79279
79280 +#define add_init_latent_entropy __latent_entropy
79281 +
79282 +#ifdef CONFIG_MEMORY_HOTPLUG
79283 +#define add_meminit_latent_entropy
79284 +#else
79285 +#define add_meminit_latent_entropy __latent_entropy
79286 +#endif
79287 +
79288 /* These are for everybody (although not all archs will actually
79289 discard it in modules) */
79290 -#define __init __section(.init.text) __cold notrace
79291 +#define __init __section(.init.text) __cold notrace add_init_latent_entropy
79292 #define __initdata __section(.init.data)
79293 #define __initconst __constsection(.init.rodata)
79294 #define __exitdata __section(.exit.data)
79295 @@ -100,7 +108,7 @@
79296 #define __cpuexitconst
79297
79298 /* Used for MEMORY_HOTPLUG */
79299 -#define __meminit __section(.meminit.text) __cold notrace
79300 +#define __meminit __section(.meminit.text) __cold notrace add_meminit_latent_entropy
79301 #define __meminitdata __section(.meminit.data)
79302 #define __meminitconst __constsection(.meminit.rodata)
79303 #define __memexit __section(.memexit.text) __exitused __cold notrace
79304 diff --git a/include/linux/init_task.h b/include/linux/init_task.h
79305 index b0ed422..d79ea23 100644
79306 --- a/include/linux/init_task.h
79307 +++ b/include/linux/init_task.h
79308 @@ -154,6 +154,12 @@ extern struct task_group root_task_group;
79309
79310 #define INIT_TASK_COMM "swapper"
79311
79312 +#ifdef CONFIG_X86
79313 +#define INIT_TASK_THREAD_INFO .tinfo = INIT_THREAD_INFO,
79314 +#else
79315 +#define INIT_TASK_THREAD_INFO
79316 +#endif
79317 +
79318 /*
79319 * INIT_TASK is used to set up the first task table, touch at
79320 * your own risk!. Base=0, limit=0x1fffff (=2MB)
79321 @@ -193,6 +199,7 @@ extern struct task_group root_task_group;
79322 RCU_POINTER_INITIALIZER(cred, &init_cred), \
79323 .comm = INIT_TASK_COMM, \
79324 .thread = INIT_THREAD, \
79325 + INIT_TASK_THREAD_INFO \
79326 .fs = &init_fs, \
79327 .files = &init_files, \
79328 .signal = &init_signals, \
79329 diff --git a/include/linux/interrupt.h b/include/linux/interrupt.h
79330 index db43b58..5d5084b 100644
79331 --- a/include/linux/interrupt.h
79332 +++ b/include/linux/interrupt.h
79333 @@ -360,7 +360,7 @@ enum
79334 /* map softirq index to softirq name. update 'softirq_to_name' in
79335 * kernel/softirq.c when adding a new softirq.
79336 */
79337 -extern char *softirq_to_name[NR_SOFTIRQS];
79338 +extern const char * const softirq_to_name[NR_SOFTIRQS];
79339
79340 /* softirq mask and active fields moved to irq_cpustat_t in
79341 * asm/hardirq.h to get better cache usage. KAO
79342 @@ -368,8 +368,8 @@ extern char *softirq_to_name[NR_SOFTIRQS];
79343
79344 struct softirq_action
79345 {
79346 - void (*action)(struct softirq_action *);
79347 -};
79348 + void (*action)(void);
79349 +} __no_const;
79350
79351 asmlinkage void do_softirq(void);
79352 asmlinkage void __do_softirq(void);
79353 @@ -383,7 +383,7 @@ static inline void do_softirq_own_stack(void)
79354 }
79355 #endif
79356
79357 -extern void open_softirq(int nr, void (*action)(struct softirq_action *));
79358 +extern void open_softirq(int nr, void (*action)(void));
79359 extern void softirq_init(void);
79360 extern void __raise_softirq_irqoff(unsigned int nr);
79361
79362 diff --git a/include/linux/iommu.h b/include/linux/iommu.h
79363 index a444c79..8c41ea9 100644
79364 --- a/include/linux/iommu.h
79365 +++ b/include/linux/iommu.h
79366 @@ -130,7 +130,7 @@ struct iommu_ops {
79367 u32 (*domain_get_windows)(struct iommu_domain *domain);
79368
79369 unsigned long pgsize_bitmap;
79370 -};
79371 +} __do_const;
79372
79373 #define IOMMU_GROUP_NOTIFY_ADD_DEVICE 1 /* Device added */
79374 #define IOMMU_GROUP_NOTIFY_DEL_DEVICE 2 /* Pre Device removed */
79375 diff --git a/include/linux/ioport.h b/include/linux/ioport.h
79376 index 89b7c24..382af74 100644
79377 --- a/include/linux/ioport.h
79378 +++ b/include/linux/ioport.h
79379 @@ -161,7 +161,7 @@ struct resource *lookup_resource(struct resource *root, resource_size_t start);
79380 int adjust_resource(struct resource *res, resource_size_t start,
79381 resource_size_t size);
79382 resource_size_t resource_alignment(struct resource *res);
79383 -static inline resource_size_t resource_size(const struct resource *res)
79384 +static inline resource_size_t __intentional_overflow(-1) resource_size(const struct resource *res)
79385 {
79386 return res->end - res->start + 1;
79387 }
79388 diff --git a/include/linux/ipc_namespace.h b/include/linux/ipc_namespace.h
79389 index d6ad91f..f10f279 100644
79390 --- a/include/linux/ipc_namespace.h
79391 +++ b/include/linux/ipc_namespace.h
79392 @@ -70,7 +70,7 @@ struct ipc_namespace {
79393 struct user_namespace *user_ns;
79394
79395 unsigned int proc_inum;
79396 -};
79397 +} __randomize_layout;
79398
79399 extern struct ipc_namespace init_ipc_ns;
79400 extern atomic_t nr_ipc_ns;
79401 diff --git a/include/linux/irq.h b/include/linux/irq.h
79402 index 7dc1003..407327b 100644
79403 --- a/include/linux/irq.h
79404 +++ b/include/linux/irq.h
79405 @@ -338,7 +338,8 @@ struct irq_chip {
79406 void (*irq_print_chip)(struct irq_data *data, struct seq_file *p);
79407
79408 unsigned long flags;
79409 -};
79410 +} __do_const;
79411 +typedef struct irq_chip __no_const irq_chip_no_const;
79412
79413 /*
79414 * irq_chip specific flags
79415 diff --git a/include/linux/irqchip/arm-gic.h b/include/linux/irqchip/arm-gic.h
79416 index cac496b..ffa0567 100644
79417 --- a/include/linux/irqchip/arm-gic.h
79418 +++ b/include/linux/irqchip/arm-gic.h
79419 @@ -61,9 +61,11 @@
79420
79421 #ifndef __ASSEMBLY__
79422
79423 +#include <linux/irq.h>
79424 +
79425 struct device_node;
79426
79427 -extern struct irq_chip gic_arch_extn;
79428 +extern irq_chip_no_const gic_arch_extn;
79429
79430 void gic_init_bases(unsigned int, int, void __iomem *, void __iomem *,
79431 u32 offset, struct device_node *);
79432 diff --git a/include/linux/jiffies.h b/include/linux/jiffies.h
79433 index d235e88..8ccbe74 100644
79434 --- a/include/linux/jiffies.h
79435 +++ b/include/linux/jiffies.h
79436 @@ -292,14 +292,14 @@ extern unsigned long preset_lpj;
79437 /*
79438 * Convert various time units to each other:
79439 */
79440 -extern unsigned int jiffies_to_msecs(const unsigned long j);
79441 -extern unsigned int jiffies_to_usecs(const unsigned long j);
79442 -extern unsigned long msecs_to_jiffies(const unsigned int m);
79443 -extern unsigned long usecs_to_jiffies(const unsigned int u);
79444 -extern unsigned long timespec_to_jiffies(const struct timespec *value);
79445 +extern unsigned int jiffies_to_msecs(const unsigned long j) __intentional_overflow(-1);
79446 +extern unsigned int jiffies_to_usecs(const unsigned long j) __intentional_overflow(-1);
79447 +extern unsigned long msecs_to_jiffies(const unsigned int m) __intentional_overflow(-1);
79448 +extern unsigned long usecs_to_jiffies(const unsigned int u) __intentional_overflow(-1);
79449 +extern unsigned long timespec_to_jiffies(const struct timespec *value) __intentional_overflow(-1);
79450 extern void jiffies_to_timespec(const unsigned long jiffies,
79451 struct timespec *value);
79452 -extern unsigned long timeval_to_jiffies(const struct timeval *value);
79453 +extern unsigned long timeval_to_jiffies(const struct timeval *value) __intentional_overflow(-1);
79454 extern void jiffies_to_timeval(const unsigned long jiffies,
79455 struct timeval *value);
79456
79457 diff --git a/include/linux/kallsyms.h b/include/linux/kallsyms.h
79458 index 6883e19..e854fcb 100644
79459 --- a/include/linux/kallsyms.h
79460 +++ b/include/linux/kallsyms.h
79461 @@ -15,7 +15,8 @@
79462
79463 struct module;
79464
79465 -#ifdef CONFIG_KALLSYMS
79466 +#if !defined(__INCLUDED_BY_HIDESYM) || !defined(CONFIG_KALLSYMS)
79467 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
79468 /* Lookup the address for a symbol. Returns 0 if not found. */
79469 unsigned long kallsyms_lookup_name(const char *name);
79470
79471 @@ -106,6 +107,21 @@ static inline int lookup_symbol_attrs(unsigned long addr, unsigned long *size, u
79472 /* Stupid that this does nothing, but I didn't create this mess. */
79473 #define __print_symbol(fmt, addr)
79474 #endif /*CONFIG_KALLSYMS*/
79475 +#else /* when included by kallsyms.c, vsnprintf.c, kprobes.c, or
79476 + arch/x86/kernel/dumpstack.c, with HIDESYM enabled */
79477 +extern unsigned long kallsyms_lookup_name(const char *name);
79478 +extern void __print_symbol(const char *fmt, unsigned long address);
79479 +extern int sprint_backtrace(char *buffer, unsigned long address);
79480 +extern int sprint_symbol(char *buffer, unsigned long address);
79481 +extern int sprint_symbol_no_offset(char *buffer, unsigned long address);
79482 +const char *kallsyms_lookup(unsigned long addr,
79483 + unsigned long *symbolsize,
79484 + unsigned long *offset,
79485 + char **modname, char *namebuf);
79486 +extern int kallsyms_lookup_size_offset(unsigned long addr,
79487 + unsigned long *symbolsize,
79488 + unsigned long *offset);
79489 +#endif
79490
79491 /* This macro allows us to keep printk typechecking */
79492 static __printf(1, 2)
79493 diff --git a/include/linux/key-type.h b/include/linux/key-type.h
79494 index a74c3a8..28d3f21 100644
79495 --- a/include/linux/key-type.h
79496 +++ b/include/linux/key-type.h
79497 @@ -131,7 +131,7 @@ struct key_type {
79498 /* internal fields */
79499 struct list_head link; /* link in types list */
79500 struct lock_class_key lock_class; /* key->sem lock class */
79501 -};
79502 +} __do_const;
79503
79504 extern struct key_type key_type_keyring;
79505
79506 diff --git a/include/linux/kgdb.h b/include/linux/kgdb.h
79507 index dfb4f2f..7927e62 100644
79508 --- a/include/linux/kgdb.h
79509 +++ b/include/linux/kgdb.h
79510 @@ -52,7 +52,7 @@ extern int kgdb_connected;
79511 extern int kgdb_io_module_registered;
79512
79513 extern atomic_t kgdb_setting_breakpoint;
79514 -extern atomic_t kgdb_cpu_doing_single_step;
79515 +extern atomic_unchecked_t kgdb_cpu_doing_single_step;
79516
79517 extern struct task_struct *kgdb_usethread;
79518 extern struct task_struct *kgdb_contthread;
79519 @@ -254,7 +254,7 @@ struct kgdb_arch {
79520 void (*correct_hw_break)(void);
79521
79522 void (*enable_nmi)(bool on);
79523 -};
79524 +} __do_const;
79525
79526 /**
79527 * struct kgdb_io - Describe the interface for an I/O driver to talk with KGDB.
79528 @@ -279,7 +279,7 @@ struct kgdb_io {
79529 void (*pre_exception) (void);
79530 void (*post_exception) (void);
79531 int is_console;
79532 -};
79533 +} __do_const;
79534
79535 extern struct kgdb_arch arch_kgdb_ops;
79536
79537 diff --git a/include/linux/kmod.h b/include/linux/kmod.h
79538 index 0555cc6..40116ce 100644
79539 --- a/include/linux/kmod.h
79540 +++ b/include/linux/kmod.h
79541 @@ -34,6 +34,8 @@ extern char modprobe_path[]; /* for sysctl */
79542 * usually useless though. */
79543 extern __printf(2, 3)
79544 int __request_module(bool wait, const char *name, ...);
79545 +extern __printf(3, 4)
79546 +int ___request_module(bool wait, char *param_name, const char *name, ...);
79547 #define request_module(mod...) __request_module(true, mod)
79548 #define request_module_nowait(mod...) __request_module(false, mod)
79549 #define try_then_request_module(x, mod...) \
79550 @@ -57,6 +59,9 @@ struct subprocess_info {
79551 struct work_struct work;
79552 struct completion *complete;
79553 char *path;
79554 +#ifdef CONFIG_GRKERNSEC
79555 + char *origpath;
79556 +#endif
79557 char **argv;
79558 char **envp;
79559 int wait;
79560 diff --git a/include/linux/kobject.h b/include/linux/kobject.h
79561 index e7ba650..0af3acb 100644
79562 --- a/include/linux/kobject.h
79563 +++ b/include/linux/kobject.h
79564 @@ -116,7 +116,7 @@ struct kobj_type {
79565 struct attribute **default_attrs;
79566 const struct kobj_ns_type_operations *(*child_ns_type)(struct kobject *kobj);
79567 const void *(*namespace)(struct kobject *kobj);
79568 -};
79569 +} __do_const;
79570
79571 struct kobj_uevent_env {
79572 char *envp[UEVENT_NUM_ENVP];
79573 @@ -139,6 +139,7 @@ struct kobj_attribute {
79574 ssize_t (*store)(struct kobject *kobj, struct kobj_attribute *attr,
79575 const char *buf, size_t count);
79576 };
79577 +typedef struct kobj_attribute __no_const kobj_attribute_no_const;
79578
79579 extern const struct sysfs_ops kobj_sysfs_ops;
79580
79581 @@ -166,7 +167,7 @@ struct kset {
79582 spinlock_t list_lock;
79583 struct kobject kobj;
79584 const struct kset_uevent_ops *uevent_ops;
79585 -};
79586 +} __randomize_layout;
79587
79588 extern void kset_init(struct kset *kset);
79589 extern int __must_check kset_register(struct kset *kset);
79590 diff --git a/include/linux/kobject_ns.h b/include/linux/kobject_ns.h
79591 index df32d25..fb52e27 100644
79592 --- a/include/linux/kobject_ns.h
79593 +++ b/include/linux/kobject_ns.h
79594 @@ -44,7 +44,7 @@ struct kobj_ns_type_operations {
79595 const void *(*netlink_ns)(struct sock *sk);
79596 const void *(*initial_ns)(void);
79597 void (*drop_ns)(void *);
79598 -};
79599 +} __do_const;
79600
79601 int kobj_ns_type_register(const struct kobj_ns_type_operations *ops);
79602 int kobj_ns_type_registered(enum kobj_ns_type type);
79603 diff --git a/include/linux/kref.h b/include/linux/kref.h
79604 index 484604d..0f6c5b6 100644
79605 --- a/include/linux/kref.h
79606 +++ b/include/linux/kref.h
79607 @@ -68,7 +68,7 @@ static inline void kref_get(struct kref *kref)
79608 static inline int kref_sub(struct kref *kref, unsigned int count,
79609 void (*release)(struct kref *kref))
79610 {
79611 - WARN_ON(release == NULL);
79612 + BUG_ON(release == NULL);
79613
79614 if (atomic_sub_and_test((int) count, &kref->refcount)) {
79615 release(kref);
79616 diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
79617 index 9523d2a..16c0424 100644
79618 --- a/include/linux/kvm_host.h
79619 +++ b/include/linux/kvm_host.h
79620 @@ -457,7 +457,7 @@ static inline void kvm_irqfd_exit(void)
79621 {
79622 }
79623 #endif
79624 -int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
79625 +int kvm_init(const void *opaque, unsigned vcpu_size, unsigned vcpu_align,
79626 struct module *module);
79627 void kvm_exit(void);
79628
79629 @@ -632,7 +632,7 @@ int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu,
79630 struct kvm_guest_debug *dbg);
79631 int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run);
79632
79633 -int kvm_arch_init(void *opaque);
79634 +int kvm_arch_init(const void *opaque);
79635 void kvm_arch_exit(void);
79636
79637 int kvm_arch_vcpu_init(struct kvm_vcpu *vcpu);
79638 diff --git a/include/linux/libata.h b/include/linux/libata.h
79639 index bec6dbe..2873d64 100644
79640 --- a/include/linux/libata.h
79641 +++ b/include/linux/libata.h
79642 @@ -975,7 +975,7 @@ struct ata_port_operations {
79643 * fields must be pointers.
79644 */
79645 const struct ata_port_operations *inherits;
79646 -};
79647 +} __do_const;
79648
79649 struct ata_port_info {
79650 unsigned long flags;
79651 diff --git a/include/linux/linkage.h b/include/linux/linkage.h
79652 index d3e8ad2..a949f68 100644
79653 --- a/include/linux/linkage.h
79654 +++ b/include/linux/linkage.h
79655 @@ -31,6 +31,7 @@
79656 #endif
79657
79658 #define __page_aligned_data __section(.data..page_aligned) __aligned(PAGE_SIZE)
79659 +#define __page_aligned_rodata __read_only __aligned(PAGE_SIZE)
79660 #define __page_aligned_bss __section(.bss..page_aligned) __aligned(PAGE_SIZE)
79661
79662 /*
79663 diff --git a/include/linux/list.h b/include/linux/list.h
79664 index ef95941..82db65a 100644
79665 --- a/include/linux/list.h
79666 +++ b/include/linux/list.h
79667 @@ -112,6 +112,19 @@ extern void __list_del_entry(struct list_head *entry);
79668 extern void list_del(struct list_head *entry);
79669 #endif
79670
79671 +extern void __pax_list_add(struct list_head *new,
79672 + struct list_head *prev,
79673 + struct list_head *next);
79674 +static inline void pax_list_add(struct list_head *new, struct list_head *head)
79675 +{
79676 + __pax_list_add(new, head, head->next);
79677 +}
79678 +static inline void pax_list_add_tail(struct list_head *new, struct list_head *head)
79679 +{
79680 + __pax_list_add(new, head->prev, head);
79681 +}
79682 +extern void pax_list_del(struct list_head *entry);
79683 +
79684 /**
79685 * list_replace - replace old entry by new one
79686 * @old : the element to be replaced
79687 @@ -145,6 +158,8 @@ static inline void list_del_init(struct list_head *entry)
79688 INIT_LIST_HEAD(entry);
79689 }
79690
79691 +extern void pax_list_del_init(struct list_head *entry);
79692 +
79693 /**
79694 * list_move - delete from one list and add as another's head
79695 * @list: the entry to move
79696 diff --git a/include/linux/math64.h b/include/linux/math64.h
79697 index c45c089..298841c 100644
79698 --- a/include/linux/math64.h
79699 +++ b/include/linux/math64.h
79700 @@ -15,7 +15,7 @@
79701 * This is commonly provided by 32bit archs to provide an optimized 64bit
79702 * divide.
79703 */
79704 -static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
79705 +static inline u64 __intentional_overflow(-1) div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
79706 {
79707 *remainder = dividend % divisor;
79708 return dividend / divisor;
79709 @@ -42,7 +42,7 @@ static inline u64 div64_u64_rem(u64 dividend, u64 divisor, u64 *remainder)
79710 /**
79711 * div64_u64 - unsigned 64bit divide with 64bit divisor
79712 */
79713 -static inline u64 div64_u64(u64 dividend, u64 divisor)
79714 +static inline u64 __intentional_overflow(-1) div64_u64(u64 dividend, u64 divisor)
79715 {
79716 return dividend / divisor;
79717 }
79718 @@ -61,7 +61,7 @@ static inline s64 div64_s64(s64 dividend, s64 divisor)
79719 #define div64_ul(x, y) div_u64((x), (y))
79720
79721 #ifndef div_u64_rem
79722 -static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
79723 +static inline u64 __intentional_overflow(-1) div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
79724 {
79725 *remainder = do_div(dividend, divisor);
79726 return dividend;
79727 @@ -77,7 +77,7 @@ extern u64 div64_u64_rem(u64 dividend, u64 divisor, u64 *remainder);
79728 #endif
79729
79730 #ifndef div64_u64
79731 -extern u64 div64_u64(u64 dividend, u64 divisor);
79732 +extern u64 __intentional_overflow(-1) div64_u64(u64 dividend, u64 divisor);
79733 #endif
79734
79735 #ifndef div64_s64
79736 @@ -94,7 +94,7 @@ extern s64 div64_s64(s64 dividend, s64 divisor);
79737 * divide.
79738 */
79739 #ifndef div_u64
79740 -static inline u64 div_u64(u64 dividend, u32 divisor)
79741 +static inline u64 __intentional_overflow(-1) div_u64(u64 dividend, u32 divisor)
79742 {
79743 u32 remainder;
79744 return div_u64_rem(dividend, divisor, &remainder);
79745 diff --git a/include/linux/mempolicy.h b/include/linux/mempolicy.h
79746 index 9fe426b..8148be6 100644
79747 --- a/include/linux/mempolicy.h
79748 +++ b/include/linux/mempolicy.h
79749 @@ -91,6 +91,10 @@ static inline struct mempolicy *mpol_dup(struct mempolicy *pol)
79750 }
79751
79752 #define vma_policy(vma) ((vma)->vm_policy)
79753 +static inline void set_vma_policy(struct vm_area_struct *vma, struct mempolicy *pol)
79754 +{
79755 + vma->vm_policy = pol;
79756 +}
79757
79758 static inline void mpol_get(struct mempolicy *pol)
79759 {
79760 @@ -241,6 +245,9 @@ mpol_shared_policy_lookup(struct shared_policy *sp, unsigned long idx)
79761 }
79762
79763 #define vma_policy(vma) NULL
79764 +static inline void set_vma_policy(struct vm_area_struct *vma, struct mempolicy *pol)
79765 +{
79766 +}
79767
79768 static inline int
79769 vma_dup_policy(struct vm_area_struct *src, struct vm_area_struct *dst)
79770 diff --git a/include/linux/mm.h b/include/linux/mm.h
79771 index 5360b82..4eedf45 100644
79772 --- a/include/linux/mm.h
79773 +++ b/include/linux/mm.h
79774 @@ -117,6 +117,11 @@ extern unsigned int kobjsize(const void *objp);
79775 #define VM_HUGETLB 0x00400000 /* Huge TLB Page VM */
79776 #define VM_NONLINEAR 0x00800000 /* Is non-linear (remap_file_pages) */
79777 #define VM_ARCH_1 0x01000000 /* Architecture-specific flag */
79778 +
79779 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
79780 +#define VM_PAGEEXEC 0x02000000 /* vma->vm_page_prot needs special handling */
79781 +#endif
79782 +
79783 #define VM_DONTDUMP 0x04000000 /* Do not include in the core dump */
79784
79785 #ifdef CONFIG_MEM_SOFT_DIRTY
79786 @@ -219,8 +224,8 @@ struct vm_operations_struct {
79787 /* called by access_process_vm when get_user_pages() fails, typically
79788 * for use by special VMAs that can switch between memory and hardware
79789 */
79790 - int (*access)(struct vm_area_struct *vma, unsigned long addr,
79791 - void *buf, int len, int write);
79792 + ssize_t (*access)(struct vm_area_struct *vma, unsigned long addr,
79793 + void *buf, size_t len, int write);
79794 #ifdef CONFIG_NUMA
79795 /*
79796 * set_policy() op must add a reference to any non-NULL @new mempolicy
79797 @@ -250,6 +255,7 @@ struct vm_operations_struct {
79798 int (*remap_pages)(struct vm_area_struct *vma, unsigned long addr,
79799 unsigned long size, pgoff_t pgoff);
79800 };
79801 +typedef struct vm_operations_struct __no_const vm_operations_struct_no_const;
79802
79803 struct mmu_gather;
79804 struct inode;
79805 @@ -1074,8 +1080,8 @@ int follow_pfn(struct vm_area_struct *vma, unsigned long address,
79806 unsigned long *pfn);
79807 int follow_phys(struct vm_area_struct *vma, unsigned long address,
79808 unsigned int flags, unsigned long *prot, resource_size_t *phys);
79809 -int generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
79810 - void *buf, int len, int write);
79811 +ssize_t generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
79812 + void *buf, size_t len, int write);
79813
79814 static inline void unmap_shared_mapping_range(struct address_space *mapping,
79815 loff_t const holebegin, loff_t const holelen)
79816 @@ -1114,9 +1120,9 @@ static inline int fixup_user_fault(struct task_struct *tsk,
79817 }
79818 #endif
79819
79820 -extern int access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, int len, int write);
79821 -extern int access_remote_vm(struct mm_struct *mm, unsigned long addr,
79822 - void *buf, int len, int write);
79823 +extern ssize_t access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, size_t len, int write);
79824 +extern ssize_t access_remote_vm(struct mm_struct *mm, unsigned long addr,
79825 + void *buf, size_t len, int write);
79826
79827 long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
79828 unsigned long start, unsigned long nr_pages,
79829 @@ -1148,34 +1154,6 @@ int set_page_dirty(struct page *page);
79830 int set_page_dirty_lock(struct page *page);
79831 int clear_page_dirty_for_io(struct page *page);
79832
79833 -/* Is the vma a continuation of the stack vma above it? */
79834 -static inline int vma_growsdown(struct vm_area_struct *vma, unsigned long addr)
79835 -{
79836 - return vma && (vma->vm_end == addr) && (vma->vm_flags & VM_GROWSDOWN);
79837 -}
79838 -
79839 -static inline int stack_guard_page_start(struct vm_area_struct *vma,
79840 - unsigned long addr)
79841 -{
79842 - return (vma->vm_flags & VM_GROWSDOWN) &&
79843 - (vma->vm_start == addr) &&
79844 - !vma_growsdown(vma->vm_prev, addr);
79845 -}
79846 -
79847 -/* Is the vma a continuation of the stack vma below it? */
79848 -static inline int vma_growsup(struct vm_area_struct *vma, unsigned long addr)
79849 -{
79850 - return vma && (vma->vm_start == addr) && (vma->vm_flags & VM_GROWSUP);
79851 -}
79852 -
79853 -static inline int stack_guard_page_end(struct vm_area_struct *vma,
79854 - unsigned long addr)
79855 -{
79856 - return (vma->vm_flags & VM_GROWSUP) &&
79857 - (vma->vm_end == addr) &&
79858 - !vma_growsup(vma->vm_next, addr);
79859 -}
79860 -
79861 extern pid_t
79862 vm_is_stack(struct task_struct *task, struct vm_area_struct *vma, int in_group);
79863
79864 @@ -1275,6 +1253,15 @@ static inline void sync_mm_rss(struct mm_struct *mm)
79865 }
79866 #endif
79867
79868 +#ifdef CONFIG_MMU
79869 +pgprot_t vm_get_page_prot(vm_flags_t vm_flags);
79870 +#else
79871 +static inline pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
79872 +{
79873 + return __pgprot(0);
79874 +}
79875 +#endif
79876 +
79877 int vma_wants_writenotify(struct vm_area_struct *vma);
79878
79879 extern pte_t *__get_locked_pte(struct mm_struct *mm, unsigned long addr,
79880 @@ -1293,8 +1280,15 @@ static inline int __pud_alloc(struct mm_struct *mm, pgd_t *pgd,
79881 {
79882 return 0;
79883 }
79884 +
79885 +static inline int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd,
79886 + unsigned long address)
79887 +{
79888 + return 0;
79889 +}
79890 #else
79891 int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
79892 +int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
79893 #endif
79894
79895 #ifdef __PAGETABLE_PMD_FOLDED
79896 @@ -1303,8 +1297,15 @@ static inline int __pmd_alloc(struct mm_struct *mm, pud_t *pud,
79897 {
79898 return 0;
79899 }
79900 +
79901 +static inline int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud,
79902 + unsigned long address)
79903 +{
79904 + return 0;
79905 +}
79906 #else
79907 int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address);
79908 +int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address);
79909 #endif
79910
79911 int __pte_alloc(struct mm_struct *mm, struct vm_area_struct *vma,
79912 @@ -1322,11 +1323,23 @@ static inline pud_t *pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long a
79913 NULL: pud_offset(pgd, address);
79914 }
79915
79916 +static inline pud_t *pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
79917 +{
79918 + return (unlikely(pgd_none(*pgd)) && __pud_alloc_kernel(mm, pgd, address))?
79919 + NULL: pud_offset(pgd, address);
79920 +}
79921 +
79922 static inline pmd_t *pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
79923 {
79924 return (unlikely(pud_none(*pud)) && __pmd_alloc(mm, pud, address))?
79925 NULL: pmd_offset(pud, address);
79926 }
79927 +
79928 +static inline pmd_t *pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
79929 +{
79930 + return (unlikely(pud_none(*pud)) && __pmd_alloc_kernel(mm, pud, address))?
79931 + NULL: pmd_offset(pud, address);
79932 +}
79933 #endif /* CONFIG_MMU && !__ARCH_HAS_4LEVEL_HACK */
79934
79935 #if USE_SPLIT_PTE_PTLOCKS
79936 @@ -1704,7 +1717,7 @@ extern int install_special_mapping(struct mm_struct *mm,
79937 unsigned long addr, unsigned long len,
79938 unsigned long flags, struct page **pages);
79939
79940 -extern unsigned long get_unmapped_area(struct file *, unsigned long, unsigned long, unsigned long, unsigned long);
79941 +extern unsigned long get_unmapped_area(struct file *, unsigned long, unsigned long, unsigned long, unsigned long) __intentional_overflow(-1);
79942
79943 extern unsigned long mmap_region(struct file *file, unsigned long addr,
79944 unsigned long len, vm_flags_t vm_flags, unsigned long pgoff);
79945 @@ -1712,6 +1725,7 @@ extern unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
79946 unsigned long len, unsigned long prot, unsigned long flags,
79947 unsigned long pgoff, unsigned long *populate);
79948 extern int do_munmap(struct mm_struct *, unsigned long, size_t);
79949 +extern int __do_munmap(struct mm_struct *, unsigned long, size_t);
79950
79951 #ifdef CONFIG_MMU
79952 extern int __mm_populate(unsigned long addr, unsigned long len,
79953 @@ -1740,10 +1754,11 @@ struct vm_unmapped_area_info {
79954 unsigned long high_limit;
79955 unsigned long align_mask;
79956 unsigned long align_offset;
79957 + unsigned long threadstack_offset;
79958 };
79959
79960 -extern unsigned long unmapped_area(struct vm_unmapped_area_info *info);
79961 -extern unsigned long unmapped_area_topdown(struct vm_unmapped_area_info *info);
79962 +extern unsigned long unmapped_area(const struct vm_unmapped_area_info *info);
79963 +extern unsigned long unmapped_area_topdown(const struct vm_unmapped_area_info *info);
79964
79965 /*
79966 * Search for an unmapped address range.
79967 @@ -1755,7 +1770,7 @@ extern unsigned long unmapped_area_topdown(struct vm_unmapped_area_info *info);
79968 * - satisfies (begin_addr & align_mask) == (align_offset & align_mask)
79969 */
79970 static inline unsigned long
79971 -vm_unmapped_area(struct vm_unmapped_area_info *info)
79972 +vm_unmapped_area(const struct vm_unmapped_area_info *info)
79973 {
79974 if (!(info->flags & VM_UNMAPPED_AREA_TOPDOWN))
79975 return unmapped_area(info);
79976 @@ -1818,6 +1833,10 @@ extern struct vm_area_struct * find_vma(struct mm_struct * mm, unsigned long add
79977 extern struct vm_area_struct * find_vma_prev(struct mm_struct * mm, unsigned long addr,
79978 struct vm_area_struct **pprev);
79979
79980 +extern struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma);
79981 +extern __must_check long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma);
79982 +extern void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl);
79983 +
79984 /* Look up the first VMA which intersects the interval start_addr..end_addr-1,
79985 NULL if none. Assume start_addr < end_addr. */
79986 static inline struct vm_area_struct * find_vma_intersection(struct mm_struct * mm, unsigned long start_addr, unsigned long end_addr)
79987 @@ -1846,15 +1865,6 @@ static inline struct vm_area_struct *find_exact_vma(struct mm_struct *mm,
79988 return vma;
79989 }
79990
79991 -#ifdef CONFIG_MMU
79992 -pgprot_t vm_get_page_prot(unsigned long vm_flags);
79993 -#else
79994 -static inline pgprot_t vm_get_page_prot(unsigned long vm_flags)
79995 -{
79996 - return __pgprot(0);
79997 -}
79998 -#endif
79999 -
80000 #ifdef CONFIG_ARCH_USES_NUMA_PROT_NONE
80001 unsigned long change_prot_numa(struct vm_area_struct *vma,
80002 unsigned long start, unsigned long end);
80003 @@ -1906,6 +1916,11 @@ void vm_stat_account(struct mm_struct *, unsigned long, struct file *, long);
80004 static inline void vm_stat_account(struct mm_struct *mm,
80005 unsigned long flags, struct file *file, long pages)
80006 {
80007 +
80008 +#ifdef CONFIG_PAX_RANDMMAP
80009 + if (!(mm->pax_flags & MF_PAX_RANDMMAP) || (flags & (VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)))
80010 +#endif
80011 +
80012 mm->total_vm += pages;
80013 }
80014 #endif /* CONFIG_PROC_FS */
80015 @@ -1987,7 +2002,7 @@ extern int unpoison_memory(unsigned long pfn);
80016 extern int sysctl_memory_failure_early_kill;
80017 extern int sysctl_memory_failure_recovery;
80018 extern void shake_page(struct page *p, int access);
80019 -extern atomic_long_t num_poisoned_pages;
80020 +extern atomic_long_unchecked_t num_poisoned_pages;
80021 extern int soft_offline_page(struct page *page, int flags);
80022
80023 extern void dump_page(struct page *page);
80024 @@ -2024,5 +2039,11 @@ void __init setup_nr_node_ids(void);
80025 static inline void setup_nr_node_ids(void) {}
80026 #endif
80027
80028 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
80029 +extern void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot);
80030 +#else
80031 +static inline void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot) {}
80032 +#endif
80033 +
80034 #endif /* __KERNEL__ */
80035 #endif /* _LINUX_MM_H */
80036 diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
80037 index 290901a..e99b01c 100644
80038 --- a/include/linux/mm_types.h
80039 +++ b/include/linux/mm_types.h
80040 @@ -307,7 +307,9 @@ struct vm_area_struct {
80041 #ifdef CONFIG_NUMA
80042 struct mempolicy *vm_policy; /* NUMA policy for the VMA */
80043 #endif
80044 -};
80045 +
80046 + struct vm_area_struct *vm_mirror;/* PaX: mirror vma or NULL */
80047 +} __randomize_layout;
80048
80049 struct core_thread {
80050 struct task_struct *task;
80051 @@ -453,7 +455,25 @@ struct mm_struct {
80052 bool tlb_flush_pending;
80053 #endif
80054 struct uprobes_state uprobes_state;
80055 -};
80056 +
80057 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
80058 + unsigned long pax_flags;
80059 +#endif
80060 +
80061 +#ifdef CONFIG_PAX_DLRESOLVE
80062 + unsigned long call_dl_resolve;
80063 +#endif
80064 +
80065 +#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
80066 + unsigned long call_syscall;
80067 +#endif
80068 +
80069 +#ifdef CONFIG_PAX_ASLR
80070 + unsigned long delta_mmap; /* randomized offset */
80071 + unsigned long delta_stack; /* randomized offset */
80072 +#endif
80073 +
80074 +} __randomize_layout;
80075
80076 static inline void mm_init_cpumask(struct mm_struct *mm)
80077 {
80078 diff --git a/include/linux/mmiotrace.h b/include/linux/mmiotrace.h
80079 index c5d5278..f0b68c8 100644
80080 --- a/include/linux/mmiotrace.h
80081 +++ b/include/linux/mmiotrace.h
80082 @@ -46,7 +46,7 @@ extern int kmmio_handler(struct pt_regs *regs, unsigned long addr);
80083 /* Called from ioremap.c */
80084 extern void mmiotrace_ioremap(resource_size_t offset, unsigned long size,
80085 void __iomem *addr);
80086 -extern void mmiotrace_iounmap(volatile void __iomem *addr);
80087 +extern void mmiotrace_iounmap(const volatile void __iomem *addr);
80088
80089 /* For anyone to insert markers. Remember trailing newline. */
80090 extern __printf(1, 2) int mmiotrace_printk(const char *fmt, ...);
80091 @@ -66,7 +66,7 @@ static inline void mmiotrace_ioremap(resource_size_t offset,
80092 {
80093 }
80094
80095 -static inline void mmiotrace_iounmap(volatile void __iomem *addr)
80096 +static inline void mmiotrace_iounmap(const volatile void __iomem *addr)
80097 {
80098 }
80099
80100 diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h
80101 index bd791e4..8617c34f 100644
80102 --- a/include/linux/mmzone.h
80103 +++ b/include/linux/mmzone.h
80104 @@ -396,7 +396,7 @@ struct zone {
80105 unsigned long flags; /* zone flags, see below */
80106
80107 /* Zone statistics */
80108 - atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
80109 + atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
80110
80111 /*
80112 * The target ratio of ACTIVE_ANON to INACTIVE_ANON pages on
80113 diff --git a/include/linux/mod_devicetable.h b/include/linux/mod_devicetable.h
80114 index 45e9214..a7227d6 100644
80115 --- a/include/linux/mod_devicetable.h
80116 +++ b/include/linux/mod_devicetable.h
80117 @@ -13,7 +13,7 @@
80118 typedef unsigned long kernel_ulong_t;
80119 #endif
80120
80121 -#define PCI_ANY_ID (~0)
80122 +#define PCI_ANY_ID ((__u16)~0)
80123
80124 struct pci_device_id {
80125 __u32 vendor, device; /* Vendor and device ID or PCI_ANY_ID*/
80126 @@ -139,7 +139,7 @@ struct usb_device_id {
80127 #define USB_DEVICE_ID_MATCH_INT_PROTOCOL 0x0200
80128 #define USB_DEVICE_ID_MATCH_INT_NUMBER 0x0400
80129
80130 -#define HID_ANY_ID (~0)
80131 +#define HID_ANY_ID (~0U)
80132 #define HID_BUS_ANY 0xffff
80133 #define HID_GROUP_ANY 0x0000
80134
80135 @@ -467,7 +467,7 @@ struct dmi_system_id {
80136 const char *ident;
80137 struct dmi_strmatch matches[4];
80138 void *driver_data;
80139 -};
80140 +} __do_const;
80141 /*
80142 * struct dmi_device_id appears during expansion of
80143 * "MODULE_DEVICE_TABLE(dmi, x)". Compiler doesn't look inside it
80144 diff --git a/include/linux/module.h b/include/linux/module.h
80145 index 15cd6b1..f6e2e6a 100644
80146 --- a/include/linux/module.h
80147 +++ b/include/linux/module.h
80148 @@ -17,9 +17,11 @@
80149 #include <linux/moduleparam.h>
80150 #include <linux/tracepoint.h>
80151 #include <linux/export.h>
80152 +#include <linux/fs.h>
80153
80154 #include <linux/percpu.h>
80155 #include <asm/module.h>
80156 +#include <asm/pgtable.h>
80157
80158 /* In stripped ARM and x86-64 modules, ~ is surprisingly rare. */
80159 #define MODULE_SIG_STRING "~Module signature appended~\n"
80160 @@ -43,7 +45,7 @@ struct module_kobject {
80161 struct kobject *drivers_dir;
80162 struct module_param_attrs *mp;
80163 struct completion *kobj_completion;
80164 -};
80165 +} __randomize_layout;
80166
80167 struct module_attribute {
80168 struct attribute attr;
80169 @@ -55,12 +57,13 @@ struct module_attribute {
80170 int (*test)(struct module *);
80171 void (*free)(struct module *);
80172 };
80173 +typedef struct module_attribute __no_const module_attribute_no_const;
80174
80175 struct module_version_attribute {
80176 struct module_attribute mattr;
80177 const char *module_name;
80178 const char *version;
80179 -} __attribute__ ((__aligned__(sizeof(void *))));
80180 +} __do_const __attribute__ ((__aligned__(sizeof(void *))));
80181
80182 extern ssize_t __modver_version_show(struct module_attribute *,
80183 struct module_kobject *, char *);
80184 @@ -238,7 +241,7 @@ struct module
80185
80186 /* Sysfs stuff. */
80187 struct module_kobject mkobj;
80188 - struct module_attribute *modinfo_attrs;
80189 + module_attribute_no_const *modinfo_attrs;
80190 const char *version;
80191 const char *srcversion;
80192 struct kobject *holders_dir;
80193 @@ -287,19 +290,16 @@ struct module
80194 int (*init)(void);
80195
80196 /* If this is non-NULL, vfree after init() returns */
80197 - void *module_init;
80198 + void *module_init_rx, *module_init_rw;
80199
80200 /* Here is the actual code + data, vfree'd on unload. */
80201 - void *module_core;
80202 + void *module_core_rx, *module_core_rw;
80203
80204 /* Here are the sizes of the init and core sections */
80205 - unsigned int init_size, core_size;
80206 + unsigned int init_size_rw, core_size_rw;
80207
80208 /* The size of the executable code in each section. */
80209 - unsigned int init_text_size, core_text_size;
80210 -
80211 - /* Size of RO sections of the module (text+rodata) */
80212 - unsigned int init_ro_size, core_ro_size;
80213 + unsigned int init_size_rx, core_size_rx;
80214
80215 /* Arch-specific module values */
80216 struct mod_arch_specific arch;
80217 @@ -355,6 +355,10 @@ struct module
80218 #ifdef CONFIG_EVENT_TRACING
80219 struct ftrace_event_call **trace_events;
80220 unsigned int num_trace_events;
80221 + struct file_operations trace_id;
80222 + struct file_operations trace_enable;
80223 + struct file_operations trace_format;
80224 + struct file_operations trace_filter;
80225 #endif
80226 #ifdef CONFIG_FTRACE_MCOUNT_RECORD
80227 unsigned int num_ftrace_callsites;
80228 @@ -378,7 +382,7 @@ struct module
80229 ctor_fn_t *ctors;
80230 unsigned int num_ctors;
80231 #endif
80232 -};
80233 +} __randomize_layout;
80234 #ifndef MODULE_ARCH_INIT
80235 #define MODULE_ARCH_INIT {}
80236 #endif
80237 @@ -399,16 +403,46 @@ bool is_module_address(unsigned long addr);
80238 bool is_module_percpu_address(unsigned long addr);
80239 bool is_module_text_address(unsigned long addr);
80240
80241 +static inline int within_module_range(unsigned long addr, void *start, unsigned long size)
80242 +{
80243 +
80244 +#ifdef CONFIG_PAX_KERNEXEC
80245 + if (ktla_ktva(addr) >= (unsigned long)start &&
80246 + ktla_ktva(addr) < (unsigned long)start + size)
80247 + return 1;
80248 +#endif
80249 +
80250 + return ((void *)addr >= start && (void *)addr < start + size);
80251 +}
80252 +
80253 +static inline int within_module_core_rx(unsigned long addr, const struct module *mod)
80254 +{
80255 + return within_module_range(addr, mod->module_core_rx, mod->core_size_rx);
80256 +}
80257 +
80258 +static inline int within_module_core_rw(unsigned long addr, const struct module *mod)
80259 +{
80260 + return within_module_range(addr, mod->module_core_rw, mod->core_size_rw);
80261 +}
80262 +
80263 +static inline int within_module_init_rx(unsigned long addr, const struct module *mod)
80264 +{
80265 + return within_module_range(addr, mod->module_init_rx, mod->init_size_rx);
80266 +}
80267 +
80268 +static inline int within_module_init_rw(unsigned long addr, const struct module *mod)
80269 +{
80270 + return within_module_range(addr, mod->module_init_rw, mod->init_size_rw);
80271 +}
80272 +
80273 static inline int within_module_core(unsigned long addr, const struct module *mod)
80274 {
80275 - return (unsigned long)mod->module_core <= addr &&
80276 - addr < (unsigned long)mod->module_core + mod->core_size;
80277 + return within_module_core_rx(addr, mod) || within_module_core_rw(addr, mod);
80278 }
80279
80280 static inline int within_module_init(unsigned long addr, const struct module *mod)
80281 {
80282 - return (unsigned long)mod->module_init <= addr &&
80283 - addr < (unsigned long)mod->module_init + mod->init_size;
80284 + return within_module_init_rx(addr, mod) || within_module_init_rw(addr, mod);
80285 }
80286
80287 /* Search for module by name: must hold module_mutex. */
80288 diff --git a/include/linux/moduleloader.h b/include/linux/moduleloader.h
80289 index 560ca53..ef621ef 100644
80290 --- a/include/linux/moduleloader.h
80291 +++ b/include/linux/moduleloader.h
80292 @@ -25,9 +25,21 @@ unsigned int arch_mod_section_prepend(struct module *mod, unsigned int section);
80293 sections. Returns NULL on failure. */
80294 void *module_alloc(unsigned long size);
80295
80296 +#ifdef CONFIG_PAX_KERNEXEC
80297 +void *module_alloc_exec(unsigned long size);
80298 +#else
80299 +#define module_alloc_exec(x) module_alloc(x)
80300 +#endif
80301 +
80302 /* Free memory returned from module_alloc. */
80303 void module_free(struct module *mod, void *module_region);
80304
80305 +#ifdef CONFIG_PAX_KERNEXEC
80306 +void module_free_exec(struct module *mod, void *module_region);
80307 +#else
80308 +#define module_free_exec(x, y) module_free((x), (y))
80309 +#endif
80310 +
80311 /*
80312 * Apply the given relocation to the (simplified) ELF. Return -error
80313 * or 0.
80314 @@ -45,7 +57,9 @@ static inline int apply_relocate(Elf_Shdr *sechdrs,
80315 unsigned int relsec,
80316 struct module *me)
80317 {
80318 +#ifdef CONFIG_MODULES
80319 printk(KERN_ERR "module %s: REL relocation unsupported\n", me->name);
80320 +#endif
80321 return -ENOEXEC;
80322 }
80323 #endif
80324 @@ -67,7 +81,9 @@ static inline int apply_relocate_add(Elf_Shdr *sechdrs,
80325 unsigned int relsec,
80326 struct module *me)
80327 {
80328 +#ifdef CONFIG_MODULES
80329 printk(KERN_ERR "module %s: REL relocation unsupported\n", me->name);
80330 +#endif
80331 return -ENOEXEC;
80332 }
80333 #endif
80334 diff --git a/include/linux/moduleparam.h b/include/linux/moduleparam.h
80335 index c3eb102..073c4a6 100644
80336 --- a/include/linux/moduleparam.h
80337 +++ b/include/linux/moduleparam.h
80338 @@ -295,7 +295,7 @@ static inline void __kernel_param_unlock(void)
80339 * @len is usually just sizeof(string).
80340 */
80341 #define module_param_string(name, string, len, perm) \
80342 - static const struct kparam_string __param_string_##name \
80343 + static const struct kparam_string __param_string_##name __used \
80344 = { len, string }; \
80345 __module_param_call(MODULE_PARAM_PREFIX, name, \
80346 &param_ops_string, \
80347 @@ -434,7 +434,7 @@ extern int param_set_bint(const char *val, const struct kernel_param *kp);
80348 */
80349 #define module_param_array_named(name, array, type, nump, perm) \
80350 param_check_##type(name, &(array)[0]); \
80351 - static const struct kparam_array __param_arr_##name \
80352 + static const struct kparam_array __param_arr_##name __used \
80353 = { .max = ARRAY_SIZE(array), .num = nump, \
80354 .ops = &param_ops_##type, \
80355 .elemsize = sizeof(array[0]), .elem = array }; \
80356 diff --git a/include/linux/mount.h b/include/linux/mount.h
80357 index 371d346..fba2819 100644
80358 --- a/include/linux/mount.h
80359 +++ b/include/linux/mount.h
80360 @@ -56,7 +56,7 @@ struct vfsmount {
80361 struct dentry *mnt_root; /* root of the mounted tree */
80362 struct super_block *mnt_sb; /* pointer to superblock */
80363 int mnt_flags;
80364 -};
80365 +} __randomize_layout;
80366
80367 struct file; /* forward dec */
80368
80369 diff --git a/include/linux/namei.h b/include/linux/namei.h
80370 index 492de72..1bddcd4 100644
80371 --- a/include/linux/namei.h
80372 +++ b/include/linux/namei.h
80373 @@ -19,7 +19,7 @@ struct nameidata {
80374 unsigned seq, m_seq;
80375 int last_type;
80376 unsigned depth;
80377 - char *saved_names[MAX_NESTED_LINKS + 1];
80378 + const char *saved_names[MAX_NESTED_LINKS + 1];
80379 };
80380
80381 /*
80382 @@ -83,12 +83,12 @@ extern void unlock_rename(struct dentry *, struct dentry *);
80383
80384 extern void nd_jump_link(struct nameidata *nd, struct path *path);
80385
80386 -static inline void nd_set_link(struct nameidata *nd, char *path)
80387 +static inline void nd_set_link(struct nameidata *nd, const char *path)
80388 {
80389 nd->saved_names[nd->depth] = path;
80390 }
80391
80392 -static inline char *nd_get_link(struct nameidata *nd)
80393 +static inline const char *nd_get_link(const struct nameidata *nd)
80394 {
80395 return nd->saved_names[nd->depth];
80396 }
80397 diff --git a/include/linux/net.h b/include/linux/net.h
80398 index 69be3e6..0fb422d 100644
80399 --- a/include/linux/net.h
80400 +++ b/include/linux/net.h
80401 @@ -192,7 +192,7 @@ struct net_proto_family {
80402 int (*create)(struct net *net, struct socket *sock,
80403 int protocol, int kern);
80404 struct module *owner;
80405 -};
80406 +} __do_const;
80407
80408 struct iovec;
80409 struct kvec;
80410 diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
80411 index 2177a6b..67fc561 100644
80412 --- a/include/linux/netdevice.h
80413 +++ b/include/linux/netdevice.h
80414 @@ -1129,6 +1129,7 @@ struct net_device_ops {
80415 struct net_device *dev,
80416 void *priv);
80417 };
80418 +typedef struct net_device_ops __no_const net_device_ops_no_const;
80419
80420 /*
80421 * The DEVICE structure.
80422 @@ -1211,7 +1212,7 @@ struct net_device {
80423 int iflink;
80424
80425 struct net_device_stats stats;
80426 - atomic_long_t rx_dropped; /* dropped packets by core network
80427 + atomic_long_unchecked_t rx_dropped; /* dropped packets by core network
80428 * Do not use this in drivers.
80429 */
80430
80431 diff --git a/include/linux/netfilter.h b/include/linux/netfilter.h
80432 index 2077489..a15e561 100644
80433 --- a/include/linux/netfilter.h
80434 +++ b/include/linux/netfilter.h
80435 @@ -84,7 +84,7 @@ struct nf_sockopt_ops {
80436 #endif
80437 /* Use the module struct to lock set/get code in place */
80438 struct module *owner;
80439 -};
80440 +} __do_const;
80441
80442 /* Function to register/unregister hook points. */
80443 int nf_register_hook(struct nf_hook_ops *reg);
80444 diff --git a/include/linux/netfilter/nfnetlink.h b/include/linux/netfilter/nfnetlink.h
80445 index 28c7436..2d6156a 100644
80446 --- a/include/linux/netfilter/nfnetlink.h
80447 +++ b/include/linux/netfilter/nfnetlink.h
80448 @@ -19,7 +19,7 @@ struct nfnl_callback {
80449 const struct nlattr * const cda[]);
80450 const struct nla_policy *policy; /* netlink attribute policy */
80451 const u_int16_t attr_count; /* number of nlattr's */
80452 -};
80453 +} __do_const;
80454
80455 struct nfnetlink_subsystem {
80456 const char *name;
80457 diff --git a/include/linux/netfilter/xt_gradm.h b/include/linux/netfilter/xt_gradm.h
80458 new file mode 100644
80459 index 0000000..33f4af8
80460 --- /dev/null
80461 +++ b/include/linux/netfilter/xt_gradm.h
80462 @@ -0,0 +1,9 @@
80463 +#ifndef _LINUX_NETFILTER_XT_GRADM_H
80464 +#define _LINUX_NETFILTER_XT_GRADM_H 1
80465 +
80466 +struct xt_gradm_mtinfo {
80467 + __u16 flags;
80468 + __u16 invflags;
80469 +};
80470 +
80471 +#endif
80472 diff --git a/include/linux/nls.h b/include/linux/nls.h
80473 index 5dc635f..35f5e11 100644
80474 --- a/include/linux/nls.h
80475 +++ b/include/linux/nls.h
80476 @@ -31,7 +31,7 @@ struct nls_table {
80477 const unsigned char *charset2upper;
80478 struct module *owner;
80479 struct nls_table *next;
80480 -};
80481 +} __do_const;
80482
80483 /* this value hold the maximum octet of charset */
80484 #define NLS_MAX_CHARSET_SIZE 6 /* for UTF-8 */
80485 diff --git a/include/linux/notifier.h b/include/linux/notifier.h
80486 index d14a4c3..a078786 100644
80487 --- a/include/linux/notifier.h
80488 +++ b/include/linux/notifier.h
80489 @@ -54,7 +54,8 @@ struct notifier_block {
80490 notifier_fn_t notifier_call;
80491 struct notifier_block __rcu *next;
80492 int priority;
80493 -};
80494 +} __do_const;
80495 +typedef struct notifier_block __no_const notifier_block_no_const;
80496
80497 struct atomic_notifier_head {
80498 spinlock_t lock;
80499 diff --git a/include/linux/oprofile.h b/include/linux/oprofile.h
80500 index b2a0f15..4d7da32 100644
80501 --- a/include/linux/oprofile.h
80502 +++ b/include/linux/oprofile.h
80503 @@ -138,9 +138,9 @@ int oprofilefs_create_ulong(struct dentry * root,
80504 int oprofilefs_create_ro_ulong(struct dentry * root,
80505 char const * name, ulong * val);
80506
80507 -/** Create a file for read-only access to an atomic_t. */
80508 +/** Create a file for read-only access to an atomic_unchecked_t. */
80509 int oprofilefs_create_ro_atomic(struct dentry * root,
80510 - char const * name, atomic_t * val);
80511 + char const * name, atomic_unchecked_t * val);
80512
80513 /** create a directory */
80514 struct dentry *oprofilefs_mkdir(struct dentry *parent, char const *name);
80515 diff --git a/include/linux/padata.h b/include/linux/padata.h
80516 index 4386946..f50c615 100644
80517 --- a/include/linux/padata.h
80518 +++ b/include/linux/padata.h
80519 @@ -129,7 +129,7 @@ struct parallel_data {
80520 struct padata_serial_queue __percpu *squeue;
80521 atomic_t reorder_objects;
80522 atomic_t refcnt;
80523 - atomic_t seq_nr;
80524 + atomic_unchecked_t seq_nr;
80525 struct padata_cpumask cpumask;
80526 spinlock_t lock ____cacheline_aligned;
80527 unsigned int processed;
80528 diff --git a/include/linux/path.h b/include/linux/path.h
80529 index d137218..be0c176 100644
80530 --- a/include/linux/path.h
80531 +++ b/include/linux/path.h
80532 @@ -1,13 +1,15 @@
80533 #ifndef _LINUX_PATH_H
80534 #define _LINUX_PATH_H
80535
80536 +#include <linux/compiler.h>
80537 +
80538 struct dentry;
80539 struct vfsmount;
80540
80541 struct path {
80542 struct vfsmount *mnt;
80543 struct dentry *dentry;
80544 -};
80545 +} __randomize_layout;
80546
80547 extern void path_get(const struct path *);
80548 extern void path_put(const struct path *);
80549 diff --git a/include/linux/pci_hotplug.h b/include/linux/pci_hotplug.h
80550 index a2e2f1d..8a391d2 100644
80551 --- a/include/linux/pci_hotplug.h
80552 +++ b/include/linux/pci_hotplug.h
80553 @@ -71,7 +71,8 @@ struct hotplug_slot_ops {
80554 int (*get_latch_status) (struct hotplug_slot *slot, u8 *value);
80555 int (*get_adapter_status) (struct hotplug_slot *slot, u8 *value);
80556 int (*reset_slot) (struct hotplug_slot *slot, int probe);
80557 -};
80558 +} __do_const;
80559 +typedef struct hotplug_slot_ops __no_const hotplug_slot_ops_no_const;
80560
80561 /**
80562 * struct hotplug_slot_info - used to notify the hotplug pci core of the state of the slot
80563 diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h
80564 index 2e069d1..27054b8 100644
80565 --- a/include/linux/perf_event.h
80566 +++ b/include/linux/perf_event.h
80567 @@ -327,8 +327,8 @@ struct perf_event {
80568
80569 enum perf_event_active_state state;
80570 unsigned int attach_state;
80571 - local64_t count;
80572 - atomic64_t child_count;
80573 + local64_t count; /* PaX: fix it one day */
80574 + atomic64_unchecked_t child_count;
80575
80576 /*
80577 * These are the total time in nanoseconds that the event
80578 @@ -379,8 +379,8 @@ struct perf_event {
80579 * These accumulate total time (in nanoseconds) that children
80580 * events have been enabled and running, respectively.
80581 */
80582 - atomic64_t child_total_time_enabled;
80583 - atomic64_t child_total_time_running;
80584 + atomic64_unchecked_t child_total_time_enabled;
80585 + atomic64_unchecked_t child_total_time_running;
80586
80587 /*
80588 * Protect attach/detach and child_list:
80589 @@ -707,7 +707,7 @@ static inline void perf_callchain_store(struct perf_callchain_entry *entry, u64
80590 entry->ip[entry->nr++] = ip;
80591 }
80592
80593 -extern int sysctl_perf_event_paranoid;
80594 +extern int sysctl_perf_event_legitimately_concerned;
80595 extern int sysctl_perf_event_mlock;
80596 extern int sysctl_perf_event_sample_rate;
80597 extern int sysctl_perf_cpu_time_max_percent;
80598 @@ -722,19 +722,24 @@ extern int perf_cpu_time_max_percent_handler(struct ctl_table *table, int write,
80599 loff_t *ppos);
80600
80601
80602 +static inline bool perf_paranoid_any(void)
80603 +{
80604 + return sysctl_perf_event_legitimately_concerned > 2;
80605 +}
80606 +
80607 static inline bool perf_paranoid_tracepoint_raw(void)
80608 {
80609 - return sysctl_perf_event_paranoid > -1;
80610 + return sysctl_perf_event_legitimately_concerned > -1;
80611 }
80612
80613 static inline bool perf_paranoid_cpu(void)
80614 {
80615 - return sysctl_perf_event_paranoid > 0;
80616 + return sysctl_perf_event_legitimately_concerned > 0;
80617 }
80618
80619 static inline bool perf_paranoid_kernel(void)
80620 {
80621 - return sysctl_perf_event_paranoid > 1;
80622 + return sysctl_perf_event_legitimately_concerned > 1;
80623 }
80624
80625 extern void perf_event_init(void);
80626 @@ -850,7 +855,7 @@ struct perf_pmu_events_attr {
80627 struct device_attribute attr;
80628 u64 id;
80629 const char *event_str;
80630 -};
80631 +} __do_const;
80632
80633 #define PMU_EVENT_ATTR(_name, _var, _id, _show) \
80634 static struct perf_pmu_events_attr _var = { \
80635 diff --git a/include/linux/pid_namespace.h b/include/linux/pid_namespace.h
80636 index 7246ef3..1539ea4 100644
80637 --- a/include/linux/pid_namespace.h
80638 +++ b/include/linux/pid_namespace.h
80639 @@ -43,7 +43,7 @@ struct pid_namespace {
80640 int hide_pid;
80641 int reboot; /* group exit code if this pidns was rebooted */
80642 unsigned int proc_inum;
80643 -};
80644 +} __randomize_layout;
80645
80646 extern struct pid_namespace init_pid_ns;
80647
80648 diff --git a/include/linux/pipe_fs_i.h b/include/linux/pipe_fs_i.h
80649 index ab57526..94598804 100644
80650 --- a/include/linux/pipe_fs_i.h
80651 +++ b/include/linux/pipe_fs_i.h
80652 @@ -47,10 +47,10 @@ struct pipe_inode_info {
80653 struct mutex mutex;
80654 wait_queue_head_t wait;
80655 unsigned int nrbufs, curbuf, buffers;
80656 - unsigned int readers;
80657 - unsigned int writers;
80658 - unsigned int files;
80659 - unsigned int waiting_writers;
80660 + atomic_t readers;
80661 + atomic_t writers;
80662 + atomic_t files;
80663 + atomic_t waiting_writers;
80664 unsigned int r_counter;
80665 unsigned int w_counter;
80666 struct page *tmp_page;
80667 diff --git a/include/linux/pm.h b/include/linux/pm.h
80668 index a224c7f..92d8a97 100644
80669 --- a/include/linux/pm.h
80670 +++ b/include/linux/pm.h
80671 @@ -576,6 +576,7 @@ extern int dev_pm_put_subsys_data(struct device *dev);
80672 struct dev_pm_domain {
80673 struct dev_pm_ops ops;
80674 };
80675 +typedef struct dev_pm_domain __no_const dev_pm_domain_no_const;
80676
80677 /*
80678 * The PM_EVENT_ messages are also used by drivers implementing the legacy
80679 diff --git a/include/linux/pm_domain.h b/include/linux/pm_domain.h
80680 index 7c1d252..0e7061d 100644
80681 --- a/include/linux/pm_domain.h
80682 +++ b/include/linux/pm_domain.h
80683 @@ -44,11 +44,11 @@ struct gpd_dev_ops {
80684 int (*thaw_early)(struct device *dev);
80685 int (*thaw)(struct device *dev);
80686 bool (*active_wakeup)(struct device *dev);
80687 -};
80688 +} __no_const;
80689
80690 struct gpd_cpu_data {
80691 unsigned int saved_exit_latency;
80692 - struct cpuidle_state *idle_state;
80693 + cpuidle_state_no_const *idle_state;
80694 };
80695
80696 struct generic_pm_domain {
80697 diff --git a/include/linux/pm_runtime.h b/include/linux/pm_runtime.h
80698 index 6fa7cea..7bf6415 100644
80699 --- a/include/linux/pm_runtime.h
80700 +++ b/include/linux/pm_runtime.h
80701 @@ -103,7 +103,7 @@ static inline bool pm_runtime_callbacks_present(struct device *dev)
80702
80703 static inline void pm_runtime_mark_last_busy(struct device *dev)
80704 {
80705 - ACCESS_ONCE(dev->power.last_busy) = jiffies;
80706 + ACCESS_ONCE_RW(dev->power.last_busy) = jiffies;
80707 }
80708
80709 #else /* !CONFIG_PM_RUNTIME */
80710 diff --git a/include/linux/pnp.h b/include/linux/pnp.h
80711 index 195aafc..49a7bc2 100644
80712 --- a/include/linux/pnp.h
80713 +++ b/include/linux/pnp.h
80714 @@ -297,7 +297,7 @@ static inline void pnp_set_drvdata(struct pnp_dev *pdev, void *data)
80715 struct pnp_fixup {
80716 char id[7];
80717 void (*quirk_function) (struct pnp_dev * dev); /* fixup function */
80718 -};
80719 +} __do_const;
80720
80721 /* config parameters */
80722 #define PNP_CONFIG_NORMAL 0x0001
80723 diff --git a/include/linux/poison.h b/include/linux/poison.h
80724 index 2110a81..13a11bb 100644
80725 --- a/include/linux/poison.h
80726 +++ b/include/linux/poison.h
80727 @@ -19,8 +19,8 @@
80728 * under normal circumstances, used to verify that nobody uses
80729 * non-initialized list entries.
80730 */
80731 -#define LIST_POISON1 ((void *) 0x00100100 + POISON_POINTER_DELTA)
80732 -#define LIST_POISON2 ((void *) 0x00200200 + POISON_POINTER_DELTA)
80733 +#define LIST_POISON1 ((void *) (long)0xFFFFFF01)
80734 +#define LIST_POISON2 ((void *) (long)0xFFFFFF02)
80735
80736 /********** include/linux/timer.h **********/
80737 /*
80738 diff --git a/include/linux/power/smartreflex.h b/include/linux/power/smartreflex.h
80739 index d8b187c3..9a9257a 100644
80740 --- a/include/linux/power/smartreflex.h
80741 +++ b/include/linux/power/smartreflex.h
80742 @@ -238,7 +238,7 @@ struct omap_sr_class_data {
80743 int (*notify)(struct omap_sr *sr, u32 status);
80744 u8 notify_flags;
80745 u8 class_type;
80746 -};
80747 +} __do_const;
80748
80749 /**
80750 * struct omap_sr_nvalue_table - Smartreflex n-target value info
80751 diff --git a/include/linux/ppp-comp.h b/include/linux/ppp-comp.h
80752 index 4ea1d37..80f4b33 100644
80753 --- a/include/linux/ppp-comp.h
80754 +++ b/include/linux/ppp-comp.h
80755 @@ -84,7 +84,7 @@ struct compressor {
80756 struct module *owner;
80757 /* Extra skb space needed by the compressor algorithm */
80758 unsigned int comp_extra;
80759 -};
80760 +} __do_const;
80761
80762 /*
80763 * The return value from decompress routine is the length of the
80764 diff --git a/include/linux/preempt.h b/include/linux/preempt.h
80765 index a3d9dc8..8af9922 100644
80766 --- a/include/linux/preempt.h
80767 +++ b/include/linux/preempt.h
80768 @@ -27,11 +27,16 @@ extern void preempt_count_sub(int val);
80769 #define preempt_count_dec_and_test() __preempt_count_dec_and_test()
80770 #endif
80771
80772 +#define raw_preempt_count_add(val) __preempt_count_add(val)
80773 +#define raw_preempt_count_sub(val) __preempt_count_sub(val)
80774 +
80775 #define __preempt_count_inc() __preempt_count_add(1)
80776 #define __preempt_count_dec() __preempt_count_sub(1)
80777
80778 #define preempt_count_inc() preempt_count_add(1)
80779 +#define raw_preempt_count_inc() raw_preempt_count_add(1)
80780 #define preempt_count_dec() preempt_count_sub(1)
80781 +#define raw_preempt_count_dec() raw_preempt_count_sub(1)
80782
80783 #ifdef CONFIG_PREEMPT_COUNT
80784
80785 @@ -41,6 +46,12 @@ do { \
80786 barrier(); \
80787 } while (0)
80788
80789 +#define raw_preempt_disable() \
80790 +do { \
80791 + raw_preempt_count_inc(); \
80792 + barrier(); \
80793 +} while (0)
80794 +
80795 #define sched_preempt_enable_no_resched() \
80796 do { \
80797 barrier(); \
80798 @@ -49,6 +60,12 @@ do { \
80799
80800 #define preempt_enable_no_resched() sched_preempt_enable_no_resched()
80801
80802 +#define raw_preempt_enable_no_resched() \
80803 +do { \
80804 + barrier(); \
80805 + raw_preempt_count_dec(); \
80806 +} while (0)
80807 +
80808 #ifdef CONFIG_PREEMPT
80809 #define preempt_enable() \
80810 do { \
80811 @@ -105,8 +122,10 @@ do { \
80812 * region.
80813 */
80814 #define preempt_disable() barrier()
80815 +#define raw_preempt_disable() barrier()
80816 #define sched_preempt_enable_no_resched() barrier()
80817 #define preempt_enable_no_resched() barrier()
80818 +#define raw_preempt_enable_no_resched() barrier()
80819 #define preempt_enable() barrier()
80820 #define preempt_check_resched() do { } while (0)
80821
80822 diff --git a/include/linux/printk.h b/include/linux/printk.h
80823 index 6949258..7c4730e 100644
80824 --- a/include/linux/printk.h
80825 +++ b/include/linux/printk.h
80826 @@ -106,6 +106,8 @@ static inline __printf(1, 2) __cold
80827 void early_printk(const char *s, ...) { }
80828 #endif
80829
80830 +extern int kptr_restrict;
80831 +
80832 #ifdef CONFIG_PRINTK
80833 asmlinkage __printf(5, 0)
80834 int vprintk_emit(int facility, int level,
80835 @@ -140,7 +142,6 @@ extern bool printk_timed_ratelimit(unsigned long *caller_jiffies,
80836
80837 extern int printk_delay_msec;
80838 extern int dmesg_restrict;
80839 -extern int kptr_restrict;
80840
80841 extern void wake_up_klogd(void);
80842
80843 diff --git a/include/linux/proc_fs.h b/include/linux/proc_fs.h
80844 index 608e60a..c26f864 100644
80845 --- a/include/linux/proc_fs.h
80846 +++ b/include/linux/proc_fs.h
80847 @@ -34,6 +34,19 @@ static inline struct proc_dir_entry *proc_create(
80848 return proc_create_data(name, mode, parent, proc_fops, NULL);
80849 }
80850
80851 +static inline struct proc_dir_entry *proc_create_grsec(const char *name, umode_t mode,
80852 + struct proc_dir_entry *parent, const struct file_operations *proc_fops)
80853 +{
80854 +#ifdef CONFIG_GRKERNSEC_PROC_USER
80855 + return proc_create_data(name, S_IRUSR, parent, proc_fops, NULL);
80856 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
80857 + return proc_create_data(name, S_IRUSR | S_IRGRP, parent, proc_fops, NULL);
80858 +#else
80859 + return proc_create_data(name, mode, parent, proc_fops, NULL);
80860 +#endif
80861 +}
80862 +
80863 +
80864 extern void proc_set_size(struct proc_dir_entry *, loff_t);
80865 extern void proc_set_user(struct proc_dir_entry *, kuid_t, kgid_t);
80866 extern void *PDE_DATA(const struct inode *);
80867 diff --git a/include/linux/proc_ns.h b/include/linux/proc_ns.h
80868 index 34a1e10..70f6bde 100644
80869 --- a/include/linux/proc_ns.h
80870 +++ b/include/linux/proc_ns.h
80871 @@ -14,7 +14,7 @@ struct proc_ns_operations {
80872 void (*put)(void *ns);
80873 int (*install)(struct nsproxy *nsproxy, void *ns);
80874 unsigned int (*inum)(void *ns);
80875 -};
80876 +} __do_const __randomize_layout;
80877
80878 struct proc_ns {
80879 void *ns;
80880 diff --git a/include/linux/quota.h b/include/linux/quota.h
80881 index cc7494a..1e27036 100644
80882 --- a/include/linux/quota.h
80883 +++ b/include/linux/quota.h
80884 @@ -70,7 +70,7 @@ struct kqid { /* Type in which we store the quota identifier */
80885
80886 extern bool qid_eq(struct kqid left, struct kqid right);
80887 extern bool qid_lt(struct kqid left, struct kqid right);
80888 -extern qid_t from_kqid(struct user_namespace *to, struct kqid qid);
80889 +extern qid_t from_kqid(struct user_namespace *to, struct kqid qid) __intentional_overflow(-1);
80890 extern qid_t from_kqid_munged(struct user_namespace *to, struct kqid qid);
80891 extern bool qid_valid(struct kqid qid);
80892
80893 diff --git a/include/linux/random.h b/include/linux/random.h
80894 index 4002b3d..d5ad855 100644
80895 --- a/include/linux/random.h
80896 +++ b/include/linux/random.h
80897 @@ -10,9 +10,19 @@
80898
80899
80900 extern void add_device_randomness(const void *, unsigned int);
80901 +
80902 +static inline void add_latent_entropy(void)
80903 +{
80904 +
80905 +#ifdef LATENT_ENTROPY_PLUGIN
80906 + add_device_randomness((const void *)&latent_entropy, sizeof(latent_entropy));
80907 +#endif
80908 +
80909 +}
80910 +
80911 extern void add_input_randomness(unsigned int type, unsigned int code,
80912 - unsigned int value);
80913 -extern void add_interrupt_randomness(int irq, int irq_flags);
80914 + unsigned int value) __latent_entropy;
80915 +extern void add_interrupt_randomness(int irq, int irq_flags) __latent_entropy;
80916
80917 extern void get_random_bytes(void *buf, int nbytes);
80918 extern void get_random_bytes_arch(void *buf, int nbytes);
80919 @@ -23,10 +33,10 @@ extern int random_int_secret_init(void);
80920 extern const struct file_operations random_fops, urandom_fops;
80921 #endif
80922
80923 -unsigned int get_random_int(void);
80924 +unsigned int __intentional_overflow(-1) get_random_int(void);
80925 unsigned long randomize_range(unsigned long start, unsigned long end, unsigned long len);
80926
80927 -u32 prandom_u32(void);
80928 +u32 prandom_u32(void) __intentional_overflow(-1);
80929 void prandom_bytes(void *buf, int nbytes);
80930 void prandom_seed(u32 seed);
80931 void prandom_reseed_late(void);
80932 @@ -38,6 +48,11 @@ struct rnd_state {
80933 u32 prandom_u32_state(struct rnd_state *state);
80934 void prandom_bytes_state(struct rnd_state *state, void *buf, int nbytes);
80935
80936 +static inline unsigned long __intentional_overflow(-1) pax_get_random_long(void)
80937 +{
80938 + return prandom_u32() + (sizeof(long) > 4 ? (unsigned long)prandom_u32() << 32 : 0);
80939 +}
80940 +
80941 /*
80942 * Handle minimum values for seeds
80943 */
80944 diff --git a/include/linux/rbtree_augmented.h b/include/linux/rbtree_augmented.h
80945 index fea49b5..2ac22bb 100644
80946 --- a/include/linux/rbtree_augmented.h
80947 +++ b/include/linux/rbtree_augmented.h
80948 @@ -80,7 +80,9 @@ rbname ## _rotate(struct rb_node *rb_old, struct rb_node *rb_new) \
80949 old->rbaugmented = rbcompute(old); \
80950 } \
80951 rbstatic const struct rb_augment_callbacks rbname = { \
80952 - rbname ## _propagate, rbname ## _copy, rbname ## _rotate \
80953 + .propagate = rbname ## _propagate, \
80954 + .copy = rbname ## _copy, \
80955 + .rotate = rbname ## _rotate \
80956 };
80957
80958
80959 diff --git a/include/linux/rculist.h b/include/linux/rculist.h
80960 index 45a0a9e..e83788e 100644
80961 --- a/include/linux/rculist.h
80962 +++ b/include/linux/rculist.h
80963 @@ -29,8 +29,8 @@
80964 */
80965 static inline void INIT_LIST_HEAD_RCU(struct list_head *list)
80966 {
80967 - ACCESS_ONCE(list->next) = list;
80968 - ACCESS_ONCE(list->prev) = list;
80969 + ACCESS_ONCE_RW(list->next) = list;
80970 + ACCESS_ONCE_RW(list->prev) = list;
80971 }
80972
80973 /*
80974 @@ -59,6 +59,9 @@ extern void __list_add_rcu(struct list_head *new,
80975 struct list_head *prev, struct list_head *next);
80976 #endif
80977
80978 +extern void __pax_list_add_rcu(struct list_head *new,
80979 + struct list_head *prev, struct list_head *next);
80980 +
80981 /**
80982 * list_add_rcu - add a new entry to rcu-protected list
80983 * @new: new entry to be added
80984 @@ -80,6 +83,11 @@ static inline void list_add_rcu(struct list_head *new, struct list_head *head)
80985 __list_add_rcu(new, head, head->next);
80986 }
80987
80988 +static inline void pax_list_add_rcu(struct list_head *new, struct list_head *head)
80989 +{
80990 + __pax_list_add_rcu(new, head, head->next);
80991 +}
80992 +
80993 /**
80994 * list_add_tail_rcu - add a new entry to rcu-protected list
80995 * @new: new entry to be added
80996 @@ -102,6 +110,12 @@ static inline void list_add_tail_rcu(struct list_head *new,
80997 __list_add_rcu(new, head->prev, head);
80998 }
80999
81000 +static inline void pax_list_add_tail_rcu(struct list_head *new,
81001 + struct list_head *head)
81002 +{
81003 + __pax_list_add_rcu(new, head->prev, head);
81004 +}
81005 +
81006 /**
81007 * list_del_rcu - deletes entry from list without re-initialization
81008 * @entry: the element to delete from the list.
81009 @@ -132,6 +146,8 @@ static inline void list_del_rcu(struct list_head *entry)
81010 entry->prev = LIST_POISON2;
81011 }
81012
81013 +extern void pax_list_del_rcu(struct list_head *entry);
81014 +
81015 /**
81016 * hlist_del_init_rcu - deletes entry from hash list with re-initialization
81017 * @n: the element to delete from the hash list.
81018 diff --git a/include/linux/reboot.h b/include/linux/reboot.h
81019 index 9e7db9e..7d4fd72 100644
81020 --- a/include/linux/reboot.h
81021 +++ b/include/linux/reboot.h
81022 @@ -44,9 +44,9 @@ extern int unregister_reboot_notifier(struct notifier_block *);
81023 */
81024
81025 extern void migrate_to_reboot_cpu(void);
81026 -extern void machine_restart(char *cmd);
81027 -extern void machine_halt(void);
81028 -extern void machine_power_off(void);
81029 +extern void machine_restart(char *cmd) __noreturn;
81030 +extern void machine_halt(void) __noreturn;
81031 +extern void machine_power_off(void) __noreturn;
81032
81033 extern void machine_shutdown(void);
81034 struct pt_regs;
81035 @@ -57,9 +57,9 @@ extern void machine_crash_shutdown(struct pt_regs *);
81036 */
81037
81038 extern void kernel_restart_prepare(char *cmd);
81039 -extern void kernel_restart(char *cmd);
81040 -extern void kernel_halt(void);
81041 -extern void kernel_power_off(void);
81042 +extern void kernel_restart(char *cmd) __noreturn;
81043 +extern void kernel_halt(void) __noreturn;
81044 +extern void kernel_power_off(void) __noreturn;
81045
81046 extern int C_A_D; /* for sysctl */
81047 void ctrl_alt_del(void);
81048 @@ -73,7 +73,7 @@ extern int orderly_poweroff(bool force);
81049 * Emergency restart, callable from an interrupt handler.
81050 */
81051
81052 -extern void emergency_restart(void);
81053 +extern void emergency_restart(void) __noreturn;
81054 #include <asm/emergency-restart.h>
81055
81056 #endif /* _LINUX_REBOOT_H */
81057 diff --git a/include/linux/regset.h b/include/linux/regset.h
81058 index 8e0c9fe..ac4d221 100644
81059 --- a/include/linux/regset.h
81060 +++ b/include/linux/regset.h
81061 @@ -161,7 +161,8 @@ struct user_regset {
81062 unsigned int align;
81063 unsigned int bias;
81064 unsigned int core_note_type;
81065 -};
81066 +} __do_const;
81067 +typedef struct user_regset __no_const user_regset_no_const;
81068
81069 /**
81070 * struct user_regset_view - available regsets
81071 diff --git a/include/linux/relay.h b/include/linux/relay.h
81072 index d7c8359..818daf5 100644
81073 --- a/include/linux/relay.h
81074 +++ b/include/linux/relay.h
81075 @@ -157,7 +157,7 @@ struct rchan_callbacks
81076 * The callback should return 0 if successful, negative if not.
81077 */
81078 int (*remove_buf_file)(struct dentry *dentry);
81079 -};
81080 +} __no_const;
81081
81082 /*
81083 * CONFIG_RELAY kernel API, kernel/relay.c
81084 diff --git a/include/linux/rio.h b/include/linux/rio.h
81085 index b71d573..2f940bd 100644
81086 --- a/include/linux/rio.h
81087 +++ b/include/linux/rio.h
81088 @@ -355,7 +355,7 @@ struct rio_ops {
81089 int (*map_inb)(struct rio_mport *mport, dma_addr_t lstart,
81090 u64 rstart, u32 size, u32 flags);
81091 void (*unmap_inb)(struct rio_mport *mport, dma_addr_t lstart);
81092 -};
81093 +} __no_const;
81094
81095 #define RIO_RESOURCE_MEM 0x00000100
81096 #define RIO_RESOURCE_DOORBELL 0x00000200
81097 diff --git a/include/linux/rmap.h b/include/linux/rmap.h
81098 index 6dacb93..6174423 100644
81099 --- a/include/linux/rmap.h
81100 +++ b/include/linux/rmap.h
81101 @@ -145,8 +145,8 @@ static inline void anon_vma_unlock_read(struct anon_vma *anon_vma)
81102 void anon_vma_init(void); /* create anon_vma_cachep */
81103 int anon_vma_prepare(struct vm_area_struct *);
81104 void unlink_anon_vmas(struct vm_area_struct *);
81105 -int anon_vma_clone(struct vm_area_struct *, struct vm_area_struct *);
81106 -int anon_vma_fork(struct vm_area_struct *, struct vm_area_struct *);
81107 +int anon_vma_clone(struct vm_area_struct *, const struct vm_area_struct *);
81108 +int anon_vma_fork(struct vm_area_struct *, const struct vm_area_struct *);
81109
81110 static inline void anon_vma_merge(struct vm_area_struct *vma,
81111 struct vm_area_struct *next)
81112 diff --git a/include/linux/sched.h b/include/linux/sched.h
81113 index 53f97eb..1d90705 100644
81114 --- a/include/linux/sched.h
81115 +++ b/include/linux/sched.h
81116 @@ -63,6 +63,7 @@ struct bio_list;
81117 struct fs_struct;
81118 struct perf_event_context;
81119 struct blk_plug;
81120 +struct linux_binprm;
81121
81122 /*
81123 * List of flags we want to share for kernel threads,
81124 @@ -304,7 +305,7 @@ extern char __sched_text_start[], __sched_text_end[];
81125 extern int in_sched_functions(unsigned long addr);
81126
81127 #define MAX_SCHEDULE_TIMEOUT LONG_MAX
81128 -extern signed long schedule_timeout(signed long timeout);
81129 +extern signed long schedule_timeout(signed long timeout) __intentional_overflow(-1);
81130 extern signed long schedule_timeout_interruptible(signed long timeout);
81131 extern signed long schedule_timeout_killable(signed long timeout);
81132 extern signed long schedule_timeout_uninterruptible(signed long timeout);
81133 @@ -315,6 +316,19 @@ struct nsproxy;
81134 struct user_namespace;
81135
81136 #ifdef CONFIG_MMU
81137 +
81138 +#ifdef CONFIG_GRKERNSEC_RAND_THREADSTACK
81139 +extern unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags);
81140 +#else
81141 +static inline unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags)
81142 +{
81143 + return 0;
81144 +}
81145 +#endif
81146 +
81147 +extern bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len, unsigned long offset);
81148 +extern unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len, unsigned long offset);
81149 +
81150 extern void arch_pick_mmap_layout(struct mm_struct *mm);
81151 extern unsigned long
81152 arch_get_unmapped_area(struct file *, unsigned long, unsigned long,
81153 @@ -600,6 +614,17 @@ struct signal_struct {
81154 #ifdef CONFIG_TASKSTATS
81155 struct taskstats *stats;
81156 #endif
81157 +
81158 +#ifdef CONFIG_GRKERNSEC
81159 + u32 curr_ip;
81160 + u32 saved_ip;
81161 + u32 gr_saddr;
81162 + u32 gr_daddr;
81163 + u16 gr_sport;
81164 + u16 gr_dport;
81165 + u8 used_accept:1;
81166 +#endif
81167 +
81168 #ifdef CONFIG_AUDIT
81169 unsigned audit_tty;
81170 unsigned audit_tty_log_passwd;
81171 @@ -626,7 +651,7 @@ struct signal_struct {
81172 struct mutex cred_guard_mutex; /* guard against foreign influences on
81173 * credential calculations
81174 * (notably. ptrace) */
81175 -};
81176 +} __randomize_layout;
81177
81178 /*
81179 * Bits in flags field of signal_struct.
81180 @@ -680,6 +705,14 @@ struct user_struct {
81181 struct key *session_keyring; /* UID's default session keyring */
81182 #endif
81183
81184 +#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
81185 + unsigned char kernel_banned;
81186 +#endif
81187 +#ifdef CONFIG_GRKERNSEC_BRUTE
81188 + unsigned char suid_banned;
81189 + unsigned long suid_ban_expires;
81190 +#endif
81191 +
81192 /* Hash table maintenance information */
81193 struct hlist_node uidhash_node;
81194 kuid_t uid;
81195 @@ -687,7 +720,7 @@ struct user_struct {
81196 #ifdef CONFIG_PERF_EVENTS
81197 atomic_long_t locked_vm;
81198 #endif
81199 -};
81200 +} __randomize_layout;
81201
81202 extern int uids_sysfs_init(void);
81203
81204 @@ -1162,8 +1195,8 @@ struct task_struct {
81205 struct list_head thread_group;
81206
81207 struct completion *vfork_done; /* for vfork() */
81208 - int __user *set_child_tid; /* CLONE_CHILD_SETTID */
81209 - int __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
81210 + pid_t __user *set_child_tid; /* CLONE_CHILD_SETTID */
81211 + pid_t __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
81212
81213 cputime_t utime, stime, utimescaled, stimescaled;
81214 cputime_t gtime;
81215 @@ -1188,11 +1221,6 @@ struct task_struct {
81216 struct task_cputime cputime_expires;
81217 struct list_head cpu_timers[3];
81218
81219 -/* process credentials */
81220 - const struct cred __rcu *real_cred; /* objective and real subjective task
81221 - * credentials (COW) */
81222 - const struct cred __rcu *cred; /* effective (overridable) subjective task
81223 - * credentials (COW) */
81224 char comm[TASK_COMM_LEN]; /* executable name excluding path
81225 - access with [gs]et_task_comm (which lock
81226 it with task_lock())
81227 @@ -1209,6 +1237,10 @@ struct task_struct {
81228 #endif
81229 /* CPU-specific state of this task */
81230 struct thread_struct thread;
81231 +/* thread_info moved to task_struct */
81232 +#ifdef CONFIG_X86
81233 + struct thread_info tinfo;
81234 +#endif
81235 /* filesystem information */
81236 struct fs_struct *fs;
81237 /* open file information */
81238 @@ -1282,6 +1314,10 @@ struct task_struct {
81239 gfp_t lockdep_reclaim_gfp;
81240 #endif
81241
81242 +/* process credentials */
81243 + const struct cred __rcu *real_cred; /* objective and real subjective task
81244 + * credentials (COW) */
81245 +
81246 /* journalling filesystem info */
81247 void *journal_info;
81248
81249 @@ -1320,6 +1356,10 @@ struct task_struct {
81250 /* cg_list protected by css_set_lock and tsk->alloc_lock */
81251 struct list_head cg_list;
81252 #endif
81253 +
81254 + const struct cred __rcu *cred; /* effective (overridable) subjective task
81255 + * credentials (COW) */
81256 +
81257 #ifdef CONFIG_FUTEX
81258 struct robust_list_head __user *robust_list;
81259 #ifdef CONFIG_COMPAT
81260 @@ -1454,7 +1494,78 @@ struct task_struct {
81261 unsigned int sequential_io;
81262 unsigned int sequential_io_avg;
81263 #endif
81264 -};
81265 +
81266 +#ifdef CONFIG_GRKERNSEC
81267 + /* grsecurity */
81268 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
81269 + u64 exec_id;
81270 +#endif
81271 +#ifdef CONFIG_GRKERNSEC_SETXID
81272 + const struct cred *delayed_cred;
81273 +#endif
81274 + struct dentry *gr_chroot_dentry;
81275 + struct acl_subject_label *acl;
81276 + struct acl_subject_label *tmpacl;
81277 + struct acl_role_label *role;
81278 + struct file *exec_file;
81279 + unsigned long brute_expires;
81280 + u16 acl_role_id;
81281 + u8 inherited;
81282 + /* is this the task that authenticated to the special role */
81283 + u8 acl_sp_role;
81284 + u8 is_writable;
81285 + u8 brute;
81286 + u8 gr_is_chrooted;
81287 +#endif
81288 +
81289 +} __randomize_layout;
81290 +
81291 +#define MF_PAX_PAGEEXEC 0x01000000 /* Paging based non-executable pages */
81292 +#define MF_PAX_EMUTRAMP 0x02000000 /* Emulate trampolines */
81293 +#define MF_PAX_MPROTECT 0x04000000 /* Restrict mprotect() */
81294 +#define MF_PAX_RANDMMAP 0x08000000 /* Randomize mmap() base */
81295 +/*#define MF_PAX_RANDEXEC 0x10000000*/ /* Randomize ET_EXEC base */
81296 +#define MF_PAX_SEGMEXEC 0x20000000 /* Segmentation based non-executable pages */
81297 +
81298 +#ifdef CONFIG_PAX_SOFTMODE
81299 +extern int pax_softmode;
81300 +#endif
81301 +
81302 +extern int pax_check_flags(unsigned long *);
81303 +#define PAX_PARSE_FLAGS_FALLBACK (~0UL)
81304 +
81305 +/* if tsk != current then task_lock must be held on it */
81306 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
81307 +static inline unsigned long pax_get_flags(struct task_struct *tsk)
81308 +{
81309 + if (likely(tsk->mm))
81310 + return tsk->mm->pax_flags;
81311 + else
81312 + return 0UL;
81313 +}
81314 +
81315 +/* if tsk != current then task_lock must be held on it */
81316 +static inline long pax_set_flags(struct task_struct *tsk, unsigned long flags)
81317 +{
81318 + if (likely(tsk->mm)) {
81319 + tsk->mm->pax_flags = flags;
81320 + return 0;
81321 + }
81322 + return -EINVAL;
81323 +}
81324 +#endif
81325 +
81326 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
81327 +extern void pax_set_initial_flags(struct linux_binprm *bprm);
81328 +#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
81329 +extern void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
81330 +#endif
81331 +
81332 +struct path;
81333 +extern char *pax_get_path(const struct path *path, char *buf, int buflen);
81334 +extern void pax_report_fault(struct pt_regs *regs, void *pc, void *sp);
81335 +extern void pax_report_insns(struct pt_regs *regs, void *pc, void *sp);
81336 +extern void pax_report_refcount_overflow(struct pt_regs *regs);
81337
81338 /* Future-safe accessor for struct task_struct's cpus_allowed. */
81339 #define tsk_cpus_allowed(tsk) (&(tsk)->cpus_allowed)
81340 @@ -1531,7 +1642,7 @@ struct pid_namespace;
81341 pid_t __task_pid_nr_ns(struct task_struct *task, enum pid_type type,
81342 struct pid_namespace *ns);
81343
81344 -static inline pid_t task_pid_nr(struct task_struct *tsk)
81345 +static inline pid_t task_pid_nr(const struct task_struct *tsk)
81346 {
81347 return tsk->pid;
81348 }
81349 @@ -1981,7 +2092,9 @@ void yield(void);
81350 extern struct exec_domain default_exec_domain;
81351
81352 union thread_union {
81353 +#ifndef CONFIG_X86
81354 struct thread_info thread_info;
81355 +#endif
81356 unsigned long stack[THREAD_SIZE/sizeof(long)];
81357 };
81358
81359 @@ -2014,6 +2127,7 @@ extern struct pid_namespace init_pid_ns;
81360 */
81361
81362 extern struct task_struct *find_task_by_vpid(pid_t nr);
81363 +extern struct task_struct *find_task_by_vpid_unrestricted(pid_t nr);
81364 extern struct task_struct *find_task_by_pid_ns(pid_t nr,
81365 struct pid_namespace *ns);
81366
81367 @@ -2178,7 +2292,7 @@ extern void __cleanup_sighand(struct sighand_struct *);
81368 extern void exit_itimers(struct signal_struct *);
81369 extern void flush_itimer_signals(void);
81370
81371 -extern void do_group_exit(int);
81372 +extern __noreturn void do_group_exit(int);
81373
81374 extern int allow_signal(int);
81375 extern int disallow_signal(int);
81376 @@ -2369,9 +2483,9 @@ static inline unsigned long *end_of_stack(struct task_struct *p)
81377
81378 #endif
81379
81380 -static inline int object_is_on_stack(void *obj)
81381 +static inline int object_starts_on_stack(void *obj)
81382 {
81383 - void *stack = task_stack_page(current);
81384 + const void *stack = task_stack_page(current);
81385
81386 return (obj >= stack) && (obj < (stack + THREAD_SIZE));
81387 }
81388 diff --git a/include/linux/sched/sysctl.h b/include/linux/sched/sysctl.h
81389 index e3347c5..f682891 100644
81390 --- a/include/linux/sched/sysctl.h
81391 +++ b/include/linux/sched/sysctl.h
81392 @@ -30,6 +30,7 @@ enum { sysctl_hung_task_timeout_secs = 0 };
81393 #define DEFAULT_MAX_MAP_COUNT (USHRT_MAX - MAPCOUNT_ELF_CORE_MARGIN)
81394
81395 extern int sysctl_max_map_count;
81396 +extern unsigned long sysctl_heap_stack_gap;
81397
81398 extern unsigned int sysctl_sched_latency;
81399 extern unsigned int sysctl_sched_min_granularity;
81400 diff --git a/include/linux/security.h b/include/linux/security.h
81401 index 5623a7f..7ae77be 100644
81402 --- a/include/linux/security.h
81403 +++ b/include/linux/security.h
81404 @@ -27,6 +27,7 @@
81405 #include <linux/slab.h>
81406 #include <linux/err.h>
81407 #include <linux/string.h>
81408 +#include <linux/grsecurity.h>
81409
81410 struct linux_binprm;
81411 struct cred;
81412 @@ -116,8 +117,6 @@ struct seq_file;
81413
81414 extern int cap_netlink_send(struct sock *sk, struct sk_buff *skb);
81415
81416 -void reset_security_ops(void);
81417 -
81418 #ifdef CONFIG_MMU
81419 extern unsigned long mmap_min_addr;
81420 extern unsigned long dac_mmap_min_addr;
81421 @@ -1718,7 +1717,7 @@ struct security_operations {
81422 struct audit_context *actx);
81423 void (*audit_rule_free) (void *lsmrule);
81424 #endif /* CONFIG_AUDIT */
81425 -};
81426 +} __randomize_layout;
81427
81428 /* prototypes */
81429 extern int security_init(void);
81430 diff --git a/include/linux/semaphore.h b/include/linux/semaphore.h
81431 index dc368b8..e895209 100644
81432 --- a/include/linux/semaphore.h
81433 +++ b/include/linux/semaphore.h
81434 @@ -37,7 +37,7 @@ static inline void sema_init(struct semaphore *sem, int val)
81435 }
81436
81437 extern void down(struct semaphore *sem);
81438 -extern int __must_check down_interruptible(struct semaphore *sem);
81439 +extern int __must_check down_interruptible(struct semaphore *sem) __intentional_overflow(-1);
81440 extern int __must_check down_killable(struct semaphore *sem);
81441 extern int __must_check down_trylock(struct semaphore *sem);
81442 extern int __must_check down_timeout(struct semaphore *sem, long jiffies);
81443 diff --git a/include/linux/seq_file.h b/include/linux/seq_file.h
81444 index 52e0097..09625ef 100644
81445 --- a/include/linux/seq_file.h
81446 +++ b/include/linux/seq_file.h
81447 @@ -27,6 +27,9 @@ struct seq_file {
81448 struct mutex lock;
81449 const struct seq_operations *op;
81450 int poll_event;
81451 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
81452 + u64 exec_id;
81453 +#endif
81454 #ifdef CONFIG_USER_NS
81455 struct user_namespace *user_ns;
81456 #endif
81457 @@ -39,6 +42,7 @@ struct seq_operations {
81458 void * (*next) (struct seq_file *m, void *v, loff_t *pos);
81459 int (*show) (struct seq_file *m, void *v);
81460 };
81461 +typedef struct seq_operations __no_const seq_operations_no_const;
81462
81463 #define SEQ_SKIP 1
81464
81465 diff --git a/include/linux/shm.h b/include/linux/shm.h
81466 index 429c199..4d42e38 100644
81467 --- a/include/linux/shm.h
81468 +++ b/include/linux/shm.h
81469 @@ -21,6 +21,10 @@ struct shmid_kernel /* private to the kernel */
81470
81471 /* The task created the shm object. NULL if the task is dead. */
81472 struct task_struct *shm_creator;
81473 +#ifdef CONFIG_GRKERNSEC
81474 + time_t shm_createtime;
81475 + pid_t shm_lapid;
81476 +#endif
81477 };
81478
81479 /* shm_mode upper byte flags */
81480 diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
81481 index 37cb679..dbaebc0 100644
81482 --- a/include/linux/skbuff.h
81483 +++ b/include/linux/skbuff.h
81484 @@ -643,7 +643,7 @@ bool skb_try_coalesce(struct sk_buff *to, struct sk_buff *from,
81485 struct sk_buff *__alloc_skb(unsigned int size, gfp_t priority, int flags,
81486 int node);
81487 struct sk_buff *build_skb(void *data, unsigned int frag_size);
81488 -static inline struct sk_buff *alloc_skb(unsigned int size,
81489 +static inline struct sk_buff * __intentional_overflow(0) alloc_skb(unsigned int size,
81490 gfp_t priority)
81491 {
81492 return __alloc_skb(size, priority, 0, NUMA_NO_NODE);
81493 @@ -750,7 +750,7 @@ static inline struct skb_shared_hwtstamps *skb_hwtstamps(struct sk_buff *skb)
81494 */
81495 static inline int skb_queue_empty(const struct sk_buff_head *list)
81496 {
81497 - return list->next == (struct sk_buff *)list;
81498 + return list->next == (const struct sk_buff *)list;
81499 }
81500
81501 /**
81502 @@ -763,7 +763,7 @@ static inline int skb_queue_empty(const struct sk_buff_head *list)
81503 static inline bool skb_queue_is_last(const struct sk_buff_head *list,
81504 const struct sk_buff *skb)
81505 {
81506 - return skb->next == (struct sk_buff *)list;
81507 + return skb->next == (const struct sk_buff *)list;
81508 }
81509
81510 /**
81511 @@ -776,7 +776,7 @@ static inline bool skb_queue_is_last(const struct sk_buff_head *list,
81512 static inline bool skb_queue_is_first(const struct sk_buff_head *list,
81513 const struct sk_buff *skb)
81514 {
81515 - return skb->prev == (struct sk_buff *)list;
81516 + return skb->prev == (const struct sk_buff *)list;
81517 }
81518
81519 /**
81520 @@ -1686,7 +1686,7 @@ static inline u32 skb_inner_network_header_len(const struct sk_buff *skb)
81521 return skb->inner_transport_header - skb->inner_network_header;
81522 }
81523
81524 -static inline int skb_network_offset(const struct sk_buff *skb)
81525 +static inline int __intentional_overflow(0) skb_network_offset(const struct sk_buff *skb)
81526 {
81527 return skb_network_header(skb) - skb->data;
81528 }
81529 @@ -1746,7 +1746,7 @@ static inline int pskb_network_may_pull(struct sk_buff *skb, unsigned int len)
81530 * NET_IP_ALIGN(2) + ethernet_header(14) + IP_header(20/40) + ports(8)
81531 */
81532 #ifndef NET_SKB_PAD
81533 -#define NET_SKB_PAD max(32, L1_CACHE_BYTES)
81534 +#define NET_SKB_PAD max(_AC(32,UL), L1_CACHE_BYTES)
81535 #endif
81536
81537 int ___pskb_trim(struct sk_buff *skb, unsigned int len);
81538 @@ -2345,7 +2345,7 @@ struct sk_buff *skb_recv_datagram(struct sock *sk, unsigned flags, int noblock,
81539 int *err);
81540 unsigned int datagram_poll(struct file *file, struct socket *sock,
81541 struct poll_table_struct *wait);
81542 -int skb_copy_datagram_iovec(const struct sk_buff *from, int offset,
81543 +int __intentional_overflow(0) skb_copy_datagram_iovec(const struct sk_buff *from, int offset,
81544 struct iovec *to, int size);
81545 int skb_copy_and_csum_datagram_iovec(struct sk_buff *skb, int hlen,
81546 struct iovec *iov);
81547 @@ -2618,6 +2618,9 @@ static inline void nf_reset(struct sk_buff *skb)
81548 nf_bridge_put(skb->nf_bridge);
81549 skb->nf_bridge = NULL;
81550 #endif
81551 +#if IS_ENABLED(CONFIG_NETFILTER_XT_TARGET_TRACE)
81552 + skb->nf_trace = 0;
81553 +#endif
81554 }
81555
81556 static inline void nf_reset_trace(struct sk_buff *skb)
81557 diff --git a/include/linux/slab.h b/include/linux/slab.h
81558 index 1e2f4fe..df49ca6 100644
81559 --- a/include/linux/slab.h
81560 +++ b/include/linux/slab.h
81561 @@ -14,15 +14,29 @@
81562 #include <linux/gfp.h>
81563 #include <linux/types.h>
81564 #include <linux/workqueue.h>
81565 -
81566 +#include <linux/err.h>
81567
81568 /*
81569 * Flags to pass to kmem_cache_create().
81570 * The ones marked DEBUG are only valid if CONFIG_SLAB_DEBUG is set.
81571 */
81572 #define SLAB_DEBUG_FREE 0x00000100UL /* DEBUG: Perform (expensive) checks on free */
81573 +
81574 +#ifdef CONFIG_PAX_USERCOPY_SLABS
81575 +#define SLAB_USERCOPY 0x00000200UL /* PaX: Allow copying objs to/from userland */
81576 +#else
81577 +#define SLAB_USERCOPY 0x00000000UL
81578 +#endif
81579 +
81580 #define SLAB_RED_ZONE 0x00000400UL /* DEBUG: Red zone objs in a cache */
81581 #define SLAB_POISON 0x00000800UL /* DEBUG: Poison objects */
81582 +
81583 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
81584 +#define SLAB_NO_SANITIZE 0x00001000UL /* PaX: Do not sanitize objs on free */
81585 +#else
81586 +#define SLAB_NO_SANITIZE 0x00000000UL
81587 +#endif
81588 +
81589 #define SLAB_HWCACHE_ALIGN 0x00002000UL /* Align objs on cache lines */
81590 #define SLAB_CACHE_DMA 0x00004000UL /* Use GFP_DMA memory */
81591 #define SLAB_STORE_USER 0x00010000UL /* DEBUG: Store the last owner for bug hunting */
81592 @@ -98,10 +112,13 @@
81593 * ZERO_SIZE_PTR can be passed to kfree though in the same way that NULL can.
81594 * Both make kfree a no-op.
81595 */
81596 -#define ZERO_SIZE_PTR ((void *)16)
81597 +#define ZERO_SIZE_PTR \
81598 +({ \
81599 + BUILD_BUG_ON(!(MAX_ERRNO & ~PAGE_MASK));\
81600 + (void *)(-MAX_ERRNO-1L); \
81601 +})
81602
81603 -#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) <= \
81604 - (unsigned long)ZERO_SIZE_PTR)
81605 +#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) - 1 >= (unsigned long)ZERO_SIZE_PTR - 1)
81606
81607 #include <linux/kmemleak.h>
81608
81609 @@ -142,6 +159,8 @@ void * __must_check krealloc(const void *, size_t, gfp_t);
81610 void kfree(const void *);
81611 void kzfree(const void *);
81612 size_t ksize(const void *);
81613 +const char *check_heap_object(const void *ptr, unsigned long n);
81614 +bool is_usercopy_object(const void *ptr);
81615
81616 /*
81617 * Some archs want to perform DMA into kmalloc caches and need a guaranteed
81618 @@ -174,7 +193,7 @@ struct kmem_cache {
81619 unsigned int align; /* Alignment as calculated */
81620 unsigned long flags; /* Active flags on the slab */
81621 const char *name; /* Slab name for sysfs */
81622 - int refcount; /* Use counter */
81623 + atomic_t refcount; /* Use counter */
81624 void (*ctor)(void *); /* Called on object slot creation */
81625 struct list_head list; /* List of all slab caches on the system */
81626 };
81627 @@ -248,6 +267,10 @@ extern struct kmem_cache *kmalloc_caches[KMALLOC_SHIFT_HIGH + 1];
81628 extern struct kmem_cache *kmalloc_dma_caches[KMALLOC_SHIFT_HIGH + 1];
81629 #endif
81630
81631 +#ifdef CONFIG_PAX_USERCOPY_SLABS
81632 +extern struct kmem_cache *kmalloc_usercopy_caches[KMALLOC_SHIFT_HIGH + 1];
81633 +#endif
81634 +
81635 /*
81636 * Figure out which kmalloc slab an allocation of a certain size
81637 * belongs to.
81638 @@ -256,7 +279,7 @@ extern struct kmem_cache *kmalloc_dma_caches[KMALLOC_SHIFT_HIGH + 1];
81639 * 2 = 120 .. 192 bytes
81640 * n = 2^(n-1) .. 2^n -1
81641 */
81642 -static __always_inline int kmalloc_index(size_t size)
81643 +static __always_inline __size_overflow(1) int kmalloc_index(size_t size)
81644 {
81645 if (!size)
81646 return 0;
81647 @@ -299,11 +322,11 @@ static __always_inline int kmalloc_index(size_t size)
81648 }
81649 #endif /* !CONFIG_SLOB */
81650
81651 -void *__kmalloc(size_t size, gfp_t flags);
81652 +void *__kmalloc(size_t size, gfp_t flags) __alloc_size(1);
81653 void *kmem_cache_alloc(struct kmem_cache *, gfp_t flags);
81654
81655 #ifdef CONFIG_NUMA
81656 -void *__kmalloc_node(size_t size, gfp_t flags, int node);
81657 +void *__kmalloc_node(size_t size, gfp_t flags, int node) __alloc_size(1);
81658 void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node);
81659 #else
81660 static __always_inline void *__kmalloc_node(size_t size, gfp_t flags, int node)
81661 diff --git a/include/linux/slab_def.h b/include/linux/slab_def.h
81662 index 09bfffb..4fc80fb 100644
81663 --- a/include/linux/slab_def.h
81664 +++ b/include/linux/slab_def.h
81665 @@ -36,7 +36,7 @@ struct kmem_cache {
81666 /* 4) cache creation/removal */
81667 const char *name;
81668 struct list_head list;
81669 - int refcount;
81670 + atomic_t refcount;
81671 int object_size;
81672 int align;
81673
81674 @@ -52,10 +52,14 @@ struct kmem_cache {
81675 unsigned long node_allocs;
81676 unsigned long node_frees;
81677 unsigned long node_overflow;
81678 - atomic_t allochit;
81679 - atomic_t allocmiss;
81680 - atomic_t freehit;
81681 - atomic_t freemiss;
81682 + atomic_unchecked_t allochit;
81683 + atomic_unchecked_t allocmiss;
81684 + atomic_unchecked_t freehit;
81685 + atomic_unchecked_t freemiss;
81686 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
81687 + atomic_unchecked_t sanitized;
81688 + atomic_unchecked_t not_sanitized;
81689 +#endif
81690
81691 /*
81692 * If debugging is enabled, then the allocator can add additional
81693 diff --git a/include/linux/slub_def.h b/include/linux/slub_def.h
81694 index f56bfa9..8378a26 100644
81695 --- a/include/linux/slub_def.h
81696 +++ b/include/linux/slub_def.h
81697 @@ -74,7 +74,7 @@ struct kmem_cache {
81698 struct kmem_cache_order_objects max;
81699 struct kmem_cache_order_objects min;
81700 gfp_t allocflags; /* gfp flags to use on each alloc */
81701 - int refcount; /* Refcount for slab cache destroy */
81702 + atomic_t refcount; /* Refcount for slab cache destroy */
81703 void (*ctor)(void *);
81704 int inuse; /* Offset to metadata */
81705 int align; /* Alignment */
81706 diff --git a/include/linux/smp.h b/include/linux/smp.h
81707 index 5da22ee..71d8a28 100644
81708 --- a/include/linux/smp.h
81709 +++ b/include/linux/smp.h
81710 @@ -176,7 +176,9 @@ static inline void kick_all_cpus_sync(void) { }
81711 #endif
81712
81713 #define get_cpu() ({ preempt_disable(); smp_processor_id(); })
81714 +#define raw_get_cpu() ({ raw_preempt_disable(); raw_smp_processor_id(); })
81715 #define put_cpu() preempt_enable()
81716 +#define raw_put_cpu_no_resched() raw_preempt_enable_no_resched()
81717
81718 /*
81719 * Callback to arch code if there's nosmp or maxcpus=0 on the
81720 diff --git a/include/linux/sock_diag.h b/include/linux/sock_diag.h
81721 index 54f91d3..be2c379 100644
81722 --- a/include/linux/sock_diag.h
81723 +++ b/include/linux/sock_diag.h
81724 @@ -11,7 +11,7 @@ struct sock;
81725 struct sock_diag_handler {
81726 __u8 family;
81727 int (*dump)(struct sk_buff *skb, struct nlmsghdr *nlh);
81728 -};
81729 +} __do_const;
81730
81731 int sock_diag_register(const struct sock_diag_handler *h);
81732 void sock_diag_unregister(const struct sock_diag_handler *h);
81733 diff --git a/include/linux/sonet.h b/include/linux/sonet.h
81734 index 680f9a3..f13aeb0 100644
81735 --- a/include/linux/sonet.h
81736 +++ b/include/linux/sonet.h
81737 @@ -7,7 +7,7 @@
81738 #include <uapi/linux/sonet.h>
81739
81740 struct k_sonet_stats {
81741 -#define __HANDLE_ITEM(i) atomic_t i
81742 +#define __HANDLE_ITEM(i) atomic_unchecked_t i
81743 __SONET_ITEMS
81744 #undef __HANDLE_ITEM
81745 };
81746 diff --git a/include/linux/sunrpc/addr.h b/include/linux/sunrpc/addr.h
81747 index 07d8e53..dc934c9 100644
81748 --- a/include/linux/sunrpc/addr.h
81749 +++ b/include/linux/sunrpc/addr.h
81750 @@ -23,9 +23,9 @@ static inline unsigned short rpc_get_port(const struct sockaddr *sap)
81751 {
81752 switch (sap->sa_family) {
81753 case AF_INET:
81754 - return ntohs(((struct sockaddr_in *)sap)->sin_port);
81755 + return ntohs(((const struct sockaddr_in *)sap)->sin_port);
81756 case AF_INET6:
81757 - return ntohs(((struct sockaddr_in6 *)sap)->sin6_port);
81758 + return ntohs(((const struct sockaddr_in6 *)sap)->sin6_port);
81759 }
81760 return 0;
81761 }
81762 @@ -58,7 +58,7 @@ static inline bool __rpc_cmp_addr4(const struct sockaddr *sap1,
81763 static inline bool __rpc_copy_addr4(struct sockaddr *dst,
81764 const struct sockaddr *src)
81765 {
81766 - const struct sockaddr_in *ssin = (struct sockaddr_in *) src;
81767 + const struct sockaddr_in *ssin = (const struct sockaddr_in *) src;
81768 struct sockaddr_in *dsin = (struct sockaddr_in *) dst;
81769
81770 dsin->sin_family = ssin->sin_family;
81771 @@ -164,7 +164,7 @@ static inline u32 rpc_get_scope_id(const struct sockaddr *sa)
81772 if (sa->sa_family != AF_INET6)
81773 return 0;
81774
81775 - return ((struct sockaddr_in6 *) sa)->sin6_scope_id;
81776 + return ((const struct sockaddr_in6 *) sa)->sin6_scope_id;
81777 }
81778
81779 #endif /* _LINUX_SUNRPC_ADDR_H */
81780 diff --git a/include/linux/sunrpc/clnt.h b/include/linux/sunrpc/clnt.h
81781 index 8af2804..c7414ef 100644
81782 --- a/include/linux/sunrpc/clnt.h
81783 +++ b/include/linux/sunrpc/clnt.h
81784 @@ -97,7 +97,7 @@ struct rpc_procinfo {
81785 unsigned int p_timer; /* Which RTT timer to use */
81786 u32 p_statidx; /* Which procedure to account */
81787 const char * p_name; /* name of procedure */
81788 -};
81789 +} __do_const;
81790
81791 #ifdef __KERNEL__
81792
81793 diff --git a/include/linux/sunrpc/svc.h b/include/linux/sunrpc/svc.h
81794 index 6eecfc2..7ada79d 100644
81795 --- a/include/linux/sunrpc/svc.h
81796 +++ b/include/linux/sunrpc/svc.h
81797 @@ -410,7 +410,7 @@ struct svc_procedure {
81798 unsigned int pc_count; /* call count */
81799 unsigned int pc_cachetype; /* cache info (NFS) */
81800 unsigned int pc_xdrressize; /* maximum size of XDR reply */
81801 -};
81802 +} __do_const;
81803
81804 /*
81805 * Function prototypes.
81806 diff --git a/include/linux/sunrpc/svc_rdma.h b/include/linux/sunrpc/svc_rdma.h
81807 index 0b8e3e6..33e0a01 100644
81808 --- a/include/linux/sunrpc/svc_rdma.h
81809 +++ b/include/linux/sunrpc/svc_rdma.h
81810 @@ -53,15 +53,15 @@ extern unsigned int svcrdma_ord;
81811 extern unsigned int svcrdma_max_requests;
81812 extern unsigned int svcrdma_max_req_size;
81813
81814 -extern atomic_t rdma_stat_recv;
81815 -extern atomic_t rdma_stat_read;
81816 -extern atomic_t rdma_stat_write;
81817 -extern atomic_t rdma_stat_sq_starve;
81818 -extern atomic_t rdma_stat_rq_starve;
81819 -extern atomic_t rdma_stat_rq_poll;
81820 -extern atomic_t rdma_stat_rq_prod;
81821 -extern atomic_t rdma_stat_sq_poll;
81822 -extern atomic_t rdma_stat_sq_prod;
81823 +extern atomic_unchecked_t rdma_stat_recv;
81824 +extern atomic_unchecked_t rdma_stat_read;
81825 +extern atomic_unchecked_t rdma_stat_write;
81826 +extern atomic_unchecked_t rdma_stat_sq_starve;
81827 +extern atomic_unchecked_t rdma_stat_rq_starve;
81828 +extern atomic_unchecked_t rdma_stat_rq_poll;
81829 +extern atomic_unchecked_t rdma_stat_rq_prod;
81830 +extern atomic_unchecked_t rdma_stat_sq_poll;
81831 +extern atomic_unchecked_t rdma_stat_sq_prod;
81832
81833 #define RPCRDMA_VERSION 1
81834
81835 diff --git a/include/linux/sunrpc/svcauth.h b/include/linux/sunrpc/svcauth.h
81836 index 8d71d65..f79586e 100644
81837 --- a/include/linux/sunrpc/svcauth.h
81838 +++ b/include/linux/sunrpc/svcauth.h
81839 @@ -120,7 +120,7 @@ struct auth_ops {
81840 int (*release)(struct svc_rqst *rq);
81841 void (*domain_release)(struct auth_domain *);
81842 int (*set_client)(struct svc_rqst *rq);
81843 -};
81844 +} __do_const;
81845
81846 #define SVC_GARBAGE 1
81847 #define SVC_SYSERR 2
81848 diff --git a/include/linux/swiotlb.h b/include/linux/swiotlb.h
81849 index a5ffd32..0935dea 100644
81850 --- a/include/linux/swiotlb.h
81851 +++ b/include/linux/swiotlb.h
81852 @@ -60,7 +60,8 @@ extern void
81853
81854 extern void
81855 swiotlb_free_coherent(struct device *hwdev, size_t size,
81856 - void *vaddr, dma_addr_t dma_handle);
81857 + void *vaddr, dma_addr_t dma_handle,
81858 + struct dma_attrs *attrs);
81859
81860 extern dma_addr_t swiotlb_map_page(struct device *dev, struct page *page,
81861 unsigned long offset, size_t size,
81862 diff --git a/include/linux/syscalls.h b/include/linux/syscalls.h
81863 index 94273bb..c2e05fc 100644
81864 --- a/include/linux/syscalls.h
81865 +++ b/include/linux/syscalls.h
81866 @@ -97,8 +97,14 @@ struct sigaltstack;
81867 #define __MAP(n,...) __MAP##n(__VA_ARGS__)
81868
81869 #define __SC_DECL(t, a) t a
81870 +#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))
81871 #define __TYPE_IS_LL(t) (__same_type((t)0, 0LL) || __same_type((t)0, 0ULL))
81872 -#define __SC_LONG(t, a) __typeof(__builtin_choose_expr(__TYPE_IS_LL(t), 0LL, 0L)) a
81873 +#define __SC_LONG(t, a) __typeof( \
81874 + __builtin_choose_expr( \
81875 + sizeof(t) > sizeof(int), \
81876 + (t) 0, \
81877 + __builtin_choose_expr(__TYPE_IS_U(t), 0UL, 0L) \
81878 + )) a
81879 #define __SC_CAST(t, a) (t) a
81880 #define __SC_ARGS(t, a) a
81881 #define __SC_TEST(t, a) (void)BUILD_BUG_ON_ZERO(!__TYPE_IS_LL(t) && sizeof(t) > sizeof(long))
81882 @@ -363,11 +369,11 @@ asmlinkage long sys_sync(void);
81883 asmlinkage long sys_fsync(unsigned int fd);
81884 asmlinkage long sys_fdatasync(unsigned int fd);
81885 asmlinkage long sys_bdflush(int func, long data);
81886 -asmlinkage long sys_mount(char __user *dev_name, char __user *dir_name,
81887 - char __user *type, unsigned long flags,
81888 +asmlinkage long sys_mount(const char __user *dev_name, const char __user *dir_name,
81889 + const char __user *type, unsigned long flags,
81890 void __user *data);
81891 -asmlinkage long sys_umount(char __user *name, int flags);
81892 -asmlinkage long sys_oldumount(char __user *name);
81893 +asmlinkage long sys_umount(const char __user *name, int flags);
81894 +asmlinkage long sys_oldumount(const char __user *name);
81895 asmlinkage long sys_truncate(const char __user *path, long length);
81896 asmlinkage long sys_ftruncate(unsigned int fd, unsigned long length);
81897 asmlinkage long sys_stat(const char __user *filename,
81898 @@ -579,7 +585,7 @@ asmlinkage long sys_getsockname(int, struct sockaddr __user *, int __user *);
81899 asmlinkage long sys_getpeername(int, struct sockaddr __user *, int __user *);
81900 asmlinkage long sys_send(int, void __user *, size_t, unsigned);
81901 asmlinkage long sys_sendto(int, void __user *, size_t, unsigned,
81902 - struct sockaddr __user *, int);
81903 + struct sockaddr __user *, int) __intentional_overflow(0);
81904 asmlinkage long sys_sendmsg(int fd, struct msghdr __user *msg, unsigned flags);
81905 asmlinkage long sys_sendmmsg(int fd, struct mmsghdr __user *msg,
81906 unsigned int vlen, unsigned flags);
81907 diff --git a/include/linux/syscore_ops.h b/include/linux/syscore_ops.h
81908 index 27b3b0b..e093dd9 100644
81909 --- a/include/linux/syscore_ops.h
81910 +++ b/include/linux/syscore_ops.h
81911 @@ -16,7 +16,7 @@ struct syscore_ops {
81912 int (*suspend)(void);
81913 void (*resume)(void);
81914 void (*shutdown)(void);
81915 -};
81916 +} __do_const;
81917
81918 extern void register_syscore_ops(struct syscore_ops *ops);
81919 extern void unregister_syscore_ops(struct syscore_ops *ops);
81920 diff --git a/include/linux/sysctl.h b/include/linux/sysctl.h
81921 index 14a8ff2..fa95f3a 100644
81922 --- a/include/linux/sysctl.h
81923 +++ b/include/linux/sysctl.h
81924 @@ -34,13 +34,13 @@ struct ctl_table_root;
81925 struct ctl_table_header;
81926 struct ctl_dir;
81927
81928 -typedef struct ctl_table ctl_table;
81929 -
81930 typedef int proc_handler (struct ctl_table *ctl, int write,
81931 void __user *buffer, size_t *lenp, loff_t *ppos);
81932
81933 extern int proc_dostring(struct ctl_table *, int,
81934 void __user *, size_t *, loff_t *);
81935 +extern int proc_dostring_modpriv(struct ctl_table *, int,
81936 + void __user *, size_t *, loff_t *);
81937 extern int proc_dointvec(struct ctl_table *, int,
81938 void __user *, size_t *, loff_t *);
81939 extern int proc_dointvec_minmax(struct ctl_table *, int,
81940 @@ -115,7 +115,9 @@ struct ctl_table
81941 struct ctl_table_poll *poll;
81942 void *extra1;
81943 void *extra2;
81944 -};
81945 +} __do_const __randomize_layout;
81946 +typedef struct ctl_table __no_const ctl_table_no_const;
81947 +typedef struct ctl_table ctl_table;
81948
81949 struct ctl_node {
81950 struct rb_node node;
81951 diff --git a/include/linux/sysfs.h b/include/linux/sysfs.h
81952 index 6695040..3d4192d 100644
81953 --- a/include/linux/sysfs.h
81954 +++ b/include/linux/sysfs.h
81955 @@ -33,7 +33,8 @@ struct attribute {
81956 struct lock_class_key *key;
81957 struct lock_class_key skey;
81958 #endif
81959 -};
81960 +} __do_const;
81961 +typedef struct attribute __no_const attribute_no_const;
81962
81963 /**
81964 * sysfs_attr_init - initialize a dynamically allocated sysfs attribute
81965 @@ -62,7 +63,8 @@ struct attribute_group {
81966 struct attribute *, int);
81967 struct attribute **attrs;
81968 struct bin_attribute **bin_attrs;
81969 -};
81970 +} __do_const;
81971 +typedef struct attribute_group __no_const attribute_group_no_const;
81972
81973 /**
81974 * Use these macros to make defining attributes easier. See include/linux/device.h
81975 @@ -126,7 +128,8 @@ struct bin_attribute {
81976 char *, loff_t, size_t);
81977 int (*mmap)(struct file *, struct kobject *, struct bin_attribute *attr,
81978 struct vm_area_struct *vma);
81979 -};
81980 +} __do_const;
81981 +typedef struct bin_attribute __no_const bin_attribute_no_const;
81982
81983 /**
81984 * sysfs_bin_attr_init - initialize a dynamically allocated bin_attribute
81985 diff --git a/include/linux/sysrq.h b/include/linux/sysrq.h
81986 index 387fa7d..3fcde6b 100644
81987 --- a/include/linux/sysrq.h
81988 +++ b/include/linux/sysrq.h
81989 @@ -16,6 +16,7 @@
81990
81991 #include <linux/errno.h>
81992 #include <linux/types.h>
81993 +#include <linux/compiler.h>
81994
81995 /* Possible values of bitmask for enabling sysrq functions */
81996 /* 0x0001 is reserved for enable everything */
81997 @@ -33,7 +34,7 @@ struct sysrq_key_op {
81998 char *help_msg;
81999 char *action_msg;
82000 int enable_mask;
82001 -};
82002 +} __do_const;
82003
82004 #ifdef CONFIG_MAGIC_SYSRQ
82005
82006 diff --git a/include/linux/thread_info.h b/include/linux/thread_info.h
82007 index fddbe20..0312de8 100644
82008 --- a/include/linux/thread_info.h
82009 +++ b/include/linux/thread_info.h
82010 @@ -161,6 +161,15 @@ static inline bool test_and_clear_restore_sigmask(void)
82011 #error "no set_restore_sigmask() provided and default one won't work"
82012 #endif
82013
82014 +extern void __check_object_size(const void *ptr, unsigned long n, bool to_user);
82015 +static inline void check_object_size(const void *ptr, unsigned long n, bool to_user)
82016 +{
82017 +#ifndef CONFIG_PAX_USERCOPY_DEBUG
82018 + if (!__builtin_constant_p(n))
82019 +#endif
82020 + __check_object_size(ptr, n, to_user);
82021 +}
82022 +
82023 #endif /* __KERNEL__ */
82024
82025 #endif /* _LINUX_THREAD_INFO_H */
82026 diff --git a/include/linux/tty.h b/include/linux/tty.h
82027 index 97d660e..6356755 100644
82028 --- a/include/linux/tty.h
82029 +++ b/include/linux/tty.h
82030 @@ -196,7 +196,7 @@ struct tty_port {
82031 const struct tty_port_operations *ops; /* Port operations */
82032 spinlock_t lock; /* Lock protecting tty field */
82033 int blocked_open; /* Waiting to open */
82034 - int count; /* Usage count */
82035 + atomic_t count; /* Usage count */
82036 wait_queue_head_t open_wait; /* Open waiters */
82037 wait_queue_head_t close_wait; /* Close waiters */
82038 wait_queue_head_t delta_msr_wait; /* Modem status change */
82039 @@ -278,7 +278,7 @@ struct tty_struct {
82040 /* If the tty has a pending do_SAK, queue it here - akpm */
82041 struct work_struct SAK_work;
82042 struct tty_port *port;
82043 -};
82044 +} __randomize_layout;
82045
82046 /* Each of a tty's open files has private_data pointing to tty_file_private */
82047 struct tty_file_private {
82048 @@ -545,7 +545,7 @@ extern int tty_port_open(struct tty_port *port,
82049 struct tty_struct *tty, struct file *filp);
82050 static inline int tty_port_users(struct tty_port *port)
82051 {
82052 - return port->count + port->blocked_open;
82053 + return atomic_read(&port->count) + port->blocked_open;
82054 }
82055
82056 extern int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc);
82057 diff --git a/include/linux/tty_driver.h b/include/linux/tty_driver.h
82058 index 756a609..89db85e 100644
82059 --- a/include/linux/tty_driver.h
82060 +++ b/include/linux/tty_driver.h
82061 @@ -285,7 +285,7 @@ struct tty_operations {
82062 void (*poll_put_char)(struct tty_driver *driver, int line, char ch);
82063 #endif
82064 const struct file_operations *proc_fops;
82065 -};
82066 +} __do_const __randomize_layout;
82067
82068 struct tty_driver {
82069 int magic; /* magic number for this structure */
82070 @@ -319,7 +319,7 @@ struct tty_driver {
82071
82072 const struct tty_operations *ops;
82073 struct list_head tty_drivers;
82074 -};
82075 +} __randomize_layout;
82076
82077 extern struct list_head tty_drivers;
82078
82079 diff --git a/include/linux/tty_ldisc.h b/include/linux/tty_ldisc.h
82080 index f15c898..207b7d1 100644
82081 --- a/include/linux/tty_ldisc.h
82082 +++ b/include/linux/tty_ldisc.h
82083 @@ -211,7 +211,7 @@ struct tty_ldisc_ops {
82084
82085 struct module *owner;
82086
82087 - int refcount;
82088 + atomic_t refcount;
82089 };
82090
82091 struct tty_ldisc {
82092 diff --git a/include/linux/types.h b/include/linux/types.h
82093 index 4d118ba..c3ee9bf 100644
82094 --- a/include/linux/types.h
82095 +++ b/include/linux/types.h
82096 @@ -176,10 +176,26 @@ typedef struct {
82097 int counter;
82098 } atomic_t;
82099
82100 +#ifdef CONFIG_PAX_REFCOUNT
82101 +typedef struct {
82102 + int counter;
82103 +} atomic_unchecked_t;
82104 +#else
82105 +typedef atomic_t atomic_unchecked_t;
82106 +#endif
82107 +
82108 #ifdef CONFIG_64BIT
82109 typedef struct {
82110 long counter;
82111 } atomic64_t;
82112 +
82113 +#ifdef CONFIG_PAX_REFCOUNT
82114 +typedef struct {
82115 + long counter;
82116 +} atomic64_unchecked_t;
82117 +#else
82118 +typedef atomic64_t atomic64_unchecked_t;
82119 +#endif
82120 #endif
82121
82122 struct list_head {
82123 diff --git a/include/linux/uaccess.h b/include/linux/uaccess.h
82124 index 9d8cf05..0ed74dd 100644
82125 --- a/include/linux/uaccess.h
82126 +++ b/include/linux/uaccess.h
82127 @@ -72,11 +72,11 @@ static inline unsigned long __copy_from_user_nocache(void *to,
82128 long ret; \
82129 mm_segment_t old_fs = get_fs(); \
82130 \
82131 - set_fs(KERNEL_DS); \
82132 pagefault_disable(); \
82133 - ret = __copy_from_user_inatomic(&(retval), (__force typeof(retval) __user *)(addr), sizeof(retval)); \
82134 - pagefault_enable(); \
82135 + set_fs(KERNEL_DS); \
82136 + ret = __copy_from_user_inatomic(&(retval), (typeof(retval) __force_user *)(addr), sizeof(retval)); \
82137 set_fs(old_fs); \
82138 + pagefault_enable(); \
82139 ret; \
82140 })
82141
82142 diff --git a/include/linux/uidgid.h b/include/linux/uidgid.h
82143 index 8e522cbc..aa8572d 100644
82144 --- a/include/linux/uidgid.h
82145 +++ b/include/linux/uidgid.h
82146 @@ -197,4 +197,9 @@ static inline bool kgid_has_mapping(struct user_namespace *ns, kgid_t gid)
82147
82148 #endif /* CONFIG_USER_NS */
82149
82150 +#define GR_GLOBAL_UID(x) from_kuid_munged(&init_user_ns, (x))
82151 +#define GR_GLOBAL_GID(x) from_kgid_munged(&init_user_ns, (x))
82152 +#define gr_is_global_root(x) uid_eq((x), GLOBAL_ROOT_UID)
82153 +#define gr_is_global_nonroot(x) (!uid_eq((x), GLOBAL_ROOT_UID))
82154 +
82155 #endif /* _LINUX_UIDGID_H */
82156 diff --git a/include/linux/unaligned/access_ok.h b/include/linux/unaligned/access_ok.h
82157 index 99c1b4d..562e6f3 100644
82158 --- a/include/linux/unaligned/access_ok.h
82159 +++ b/include/linux/unaligned/access_ok.h
82160 @@ -4,34 +4,34 @@
82161 #include <linux/kernel.h>
82162 #include <asm/byteorder.h>
82163
82164 -static inline u16 get_unaligned_le16(const void *p)
82165 +static inline u16 __intentional_overflow(-1) get_unaligned_le16(const void *p)
82166 {
82167 - return le16_to_cpup((__le16 *)p);
82168 + return le16_to_cpup((const __le16 *)p);
82169 }
82170
82171 -static inline u32 get_unaligned_le32(const void *p)
82172 +static inline u32 __intentional_overflow(-1) get_unaligned_le32(const void *p)
82173 {
82174 - return le32_to_cpup((__le32 *)p);
82175 + return le32_to_cpup((const __le32 *)p);
82176 }
82177
82178 -static inline u64 get_unaligned_le64(const void *p)
82179 +static inline u64 __intentional_overflow(-1) get_unaligned_le64(const void *p)
82180 {
82181 - return le64_to_cpup((__le64 *)p);
82182 + return le64_to_cpup((const __le64 *)p);
82183 }
82184
82185 -static inline u16 get_unaligned_be16(const void *p)
82186 +static inline u16 __intentional_overflow(-1) get_unaligned_be16(const void *p)
82187 {
82188 - return be16_to_cpup((__be16 *)p);
82189 + return be16_to_cpup((const __be16 *)p);
82190 }
82191
82192 -static inline u32 get_unaligned_be32(const void *p)
82193 +static inline u32 __intentional_overflow(-1) get_unaligned_be32(const void *p)
82194 {
82195 - return be32_to_cpup((__be32 *)p);
82196 + return be32_to_cpup((const __be32 *)p);
82197 }
82198
82199 -static inline u64 get_unaligned_be64(const void *p)
82200 +static inline u64 __intentional_overflow(-1) get_unaligned_be64(const void *p)
82201 {
82202 - return be64_to_cpup((__be64 *)p);
82203 + return be64_to_cpup((const __be64 *)p);
82204 }
82205
82206 static inline void put_unaligned_le16(u16 val, void *p)
82207 diff --git a/include/linux/usb.h b/include/linux/usb.h
82208 index 7454865..29f4bfa 100644
82209 --- a/include/linux/usb.h
82210 +++ b/include/linux/usb.h
82211 @@ -563,7 +563,7 @@ struct usb_device {
82212 int maxchild;
82213
82214 u32 quirks;
82215 - atomic_t urbnum;
82216 + atomic_unchecked_t urbnum;
82217
82218 unsigned long active_duration;
82219
82220 @@ -1641,7 +1641,7 @@ void usb_buffer_unmap_sg(const struct usb_device *dev, int is_in,
82221
82222 extern int usb_control_msg(struct usb_device *dev, unsigned int pipe,
82223 __u8 request, __u8 requesttype, __u16 value, __u16 index,
82224 - void *data, __u16 size, int timeout);
82225 + void *data, __u16 size, int timeout) __intentional_overflow(-1);
82226 extern int usb_interrupt_msg(struct usb_device *usb_dev, unsigned int pipe,
82227 void *data, int len, int *actual_length, int timeout);
82228 extern int usb_bulk_msg(struct usb_device *usb_dev, unsigned int pipe,
82229 diff --git a/include/linux/usb/renesas_usbhs.h b/include/linux/usb/renesas_usbhs.h
82230 index e452ba6..78f8e80 100644
82231 --- a/include/linux/usb/renesas_usbhs.h
82232 +++ b/include/linux/usb/renesas_usbhs.h
82233 @@ -39,7 +39,7 @@ enum {
82234 */
82235 struct renesas_usbhs_driver_callback {
82236 int (*notify_hotplug)(struct platform_device *pdev);
82237 -};
82238 +} __no_const;
82239
82240 /*
82241 * callback functions for platform
82242 diff --git a/include/linux/user_namespace.h b/include/linux/user_namespace.h
82243 index 4836ba3..603f6ee 100644
82244 --- a/include/linux/user_namespace.h
82245 +++ b/include/linux/user_namespace.h
82246 @@ -33,7 +33,7 @@ struct user_namespace {
82247 struct key *persistent_keyring_register;
82248 struct rw_semaphore persistent_keyring_register_sem;
82249 #endif
82250 -};
82251 +} __randomize_layout;
82252
82253 extern struct user_namespace init_user_ns;
82254
82255 diff --git a/include/linux/utsname.h b/include/linux/utsname.h
82256 index 239e277..22a5cf5 100644
82257 --- a/include/linux/utsname.h
82258 +++ b/include/linux/utsname.h
82259 @@ -24,7 +24,7 @@ struct uts_namespace {
82260 struct new_utsname name;
82261 struct user_namespace *user_ns;
82262 unsigned int proc_inum;
82263 -};
82264 +} __randomize_layout;
82265 extern struct uts_namespace init_uts_ns;
82266
82267 #ifdef CONFIG_UTS_NS
82268 diff --git a/include/linux/vermagic.h b/include/linux/vermagic.h
82269 index 6f8fbcf..4efc177 100644
82270 --- a/include/linux/vermagic.h
82271 +++ b/include/linux/vermagic.h
82272 @@ -25,9 +25,42 @@
82273 #define MODULE_ARCH_VERMAGIC ""
82274 #endif
82275
82276 +#ifdef CONFIG_PAX_REFCOUNT
82277 +#define MODULE_PAX_REFCOUNT "REFCOUNT "
82278 +#else
82279 +#define MODULE_PAX_REFCOUNT ""
82280 +#endif
82281 +
82282 +#ifdef CONSTIFY_PLUGIN
82283 +#define MODULE_CONSTIFY_PLUGIN "CONSTIFY_PLUGIN "
82284 +#else
82285 +#define MODULE_CONSTIFY_PLUGIN ""
82286 +#endif
82287 +
82288 +#ifdef STACKLEAK_PLUGIN
82289 +#define MODULE_STACKLEAK_PLUGIN "STACKLEAK_PLUGIN "
82290 +#else
82291 +#define MODULE_STACKLEAK_PLUGIN ""
82292 +#endif
82293 +
82294 +#ifdef RANDSTRUCT_PLUGIN
82295 +#include <generated/randomize_layout_hash.h>
82296 +#define MODULE_RANDSTRUCT_PLUGIN "RANDSTRUCT_PLUGIN_" RANDSTRUCT_HASHED_SEED
82297 +#else
82298 +#define MODULE_RANDSTRUCT_PLUGIN
82299 +#endif
82300 +
82301 +#ifdef CONFIG_GRKERNSEC
82302 +#define MODULE_GRSEC "GRSEC "
82303 +#else
82304 +#define MODULE_GRSEC ""
82305 +#endif
82306 +
82307 #define VERMAGIC_STRING \
82308 UTS_RELEASE " " \
82309 MODULE_VERMAGIC_SMP MODULE_VERMAGIC_PREEMPT \
82310 MODULE_VERMAGIC_MODULE_UNLOAD MODULE_VERMAGIC_MODVERSIONS \
82311 - MODULE_ARCH_VERMAGIC
82312 + MODULE_ARCH_VERMAGIC \
82313 + MODULE_PAX_REFCOUNT MODULE_CONSTIFY_PLUGIN MODULE_STACKLEAK_PLUGIN \
82314 + MODULE_GRSEC MODULE_RANDSTRUCT_PLUGIN
82315
82316 diff --git a/include/linux/vga_switcheroo.h b/include/linux/vga_switcheroo.h
82317 index 502073a..a7de024 100644
82318 --- a/include/linux/vga_switcheroo.h
82319 +++ b/include/linux/vga_switcheroo.h
82320 @@ -63,8 +63,8 @@ int vga_switcheroo_get_client_state(struct pci_dev *dev);
82321
82322 void vga_switcheroo_set_dynamic_switch(struct pci_dev *pdev, enum vga_switcheroo_state dynamic);
82323
82324 -int vga_switcheroo_init_domain_pm_ops(struct device *dev, struct dev_pm_domain *domain);
82325 -int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, struct dev_pm_domain *domain);
82326 +int vga_switcheroo_init_domain_pm_ops(struct device *dev, dev_pm_domain_no_const *domain);
82327 +int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, dev_pm_domain_no_const *domain);
82328 #else
82329
82330 static inline void vga_switcheroo_unregister_client(struct pci_dev *dev) {}
82331 @@ -81,8 +81,8 @@ static inline int vga_switcheroo_get_client_state(struct pci_dev *dev) { return
82332
82333 static inline void vga_switcheroo_set_dynamic_switch(struct pci_dev *pdev, enum vga_switcheroo_state dynamic) {}
82334
82335 -static inline int vga_switcheroo_init_domain_pm_ops(struct device *dev, struct dev_pm_domain *domain) { return -EINVAL; }
82336 -static inline int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, struct dev_pm_domain *domain) { return -EINVAL; }
82337 +static inline int vga_switcheroo_init_domain_pm_ops(struct device *dev, dev_pm_domain_no_const *domain) { return -EINVAL; }
82338 +static inline int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, dev_pm_domain_no_const *domain) { return -EINVAL; }
82339
82340 #endif
82341 #endif /* _LINUX_VGA_SWITCHEROO_H_ */
82342 diff --git a/include/linux/vmalloc.h b/include/linux/vmalloc.h
82343 index 4b8a891..cb8df6e 100644
82344 --- a/include/linux/vmalloc.h
82345 +++ b/include/linux/vmalloc.h
82346 @@ -16,6 +16,11 @@ struct vm_area_struct; /* vma defining user mapping in mm_types.h */
82347 #define VM_USERMAP 0x00000008 /* suitable for remap_vmalloc_range */
82348 #define VM_VPAGES 0x00000010 /* buffer for pages was vmalloc'ed */
82349 #define VM_UNINITIALIZED 0x00000020 /* vm_struct is not fully initialized */
82350 +
82351 +#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
82352 +#define VM_KERNEXEC 0x00000040 /* allocate from executable kernel memory range */
82353 +#endif
82354 +
82355 /* bits [20..32] reserved for arch specific ioremap internals */
82356
82357 /*
82358 @@ -142,7 +147,7 @@ extern void free_vm_area(struct vm_struct *area);
82359
82360 /* for /dev/kmem */
82361 extern long vread(char *buf, char *addr, unsigned long count);
82362 -extern long vwrite(char *buf, char *addr, unsigned long count);
82363 +extern long vwrite(char *buf, char *addr, unsigned long count) __size_overflow(3);
82364
82365 /*
82366 * Internals. Dont't use..
82367 diff --git a/include/linux/vmstat.h b/include/linux/vmstat.h
82368 index a67b384..f52a537 100644
82369 --- a/include/linux/vmstat.h
82370 +++ b/include/linux/vmstat.h
82371 @@ -90,18 +90,18 @@ static inline void vm_events_fold_cpu(int cpu)
82372 /*
82373 * Zone based page accounting with per cpu differentials.
82374 */
82375 -extern atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
82376 +extern atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
82377
82378 static inline void zone_page_state_add(long x, struct zone *zone,
82379 enum zone_stat_item item)
82380 {
82381 - atomic_long_add(x, &zone->vm_stat[item]);
82382 - atomic_long_add(x, &vm_stat[item]);
82383 + atomic_long_add_unchecked(x, &zone->vm_stat[item]);
82384 + atomic_long_add_unchecked(x, &vm_stat[item]);
82385 }
82386
82387 -static inline unsigned long global_page_state(enum zone_stat_item item)
82388 +static inline unsigned long __intentional_overflow(-1) global_page_state(enum zone_stat_item item)
82389 {
82390 - long x = atomic_long_read(&vm_stat[item]);
82391 + long x = atomic_long_read_unchecked(&vm_stat[item]);
82392 #ifdef CONFIG_SMP
82393 if (x < 0)
82394 x = 0;
82395 @@ -109,10 +109,10 @@ static inline unsigned long global_page_state(enum zone_stat_item item)
82396 return x;
82397 }
82398
82399 -static inline unsigned long zone_page_state(struct zone *zone,
82400 +static inline unsigned long __intentional_overflow(-1) zone_page_state(struct zone *zone,
82401 enum zone_stat_item item)
82402 {
82403 - long x = atomic_long_read(&zone->vm_stat[item]);
82404 + long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
82405 #ifdef CONFIG_SMP
82406 if (x < 0)
82407 x = 0;
82408 @@ -129,7 +129,7 @@ static inline unsigned long zone_page_state(struct zone *zone,
82409 static inline unsigned long zone_page_state_snapshot(struct zone *zone,
82410 enum zone_stat_item item)
82411 {
82412 - long x = atomic_long_read(&zone->vm_stat[item]);
82413 + long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
82414
82415 #ifdef CONFIG_SMP
82416 int cpu;
82417 @@ -218,8 +218,8 @@ static inline void __mod_zone_page_state(struct zone *zone,
82418
82419 static inline void __inc_zone_state(struct zone *zone, enum zone_stat_item item)
82420 {
82421 - atomic_long_inc(&zone->vm_stat[item]);
82422 - atomic_long_inc(&vm_stat[item]);
82423 + atomic_long_inc_unchecked(&zone->vm_stat[item]);
82424 + atomic_long_inc_unchecked(&vm_stat[item]);
82425 }
82426
82427 static inline void __inc_zone_page_state(struct page *page,
82428 @@ -230,8 +230,8 @@ static inline void __inc_zone_page_state(struct page *page,
82429
82430 static inline void __dec_zone_state(struct zone *zone, enum zone_stat_item item)
82431 {
82432 - atomic_long_dec(&zone->vm_stat[item]);
82433 - atomic_long_dec(&vm_stat[item]);
82434 + atomic_long_dec_unchecked(&zone->vm_stat[item]);
82435 + atomic_long_dec_unchecked(&vm_stat[item]);
82436 }
82437
82438 static inline void __dec_zone_page_state(struct page *page,
82439 diff --git a/include/linux/xattr.h b/include/linux/xattr.h
82440 index 91b0a68..0e9adf6 100644
82441 --- a/include/linux/xattr.h
82442 +++ b/include/linux/xattr.h
82443 @@ -28,7 +28,7 @@ struct xattr_handler {
82444 size_t size, int handler_flags);
82445 int (*set)(struct dentry *dentry, const char *name, const void *buffer,
82446 size_t size, int flags, int handler_flags);
82447 -};
82448 +} __do_const;
82449
82450 struct xattr {
82451 const char *name;
82452 @@ -37,6 +37,9 @@ struct xattr {
82453 };
82454
82455 ssize_t xattr_getsecurity(struct inode *, const char *, void *, size_t);
82456 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
82457 +ssize_t pax_getxattr(struct dentry *, void *, size_t);
82458 +#endif
82459 ssize_t vfs_getxattr(struct dentry *, const char *, void *, size_t);
82460 ssize_t vfs_listxattr(struct dentry *d, char *list, size_t size);
82461 int __vfs_setxattr_noperm(struct dentry *, const char *, const void *, size_t, int);
82462 diff --git a/include/linux/zlib.h b/include/linux/zlib.h
82463 index 9c5a6b4..09c9438 100644
82464 --- a/include/linux/zlib.h
82465 +++ b/include/linux/zlib.h
82466 @@ -31,6 +31,7 @@
82467 #define _ZLIB_H
82468
82469 #include <linux/zconf.h>
82470 +#include <linux/compiler.h>
82471
82472 /* zlib deflate based on ZLIB_VERSION "1.1.3" */
82473 /* zlib inflate based on ZLIB_VERSION "1.2.3" */
82474 @@ -179,7 +180,7 @@ typedef z_stream *z_streamp;
82475
82476 /* basic functions */
82477
82478 -extern int zlib_deflate_workspacesize (int windowBits, int memLevel);
82479 +extern int zlib_deflate_workspacesize (int windowBits, int memLevel) __intentional_overflow(0);
82480 /*
82481 Returns the number of bytes that needs to be allocated for a per-
82482 stream workspace with the specified parameters. A pointer to this
82483 diff --git a/include/media/v4l2-dev.h b/include/media/v4l2-dev.h
82484 index c768c9f..bdcaa5a 100644
82485 --- a/include/media/v4l2-dev.h
82486 +++ b/include/media/v4l2-dev.h
82487 @@ -76,7 +76,7 @@ struct v4l2_file_operations {
82488 int (*mmap) (struct file *, struct vm_area_struct *);
82489 int (*open) (struct file *);
82490 int (*release) (struct file *);
82491 -};
82492 +} __do_const;
82493
82494 /*
82495 * Newer version of video_device, handled by videodev2.c
82496 diff --git a/include/media/v4l2-device.h b/include/media/v4l2-device.h
82497 index c9b1593..a572459 100644
82498 --- a/include/media/v4l2-device.h
82499 +++ b/include/media/v4l2-device.h
82500 @@ -95,7 +95,7 @@ int __must_check v4l2_device_register(struct device *dev, struct v4l2_device *v4
82501 this function returns 0. If the name ends with a digit (e.g. cx18),
82502 then the name will be set to cx18-0 since cx180 looks really odd. */
82503 int v4l2_device_set_name(struct v4l2_device *v4l2_dev, const char *basename,
82504 - atomic_t *instance);
82505 + atomic_unchecked_t *instance);
82506
82507 /* Set v4l2_dev->dev to NULL. Call when the USB parent disconnects.
82508 Since the parent disappears this ensures that v4l2_dev doesn't have an
82509 diff --git a/include/net/9p/transport.h b/include/net/9p/transport.h
82510 index 9a36d92..0aafe2a 100644
82511 --- a/include/net/9p/transport.h
82512 +++ b/include/net/9p/transport.h
82513 @@ -60,7 +60,7 @@ struct p9_trans_module {
82514 int (*cancel) (struct p9_client *, struct p9_req_t *req);
82515 int (*zc_request)(struct p9_client *, struct p9_req_t *,
82516 char *, char *, int , int, int, int);
82517 -};
82518 +} __do_const;
82519
82520 void v9fs_register_trans(struct p9_trans_module *m);
82521 void v9fs_unregister_trans(struct p9_trans_module *m);
82522 diff --git a/include/net/af_unix.h b/include/net/af_unix.h
82523 index a175ba4..196eb82 100644
82524 --- a/include/net/af_unix.h
82525 +++ b/include/net/af_unix.h
82526 @@ -36,7 +36,7 @@ struct unix_skb_parms {
82527 u32 secid; /* Security ID */
82528 #endif
82529 u32 consumed;
82530 -};
82531 +} __randomize_layout;
82532
82533 #define UNIXCB(skb) (*(struct unix_skb_parms *)&((skb)->cb))
82534 #define UNIXSID(skb) (&UNIXCB((skb)).secid)
82535 diff --git a/include/net/bluetooth/l2cap.h b/include/net/bluetooth/l2cap.h
82536 index c853b16d..37fccb7 100644
82537 --- a/include/net/bluetooth/l2cap.h
82538 +++ b/include/net/bluetooth/l2cap.h
82539 @@ -557,7 +557,7 @@ struct l2cap_ops {
82540 long (*get_sndtimeo) (struct l2cap_chan *chan);
82541 struct sk_buff *(*alloc_skb) (struct l2cap_chan *chan,
82542 unsigned long len, int nb);
82543 -};
82544 +} __do_const;
82545
82546 struct l2cap_conn {
82547 struct hci_conn *hcon;
82548 diff --git a/include/net/caif/cfctrl.h b/include/net/caif/cfctrl.h
82549 index f2ae33d..c457cf0 100644
82550 --- a/include/net/caif/cfctrl.h
82551 +++ b/include/net/caif/cfctrl.h
82552 @@ -52,7 +52,7 @@ struct cfctrl_rsp {
82553 void (*radioset_rsp)(void);
82554 void (*reject_rsp)(struct cflayer *layer, u8 linkid,
82555 struct cflayer *client_layer);
82556 -};
82557 +} __no_const;
82558
82559 /* Link Setup Parameters for CAIF-Links. */
82560 struct cfctrl_link_param {
82561 @@ -101,8 +101,8 @@ struct cfctrl_request_info {
82562 struct cfctrl {
82563 struct cfsrvl serv;
82564 struct cfctrl_rsp res;
82565 - atomic_t req_seq_no;
82566 - atomic_t rsp_seq_no;
82567 + atomic_unchecked_t req_seq_no;
82568 + atomic_unchecked_t rsp_seq_no;
82569 struct list_head list;
82570 /* Protects from simultaneous access to first_req list */
82571 spinlock_t info_list_lock;
82572 diff --git a/include/net/flow.h b/include/net/flow.h
82573 index 65ce471..b7bbe9b 100644
82574 --- a/include/net/flow.h
82575 +++ b/include/net/flow.h
82576 @@ -222,6 +222,6 @@ struct flow_cache_object *flow_cache_lookup(struct net *net,
82577
82578 void flow_cache_flush(void);
82579 void flow_cache_flush_deferred(void);
82580 -extern atomic_t flow_cache_genid;
82581 +extern atomic_unchecked_t flow_cache_genid;
82582
82583 #endif
82584 diff --git a/include/net/genetlink.h b/include/net/genetlink.h
82585 index 1b177ed..a24a138 100644
82586 --- a/include/net/genetlink.h
82587 +++ b/include/net/genetlink.h
82588 @@ -118,7 +118,7 @@ struct genl_ops {
82589 u8 cmd;
82590 u8 internal_flags;
82591 u8 flags;
82592 -};
82593 +} __do_const;
82594
82595 int __genl_register_family(struct genl_family *family);
82596
82597 diff --git a/include/net/gro_cells.h b/include/net/gro_cells.h
82598 index 734d9b5..48a9a4b 100644
82599 --- a/include/net/gro_cells.h
82600 +++ b/include/net/gro_cells.h
82601 @@ -29,7 +29,7 @@ static inline void gro_cells_receive(struct gro_cells *gcells, struct sk_buff *s
82602 cell += skb_get_rx_queue(skb) & gcells->gro_cells_mask;
82603
82604 if (skb_queue_len(&cell->napi_skbs) > netdev_max_backlog) {
82605 - atomic_long_inc(&dev->rx_dropped);
82606 + atomic_long_inc_unchecked(&dev->rx_dropped);
82607 kfree_skb(skb);
82608 return;
82609 }
82610 diff --git a/include/net/inet_connection_sock.h b/include/net/inet_connection_sock.h
82611 index c55aeed..b3393f4 100644
82612 --- a/include/net/inet_connection_sock.h
82613 +++ b/include/net/inet_connection_sock.h
82614 @@ -62,7 +62,7 @@ struct inet_connection_sock_af_ops {
82615 void (*addr2sockaddr)(struct sock *sk, struct sockaddr *);
82616 int (*bind_conflict)(const struct sock *sk,
82617 const struct inet_bind_bucket *tb, bool relax);
82618 -};
82619 +} __do_const;
82620
82621 /** inet_connection_sock - INET connection oriented sock
82622 *
82623 diff --git a/include/net/inetpeer.h b/include/net/inetpeer.h
82624 index f4e127a..c3d5e9c 100644
82625 --- a/include/net/inetpeer.h
82626 +++ b/include/net/inetpeer.h
82627 @@ -47,8 +47,8 @@ struct inet_peer {
82628 */
82629 union {
82630 struct {
82631 - atomic_t rid; /* Frag reception counter */
82632 - atomic_t ip_id_count; /* IP ID for the next packet */
82633 + atomic_unchecked_t rid; /* Frag reception counter */
82634 + atomic_unchecked_t ip_id_count; /* IP ID for the next packet */
82635 };
82636 struct rcu_head rcu;
82637 struct inet_peer *gc_next;
82638 @@ -178,16 +178,13 @@ static inline void inet_peer_refcheck(const struct inet_peer *p)
82639 /* can be called with or without local BH being disabled */
82640 static inline int inet_getid(struct inet_peer *p, int more)
82641 {
82642 - int old, new;
82643 + int id;
82644 more++;
82645 inet_peer_refcheck(p);
82646 - do {
82647 - old = atomic_read(&p->ip_id_count);
82648 - new = old + more;
82649 - if (!new)
82650 - new = 1;
82651 - } while (atomic_cmpxchg(&p->ip_id_count, old, new) != old);
82652 - return new;
82653 + id = atomic_add_return_unchecked(more, &p->ip_id_count);
82654 + if (!id)
82655 + id = atomic_inc_return_unchecked(&p->ip_id_count);
82656 + return id;
82657 }
82658
82659 #endif /* _NET_INETPEER_H */
82660 diff --git a/include/net/ip.h b/include/net/ip.h
82661 index 5a25f36..2e73203 100644
82662 --- a/include/net/ip.h
82663 +++ b/include/net/ip.h
82664 @@ -219,7 +219,7 @@ static inline void snmp_mib_free(void __percpu *ptr[SNMP_ARRAY_SZ])
82665
82666 void inet_get_local_port_range(struct net *net, int *low, int *high);
82667
82668 -extern unsigned long *sysctl_local_reserved_ports;
82669 +extern unsigned long sysctl_local_reserved_ports[65536 / 8 / sizeof(unsigned long)];
82670 static inline int inet_is_reserved_local_port(int port)
82671 {
82672 return test_bit(port, sysctl_local_reserved_ports);
82673 diff --git a/include/net/ip_fib.h b/include/net/ip_fib.h
82674 index 9922093..a1755d6 100644
82675 --- a/include/net/ip_fib.h
82676 +++ b/include/net/ip_fib.h
82677 @@ -169,7 +169,7 @@ __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh);
82678
82679 #define FIB_RES_SADDR(net, res) \
82680 ((FIB_RES_NH(res).nh_saddr_genid == \
82681 - atomic_read(&(net)->ipv4.dev_addr_genid)) ? \
82682 + atomic_read_unchecked(&(net)->ipv4.dev_addr_genid)) ? \
82683 FIB_RES_NH(res).nh_saddr : \
82684 fib_info_update_nh_saddr((net), &FIB_RES_NH(res)))
82685 #define FIB_RES_GW(res) (FIB_RES_NH(res).nh_gw)
82686 diff --git a/include/net/ip_vs.h b/include/net/ip_vs.h
82687 index 5679d92..2e7a690 100644
82688 --- a/include/net/ip_vs.h
82689 +++ b/include/net/ip_vs.h
82690 @@ -558,7 +558,7 @@ struct ip_vs_conn {
82691 struct ip_vs_conn *control; /* Master control connection */
82692 atomic_t n_control; /* Number of controlled ones */
82693 struct ip_vs_dest *dest; /* real server */
82694 - atomic_t in_pkts; /* incoming packet counter */
82695 + atomic_unchecked_t in_pkts; /* incoming packet counter */
82696
82697 /* packet transmitter for different forwarding methods. If it
82698 mangles the packet, it must return NF_DROP or better NF_STOLEN,
82699 @@ -705,7 +705,7 @@ struct ip_vs_dest {
82700 __be16 port; /* port number of the server */
82701 union nf_inet_addr addr; /* IP address of the server */
82702 volatile unsigned int flags; /* dest status flags */
82703 - atomic_t conn_flags; /* flags to copy to conn */
82704 + atomic_unchecked_t conn_flags; /* flags to copy to conn */
82705 atomic_t weight; /* server weight */
82706
82707 atomic_t refcnt; /* reference counter */
82708 @@ -960,11 +960,11 @@ struct netns_ipvs {
82709 /* ip_vs_lblc */
82710 int sysctl_lblc_expiration;
82711 struct ctl_table_header *lblc_ctl_header;
82712 - struct ctl_table *lblc_ctl_table;
82713 + ctl_table_no_const *lblc_ctl_table;
82714 /* ip_vs_lblcr */
82715 int sysctl_lblcr_expiration;
82716 struct ctl_table_header *lblcr_ctl_header;
82717 - struct ctl_table *lblcr_ctl_table;
82718 + ctl_table_no_const *lblcr_ctl_table;
82719 /* ip_vs_est */
82720 struct list_head est_list; /* estimator list */
82721 spinlock_t est_lock;
82722 diff --git a/include/net/irda/ircomm_tty.h b/include/net/irda/ircomm_tty.h
82723 index 0224402..dafaf94a 100644
82724 --- a/include/net/irda/ircomm_tty.h
82725 +++ b/include/net/irda/ircomm_tty.h
82726 @@ -35,6 +35,7 @@
82727 #include <linux/termios.h>
82728 #include <linux/timer.h>
82729 #include <linux/tty.h> /* struct tty_struct */
82730 +#include <asm/local.h>
82731
82732 #include <net/irda/irias_object.h>
82733 #include <net/irda/ircomm_core.h>
82734 diff --git a/include/net/iucv/af_iucv.h b/include/net/iucv/af_iucv.h
82735 index 714cc9a..ea05f3e 100644
82736 --- a/include/net/iucv/af_iucv.h
82737 +++ b/include/net/iucv/af_iucv.h
82738 @@ -149,7 +149,7 @@ struct iucv_skb_cb {
82739 struct iucv_sock_list {
82740 struct hlist_head head;
82741 rwlock_t lock;
82742 - atomic_t autobind_name;
82743 + atomic_unchecked_t autobind_name;
82744 };
82745
82746 unsigned int iucv_sock_poll(struct file *file, struct socket *sock,
82747 diff --git a/include/net/llc_c_ac.h b/include/net/llc_c_ac.h
82748 index f3be818..bf46196 100644
82749 --- a/include/net/llc_c_ac.h
82750 +++ b/include/net/llc_c_ac.h
82751 @@ -87,7 +87,7 @@
82752 #define LLC_CONN_AC_STOP_SENDACK_TMR 70
82753 #define LLC_CONN_AC_START_SENDACK_TMR_IF_NOT_RUNNING 71
82754
82755 -typedef int (*llc_conn_action_t)(struct sock *sk, struct sk_buff *skb);
82756 +typedef int (* const llc_conn_action_t)(struct sock *sk, struct sk_buff *skb);
82757
82758 int llc_conn_ac_clear_remote_busy(struct sock *sk, struct sk_buff *skb);
82759 int llc_conn_ac_conn_ind(struct sock *sk, struct sk_buff *skb);
82760 diff --git a/include/net/llc_c_ev.h b/include/net/llc_c_ev.h
82761 index 3948cf1..83b28c4 100644
82762 --- a/include/net/llc_c_ev.h
82763 +++ b/include/net/llc_c_ev.h
82764 @@ -125,8 +125,8 @@ static __inline__ struct llc_conn_state_ev *llc_conn_ev(struct sk_buff *skb)
82765 return (struct llc_conn_state_ev *)skb->cb;
82766 }
82767
82768 -typedef int (*llc_conn_ev_t)(struct sock *sk, struct sk_buff *skb);
82769 -typedef int (*llc_conn_ev_qfyr_t)(struct sock *sk, struct sk_buff *skb);
82770 +typedef int (* const llc_conn_ev_t)(struct sock *sk, struct sk_buff *skb);
82771 +typedef int (* const llc_conn_ev_qfyr_t)(struct sock *sk, struct sk_buff *skb);
82772
82773 int llc_conn_ev_conn_req(struct sock *sk, struct sk_buff *skb);
82774 int llc_conn_ev_data_req(struct sock *sk, struct sk_buff *skb);
82775 diff --git a/include/net/llc_c_st.h b/include/net/llc_c_st.h
82776 index 0e79cfb..f46db31 100644
82777 --- a/include/net/llc_c_st.h
82778 +++ b/include/net/llc_c_st.h
82779 @@ -37,7 +37,7 @@ struct llc_conn_state_trans {
82780 u8 next_state;
82781 llc_conn_ev_qfyr_t *ev_qualifiers;
82782 llc_conn_action_t *ev_actions;
82783 -};
82784 +} __do_const;
82785
82786 struct llc_conn_state {
82787 u8 current_state;
82788 diff --git a/include/net/llc_s_ac.h b/include/net/llc_s_ac.h
82789 index a61b98c..aade1eb 100644
82790 --- a/include/net/llc_s_ac.h
82791 +++ b/include/net/llc_s_ac.h
82792 @@ -23,7 +23,7 @@
82793 #define SAP_ACT_TEST_IND 9
82794
82795 /* All action functions must look like this */
82796 -typedef int (*llc_sap_action_t)(struct llc_sap *sap, struct sk_buff *skb);
82797 +typedef int (* const llc_sap_action_t)(struct llc_sap *sap, struct sk_buff *skb);
82798
82799 int llc_sap_action_unitdata_ind(struct llc_sap *sap, struct sk_buff *skb);
82800 int llc_sap_action_send_ui(struct llc_sap *sap, struct sk_buff *skb);
82801 diff --git a/include/net/llc_s_st.h b/include/net/llc_s_st.h
82802 index 567c681..cd73ac0 100644
82803 --- a/include/net/llc_s_st.h
82804 +++ b/include/net/llc_s_st.h
82805 @@ -20,7 +20,7 @@ struct llc_sap_state_trans {
82806 llc_sap_ev_t ev;
82807 u8 next_state;
82808 llc_sap_action_t *ev_actions;
82809 -};
82810 +} __do_const;
82811
82812 struct llc_sap_state {
82813 u8 curr_state;
82814 diff --git a/include/net/mac80211.h b/include/net/mac80211.h
82815 index 7ceed99..d3ffaa2 100644
82816 --- a/include/net/mac80211.h
82817 +++ b/include/net/mac80211.h
82818 @@ -4407,7 +4407,7 @@ struct rate_control_ops {
82819 void (*add_sta_debugfs)(void *priv, void *priv_sta,
82820 struct dentry *dir);
82821 void (*remove_sta_debugfs)(void *priv, void *priv_sta);
82822 -};
82823 +} __do_const;
82824
82825 static inline int rate_supported(struct ieee80211_sta *sta,
82826 enum ieee80211_band band,
82827 diff --git a/include/net/neighbour.h b/include/net/neighbour.h
82828 index 536501a..47b7982 100644
82829 --- a/include/net/neighbour.h
82830 +++ b/include/net/neighbour.h
82831 @@ -123,7 +123,7 @@ struct neigh_ops {
82832 void (*error_report)(struct neighbour *, struct sk_buff *);
82833 int (*output)(struct neighbour *, struct sk_buff *);
82834 int (*connected_output)(struct neighbour *, struct sk_buff *);
82835 -};
82836 +} __do_const;
82837
82838 struct pneigh_entry {
82839 struct pneigh_entry *next;
82840 @@ -163,7 +163,6 @@ struct neigh_table {
82841 void (*proxy_redo)(struct sk_buff *skb);
82842 char *id;
82843 struct neigh_parms parms;
82844 - /* HACK. gc_* should follow parms without a gap! */
82845 int gc_interval;
82846 int gc_thresh1;
82847 int gc_thresh2;
82848 @@ -178,7 +177,7 @@ struct neigh_table {
82849 struct neigh_statistics __percpu *stats;
82850 struct neigh_hash_table __rcu *nht;
82851 struct pneigh_entry **phash_buckets;
82852 -};
82853 +} __randomize_layout;
82854
82855 #define NEIGH_PRIV_ALIGN sizeof(long long)
82856 #define NEIGH_ENTRY_SIZE(size) ALIGN((size), NEIGH_PRIV_ALIGN)
82857 diff --git a/include/net/net_namespace.h b/include/net/net_namespace.h
82858 index da68c9a..c4a0720 100644
82859 --- a/include/net/net_namespace.h
82860 +++ b/include/net/net_namespace.h
82861 @@ -124,8 +124,8 @@ struct net {
82862 struct netns_ipvs *ipvs;
82863 #endif
82864 struct sock *diag_nlsk;
82865 - atomic_t fnhe_genid;
82866 -};
82867 + atomic_unchecked_t fnhe_genid;
82868 +} __randomize_layout;
82869
82870 /*
82871 * ifindex generation is per-net namespace, and loopback is
82872 @@ -281,7 +281,11 @@ static inline struct net *read_pnet(struct net * const *pnet)
82873 #define __net_init __init
82874 #define __net_exit __exit_refok
82875 #define __net_initdata __initdata
82876 +#ifdef CONSTIFY_PLUGIN
82877 #define __net_initconst __initconst
82878 +#else
82879 +#define __net_initconst __initdata
82880 +#endif
82881 #endif
82882
82883 struct pernet_operations {
82884 @@ -291,7 +295,7 @@ struct pernet_operations {
82885 void (*exit_batch)(struct list_head *net_exit_list);
82886 int *id;
82887 size_t size;
82888 -};
82889 +} __do_const;
82890
82891 /*
82892 * Use these carefully. If you implement a network device and it
82893 @@ -339,23 +343,23 @@ static inline void unregister_net_sysctl_table(struct ctl_table_header *header)
82894
82895 static inline int rt_genid_ipv4(struct net *net)
82896 {
82897 - return atomic_read(&net->ipv4.rt_genid);
82898 + return atomic_read_unchecked(&net->ipv4.rt_genid);
82899 }
82900
82901 static inline void rt_genid_bump_ipv4(struct net *net)
82902 {
82903 - atomic_inc(&net->ipv4.rt_genid);
82904 + atomic_inc_unchecked(&net->ipv4.rt_genid);
82905 }
82906
82907 #if IS_ENABLED(CONFIG_IPV6)
82908 static inline int rt_genid_ipv6(struct net *net)
82909 {
82910 - return atomic_read(&net->ipv6.rt_genid);
82911 + return atomic_read_unchecked(&net->ipv6.rt_genid);
82912 }
82913
82914 static inline void rt_genid_bump_ipv6(struct net *net)
82915 {
82916 - atomic_inc(&net->ipv6.rt_genid);
82917 + atomic_inc_unchecked(&net->ipv6.rt_genid);
82918 }
82919 #else
82920 static inline int rt_genid_ipv6(struct net *net)
82921 @@ -377,12 +381,12 @@ static inline void rt_genid_bump_all(struct net *net)
82922
82923 static inline int fnhe_genid(struct net *net)
82924 {
82925 - return atomic_read(&net->fnhe_genid);
82926 + return atomic_read_unchecked(&net->fnhe_genid);
82927 }
82928
82929 static inline void fnhe_genid_bump(struct net *net)
82930 {
82931 - atomic_inc(&net->fnhe_genid);
82932 + atomic_inc_unchecked(&net->fnhe_genid);
82933 }
82934
82935 #endif /* __NET_NET_NAMESPACE_H */
82936 diff --git a/include/net/netdma.h b/include/net/netdma.h
82937 index 8ba8ce2..99b7fff 100644
82938 --- a/include/net/netdma.h
82939 +++ b/include/net/netdma.h
82940 @@ -24,7 +24,7 @@
82941 #include <linux/dmaengine.h>
82942 #include <linux/skbuff.h>
82943
82944 -int dma_skb_copy_datagram_iovec(struct dma_chan* chan,
82945 +int __intentional_overflow(3,5) dma_skb_copy_datagram_iovec(struct dma_chan* chan,
82946 struct sk_buff *skb, int offset, struct iovec *to,
82947 size_t len, struct dma_pinned_list *pinned_list);
82948
82949 diff --git a/include/net/netfilter/nf_conntrack_extend.h b/include/net/netfilter/nf_conntrack_extend.h
82950 index 956b175..55d1504 100644
82951 --- a/include/net/netfilter/nf_conntrack_extend.h
82952 +++ b/include/net/netfilter/nf_conntrack_extend.h
82953 @@ -47,8 +47,8 @@ enum nf_ct_ext_id {
82954 /* Extensions: optional stuff which isn't permanently in struct. */
82955 struct nf_ct_ext {
82956 struct rcu_head rcu;
82957 - u8 offset[NF_CT_EXT_NUM];
82958 - u8 len;
82959 + u16 offset[NF_CT_EXT_NUM];
82960 + u16 len;
82961 char data[0];
82962 };
82963
82964 diff --git a/include/net/netlink.h b/include/net/netlink.h
82965 index 2b47eaa..6d5bcc2 100644
82966 --- a/include/net/netlink.h
82967 +++ b/include/net/netlink.h
82968 @@ -521,7 +521,7 @@ static inline void *nlmsg_get_pos(struct sk_buff *skb)
82969 static inline void nlmsg_trim(struct sk_buff *skb, const void *mark)
82970 {
82971 if (mark)
82972 - skb_trim(skb, (unsigned char *) mark - skb->data);
82973 + skb_trim(skb, (const unsigned char *) mark - skb->data);
82974 }
82975
82976 /**
82977 diff --git a/include/net/netns/conntrack.h b/include/net/netns/conntrack.h
82978 index c9c0c53..53f24c3 100644
82979 --- a/include/net/netns/conntrack.h
82980 +++ b/include/net/netns/conntrack.h
82981 @@ -12,10 +12,10 @@ struct nf_conntrack_ecache;
82982 struct nf_proto_net {
82983 #ifdef CONFIG_SYSCTL
82984 struct ctl_table_header *ctl_table_header;
82985 - struct ctl_table *ctl_table;
82986 + ctl_table_no_const *ctl_table;
82987 #ifdef CONFIG_NF_CONNTRACK_PROC_COMPAT
82988 struct ctl_table_header *ctl_compat_header;
82989 - struct ctl_table *ctl_compat_table;
82990 + ctl_table_no_const *ctl_compat_table;
82991 #endif
82992 #endif
82993 unsigned int users;
82994 @@ -58,7 +58,7 @@ struct nf_ip_net {
82995 struct nf_icmp_net icmpv6;
82996 #if defined(CONFIG_SYSCTL) && defined(CONFIG_NF_CONNTRACK_PROC_COMPAT)
82997 struct ctl_table_header *ctl_table_header;
82998 - struct ctl_table *ctl_table;
82999 + ctl_table_no_const *ctl_table;
83000 #endif
83001 };
83002
83003 diff --git a/include/net/netns/ipv4.h b/include/net/netns/ipv4.h
83004 index ee520cb..9a0fd88 100644
83005 --- a/include/net/netns/ipv4.h
83006 +++ b/include/net/netns/ipv4.h
83007 @@ -72,7 +72,7 @@ struct netns_ipv4 {
83008
83009 kgid_t sysctl_ping_group_range[2];
83010
83011 - atomic_t dev_addr_genid;
83012 + atomic_unchecked_t dev_addr_genid;
83013
83014 #ifdef CONFIG_IP_MROUTE
83015 #ifndef CONFIG_IP_MROUTE_MULTIPLE_TABLES
83016 @@ -82,6 +82,6 @@ struct netns_ipv4 {
83017 struct fib_rules_ops *mr_rules_ops;
83018 #endif
83019 #endif
83020 - atomic_t rt_genid;
83021 + atomic_unchecked_t rt_genid;
83022 };
83023 #endif
83024 diff --git a/include/net/netns/ipv6.h b/include/net/netns/ipv6.h
83025 index 0fb2401..477d81c 100644
83026 --- a/include/net/netns/ipv6.h
83027 +++ b/include/net/netns/ipv6.h
83028 @@ -71,8 +71,8 @@ struct netns_ipv6 {
83029 struct fib_rules_ops *mr6_rules_ops;
83030 #endif
83031 #endif
83032 - atomic_t dev_addr_genid;
83033 - atomic_t rt_genid;
83034 + atomic_unchecked_t dev_addr_genid;
83035 + atomic_unchecked_t rt_genid;
83036 };
83037
83038 #if IS_ENABLED(CONFIG_NF_DEFRAG_IPV6)
83039 diff --git a/include/net/ping.h b/include/net/ping.h
83040 index 90f4841..74446a8 100644
83041 --- a/include/net/ping.h
83042 +++ b/include/net/ping.h
83043 @@ -56,7 +56,7 @@ struct ping_iter_state {
83044 extern struct proto ping_prot;
83045 extern struct ping_table ping_table;
83046 #if IS_ENABLED(CONFIG_IPV6)
83047 -extern struct pingv6_ops pingv6_ops;
83048 +extern struct pingv6_ops *pingv6_ops;
83049 #endif
83050
83051 struct pingfakehdr {
83052 diff --git a/include/net/protocol.h b/include/net/protocol.h
83053 index fbf7676..a5e21c3 100644
83054 --- a/include/net/protocol.h
83055 +++ b/include/net/protocol.h
83056 @@ -44,7 +44,7 @@ struct net_protocol {
83057 void (*err_handler)(struct sk_buff *skb, u32 info);
83058 unsigned int no_policy:1,
83059 netns_ok:1;
83060 -};
83061 +} __do_const;
83062
83063 #if IS_ENABLED(CONFIG_IPV6)
83064 struct inet6_protocol {
83065 @@ -57,7 +57,7 @@ struct inet6_protocol {
83066 u8 type, u8 code, int offset,
83067 __be32 info);
83068 unsigned int flags; /* INET6_PROTO_xxx */
83069 -};
83070 +} __do_const;
83071
83072 #define INET6_PROTO_NOPOLICY 0x1
83073 #define INET6_PROTO_FINAL 0x2
83074 diff --git a/include/net/rtnetlink.h b/include/net/rtnetlink.h
83075 index bb13a18..e734116 100644
83076 --- a/include/net/rtnetlink.h
83077 +++ b/include/net/rtnetlink.h
83078 @@ -79,7 +79,7 @@ struct rtnl_link_ops {
83079 const struct net_device *dev);
83080 unsigned int (*get_num_tx_queues)(void);
83081 unsigned int (*get_num_rx_queues)(void);
83082 -};
83083 +} __do_const;
83084
83085 int __rtnl_link_register(struct rtnl_link_ops *ops);
83086 void __rtnl_link_unregister(struct rtnl_link_ops *ops);
83087 diff --git a/include/net/sctp/checksum.h b/include/net/sctp/checksum.h
83088 index 6bd44fe..96f364e 100644
83089 --- a/include/net/sctp/checksum.h
83090 +++ b/include/net/sctp/checksum.h
83091 @@ -62,8 +62,8 @@ static inline __le32 sctp_compute_cksum(const struct sk_buff *skb,
83092 unsigned int offset)
83093 {
83094 struct sctphdr *sh = sctp_hdr(skb);
83095 - __le32 ret, old = sh->checksum;
83096 - const struct skb_checksum_ops ops = {
83097 + __le32 ret, old = sh->checksum;
83098 + static const struct skb_checksum_ops ops = {
83099 .update = sctp_csum_update,
83100 .combine = sctp_csum_combine,
83101 };
83102 diff --git a/include/net/sctp/sm.h b/include/net/sctp/sm.h
83103 index 4ef75af..5aa073a 100644
83104 --- a/include/net/sctp/sm.h
83105 +++ b/include/net/sctp/sm.h
83106 @@ -81,7 +81,7 @@ typedef void (sctp_timer_event_t) (unsigned long);
83107 typedef struct {
83108 sctp_state_fn_t *fn;
83109 const char *name;
83110 -} sctp_sm_table_entry_t;
83111 +} __do_const sctp_sm_table_entry_t;
83112
83113 /* A naming convention of "sctp_sf_xxx" applies to all the state functions
83114 * currently in use.
83115 @@ -293,7 +293,7 @@ __u32 sctp_generate_tag(const struct sctp_endpoint *);
83116 __u32 sctp_generate_tsn(const struct sctp_endpoint *);
83117
83118 /* Extern declarations for major data structures. */
83119 -extern sctp_timer_event_t *sctp_timer_events[SCTP_NUM_TIMEOUT_TYPES];
83120 +extern sctp_timer_event_t * const sctp_timer_events[SCTP_NUM_TIMEOUT_TYPES];
83121
83122
83123 /* Get the size of a DATA chunk payload. */
83124 diff --git a/include/net/sctp/structs.h b/include/net/sctp/structs.h
83125 index 0a248b3..4dcbe5c 100644
83126 --- a/include/net/sctp/structs.h
83127 +++ b/include/net/sctp/structs.h
83128 @@ -508,7 +508,7 @@ struct sctp_pf {
83129 struct sctp_association *asoc);
83130 void (*addr_v4map) (struct sctp_sock *, union sctp_addr *);
83131 struct sctp_af *af;
83132 -};
83133 +} __do_const;
83134
83135
83136 /* Structure to track chunk fragments that have been acked, but peer
83137 diff --git a/include/net/sock.h b/include/net/sock.h
83138 index a2b3d4e..466983f 100644
83139 --- a/include/net/sock.h
83140 +++ b/include/net/sock.h
83141 @@ -348,7 +348,7 @@ struct sock {
83142 unsigned int sk_napi_id;
83143 unsigned int sk_ll_usec;
83144 #endif
83145 - atomic_t sk_drops;
83146 + atomic_unchecked_t sk_drops;
83147 int sk_rcvbuf;
83148
83149 struct sk_filter __rcu *sk_filter;
83150 @@ -1022,7 +1022,7 @@ struct proto {
83151 void (*destroy_cgroup)(struct mem_cgroup *memcg);
83152 struct cg_proto *(*proto_cgroup)(struct mem_cgroup *memcg);
83153 #endif
83154 -};
83155 +} __randomize_layout;
83156
83157 /*
83158 * Bits in struct cg_proto.flags
83159 @@ -1209,7 +1209,7 @@ static inline u64 memcg_memory_allocated_read(struct cg_proto *prot)
83160 return ret >> PAGE_SHIFT;
83161 }
83162
83163 -static inline long
83164 +static inline long __intentional_overflow(-1)
83165 sk_memory_allocated(const struct sock *sk)
83166 {
83167 struct proto *prot = sk->sk_prot;
83168 @@ -1354,7 +1354,7 @@ struct sock_iocb {
83169 struct scm_cookie *scm;
83170 struct msghdr *msg, async_msg;
83171 struct kiocb *kiocb;
83172 -};
83173 +} __randomize_layout;
83174
83175 static inline struct sock_iocb *kiocb_to_siocb(struct kiocb *iocb)
83176 {
83177 @@ -1818,7 +1818,7 @@ static inline void sk_nocaps_add(struct sock *sk, netdev_features_t flags)
83178 }
83179
83180 static inline int skb_do_copy_data_nocache(struct sock *sk, struct sk_buff *skb,
83181 - char __user *from, char *to,
83182 + char __user *from, unsigned char *to,
83183 int copy, int offset)
83184 {
83185 if (skb->ip_summed == CHECKSUM_NONE) {
83186 @@ -2080,7 +2080,7 @@ static inline void sk_stream_moderate_sndbuf(struct sock *sk)
83187 }
83188 }
83189
83190 -struct sk_buff *sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp);
83191 +struct sk_buff * __intentional_overflow(0) sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp);
83192
83193 /**
83194 * sk_page_frag - return an appropriate page_frag
83195 diff --git a/include/net/tcp.h b/include/net/tcp.h
83196 index 197b020..10a7f03 100644
83197 --- a/include/net/tcp.h
83198 +++ b/include/net/tcp.h
83199 @@ -541,7 +541,7 @@ void tcp_retransmit_timer(struct sock *sk);
83200 void tcp_xmit_retransmit_queue(struct sock *);
83201 void tcp_simple_retransmit(struct sock *);
83202 int tcp_trim_head(struct sock *, struct sk_buff *, u32);
83203 -int tcp_fragment(struct sock *, struct sk_buff *, u32, unsigned int);
83204 +int __intentional_overflow(3) tcp_fragment(struct sock *, struct sk_buff *, u32, unsigned int);
83205
83206 void tcp_send_probe0(struct sock *);
83207 void tcp_send_partial(struct sock *);
83208 @@ -712,8 +712,8 @@ struct tcp_skb_cb {
83209 struct inet6_skb_parm h6;
83210 #endif
83211 } header; /* For incoming frames */
83212 - __u32 seq; /* Starting sequence number */
83213 - __u32 end_seq; /* SEQ + FIN + SYN + datalen */
83214 + __u32 seq __intentional_overflow(0); /* Starting sequence number */
83215 + __u32 end_seq __intentional_overflow(0); /* SEQ + FIN + SYN + datalen */
83216 __u32 when; /* used to compute rtt's */
83217 __u8 tcp_flags; /* TCP header flags. (tcp[13]) */
83218
83219 @@ -727,7 +727,7 @@ struct tcp_skb_cb {
83220
83221 __u8 ip_dsfield; /* IPv4 tos or IPv6 dsfield */
83222 /* 1 byte hole */
83223 - __u32 ack_seq; /* Sequence number ACK'd */
83224 + __u32 ack_seq __intentional_overflow(0); /* Sequence number ACK'd */
83225 };
83226
83227 #define TCP_SKB_CB(__skb) ((struct tcp_skb_cb *)&((__skb)->cb[0]))
83228 diff --git a/include/net/xfrm.h b/include/net/xfrm.h
83229 index 6b82fdf..14d74d2 100644
83230 --- a/include/net/xfrm.h
83231 +++ b/include/net/xfrm.h
83232 @@ -287,7 +287,6 @@ struct xfrm_dst;
83233 struct xfrm_policy_afinfo {
83234 unsigned short family;
83235 struct dst_ops *dst_ops;
83236 - void (*garbage_collect)(struct net *net);
83237 struct dst_entry *(*dst_lookup)(struct net *net, int tos,
83238 const xfrm_address_t *saddr,
83239 const xfrm_address_t *daddr);
83240 @@ -305,7 +304,7 @@ struct xfrm_policy_afinfo {
83241 struct net_device *dev,
83242 const struct flowi *fl);
83243 struct dst_entry *(*blackhole_route)(struct net *net, struct dst_entry *orig);
83244 -};
83245 +} __do_const;
83246
83247 int xfrm_policy_register_afinfo(struct xfrm_policy_afinfo *afinfo);
83248 int xfrm_policy_unregister_afinfo(struct xfrm_policy_afinfo *afinfo);
83249 @@ -344,7 +343,7 @@ struct xfrm_state_afinfo {
83250 int (*transport_finish)(struct sk_buff *skb,
83251 int async);
83252 void (*local_error)(struct sk_buff *skb, u32 mtu);
83253 -};
83254 +} __do_const;
83255
83256 int xfrm_state_register_afinfo(struct xfrm_state_afinfo *afinfo);
83257 int xfrm_state_unregister_afinfo(struct xfrm_state_afinfo *afinfo);
83258 @@ -429,7 +428,7 @@ struct xfrm_mode {
83259 struct module *owner;
83260 unsigned int encap;
83261 int flags;
83262 -};
83263 +} __do_const;
83264
83265 /* Flags for xfrm_mode. */
83266 enum {
83267 @@ -526,7 +525,7 @@ struct xfrm_policy {
83268 struct timer_list timer;
83269
83270 struct flow_cache_object flo;
83271 - atomic_t genid;
83272 + atomic_unchecked_t genid;
83273 u32 priority;
83274 u32 index;
83275 struct xfrm_mark mark;
83276 @@ -1166,6 +1165,7 @@ static inline void xfrm_sk_free_policy(struct sock *sk)
83277 }
83278
83279 void xfrm_garbage_collect(struct net *net);
83280 +void xfrm_garbage_collect_deferred(struct net *net);
83281
83282 #else
83283
83284 @@ -1204,6 +1204,9 @@ static inline int xfrm6_policy_check_reverse(struct sock *sk, int dir,
83285 static inline void xfrm_garbage_collect(struct net *net)
83286 {
83287 }
83288 +static inline void xfrm_garbage_collect_deferred(struct net *net)
83289 +{
83290 +}
83291 #endif
83292
83293 static __inline__
83294 diff --git a/include/rdma/iw_cm.h b/include/rdma/iw_cm.h
83295 index 1017e0b..227aa4d 100644
83296 --- a/include/rdma/iw_cm.h
83297 +++ b/include/rdma/iw_cm.h
83298 @@ -122,7 +122,7 @@ struct iw_cm_verbs {
83299 int backlog);
83300
83301 int (*destroy_listen)(struct iw_cm_id *cm_id);
83302 -};
83303 +} __no_const;
83304
83305 /**
83306 * iw_create_cm_id - Create an IW CM identifier.
83307 diff --git a/include/scsi/libfc.h b/include/scsi/libfc.h
83308 index 52beadf..598734c 100644
83309 --- a/include/scsi/libfc.h
83310 +++ b/include/scsi/libfc.h
83311 @@ -771,6 +771,7 @@ struct libfc_function_template {
83312 */
83313 void (*disc_stop_final) (struct fc_lport *);
83314 };
83315 +typedef struct libfc_function_template __no_const libfc_function_template_no_const;
83316
83317 /**
83318 * struct fc_disc - Discovery context
83319 @@ -875,7 +876,7 @@ struct fc_lport {
83320 struct fc_vport *vport;
83321
83322 /* Operational Information */
83323 - struct libfc_function_template tt;
83324 + libfc_function_template_no_const tt;
83325 u8 link_up;
83326 u8 qfull;
83327 enum fc_lport_state state;
83328 diff --git a/include/scsi/scsi_device.h b/include/scsi/scsi_device.h
83329 index d65fbec..f80fef2 100644
83330 --- a/include/scsi/scsi_device.h
83331 +++ b/include/scsi/scsi_device.h
83332 @@ -180,9 +180,9 @@ struct scsi_device {
83333 unsigned int max_device_blocked; /* what device_blocked counts down from */
83334 #define SCSI_DEFAULT_DEVICE_BLOCKED 3
83335
83336 - atomic_t iorequest_cnt;
83337 - atomic_t iodone_cnt;
83338 - atomic_t ioerr_cnt;
83339 + atomic_unchecked_t iorequest_cnt;
83340 + atomic_unchecked_t iodone_cnt;
83341 + atomic_unchecked_t ioerr_cnt;
83342
83343 struct device sdev_gendev,
83344 sdev_dev;
83345 diff --git a/include/scsi/scsi_transport_fc.h b/include/scsi/scsi_transport_fc.h
83346 index b797e8f..8e2c3aa 100644
83347 --- a/include/scsi/scsi_transport_fc.h
83348 +++ b/include/scsi/scsi_transport_fc.h
83349 @@ -751,7 +751,8 @@ struct fc_function_template {
83350 unsigned long show_host_system_hostname:1;
83351
83352 unsigned long disable_target_scan:1;
83353 -};
83354 +} __do_const;
83355 +typedef struct fc_function_template __no_const fc_function_template_no_const;
83356
83357
83358 /**
83359 diff --git a/include/sound/compress_driver.h b/include/sound/compress_driver.h
83360 index ae6c3b8..fd748ac 100644
83361 --- a/include/sound/compress_driver.h
83362 +++ b/include/sound/compress_driver.h
83363 @@ -128,7 +128,7 @@ struct snd_compr_ops {
83364 struct snd_compr_caps *caps);
83365 int (*get_codec_caps) (struct snd_compr_stream *stream,
83366 struct snd_compr_codec_caps *codec);
83367 -};
83368 +} __no_const;
83369
83370 /**
83371 * struct snd_compr: Compressed device
83372 diff --git a/include/sound/soc.h b/include/sound/soc.h
83373 index 1f741cb..8cefc08 100644
83374 --- a/include/sound/soc.h
83375 +++ b/include/sound/soc.h
83376 @@ -763,7 +763,7 @@ struct snd_soc_codec_driver {
83377 /* probe ordering - for components with runtime dependencies */
83378 int probe_order;
83379 int remove_order;
83380 -};
83381 +} __do_const;
83382
83383 /* SoC platform interface */
83384 struct snd_soc_platform_driver {
83385 @@ -809,7 +809,7 @@ struct snd_soc_platform_driver {
83386 unsigned int (*read)(struct snd_soc_platform *, unsigned int);
83387 int (*write)(struct snd_soc_platform *, unsigned int, unsigned int);
83388 int (*bespoke_trigger)(struct snd_pcm_substream *, int);
83389 -};
83390 +} __do_const;
83391
83392 struct snd_soc_platform {
83393 const char *name;
83394 diff --git a/include/target/target_core_base.h b/include/target/target_core_base.h
83395 index e3569f8..6544ffd 100644
83396 --- a/include/target/target_core_base.h
83397 +++ b/include/target/target_core_base.h
83398 @@ -687,7 +687,7 @@ struct se_device {
83399 atomic_long_t write_bytes;
83400 /* Active commands on this virtual SE device */
83401 atomic_t simple_cmds;
83402 - atomic_t dev_ordered_id;
83403 + atomic_unchecked_t dev_ordered_id;
83404 atomic_t dev_ordered_sync;
83405 atomic_t dev_qf_count;
83406 int export_count;
83407 diff --git a/include/trace/events/fs.h b/include/trace/events/fs.h
83408 new file mode 100644
83409 index 0000000..fb634b7
83410 --- /dev/null
83411 +++ b/include/trace/events/fs.h
83412 @@ -0,0 +1,53 @@
83413 +#undef TRACE_SYSTEM
83414 +#define TRACE_SYSTEM fs
83415 +
83416 +#if !defined(_TRACE_FS_H) || defined(TRACE_HEADER_MULTI_READ)
83417 +#define _TRACE_FS_H
83418 +
83419 +#include <linux/fs.h>
83420 +#include <linux/tracepoint.h>
83421 +
83422 +TRACE_EVENT(do_sys_open,
83423 +
83424 + TP_PROTO(const char *filename, int flags, int mode),
83425 +
83426 + TP_ARGS(filename, flags, mode),
83427 +
83428 + TP_STRUCT__entry(
83429 + __string( filename, filename )
83430 + __field( int, flags )
83431 + __field( int, mode )
83432 + ),
83433 +
83434 + TP_fast_assign(
83435 + __assign_str(filename, filename);
83436 + __entry->flags = flags;
83437 + __entry->mode = mode;
83438 + ),
83439 +
83440 + TP_printk("\"%s\" %x %o",
83441 + __get_str(filename), __entry->flags, __entry->mode)
83442 +);
83443 +
83444 +TRACE_EVENT(open_exec,
83445 +
83446 + TP_PROTO(const char *filename),
83447 +
83448 + TP_ARGS(filename),
83449 +
83450 + TP_STRUCT__entry(
83451 + __string( filename, filename )
83452 + ),
83453 +
83454 + TP_fast_assign(
83455 + __assign_str(filename, filename);
83456 + ),
83457 +
83458 + TP_printk("\"%s\"",
83459 + __get_str(filename))
83460 +);
83461 +
83462 +#endif /* _TRACE_FS_H */
83463 +
83464 +/* This part must be outside protection */
83465 +#include <trace/define_trace.h>
83466 diff --git a/include/trace/events/irq.h b/include/trace/events/irq.h
83467 index 1c09820..7f5ec79 100644
83468 --- a/include/trace/events/irq.h
83469 +++ b/include/trace/events/irq.h
83470 @@ -36,7 +36,7 @@ struct softirq_action;
83471 */
83472 TRACE_EVENT(irq_handler_entry,
83473
83474 - TP_PROTO(int irq, struct irqaction *action),
83475 + TP_PROTO(int irq, const struct irqaction *action),
83476
83477 TP_ARGS(irq, action),
83478
83479 @@ -66,7 +66,7 @@ TRACE_EVENT(irq_handler_entry,
83480 */
83481 TRACE_EVENT(irq_handler_exit,
83482
83483 - TP_PROTO(int irq, struct irqaction *action, int ret),
83484 + TP_PROTO(int irq, const struct irqaction *action, int ret),
83485
83486 TP_ARGS(irq, action, ret),
83487
83488 diff --git a/include/uapi/linux/a.out.h b/include/uapi/linux/a.out.h
83489 index 7caf44c..23c6f27 100644
83490 --- a/include/uapi/linux/a.out.h
83491 +++ b/include/uapi/linux/a.out.h
83492 @@ -39,6 +39,14 @@ enum machine_type {
83493 M_MIPS2 = 152 /* MIPS R6000/R4000 binary */
83494 };
83495
83496 +/* Constants for the N_FLAGS field */
83497 +#define F_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
83498 +#define F_PAX_EMUTRAMP 2 /* Emulate trampolines */
83499 +#define F_PAX_MPROTECT 4 /* Restrict mprotect() */
83500 +#define F_PAX_RANDMMAP 8 /* Randomize mmap() base */
83501 +/*#define F_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
83502 +#define F_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
83503 +
83504 #if !defined (N_MAGIC)
83505 #define N_MAGIC(exec) ((exec).a_info & 0xffff)
83506 #endif
83507 diff --git a/include/uapi/linux/bcache.h b/include/uapi/linux/bcache.h
83508 index 164a7e2..0f581a7 100644
83509 --- a/include/uapi/linux/bcache.h
83510 +++ b/include/uapi/linux/bcache.h
83511 @@ -5,6 +5,7 @@
83512 * Bcache on disk data structures
83513 */
83514
83515 +#include <linux/compiler.h>
83516 #include <asm/types.h>
83517
83518 #define BITMASK(name, type, field, offset, size) \
83519 @@ -20,8 +21,8 @@ static inline void SET_##name(type *k, __u64 v) \
83520 /* Btree keys - all units are in sectors */
83521
83522 struct bkey {
83523 - __u64 high;
83524 - __u64 low;
83525 + __u64 high __intentional_overflow(-1);
83526 + __u64 low __intentional_overflow(-1);
83527 __u64 ptr[];
83528 };
83529
83530 diff --git a/include/uapi/linux/byteorder/little_endian.h b/include/uapi/linux/byteorder/little_endian.h
83531 index d876736..ccce5c0 100644
83532 --- a/include/uapi/linux/byteorder/little_endian.h
83533 +++ b/include/uapi/linux/byteorder/little_endian.h
83534 @@ -42,51 +42,51 @@
83535
83536 static inline __le64 __cpu_to_le64p(const __u64 *p)
83537 {
83538 - return (__force __le64)*p;
83539 + return (__force const __le64)*p;
83540 }
83541 -static inline __u64 __le64_to_cpup(const __le64 *p)
83542 +static inline __u64 __intentional_overflow(-1) __le64_to_cpup(const __le64 *p)
83543 {
83544 - return (__force __u64)*p;
83545 + return (__force const __u64)*p;
83546 }
83547 static inline __le32 __cpu_to_le32p(const __u32 *p)
83548 {
83549 - return (__force __le32)*p;
83550 + return (__force const __le32)*p;
83551 }
83552 static inline __u32 __le32_to_cpup(const __le32 *p)
83553 {
83554 - return (__force __u32)*p;
83555 + return (__force const __u32)*p;
83556 }
83557 static inline __le16 __cpu_to_le16p(const __u16 *p)
83558 {
83559 - return (__force __le16)*p;
83560 + return (__force const __le16)*p;
83561 }
83562 static inline __u16 __le16_to_cpup(const __le16 *p)
83563 {
83564 - return (__force __u16)*p;
83565 + return (__force const __u16)*p;
83566 }
83567 static inline __be64 __cpu_to_be64p(const __u64 *p)
83568 {
83569 - return (__force __be64)__swab64p(p);
83570 + return (__force const __be64)__swab64p(p);
83571 }
83572 static inline __u64 __be64_to_cpup(const __be64 *p)
83573 {
83574 - return __swab64p((__u64 *)p);
83575 + return __swab64p((const __u64 *)p);
83576 }
83577 static inline __be32 __cpu_to_be32p(const __u32 *p)
83578 {
83579 - return (__force __be32)__swab32p(p);
83580 + return (__force const __be32)__swab32p(p);
83581 }
83582 -static inline __u32 __be32_to_cpup(const __be32 *p)
83583 +static inline __u32 __intentional_overflow(-1) __be32_to_cpup(const __be32 *p)
83584 {
83585 - return __swab32p((__u32 *)p);
83586 + return __swab32p((const __u32 *)p);
83587 }
83588 static inline __be16 __cpu_to_be16p(const __u16 *p)
83589 {
83590 - return (__force __be16)__swab16p(p);
83591 + return (__force const __be16)__swab16p(p);
83592 }
83593 static inline __u16 __be16_to_cpup(const __be16 *p)
83594 {
83595 - return __swab16p((__u16 *)p);
83596 + return __swab16p((const __u16 *)p);
83597 }
83598 #define __cpu_to_le64s(x) do { (void)(x); } while (0)
83599 #define __le64_to_cpus(x) do { (void)(x); } while (0)
83600 diff --git a/include/uapi/linux/elf.h b/include/uapi/linux/elf.h
83601 index ef6103b..d4e65dd 100644
83602 --- a/include/uapi/linux/elf.h
83603 +++ b/include/uapi/linux/elf.h
83604 @@ -37,6 +37,17 @@ typedef __s64 Elf64_Sxword;
83605 #define PT_GNU_EH_FRAME 0x6474e550
83606
83607 #define PT_GNU_STACK (PT_LOOS + 0x474e551)
83608 +#define PT_GNU_RELRO (PT_LOOS + 0x474e552)
83609 +
83610 +#define PT_PAX_FLAGS (PT_LOOS + 0x5041580)
83611 +
83612 +/* Constants for the e_flags field */
83613 +#define EF_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
83614 +#define EF_PAX_EMUTRAMP 2 /* Emulate trampolines */
83615 +#define EF_PAX_MPROTECT 4 /* Restrict mprotect() */
83616 +#define EF_PAX_RANDMMAP 8 /* Randomize mmap() base */
83617 +/*#define EF_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
83618 +#define EF_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
83619
83620 /*
83621 * Extended Numbering
83622 @@ -94,6 +105,8 @@ typedef __s64 Elf64_Sxword;
83623 #define DT_DEBUG 21
83624 #define DT_TEXTREL 22
83625 #define DT_JMPREL 23
83626 +#define DT_FLAGS 30
83627 + #define DF_TEXTREL 0x00000004
83628 #define DT_ENCODING 32
83629 #define OLD_DT_LOOS 0x60000000
83630 #define DT_LOOS 0x6000000d
83631 @@ -240,6 +253,19 @@ typedef struct elf64_hdr {
83632 #define PF_W 0x2
83633 #define PF_X 0x1
83634
83635 +#define PF_PAGEEXEC (1U << 4) /* Enable PAGEEXEC */
83636 +#define PF_NOPAGEEXEC (1U << 5) /* Disable PAGEEXEC */
83637 +#define PF_SEGMEXEC (1U << 6) /* Enable SEGMEXEC */
83638 +#define PF_NOSEGMEXEC (1U << 7) /* Disable SEGMEXEC */
83639 +#define PF_MPROTECT (1U << 8) /* Enable MPROTECT */
83640 +#define PF_NOMPROTECT (1U << 9) /* Disable MPROTECT */
83641 +/*#define PF_RANDEXEC (1U << 10)*/ /* Enable RANDEXEC */
83642 +/*#define PF_NORANDEXEC (1U << 11)*/ /* Disable RANDEXEC */
83643 +#define PF_EMUTRAMP (1U << 12) /* Enable EMUTRAMP */
83644 +#define PF_NOEMUTRAMP (1U << 13) /* Disable EMUTRAMP */
83645 +#define PF_RANDMMAP (1U << 14) /* Enable RANDMMAP */
83646 +#define PF_NORANDMMAP (1U << 15) /* Disable RANDMMAP */
83647 +
83648 typedef struct elf32_phdr{
83649 Elf32_Word p_type;
83650 Elf32_Off p_offset;
83651 @@ -332,6 +358,8 @@ typedef struct elf64_shdr {
83652 #define EI_OSABI 7
83653 #define EI_PAD 8
83654
83655 +#define EI_PAX 14
83656 +
83657 #define ELFMAG0 0x7f /* EI_MAG */
83658 #define ELFMAG1 'E'
83659 #define ELFMAG2 'L'
83660 diff --git a/include/uapi/linux/personality.h b/include/uapi/linux/personality.h
83661 index aa169c4..6a2771d 100644
83662 --- a/include/uapi/linux/personality.h
83663 +++ b/include/uapi/linux/personality.h
83664 @@ -30,6 +30,7 @@ enum {
83665 #define PER_CLEAR_ON_SETID (READ_IMPLIES_EXEC | \
83666 ADDR_NO_RANDOMIZE | \
83667 ADDR_COMPAT_LAYOUT | \
83668 + ADDR_LIMIT_3GB | \
83669 MMAP_PAGE_ZERO)
83670
83671 /*
83672 diff --git a/include/uapi/linux/screen_info.h b/include/uapi/linux/screen_info.h
83673 index 7530e74..e714828 100644
83674 --- a/include/uapi/linux/screen_info.h
83675 +++ b/include/uapi/linux/screen_info.h
83676 @@ -43,7 +43,8 @@ struct screen_info {
83677 __u16 pages; /* 0x32 */
83678 __u16 vesa_attributes; /* 0x34 */
83679 __u32 capabilities; /* 0x36 */
83680 - __u8 _reserved[6]; /* 0x3a */
83681 + __u16 vesapm_size; /* 0x3a */
83682 + __u8 _reserved[4]; /* 0x3c */
83683 } __attribute__((packed));
83684
83685 #define VIDEO_TYPE_MDA 0x10 /* Monochrome Text Display */
83686 diff --git a/include/uapi/linux/swab.h b/include/uapi/linux/swab.h
83687 index 0e011eb..82681b1 100644
83688 --- a/include/uapi/linux/swab.h
83689 +++ b/include/uapi/linux/swab.h
83690 @@ -43,7 +43,7 @@
83691 * ___swab16, ___swab32, ___swab64, ___swahw32, ___swahb32
83692 */
83693
83694 -static inline __attribute_const__ __u16 __fswab16(__u16 val)
83695 +static inline __intentional_overflow(-1) __attribute_const__ __u16 __fswab16(__u16 val)
83696 {
83697 #ifdef __HAVE_BUILTIN_BSWAP16__
83698 return __builtin_bswap16(val);
83699 @@ -54,7 +54,7 @@ static inline __attribute_const__ __u16 __fswab16(__u16 val)
83700 #endif
83701 }
83702
83703 -static inline __attribute_const__ __u32 __fswab32(__u32 val)
83704 +static inline __intentional_overflow(-1) __attribute_const__ __u32 __fswab32(__u32 val)
83705 {
83706 #ifdef __HAVE_BUILTIN_BSWAP32__
83707 return __builtin_bswap32(val);
83708 @@ -65,7 +65,7 @@ static inline __attribute_const__ __u32 __fswab32(__u32 val)
83709 #endif
83710 }
83711
83712 -static inline __attribute_const__ __u64 __fswab64(__u64 val)
83713 +static inline __intentional_overflow(-1) __attribute_const__ __u64 __fswab64(__u64 val)
83714 {
83715 #ifdef __HAVE_BUILTIN_BSWAP64__
83716 return __builtin_bswap64(val);
83717 diff --git a/include/uapi/linux/sysctl.h b/include/uapi/linux/sysctl.h
83718 index 6d67213..552fdd9 100644
83719 --- a/include/uapi/linux/sysctl.h
83720 +++ b/include/uapi/linux/sysctl.h
83721 @@ -155,8 +155,6 @@ enum
83722 KERN_PANIC_ON_NMI=76, /* int: whether we will panic on an unrecovered */
83723 };
83724
83725 -
83726 -
83727 /* CTL_VM names: */
83728 enum
83729 {
83730 diff --git a/include/uapi/linux/videodev2.h b/include/uapi/linux/videodev2.h
83731 index 437f1b0..0eeb38d 100644
83732 --- a/include/uapi/linux/videodev2.h
83733 +++ b/include/uapi/linux/videodev2.h
83734 @@ -1227,7 +1227,7 @@ struct v4l2_ext_control {
83735 union {
83736 __s32 value;
83737 __s64 value64;
83738 - char *string;
83739 + char __user *string;
83740 };
83741 } __attribute__ ((packed));
83742
83743 diff --git a/include/uapi/linux/xattr.h b/include/uapi/linux/xattr.h
83744 index e4629b9..6958086 100644
83745 --- a/include/uapi/linux/xattr.h
83746 +++ b/include/uapi/linux/xattr.h
83747 @@ -63,5 +63,9 @@
83748 #define XATTR_POSIX_ACL_DEFAULT "posix_acl_default"
83749 #define XATTR_NAME_POSIX_ACL_DEFAULT XATTR_SYSTEM_PREFIX XATTR_POSIX_ACL_DEFAULT
83750
83751 +/* User namespace */
83752 +#define XATTR_PAX_PREFIX XATTR_USER_PREFIX "pax."
83753 +#define XATTR_PAX_FLAGS_SUFFIX "flags"
83754 +#define XATTR_NAME_PAX_FLAGS XATTR_PAX_PREFIX XATTR_PAX_FLAGS_SUFFIX
83755
83756 #endif /* _UAPI_LINUX_XATTR_H */
83757 diff --git a/include/video/udlfb.h b/include/video/udlfb.h
83758 index f9466fa..f4e2b81 100644
83759 --- a/include/video/udlfb.h
83760 +++ b/include/video/udlfb.h
83761 @@ -53,10 +53,10 @@ struct dlfb_data {
83762 u32 pseudo_palette[256];
83763 int blank_mode; /*one of FB_BLANK_ */
83764 /* blit-only rendering path metrics, exposed through sysfs */
83765 - atomic_t bytes_rendered; /* raw pixel-bytes driver asked to render */
83766 - atomic_t bytes_identical; /* saved effort with backbuffer comparison */
83767 - atomic_t bytes_sent; /* to usb, after compression including overhead */
83768 - atomic_t cpu_kcycles_used; /* transpired during pixel processing */
83769 + atomic_unchecked_t bytes_rendered; /* raw pixel-bytes driver asked to render */
83770 + atomic_unchecked_t bytes_identical; /* saved effort with backbuffer comparison */
83771 + atomic_unchecked_t bytes_sent; /* to usb, after compression including overhead */
83772 + atomic_unchecked_t cpu_kcycles_used; /* transpired during pixel processing */
83773 };
83774
83775 #define NR_USB_REQUEST_I2C_SUB_IO 0x02
83776 diff --git a/include/video/uvesafb.h b/include/video/uvesafb.h
83777 index 30f5362..8ed8ac9 100644
83778 --- a/include/video/uvesafb.h
83779 +++ b/include/video/uvesafb.h
83780 @@ -122,6 +122,7 @@ struct uvesafb_par {
83781 u8 ypan; /* 0 - nothing, 1 - ypan, 2 - ywrap */
83782 u8 pmi_setpal; /* PMI for palette changes */
83783 u16 *pmi_base; /* protected mode interface location */
83784 + u8 *pmi_code; /* protected mode code location */
83785 void *pmi_start;
83786 void *pmi_pal;
83787 u8 *vbe_state_orig; /*
83788 diff --git a/init/Kconfig b/init/Kconfig
83789 index 66e6759..1333b01 100644
83790 --- a/init/Kconfig
83791 +++ b/init/Kconfig
83792 @@ -1079,6 +1079,7 @@ endif # CGROUPS
83793
83794 config CHECKPOINT_RESTORE
83795 bool "Checkpoint/restore support" if EXPERT
83796 + depends on !GRKERNSEC
83797 default n
83798 help
83799 Enables additional kernel features in a sake of checkpoint/restore.
83800 @@ -1557,7 +1558,7 @@ config SLUB_DEBUG
83801
83802 config COMPAT_BRK
83803 bool "Disable heap randomization"
83804 - default y
83805 + default n
83806 help
83807 Randomizing heap placement makes heap exploits harder, but it
83808 also breaks ancient binaries (including anything libc5 based).
83809 @@ -1845,7 +1846,7 @@ config INIT_ALL_POSSIBLE
83810 config STOP_MACHINE
83811 bool
83812 default y
83813 - depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU
83814 + depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU || GRKERNSEC
83815 help
83816 Need stop_machine() primitive.
83817
83818 diff --git a/init/Makefile b/init/Makefile
83819 index 7bc47ee..6da2dc7 100644
83820 --- a/init/Makefile
83821 +++ b/init/Makefile
83822 @@ -2,6 +2,9 @@
83823 # Makefile for the linux kernel.
83824 #
83825
83826 +ccflags-y := $(GCC_PLUGINS_CFLAGS)
83827 +asflags-y := $(GCC_PLUGINS_AFLAGS)
83828 +
83829 obj-y := main.o version.o mounts.o
83830 ifneq ($(CONFIG_BLK_DEV_INITRD),y)
83831 obj-y += noinitramfs.o
83832 diff --git a/init/do_mounts.c b/init/do_mounts.c
83833 index 8e5addc..c96ea61 100644
83834 --- a/init/do_mounts.c
83835 +++ b/init/do_mounts.c
83836 @@ -359,11 +359,11 @@ static void __init get_fs_names(char *page)
83837 static int __init do_mount_root(char *name, char *fs, int flags, void *data)
83838 {
83839 struct super_block *s;
83840 - int err = sys_mount(name, "/root", fs, flags, data);
83841 + int err = sys_mount((char __force_user *)name, (char __force_user *)"/root", (char __force_user *)fs, flags, (void __force_user *)data);
83842 if (err)
83843 return err;
83844
83845 - sys_chdir("/root");
83846 + sys_chdir((const char __force_user *)"/root");
83847 s = current->fs->pwd.dentry->d_sb;
83848 ROOT_DEV = s->s_dev;
83849 printk(KERN_INFO
83850 @@ -484,18 +484,18 @@ void __init change_floppy(char *fmt, ...)
83851 va_start(args, fmt);
83852 vsprintf(buf, fmt, args);
83853 va_end(args);
83854 - fd = sys_open("/dev/root", O_RDWR | O_NDELAY, 0);
83855 + fd = sys_open((char __user *)"/dev/root", O_RDWR | O_NDELAY, 0);
83856 if (fd >= 0) {
83857 sys_ioctl(fd, FDEJECT, 0);
83858 sys_close(fd);
83859 }
83860 printk(KERN_NOTICE "VFS: Insert %s and press ENTER\n", buf);
83861 - fd = sys_open("/dev/console", O_RDWR, 0);
83862 + fd = sys_open((__force const char __user *)"/dev/console", O_RDWR, 0);
83863 if (fd >= 0) {
83864 sys_ioctl(fd, TCGETS, (long)&termios);
83865 termios.c_lflag &= ~ICANON;
83866 sys_ioctl(fd, TCSETSF, (long)&termios);
83867 - sys_read(fd, &c, 1);
83868 + sys_read(fd, (char __user *)&c, 1);
83869 termios.c_lflag |= ICANON;
83870 sys_ioctl(fd, TCSETSF, (long)&termios);
83871 sys_close(fd);
83872 @@ -589,8 +589,8 @@ void __init prepare_namespace(void)
83873 mount_root();
83874 out:
83875 devtmpfs_mount("dev");
83876 - sys_mount(".", "/", NULL, MS_MOVE, NULL);
83877 - sys_chroot(".");
83878 + sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
83879 + sys_chroot((const char __force_user *)".");
83880 }
83881
83882 static bool is_tmpfs;
83883 diff --git a/init/do_mounts.h b/init/do_mounts.h
83884 index f5b978a..69dbfe8 100644
83885 --- a/init/do_mounts.h
83886 +++ b/init/do_mounts.h
83887 @@ -15,15 +15,15 @@ extern int root_mountflags;
83888
83889 static inline int create_dev(char *name, dev_t dev)
83890 {
83891 - sys_unlink(name);
83892 - return sys_mknod(name, S_IFBLK|0600, new_encode_dev(dev));
83893 + sys_unlink((char __force_user *)name);
83894 + return sys_mknod((char __force_user *)name, S_IFBLK|0600, new_encode_dev(dev));
83895 }
83896
83897 #if BITS_PER_LONG == 32
83898 static inline u32 bstat(char *name)
83899 {
83900 struct stat64 stat;
83901 - if (sys_stat64(name, &stat) != 0)
83902 + if (sys_stat64((char __force_user *)name, (struct stat64 __force_user *)&stat) != 0)
83903 return 0;
83904 if (!S_ISBLK(stat.st_mode))
83905 return 0;
83906 @@ -35,7 +35,7 @@ static inline u32 bstat(char *name)
83907 static inline u32 bstat(char *name)
83908 {
83909 struct stat stat;
83910 - if (sys_newstat(name, &stat) != 0)
83911 + if (sys_newstat((const char __force_user *)name, (struct stat __force_user *)&stat) != 0)
83912 return 0;
83913 if (!S_ISBLK(stat.st_mode))
83914 return 0;
83915 diff --git a/init/do_mounts_initrd.c b/init/do_mounts_initrd.c
83916 index 3e0878e..8a9d7a0 100644
83917 --- a/init/do_mounts_initrd.c
83918 +++ b/init/do_mounts_initrd.c
83919 @@ -37,13 +37,13 @@ static int init_linuxrc(struct subprocess_info *info, struct cred *new)
83920 {
83921 sys_unshare(CLONE_FS | CLONE_FILES);
83922 /* stdin/stdout/stderr for /linuxrc */
83923 - sys_open("/dev/console", O_RDWR, 0);
83924 + sys_open((const char __force_user *)"/dev/console", O_RDWR, 0);
83925 sys_dup(0);
83926 sys_dup(0);
83927 /* move initrd over / and chdir/chroot in initrd root */
83928 - sys_chdir("/root");
83929 - sys_mount(".", "/", NULL, MS_MOVE, NULL);
83930 - sys_chroot(".");
83931 + sys_chdir((const char __force_user *)"/root");
83932 + sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
83933 + sys_chroot((const char __force_user *)".");
83934 sys_setsid();
83935 return 0;
83936 }
83937 @@ -59,8 +59,8 @@ static void __init handle_initrd(void)
83938 create_dev("/dev/root.old", Root_RAM0);
83939 /* mount initrd on rootfs' /root */
83940 mount_block_root("/dev/root.old", root_mountflags & ~MS_RDONLY);
83941 - sys_mkdir("/old", 0700);
83942 - sys_chdir("/old");
83943 + sys_mkdir((const char __force_user *)"/old", 0700);
83944 + sys_chdir((const char __force_user *)"/old");
83945
83946 /* try loading default modules from initrd */
83947 load_default_modules();
83948 @@ -80,31 +80,31 @@ static void __init handle_initrd(void)
83949 current->flags &= ~PF_FREEZER_SKIP;
83950
83951 /* move initrd to rootfs' /old */
83952 - sys_mount("..", ".", NULL, MS_MOVE, NULL);
83953 + sys_mount((char __force_user *)"..", (char __force_user *)".", NULL, MS_MOVE, NULL);
83954 /* switch root and cwd back to / of rootfs */
83955 - sys_chroot("..");
83956 + sys_chroot((const char __force_user *)"..");
83957
83958 if (new_decode_dev(real_root_dev) == Root_RAM0) {
83959 - sys_chdir("/old");
83960 + sys_chdir((const char __force_user *)"/old");
83961 return;
83962 }
83963
83964 - sys_chdir("/");
83965 + sys_chdir((const char __force_user *)"/");
83966 ROOT_DEV = new_decode_dev(real_root_dev);
83967 mount_root();
83968
83969 printk(KERN_NOTICE "Trying to move old root to /initrd ... ");
83970 - error = sys_mount("/old", "/root/initrd", NULL, MS_MOVE, NULL);
83971 + error = sys_mount((char __force_user *)"/old", (char __force_user *)"/root/initrd", NULL, MS_MOVE, NULL);
83972 if (!error)
83973 printk("okay\n");
83974 else {
83975 - int fd = sys_open("/dev/root.old", O_RDWR, 0);
83976 + int fd = sys_open((const char __force_user *)"/dev/root.old", O_RDWR, 0);
83977 if (error == -ENOENT)
83978 printk("/initrd does not exist. Ignored.\n");
83979 else
83980 printk("failed\n");
83981 printk(KERN_NOTICE "Unmounting old root\n");
83982 - sys_umount("/old", MNT_DETACH);
83983 + sys_umount((char __force_user *)"/old", MNT_DETACH);
83984 printk(KERN_NOTICE "Trying to free ramdisk memory ... ");
83985 if (fd < 0) {
83986 error = fd;
83987 @@ -127,11 +127,11 @@ int __init initrd_load(void)
83988 * mounted in the normal path.
83989 */
83990 if (rd_load_image("/initrd.image") && ROOT_DEV != Root_RAM0) {
83991 - sys_unlink("/initrd.image");
83992 + sys_unlink((const char __force_user *)"/initrd.image");
83993 handle_initrd();
83994 return 1;
83995 }
83996 }
83997 - sys_unlink("/initrd.image");
83998 + sys_unlink((const char __force_user *)"/initrd.image");
83999 return 0;
84000 }
84001 diff --git a/init/do_mounts_md.c b/init/do_mounts_md.c
84002 index 8cb6db5..d729f50 100644
84003 --- a/init/do_mounts_md.c
84004 +++ b/init/do_mounts_md.c
84005 @@ -180,7 +180,7 @@ static void __init md_setup_drive(void)
84006 partitioned ? "_d" : "", minor,
84007 md_setup_args[ent].device_names);
84008
84009 - fd = sys_open(name, 0, 0);
84010 + fd = sys_open((char __force_user *)name, 0, 0);
84011 if (fd < 0) {
84012 printk(KERN_ERR "md: open failed - cannot start "
84013 "array %s\n", name);
84014 @@ -243,7 +243,7 @@ static void __init md_setup_drive(void)
84015 * array without it
84016 */
84017 sys_close(fd);
84018 - fd = sys_open(name, 0, 0);
84019 + fd = sys_open((char __force_user *)name, 0, 0);
84020 sys_ioctl(fd, BLKRRPART, 0);
84021 }
84022 sys_close(fd);
84023 @@ -293,7 +293,7 @@ static void __init autodetect_raid(void)
84024
84025 wait_for_device_probe();
84026
84027 - fd = sys_open("/dev/md0", 0, 0);
84028 + fd = sys_open((const char __force_user *) "/dev/md0", 0, 0);
84029 if (fd >= 0) {
84030 sys_ioctl(fd, RAID_AUTORUN, raid_autopart);
84031 sys_close(fd);
84032 diff --git a/init/init_task.c b/init/init_task.c
84033 index ba0a7f36..2bcf1d5 100644
84034 --- a/init/init_task.c
84035 +++ b/init/init_task.c
84036 @@ -22,5 +22,9 @@ EXPORT_SYMBOL(init_task);
84037 * Initial thread structure. Alignment of this is handled by a special
84038 * linker map entry.
84039 */
84040 +#ifdef CONFIG_X86
84041 +union thread_union init_thread_union __init_task_data;
84042 +#else
84043 union thread_union init_thread_union __init_task_data =
84044 { INIT_THREAD_INFO(init_task) };
84045 +#endif
84046 diff --git a/init/initramfs.c b/init/initramfs.c
84047 index a67ef9d..2d17ed9 100644
84048 --- a/init/initramfs.c
84049 +++ b/init/initramfs.c
84050 @@ -84,7 +84,7 @@ static void __init free_hash(void)
84051 }
84052 }
84053
84054 -static long __init do_utime(char *filename, time_t mtime)
84055 +static long __init do_utime(char __force_user *filename, time_t mtime)
84056 {
84057 struct timespec t[2];
84058
84059 @@ -119,7 +119,7 @@ static void __init dir_utime(void)
84060 struct dir_entry *de, *tmp;
84061 list_for_each_entry_safe(de, tmp, &dir_list, list) {
84062 list_del(&de->list);
84063 - do_utime(de->name, de->mtime);
84064 + do_utime((char __force_user *)de->name, de->mtime);
84065 kfree(de->name);
84066 kfree(de);
84067 }
84068 @@ -281,7 +281,7 @@ static int __init maybe_link(void)
84069 if (nlink >= 2) {
84070 char *old = find_link(major, minor, ino, mode, collected);
84071 if (old)
84072 - return (sys_link(old, collected) < 0) ? -1 : 1;
84073 + return (sys_link((char __force_user *)old, (char __force_user *)collected) < 0) ? -1 : 1;
84074 }
84075 return 0;
84076 }
84077 @@ -290,11 +290,11 @@ static void __init clean_path(char *path, umode_t mode)
84078 {
84079 struct stat st;
84080
84081 - if (!sys_newlstat(path, &st) && (st.st_mode^mode) & S_IFMT) {
84082 + if (!sys_newlstat((char __force_user *)path, (struct stat __force_user *)&st) && (st.st_mode^mode) & S_IFMT) {
84083 if (S_ISDIR(st.st_mode))
84084 - sys_rmdir(path);
84085 + sys_rmdir((char __force_user *)path);
84086 else
84087 - sys_unlink(path);
84088 + sys_unlink((char __force_user *)path);
84089 }
84090 }
84091
84092 @@ -315,7 +315,7 @@ static int __init do_name(void)
84093 int openflags = O_WRONLY|O_CREAT;
84094 if (ml != 1)
84095 openflags |= O_TRUNC;
84096 - wfd = sys_open(collected, openflags, mode);
84097 + wfd = sys_open((char __force_user *)collected, openflags, mode);
84098
84099 if (wfd >= 0) {
84100 sys_fchown(wfd, uid, gid);
84101 @@ -327,17 +327,17 @@ static int __init do_name(void)
84102 }
84103 }
84104 } else if (S_ISDIR(mode)) {
84105 - sys_mkdir(collected, mode);
84106 - sys_chown(collected, uid, gid);
84107 - sys_chmod(collected, mode);
84108 + sys_mkdir((char __force_user *)collected, mode);
84109 + sys_chown((char __force_user *)collected, uid, gid);
84110 + sys_chmod((char __force_user *)collected, mode);
84111 dir_add(collected, mtime);
84112 } else if (S_ISBLK(mode) || S_ISCHR(mode) ||
84113 S_ISFIFO(mode) || S_ISSOCK(mode)) {
84114 if (maybe_link() == 0) {
84115 - sys_mknod(collected, mode, rdev);
84116 - sys_chown(collected, uid, gid);
84117 - sys_chmod(collected, mode);
84118 - do_utime(collected, mtime);
84119 + sys_mknod((char __force_user *)collected, mode, rdev);
84120 + sys_chown((char __force_user *)collected, uid, gid);
84121 + sys_chmod((char __force_user *)collected, mode);
84122 + do_utime((char __force_user *)collected, mtime);
84123 }
84124 }
84125 return 0;
84126 @@ -346,15 +346,15 @@ static int __init do_name(void)
84127 static int __init do_copy(void)
84128 {
84129 if (count >= body_len) {
84130 - sys_write(wfd, victim, body_len);
84131 + sys_write(wfd, (char __force_user *)victim, body_len);
84132 sys_close(wfd);
84133 - do_utime(vcollected, mtime);
84134 + do_utime((char __force_user *)vcollected, mtime);
84135 kfree(vcollected);
84136 eat(body_len);
84137 state = SkipIt;
84138 return 0;
84139 } else {
84140 - sys_write(wfd, victim, count);
84141 + sys_write(wfd, (char __force_user *)victim, count);
84142 body_len -= count;
84143 eat(count);
84144 return 1;
84145 @@ -365,9 +365,9 @@ static int __init do_symlink(void)
84146 {
84147 collected[N_ALIGN(name_len) + body_len] = '\0';
84148 clean_path(collected, 0);
84149 - sys_symlink(collected + N_ALIGN(name_len), collected);
84150 - sys_lchown(collected, uid, gid);
84151 - do_utime(collected, mtime);
84152 + sys_symlink((char __force_user *)collected + N_ALIGN(name_len), (char __force_user *)collected);
84153 + sys_lchown((char __force_user *)collected, uid, gid);
84154 + do_utime((char __force_user *)collected, mtime);
84155 state = SkipIt;
84156 next_state = Reset;
84157 return 0;
84158 @@ -583,7 +583,7 @@ static int __init populate_rootfs(void)
84159 {
84160 char *err = unpack_to_rootfs(__initramfs_start, __initramfs_size);
84161 if (err)
84162 - panic(err); /* Failed to decompress INTERNAL initramfs */
84163 + panic("%s", err); /* Failed to decompress INTERNAL initramfs */
84164 if (initrd_start) {
84165 #ifdef CONFIG_BLK_DEV_RAM
84166 int fd;
84167 diff --git a/init/main.c b/init/main.c
84168 index febc511..f0851763 100644
84169 --- a/init/main.c
84170 +++ b/init/main.c
84171 @@ -103,6 +103,8 @@ static inline void mark_rodata_ro(void) { }
84172 extern void tc_init(void);
84173 #endif
84174
84175 +extern void grsecurity_init(void);
84176 +
84177 /*
84178 * Debug helper: via this flag we know that we are in 'early bootup code'
84179 * where only the boot processor is running with IRQ disabled. This means
84180 @@ -164,6 +166,75 @@ static int __init set_reset_devices(char *str)
84181
84182 __setup("reset_devices", set_reset_devices);
84183
84184 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
84185 +kgid_t grsec_proc_gid = KGIDT_INIT(CONFIG_GRKERNSEC_PROC_GID);
84186 +static int __init setup_grsec_proc_gid(char *str)
84187 +{
84188 + grsec_proc_gid = KGIDT_INIT(simple_strtol(str, NULL, 0));
84189 + return 1;
84190 +}
84191 +__setup("grsec_proc_gid=", setup_grsec_proc_gid);
84192 +#endif
84193 +
84194 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
84195 +unsigned long pax_user_shadow_base __read_only;
84196 +EXPORT_SYMBOL(pax_user_shadow_base);
84197 +extern char pax_enter_kernel_user[];
84198 +extern char pax_exit_kernel_user[];
84199 +#endif
84200 +
84201 +#if defined(CONFIG_X86) && defined(CONFIG_PAX_MEMORY_UDEREF)
84202 +static int __init setup_pax_nouderef(char *str)
84203 +{
84204 +#ifdef CONFIG_X86_32
84205 + unsigned int cpu;
84206 + struct desc_struct *gdt;
84207 +
84208 + for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
84209 + gdt = get_cpu_gdt_table(cpu);
84210 + gdt[GDT_ENTRY_KERNEL_DS].type = 3;
84211 + gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
84212 + gdt[GDT_ENTRY_DEFAULT_USER_CS].limit = 0xf;
84213 + gdt[GDT_ENTRY_DEFAULT_USER_DS].limit = 0xf;
84214 + }
84215 + loadsegment(ds, __KERNEL_DS);
84216 + loadsegment(es, __KERNEL_DS);
84217 + loadsegment(ss, __KERNEL_DS);
84218 +#else
84219 + memcpy(pax_enter_kernel_user, (unsigned char []){0xc3}, 1);
84220 + memcpy(pax_exit_kernel_user, (unsigned char []){0xc3}, 1);
84221 + clone_pgd_mask = ~(pgdval_t)0UL;
84222 + pax_user_shadow_base = 0UL;
84223 + setup_clear_cpu_cap(X86_FEATURE_PCID);
84224 + setup_clear_cpu_cap(X86_FEATURE_INVPCID);
84225 +#endif
84226 +
84227 + return 0;
84228 +}
84229 +early_param("pax_nouderef", setup_pax_nouderef);
84230 +
84231 +#ifdef CONFIG_X86_64
84232 +static int __init setup_pax_weakuderef(char *str)
84233 +{
84234 + if (clone_pgd_mask != ~(pgdval_t)0UL)
84235 + pax_user_shadow_base = 1UL << TASK_SIZE_MAX_SHIFT;
84236 + return 1;
84237 +}
84238 +__setup("pax_weakuderef", setup_pax_weakuderef);
84239 +#endif
84240 +#endif
84241 +
84242 +#ifdef CONFIG_PAX_SOFTMODE
84243 +int pax_softmode;
84244 +
84245 +static int __init setup_pax_softmode(char *str)
84246 +{
84247 + get_option(&str, &pax_softmode);
84248 + return 1;
84249 +}
84250 +__setup("pax_softmode=", setup_pax_softmode);
84251 +#endif
84252 +
84253 static const char * argv_init[MAX_INIT_ARGS+2] = { "init", NULL, };
84254 const char * envp_init[MAX_INIT_ENVS+2] = { "HOME=/", "TERM=linux", NULL, };
84255 static const char *panic_later, *panic_param;
84256 @@ -691,25 +762,24 @@ int __init_or_module do_one_initcall(initcall_t fn)
84257 {
84258 int count = preempt_count();
84259 int ret;
84260 - char msgbuf[64];
84261 + const char *msg1 = "", *msg2 = "";
84262
84263 if (initcall_debug)
84264 ret = do_one_initcall_debug(fn);
84265 else
84266 ret = fn();
84267
84268 - msgbuf[0] = 0;
84269 -
84270 if (preempt_count() != count) {
84271 - sprintf(msgbuf, "preemption imbalance ");
84272 + msg1 = " preemption imbalance";
84273 preempt_count_set(count);
84274 }
84275 if (irqs_disabled()) {
84276 - strlcat(msgbuf, "disabled interrupts ", sizeof(msgbuf));
84277 + msg2 = " disabled interrupts";
84278 local_irq_enable();
84279 }
84280 - WARN(msgbuf[0], "initcall %pF returned with %s\n", fn, msgbuf);
84281 + WARN(*msg1 || *msg2, "initcall %pF returned with%s%s\n", fn, msg1, msg2);
84282
84283 + add_latent_entropy();
84284 return ret;
84285 }
84286
84287 @@ -816,8 +886,8 @@ static int run_init_process(const char *init_filename)
84288 {
84289 argv_init[0] = init_filename;
84290 return do_execve(init_filename,
84291 - (const char __user *const __user *)argv_init,
84292 - (const char __user *const __user *)envp_init);
84293 + (const char __user *const __force_user *)argv_init,
84294 + (const char __user *const __force_user *)envp_init);
84295 }
84296
84297 static int try_to_run_init_process(const char *init_filename)
84298 @@ -834,6 +904,10 @@ static int try_to_run_init_process(const char *init_filename)
84299 return ret;
84300 }
84301
84302 +#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
84303 +extern int gr_init_ran;
84304 +#endif
84305 +
84306 static noinline void __init kernel_init_freeable(void);
84307
84308 static int __ref kernel_init(void *unused)
84309 @@ -858,6 +932,11 @@ static int __ref kernel_init(void *unused)
84310 ramdisk_execute_command, ret);
84311 }
84312
84313 +#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
84314 + /* if no initrd was used, be extra sure we enforce chroot restrictions */
84315 + gr_init_ran = 1;
84316 +#endif
84317 +
84318 /*
84319 * We try each of these until one succeeds.
84320 *
84321 @@ -913,7 +992,7 @@ static noinline void __init kernel_init_freeable(void)
84322 do_basic_setup();
84323
84324 /* Open the /dev/console on the rootfs, this should never fail */
84325 - if (sys_open((const char __user *) "/dev/console", O_RDWR, 0) < 0)
84326 + if (sys_open((const char __force_user *) "/dev/console", O_RDWR, 0) < 0)
84327 pr_err("Warning: unable to open an initial console.\n");
84328
84329 (void) sys_dup(0);
84330 @@ -926,11 +1005,13 @@ static noinline void __init kernel_init_freeable(void)
84331 if (!ramdisk_execute_command)
84332 ramdisk_execute_command = "/init";
84333
84334 - if (sys_access((const char __user *) ramdisk_execute_command, 0) != 0) {
84335 + if (sys_access((const char __force_user *) ramdisk_execute_command, 0) != 0) {
84336 ramdisk_execute_command = NULL;
84337 prepare_namespace();
84338 }
84339
84340 + grsecurity_init();
84341 +
84342 /*
84343 * Ok, we have completed the initial bootup, and
84344 * we're essentially up and running. Get rid of the
84345 diff --git a/ipc/compat.c b/ipc/compat.c
84346 index 892f658..e7c6320 100644
84347 --- a/ipc/compat.c
84348 +++ b/ipc/compat.c
84349 @@ -399,7 +399,7 @@ COMPAT_SYSCALL_DEFINE6(ipc, u32, call, int, first, int, second,
84350 COMPAT_SHMLBA);
84351 if (err < 0)
84352 return err;
84353 - return put_user(raddr, (compat_ulong_t *)compat_ptr(third));
84354 + return put_user(raddr, (compat_ulong_t __user *)compat_ptr(third));
84355 }
84356 case SHMDT:
84357 return sys_shmdt(compat_ptr(ptr));
84358 diff --git a/ipc/ipc_sysctl.c b/ipc/ipc_sysctl.c
84359 index b0e99de..09f385c 100644
84360 --- a/ipc/ipc_sysctl.c
84361 +++ b/ipc/ipc_sysctl.c
84362 @@ -30,7 +30,7 @@ static void *get_ipc(ctl_table *table)
84363 static int proc_ipc_dointvec(ctl_table *table, int write,
84364 void __user *buffer, size_t *lenp, loff_t *ppos)
84365 {
84366 - struct ctl_table ipc_table;
84367 + ctl_table_no_const ipc_table;
84368
84369 memcpy(&ipc_table, table, sizeof(ipc_table));
84370 ipc_table.data = get_ipc(table);
84371 @@ -41,7 +41,7 @@ static int proc_ipc_dointvec(ctl_table *table, int write,
84372 static int proc_ipc_dointvec_minmax(ctl_table *table, int write,
84373 void __user *buffer, size_t *lenp, loff_t *ppos)
84374 {
84375 - struct ctl_table ipc_table;
84376 + ctl_table_no_const ipc_table;
84377
84378 memcpy(&ipc_table, table, sizeof(ipc_table));
84379 ipc_table.data = get_ipc(table);
84380 @@ -65,7 +65,7 @@ static int proc_ipc_dointvec_minmax_orphans(ctl_table *table, int write,
84381 static int proc_ipc_callback_dointvec_minmax(ctl_table *table, int write,
84382 void __user *buffer, size_t *lenp, loff_t *ppos)
84383 {
84384 - struct ctl_table ipc_table;
84385 + ctl_table_no_const ipc_table;
84386 size_t lenp_bef = *lenp;
84387 int rc;
84388
84389 @@ -88,7 +88,7 @@ static int proc_ipc_callback_dointvec_minmax(ctl_table *table, int write,
84390 static int proc_ipc_doulongvec_minmax(ctl_table *table, int write,
84391 void __user *buffer, size_t *lenp, loff_t *ppos)
84392 {
84393 - struct ctl_table ipc_table;
84394 + ctl_table_no_const ipc_table;
84395 memcpy(&ipc_table, table, sizeof(ipc_table));
84396 ipc_table.data = get_ipc(table);
84397
84398 @@ -122,7 +122,7 @@ static void ipc_auto_callback(int val)
84399 static int proc_ipcauto_dointvec_minmax(ctl_table *table, int write,
84400 void __user *buffer, size_t *lenp, loff_t *ppos)
84401 {
84402 - struct ctl_table ipc_table;
84403 + ctl_table_no_const ipc_table;
84404 size_t lenp_bef = *lenp;
84405 int oldval;
84406 int rc;
84407 diff --git a/ipc/mq_sysctl.c b/ipc/mq_sysctl.c
84408 index 5bb8bfe..a38ec05 100644
84409 --- a/ipc/mq_sysctl.c
84410 +++ b/ipc/mq_sysctl.c
84411 @@ -25,7 +25,7 @@ static void *get_mq(ctl_table *table)
84412 static int proc_mq_dointvec(ctl_table *table, int write,
84413 void __user *buffer, size_t *lenp, loff_t *ppos)
84414 {
84415 - struct ctl_table mq_table;
84416 + ctl_table_no_const mq_table;
84417 memcpy(&mq_table, table, sizeof(mq_table));
84418 mq_table.data = get_mq(table);
84419
84420 @@ -35,7 +35,7 @@ static int proc_mq_dointvec(ctl_table *table, int write,
84421 static int proc_mq_dointvec_minmax(ctl_table *table, int write,
84422 void __user *buffer, size_t *lenp, loff_t *ppos)
84423 {
84424 - struct ctl_table mq_table;
84425 + ctl_table_no_const mq_table;
84426 memcpy(&mq_table, table, sizeof(mq_table));
84427 mq_table.data = get_mq(table);
84428
84429 diff --git a/ipc/mqueue.c b/ipc/mqueue.c
84430 index b8d4aed..96a4fe8 100644
84431 --- a/ipc/mqueue.c
84432 +++ b/ipc/mqueue.c
84433 @@ -278,6 +278,7 @@ static struct inode *mqueue_get_inode(struct super_block *sb,
84434 mq_bytes = mq_treesize + (info->attr.mq_maxmsg *
84435 info->attr.mq_msgsize);
84436
84437 + gr_learn_resource(current, RLIMIT_MSGQUEUE, u->mq_bytes + mq_bytes, 1);
84438 spin_lock(&mq_lock);
84439 if (u->mq_bytes + mq_bytes < u->mq_bytes ||
84440 u->mq_bytes + mq_bytes > rlimit(RLIMIT_MSGQUEUE)) {
84441 diff --git a/ipc/msg.c b/ipc/msg.c
84442 index 52770bf..1c60a6f 100644
84443 --- a/ipc/msg.c
84444 +++ b/ipc/msg.c
84445 @@ -297,18 +297,19 @@ static inline int msg_security(struct kern_ipc_perm *ipcp, int msgflg)
84446 return security_msg_queue_associate(msq, msgflg);
84447 }
84448
84449 +static struct ipc_ops msg_ops = {
84450 + .getnew = newque,
84451 + .associate = msg_security,
84452 + .more_checks = NULL
84453 +};
84454 +
84455 SYSCALL_DEFINE2(msgget, key_t, key, int, msgflg)
84456 {
84457 struct ipc_namespace *ns;
84458 - struct ipc_ops msg_ops;
84459 struct ipc_params msg_params;
84460
84461 ns = current->nsproxy->ipc_ns;
84462
84463 - msg_ops.getnew = newque;
84464 - msg_ops.associate = msg_security;
84465 - msg_ops.more_checks = NULL;
84466 -
84467 msg_params.key = key;
84468 msg_params.flg = msgflg;
84469
84470 diff --git a/ipc/sem.c b/ipc/sem.c
84471 index db9d241..bc8427c 100644
84472 --- a/ipc/sem.c
84473 +++ b/ipc/sem.c
84474 @@ -562,10 +562,15 @@ static inline int sem_more_checks(struct kern_ipc_perm *ipcp,
84475 return 0;
84476 }
84477
84478 +static struct ipc_ops sem_ops = {
84479 + .getnew = newary,
84480 + .associate = sem_security,
84481 + .more_checks = sem_more_checks
84482 +};
84483 +
84484 SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
84485 {
84486 struct ipc_namespace *ns;
84487 - struct ipc_ops sem_ops;
84488 struct ipc_params sem_params;
84489
84490 ns = current->nsproxy->ipc_ns;
84491 @@ -573,10 +578,6 @@ SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
84492 if (nsems < 0 || nsems > ns->sc_semmsl)
84493 return -EINVAL;
84494
84495 - sem_ops.getnew = newary;
84496 - sem_ops.associate = sem_security;
84497 - sem_ops.more_checks = sem_more_checks;
84498 -
84499 sem_params.key = key;
84500 sem_params.flg = semflg;
84501 sem_params.u.nsems = nsems;
84502 diff --git a/ipc/shm.c b/ipc/shm.c
84503 index 7a51443..3a257d8 100644
84504 --- a/ipc/shm.c
84505 +++ b/ipc/shm.c
84506 @@ -72,6 +72,14 @@ static void shm_destroy (struct ipc_namespace *ns, struct shmid_kernel *shp);
84507 static int sysvipc_shm_proc_show(struct seq_file *s, void *it);
84508 #endif
84509
84510 +#ifdef CONFIG_GRKERNSEC
84511 +extern int gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
84512 + const time_t shm_createtime, const kuid_t cuid,
84513 + const int shmid);
84514 +extern int gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
84515 + const time_t shm_createtime);
84516 +#endif
84517 +
84518 void shm_init_ns(struct ipc_namespace *ns)
84519 {
84520 ns->shm_ctlmax = SHMMAX;
84521 @@ -554,6 +562,14 @@ static int newseg(struct ipc_namespace *ns, struct ipc_params *params)
84522 shp->shm_lprid = 0;
84523 shp->shm_atim = shp->shm_dtim = 0;
84524 shp->shm_ctim = get_seconds();
84525 +#ifdef CONFIG_GRKERNSEC
84526 + {
84527 + struct timespec timeval;
84528 + do_posix_clock_monotonic_gettime(&timeval);
84529 +
84530 + shp->shm_createtime = timeval.tv_sec;
84531 + }
84532 +#endif
84533 shp->shm_segsz = size;
84534 shp->shm_nattch = 0;
84535 shp->shm_file = file;
84536 @@ -607,18 +623,19 @@ static inline int shm_more_checks(struct kern_ipc_perm *ipcp,
84537 return 0;
84538 }
84539
84540 +static struct ipc_ops shm_ops = {
84541 + .getnew = newseg,
84542 + .associate = shm_security,
84543 + .more_checks = shm_more_checks
84544 +};
84545 +
84546 SYSCALL_DEFINE3(shmget, key_t, key, size_t, size, int, shmflg)
84547 {
84548 struct ipc_namespace *ns;
84549 - struct ipc_ops shm_ops;
84550 struct ipc_params shm_params;
84551
84552 ns = current->nsproxy->ipc_ns;
84553
84554 - shm_ops.getnew = newseg;
84555 - shm_ops.associate = shm_security;
84556 - shm_ops.more_checks = shm_more_checks;
84557 -
84558 shm_params.key = key;
84559 shm_params.flg = shmflg;
84560 shm_params.u.size = size;
84561 @@ -1089,6 +1106,12 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
84562 f_mode = FMODE_READ | FMODE_WRITE;
84563 }
84564 if (shmflg & SHM_EXEC) {
84565 +
84566 +#ifdef CONFIG_PAX_MPROTECT
84567 + if (current->mm->pax_flags & MF_PAX_MPROTECT)
84568 + goto out;
84569 +#endif
84570 +
84571 prot |= PROT_EXEC;
84572 acc_mode |= S_IXUGO;
84573 }
84574 @@ -1113,6 +1136,15 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
84575 if (err)
84576 goto out_unlock;
84577
84578 +#ifdef CONFIG_GRKERNSEC
84579 + if (!gr_handle_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime,
84580 + shp->shm_perm.cuid, shmid) ||
84581 + !gr_chroot_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime)) {
84582 + err = -EACCES;
84583 + goto out_unlock;
84584 + }
84585 +#endif
84586 +
84587 ipc_lock_object(&shp->shm_perm);
84588
84589 /* check if shm_destroy() is tearing down shp */
84590 @@ -1125,6 +1157,9 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
84591 path = shp->shm_file->f_path;
84592 path_get(&path);
84593 shp->shm_nattch++;
84594 +#ifdef CONFIG_GRKERNSEC
84595 + shp->shm_lapid = current->pid;
84596 +#endif
84597 size = i_size_read(path.dentry->d_inode);
84598 ipc_unlock_object(&shp->shm_perm);
84599 rcu_read_unlock();
84600 diff --git a/ipc/util.c b/ipc/util.c
84601 index 3ae17a4..d67c32f 100644
84602 --- a/ipc/util.c
84603 +++ b/ipc/util.c
84604 @@ -71,6 +71,8 @@ struct ipc_proc_iface {
84605 int (*show)(struct seq_file *, void *);
84606 };
84607
84608 +extern int gr_ipc_permitted(struct ipc_namespace *ns, struct kern_ipc_perm *ipcp, int requested_mode, int granted_mode);
84609 +
84610 static void ipc_memory_notifier(struct work_struct *work)
84611 {
84612 ipcns_notify(IPCNS_MEMCHANGED);
84613 @@ -558,6 +560,10 @@ int ipcperms(struct ipc_namespace *ns, struct kern_ipc_perm *ipcp, short flag)
84614 granted_mode >>= 6;
84615 else if (in_group_p(ipcp->cgid) || in_group_p(ipcp->gid))
84616 granted_mode >>= 3;
84617 +
84618 + if (!gr_ipc_permitted(ns, ipcp, requested_mode, granted_mode))
84619 + return -1;
84620 +
84621 /* is there some bit set in requested_mode but not in granted_mode? */
84622 if ((requested_mode & ~granted_mode & 0007) &&
84623 !ns_capable(ns->user_ns, CAP_IPC_OWNER))
84624 diff --git a/kernel/acct.c b/kernel/acct.c
84625 index 8d6e145..33e0b1e 100644
84626 --- a/kernel/acct.c
84627 +++ b/kernel/acct.c
84628 @@ -556,7 +556,7 @@ static void do_acct_process(struct bsd_acct_struct *acct,
84629 */
84630 flim = current->signal->rlim[RLIMIT_FSIZE].rlim_cur;
84631 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = RLIM_INFINITY;
84632 - file->f_op->write(file, (char *)&ac,
84633 + file->f_op->write(file, (char __force_user *)&ac,
84634 sizeof(acct_t), &file->f_pos);
84635 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = flim;
84636 set_fs(fs);
84637 diff --git a/kernel/audit.c b/kernel/audit.c
84638 index 15ec13a..986322e 100644
84639 --- a/kernel/audit.c
84640 +++ b/kernel/audit.c
84641 @@ -118,7 +118,7 @@ u32 audit_sig_sid = 0;
84642 3) suppressed due to audit_rate_limit
84643 4) suppressed due to audit_backlog_limit
84644 */
84645 -static atomic_t audit_lost = ATOMIC_INIT(0);
84646 +static atomic_unchecked_t audit_lost = ATOMIC_INIT(0);
84647
84648 /* The netlink socket. */
84649 static struct sock *audit_sock;
84650 @@ -251,7 +251,7 @@ void audit_log_lost(const char *message)
84651 unsigned long now;
84652 int print;
84653
84654 - atomic_inc(&audit_lost);
84655 + atomic_inc_unchecked(&audit_lost);
84656
84657 print = (audit_failure == AUDIT_FAIL_PANIC || !audit_rate_limit);
84658
84659 @@ -270,7 +270,7 @@ void audit_log_lost(const char *message)
84660 printk(KERN_WARNING
84661 "audit: audit_lost=%d audit_rate_limit=%d "
84662 "audit_backlog_limit=%d\n",
84663 - atomic_read(&audit_lost),
84664 + atomic_read_unchecked(&audit_lost),
84665 audit_rate_limit,
84666 audit_backlog_limit);
84667 audit_panic(message);
84668 @@ -766,7 +766,7 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
84669 status_set.pid = audit_pid;
84670 status_set.rate_limit = audit_rate_limit;
84671 status_set.backlog_limit = audit_backlog_limit;
84672 - status_set.lost = atomic_read(&audit_lost);
84673 + status_set.lost = atomic_read_unchecked(&audit_lost);
84674 status_set.backlog = skb_queue_len(&audit_skb_queue);
84675 audit_send_reply(NETLINK_CB(skb).portid, seq, AUDIT_GET, 0, 0,
84676 &status_set, sizeof(status_set));
84677 @@ -1359,7 +1359,7 @@ void audit_log_n_hex(struct audit_buffer *ab, const unsigned char *buf,
84678 int i, avail, new_len;
84679 unsigned char *ptr;
84680 struct sk_buff *skb;
84681 - static const unsigned char *hex = "0123456789ABCDEF";
84682 + static const unsigned char hex[] = "0123456789ABCDEF";
84683
84684 if (!ab)
84685 return;
84686 diff --git a/kernel/auditsc.c b/kernel/auditsc.c
84687 index ff32843..27fc708 100644
84688 --- a/kernel/auditsc.c
84689 +++ b/kernel/auditsc.c
84690 @@ -1945,7 +1945,7 @@ int auditsc_get_stamp(struct audit_context *ctx,
84691 }
84692
84693 /* global counter which is incremented every time something logs in */
84694 -static atomic_t session_id = ATOMIC_INIT(0);
84695 +static atomic_unchecked_t session_id = ATOMIC_INIT(0);
84696
84697 static int audit_set_loginuid_perm(kuid_t loginuid)
84698 {
84699 @@ -2011,7 +2011,7 @@ int audit_set_loginuid(kuid_t loginuid)
84700
84701 /* are we setting or clearing? */
84702 if (uid_valid(loginuid))
84703 - sessionid = atomic_inc_return(&session_id);
84704 + sessionid = atomic_inc_return_unchecked(&session_id);
84705
84706 task->sessionid = sessionid;
84707 task->loginuid = loginuid;
84708 diff --git a/kernel/capability.c b/kernel/capability.c
84709 index 4e66bf9..cdccecf 100644
84710 --- a/kernel/capability.c
84711 +++ b/kernel/capability.c
84712 @@ -202,6 +202,9 @@ SYSCALL_DEFINE2(capget, cap_user_header_t, header, cap_user_data_t, dataptr)
84713 * before modification is attempted and the application
84714 * fails.
84715 */
84716 + if (tocopy > ARRAY_SIZE(kdata))
84717 + return -EFAULT;
84718 +
84719 if (copy_to_user(dataptr, kdata, tocopy
84720 * sizeof(struct __user_cap_data_struct))) {
84721 return -EFAULT;
84722 @@ -303,10 +306,11 @@ bool has_ns_capability(struct task_struct *t,
84723 int ret;
84724
84725 rcu_read_lock();
84726 - ret = security_capable(__task_cred(t), ns, cap);
84727 + ret = security_capable(__task_cred(t), ns, cap) == 0 &&
84728 + gr_task_is_capable(t, __task_cred(t), cap);
84729 rcu_read_unlock();
84730
84731 - return (ret == 0);
84732 + return ret;
84733 }
84734
84735 /**
84736 @@ -343,10 +347,10 @@ bool has_ns_capability_noaudit(struct task_struct *t,
84737 int ret;
84738
84739 rcu_read_lock();
84740 - ret = security_capable_noaudit(__task_cred(t), ns, cap);
84741 + ret = security_capable_noaudit(__task_cred(t), ns, cap) == 0 && gr_task_is_capable_nolog(t, cap);
84742 rcu_read_unlock();
84743
84744 - return (ret == 0);
84745 + return ret;
84746 }
84747
84748 /**
84749 @@ -384,7 +388,7 @@ bool ns_capable(struct user_namespace *ns, int cap)
84750 BUG();
84751 }
84752
84753 - if (security_capable(current_cred(), ns, cap) == 0) {
84754 + if (security_capable(current_cred(), ns, cap) == 0 && gr_is_capable(cap)) {
84755 current->flags |= PF_SUPERPRIV;
84756 return true;
84757 }
84758 @@ -392,6 +396,21 @@ bool ns_capable(struct user_namespace *ns, int cap)
84759 }
84760 EXPORT_SYMBOL(ns_capable);
84761
84762 +bool ns_capable_nolog(struct user_namespace *ns, int cap)
84763 +{
84764 + if (unlikely(!cap_valid(cap))) {
84765 + printk(KERN_CRIT "capable_nolog() called with invalid cap=%u\n", cap);
84766 + BUG();
84767 + }
84768 +
84769 + if (security_capable_noaudit(current_cred(), ns, cap) == 0 && gr_is_capable_nolog(cap)) {
84770 + current->flags |= PF_SUPERPRIV;
84771 + return true;
84772 + }
84773 + return false;
84774 +}
84775 +EXPORT_SYMBOL(ns_capable_nolog);
84776 +
84777 /**
84778 * file_ns_capable - Determine if the file's opener had a capability in effect
84779 * @file: The file we want to check
84780 @@ -432,6 +451,12 @@ bool capable(int cap)
84781 }
84782 EXPORT_SYMBOL(capable);
84783
84784 +bool capable_nolog(int cap)
84785 +{
84786 + return ns_capable_nolog(&init_user_ns, cap);
84787 +}
84788 +EXPORT_SYMBOL(capable_nolog);
84789 +
84790 /**
84791 * inode_capable - Check superior capability over inode
84792 * @inode: The inode in question
84793 @@ -453,3 +478,11 @@ bool inode_capable(const struct inode *inode, int cap)
84794 return ns_capable(ns, cap) && kuid_has_mapping(ns, inode->i_uid);
84795 }
84796 EXPORT_SYMBOL(inode_capable);
84797 +
84798 +bool inode_capable_nolog(const struct inode *inode, int cap)
84799 +{
84800 + struct user_namespace *ns = current_user_ns();
84801 +
84802 + return ns_capable_nolog(ns, cap) && kuid_has_mapping(ns, inode->i_uid);
84803 +}
84804 +EXPORT_SYMBOL(inode_capable_nolog);
84805 diff --git a/kernel/cgroup.c b/kernel/cgroup.c
84806 index b44dd49..94c2826 100644
84807 --- a/kernel/cgroup.c
84808 +++ b/kernel/cgroup.c
84809 @@ -5609,7 +5609,7 @@ static int cgroup_css_links_read(struct cgroup_subsys_state *css,
84810 struct css_set *cset = link->cset;
84811 struct task_struct *task;
84812 int count = 0;
84813 - seq_printf(seq, "css_set %p\n", cset);
84814 + seq_printf(seq, "css_set %pK\n", cset);
84815 list_for_each_entry(task, &cset->tasks, cg_list) {
84816 if (count++ > MAX_TASKS_SHOWN_PER_CSS) {
84817 seq_puts(seq, " ...\n");
84818 diff --git a/kernel/compat.c b/kernel/compat.c
84819 index 0a09e48..b46b3d78 100644
84820 --- a/kernel/compat.c
84821 +++ b/kernel/compat.c
84822 @@ -13,6 +13,7 @@
84823
84824 #include <linux/linkage.h>
84825 #include <linux/compat.h>
84826 +#include <linux/module.h>
84827 #include <linux/errno.h>
84828 #include <linux/time.h>
84829 #include <linux/signal.h>
84830 @@ -220,7 +221,7 @@ static long compat_nanosleep_restart(struct restart_block *restart)
84831 mm_segment_t oldfs;
84832 long ret;
84833
84834 - restart->nanosleep.rmtp = (struct timespec __user *) &rmt;
84835 + restart->nanosleep.rmtp = (struct timespec __force_user *) &rmt;
84836 oldfs = get_fs();
84837 set_fs(KERNEL_DS);
84838 ret = hrtimer_nanosleep_restart(restart);
84839 @@ -252,7 +253,7 @@ asmlinkage long compat_sys_nanosleep(struct compat_timespec __user *rqtp,
84840 oldfs = get_fs();
84841 set_fs(KERNEL_DS);
84842 ret = hrtimer_nanosleep(&tu,
84843 - rmtp ? (struct timespec __user *)&rmt : NULL,
84844 + rmtp ? (struct timespec __force_user *)&rmt : NULL,
84845 HRTIMER_MODE_REL, CLOCK_MONOTONIC);
84846 set_fs(oldfs);
84847
84848 @@ -361,7 +362,7 @@ asmlinkage long compat_sys_sigpending(compat_old_sigset_t __user *set)
84849 mm_segment_t old_fs = get_fs();
84850
84851 set_fs(KERNEL_DS);
84852 - ret = sys_sigpending((old_sigset_t __user *) &s);
84853 + ret = sys_sigpending((old_sigset_t __force_user *) &s);
84854 set_fs(old_fs);
84855 if (ret == 0)
84856 ret = put_user(s, set);
84857 @@ -451,7 +452,7 @@ asmlinkage long compat_sys_old_getrlimit(unsigned int resource,
84858 mm_segment_t old_fs = get_fs();
84859
84860 set_fs(KERNEL_DS);
84861 - ret = sys_old_getrlimit(resource, &r);
84862 + ret = sys_old_getrlimit(resource, (struct rlimit __force_user *)&r);
84863 set_fs(old_fs);
84864
84865 if (!ret) {
84866 @@ -533,8 +534,8 @@ COMPAT_SYSCALL_DEFINE4(wait4,
84867 set_fs (KERNEL_DS);
84868 ret = sys_wait4(pid,
84869 (stat_addr ?
84870 - (unsigned int __user *) &status : NULL),
84871 - options, (struct rusage __user *) &r);
84872 + (unsigned int __force_user *) &status : NULL),
84873 + options, (struct rusage __force_user *) &r);
84874 set_fs (old_fs);
84875
84876 if (ret > 0) {
84877 @@ -560,8 +561,8 @@ COMPAT_SYSCALL_DEFINE5(waitid,
84878 memset(&info, 0, sizeof(info));
84879
84880 set_fs(KERNEL_DS);
84881 - ret = sys_waitid(which, pid, (siginfo_t __user *)&info, options,
84882 - uru ? (struct rusage __user *)&ru : NULL);
84883 + ret = sys_waitid(which, pid, (siginfo_t __force_user *)&info, options,
84884 + uru ? (struct rusage __force_user *)&ru : NULL);
84885 set_fs(old_fs);
84886
84887 if ((ret < 0) || (info.si_signo == 0))
84888 @@ -695,8 +696,8 @@ long compat_sys_timer_settime(timer_t timer_id, int flags,
84889 oldfs = get_fs();
84890 set_fs(KERNEL_DS);
84891 err = sys_timer_settime(timer_id, flags,
84892 - (struct itimerspec __user *) &newts,
84893 - (struct itimerspec __user *) &oldts);
84894 + (struct itimerspec __force_user *) &newts,
84895 + (struct itimerspec __force_user *) &oldts);
84896 set_fs(oldfs);
84897 if (!err && old && put_compat_itimerspec(old, &oldts))
84898 return -EFAULT;
84899 @@ -713,7 +714,7 @@ long compat_sys_timer_gettime(timer_t timer_id,
84900 oldfs = get_fs();
84901 set_fs(KERNEL_DS);
84902 err = sys_timer_gettime(timer_id,
84903 - (struct itimerspec __user *) &ts);
84904 + (struct itimerspec __force_user *) &ts);
84905 set_fs(oldfs);
84906 if (!err && put_compat_itimerspec(setting, &ts))
84907 return -EFAULT;
84908 @@ -732,7 +733,7 @@ long compat_sys_clock_settime(clockid_t which_clock,
84909 oldfs = get_fs();
84910 set_fs(KERNEL_DS);
84911 err = sys_clock_settime(which_clock,
84912 - (struct timespec __user *) &ts);
84913 + (struct timespec __force_user *) &ts);
84914 set_fs(oldfs);
84915 return err;
84916 }
84917 @@ -747,7 +748,7 @@ long compat_sys_clock_gettime(clockid_t which_clock,
84918 oldfs = get_fs();
84919 set_fs(KERNEL_DS);
84920 err = sys_clock_gettime(which_clock,
84921 - (struct timespec __user *) &ts);
84922 + (struct timespec __force_user *) &ts);
84923 set_fs(oldfs);
84924 if (!err && put_compat_timespec(&ts, tp))
84925 return -EFAULT;
84926 @@ -767,7 +768,7 @@ long compat_sys_clock_adjtime(clockid_t which_clock,
84927
84928 oldfs = get_fs();
84929 set_fs(KERNEL_DS);
84930 - ret = sys_clock_adjtime(which_clock, (struct timex __user *) &txc);
84931 + ret = sys_clock_adjtime(which_clock, (struct timex __force_user *) &txc);
84932 set_fs(oldfs);
84933
84934 err = compat_put_timex(utp, &txc);
84935 @@ -787,7 +788,7 @@ long compat_sys_clock_getres(clockid_t which_clock,
84936 oldfs = get_fs();
84937 set_fs(KERNEL_DS);
84938 err = sys_clock_getres(which_clock,
84939 - (struct timespec __user *) &ts);
84940 + (struct timespec __force_user *) &ts);
84941 set_fs(oldfs);
84942 if (!err && tp && put_compat_timespec(&ts, tp))
84943 return -EFAULT;
84944 @@ -799,9 +800,9 @@ static long compat_clock_nanosleep_restart(struct restart_block *restart)
84945 long err;
84946 mm_segment_t oldfs;
84947 struct timespec tu;
84948 - struct compat_timespec *rmtp = restart->nanosleep.compat_rmtp;
84949 + struct compat_timespec __user *rmtp = restart->nanosleep.compat_rmtp;
84950
84951 - restart->nanosleep.rmtp = (struct timespec __user *) &tu;
84952 + restart->nanosleep.rmtp = (struct timespec __force_user *) &tu;
84953 oldfs = get_fs();
84954 set_fs(KERNEL_DS);
84955 err = clock_nanosleep_restart(restart);
84956 @@ -833,8 +834,8 @@ long compat_sys_clock_nanosleep(clockid_t which_clock, int flags,
84957 oldfs = get_fs();
84958 set_fs(KERNEL_DS);
84959 err = sys_clock_nanosleep(which_clock, flags,
84960 - (struct timespec __user *) &in,
84961 - (struct timespec __user *) &out);
84962 + (struct timespec __force_user *) &in,
84963 + (struct timespec __force_user *) &out);
84964 set_fs(oldfs);
84965
84966 if ((err == -ERESTART_RESTARTBLOCK) && rmtp &&
84967 @@ -1128,7 +1129,7 @@ COMPAT_SYSCALL_DEFINE2(sched_rr_get_interval,
84968 mm_segment_t old_fs = get_fs();
84969
84970 set_fs(KERNEL_DS);
84971 - ret = sys_sched_rr_get_interval(pid, (struct timespec __user *)&t);
84972 + ret = sys_sched_rr_get_interval(pid, (struct timespec __force_user *)&t);
84973 set_fs(old_fs);
84974 if (put_compat_timespec(&t, interval))
84975 return -EFAULT;
84976 diff --git a/kernel/configs.c b/kernel/configs.c
84977 index c18b1f1..b9a0132 100644
84978 --- a/kernel/configs.c
84979 +++ b/kernel/configs.c
84980 @@ -74,8 +74,19 @@ static int __init ikconfig_init(void)
84981 struct proc_dir_entry *entry;
84982
84983 /* create the current config file */
84984 +#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
84985 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_HIDESYM)
84986 + entry = proc_create("config.gz", S_IFREG | S_IRUSR, NULL,
84987 + &ikconfig_file_ops);
84988 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
84989 + entry = proc_create("config.gz", S_IFREG | S_IRUSR | S_IRGRP, NULL,
84990 + &ikconfig_file_ops);
84991 +#endif
84992 +#else
84993 entry = proc_create("config.gz", S_IFREG | S_IRUGO, NULL,
84994 &ikconfig_file_ops);
84995 +#endif
84996 +
84997 if (!entry)
84998 return -ENOMEM;
84999
85000 diff --git a/kernel/cred.c b/kernel/cred.c
85001 index e0573a4..3874e41 100644
85002 --- a/kernel/cred.c
85003 +++ b/kernel/cred.c
85004 @@ -164,6 +164,16 @@ void exit_creds(struct task_struct *tsk)
85005 validate_creds(cred);
85006 alter_cred_subscribers(cred, -1);
85007 put_cred(cred);
85008 +
85009 +#ifdef CONFIG_GRKERNSEC_SETXID
85010 + cred = (struct cred *) tsk->delayed_cred;
85011 + if (cred != NULL) {
85012 + tsk->delayed_cred = NULL;
85013 + validate_creds(cred);
85014 + alter_cred_subscribers(cred, -1);
85015 + put_cred(cred);
85016 + }
85017 +#endif
85018 }
85019
85020 /**
85021 @@ -411,7 +421,7 @@ static bool cred_cap_issubset(const struct cred *set, const struct cred *subset)
85022 * Always returns 0 thus allowing this function to be tail-called at the end
85023 * of, say, sys_setgid().
85024 */
85025 -int commit_creds(struct cred *new)
85026 +static int __commit_creds(struct cred *new)
85027 {
85028 struct task_struct *task = current;
85029 const struct cred *old = task->real_cred;
85030 @@ -430,6 +440,8 @@ int commit_creds(struct cred *new)
85031
85032 get_cred(new); /* we will require a ref for the subj creds too */
85033
85034 + gr_set_role_label(task, new->uid, new->gid);
85035 +
85036 /* dumpability changes */
85037 if (!uid_eq(old->euid, new->euid) ||
85038 !gid_eq(old->egid, new->egid) ||
85039 @@ -479,6 +491,102 @@ int commit_creds(struct cred *new)
85040 put_cred(old);
85041 return 0;
85042 }
85043 +#ifdef CONFIG_GRKERNSEC_SETXID
85044 +extern int set_user(struct cred *new);
85045 +
85046 +void gr_delayed_cred_worker(void)
85047 +{
85048 + const struct cred *new = current->delayed_cred;
85049 + struct cred *ncred;
85050 +
85051 + current->delayed_cred = NULL;
85052 +
85053 + if (!uid_eq(current_uid(), GLOBAL_ROOT_UID) && new != NULL) {
85054 + // from doing get_cred on it when queueing this
85055 + put_cred(new);
85056 + return;
85057 + } else if (new == NULL)
85058 + return;
85059 +
85060 + ncred = prepare_creds();
85061 + if (!ncred)
85062 + goto die;
85063 + // uids
85064 + ncred->uid = new->uid;
85065 + ncred->euid = new->euid;
85066 + ncred->suid = new->suid;
85067 + ncred->fsuid = new->fsuid;
85068 + // gids
85069 + ncred->gid = new->gid;
85070 + ncred->egid = new->egid;
85071 + ncred->sgid = new->sgid;
85072 + ncred->fsgid = new->fsgid;
85073 + // groups
85074 + if (set_groups(ncred, new->group_info) < 0) {
85075 + abort_creds(ncred);
85076 + goto die;
85077 + }
85078 + // caps
85079 + ncred->securebits = new->securebits;
85080 + ncred->cap_inheritable = new->cap_inheritable;
85081 + ncred->cap_permitted = new->cap_permitted;
85082 + ncred->cap_effective = new->cap_effective;
85083 + ncred->cap_bset = new->cap_bset;
85084 +
85085 + if (set_user(ncred)) {
85086 + abort_creds(ncred);
85087 + goto die;
85088 + }
85089 +
85090 + // from doing get_cred on it when queueing this
85091 + put_cred(new);
85092 +
85093 + __commit_creds(ncred);
85094 + return;
85095 +die:
85096 + // from doing get_cred on it when queueing this
85097 + put_cred(new);
85098 + do_group_exit(SIGKILL);
85099 +}
85100 +#endif
85101 +
85102 +int commit_creds(struct cred *new)
85103 +{
85104 +#ifdef CONFIG_GRKERNSEC_SETXID
85105 + int ret;
85106 + int schedule_it = 0;
85107 + struct task_struct *t;
85108 +
85109 + /* we won't get called with tasklist_lock held for writing
85110 + and interrupts disabled as the cred struct in that case is
85111 + init_cred
85112 + */
85113 + if (grsec_enable_setxid && !current_is_single_threaded() &&
85114 + uid_eq(current_uid(), GLOBAL_ROOT_UID) &&
85115 + !uid_eq(new->uid, GLOBAL_ROOT_UID)) {
85116 + schedule_it = 1;
85117 + }
85118 + ret = __commit_creds(new);
85119 + if (schedule_it) {
85120 + rcu_read_lock();
85121 + read_lock(&tasklist_lock);
85122 + for (t = next_thread(current); t != current;
85123 + t = next_thread(t)) {
85124 + if (t->delayed_cred == NULL) {
85125 + t->delayed_cred = get_cred(new);
85126 + set_tsk_thread_flag(t, TIF_GRSEC_SETXID);
85127 + set_tsk_need_resched(t);
85128 + }
85129 + }
85130 + read_unlock(&tasklist_lock);
85131 + rcu_read_unlock();
85132 + }
85133 + return ret;
85134 +#else
85135 + return __commit_creds(new);
85136 +#endif
85137 +}
85138 +
85139 EXPORT_SYMBOL(commit_creds);
85140
85141 /**
85142 diff --git a/kernel/debug/debug_core.c b/kernel/debug/debug_core.c
85143 index 7d2f35e..1bafcd0 100644
85144 --- a/kernel/debug/debug_core.c
85145 +++ b/kernel/debug/debug_core.c
85146 @@ -123,7 +123,7 @@ static DEFINE_RAW_SPINLOCK(dbg_slave_lock);
85147 */
85148 static atomic_t masters_in_kgdb;
85149 static atomic_t slaves_in_kgdb;
85150 -static atomic_t kgdb_break_tasklet_var;
85151 +static atomic_unchecked_t kgdb_break_tasklet_var;
85152 atomic_t kgdb_setting_breakpoint;
85153
85154 struct task_struct *kgdb_usethread;
85155 @@ -133,7 +133,7 @@ int kgdb_single_step;
85156 static pid_t kgdb_sstep_pid;
85157
85158 /* to keep track of the CPU which is doing the single stepping*/
85159 -atomic_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
85160 +atomic_unchecked_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
85161
85162 /*
85163 * If you are debugging a problem where roundup (the collection of
85164 @@ -541,7 +541,7 @@ return_normal:
85165 * kernel will only try for the value of sstep_tries before
85166 * giving up and continuing on.
85167 */
85168 - if (atomic_read(&kgdb_cpu_doing_single_step) != -1 &&
85169 + if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1 &&
85170 (kgdb_info[cpu].task &&
85171 kgdb_info[cpu].task->pid != kgdb_sstep_pid) && --sstep_tries) {
85172 atomic_set(&kgdb_active, -1);
85173 @@ -639,8 +639,8 @@ cpu_master_loop:
85174 }
85175
85176 kgdb_restore:
85177 - if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
85178 - int sstep_cpu = atomic_read(&kgdb_cpu_doing_single_step);
85179 + if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
85180 + int sstep_cpu = atomic_read_unchecked(&kgdb_cpu_doing_single_step);
85181 if (kgdb_info[sstep_cpu].task)
85182 kgdb_sstep_pid = kgdb_info[sstep_cpu].task->pid;
85183 else
85184 @@ -916,18 +916,18 @@ static void kgdb_unregister_callbacks(void)
85185 static void kgdb_tasklet_bpt(unsigned long ing)
85186 {
85187 kgdb_breakpoint();
85188 - atomic_set(&kgdb_break_tasklet_var, 0);
85189 + atomic_set_unchecked(&kgdb_break_tasklet_var, 0);
85190 }
85191
85192 static DECLARE_TASKLET(kgdb_tasklet_breakpoint, kgdb_tasklet_bpt, 0);
85193
85194 void kgdb_schedule_breakpoint(void)
85195 {
85196 - if (atomic_read(&kgdb_break_tasklet_var) ||
85197 + if (atomic_read_unchecked(&kgdb_break_tasklet_var) ||
85198 atomic_read(&kgdb_active) != -1 ||
85199 atomic_read(&kgdb_setting_breakpoint))
85200 return;
85201 - atomic_inc(&kgdb_break_tasklet_var);
85202 + atomic_inc_unchecked(&kgdb_break_tasklet_var);
85203 tasklet_schedule(&kgdb_tasklet_breakpoint);
85204 }
85205 EXPORT_SYMBOL_GPL(kgdb_schedule_breakpoint);
85206 diff --git a/kernel/debug/kdb/kdb_main.c b/kernel/debug/kdb/kdb_main.c
85207 index 0b097c8..11dd5c5 100644
85208 --- a/kernel/debug/kdb/kdb_main.c
85209 +++ b/kernel/debug/kdb/kdb_main.c
85210 @@ -1977,7 +1977,7 @@ static int kdb_lsmod(int argc, const char **argv)
85211 continue;
85212
85213 kdb_printf("%-20s%8u 0x%p ", mod->name,
85214 - mod->core_size, (void *)mod);
85215 + mod->core_size_rx + mod->core_size_rw, (void *)mod);
85216 #ifdef CONFIG_MODULE_UNLOAD
85217 kdb_printf("%4ld ", module_refcount(mod));
85218 #endif
85219 @@ -1987,7 +1987,7 @@ static int kdb_lsmod(int argc, const char **argv)
85220 kdb_printf(" (Loading)");
85221 else
85222 kdb_printf(" (Live)");
85223 - kdb_printf(" 0x%p", mod->module_core);
85224 + kdb_printf(" 0x%p 0x%p", mod->module_core_rx, mod->module_core_rw);
85225
85226 #ifdef CONFIG_MODULE_UNLOAD
85227 {
85228 diff --git a/kernel/events/core.c b/kernel/events/core.c
85229 index 6ed1163..f36346e 100644
85230 --- a/kernel/events/core.c
85231 +++ b/kernel/events/core.c
85232 @@ -157,8 +157,15 @@ static struct srcu_struct pmus_srcu;
85233 * 0 - disallow raw tracepoint access for unpriv
85234 * 1 - disallow cpu events for unpriv
85235 * 2 - disallow kernel profiling for unpriv
85236 + * 3 - disallow all unpriv perf event use
85237 */
85238 -int sysctl_perf_event_paranoid __read_mostly = 1;
85239 +#ifdef CONFIG_GRKERNSEC_PERF_HARDEN
85240 +int sysctl_perf_event_legitimately_concerned __read_mostly = 3;
85241 +#elif defined(CONFIG_GRKERNSEC_HIDESYM)
85242 +int sysctl_perf_event_legitimately_concerned __read_mostly = 2;
85243 +#else
85244 +int sysctl_perf_event_legitimately_concerned __read_mostly = 1;
85245 +#endif
85246
85247 /* Minimum for 512 kiB + 1 user control page */
85248 int sysctl_perf_event_mlock __read_mostly = 512 + (PAGE_SIZE / 1024); /* 'free' kiB per user */
85249 @@ -184,7 +191,7 @@ void update_perf_cpu_limits(void)
85250
85251 tmp *= sysctl_perf_cpu_time_max_percent;
85252 do_div(tmp, 100);
85253 - ACCESS_ONCE(perf_sample_allowed_ns) = tmp;
85254 + ACCESS_ONCE_RW(perf_sample_allowed_ns) = tmp;
85255 }
85256
85257 static int perf_rotate_context(struct perf_cpu_context *cpuctx);
85258 @@ -271,7 +278,7 @@ void perf_sample_event_took(u64 sample_len_ns)
85259 update_perf_cpu_limits();
85260 }
85261
85262 -static atomic64_t perf_event_id;
85263 +static atomic64_unchecked_t perf_event_id;
85264
85265 static void cpu_ctx_sched_out(struct perf_cpu_context *cpuctx,
85266 enum event_type_t event_type);
85267 @@ -2985,7 +2992,7 @@ static void __perf_event_read(void *info)
85268
85269 static inline u64 perf_event_count(struct perf_event *event)
85270 {
85271 - return local64_read(&event->count) + atomic64_read(&event->child_count);
85272 + return local64_read(&event->count) + atomic64_read_unchecked(&event->child_count);
85273 }
85274
85275 static u64 perf_event_read(struct perf_event *event)
85276 @@ -3353,9 +3360,9 @@ u64 perf_event_read_value(struct perf_event *event, u64 *enabled, u64 *running)
85277 mutex_lock(&event->child_mutex);
85278 total += perf_event_read(event);
85279 *enabled += event->total_time_enabled +
85280 - atomic64_read(&event->child_total_time_enabled);
85281 + atomic64_read_unchecked(&event->child_total_time_enabled);
85282 *running += event->total_time_running +
85283 - atomic64_read(&event->child_total_time_running);
85284 + atomic64_read_unchecked(&event->child_total_time_running);
85285
85286 list_for_each_entry(child, &event->child_list, child_list) {
85287 total += perf_event_read(child);
85288 @@ -3770,10 +3777,10 @@ void perf_event_update_userpage(struct perf_event *event)
85289 userpg->offset -= local64_read(&event->hw.prev_count);
85290
85291 userpg->time_enabled = enabled +
85292 - atomic64_read(&event->child_total_time_enabled);
85293 + atomic64_read_unchecked(&event->child_total_time_enabled);
85294
85295 userpg->time_running = running +
85296 - atomic64_read(&event->child_total_time_running);
85297 + atomic64_read_unchecked(&event->child_total_time_running);
85298
85299 arch_perf_update_userpage(userpg, now);
85300
85301 @@ -4324,7 +4331,7 @@ perf_output_sample_ustack(struct perf_output_handle *handle, u64 dump_size,
85302
85303 /* Data. */
85304 sp = perf_user_stack_pointer(regs);
85305 - rem = __output_copy_user(handle, (void *) sp, dump_size);
85306 + rem = __output_copy_user(handle, (void __user *) sp, dump_size);
85307 dyn_size = dump_size - rem;
85308
85309 perf_output_skip(handle, rem);
85310 @@ -4415,11 +4422,11 @@ static void perf_output_read_one(struct perf_output_handle *handle,
85311 values[n++] = perf_event_count(event);
85312 if (read_format & PERF_FORMAT_TOTAL_TIME_ENABLED) {
85313 values[n++] = enabled +
85314 - atomic64_read(&event->child_total_time_enabled);
85315 + atomic64_read_unchecked(&event->child_total_time_enabled);
85316 }
85317 if (read_format & PERF_FORMAT_TOTAL_TIME_RUNNING) {
85318 values[n++] = running +
85319 - atomic64_read(&event->child_total_time_running);
85320 + atomic64_read_unchecked(&event->child_total_time_running);
85321 }
85322 if (read_format & PERF_FORMAT_ID)
85323 values[n++] = primary_event_id(event);
85324 @@ -6686,7 +6693,7 @@ perf_event_alloc(struct perf_event_attr *attr, int cpu,
85325 event->parent = parent_event;
85326
85327 event->ns = get_pid_ns(task_active_pid_ns(current));
85328 - event->id = atomic64_inc_return(&perf_event_id);
85329 + event->id = atomic64_inc_return_unchecked(&perf_event_id);
85330
85331 event->state = PERF_EVENT_STATE_INACTIVE;
85332
85333 @@ -6985,6 +6992,11 @@ SYSCALL_DEFINE5(perf_event_open,
85334 if (flags & ~PERF_FLAG_ALL)
85335 return -EINVAL;
85336
85337 +#ifdef CONFIG_GRKERNSEC_PERF_HARDEN
85338 + if (perf_paranoid_any() && !capable(CAP_SYS_ADMIN))
85339 + return -EACCES;
85340 +#endif
85341 +
85342 err = perf_copy_attr(attr_uptr, &attr);
85343 if (err)
85344 return err;
85345 @@ -7316,10 +7328,10 @@ static void sync_child_event(struct perf_event *child_event,
85346 /*
85347 * Add back the child's count to the parent's count:
85348 */
85349 - atomic64_add(child_val, &parent_event->child_count);
85350 - atomic64_add(child_event->total_time_enabled,
85351 + atomic64_add_unchecked(child_val, &parent_event->child_count);
85352 + atomic64_add_unchecked(child_event->total_time_enabled,
85353 &parent_event->child_total_time_enabled);
85354 - atomic64_add(child_event->total_time_running,
85355 + atomic64_add_unchecked(child_event->total_time_running,
85356 &parent_event->child_total_time_running);
85357
85358 /*
85359 diff --git a/kernel/events/internal.h b/kernel/events/internal.h
85360 index 569b2187..19940d9 100644
85361 --- a/kernel/events/internal.h
85362 +++ b/kernel/events/internal.h
85363 @@ -81,10 +81,10 @@ static inline unsigned long perf_data_size(struct ring_buffer *rb)
85364 return rb->nr_pages << (PAGE_SHIFT + page_order(rb));
85365 }
85366
85367 -#define DEFINE_OUTPUT_COPY(func_name, memcpy_func) \
85368 +#define DEFINE_OUTPUT_COPY(func_name, memcpy_func, user) \
85369 static inline unsigned long \
85370 func_name(struct perf_output_handle *handle, \
85371 - const void *buf, unsigned long len) \
85372 + const void user *buf, unsigned long len) \
85373 { \
85374 unsigned long size, written; \
85375 \
85376 @@ -117,7 +117,7 @@ memcpy_common(void *dst, const void *src, unsigned long n)
85377 return 0;
85378 }
85379
85380 -DEFINE_OUTPUT_COPY(__output_copy, memcpy_common)
85381 +DEFINE_OUTPUT_COPY(__output_copy, memcpy_common, )
85382
85383 static inline unsigned long
85384 memcpy_skip(void *dst, const void *src, unsigned long n)
85385 @@ -125,7 +125,7 @@ memcpy_skip(void *dst, const void *src, unsigned long n)
85386 return 0;
85387 }
85388
85389 -DEFINE_OUTPUT_COPY(__output_skip, memcpy_skip)
85390 +DEFINE_OUTPUT_COPY(__output_skip, memcpy_skip, )
85391
85392 #ifndef arch_perf_out_copy_user
85393 #define arch_perf_out_copy_user arch_perf_out_copy_user
85394 @@ -143,7 +143,7 @@ arch_perf_out_copy_user(void *dst, const void *src, unsigned long n)
85395 }
85396 #endif
85397
85398 -DEFINE_OUTPUT_COPY(__output_copy_user, arch_perf_out_copy_user)
85399 +DEFINE_OUTPUT_COPY(__output_copy_user, arch_perf_out_copy_user, __user)
85400
85401 /* Callchain handling */
85402 extern struct perf_callchain_entry *
85403 diff --git a/kernel/events/uprobes.c b/kernel/events/uprobes.c
85404 index 24b7d6c..40cf797 100644
85405 --- a/kernel/events/uprobes.c
85406 +++ b/kernel/events/uprobes.c
85407 @@ -1640,7 +1640,7 @@ static int is_trap_at_addr(struct mm_struct *mm, unsigned long vaddr)
85408 {
85409 struct page *page;
85410 uprobe_opcode_t opcode;
85411 - int result;
85412 + long result;
85413
85414 pagefault_disable();
85415 result = __copy_from_user_inatomic(&opcode, (void __user*)vaddr,
85416 diff --git a/kernel/exit.c b/kernel/exit.c
85417 index a949819..a5f127d 100644
85418 --- a/kernel/exit.c
85419 +++ b/kernel/exit.c
85420 @@ -172,6 +172,10 @@ void release_task(struct task_struct * p)
85421 struct task_struct *leader;
85422 int zap_leader;
85423 repeat:
85424 +#ifdef CONFIG_NET
85425 + gr_del_task_from_ip_table(p);
85426 +#endif
85427 +
85428 /* don't need to get the RCU readlock here - the process is dead and
85429 * can't be modifying its own credentials. But shut RCU-lockdep up */
85430 rcu_read_lock();
85431 @@ -329,7 +333,7 @@ int allow_signal(int sig)
85432 * know it'll be handled, so that they don't get converted to
85433 * SIGKILL or just silently dropped.
85434 */
85435 - current->sighand->action[(sig)-1].sa.sa_handler = (void __user *)2;
85436 + current->sighand->action[(sig)-1].sa.sa_handler = (__force void __user *)2;
85437 recalc_sigpending();
85438 spin_unlock_irq(&current->sighand->siglock);
85439 return 0;
85440 @@ -698,6 +702,8 @@ void do_exit(long code)
85441 struct task_struct *tsk = current;
85442 int group_dead;
85443
85444 + set_fs(USER_DS);
85445 +
85446 profile_task_exit(tsk);
85447
85448 WARN_ON(blk_needs_flush_plug(tsk));
85449 @@ -714,7 +720,6 @@ void do_exit(long code)
85450 * mm_release()->clear_child_tid() from writing to a user-controlled
85451 * kernel address.
85452 */
85453 - set_fs(USER_DS);
85454
85455 ptrace_event(PTRACE_EVENT_EXIT, code);
85456
85457 @@ -773,6 +778,9 @@ void do_exit(long code)
85458 tsk->exit_code = code;
85459 taskstats_exit(tsk, group_dead);
85460
85461 + gr_acl_handle_psacct(tsk, code);
85462 + gr_acl_handle_exit();
85463 +
85464 exit_mm(tsk);
85465
85466 if (group_dead)
85467 @@ -894,7 +902,7 @@ SYSCALL_DEFINE1(exit, int, error_code)
85468 * Take down every thread in the group. This is called by fatal signals
85469 * as well as by sys_exit_group (below).
85470 */
85471 -void
85472 +__noreturn void
85473 do_group_exit(int exit_code)
85474 {
85475 struct signal_struct *sig = current->signal;
85476 diff --git a/kernel/fork.c b/kernel/fork.c
85477 index dfa736c..d170f9b 100644
85478 --- a/kernel/fork.c
85479 +++ b/kernel/fork.c
85480 @@ -319,7 +319,7 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
85481 *stackend = STACK_END_MAGIC; /* for overflow detection */
85482
85483 #ifdef CONFIG_CC_STACKPROTECTOR
85484 - tsk->stack_canary = get_random_int();
85485 + tsk->stack_canary = pax_get_random_long();
85486 #endif
85487
85488 /*
85489 @@ -345,12 +345,80 @@ free_tsk:
85490 }
85491
85492 #ifdef CONFIG_MMU
85493 -static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
85494 +static struct vm_area_struct *dup_vma(struct mm_struct *mm, struct mm_struct *oldmm, struct vm_area_struct *mpnt)
85495 +{
85496 + struct vm_area_struct *tmp;
85497 + unsigned long charge;
85498 + struct file *file;
85499 + int retval;
85500 +
85501 + charge = 0;
85502 + if (mpnt->vm_flags & VM_ACCOUNT) {
85503 + unsigned long len = vma_pages(mpnt);
85504 +
85505 + if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
85506 + goto fail_nomem;
85507 + charge = len;
85508 + }
85509 + tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
85510 + if (!tmp)
85511 + goto fail_nomem;
85512 + *tmp = *mpnt;
85513 + tmp->vm_mm = mm;
85514 + INIT_LIST_HEAD(&tmp->anon_vma_chain);
85515 + retval = vma_dup_policy(mpnt, tmp);
85516 + if (retval)
85517 + goto fail_nomem_policy;
85518 + if (anon_vma_fork(tmp, mpnt))
85519 + goto fail_nomem_anon_vma_fork;
85520 + tmp->vm_flags &= ~VM_LOCKED;
85521 + tmp->vm_next = tmp->vm_prev = NULL;
85522 + tmp->vm_mirror = NULL;
85523 + file = tmp->vm_file;
85524 + if (file) {
85525 + struct inode *inode = file_inode(file);
85526 + struct address_space *mapping = file->f_mapping;
85527 +
85528 + get_file(file);
85529 + if (tmp->vm_flags & VM_DENYWRITE)
85530 + atomic_dec(&inode->i_writecount);
85531 + mutex_lock(&mapping->i_mmap_mutex);
85532 + if (tmp->vm_flags & VM_SHARED)
85533 + mapping->i_mmap_writable++;
85534 + flush_dcache_mmap_lock(mapping);
85535 + /* insert tmp into the share list, just after mpnt */
85536 + if (unlikely(tmp->vm_flags & VM_NONLINEAR))
85537 + vma_nonlinear_insert(tmp, &mapping->i_mmap_nonlinear);
85538 + else
85539 + vma_interval_tree_insert_after(tmp, mpnt, &mapping->i_mmap);
85540 + flush_dcache_mmap_unlock(mapping);
85541 + mutex_unlock(&mapping->i_mmap_mutex);
85542 + }
85543 +
85544 + /*
85545 + * Clear hugetlb-related page reserves for children. This only
85546 + * affects MAP_PRIVATE mappings. Faults generated by the child
85547 + * are not guaranteed to succeed, even if read-only
85548 + */
85549 + if (is_vm_hugetlb_page(tmp))
85550 + reset_vma_resv_huge_pages(tmp);
85551 +
85552 + return tmp;
85553 +
85554 +fail_nomem_anon_vma_fork:
85555 + mpol_put(vma_policy(tmp));
85556 +fail_nomem_policy:
85557 + kmem_cache_free(vm_area_cachep, tmp);
85558 +fail_nomem:
85559 + vm_unacct_memory(charge);
85560 + return NULL;
85561 +}
85562 +
85563 +static __latent_entropy int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
85564 {
85565 struct vm_area_struct *mpnt, *tmp, *prev, **pprev;
85566 struct rb_node **rb_link, *rb_parent;
85567 int retval;
85568 - unsigned long charge;
85569
85570 uprobe_start_dup_mmap();
85571 down_write(&oldmm->mmap_sem);
85572 @@ -379,55 +447,15 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
85573
85574 prev = NULL;
85575 for (mpnt = oldmm->mmap; mpnt; mpnt = mpnt->vm_next) {
85576 - struct file *file;
85577 -
85578 if (mpnt->vm_flags & VM_DONTCOPY) {
85579 vm_stat_account(mm, mpnt->vm_flags, mpnt->vm_file,
85580 -vma_pages(mpnt));
85581 continue;
85582 }
85583 - charge = 0;
85584 - if (mpnt->vm_flags & VM_ACCOUNT) {
85585 - unsigned long len = vma_pages(mpnt);
85586 -
85587 - if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
85588 - goto fail_nomem;
85589 - charge = len;
85590 - }
85591 - tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
85592 - if (!tmp)
85593 - goto fail_nomem;
85594 - *tmp = *mpnt;
85595 - INIT_LIST_HEAD(&tmp->anon_vma_chain);
85596 - retval = vma_dup_policy(mpnt, tmp);
85597 - if (retval)
85598 - goto fail_nomem_policy;
85599 - tmp->vm_mm = mm;
85600 - if (anon_vma_fork(tmp, mpnt))
85601 - goto fail_nomem_anon_vma_fork;
85602 - tmp->vm_flags &= ~VM_LOCKED;
85603 - tmp->vm_next = tmp->vm_prev = NULL;
85604 - file = tmp->vm_file;
85605 - if (file) {
85606 - struct inode *inode = file_inode(file);
85607 - struct address_space *mapping = file->f_mapping;
85608 -
85609 - get_file(file);
85610 - if (tmp->vm_flags & VM_DENYWRITE)
85611 - atomic_dec(&inode->i_writecount);
85612 - mutex_lock(&mapping->i_mmap_mutex);
85613 - if (tmp->vm_flags & VM_SHARED)
85614 - mapping->i_mmap_writable++;
85615 - flush_dcache_mmap_lock(mapping);
85616 - /* insert tmp into the share list, just after mpnt */
85617 - if (unlikely(tmp->vm_flags & VM_NONLINEAR))
85618 - vma_nonlinear_insert(tmp,
85619 - &mapping->i_mmap_nonlinear);
85620 - else
85621 - vma_interval_tree_insert_after(tmp, mpnt,
85622 - &mapping->i_mmap);
85623 - flush_dcache_mmap_unlock(mapping);
85624 - mutex_unlock(&mapping->i_mmap_mutex);
85625 + tmp = dup_vma(mm, oldmm, mpnt);
85626 + if (!tmp) {
85627 + retval = -ENOMEM;
85628 + goto out;
85629 }
85630
85631 /*
85632 @@ -459,6 +487,31 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
85633 if (retval)
85634 goto out;
85635 }
85636 +
85637 +#ifdef CONFIG_PAX_SEGMEXEC
85638 + if (oldmm->pax_flags & MF_PAX_SEGMEXEC) {
85639 + struct vm_area_struct *mpnt_m;
85640 +
85641 + for (mpnt = oldmm->mmap, mpnt_m = mm->mmap; mpnt; mpnt = mpnt->vm_next, mpnt_m = mpnt_m->vm_next) {
85642 + BUG_ON(!mpnt_m || mpnt_m->vm_mirror || mpnt->vm_mm != oldmm || mpnt_m->vm_mm != mm);
85643 +
85644 + if (!mpnt->vm_mirror)
85645 + continue;
85646 +
85647 + if (mpnt->vm_end <= SEGMEXEC_TASK_SIZE) {
85648 + BUG_ON(mpnt->vm_mirror->vm_mirror != mpnt);
85649 + mpnt->vm_mirror = mpnt_m;
85650 + } else {
85651 + BUG_ON(mpnt->vm_mirror->vm_mirror == mpnt || mpnt->vm_mirror->vm_mirror->vm_mm != mm);
85652 + mpnt_m->vm_mirror = mpnt->vm_mirror->vm_mirror;
85653 + mpnt_m->vm_mirror->vm_mirror = mpnt_m;
85654 + mpnt->vm_mirror->vm_mirror = mpnt;
85655 + }
85656 + }
85657 + BUG_ON(mpnt_m);
85658 + }
85659 +#endif
85660 +
85661 /* a new mm has just been created */
85662 arch_dup_mmap(oldmm, mm);
85663 retval = 0;
85664 @@ -468,14 +521,6 @@ out:
85665 up_write(&oldmm->mmap_sem);
85666 uprobe_end_dup_mmap();
85667 return retval;
85668 -fail_nomem_anon_vma_fork:
85669 - mpol_put(vma_policy(tmp));
85670 -fail_nomem_policy:
85671 - kmem_cache_free(vm_area_cachep, tmp);
85672 -fail_nomem:
85673 - retval = -ENOMEM;
85674 - vm_unacct_memory(charge);
85675 - goto out;
85676 }
85677
85678 static inline int mm_alloc_pgd(struct mm_struct *mm)
85679 @@ -689,8 +734,8 @@ struct mm_struct *mm_access(struct task_struct *task, unsigned int mode)
85680 return ERR_PTR(err);
85681
85682 mm = get_task_mm(task);
85683 - if (mm && mm != current->mm &&
85684 - !ptrace_may_access(task, mode)) {
85685 + if (mm && ((mm != current->mm && !ptrace_may_access(task, mode)) ||
85686 + (mode == PTRACE_MODE_ATTACH && (gr_handle_proc_ptrace(task) || gr_acl_handle_procpidmem(task))))) {
85687 mmput(mm);
85688 mm = ERR_PTR(-EACCES);
85689 }
85690 @@ -909,13 +954,20 @@ static int copy_fs(unsigned long clone_flags, struct task_struct *tsk)
85691 spin_unlock(&fs->lock);
85692 return -EAGAIN;
85693 }
85694 - fs->users++;
85695 + atomic_inc(&fs->users);
85696 spin_unlock(&fs->lock);
85697 return 0;
85698 }
85699 tsk->fs = copy_fs_struct(fs);
85700 if (!tsk->fs)
85701 return -ENOMEM;
85702 + /* Carry through gr_chroot_dentry and is_chrooted instead
85703 + of recomputing it here. Already copied when the task struct
85704 + is duplicated. This allows pivot_root to not be treated as
85705 + a chroot
85706 + */
85707 + //gr_set_chroot_entries(tsk, &tsk->fs->root);
85708 +
85709 return 0;
85710 }
85711
85712 @@ -1126,7 +1178,7 @@ init_task_pid(struct task_struct *task, enum pid_type type, struct pid *pid)
85713 * parts of the process environment (as per the clone
85714 * flags). The actual kick-off is left to the caller.
85715 */
85716 -static struct task_struct *copy_process(unsigned long clone_flags,
85717 +static __latent_entropy struct task_struct *copy_process(unsigned long clone_flags,
85718 unsigned long stack_start,
85719 unsigned long stack_size,
85720 int __user *child_tidptr,
85721 @@ -1198,6 +1250,9 @@ static struct task_struct *copy_process(unsigned long clone_flags,
85722 DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled);
85723 #endif
85724 retval = -EAGAIN;
85725 +
85726 + gr_learn_resource(p, RLIMIT_NPROC, atomic_read(&p->real_cred->user->processes), 0);
85727 +
85728 if (atomic_read(&p->real_cred->user->processes) >=
85729 task_rlimit(p, RLIMIT_NPROC)) {
85730 if (p->real_cred->user != INIT_USER &&
85731 @@ -1446,6 +1501,11 @@ static struct task_struct *copy_process(unsigned long clone_flags,
85732 goto bad_fork_free_pid;
85733 }
85734
85735 + /* synchronizes with gr_set_acls()
85736 + we need to call this past the point of no return for fork()
85737 + */
85738 + gr_copy_label(p);
85739 +
85740 if (likely(p->pid)) {
85741 ptrace_init_task(p, (clone_flags & CLONE_PTRACE) || trace);
85742
85743 @@ -1532,6 +1592,8 @@ bad_fork_cleanup_count:
85744 bad_fork_free:
85745 free_task(p);
85746 fork_out:
85747 + gr_log_forkfail(retval);
85748 +
85749 return ERR_PTR(retval);
85750 }
85751
85752 @@ -1593,6 +1655,7 @@ long do_fork(unsigned long clone_flags,
85753
85754 p = copy_process(clone_flags, stack_start, stack_size,
85755 child_tidptr, NULL, trace);
85756 + add_latent_entropy();
85757 /*
85758 * Do this prior waking up the new thread - the thread pointer
85759 * might get invalid after that point, if the thread exits quickly.
85760 @@ -1607,6 +1670,8 @@ long do_fork(unsigned long clone_flags,
85761 if (clone_flags & CLONE_PARENT_SETTID)
85762 put_user(nr, parent_tidptr);
85763
85764 + gr_handle_brute_check();
85765 +
85766 if (clone_flags & CLONE_VFORK) {
85767 p->vfork_done = &vfork;
85768 init_completion(&vfork);
85769 @@ -1723,7 +1788,7 @@ void __init proc_caches_init(void)
85770 mm_cachep = kmem_cache_create("mm_struct",
85771 sizeof(struct mm_struct), ARCH_MIN_MMSTRUCT_ALIGN,
85772 SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_NOTRACK, NULL);
85773 - vm_area_cachep = KMEM_CACHE(vm_area_struct, SLAB_PANIC);
85774 + vm_area_cachep = KMEM_CACHE(vm_area_struct, SLAB_PANIC | SLAB_NO_SANITIZE);
85775 mmap_init();
85776 nsproxy_cache_init();
85777 }
85778 @@ -1763,7 +1828,7 @@ static int unshare_fs(unsigned long unshare_flags, struct fs_struct **new_fsp)
85779 return 0;
85780
85781 /* don't need lock here; in the worst case we'll do useless copy */
85782 - if (fs->users == 1)
85783 + if (atomic_read(&fs->users) == 1)
85784 return 0;
85785
85786 *new_fsp = copy_fs_struct(fs);
85787 @@ -1870,7 +1935,8 @@ SYSCALL_DEFINE1(unshare, unsigned long, unshare_flags)
85788 fs = current->fs;
85789 spin_lock(&fs->lock);
85790 current->fs = new_fs;
85791 - if (--fs->users)
85792 + gr_set_chroot_entries(current, &current->fs->root);
85793 + if (atomic_dec_return(&fs->users))
85794 new_fs = NULL;
85795 else
85796 new_fs = fs;
85797 diff --git a/kernel/futex.c b/kernel/futex.c
85798 index 0d74e3a..59bea40 100644
85799 --- a/kernel/futex.c
85800 +++ b/kernel/futex.c
85801 @@ -54,6 +54,7 @@
85802 #include <linux/mount.h>
85803 #include <linux/pagemap.h>
85804 #include <linux/syscalls.h>
85805 +#include <linux/ptrace.h>
85806 #include <linux/signal.h>
85807 #include <linux/export.h>
85808 #include <linux/magic.h>
85809 @@ -245,6 +246,11 @@ get_futex_key(u32 __user *uaddr, int fshared, union futex_key *key, int rw)
85810 struct page *page, *page_head;
85811 int err, ro = 0;
85812
85813 +#ifdef CONFIG_PAX_SEGMEXEC
85814 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && address >= SEGMEXEC_TASK_SIZE)
85815 + return -EFAULT;
85816 +#endif
85817 +
85818 /*
85819 * The futex address must be "naturally" aligned.
85820 */
85821 @@ -444,7 +450,7 @@ static int cmpxchg_futex_value_locked(u32 *curval, u32 __user *uaddr,
85822
85823 static int get_futex_value_locked(u32 *dest, u32 __user *from)
85824 {
85825 - int ret;
85826 + unsigned long ret;
85827
85828 pagefault_disable();
85829 ret = __copy_from_user_inatomic(dest, from, sizeof(u32));
85830 @@ -2737,6 +2743,7 @@ static void __init futex_detect_cmpxchg(void)
85831 {
85832 #ifndef CONFIG_HAVE_FUTEX_CMPXCHG
85833 u32 curval;
85834 + mm_segment_t oldfs;
85835
85836 /*
85837 * This will fail and we want it. Some arch implementations do
85838 @@ -2748,8 +2755,11 @@ static void __init futex_detect_cmpxchg(void)
85839 * implementation, the non-functional ones will return
85840 * -ENOSYS.
85841 */
85842 + oldfs = get_fs();
85843 + set_fs(USER_DS);
85844 if (cmpxchg_futex_value_locked(&curval, NULL, 0, 0) == -EFAULT)
85845 futex_cmpxchg_enabled = 1;
85846 + set_fs(oldfs);
85847 #endif
85848 }
85849
85850 diff --git a/kernel/futex_compat.c b/kernel/futex_compat.c
85851 index f9f44fd..29885e4 100644
85852 --- a/kernel/futex_compat.c
85853 +++ b/kernel/futex_compat.c
85854 @@ -32,7 +32,7 @@ fetch_robust_entry(compat_uptr_t *uentry, struct robust_list __user **entry,
85855 return 0;
85856 }
85857
85858 -static void __user *futex_uaddr(struct robust_list __user *entry,
85859 +static void __user __intentional_overflow(-1) *futex_uaddr(struct robust_list __user *entry,
85860 compat_long_t futex_offset)
85861 {
85862 compat_uptr_t base = ptr_to_compat(entry);
85863 diff --git a/kernel/gcov/base.c b/kernel/gcov/base.c
85864 index f45b75b..bfac6d5 100644
85865 --- a/kernel/gcov/base.c
85866 +++ b/kernel/gcov/base.c
85867 @@ -108,11 +108,6 @@ void gcov_enable_events(void)
85868 }
85869
85870 #ifdef CONFIG_MODULES
85871 -static inline int within(void *addr, void *start, unsigned long size)
85872 -{
85873 - return ((addr >= start) && (addr < start + size));
85874 -}
85875 -
85876 /* Update list and generate events when modules are unloaded. */
85877 static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
85878 void *data)
85879 @@ -127,7 +122,7 @@ static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
85880
85881 /* Remove entries located in module from linked list. */
85882 while ((info = gcov_info_next(info))) {
85883 - if (within(info, mod->module_core, mod->core_size)) {
85884 + if (within_module_core_rw((unsigned long)info, mod)) {
85885 gcov_info_unlink(prev, info);
85886 if (gcov_events_enabled)
85887 gcov_event(GCOV_REMOVE, info);
85888 diff --git a/kernel/hrtimer.c b/kernel/hrtimer.c
85889 index 383319b..56ebb13 100644
85890 --- a/kernel/hrtimer.c
85891 +++ b/kernel/hrtimer.c
85892 @@ -1438,7 +1438,7 @@ void hrtimer_peek_ahead_timers(void)
85893 local_irq_restore(flags);
85894 }
85895
85896 -static void run_hrtimer_softirq(struct softirq_action *h)
85897 +static __latent_entropy void run_hrtimer_softirq(void)
85898 {
85899 hrtimer_peek_ahead_timers();
85900 }
85901 diff --git a/kernel/irq_work.c b/kernel/irq_work.c
85902 index 55fcce6..0e4cf34 100644
85903 --- a/kernel/irq_work.c
85904 +++ b/kernel/irq_work.c
85905 @@ -189,12 +189,13 @@ static int irq_work_cpu_notify(struct notifier_block *self,
85906 return NOTIFY_OK;
85907 }
85908
85909 -static struct notifier_block cpu_notify;
85910 +static struct notifier_block cpu_notify = {
85911 + .notifier_call = irq_work_cpu_notify,
85912 + .priority = 0,
85913 +};
85914
85915 static __init int irq_work_init_cpu_notifier(void)
85916 {
85917 - cpu_notify.notifier_call = irq_work_cpu_notify;
85918 - cpu_notify.priority = 0;
85919 register_cpu_notifier(&cpu_notify);
85920 return 0;
85921 }
85922 diff --git a/kernel/jump_label.c b/kernel/jump_label.c
85923 index 9019f15..9a3c42e 100644
85924 --- a/kernel/jump_label.c
85925 +++ b/kernel/jump_label.c
85926 @@ -14,6 +14,7 @@
85927 #include <linux/err.h>
85928 #include <linux/static_key.h>
85929 #include <linux/jump_label_ratelimit.h>
85930 +#include <linux/mm.h>
85931
85932 #ifdef HAVE_JUMP_LABEL
85933
85934 @@ -51,7 +52,9 @@ jump_label_sort_entries(struct jump_entry *start, struct jump_entry *stop)
85935
85936 size = (((unsigned long)stop - (unsigned long)start)
85937 / sizeof(struct jump_entry));
85938 + pax_open_kernel();
85939 sort(start, size, sizeof(struct jump_entry), jump_label_cmp, NULL);
85940 + pax_close_kernel();
85941 }
85942
85943 static void jump_label_update(struct static_key *key, int enable);
85944 @@ -363,10 +366,12 @@ static void jump_label_invalidate_module_init(struct module *mod)
85945 struct jump_entry *iter_stop = iter_start + mod->num_jump_entries;
85946 struct jump_entry *iter;
85947
85948 + pax_open_kernel();
85949 for (iter = iter_start; iter < iter_stop; iter++) {
85950 if (within_module_init(iter->code, mod))
85951 iter->code = 0;
85952 }
85953 + pax_close_kernel();
85954 }
85955
85956 static int
85957 diff --git a/kernel/kallsyms.c b/kernel/kallsyms.c
85958 index 3127ad5..159d880 100644
85959 --- a/kernel/kallsyms.c
85960 +++ b/kernel/kallsyms.c
85961 @@ -11,6 +11,9 @@
85962 * Changed the compression method from stem compression to "table lookup"
85963 * compression (see scripts/kallsyms.c for a more complete description)
85964 */
85965 +#ifdef CONFIG_GRKERNSEC_HIDESYM
85966 +#define __INCLUDED_BY_HIDESYM 1
85967 +#endif
85968 #include <linux/kallsyms.h>
85969 #include <linux/module.h>
85970 #include <linux/init.h>
85971 @@ -53,12 +56,33 @@ extern const unsigned long kallsyms_markers[] __attribute__((weak));
85972
85973 static inline int is_kernel_inittext(unsigned long addr)
85974 {
85975 + if (system_state != SYSTEM_BOOTING)
85976 + return 0;
85977 +
85978 if (addr >= (unsigned long)_sinittext
85979 && addr <= (unsigned long)_einittext)
85980 return 1;
85981 return 0;
85982 }
85983
85984 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
85985 +#ifdef CONFIG_MODULES
85986 +static inline int is_module_text(unsigned long addr)
85987 +{
85988 + if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END)
85989 + return 1;
85990 +
85991 + addr = ktla_ktva(addr);
85992 + return (unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END;
85993 +}
85994 +#else
85995 +static inline int is_module_text(unsigned long addr)
85996 +{
85997 + return 0;
85998 +}
85999 +#endif
86000 +#endif
86001 +
86002 static inline int is_kernel_text(unsigned long addr)
86003 {
86004 if ((addr >= (unsigned long)_stext && addr <= (unsigned long)_etext) ||
86005 @@ -69,13 +93,28 @@ static inline int is_kernel_text(unsigned long addr)
86006
86007 static inline int is_kernel(unsigned long addr)
86008 {
86009 +
86010 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
86011 + if (is_kernel_text(addr) || is_kernel_inittext(addr))
86012 + return 1;
86013 +
86014 + if (ktla_ktva((unsigned long)_text) <= addr && addr < (unsigned long)_end)
86015 +#else
86016 if (addr >= (unsigned long)_stext && addr <= (unsigned long)_end)
86017 +#endif
86018 +
86019 return 1;
86020 return in_gate_area_no_mm(addr);
86021 }
86022
86023 static int is_ksym_addr(unsigned long addr)
86024 {
86025 +
86026 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
86027 + if (is_module_text(addr))
86028 + return 0;
86029 +#endif
86030 +
86031 if (all_var)
86032 return is_kernel(addr);
86033
86034 @@ -480,7 +519,6 @@ static unsigned long get_ksymbol_core(struct kallsym_iter *iter)
86035
86036 static void reset_iter(struct kallsym_iter *iter, loff_t new_pos)
86037 {
86038 - iter->name[0] = '\0';
86039 iter->nameoff = get_symbol_offset(new_pos);
86040 iter->pos = new_pos;
86041 }
86042 @@ -528,6 +566,11 @@ static int s_show(struct seq_file *m, void *p)
86043 {
86044 struct kallsym_iter *iter = m->private;
86045
86046 +#ifdef CONFIG_GRKERNSEC_HIDESYM
86047 + if (!uid_eq(current_uid(), GLOBAL_ROOT_UID))
86048 + return 0;
86049 +#endif
86050 +
86051 /* Some debugging symbols have no name. Ignore them. */
86052 if (!iter->name[0])
86053 return 0;
86054 @@ -541,6 +584,7 @@ static int s_show(struct seq_file *m, void *p)
86055 */
86056 type = iter->exported ? toupper(iter->type) :
86057 tolower(iter->type);
86058 +
86059 seq_printf(m, "%pK %c %s\t[%s]\n", (void *)iter->value,
86060 type, iter->name, iter->module_name);
86061 } else
86062 @@ -566,7 +610,7 @@ static int kallsyms_open(struct inode *inode, struct file *file)
86063 struct kallsym_iter *iter;
86064 int ret;
86065
86066 - iter = kmalloc(sizeof(*iter), GFP_KERNEL);
86067 + iter = kzalloc(sizeof(*iter), GFP_KERNEL);
86068 if (!iter)
86069 return -ENOMEM;
86070 reset_iter(iter, 0);
86071 diff --git a/kernel/kcmp.c b/kernel/kcmp.c
86072 index e30ac0f..3528cac 100644
86073 --- a/kernel/kcmp.c
86074 +++ b/kernel/kcmp.c
86075 @@ -99,6 +99,10 @@ SYSCALL_DEFINE5(kcmp, pid_t, pid1, pid_t, pid2, int, type,
86076 struct task_struct *task1, *task2;
86077 int ret;
86078
86079 +#ifdef CONFIG_GRKERNSEC
86080 + return -ENOSYS;
86081 +#endif
86082 +
86083 rcu_read_lock();
86084
86085 /*
86086 diff --git a/kernel/kexec.c b/kernel/kexec.c
86087 index 9c97016..df438f8 100644
86088 --- a/kernel/kexec.c
86089 +++ b/kernel/kexec.c
86090 @@ -1044,7 +1044,8 @@ asmlinkage long compat_sys_kexec_load(unsigned long entry,
86091 unsigned long flags)
86092 {
86093 struct compat_kexec_segment in;
86094 - struct kexec_segment out, __user *ksegments;
86095 + struct kexec_segment out;
86096 + struct kexec_segment __user *ksegments;
86097 unsigned long i, result;
86098
86099 /* Don't allow clients that don't understand the native
86100 diff --git a/kernel/kmod.c b/kernel/kmod.c
86101 index b086006..b66f630 100644
86102 --- a/kernel/kmod.c
86103 +++ b/kernel/kmod.c
86104 @@ -75,7 +75,7 @@ static void free_modprobe_argv(struct subprocess_info *info)
86105 kfree(info->argv);
86106 }
86107
86108 -static int call_modprobe(char *module_name, int wait)
86109 +static int call_modprobe(char *module_name, char *module_param, int wait)
86110 {
86111 struct subprocess_info *info;
86112 static char *envp[] = {
86113 @@ -85,7 +85,7 @@ static int call_modprobe(char *module_name, int wait)
86114 NULL
86115 };
86116
86117 - char **argv = kmalloc(sizeof(char *[5]), GFP_KERNEL);
86118 + char **argv = kmalloc(sizeof(char *[6]), GFP_KERNEL);
86119 if (!argv)
86120 goto out;
86121
86122 @@ -97,7 +97,8 @@ static int call_modprobe(char *module_name, int wait)
86123 argv[1] = "-q";
86124 argv[2] = "--";
86125 argv[3] = module_name; /* check free_modprobe_argv() */
86126 - argv[4] = NULL;
86127 + argv[4] = module_param;
86128 + argv[5] = NULL;
86129
86130 info = call_usermodehelper_setup(modprobe_path, argv, envp, GFP_KERNEL,
86131 NULL, free_modprobe_argv, NULL);
86132 @@ -129,9 +130,8 @@ out:
86133 * If module auto-loading support is disabled then this function
86134 * becomes a no-operation.
86135 */
86136 -int __request_module(bool wait, const char *fmt, ...)
86137 +static int ____request_module(bool wait, char *module_param, const char *fmt, va_list ap)
86138 {
86139 - va_list args;
86140 char module_name[MODULE_NAME_LEN];
86141 unsigned int max_modprobes;
86142 int ret;
86143 @@ -150,9 +150,7 @@ int __request_module(bool wait, const char *fmt, ...)
86144 if (!modprobe_path[0])
86145 return 0;
86146
86147 - va_start(args, fmt);
86148 - ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, args);
86149 - va_end(args);
86150 + ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, ap);
86151 if (ret >= MODULE_NAME_LEN)
86152 return -ENAMETOOLONG;
86153
86154 @@ -160,6 +158,20 @@ int __request_module(bool wait, const char *fmt, ...)
86155 if (ret)
86156 return ret;
86157
86158 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
86159 + if (uid_eq(current_uid(), GLOBAL_ROOT_UID)) {
86160 + /* hack to workaround consolekit/udisks stupidity */
86161 + read_lock(&tasklist_lock);
86162 + if (!strcmp(current->comm, "mount") &&
86163 + current->real_parent && !strncmp(current->real_parent->comm, "udisk", 5)) {
86164 + read_unlock(&tasklist_lock);
86165 + printk(KERN_ALERT "grsec: denied attempt to auto-load fs module %.64s by udisks\n", module_name);
86166 + return -EPERM;
86167 + }
86168 + read_unlock(&tasklist_lock);
86169 + }
86170 +#endif
86171 +
86172 /* If modprobe needs a service that is in a module, we get a recursive
86173 * loop. Limit the number of running kmod threads to max_threads/2 or
86174 * MAX_KMOD_CONCURRENT, whichever is the smaller. A cleaner method
86175 @@ -188,11 +200,52 @@ int __request_module(bool wait, const char *fmt, ...)
86176
86177 trace_module_request(module_name, wait, _RET_IP_);
86178
86179 - ret = call_modprobe(module_name, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
86180 + ret = call_modprobe(module_name, module_param, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
86181
86182 atomic_dec(&kmod_concurrent);
86183 return ret;
86184 }
86185 +
86186 +int ___request_module(bool wait, char *module_param, const char *fmt, ...)
86187 +{
86188 + va_list args;
86189 + int ret;
86190 +
86191 + va_start(args, fmt);
86192 + ret = ____request_module(wait, module_param, fmt, args);
86193 + va_end(args);
86194 +
86195 + return ret;
86196 +}
86197 +
86198 +int __request_module(bool wait, const char *fmt, ...)
86199 +{
86200 + va_list args;
86201 + int ret;
86202 +
86203 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
86204 + if (!uid_eq(current_uid(), GLOBAL_ROOT_UID)) {
86205 + char module_param[MODULE_NAME_LEN];
86206 +
86207 + memset(module_param, 0, sizeof(module_param));
86208 +
86209 + snprintf(module_param, sizeof(module_param) - 1, "grsec_modharden_normal%u_", GR_GLOBAL_UID(current_uid()));
86210 +
86211 + va_start(args, fmt);
86212 + ret = ____request_module(wait, module_param, fmt, args);
86213 + va_end(args);
86214 +
86215 + return ret;
86216 + }
86217 +#endif
86218 +
86219 + va_start(args, fmt);
86220 + ret = ____request_module(wait, NULL, fmt, args);
86221 + va_end(args);
86222 +
86223 + return ret;
86224 +}
86225 +
86226 EXPORT_SYMBOL(__request_module);
86227 #endif /* CONFIG_MODULES */
86228
86229 @@ -218,6 +271,20 @@ static int ____call_usermodehelper(void *data)
86230 */
86231 set_user_nice(current, 0);
86232
86233 +#ifdef CONFIG_GRKERNSEC
86234 + /* this is race-free as far as userland is concerned as we copied
86235 + out the path to be used prior to this point and are now operating
86236 + on that copy
86237 + */
86238 + if ((strncmp(sub_info->path, "/sbin/", 6) && strncmp(sub_info->path, "/usr/lib/", 9) &&
86239 + strncmp(sub_info->path, "/lib/", 5) && strncmp(sub_info->path, "/lib64/", 7) &&
86240 + strcmp(sub_info->path, "/usr/share/apport/apport")) || strstr(sub_info->path, "..")) {
86241 + printk(KERN_ALERT "grsec: denied exec of usermode helper binary %.950s located outside of /sbin and system library paths\n", sub_info->path);
86242 + retval = -EPERM;
86243 + goto fail;
86244 + }
86245 +#endif
86246 +
86247 retval = -ENOMEM;
86248 new = prepare_kernel_cred(current);
86249 if (!new)
86250 @@ -240,8 +307,8 @@ static int ____call_usermodehelper(void *data)
86251 commit_creds(new);
86252
86253 retval = do_execve(sub_info->path,
86254 - (const char __user *const __user *)sub_info->argv,
86255 - (const char __user *const __user *)sub_info->envp);
86256 + (const char __user *const __force_user *)sub_info->argv,
86257 + (const char __user *const __force_user *)sub_info->envp);
86258 if (!retval)
86259 return 0;
86260
86261 @@ -260,6 +327,10 @@ static int call_helper(void *data)
86262
86263 static void call_usermodehelper_freeinfo(struct subprocess_info *info)
86264 {
86265 +#ifdef CONFIG_GRKERNSEC
86266 + kfree(info->path);
86267 + info->path = info->origpath;
86268 +#endif
86269 if (info->cleanup)
86270 (*info->cleanup)(info);
86271 kfree(info);
86272 @@ -303,7 +374,7 @@ static int wait_for_helper(void *data)
86273 *
86274 * Thus the __user pointer cast is valid here.
86275 */
86276 - sys_wait4(pid, (int __user *)&ret, 0, NULL);
86277 + sys_wait4(pid, (int __force_user *)&ret, 0, NULL);
86278
86279 /*
86280 * If ret is 0, either ____call_usermodehelper failed and the
86281 @@ -542,7 +613,12 @@ struct subprocess_info *call_usermodehelper_setup(char *path, char **argv,
86282 goto out;
86283
86284 INIT_WORK(&sub_info->work, __call_usermodehelper);
86285 +#ifdef CONFIG_GRKERNSEC
86286 + sub_info->origpath = path;
86287 + sub_info->path = kstrdup(path, gfp_mask);
86288 +#else
86289 sub_info->path = path;
86290 +#endif
86291 sub_info->argv = argv;
86292 sub_info->envp = envp;
86293
86294 @@ -650,7 +726,7 @@ EXPORT_SYMBOL(call_usermodehelper);
86295 static int proc_cap_handler(struct ctl_table *table, int write,
86296 void __user *buffer, size_t *lenp, loff_t *ppos)
86297 {
86298 - struct ctl_table t;
86299 + ctl_table_no_const t;
86300 unsigned long cap_array[_KERNEL_CAPABILITY_U32S];
86301 kernel_cap_t new_cap;
86302 int err, i;
86303 diff --git a/kernel/kprobes.c b/kernel/kprobes.c
86304 index ceeadfc..11c18b6 100644
86305 --- a/kernel/kprobes.c
86306 +++ b/kernel/kprobes.c
86307 @@ -31,6 +31,9 @@
86308 * <jkenisto@us.ibm.com> and Prasanna S Panchamukhi
86309 * <prasanna@in.ibm.com> added function-return probes.
86310 */
86311 +#ifdef CONFIG_GRKERNSEC_HIDESYM
86312 +#define __INCLUDED_BY_HIDESYM 1
86313 +#endif
86314 #include <linux/kprobes.h>
86315 #include <linux/hash.h>
86316 #include <linux/init.h>
86317 @@ -135,12 +138,12 @@ enum kprobe_slot_state {
86318
86319 static void *alloc_insn_page(void)
86320 {
86321 - return module_alloc(PAGE_SIZE);
86322 + return module_alloc_exec(PAGE_SIZE);
86323 }
86324
86325 static void free_insn_page(void *page)
86326 {
86327 - module_free(NULL, page);
86328 + module_free_exec(NULL, page);
86329 }
86330
86331 struct kprobe_insn_cache kprobe_insn_slots = {
86332 @@ -2151,11 +2154,11 @@ static void __kprobes report_probe(struct seq_file *pi, struct kprobe *p,
86333 kprobe_type = "k";
86334
86335 if (sym)
86336 - seq_printf(pi, "%p %s %s+0x%x %s ",
86337 + seq_printf(pi, "%pK %s %s+0x%x %s ",
86338 p->addr, kprobe_type, sym, offset,
86339 (modname ? modname : " "));
86340 else
86341 - seq_printf(pi, "%p %s %p ",
86342 + seq_printf(pi, "%pK %s %pK ",
86343 p->addr, kprobe_type, p->addr);
86344
86345 if (!pp)
86346 diff --git a/kernel/ksysfs.c b/kernel/ksysfs.c
86347 index 9659d38..bffd520 100644
86348 --- a/kernel/ksysfs.c
86349 +++ b/kernel/ksysfs.c
86350 @@ -46,6 +46,8 @@ static ssize_t uevent_helper_store(struct kobject *kobj,
86351 {
86352 if (count+1 > UEVENT_HELPER_PATH_LEN)
86353 return -ENOENT;
86354 + if (!capable(CAP_SYS_ADMIN))
86355 + return -EPERM;
86356 memcpy(uevent_helper, buf, count);
86357 uevent_helper[count] = '\0';
86358 if (count && uevent_helper[count-1] == '\n')
86359 @@ -172,7 +174,7 @@ static ssize_t notes_read(struct file *filp, struct kobject *kobj,
86360 return count;
86361 }
86362
86363 -static struct bin_attribute notes_attr = {
86364 +static bin_attribute_no_const notes_attr __read_only = {
86365 .attr = {
86366 .name = "notes",
86367 .mode = S_IRUGO,
86368 diff --git a/kernel/locking/lockdep.c b/kernel/locking/lockdep.c
86369 index 576ba75..7c256e4 100644
86370 --- a/kernel/locking/lockdep.c
86371 +++ b/kernel/locking/lockdep.c
86372 @@ -596,6 +596,10 @@ static int static_obj(void *obj)
86373 end = (unsigned long) &_end,
86374 addr = (unsigned long) obj;
86375
86376 +#ifdef CONFIG_PAX_KERNEXEC
86377 + start = ktla_ktva(start);
86378 +#endif
86379 +
86380 /*
86381 * static variable?
86382 */
86383 @@ -736,6 +740,7 @@ register_lock_class(struct lockdep_map *lock, unsigned int subclass, int force)
86384 if (!static_obj(lock->key)) {
86385 debug_locks_off();
86386 printk("INFO: trying to register non-static key.\n");
86387 + printk("lock:%pS key:%pS.\n", lock, lock->key);
86388 printk("the code is fine but needs lockdep annotation.\n");
86389 printk("turning off the locking correctness validator.\n");
86390 dump_stack();
86391 @@ -3080,7 +3085,7 @@ static int __lock_acquire(struct lockdep_map *lock, unsigned int subclass,
86392 if (!class)
86393 return 0;
86394 }
86395 - atomic_inc((atomic_t *)&class->ops);
86396 + atomic_long_inc_unchecked((atomic_long_unchecked_t *)&class->ops);
86397 if (very_verbose(class)) {
86398 printk("\nacquire class [%p] %s", class->key, class->name);
86399 if (class->name_version > 1)
86400 diff --git a/kernel/locking/lockdep_proc.c b/kernel/locking/lockdep_proc.c
86401 index ef43ac4..2720dfa 100644
86402 --- a/kernel/locking/lockdep_proc.c
86403 +++ b/kernel/locking/lockdep_proc.c
86404 @@ -65,7 +65,7 @@ static int l_show(struct seq_file *m, void *v)
86405 return 0;
86406 }
86407
86408 - seq_printf(m, "%p", class->key);
86409 + seq_printf(m, "%pK", class->key);
86410 #ifdef CONFIG_DEBUG_LOCKDEP
86411 seq_printf(m, " OPS:%8ld", class->ops);
86412 #endif
86413 @@ -83,7 +83,7 @@ static int l_show(struct seq_file *m, void *v)
86414
86415 list_for_each_entry(entry, &class->locks_after, entry) {
86416 if (entry->distance == 1) {
86417 - seq_printf(m, " -> [%p] ", entry->class->key);
86418 + seq_printf(m, " -> [%pK] ", entry->class->key);
86419 print_name(m, entry->class);
86420 seq_puts(m, "\n");
86421 }
86422 @@ -152,7 +152,7 @@ static int lc_show(struct seq_file *m, void *v)
86423 if (!class->key)
86424 continue;
86425
86426 - seq_printf(m, "[%p] ", class->key);
86427 + seq_printf(m, "[%pK] ", class->key);
86428 print_name(m, class);
86429 seq_puts(m, "\n");
86430 }
86431 @@ -496,7 +496,7 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
86432 if (!i)
86433 seq_line(m, '-', 40-namelen, namelen);
86434
86435 - snprintf(ip, sizeof(ip), "[<%p>]",
86436 + snprintf(ip, sizeof(ip), "[<%pK>]",
86437 (void *)class->contention_point[i]);
86438 seq_printf(m, "%40s %14lu %29s %pS\n",
86439 name, stats->contention_point[i],
86440 @@ -511,7 +511,7 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
86441 if (!i)
86442 seq_line(m, '-', 40-namelen, namelen);
86443
86444 - snprintf(ip, sizeof(ip), "[<%p>]",
86445 + snprintf(ip, sizeof(ip), "[<%pK>]",
86446 (void *)class->contending_point[i]);
86447 seq_printf(m, "%40s %14lu %29s %pS\n",
86448 name, stats->contending_point[i],
86449 diff --git a/kernel/locking/mutex-debug.c b/kernel/locking/mutex-debug.c
86450 index 7e3443f..b2a1e6b 100644
86451 --- a/kernel/locking/mutex-debug.c
86452 +++ b/kernel/locking/mutex-debug.c
86453 @@ -49,21 +49,21 @@ void debug_mutex_free_waiter(struct mutex_waiter *waiter)
86454 }
86455
86456 void debug_mutex_add_waiter(struct mutex *lock, struct mutex_waiter *waiter,
86457 - struct thread_info *ti)
86458 + struct task_struct *task)
86459 {
86460 SMP_DEBUG_LOCKS_WARN_ON(!spin_is_locked(&lock->wait_lock));
86461
86462 /* Mark the current thread as blocked on the lock: */
86463 - ti->task->blocked_on = waiter;
86464 + task->blocked_on = waiter;
86465 }
86466
86467 void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
86468 - struct thread_info *ti)
86469 + struct task_struct *task)
86470 {
86471 DEBUG_LOCKS_WARN_ON(list_empty(&waiter->list));
86472 - DEBUG_LOCKS_WARN_ON(waiter->task != ti->task);
86473 - DEBUG_LOCKS_WARN_ON(ti->task->blocked_on != waiter);
86474 - ti->task->blocked_on = NULL;
86475 + DEBUG_LOCKS_WARN_ON(waiter->task != task);
86476 + DEBUG_LOCKS_WARN_ON(task->blocked_on != waiter);
86477 + task->blocked_on = NULL;
86478
86479 list_del_init(&waiter->list);
86480 waiter->task = NULL;
86481 diff --git a/kernel/locking/mutex-debug.h b/kernel/locking/mutex-debug.h
86482 index 0799fd3..d06ae3b 100644
86483 --- a/kernel/locking/mutex-debug.h
86484 +++ b/kernel/locking/mutex-debug.h
86485 @@ -20,9 +20,9 @@ extern void debug_mutex_wake_waiter(struct mutex *lock,
86486 extern void debug_mutex_free_waiter(struct mutex_waiter *waiter);
86487 extern void debug_mutex_add_waiter(struct mutex *lock,
86488 struct mutex_waiter *waiter,
86489 - struct thread_info *ti);
86490 + struct task_struct *task);
86491 extern void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
86492 - struct thread_info *ti);
86493 + struct task_struct *task);
86494 extern void debug_mutex_unlock(struct mutex *lock);
86495 extern void debug_mutex_init(struct mutex *lock, const char *name,
86496 struct lock_class_key *key);
86497 diff --git a/kernel/locking/mutex.c b/kernel/locking/mutex.c
86498 index 4dd6e4c..df52693 100644
86499 --- a/kernel/locking/mutex.c
86500 +++ b/kernel/locking/mutex.c
86501 @@ -135,7 +135,7 @@ void mspin_lock(struct mspin_node **lock, struct mspin_node *node)
86502 node->locked = 1;
86503 return;
86504 }
86505 - ACCESS_ONCE(prev->next) = node;
86506 + ACCESS_ONCE_RW(prev->next) = node;
86507 smp_wmb();
86508 /* Wait until the lock holder passes the lock down */
86509 while (!ACCESS_ONCE(node->locked))
86510 @@ -156,7 +156,7 @@ static void mspin_unlock(struct mspin_node **lock, struct mspin_node *node)
86511 while (!(next = ACCESS_ONCE(node->next)))
86512 arch_mutex_cpu_relax();
86513 }
86514 - ACCESS_ONCE(next->locked) = 1;
86515 + ACCESS_ONCE_RW(next->locked) = 1;
86516 smp_wmb();
86517 }
86518
86519 @@ -520,7 +520,7 @@ slowpath:
86520 goto skip_wait;
86521
86522 debug_mutex_lock_common(lock, &waiter);
86523 - debug_mutex_add_waiter(lock, &waiter, task_thread_info(task));
86524 + debug_mutex_add_waiter(lock, &waiter, task);
86525
86526 /* add waiting tasks to the end of the waitqueue (FIFO): */
86527 list_add_tail(&waiter.list, &lock->wait_list);
86528 @@ -564,7 +564,7 @@ slowpath:
86529 schedule_preempt_disabled();
86530 spin_lock_mutex(&lock->wait_lock, flags);
86531 }
86532 - mutex_remove_waiter(lock, &waiter, current_thread_info());
86533 + mutex_remove_waiter(lock, &waiter, task);
86534 /* set it to 0 if there are no waiters left: */
86535 if (likely(list_empty(&lock->wait_list)))
86536 atomic_set(&lock->count, 0);
86537 @@ -601,7 +601,7 @@ skip_wait:
86538 return 0;
86539
86540 err:
86541 - mutex_remove_waiter(lock, &waiter, task_thread_info(task));
86542 + mutex_remove_waiter(lock, &waiter, task);
86543 spin_unlock_mutex(&lock->wait_lock, flags);
86544 debug_mutex_free_waiter(&waiter);
86545 mutex_release(&lock->dep_map, 1, ip);
86546 diff --git a/kernel/locking/rtmutex-tester.c b/kernel/locking/rtmutex-tester.c
86547 index 1d96dd0..994ff19 100644
86548 --- a/kernel/locking/rtmutex-tester.c
86549 +++ b/kernel/locking/rtmutex-tester.c
86550 @@ -22,7 +22,7 @@
86551 #define MAX_RT_TEST_MUTEXES 8
86552
86553 static spinlock_t rttest_lock;
86554 -static atomic_t rttest_event;
86555 +static atomic_unchecked_t rttest_event;
86556
86557 struct test_thread_data {
86558 int opcode;
86559 @@ -63,7 +63,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
86560
86561 case RTTEST_LOCKCONT:
86562 td->mutexes[td->opdata] = 1;
86563 - td->event = atomic_add_return(1, &rttest_event);
86564 + td->event = atomic_add_return_unchecked(1, &rttest_event);
86565 return 0;
86566
86567 case RTTEST_RESET:
86568 @@ -76,7 +76,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
86569 return 0;
86570
86571 case RTTEST_RESETEVENT:
86572 - atomic_set(&rttest_event, 0);
86573 + atomic_set_unchecked(&rttest_event, 0);
86574 return 0;
86575
86576 default:
86577 @@ -93,9 +93,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
86578 return ret;
86579
86580 td->mutexes[id] = 1;
86581 - td->event = atomic_add_return(1, &rttest_event);
86582 + td->event = atomic_add_return_unchecked(1, &rttest_event);
86583 rt_mutex_lock(&mutexes[id]);
86584 - td->event = atomic_add_return(1, &rttest_event);
86585 + td->event = atomic_add_return_unchecked(1, &rttest_event);
86586 td->mutexes[id] = 4;
86587 return 0;
86588
86589 @@ -106,9 +106,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
86590 return ret;
86591
86592 td->mutexes[id] = 1;
86593 - td->event = atomic_add_return(1, &rttest_event);
86594 + td->event = atomic_add_return_unchecked(1, &rttest_event);
86595 ret = rt_mutex_lock_interruptible(&mutexes[id], 0);
86596 - td->event = atomic_add_return(1, &rttest_event);
86597 + td->event = atomic_add_return_unchecked(1, &rttest_event);
86598 td->mutexes[id] = ret ? 0 : 4;
86599 return ret ? -EINTR : 0;
86600
86601 @@ -117,9 +117,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
86602 if (id < 0 || id >= MAX_RT_TEST_MUTEXES || td->mutexes[id] != 4)
86603 return ret;
86604
86605 - td->event = atomic_add_return(1, &rttest_event);
86606 + td->event = atomic_add_return_unchecked(1, &rttest_event);
86607 rt_mutex_unlock(&mutexes[id]);
86608 - td->event = atomic_add_return(1, &rttest_event);
86609 + td->event = atomic_add_return_unchecked(1, &rttest_event);
86610 td->mutexes[id] = 0;
86611 return 0;
86612
86613 @@ -166,7 +166,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
86614 break;
86615
86616 td->mutexes[dat] = 2;
86617 - td->event = atomic_add_return(1, &rttest_event);
86618 + td->event = atomic_add_return_unchecked(1, &rttest_event);
86619 break;
86620
86621 default:
86622 @@ -186,7 +186,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
86623 return;
86624
86625 td->mutexes[dat] = 3;
86626 - td->event = atomic_add_return(1, &rttest_event);
86627 + td->event = atomic_add_return_unchecked(1, &rttest_event);
86628 break;
86629
86630 case RTTEST_LOCKNOWAIT:
86631 @@ -198,7 +198,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
86632 return;
86633
86634 td->mutexes[dat] = 1;
86635 - td->event = atomic_add_return(1, &rttest_event);
86636 + td->event = atomic_add_return_unchecked(1, &rttest_event);
86637 return;
86638
86639 default:
86640 diff --git a/kernel/module.c b/kernel/module.c
86641 index f5a3b1e..97ebb15 100644
86642 --- a/kernel/module.c
86643 +++ b/kernel/module.c
86644 @@ -61,6 +61,7 @@
86645 #include <linux/pfn.h>
86646 #include <linux/bsearch.h>
86647 #include <linux/fips.h>
86648 +#include <linux/grsecurity.h>
86649 #include <uapi/linux/module.h>
86650 #include "module-internal.h"
86651
86652 @@ -157,7 +158,8 @@ static BLOCKING_NOTIFIER_HEAD(module_notify_list);
86653
86654 /* Bounds of module allocation, for speeding __module_address.
86655 * Protected by module_mutex. */
86656 -static unsigned long module_addr_min = -1UL, module_addr_max = 0;
86657 +static unsigned long module_addr_min_rw = -1UL, module_addr_max_rw = 0;
86658 +static unsigned long module_addr_min_rx = -1UL, module_addr_max_rx = 0;
86659
86660 int register_module_notifier(struct notifier_block * nb)
86661 {
86662 @@ -324,7 +326,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
86663 return true;
86664
86665 list_for_each_entry_rcu(mod, &modules, list) {
86666 - struct symsearch arr[] = {
86667 + struct symsearch modarr[] = {
86668 { mod->syms, mod->syms + mod->num_syms, mod->crcs,
86669 NOT_GPL_ONLY, false },
86670 { mod->gpl_syms, mod->gpl_syms + mod->num_gpl_syms,
86671 @@ -349,7 +351,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
86672 if (mod->state == MODULE_STATE_UNFORMED)
86673 continue;
86674
86675 - if (each_symbol_in_section(arr, ARRAY_SIZE(arr), mod, fn, data))
86676 + if (each_symbol_in_section(modarr, ARRAY_SIZE(modarr), mod, fn, data))
86677 return true;
86678 }
86679 return false;
86680 @@ -489,7 +491,7 @@ static int percpu_modalloc(struct module *mod, struct load_info *info)
86681 if (!pcpusec->sh_size)
86682 return 0;
86683
86684 - if (align > PAGE_SIZE) {
86685 + if (align-1 >= PAGE_SIZE) {
86686 pr_warn("%s: per-cpu alignment %li > %li\n",
86687 mod->name, align, PAGE_SIZE);
86688 align = PAGE_SIZE;
86689 @@ -1064,7 +1066,7 @@ struct module_attribute module_uevent =
86690 static ssize_t show_coresize(struct module_attribute *mattr,
86691 struct module_kobject *mk, char *buffer)
86692 {
86693 - return sprintf(buffer, "%u\n", mk->mod->core_size);
86694 + return sprintf(buffer, "%u\n", mk->mod->core_size_rx + mk->mod->core_size_rw);
86695 }
86696
86697 static struct module_attribute modinfo_coresize =
86698 @@ -1073,7 +1075,7 @@ static struct module_attribute modinfo_coresize =
86699 static ssize_t show_initsize(struct module_attribute *mattr,
86700 struct module_kobject *mk, char *buffer)
86701 {
86702 - return sprintf(buffer, "%u\n", mk->mod->init_size);
86703 + return sprintf(buffer, "%u\n", mk->mod->init_size_rx + mk->mod->init_size_rw);
86704 }
86705
86706 static struct module_attribute modinfo_initsize =
86707 @@ -1165,12 +1167,29 @@ static int check_version(Elf_Shdr *sechdrs,
86708 goto bad_version;
86709 }
86710
86711 +#ifdef CONFIG_GRKERNSEC_RANDSTRUCT
86712 + /*
86713 + * avoid potentially printing jibberish on attempted load
86714 + * of a module randomized with a different seed
86715 + */
86716 + pr_warn("no symbol version for %s\n", symname);
86717 +#else
86718 pr_warn("%s: no symbol version for %s\n", mod->name, symname);
86719 +#endif
86720 return 0;
86721
86722 bad_version:
86723 +#ifdef CONFIG_GRKERNSEC_RANDSTRUCT
86724 + /*
86725 + * avoid potentially printing jibberish on attempted load
86726 + * of a module randomized with a different seed
86727 + */
86728 + printk("attempted module disagrees about version of symbol %s\n",
86729 + symname);
86730 +#else
86731 printk("%s: disagrees about version of symbol %s\n",
86732 mod->name, symname);
86733 +#endif
86734 return 0;
86735 }
86736
86737 @@ -1286,7 +1305,7 @@ resolve_symbol_wait(struct module *mod,
86738 */
86739 #ifdef CONFIG_SYSFS
86740
86741 -#ifdef CONFIG_KALLSYMS
86742 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
86743 static inline bool sect_empty(const Elf_Shdr *sect)
86744 {
86745 return !(sect->sh_flags & SHF_ALLOC) || sect->sh_size == 0;
86746 @@ -1426,7 +1445,7 @@ static void add_notes_attrs(struct module *mod, const struct load_info *info)
86747 {
86748 unsigned int notes, loaded, i;
86749 struct module_notes_attrs *notes_attrs;
86750 - struct bin_attribute *nattr;
86751 + bin_attribute_no_const *nattr;
86752
86753 /* failed to create section attributes, so can't create notes */
86754 if (!mod->sect_attrs)
86755 @@ -1538,7 +1557,7 @@ static void del_usage_links(struct module *mod)
86756 static int module_add_modinfo_attrs(struct module *mod)
86757 {
86758 struct module_attribute *attr;
86759 - struct module_attribute *temp_attr;
86760 + module_attribute_no_const *temp_attr;
86761 int error = 0;
86762 int i;
86763
86764 @@ -1759,21 +1778,21 @@ static void set_section_ro_nx(void *base,
86765
86766 static void unset_module_core_ro_nx(struct module *mod)
86767 {
86768 - set_page_attributes(mod->module_core + mod->core_text_size,
86769 - mod->module_core + mod->core_size,
86770 + set_page_attributes(mod->module_core_rw,
86771 + mod->module_core_rw + mod->core_size_rw,
86772 set_memory_x);
86773 - set_page_attributes(mod->module_core,
86774 - mod->module_core + mod->core_ro_size,
86775 + set_page_attributes(mod->module_core_rx,
86776 + mod->module_core_rx + mod->core_size_rx,
86777 set_memory_rw);
86778 }
86779
86780 static void unset_module_init_ro_nx(struct module *mod)
86781 {
86782 - set_page_attributes(mod->module_init + mod->init_text_size,
86783 - mod->module_init + mod->init_size,
86784 + set_page_attributes(mod->module_init_rw,
86785 + mod->module_init_rw + mod->init_size_rw,
86786 set_memory_x);
86787 - set_page_attributes(mod->module_init,
86788 - mod->module_init + mod->init_ro_size,
86789 + set_page_attributes(mod->module_init_rx,
86790 + mod->module_init_rx + mod->init_size_rx,
86791 set_memory_rw);
86792 }
86793
86794 @@ -1786,14 +1805,14 @@ void set_all_modules_text_rw(void)
86795 list_for_each_entry_rcu(mod, &modules, list) {
86796 if (mod->state == MODULE_STATE_UNFORMED)
86797 continue;
86798 - if ((mod->module_core) && (mod->core_text_size)) {
86799 - set_page_attributes(mod->module_core,
86800 - mod->module_core + mod->core_text_size,
86801 + if ((mod->module_core_rx) && (mod->core_size_rx)) {
86802 + set_page_attributes(mod->module_core_rx,
86803 + mod->module_core_rx + mod->core_size_rx,
86804 set_memory_rw);
86805 }
86806 - if ((mod->module_init) && (mod->init_text_size)) {
86807 - set_page_attributes(mod->module_init,
86808 - mod->module_init + mod->init_text_size,
86809 + if ((mod->module_init_rx) && (mod->init_size_rx)) {
86810 + set_page_attributes(mod->module_init_rx,
86811 + mod->module_init_rx + mod->init_size_rx,
86812 set_memory_rw);
86813 }
86814 }
86815 @@ -1809,14 +1828,14 @@ void set_all_modules_text_ro(void)
86816 list_for_each_entry_rcu(mod, &modules, list) {
86817 if (mod->state == MODULE_STATE_UNFORMED)
86818 continue;
86819 - if ((mod->module_core) && (mod->core_text_size)) {
86820 - set_page_attributes(mod->module_core,
86821 - mod->module_core + mod->core_text_size,
86822 + if ((mod->module_core_rx) && (mod->core_size_rx)) {
86823 + set_page_attributes(mod->module_core_rx,
86824 + mod->module_core_rx + mod->core_size_rx,
86825 set_memory_ro);
86826 }
86827 - if ((mod->module_init) && (mod->init_text_size)) {
86828 - set_page_attributes(mod->module_init,
86829 - mod->module_init + mod->init_text_size,
86830 + if ((mod->module_init_rx) && (mod->init_size_rx)) {
86831 + set_page_attributes(mod->module_init_rx,
86832 + mod->module_init_rx + mod->init_size_rx,
86833 set_memory_ro);
86834 }
86835 }
86836 @@ -1867,16 +1886,19 @@ static void free_module(struct module *mod)
86837
86838 /* This may be NULL, but that's OK */
86839 unset_module_init_ro_nx(mod);
86840 - module_free(mod, mod->module_init);
86841 + module_free(mod, mod->module_init_rw);
86842 + module_free_exec(mod, mod->module_init_rx);
86843 kfree(mod->args);
86844 percpu_modfree(mod);
86845
86846 /* Free lock-classes: */
86847 - lockdep_free_key_range(mod->module_core, mod->core_size);
86848 + lockdep_free_key_range(mod->module_core_rx, mod->core_size_rx);
86849 + lockdep_free_key_range(mod->module_core_rw, mod->core_size_rw);
86850
86851 /* Finally, free the core (containing the module structure) */
86852 unset_module_core_ro_nx(mod);
86853 - module_free(mod, mod->module_core);
86854 + module_free_exec(mod, mod->module_core_rx);
86855 + module_free(mod, mod->module_core_rw);
86856
86857 #ifdef CONFIG_MPU
86858 update_protections(current->mm);
86859 @@ -1945,9 +1967,31 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
86860 int ret = 0;
86861 const struct kernel_symbol *ksym;
86862
86863 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
86864 + int is_fs_load = 0;
86865 + int register_filesystem_found = 0;
86866 + char *p;
86867 +
86868 + p = strstr(mod->args, "grsec_modharden_fs");
86869 + if (p) {
86870 + char *endptr = p + sizeof("grsec_modharden_fs") - 1;
86871 + /* copy \0 as well */
86872 + memmove(p, endptr, strlen(mod->args) - (unsigned int)(endptr - mod->args) + 1);
86873 + is_fs_load = 1;
86874 + }
86875 +#endif
86876 +
86877 for (i = 1; i < symsec->sh_size / sizeof(Elf_Sym); i++) {
86878 const char *name = info->strtab + sym[i].st_name;
86879
86880 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
86881 + /* it's a real shame this will never get ripped and copied
86882 + upstream! ;(
86883 + */
86884 + if (is_fs_load && !strcmp(name, "register_filesystem"))
86885 + register_filesystem_found = 1;
86886 +#endif
86887 +
86888 switch (sym[i].st_shndx) {
86889 case SHN_COMMON:
86890 /* We compiled with -fno-common. These are not
86891 @@ -1968,7 +2012,9 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
86892 ksym = resolve_symbol_wait(mod, info, name);
86893 /* Ok if resolved. */
86894 if (ksym && !IS_ERR(ksym)) {
86895 + pax_open_kernel();
86896 sym[i].st_value = ksym->value;
86897 + pax_close_kernel();
86898 break;
86899 }
86900
86901 @@ -1987,11 +2033,20 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
86902 secbase = (unsigned long)mod_percpu(mod);
86903 else
86904 secbase = info->sechdrs[sym[i].st_shndx].sh_addr;
86905 + pax_open_kernel();
86906 sym[i].st_value += secbase;
86907 + pax_close_kernel();
86908 break;
86909 }
86910 }
86911
86912 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
86913 + if (is_fs_load && !register_filesystem_found) {
86914 + printk(KERN_ALERT "grsec: Denied attempt to load non-fs module %.64s through mount\n", mod->name);
86915 + ret = -EPERM;
86916 + }
86917 +#endif
86918 +
86919 return ret;
86920 }
86921
86922 @@ -2075,22 +2130,12 @@ static void layout_sections(struct module *mod, struct load_info *info)
86923 || s->sh_entsize != ~0UL
86924 || strstarts(sname, ".init"))
86925 continue;
86926 - s->sh_entsize = get_offset(mod, &mod->core_size, s, i);
86927 + if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
86928 + s->sh_entsize = get_offset(mod, &mod->core_size_rw, s, i);
86929 + else
86930 + s->sh_entsize = get_offset(mod, &mod->core_size_rx, s, i);
86931 pr_debug("\t%s\n", sname);
86932 }
86933 - switch (m) {
86934 - case 0: /* executable */
86935 - mod->core_size = debug_align(mod->core_size);
86936 - mod->core_text_size = mod->core_size;
86937 - break;
86938 - case 1: /* RO: text and ro-data */
86939 - mod->core_size = debug_align(mod->core_size);
86940 - mod->core_ro_size = mod->core_size;
86941 - break;
86942 - case 3: /* whole core */
86943 - mod->core_size = debug_align(mod->core_size);
86944 - break;
86945 - }
86946 }
86947
86948 pr_debug("Init section allocation order:\n");
86949 @@ -2104,23 +2149,13 @@ static void layout_sections(struct module *mod, struct load_info *info)
86950 || s->sh_entsize != ~0UL
86951 || !strstarts(sname, ".init"))
86952 continue;
86953 - s->sh_entsize = (get_offset(mod, &mod->init_size, s, i)
86954 - | INIT_OFFSET_MASK);
86955 + if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
86956 + s->sh_entsize = get_offset(mod, &mod->init_size_rw, s, i);
86957 + else
86958 + s->sh_entsize = get_offset(mod, &mod->init_size_rx, s, i);
86959 + s->sh_entsize |= INIT_OFFSET_MASK;
86960 pr_debug("\t%s\n", sname);
86961 }
86962 - switch (m) {
86963 - case 0: /* executable */
86964 - mod->init_size = debug_align(mod->init_size);
86965 - mod->init_text_size = mod->init_size;
86966 - break;
86967 - case 1: /* RO: text and ro-data */
86968 - mod->init_size = debug_align(mod->init_size);
86969 - mod->init_ro_size = mod->init_size;
86970 - break;
86971 - case 3: /* whole init */
86972 - mod->init_size = debug_align(mod->init_size);
86973 - break;
86974 - }
86975 }
86976 }
86977
86978 @@ -2293,7 +2328,7 @@ static void layout_symtab(struct module *mod, struct load_info *info)
86979
86980 /* Put symbol section at end of init part of module. */
86981 symsect->sh_flags |= SHF_ALLOC;
86982 - symsect->sh_entsize = get_offset(mod, &mod->init_size, symsect,
86983 + symsect->sh_entsize = get_offset(mod, &mod->init_size_rx, symsect,
86984 info->index.sym) | INIT_OFFSET_MASK;
86985 pr_debug("\t%s\n", info->secstrings + symsect->sh_name);
86986
86987 @@ -2310,13 +2345,13 @@ static void layout_symtab(struct module *mod, struct load_info *info)
86988 }
86989
86990 /* Append room for core symbols at end of core part. */
86991 - info->symoffs = ALIGN(mod->core_size, symsect->sh_addralign ?: 1);
86992 - info->stroffs = mod->core_size = info->symoffs + ndst * sizeof(Elf_Sym);
86993 - mod->core_size += strtab_size;
86994 + info->symoffs = ALIGN(mod->core_size_rx, symsect->sh_addralign ?: 1);
86995 + info->stroffs = mod->core_size_rx = info->symoffs + ndst * sizeof(Elf_Sym);
86996 + mod->core_size_rx += strtab_size;
86997
86998 /* Put string table section at end of init part of module. */
86999 strsect->sh_flags |= SHF_ALLOC;
87000 - strsect->sh_entsize = get_offset(mod, &mod->init_size, strsect,
87001 + strsect->sh_entsize = get_offset(mod, &mod->init_size_rx, strsect,
87002 info->index.str) | INIT_OFFSET_MASK;
87003 pr_debug("\t%s\n", info->secstrings + strsect->sh_name);
87004 }
87005 @@ -2334,12 +2369,14 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
87006 /* Make sure we get permanent strtab: don't use info->strtab. */
87007 mod->strtab = (void *)info->sechdrs[info->index.str].sh_addr;
87008
87009 + pax_open_kernel();
87010 +
87011 /* Set types up while we still have access to sections. */
87012 for (i = 0; i < mod->num_symtab; i++)
87013 mod->symtab[i].st_info = elf_type(&mod->symtab[i], info);
87014
87015 - mod->core_symtab = dst = mod->module_core + info->symoffs;
87016 - mod->core_strtab = s = mod->module_core + info->stroffs;
87017 + mod->core_symtab = dst = mod->module_core_rx + info->symoffs;
87018 + mod->core_strtab = s = mod->module_core_rx + info->stroffs;
87019 src = mod->symtab;
87020 for (ndst = i = 0; i < mod->num_symtab; i++) {
87021 if (i == 0 ||
87022 @@ -2351,6 +2388,8 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
87023 }
87024 }
87025 mod->core_num_syms = ndst;
87026 +
87027 + pax_close_kernel();
87028 }
87029 #else
87030 static inline void layout_symtab(struct module *mod, struct load_info *info)
87031 @@ -2384,17 +2423,33 @@ void * __weak module_alloc(unsigned long size)
87032 return vmalloc_exec(size);
87033 }
87034
87035 -static void *module_alloc_update_bounds(unsigned long size)
87036 +static void *module_alloc_update_bounds_rw(unsigned long size)
87037 {
87038 void *ret = module_alloc(size);
87039
87040 if (ret) {
87041 mutex_lock(&module_mutex);
87042 /* Update module bounds. */
87043 - if ((unsigned long)ret < module_addr_min)
87044 - module_addr_min = (unsigned long)ret;
87045 - if ((unsigned long)ret + size > module_addr_max)
87046 - module_addr_max = (unsigned long)ret + size;
87047 + if ((unsigned long)ret < module_addr_min_rw)
87048 + module_addr_min_rw = (unsigned long)ret;
87049 + if ((unsigned long)ret + size > module_addr_max_rw)
87050 + module_addr_max_rw = (unsigned long)ret + size;
87051 + mutex_unlock(&module_mutex);
87052 + }
87053 + return ret;
87054 +}
87055 +
87056 +static void *module_alloc_update_bounds_rx(unsigned long size)
87057 +{
87058 + void *ret = module_alloc_exec(size);
87059 +
87060 + if (ret) {
87061 + mutex_lock(&module_mutex);
87062 + /* Update module bounds. */
87063 + if ((unsigned long)ret < module_addr_min_rx)
87064 + module_addr_min_rx = (unsigned long)ret;
87065 + if ((unsigned long)ret + size > module_addr_max_rx)
87066 + module_addr_max_rx = (unsigned long)ret + size;
87067 mutex_unlock(&module_mutex);
87068 }
87069 return ret;
87070 @@ -2651,7 +2706,15 @@ static struct module *setup_load_info(struct load_info *info, int flags)
87071 mod = (void *)info->sechdrs[info->index.mod].sh_addr;
87072
87073 if (info->index.sym == 0) {
87074 +#ifdef CONFIG_GRKERNSEC_RANDSTRUCT
87075 + /*
87076 + * avoid potentially printing jibberish on attempted load
87077 + * of a module randomized with a different seed
87078 + */
87079 + pr_warn("module has no symbols (stripped?)\n");
87080 +#else
87081 pr_warn("%s: module has no symbols (stripped?)\n", mod->name);
87082 +#endif
87083 return ERR_PTR(-ENOEXEC);
87084 }
87085
87086 @@ -2667,8 +2730,14 @@ static struct module *setup_load_info(struct load_info *info, int flags)
87087 static int check_modinfo(struct module *mod, struct load_info *info, int flags)
87088 {
87089 const char *modmagic = get_modinfo(info, "vermagic");
87090 + const char *license = get_modinfo(info, "license");
87091 int err;
87092
87093 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
87094 + if (!license || !license_is_gpl_compatible(license))
87095 + return -ENOEXEC;
87096 +#endif
87097 +
87098 if (flags & MODULE_INIT_IGNORE_VERMAGIC)
87099 modmagic = NULL;
87100
87101 @@ -2693,7 +2762,7 @@ static int check_modinfo(struct module *mod, struct load_info *info, int flags)
87102 }
87103
87104 /* Set up license info based on the info section */
87105 - set_license(mod, get_modinfo(info, "license"));
87106 + set_license(mod, license);
87107
87108 return 0;
87109 }
87110 @@ -2787,7 +2856,7 @@ static int move_module(struct module *mod, struct load_info *info)
87111 void *ptr;
87112
87113 /* Do the allocs. */
87114 - ptr = module_alloc_update_bounds(mod->core_size);
87115 + ptr = module_alloc_update_bounds_rw(mod->core_size_rw);
87116 /*
87117 * The pointer to this block is stored in the module structure
87118 * which is inside the block. Just mark it as not being a
87119 @@ -2797,11 +2866,11 @@ static int move_module(struct module *mod, struct load_info *info)
87120 if (!ptr)
87121 return -ENOMEM;
87122
87123 - memset(ptr, 0, mod->core_size);
87124 - mod->module_core = ptr;
87125 + memset(ptr, 0, mod->core_size_rw);
87126 + mod->module_core_rw = ptr;
87127
87128 - if (mod->init_size) {
87129 - ptr = module_alloc_update_bounds(mod->init_size);
87130 + if (mod->init_size_rw) {
87131 + ptr = module_alloc_update_bounds_rw(mod->init_size_rw);
87132 /*
87133 * The pointer to this block is stored in the module structure
87134 * which is inside the block. This block doesn't need to be
87135 @@ -2810,13 +2879,45 @@ static int move_module(struct module *mod, struct load_info *info)
87136 */
87137 kmemleak_ignore(ptr);
87138 if (!ptr) {
87139 - module_free(mod, mod->module_core);
87140 + module_free(mod, mod->module_core_rw);
87141 return -ENOMEM;
87142 }
87143 - memset(ptr, 0, mod->init_size);
87144 - mod->module_init = ptr;
87145 + memset(ptr, 0, mod->init_size_rw);
87146 + mod->module_init_rw = ptr;
87147 } else
87148 - mod->module_init = NULL;
87149 + mod->module_init_rw = NULL;
87150 +
87151 + ptr = module_alloc_update_bounds_rx(mod->core_size_rx);
87152 + kmemleak_not_leak(ptr);
87153 + if (!ptr) {
87154 + if (mod->module_init_rw)
87155 + module_free(mod, mod->module_init_rw);
87156 + module_free(mod, mod->module_core_rw);
87157 + return -ENOMEM;
87158 + }
87159 +
87160 + pax_open_kernel();
87161 + memset(ptr, 0, mod->core_size_rx);
87162 + pax_close_kernel();
87163 + mod->module_core_rx = ptr;
87164 +
87165 + if (mod->init_size_rx) {
87166 + ptr = module_alloc_update_bounds_rx(mod->init_size_rx);
87167 + kmemleak_ignore(ptr);
87168 + if (!ptr && mod->init_size_rx) {
87169 + module_free_exec(mod, mod->module_core_rx);
87170 + if (mod->module_init_rw)
87171 + module_free(mod, mod->module_init_rw);
87172 + module_free(mod, mod->module_core_rw);
87173 + return -ENOMEM;
87174 + }
87175 +
87176 + pax_open_kernel();
87177 + memset(ptr, 0, mod->init_size_rx);
87178 + pax_close_kernel();
87179 + mod->module_init_rx = ptr;
87180 + } else
87181 + mod->module_init_rx = NULL;
87182
87183 /* Transfer each section which specifies SHF_ALLOC */
87184 pr_debug("final section addresses:\n");
87185 @@ -2827,16 +2928,45 @@ static int move_module(struct module *mod, struct load_info *info)
87186 if (!(shdr->sh_flags & SHF_ALLOC))
87187 continue;
87188
87189 - if (shdr->sh_entsize & INIT_OFFSET_MASK)
87190 - dest = mod->module_init
87191 - + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
87192 - else
87193 - dest = mod->module_core + shdr->sh_entsize;
87194 + if (shdr->sh_entsize & INIT_OFFSET_MASK) {
87195 + if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
87196 + dest = mod->module_init_rw
87197 + + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
87198 + else
87199 + dest = mod->module_init_rx
87200 + + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
87201 + } else {
87202 + if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
87203 + dest = mod->module_core_rw + shdr->sh_entsize;
87204 + else
87205 + dest = mod->module_core_rx + shdr->sh_entsize;
87206 + }
87207 +
87208 + if (shdr->sh_type != SHT_NOBITS) {
87209 +
87210 +#ifdef CONFIG_PAX_KERNEXEC
87211 +#ifdef CONFIG_X86_64
87212 + if ((shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_EXECINSTR))
87213 + set_memory_x((unsigned long)dest, (shdr->sh_size + PAGE_SIZE) >> PAGE_SHIFT);
87214 +#endif
87215 + if (!(shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_ALLOC)) {
87216 + pax_open_kernel();
87217 + memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
87218 + pax_close_kernel();
87219 + } else
87220 +#endif
87221
87222 - if (shdr->sh_type != SHT_NOBITS)
87223 memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
87224 + }
87225 /* Update sh_addr to point to copy in image. */
87226 - shdr->sh_addr = (unsigned long)dest;
87227 +
87228 +#ifdef CONFIG_PAX_KERNEXEC
87229 + if (shdr->sh_flags & SHF_EXECINSTR)
87230 + shdr->sh_addr = ktva_ktla((unsigned long)dest);
87231 + else
87232 +#endif
87233 +
87234 + shdr->sh_addr = (unsigned long)dest;
87235 pr_debug("\t0x%lx %s\n",
87236 (long)shdr->sh_addr, info->secstrings + shdr->sh_name);
87237 }
87238 @@ -2893,12 +3023,12 @@ static void flush_module_icache(const struct module *mod)
87239 * Do it before processing of module parameters, so the module
87240 * can provide parameter accessor functions of its own.
87241 */
87242 - if (mod->module_init)
87243 - flush_icache_range((unsigned long)mod->module_init,
87244 - (unsigned long)mod->module_init
87245 - + mod->init_size);
87246 - flush_icache_range((unsigned long)mod->module_core,
87247 - (unsigned long)mod->module_core + mod->core_size);
87248 + if (mod->module_init_rx)
87249 + flush_icache_range((unsigned long)mod->module_init_rx,
87250 + (unsigned long)mod->module_init_rx
87251 + + mod->init_size_rx);
87252 + flush_icache_range((unsigned long)mod->module_core_rx,
87253 + (unsigned long)mod->module_core_rx + mod->core_size_rx);
87254
87255 set_fs(old_fs);
87256 }
87257 @@ -2955,8 +3085,10 @@ static struct module *layout_and_allocate(struct load_info *info, int flags)
87258 static void module_deallocate(struct module *mod, struct load_info *info)
87259 {
87260 percpu_modfree(mod);
87261 - module_free(mod, mod->module_init);
87262 - module_free(mod, mod->module_core);
87263 + module_free_exec(mod, mod->module_init_rx);
87264 + module_free_exec(mod, mod->module_core_rx);
87265 + module_free(mod, mod->module_init_rw);
87266 + module_free(mod, mod->module_core_rw);
87267 }
87268
87269 int __weak module_finalize(const Elf_Ehdr *hdr,
87270 @@ -2969,7 +3101,9 @@ int __weak module_finalize(const Elf_Ehdr *hdr,
87271 static int post_relocation(struct module *mod, const struct load_info *info)
87272 {
87273 /* Sort exception table now relocations are done. */
87274 + pax_open_kernel();
87275 sort_extable(mod->extable, mod->extable + mod->num_exentries);
87276 + pax_close_kernel();
87277
87278 /* Copy relocated percpu area over. */
87279 percpu_modcopy(mod, (void *)info->sechdrs[info->index.pcpu].sh_addr,
87280 @@ -3023,16 +3157,16 @@ static int do_init_module(struct module *mod)
87281 MODULE_STATE_COMING, mod);
87282
87283 /* Set RO and NX regions for core */
87284 - set_section_ro_nx(mod->module_core,
87285 - mod->core_text_size,
87286 - mod->core_ro_size,
87287 - mod->core_size);
87288 + set_section_ro_nx(mod->module_core_rx,
87289 + mod->core_size_rx,
87290 + mod->core_size_rx,
87291 + mod->core_size_rx);
87292
87293 /* Set RO and NX regions for init */
87294 - set_section_ro_nx(mod->module_init,
87295 - mod->init_text_size,
87296 - mod->init_ro_size,
87297 - mod->init_size);
87298 + set_section_ro_nx(mod->module_init_rx,
87299 + mod->init_size_rx,
87300 + mod->init_size_rx,
87301 + mod->init_size_rx);
87302
87303 do_mod_ctors(mod);
87304 /* Start the module */
87305 @@ -3093,11 +3227,12 @@ static int do_init_module(struct module *mod)
87306 mod->strtab = mod->core_strtab;
87307 #endif
87308 unset_module_init_ro_nx(mod);
87309 - module_free(mod, mod->module_init);
87310 - mod->module_init = NULL;
87311 - mod->init_size = 0;
87312 - mod->init_ro_size = 0;
87313 - mod->init_text_size = 0;
87314 + module_free(mod, mod->module_init_rw);
87315 + module_free_exec(mod, mod->module_init_rx);
87316 + mod->module_init_rw = NULL;
87317 + mod->module_init_rx = NULL;
87318 + mod->init_size_rw = 0;
87319 + mod->init_size_rx = 0;
87320 mutex_unlock(&module_mutex);
87321 wake_up_all(&module_wq);
87322
87323 @@ -3240,9 +3375,38 @@ static int load_module(struct load_info *info, const char __user *uargs,
87324 if (err)
87325 goto free_unload;
87326
87327 + /* Now copy in args */
87328 + mod->args = strndup_user(uargs, ~0UL >> 1);
87329 + if (IS_ERR(mod->args)) {
87330 + err = PTR_ERR(mod->args);
87331 + goto free_unload;
87332 + }
87333 +
87334 /* Set up MODINFO_ATTR fields */
87335 setup_modinfo(mod, info);
87336
87337 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
87338 + {
87339 + char *p, *p2;
87340 +
87341 + if (strstr(mod->args, "grsec_modharden_netdev")) {
87342 + 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);
87343 + err = -EPERM;
87344 + goto free_modinfo;
87345 + } else if ((p = strstr(mod->args, "grsec_modharden_normal"))) {
87346 + p += sizeof("grsec_modharden_normal") - 1;
87347 + p2 = strstr(p, "_");
87348 + if (p2) {
87349 + *p2 = '\0';
87350 + printk(KERN_ALERT "grsec: denied kernel module auto-load of %.64s by uid %.9s\n", mod->name, p);
87351 + *p2 = '_';
87352 + }
87353 + err = -EPERM;
87354 + goto free_modinfo;
87355 + }
87356 + }
87357 +#endif
87358 +
87359 /* Fix up syms, so that st_value is a pointer to location. */
87360 err = simplify_symbols(mod, info);
87361 if (err < 0)
87362 @@ -3258,13 +3422,6 @@ static int load_module(struct load_info *info, const char __user *uargs,
87363
87364 flush_module_icache(mod);
87365
87366 - /* Now copy in args */
87367 - mod->args = strndup_user(uargs, ~0UL >> 1);
87368 - if (IS_ERR(mod->args)) {
87369 - err = PTR_ERR(mod->args);
87370 - goto free_arch_cleanup;
87371 - }
87372 -
87373 dynamic_debug_setup(info->debug, info->num_debug);
87374
87375 /* Finally it's fully formed, ready to start executing. */
87376 @@ -3299,11 +3456,10 @@ static int load_module(struct load_info *info, const char __user *uargs,
87377 ddebug_cleanup:
87378 dynamic_debug_remove(info->debug);
87379 synchronize_sched();
87380 - kfree(mod->args);
87381 - free_arch_cleanup:
87382 module_arch_cleanup(mod);
87383 free_modinfo:
87384 free_modinfo(mod);
87385 + kfree(mod->args);
87386 free_unload:
87387 module_unload_free(mod);
87388 unlink_mod:
87389 @@ -3386,10 +3542,16 @@ static const char *get_ksymbol(struct module *mod,
87390 unsigned long nextval;
87391
87392 /* At worse, next value is at end of module */
87393 - if (within_module_init(addr, mod))
87394 - nextval = (unsigned long)mod->module_init+mod->init_text_size;
87395 + if (within_module_init_rx(addr, mod))
87396 + nextval = (unsigned long)mod->module_init_rx+mod->init_size_rx;
87397 + else if (within_module_init_rw(addr, mod))
87398 + nextval = (unsigned long)mod->module_init_rw+mod->init_size_rw;
87399 + else if (within_module_core_rx(addr, mod))
87400 + nextval = (unsigned long)mod->module_core_rx+mod->core_size_rx;
87401 + else if (within_module_core_rw(addr, mod))
87402 + nextval = (unsigned long)mod->module_core_rw+mod->core_size_rw;
87403 else
87404 - nextval = (unsigned long)mod->module_core+mod->core_text_size;
87405 + return NULL;
87406
87407 /* Scan for closest preceding symbol, and next symbol. (ELF
87408 starts real symbols at 1). */
87409 @@ -3640,7 +3802,7 @@ static int m_show(struct seq_file *m, void *p)
87410 return 0;
87411
87412 seq_printf(m, "%s %u",
87413 - mod->name, mod->init_size + mod->core_size);
87414 + mod->name, mod->init_size_rx + mod->init_size_rw + mod->core_size_rx + mod->core_size_rw);
87415 print_unload_info(m, mod);
87416
87417 /* Informative for users. */
87418 @@ -3649,7 +3811,7 @@ static int m_show(struct seq_file *m, void *p)
87419 mod->state == MODULE_STATE_COMING ? "Loading":
87420 "Live");
87421 /* Used by oprofile and other similar tools. */
87422 - seq_printf(m, " 0x%pK", mod->module_core);
87423 + seq_printf(m, " 0x%pK 0x%pK", mod->module_core_rx, mod->module_core_rw);
87424
87425 /* Taints info */
87426 if (mod->taints)
87427 @@ -3685,7 +3847,17 @@ static const struct file_operations proc_modules_operations = {
87428
87429 static int __init proc_modules_init(void)
87430 {
87431 +#ifndef CONFIG_GRKERNSEC_HIDESYM
87432 +#ifdef CONFIG_GRKERNSEC_PROC_USER
87433 + proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
87434 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
87435 + proc_create("modules", S_IRUSR | S_IRGRP, NULL, &proc_modules_operations);
87436 +#else
87437 proc_create("modules", 0, NULL, &proc_modules_operations);
87438 +#endif
87439 +#else
87440 + proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
87441 +#endif
87442 return 0;
87443 }
87444 module_init(proc_modules_init);
87445 @@ -3746,14 +3918,14 @@ struct module *__module_address(unsigned long addr)
87446 {
87447 struct module *mod;
87448
87449 - if (addr < module_addr_min || addr > module_addr_max)
87450 + if ((addr < module_addr_min_rx || addr > module_addr_max_rx) &&
87451 + (addr < module_addr_min_rw || addr > module_addr_max_rw))
87452 return NULL;
87453
87454 list_for_each_entry_rcu(mod, &modules, list) {
87455 if (mod->state == MODULE_STATE_UNFORMED)
87456 continue;
87457 - if (within_module_core(addr, mod)
87458 - || within_module_init(addr, mod))
87459 + if (within_module_init(addr, mod) || within_module_core(addr, mod))
87460 return mod;
87461 }
87462 return NULL;
87463 @@ -3788,11 +3960,20 @@ bool is_module_text_address(unsigned long addr)
87464 */
87465 struct module *__module_text_address(unsigned long addr)
87466 {
87467 - struct module *mod = __module_address(addr);
87468 + struct module *mod;
87469 +
87470 +#ifdef CONFIG_X86_32
87471 + addr = ktla_ktva(addr);
87472 +#endif
87473 +
87474 + if (addr < module_addr_min_rx || addr > module_addr_max_rx)
87475 + return NULL;
87476 +
87477 + mod = __module_address(addr);
87478 +
87479 if (mod) {
87480 /* Make sure it's within the text section. */
87481 - if (!within(addr, mod->module_init, mod->init_text_size)
87482 - && !within(addr, mod->module_core, mod->core_text_size))
87483 + if (!within_module_init_rx(addr, mod) && !within_module_core_rx(addr, mod))
87484 mod = NULL;
87485 }
87486 return mod;
87487 diff --git a/kernel/notifier.c b/kernel/notifier.c
87488 index 2d5cc4c..d9ea600 100644
87489 --- a/kernel/notifier.c
87490 +++ b/kernel/notifier.c
87491 @@ -5,6 +5,7 @@
87492 #include <linux/rcupdate.h>
87493 #include <linux/vmalloc.h>
87494 #include <linux/reboot.h>
87495 +#include <linux/mm.h>
87496
87497 /*
87498 * Notifier list for kernel code which wants to be called
87499 @@ -24,10 +25,12 @@ static int notifier_chain_register(struct notifier_block **nl,
87500 while ((*nl) != NULL) {
87501 if (n->priority > (*nl)->priority)
87502 break;
87503 - nl = &((*nl)->next);
87504 + nl = (struct notifier_block **)&((*nl)->next);
87505 }
87506 - n->next = *nl;
87507 + pax_open_kernel();
87508 + *(const void **)&n->next = *nl;
87509 rcu_assign_pointer(*nl, n);
87510 + pax_close_kernel();
87511 return 0;
87512 }
87513
87514 @@ -39,10 +42,12 @@ static int notifier_chain_cond_register(struct notifier_block **nl,
87515 return 0;
87516 if (n->priority > (*nl)->priority)
87517 break;
87518 - nl = &((*nl)->next);
87519 + nl = (struct notifier_block **)&((*nl)->next);
87520 }
87521 - n->next = *nl;
87522 + pax_open_kernel();
87523 + *(const void **)&n->next = *nl;
87524 rcu_assign_pointer(*nl, n);
87525 + pax_close_kernel();
87526 return 0;
87527 }
87528
87529 @@ -51,10 +56,12 @@ static int notifier_chain_unregister(struct notifier_block **nl,
87530 {
87531 while ((*nl) != NULL) {
87532 if ((*nl) == n) {
87533 + pax_open_kernel();
87534 rcu_assign_pointer(*nl, n->next);
87535 + pax_close_kernel();
87536 return 0;
87537 }
87538 - nl = &((*nl)->next);
87539 + nl = (struct notifier_block **)&((*nl)->next);
87540 }
87541 return -ENOENT;
87542 }
87543 diff --git a/kernel/padata.c b/kernel/padata.c
87544 index 2abd25d..02c4faa 100644
87545 --- a/kernel/padata.c
87546 +++ b/kernel/padata.c
87547 @@ -54,7 +54,7 @@ static int padata_cpu_hash(struct parallel_data *pd)
87548 * seq_nr mod. number of cpus in use.
87549 */
87550
87551 - seq_nr = atomic_inc_return(&pd->seq_nr);
87552 + seq_nr = atomic_inc_return_unchecked(&pd->seq_nr);
87553 cpu_index = seq_nr % cpumask_weight(pd->cpumask.pcpu);
87554
87555 return padata_index_to_cpu(pd, cpu_index);
87556 @@ -428,7 +428,7 @@ static struct parallel_data *padata_alloc_pd(struct padata_instance *pinst,
87557 padata_init_pqueues(pd);
87558 padata_init_squeues(pd);
87559 setup_timer(&pd->timer, padata_reorder_timer, (unsigned long)pd);
87560 - atomic_set(&pd->seq_nr, -1);
87561 + atomic_set_unchecked(&pd->seq_nr, -1);
87562 atomic_set(&pd->reorder_objects, 0);
87563 atomic_set(&pd->refcnt, 0);
87564 pd->pinst = pinst;
87565 diff --git a/kernel/panic.c b/kernel/panic.c
87566 index c00b4ce..98c7d1a 100644
87567 --- a/kernel/panic.c
87568 +++ b/kernel/panic.c
87569 @@ -52,7 +52,7 @@ EXPORT_SYMBOL(panic_blink);
87570 /*
87571 * Stop ourself in panic -- architecture code may override this
87572 */
87573 -void __weak panic_smp_self_stop(void)
87574 +void __weak __noreturn panic_smp_self_stop(void)
87575 {
87576 while (1)
87577 cpu_relax();
87578 @@ -407,7 +407,7 @@ static void warn_slowpath_common(const char *file, int line, void *caller,
87579 disable_trace_on_warning();
87580
87581 pr_warn("------------[ cut here ]------------\n");
87582 - pr_warn("WARNING: CPU: %d PID: %d at %s:%d %pS()\n",
87583 + pr_warn("WARNING: CPU: %d PID: %d at %s:%d %pA()\n",
87584 raw_smp_processor_id(), current->pid, file, line, caller);
87585
87586 if (args)
87587 @@ -461,7 +461,8 @@ EXPORT_SYMBOL(warn_slowpath_null);
87588 */
87589 void __stack_chk_fail(void)
87590 {
87591 - panic("stack-protector: Kernel stack is corrupted in: %p\n",
87592 + dump_stack();
87593 + panic("stack-protector: Kernel stack is corrupted in: %pA\n",
87594 __builtin_return_address(0));
87595 }
87596 EXPORT_SYMBOL(__stack_chk_fail);
87597 diff --git a/kernel/pid.c b/kernel/pid.c
87598 index 9b9a266..c20ef80 100644
87599 --- a/kernel/pid.c
87600 +++ b/kernel/pid.c
87601 @@ -33,6 +33,7 @@
87602 #include <linux/rculist.h>
87603 #include <linux/bootmem.h>
87604 #include <linux/hash.h>
87605 +#include <linux/security.h>
87606 #include <linux/pid_namespace.h>
87607 #include <linux/init_task.h>
87608 #include <linux/syscalls.h>
87609 @@ -47,7 +48,7 @@ struct pid init_struct_pid = INIT_STRUCT_PID;
87610
87611 int pid_max = PID_MAX_DEFAULT;
87612
87613 -#define RESERVED_PIDS 300
87614 +#define RESERVED_PIDS 500
87615
87616 int pid_max_min = RESERVED_PIDS + 1;
87617 int pid_max_max = PID_MAX_LIMIT;
87618 @@ -445,10 +446,18 @@ EXPORT_SYMBOL(pid_task);
87619 */
87620 struct task_struct *find_task_by_pid_ns(pid_t nr, struct pid_namespace *ns)
87621 {
87622 + struct task_struct *task;
87623 +
87624 rcu_lockdep_assert(rcu_read_lock_held(),
87625 "find_task_by_pid_ns() needs rcu_read_lock()"
87626 " protection");
87627 - return pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
87628 +
87629 + task = pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
87630 +
87631 + if (gr_pid_is_chrooted(task))
87632 + return NULL;
87633 +
87634 + return task;
87635 }
87636
87637 struct task_struct *find_task_by_vpid(pid_t vnr)
87638 @@ -456,6 +465,14 @@ struct task_struct *find_task_by_vpid(pid_t vnr)
87639 return find_task_by_pid_ns(vnr, task_active_pid_ns(current));
87640 }
87641
87642 +struct task_struct *find_task_by_vpid_unrestricted(pid_t vnr)
87643 +{
87644 + rcu_lockdep_assert(rcu_read_lock_held(),
87645 + "find_task_by_pid_ns() needs rcu_read_lock()"
87646 + " protection");
87647 + return pid_task(find_pid_ns(vnr, task_active_pid_ns(current)), PIDTYPE_PID);
87648 +}
87649 +
87650 struct pid *get_task_pid(struct task_struct *task, enum pid_type type)
87651 {
87652 struct pid *pid;
87653 diff --git a/kernel/pid_namespace.c b/kernel/pid_namespace.c
87654 index 06c62de..a0ca23f 100644
87655 --- a/kernel/pid_namespace.c
87656 +++ b/kernel/pid_namespace.c
87657 @@ -253,7 +253,7 @@ static int pid_ns_ctl_handler(struct ctl_table *table, int write,
87658 void __user *buffer, size_t *lenp, loff_t *ppos)
87659 {
87660 struct pid_namespace *pid_ns = task_active_pid_ns(current);
87661 - struct ctl_table tmp = *table;
87662 + ctl_table_no_const tmp = *table;
87663
87664 if (write && !ns_capable(pid_ns->user_ns, CAP_SYS_ADMIN))
87665 return -EPERM;
87666 @@ -318,7 +318,9 @@ static void *pidns_get(struct task_struct *task)
87667 struct pid_namespace *ns;
87668
87669 rcu_read_lock();
87670 - ns = get_pid_ns(task_active_pid_ns(task));
87671 + ns = task_active_pid_ns(task);
87672 + if (ns)
87673 + get_pid_ns(ns);
87674 rcu_read_unlock();
87675
87676 return ns;
87677 diff --git a/kernel/posix-cpu-timers.c b/kernel/posix-cpu-timers.c
87678 index c7f31aa..2b44977 100644
87679 --- a/kernel/posix-cpu-timers.c
87680 +++ b/kernel/posix-cpu-timers.c
87681 @@ -1521,14 +1521,14 @@ struct k_clock clock_posix_cpu = {
87682
87683 static __init int init_posix_cpu_timers(void)
87684 {
87685 - struct k_clock process = {
87686 + static struct k_clock process = {
87687 .clock_getres = process_cpu_clock_getres,
87688 .clock_get = process_cpu_clock_get,
87689 .timer_create = process_cpu_timer_create,
87690 .nsleep = process_cpu_nsleep,
87691 .nsleep_restart = process_cpu_nsleep_restart,
87692 };
87693 - struct k_clock thread = {
87694 + static struct k_clock thread = {
87695 .clock_getres = thread_cpu_clock_getres,
87696 .clock_get = thread_cpu_clock_get,
87697 .timer_create = thread_cpu_timer_create,
87698 diff --git a/kernel/posix-timers.c b/kernel/posix-timers.c
87699 index 424c2d4..679242f 100644
87700 --- a/kernel/posix-timers.c
87701 +++ b/kernel/posix-timers.c
87702 @@ -43,6 +43,7 @@
87703 #include <linux/hash.h>
87704 #include <linux/posix-clock.h>
87705 #include <linux/posix-timers.h>
87706 +#include <linux/grsecurity.h>
87707 #include <linux/syscalls.h>
87708 #include <linux/wait.h>
87709 #include <linux/workqueue.h>
87710 @@ -122,7 +123,7 @@ static DEFINE_SPINLOCK(hash_lock);
87711 * which we beg off on and pass to do_sys_settimeofday().
87712 */
87713
87714 -static struct k_clock posix_clocks[MAX_CLOCKS];
87715 +static struct k_clock *posix_clocks[MAX_CLOCKS];
87716
87717 /*
87718 * These ones are defined below.
87719 @@ -275,7 +276,7 @@ static int posix_get_tai(clockid_t which_clock, struct timespec *tp)
87720 */
87721 static __init int init_posix_timers(void)
87722 {
87723 - struct k_clock clock_realtime = {
87724 + static struct k_clock clock_realtime = {
87725 .clock_getres = hrtimer_get_res,
87726 .clock_get = posix_clock_realtime_get,
87727 .clock_set = posix_clock_realtime_set,
87728 @@ -287,7 +288,7 @@ static __init int init_posix_timers(void)
87729 .timer_get = common_timer_get,
87730 .timer_del = common_timer_del,
87731 };
87732 - struct k_clock clock_monotonic = {
87733 + static struct k_clock clock_monotonic = {
87734 .clock_getres = hrtimer_get_res,
87735 .clock_get = posix_ktime_get_ts,
87736 .nsleep = common_nsleep,
87737 @@ -297,19 +298,19 @@ static __init int init_posix_timers(void)
87738 .timer_get = common_timer_get,
87739 .timer_del = common_timer_del,
87740 };
87741 - struct k_clock clock_monotonic_raw = {
87742 + static struct k_clock clock_monotonic_raw = {
87743 .clock_getres = hrtimer_get_res,
87744 .clock_get = posix_get_monotonic_raw,
87745 };
87746 - struct k_clock clock_realtime_coarse = {
87747 + static struct k_clock clock_realtime_coarse = {
87748 .clock_getres = posix_get_coarse_res,
87749 .clock_get = posix_get_realtime_coarse,
87750 };
87751 - struct k_clock clock_monotonic_coarse = {
87752 + static struct k_clock clock_monotonic_coarse = {
87753 .clock_getres = posix_get_coarse_res,
87754 .clock_get = posix_get_monotonic_coarse,
87755 };
87756 - struct k_clock clock_tai = {
87757 + static struct k_clock clock_tai = {
87758 .clock_getres = hrtimer_get_res,
87759 .clock_get = posix_get_tai,
87760 .nsleep = common_nsleep,
87761 @@ -319,7 +320,7 @@ static __init int init_posix_timers(void)
87762 .timer_get = common_timer_get,
87763 .timer_del = common_timer_del,
87764 };
87765 - struct k_clock clock_boottime = {
87766 + static struct k_clock clock_boottime = {
87767 .clock_getres = hrtimer_get_res,
87768 .clock_get = posix_get_boottime,
87769 .nsleep = common_nsleep,
87770 @@ -531,7 +532,7 @@ void posix_timers_register_clock(const clockid_t clock_id,
87771 return;
87772 }
87773
87774 - posix_clocks[clock_id] = *new_clock;
87775 + posix_clocks[clock_id] = new_clock;
87776 }
87777 EXPORT_SYMBOL_GPL(posix_timers_register_clock);
87778
87779 @@ -577,9 +578,9 @@ static struct k_clock *clockid_to_kclock(const clockid_t id)
87780 return (id & CLOCKFD_MASK) == CLOCKFD ?
87781 &clock_posix_dynamic : &clock_posix_cpu;
87782
87783 - if (id >= MAX_CLOCKS || !posix_clocks[id].clock_getres)
87784 + if (id >= MAX_CLOCKS || !posix_clocks[id] || !posix_clocks[id]->clock_getres)
87785 return NULL;
87786 - return &posix_clocks[id];
87787 + return posix_clocks[id];
87788 }
87789
87790 static int common_timer_create(struct k_itimer *new_timer)
87791 @@ -597,7 +598,7 @@ SYSCALL_DEFINE3(timer_create, const clockid_t, which_clock,
87792 struct k_clock *kc = clockid_to_kclock(which_clock);
87793 struct k_itimer *new_timer;
87794 int error, new_timer_id;
87795 - sigevent_t event;
87796 + sigevent_t event = { };
87797 int it_id_set = IT_ID_NOT_SET;
87798
87799 if (!kc)
87800 @@ -1011,6 +1012,13 @@ SYSCALL_DEFINE2(clock_settime, const clockid_t, which_clock,
87801 if (copy_from_user(&new_tp, tp, sizeof (*tp)))
87802 return -EFAULT;
87803
87804 + /* only the CLOCK_REALTIME clock can be set, all other clocks
87805 + have their clock_set fptr set to a nosettime dummy function
87806 + CLOCK_REALTIME has a NULL clock_set fptr which causes it to
87807 + call common_clock_set, which calls do_sys_settimeofday, which
87808 + we hook
87809 + */
87810 +
87811 return kc->clock_set(which_clock, &new_tp);
87812 }
87813
87814 diff --git a/kernel/power/Kconfig b/kernel/power/Kconfig
87815 index 2fac9cc..56fef29 100644
87816 --- a/kernel/power/Kconfig
87817 +++ b/kernel/power/Kconfig
87818 @@ -24,6 +24,8 @@ config HIBERNATE_CALLBACKS
87819 config HIBERNATION
87820 bool "Hibernation (aka 'suspend to disk')"
87821 depends on SWAP && ARCH_HIBERNATION_POSSIBLE
87822 + depends on !GRKERNSEC_KMEM
87823 + depends on !PAX_MEMORY_SANITIZE
87824 select HIBERNATE_CALLBACKS
87825 select LZO_COMPRESS
87826 select LZO_DECOMPRESS
87827 diff --git a/kernel/power/process.c b/kernel/power/process.c
87828 index 06ec886..9dba35e 100644
87829 --- a/kernel/power/process.c
87830 +++ b/kernel/power/process.c
87831 @@ -34,6 +34,7 @@ static int try_to_freeze_tasks(bool user_only)
87832 unsigned int elapsed_msecs;
87833 bool wakeup = false;
87834 int sleep_usecs = USEC_PER_MSEC;
87835 + bool timedout = false;
87836
87837 do_gettimeofday(&start);
87838
87839 @@ -44,13 +45,20 @@ static int try_to_freeze_tasks(bool user_only)
87840
87841 while (true) {
87842 todo = 0;
87843 + if (time_after(jiffies, end_time))
87844 + timedout = true;
87845 read_lock(&tasklist_lock);
87846 do_each_thread(g, p) {
87847 if (p == current || !freeze_task(p))
87848 continue;
87849
87850 - if (!freezer_should_skip(p))
87851 + if (!freezer_should_skip(p)) {
87852 todo++;
87853 + if (timedout) {
87854 + printk(KERN_ERR "Task refusing to freeze:\n");
87855 + sched_show_task(p);
87856 + }
87857 + }
87858 } while_each_thread(g, p);
87859 read_unlock(&tasklist_lock);
87860
87861 @@ -59,7 +67,7 @@ static int try_to_freeze_tasks(bool user_only)
87862 todo += wq_busy;
87863 }
87864
87865 - if (!todo || time_after(jiffies, end_time))
87866 + if (!todo || timedout)
87867 break;
87868
87869 if (pm_wakeup_pending()) {
87870 diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
87871 index 97fb834..b972b27 100644
87872 --- a/kernel/printk/printk.c
87873 +++ b/kernel/printk/printk.c
87874 @@ -385,6 +385,11 @@ static int check_syslog_permissions(int type, bool from_file)
87875 if (from_file && type != SYSLOG_ACTION_OPEN)
87876 return 0;
87877
87878 +#ifdef CONFIG_GRKERNSEC_DMESG
87879 + if (grsec_enable_dmesg && !capable(CAP_SYSLOG) && !capable_nolog(CAP_SYS_ADMIN))
87880 + return -EPERM;
87881 +#endif
87882 +
87883 if (syslog_action_restricted(type)) {
87884 if (capable(CAP_SYSLOG))
87885 return 0;
87886 diff --git a/kernel/profile.c b/kernel/profile.c
87887 index 6631e1e..310c266 100644
87888 --- a/kernel/profile.c
87889 +++ b/kernel/profile.c
87890 @@ -37,7 +37,7 @@ struct profile_hit {
87891 #define NR_PROFILE_HIT (PAGE_SIZE/sizeof(struct profile_hit))
87892 #define NR_PROFILE_GRP (NR_PROFILE_HIT/PROFILE_GRPSZ)
87893
87894 -static atomic_t *prof_buffer;
87895 +static atomic_unchecked_t *prof_buffer;
87896 static unsigned long prof_len, prof_shift;
87897
87898 int prof_on __read_mostly;
87899 @@ -260,7 +260,7 @@ static void profile_flip_buffers(void)
87900 hits[i].pc = 0;
87901 continue;
87902 }
87903 - atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
87904 + atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
87905 hits[i].hits = hits[i].pc = 0;
87906 }
87907 }
87908 @@ -321,9 +321,9 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
87909 * Add the current hit(s) and flush the write-queue out
87910 * to the global buffer:
87911 */
87912 - atomic_add(nr_hits, &prof_buffer[pc]);
87913 + atomic_add_unchecked(nr_hits, &prof_buffer[pc]);
87914 for (i = 0; i < NR_PROFILE_HIT; ++i) {
87915 - atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
87916 + atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
87917 hits[i].pc = hits[i].hits = 0;
87918 }
87919 out:
87920 @@ -398,7 +398,7 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
87921 {
87922 unsigned long pc;
87923 pc = ((unsigned long)__pc - (unsigned long)_stext) >> prof_shift;
87924 - atomic_add(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
87925 + atomic_add_unchecked(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
87926 }
87927 #endif /* !CONFIG_SMP */
87928
87929 @@ -494,7 +494,7 @@ read_profile(struct file *file, char __user *buf, size_t count, loff_t *ppos)
87930 return -EFAULT;
87931 buf++; p++; count--; read++;
87932 }
87933 - pnt = (char *)prof_buffer + p - sizeof(atomic_t);
87934 + pnt = (char *)prof_buffer + p - sizeof(atomic_unchecked_t);
87935 if (copy_to_user(buf, (void *)pnt, count))
87936 return -EFAULT;
87937 read += count;
87938 @@ -525,7 +525,7 @@ static ssize_t write_profile(struct file *file, const char __user *buf,
87939 }
87940 #endif
87941 profile_discard_flip_buffers();
87942 - memset(prof_buffer, 0, prof_len * sizeof(atomic_t));
87943 + memset(prof_buffer, 0, prof_len * sizeof(atomic_unchecked_t));
87944 return count;
87945 }
87946
87947 diff --git a/kernel/ptrace.c b/kernel/ptrace.c
87948 index 1f4bcb3..99cf7ab 100644
87949 --- a/kernel/ptrace.c
87950 +++ b/kernel/ptrace.c
87951 @@ -327,7 +327,7 @@ static int ptrace_attach(struct task_struct *task, long request,
87952 if (seize)
87953 flags |= PT_SEIZED;
87954 rcu_read_lock();
87955 - if (ns_capable(__task_cred(task)->user_ns, CAP_SYS_PTRACE))
87956 + if (ns_capable_nolog(__task_cred(task)->user_ns, CAP_SYS_PTRACE))
87957 flags |= PT_PTRACE_CAP;
87958 rcu_read_unlock();
87959 task->ptrace = flags;
87960 @@ -538,7 +538,7 @@ int ptrace_readdata(struct task_struct *tsk, unsigned long src, char __user *dst
87961 break;
87962 return -EIO;
87963 }
87964 - if (copy_to_user(dst, buf, retval))
87965 + if (retval > sizeof(buf) || copy_to_user(dst, buf, retval))
87966 return -EFAULT;
87967 copied += retval;
87968 src += retval;
87969 @@ -806,7 +806,7 @@ int ptrace_request(struct task_struct *child, long request,
87970 bool seized = child->ptrace & PT_SEIZED;
87971 int ret = -EIO;
87972 siginfo_t siginfo, *si;
87973 - void __user *datavp = (void __user *) data;
87974 + void __user *datavp = (__force void __user *) data;
87975 unsigned long __user *datalp = datavp;
87976 unsigned long flags;
87977
87978 @@ -1052,14 +1052,21 @@ SYSCALL_DEFINE4(ptrace, long, request, long, pid, unsigned long, addr,
87979 goto out;
87980 }
87981
87982 + if (gr_handle_ptrace(child, request)) {
87983 + ret = -EPERM;
87984 + goto out_put_task_struct;
87985 + }
87986 +
87987 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
87988 ret = ptrace_attach(child, request, addr, data);
87989 /*
87990 * Some architectures need to do book-keeping after
87991 * a ptrace attach.
87992 */
87993 - if (!ret)
87994 + if (!ret) {
87995 arch_ptrace_attach(child);
87996 + gr_audit_ptrace(child);
87997 + }
87998 goto out_put_task_struct;
87999 }
88000
88001 @@ -1087,7 +1094,7 @@ int generic_ptrace_peekdata(struct task_struct *tsk, unsigned long addr,
88002 copied = access_process_vm(tsk, addr, &tmp, sizeof(tmp), 0);
88003 if (copied != sizeof(tmp))
88004 return -EIO;
88005 - return put_user(tmp, (unsigned long __user *)data);
88006 + return put_user(tmp, (__force unsigned long __user *)data);
88007 }
88008
88009 int generic_ptrace_pokedata(struct task_struct *tsk, unsigned long addr,
88010 @@ -1181,7 +1188,7 @@ int compat_ptrace_request(struct task_struct *child, compat_long_t request,
88011 }
88012
88013 asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
88014 - compat_long_t addr, compat_long_t data)
88015 + compat_ulong_t addr, compat_ulong_t data)
88016 {
88017 struct task_struct *child;
88018 long ret;
88019 @@ -1197,14 +1204,21 @@ asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
88020 goto out;
88021 }
88022
88023 + if (gr_handle_ptrace(child, request)) {
88024 + ret = -EPERM;
88025 + goto out_put_task_struct;
88026 + }
88027 +
88028 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
88029 ret = ptrace_attach(child, request, addr, data);
88030 /*
88031 * Some architectures need to do book-keeping after
88032 * a ptrace attach.
88033 */
88034 - if (!ret)
88035 + if (!ret) {
88036 arch_ptrace_attach(child);
88037 + gr_audit_ptrace(child);
88038 + }
88039 goto out_put_task_struct;
88040 }
88041
88042 diff --git a/kernel/rcu/srcu.c b/kernel/rcu/srcu.c
88043 index 01d5ccb..cdcbee6 100644
88044 --- a/kernel/rcu/srcu.c
88045 +++ b/kernel/rcu/srcu.c
88046 @@ -300,9 +300,9 @@ int __srcu_read_lock(struct srcu_struct *sp)
88047
88048 idx = ACCESS_ONCE(sp->completed) & 0x1;
88049 preempt_disable();
88050 - ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) += 1;
88051 + ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) += 1;
88052 smp_mb(); /* B */ /* Avoid leaking the critical section. */
88053 - ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->seq[idx]) += 1;
88054 + ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->seq[idx]) += 1;
88055 preempt_enable();
88056 return idx;
88057 }
88058 diff --git a/kernel/rcu/tiny.c b/kernel/rcu/tiny.c
88059 index 1254f31..16258dc 100644
88060 --- a/kernel/rcu/tiny.c
88061 +++ b/kernel/rcu/tiny.c
88062 @@ -46,7 +46,7 @@
88063 /* Forward declarations for tiny_plugin.h. */
88064 struct rcu_ctrlblk;
88065 static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp);
88066 -static void rcu_process_callbacks(struct softirq_action *unused);
88067 +static void rcu_process_callbacks(void);
88068 static void __call_rcu(struct rcu_head *head,
88069 void (*func)(struct rcu_head *rcu),
88070 struct rcu_ctrlblk *rcp);
88071 @@ -312,7 +312,7 @@ static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp)
88072 false));
88073 }
88074
88075 -static void rcu_process_callbacks(struct softirq_action *unused)
88076 +static __latent_entropy void rcu_process_callbacks(void)
88077 {
88078 __rcu_process_callbacks(&rcu_sched_ctrlblk);
88079 __rcu_process_callbacks(&rcu_bh_ctrlblk);
88080 diff --git a/kernel/rcu/torture.c b/kernel/rcu/torture.c
88081 index 3929cd4..421624d 100644
88082 --- a/kernel/rcu/torture.c
88083 +++ b/kernel/rcu/torture.c
88084 @@ -176,12 +176,12 @@ static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_count) =
88085 { 0 };
88086 static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_batch) =
88087 { 0 };
88088 -static atomic_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
88089 -static atomic_t n_rcu_torture_alloc;
88090 -static atomic_t n_rcu_torture_alloc_fail;
88091 -static atomic_t n_rcu_torture_free;
88092 -static atomic_t n_rcu_torture_mberror;
88093 -static atomic_t n_rcu_torture_error;
88094 +static atomic_unchecked_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
88095 +static atomic_unchecked_t n_rcu_torture_alloc;
88096 +static atomic_unchecked_t n_rcu_torture_alloc_fail;
88097 +static atomic_unchecked_t n_rcu_torture_free;
88098 +static atomic_unchecked_t n_rcu_torture_mberror;
88099 +static atomic_unchecked_t n_rcu_torture_error;
88100 static long n_rcu_torture_barrier_error;
88101 static long n_rcu_torture_boost_ktrerror;
88102 static long n_rcu_torture_boost_rterror;
88103 @@ -299,11 +299,11 @@ rcu_torture_alloc(void)
88104
88105 spin_lock_bh(&rcu_torture_lock);
88106 if (list_empty(&rcu_torture_freelist)) {
88107 - atomic_inc(&n_rcu_torture_alloc_fail);
88108 + atomic_inc_unchecked(&n_rcu_torture_alloc_fail);
88109 spin_unlock_bh(&rcu_torture_lock);
88110 return NULL;
88111 }
88112 - atomic_inc(&n_rcu_torture_alloc);
88113 + atomic_inc_unchecked(&n_rcu_torture_alloc);
88114 p = rcu_torture_freelist.next;
88115 list_del_init(p);
88116 spin_unlock_bh(&rcu_torture_lock);
88117 @@ -316,7 +316,7 @@ rcu_torture_alloc(void)
88118 static void
88119 rcu_torture_free(struct rcu_torture *p)
88120 {
88121 - atomic_inc(&n_rcu_torture_free);
88122 + atomic_inc_unchecked(&n_rcu_torture_free);
88123 spin_lock_bh(&rcu_torture_lock);
88124 list_add_tail(&p->rtort_free, &rcu_torture_freelist);
88125 spin_unlock_bh(&rcu_torture_lock);
88126 @@ -437,7 +437,7 @@ rcu_torture_cb(struct rcu_head *p)
88127 i = rp->rtort_pipe_count;
88128 if (i > RCU_TORTURE_PIPE_LEN)
88129 i = RCU_TORTURE_PIPE_LEN;
88130 - atomic_inc(&rcu_torture_wcount[i]);
88131 + atomic_inc_unchecked(&rcu_torture_wcount[i]);
88132 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
88133 rp->rtort_mbtest = 0;
88134 rcu_torture_free(rp);
88135 @@ -827,7 +827,7 @@ rcu_torture_writer(void *arg)
88136 i = old_rp->rtort_pipe_count;
88137 if (i > RCU_TORTURE_PIPE_LEN)
88138 i = RCU_TORTURE_PIPE_LEN;
88139 - atomic_inc(&rcu_torture_wcount[i]);
88140 + atomic_inc_unchecked(&rcu_torture_wcount[i]);
88141 old_rp->rtort_pipe_count++;
88142 if (gp_normal == gp_exp)
88143 exp = !!(rcu_random(&rand) & 0x80);
88144 @@ -845,7 +845,7 @@ rcu_torture_writer(void *arg)
88145 i = rp->rtort_pipe_count;
88146 if (i > RCU_TORTURE_PIPE_LEN)
88147 i = RCU_TORTURE_PIPE_LEN;
88148 - atomic_inc(&rcu_torture_wcount[i]);
88149 + atomic_inc_unchecked(&rcu_torture_wcount[i]);
88150 if (++rp->rtort_pipe_count >=
88151 RCU_TORTURE_PIPE_LEN) {
88152 rp->rtort_mbtest = 0;
88153 @@ -944,7 +944,7 @@ static void rcu_torture_timer(unsigned long unused)
88154 return;
88155 }
88156 if (p->rtort_mbtest == 0)
88157 - atomic_inc(&n_rcu_torture_mberror);
88158 + atomic_inc_unchecked(&n_rcu_torture_mberror);
88159 spin_lock(&rand_lock);
88160 cur_ops->read_delay(&rand);
88161 n_rcu_torture_timers++;
88162 @@ -1014,7 +1014,7 @@ rcu_torture_reader(void *arg)
88163 continue;
88164 }
88165 if (p->rtort_mbtest == 0)
88166 - atomic_inc(&n_rcu_torture_mberror);
88167 + atomic_inc_unchecked(&n_rcu_torture_mberror);
88168 cur_ops->read_delay(&rand);
88169 preempt_disable();
88170 pipe_count = p->rtort_pipe_count;
88171 @@ -1077,11 +1077,11 @@ rcu_torture_printk(char *page)
88172 rcu_torture_current,
88173 rcu_torture_current_version,
88174 list_empty(&rcu_torture_freelist),
88175 - atomic_read(&n_rcu_torture_alloc),
88176 - atomic_read(&n_rcu_torture_alloc_fail),
88177 - atomic_read(&n_rcu_torture_free));
88178 + atomic_read_unchecked(&n_rcu_torture_alloc),
88179 + atomic_read_unchecked(&n_rcu_torture_alloc_fail),
88180 + atomic_read_unchecked(&n_rcu_torture_free));
88181 cnt += sprintf(&page[cnt], "rtmbe: %d rtbke: %ld rtbre: %ld ",
88182 - atomic_read(&n_rcu_torture_mberror),
88183 + atomic_read_unchecked(&n_rcu_torture_mberror),
88184 n_rcu_torture_boost_ktrerror,
88185 n_rcu_torture_boost_rterror);
88186 cnt += sprintf(&page[cnt], "rtbf: %ld rtb: %ld nt: %ld ",
88187 @@ -1100,14 +1100,14 @@ rcu_torture_printk(char *page)
88188 n_barrier_attempts,
88189 n_rcu_torture_barrier_error);
88190 cnt += sprintf(&page[cnt], "\n%s%s ", torture_type, TORTURE_FLAG);
88191 - if (atomic_read(&n_rcu_torture_mberror) != 0 ||
88192 + if (atomic_read_unchecked(&n_rcu_torture_mberror) != 0 ||
88193 n_rcu_torture_barrier_error != 0 ||
88194 n_rcu_torture_boost_ktrerror != 0 ||
88195 n_rcu_torture_boost_rterror != 0 ||
88196 n_rcu_torture_boost_failure != 0 ||
88197 i > 1) {
88198 cnt += sprintf(&page[cnt], "!!! ");
88199 - atomic_inc(&n_rcu_torture_error);
88200 + atomic_inc_unchecked(&n_rcu_torture_error);
88201 WARN_ON_ONCE(1);
88202 }
88203 cnt += sprintf(&page[cnt], "Reader Pipe: ");
88204 @@ -1121,7 +1121,7 @@ rcu_torture_printk(char *page)
88205 cnt += sprintf(&page[cnt], "Free-Block Circulation: ");
88206 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
88207 cnt += sprintf(&page[cnt], " %d",
88208 - atomic_read(&rcu_torture_wcount[i]));
88209 + atomic_read_unchecked(&rcu_torture_wcount[i]));
88210 }
88211 cnt += sprintf(&page[cnt], "\n");
88212 if (cur_ops->stats)
88213 @@ -1836,7 +1836,7 @@ rcu_torture_cleanup(void)
88214
88215 rcu_torture_stats_print(); /* -After- the stats thread is stopped! */
88216
88217 - if (atomic_read(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
88218 + if (atomic_read_unchecked(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
88219 rcu_torture_print_module_parms(cur_ops, "End of test: FAILURE");
88220 else if (n_online_successes != n_online_attempts ||
88221 n_offline_successes != n_offline_attempts)
88222 @@ -1958,18 +1958,18 @@ rcu_torture_init(void)
88223
88224 rcu_torture_current = NULL;
88225 rcu_torture_current_version = 0;
88226 - atomic_set(&n_rcu_torture_alloc, 0);
88227 - atomic_set(&n_rcu_torture_alloc_fail, 0);
88228 - atomic_set(&n_rcu_torture_free, 0);
88229 - atomic_set(&n_rcu_torture_mberror, 0);
88230 - atomic_set(&n_rcu_torture_error, 0);
88231 + atomic_set_unchecked(&n_rcu_torture_alloc, 0);
88232 + atomic_set_unchecked(&n_rcu_torture_alloc_fail, 0);
88233 + atomic_set_unchecked(&n_rcu_torture_free, 0);
88234 + atomic_set_unchecked(&n_rcu_torture_mberror, 0);
88235 + atomic_set_unchecked(&n_rcu_torture_error, 0);
88236 n_rcu_torture_barrier_error = 0;
88237 n_rcu_torture_boost_ktrerror = 0;
88238 n_rcu_torture_boost_rterror = 0;
88239 n_rcu_torture_boost_failure = 0;
88240 n_rcu_torture_boosts = 0;
88241 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++)
88242 - atomic_set(&rcu_torture_wcount[i], 0);
88243 + atomic_set_unchecked(&rcu_torture_wcount[i], 0);
88244 for_each_possible_cpu(cpu) {
88245 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
88246 per_cpu(rcu_torture_count, cpu)[i] = 0;
88247 diff --git a/kernel/rcu/tree.c b/kernel/rcu/tree.c
88248 index dd08198..5ccccbe 100644
88249 --- a/kernel/rcu/tree.c
88250 +++ b/kernel/rcu/tree.c
88251 @@ -383,9 +383,9 @@ static void rcu_eqs_enter_common(struct rcu_dynticks *rdtp, long long oldval,
88252 rcu_prepare_for_idle(smp_processor_id());
88253 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
88254 smp_mb__before_atomic_inc(); /* See above. */
88255 - atomic_inc(&rdtp->dynticks);
88256 + atomic_inc_unchecked(&rdtp->dynticks);
88257 smp_mb__after_atomic_inc(); /* Force ordering with next sojourn. */
88258 - WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
88259 + WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
88260
88261 /*
88262 * It is illegal to enter an extended quiescent state while
88263 @@ -502,10 +502,10 @@ static void rcu_eqs_exit_common(struct rcu_dynticks *rdtp, long long oldval,
88264 int user)
88265 {
88266 smp_mb__before_atomic_inc(); /* Force ordering w/previous sojourn. */
88267 - atomic_inc(&rdtp->dynticks);
88268 + atomic_inc_unchecked(&rdtp->dynticks);
88269 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
88270 smp_mb__after_atomic_inc(); /* See above. */
88271 - WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
88272 + WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
88273 rcu_cleanup_after_idle(smp_processor_id());
88274 trace_rcu_dyntick(TPS("End"), oldval, rdtp->dynticks_nesting);
88275 if (!user && !is_idle_task(current)) {
88276 @@ -625,14 +625,14 @@ void rcu_nmi_enter(void)
88277 struct rcu_dynticks *rdtp = this_cpu_ptr(&rcu_dynticks);
88278
88279 if (rdtp->dynticks_nmi_nesting == 0 &&
88280 - (atomic_read(&rdtp->dynticks) & 0x1))
88281 + (atomic_read_unchecked(&rdtp->dynticks) & 0x1))
88282 return;
88283 rdtp->dynticks_nmi_nesting++;
88284 smp_mb__before_atomic_inc(); /* Force delay from prior write. */
88285 - atomic_inc(&rdtp->dynticks);
88286 + atomic_inc_unchecked(&rdtp->dynticks);
88287 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
88288 smp_mb__after_atomic_inc(); /* See above. */
88289 - WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
88290 + WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
88291 }
88292
88293 /**
88294 @@ -651,9 +651,9 @@ void rcu_nmi_exit(void)
88295 return;
88296 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
88297 smp_mb__before_atomic_inc(); /* See above. */
88298 - atomic_inc(&rdtp->dynticks);
88299 + atomic_inc_unchecked(&rdtp->dynticks);
88300 smp_mb__after_atomic_inc(); /* Force delay to next write. */
88301 - WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
88302 + WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
88303 }
88304
88305 /**
88306 @@ -666,7 +666,7 @@ void rcu_nmi_exit(void)
88307 */
88308 bool notrace __rcu_is_watching(void)
88309 {
88310 - return atomic_read(this_cpu_ptr(&rcu_dynticks.dynticks)) & 0x1;
88311 + return atomic_read_unchecked(this_cpu_ptr(&rcu_dynticks.dynticks)) & 0x1;
88312 }
88313
88314 /**
88315 @@ -749,7 +749,7 @@ static int rcu_is_cpu_rrupt_from_idle(void)
88316 static int dyntick_save_progress_counter(struct rcu_data *rdp,
88317 bool *isidle, unsigned long *maxj)
88318 {
88319 - rdp->dynticks_snap = atomic_add_return(0, &rdp->dynticks->dynticks);
88320 + rdp->dynticks_snap = atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
88321 rcu_sysidle_check_cpu(rdp, isidle, maxj);
88322 return (rdp->dynticks_snap & 0x1) == 0;
88323 }
88324 @@ -766,7 +766,7 @@ static int rcu_implicit_dynticks_qs(struct rcu_data *rdp,
88325 unsigned int curr;
88326 unsigned int snap;
88327
88328 - curr = (unsigned int)atomic_add_return(0, &rdp->dynticks->dynticks);
88329 + curr = (unsigned int)atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
88330 snap = (unsigned int)rdp->dynticks_snap;
88331
88332 /*
88333 @@ -1412,9 +1412,9 @@ static int rcu_gp_init(struct rcu_state *rsp)
88334 rdp = this_cpu_ptr(rsp->rda);
88335 rcu_preempt_check_blocked_tasks(rnp);
88336 rnp->qsmask = rnp->qsmaskinit;
88337 - ACCESS_ONCE(rnp->gpnum) = rsp->gpnum;
88338 + ACCESS_ONCE_RW(rnp->gpnum) = rsp->gpnum;
88339 WARN_ON_ONCE(rnp->completed != rsp->completed);
88340 - ACCESS_ONCE(rnp->completed) = rsp->completed;
88341 + ACCESS_ONCE_RW(rnp->completed) = rsp->completed;
88342 if (rnp == rdp->mynode)
88343 __note_gp_changes(rsp, rnp, rdp);
88344 rcu_preempt_boost_start_gp(rnp);
88345 @@ -1505,7 +1505,7 @@ static void rcu_gp_cleanup(struct rcu_state *rsp)
88346 */
88347 rcu_for_each_node_breadth_first(rsp, rnp) {
88348 raw_spin_lock_irq(&rnp->lock);
88349 - ACCESS_ONCE(rnp->completed) = rsp->gpnum;
88350 + ACCESS_ONCE_RW(rnp->completed) = rsp->gpnum;
88351 rdp = this_cpu_ptr(rsp->rda);
88352 if (rnp == rdp->mynode)
88353 __note_gp_changes(rsp, rnp, rdp);
88354 @@ -1865,7 +1865,7 @@ rcu_send_cbs_to_orphanage(int cpu, struct rcu_state *rsp,
88355 rsp->qlen += rdp->qlen;
88356 rdp->n_cbs_orphaned += rdp->qlen;
88357 rdp->qlen_lazy = 0;
88358 - ACCESS_ONCE(rdp->qlen) = 0;
88359 + ACCESS_ONCE_RW(rdp->qlen) = 0;
88360 }
88361
88362 /*
88363 @@ -2111,7 +2111,7 @@ static void rcu_do_batch(struct rcu_state *rsp, struct rcu_data *rdp)
88364 }
88365 smp_mb(); /* List handling before counting for rcu_barrier(). */
88366 rdp->qlen_lazy -= count_lazy;
88367 - ACCESS_ONCE(rdp->qlen) -= count;
88368 + ACCESS_ONCE_RW(rdp->qlen) -= count;
88369 rdp->n_cbs_invoked += count;
88370
88371 /* Reinstate batch limit if we have worked down the excess. */
88372 @@ -2308,7 +2308,7 @@ __rcu_process_callbacks(struct rcu_state *rsp)
88373 /*
88374 * Do RCU core processing for the current CPU.
88375 */
88376 -static void rcu_process_callbacks(struct softirq_action *unused)
88377 +static void rcu_process_callbacks(void)
88378 {
88379 struct rcu_state *rsp;
88380
88381 @@ -2415,7 +2415,7 @@ __call_rcu(struct rcu_head *head, void (*func)(struct rcu_head *rcu),
88382 WARN_ON_ONCE((unsigned long)head & 0x3); /* Misaligned rcu_head! */
88383 if (debug_rcu_head_queue(head)) {
88384 /* Probable double call_rcu(), so leak the callback. */
88385 - ACCESS_ONCE(head->func) = rcu_leak_callback;
88386 + ACCESS_ONCE_RW(head->func) = rcu_leak_callback;
88387 WARN_ONCE(1, "__call_rcu(): Leaked duplicate callback\n");
88388 return;
88389 }
88390 @@ -2443,7 +2443,7 @@ __call_rcu(struct rcu_head *head, void (*func)(struct rcu_head *rcu),
88391 local_irq_restore(flags);
88392 return;
88393 }
88394 - ACCESS_ONCE(rdp->qlen)++;
88395 + ACCESS_ONCE_RW(rdp->qlen)++;
88396 if (lazy)
88397 rdp->qlen_lazy++;
88398 else
88399 @@ -2652,11 +2652,11 @@ void synchronize_sched_expedited(void)
88400 * counter wrap on a 32-bit system. Quite a few more CPUs would of
88401 * course be required on a 64-bit system.
88402 */
88403 - if (ULONG_CMP_GE((ulong)atomic_long_read(&rsp->expedited_start),
88404 + if (ULONG_CMP_GE((ulong)atomic_long_read_unchecked(&rsp->expedited_start),
88405 (ulong)atomic_long_read(&rsp->expedited_done) +
88406 ULONG_MAX / 8)) {
88407 synchronize_sched();
88408 - atomic_long_inc(&rsp->expedited_wrap);
88409 + atomic_long_inc_unchecked(&rsp->expedited_wrap);
88410 return;
88411 }
88412
88413 @@ -2664,7 +2664,7 @@ void synchronize_sched_expedited(void)
88414 * Take a ticket. Note that atomic_inc_return() implies a
88415 * full memory barrier.
88416 */
88417 - snap = atomic_long_inc_return(&rsp->expedited_start);
88418 + snap = atomic_long_inc_return_unchecked(&rsp->expedited_start);
88419 firstsnap = snap;
88420 get_online_cpus();
88421 WARN_ON_ONCE(cpu_is_offline(raw_smp_processor_id()));
88422 @@ -2677,14 +2677,14 @@ void synchronize_sched_expedited(void)
88423 synchronize_sched_expedited_cpu_stop,
88424 NULL) == -EAGAIN) {
88425 put_online_cpus();
88426 - atomic_long_inc(&rsp->expedited_tryfail);
88427 + atomic_long_inc_unchecked(&rsp->expedited_tryfail);
88428
88429 /* Check to see if someone else did our work for us. */
88430 s = atomic_long_read(&rsp->expedited_done);
88431 if (ULONG_CMP_GE((ulong)s, (ulong)firstsnap)) {
88432 /* ensure test happens before caller kfree */
88433 smp_mb__before_atomic_inc(); /* ^^^ */
88434 - atomic_long_inc(&rsp->expedited_workdone1);
88435 + atomic_long_inc_unchecked(&rsp->expedited_workdone1);
88436 return;
88437 }
88438
88439 @@ -2693,7 +2693,7 @@ void synchronize_sched_expedited(void)
88440 udelay(trycount * num_online_cpus());
88441 } else {
88442 wait_rcu_gp(call_rcu_sched);
88443 - atomic_long_inc(&rsp->expedited_normal);
88444 + atomic_long_inc_unchecked(&rsp->expedited_normal);
88445 return;
88446 }
88447
88448 @@ -2702,7 +2702,7 @@ void synchronize_sched_expedited(void)
88449 if (ULONG_CMP_GE((ulong)s, (ulong)firstsnap)) {
88450 /* ensure test happens before caller kfree */
88451 smp_mb__before_atomic_inc(); /* ^^^ */
88452 - atomic_long_inc(&rsp->expedited_workdone2);
88453 + atomic_long_inc_unchecked(&rsp->expedited_workdone2);
88454 return;
88455 }
88456
88457 @@ -2714,10 +2714,10 @@ void synchronize_sched_expedited(void)
88458 * period works for us.
88459 */
88460 get_online_cpus();
88461 - snap = atomic_long_read(&rsp->expedited_start);
88462 + snap = atomic_long_read_unchecked(&rsp->expedited_start);
88463 smp_mb(); /* ensure read is before try_stop_cpus(). */
88464 }
88465 - atomic_long_inc(&rsp->expedited_stoppedcpus);
88466 + atomic_long_inc_unchecked(&rsp->expedited_stoppedcpus);
88467
88468 /*
88469 * Everyone up to our most recent fetch is covered by our grace
88470 @@ -2726,16 +2726,16 @@ void synchronize_sched_expedited(void)
88471 * than we did already did their update.
88472 */
88473 do {
88474 - atomic_long_inc(&rsp->expedited_done_tries);
88475 + atomic_long_inc_unchecked(&rsp->expedited_done_tries);
88476 s = atomic_long_read(&rsp->expedited_done);
88477 if (ULONG_CMP_GE((ulong)s, (ulong)snap)) {
88478 /* ensure test happens before caller kfree */
88479 smp_mb__before_atomic_inc(); /* ^^^ */
88480 - atomic_long_inc(&rsp->expedited_done_lost);
88481 + atomic_long_inc_unchecked(&rsp->expedited_done_lost);
88482 break;
88483 }
88484 } while (atomic_long_cmpxchg(&rsp->expedited_done, s, snap) != s);
88485 - atomic_long_inc(&rsp->expedited_done_exit);
88486 + atomic_long_inc_unchecked(&rsp->expedited_done_exit);
88487
88488 put_online_cpus();
88489 }
88490 @@ -2931,7 +2931,7 @@ static void _rcu_barrier(struct rcu_state *rsp)
88491 * ACCESS_ONCE() to prevent the compiler from speculating
88492 * the increment to precede the early-exit check.
88493 */
88494 - ACCESS_ONCE(rsp->n_barrier_done)++;
88495 + ACCESS_ONCE_RW(rsp->n_barrier_done)++;
88496 WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 1);
88497 _rcu_barrier_trace(rsp, "Inc1", -1, rsp->n_barrier_done);
88498 smp_mb(); /* Order ->n_barrier_done increment with below mechanism. */
88499 @@ -2981,7 +2981,7 @@ static void _rcu_barrier(struct rcu_state *rsp)
88500
88501 /* Increment ->n_barrier_done to prevent duplicate work. */
88502 smp_mb(); /* Keep increment after above mechanism. */
88503 - ACCESS_ONCE(rsp->n_barrier_done)++;
88504 + ACCESS_ONCE_RW(rsp->n_barrier_done)++;
88505 WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 0);
88506 _rcu_barrier_trace(rsp, "Inc2", -1, rsp->n_barrier_done);
88507 smp_mb(); /* Keep increment before caller's subsequent code. */
88508 @@ -3026,10 +3026,10 @@ rcu_boot_init_percpu_data(int cpu, struct rcu_state *rsp)
88509 rdp->grpmask = 1UL << (cpu - rdp->mynode->grplo);
88510 init_callback_list(rdp);
88511 rdp->qlen_lazy = 0;
88512 - ACCESS_ONCE(rdp->qlen) = 0;
88513 + ACCESS_ONCE_RW(rdp->qlen) = 0;
88514 rdp->dynticks = &per_cpu(rcu_dynticks, cpu);
88515 WARN_ON_ONCE(rdp->dynticks->dynticks_nesting != DYNTICK_TASK_EXIT_IDLE);
88516 - WARN_ON_ONCE(atomic_read(&rdp->dynticks->dynticks) != 1);
88517 + WARN_ON_ONCE(atomic_read_unchecked(&rdp->dynticks->dynticks) != 1);
88518 rdp->cpu = cpu;
88519 rdp->rsp = rsp;
88520 rcu_boot_init_nocb_percpu_data(rdp);
88521 @@ -3063,8 +3063,8 @@ rcu_init_percpu_data(int cpu, struct rcu_state *rsp, int preemptible)
88522 init_callback_list(rdp); /* Re-enable callbacks on this CPU. */
88523 rdp->dynticks->dynticks_nesting = DYNTICK_TASK_EXIT_IDLE;
88524 rcu_sysidle_init_percpu_data(rdp->dynticks);
88525 - atomic_set(&rdp->dynticks->dynticks,
88526 - (atomic_read(&rdp->dynticks->dynticks) & ~0x1) + 1);
88527 + atomic_set_unchecked(&rdp->dynticks->dynticks,
88528 + (atomic_read_unchecked(&rdp->dynticks->dynticks) & ~0x1) + 1);
88529 raw_spin_unlock(&rnp->lock); /* irqs remain disabled. */
88530
88531 /* Add CPU to rcu_node bitmasks. */
88532 diff --git a/kernel/rcu/tree.h b/kernel/rcu/tree.h
88533 index 52be957..365ded3 100644
88534 --- a/kernel/rcu/tree.h
88535 +++ b/kernel/rcu/tree.h
88536 @@ -87,11 +87,11 @@ struct rcu_dynticks {
88537 long long dynticks_nesting; /* Track irq/process nesting level. */
88538 /* Process level is worth LLONG_MAX/2. */
88539 int dynticks_nmi_nesting; /* Track NMI nesting level. */
88540 - atomic_t dynticks; /* Even value for idle, else odd. */
88541 + atomic_unchecked_t dynticks;/* Even value for idle, else odd. */
88542 #ifdef CONFIG_NO_HZ_FULL_SYSIDLE
88543 long long dynticks_idle_nesting;
88544 /* irq/process nesting level from idle. */
88545 - atomic_t dynticks_idle; /* Even value for idle, else odd. */
88546 + atomic_unchecked_t dynticks_idle;/* Even value for idle, else odd. */
88547 /* "Idle" excludes userspace execution. */
88548 unsigned long dynticks_idle_jiffies;
88549 /* End of last non-NMI non-idle period. */
88550 @@ -429,17 +429,17 @@ struct rcu_state {
88551 /* _rcu_barrier(). */
88552 /* End of fields guarded by barrier_mutex. */
88553
88554 - atomic_long_t expedited_start; /* Starting ticket. */
88555 - atomic_long_t expedited_done; /* Done ticket. */
88556 - atomic_long_t expedited_wrap; /* # near-wrap incidents. */
88557 - atomic_long_t expedited_tryfail; /* # acquisition failures. */
88558 - atomic_long_t expedited_workdone1; /* # done by others #1. */
88559 - atomic_long_t expedited_workdone2; /* # done by others #2. */
88560 - atomic_long_t expedited_normal; /* # fallbacks to normal. */
88561 - atomic_long_t expedited_stoppedcpus; /* # successful stop_cpus. */
88562 - atomic_long_t expedited_done_tries; /* # tries to update _done. */
88563 - atomic_long_t expedited_done_lost; /* # times beaten to _done. */
88564 - atomic_long_t expedited_done_exit; /* # times exited _done loop. */
88565 + atomic_long_unchecked_t expedited_start; /* Starting ticket. */
88566 + atomic_long_t expedited_done; /* Done ticket. */
88567 + atomic_long_unchecked_t expedited_wrap; /* # near-wrap incidents. */
88568 + atomic_long_unchecked_t expedited_tryfail; /* # acquisition failures. */
88569 + atomic_long_unchecked_t expedited_workdone1; /* # done by others #1. */
88570 + atomic_long_unchecked_t expedited_workdone2; /* # done by others #2. */
88571 + atomic_long_unchecked_t expedited_normal; /* # fallbacks to normal. */
88572 + atomic_long_unchecked_t expedited_stoppedcpus; /* # successful stop_cpus. */
88573 + atomic_long_unchecked_t expedited_done_tries; /* # tries to update _done. */
88574 + atomic_long_unchecked_t expedited_done_lost; /* # times beaten to _done. */
88575 + atomic_long_unchecked_t expedited_done_exit; /* # times exited _done loop. */
88576
88577 unsigned long jiffies_force_qs; /* Time at which to invoke */
88578 /* force_quiescent_state(). */
88579 diff --git a/kernel/rcu/tree_plugin.h b/kernel/rcu/tree_plugin.h
88580 index 08a7652..3598c7e 100644
88581 --- a/kernel/rcu/tree_plugin.h
88582 +++ b/kernel/rcu/tree_plugin.h
88583 @@ -749,7 +749,7 @@ static int rcu_preempted_readers_exp(struct rcu_node *rnp)
88584 static int sync_rcu_preempt_exp_done(struct rcu_node *rnp)
88585 {
88586 return !rcu_preempted_readers_exp(rnp) &&
88587 - ACCESS_ONCE(rnp->expmask) == 0;
88588 + ACCESS_ONCE_RW(rnp->expmask) == 0;
88589 }
88590
88591 /*
88592 @@ -905,7 +905,7 @@ void synchronize_rcu_expedited(void)
88593
88594 /* Clean up and exit. */
88595 smp_mb(); /* ensure expedited GP seen before counter increment. */
88596 - ACCESS_ONCE(sync_rcu_preempt_exp_count)++;
88597 + ACCESS_ONCE_RW(sync_rcu_preempt_exp_count)++;
88598 unlock_mb_ret:
88599 mutex_unlock(&sync_rcu_preempt_exp_mutex);
88600 mb_ret:
88601 @@ -1479,7 +1479,7 @@ static void rcu_boost_kthread_setaffinity(struct rcu_node *rnp, int outgoingcpu)
88602 free_cpumask_var(cm);
88603 }
88604
88605 -static struct smp_hotplug_thread rcu_cpu_thread_spec = {
88606 +static struct smp_hotplug_thread rcu_cpu_thread_spec __read_only = {
88607 .store = &rcu_cpu_kthread_task,
88608 .thread_should_run = rcu_cpu_kthread_should_run,
88609 .thread_fn = rcu_cpu_kthread,
88610 @@ -1946,7 +1946,7 @@ static void print_cpu_stall_info(struct rcu_state *rsp, int cpu)
88611 print_cpu_stall_fast_no_hz(fast_no_hz, cpu);
88612 pr_err("\t%d: (%lu %s) idle=%03x/%llx/%d softirq=%u/%u %s\n",
88613 cpu, ticks_value, ticks_title,
88614 - atomic_read(&rdtp->dynticks) & 0xfff,
88615 + atomic_read_unchecked(&rdtp->dynticks) & 0xfff,
88616 rdtp->dynticks_nesting, rdtp->dynticks_nmi_nesting,
88617 rdp->softirq_snap, kstat_softirqs_cpu(RCU_SOFTIRQ, cpu),
88618 fast_no_hz);
88619 @@ -2109,7 +2109,7 @@ static void __call_rcu_nocb_enqueue(struct rcu_data *rdp,
88620
88621 /* Enqueue the callback on the nocb list and update counts. */
88622 old_rhpp = xchg(&rdp->nocb_tail, rhtp);
88623 - ACCESS_ONCE(*old_rhpp) = rhp;
88624 + ACCESS_ONCE_RW(*old_rhpp) = rhp;
88625 atomic_long_add(rhcount, &rdp->nocb_q_count);
88626 atomic_long_add(rhcount_lazy, &rdp->nocb_q_count_lazy);
88627
88628 @@ -2272,12 +2272,12 @@ static int rcu_nocb_kthread(void *arg)
88629 * Extract queued callbacks, update counts, and wait
88630 * for a grace period to elapse.
88631 */
88632 - ACCESS_ONCE(rdp->nocb_head) = NULL;
88633 + ACCESS_ONCE_RW(rdp->nocb_head) = NULL;
88634 tail = xchg(&rdp->nocb_tail, &rdp->nocb_head);
88635 c = atomic_long_xchg(&rdp->nocb_q_count, 0);
88636 cl = atomic_long_xchg(&rdp->nocb_q_count_lazy, 0);
88637 - ACCESS_ONCE(rdp->nocb_p_count) += c;
88638 - ACCESS_ONCE(rdp->nocb_p_count_lazy) += cl;
88639 + ACCESS_ONCE_RW(rdp->nocb_p_count) += c;
88640 + ACCESS_ONCE_RW(rdp->nocb_p_count_lazy) += cl;
88641 rcu_nocb_wait_gp(rdp);
88642
88643 /* Each pass through the following loop invokes a callback. */
88644 @@ -2303,8 +2303,8 @@ static int rcu_nocb_kthread(void *arg)
88645 list = next;
88646 }
88647 trace_rcu_batch_end(rdp->rsp->name, c, !!list, 0, 0, 1);
88648 - ACCESS_ONCE(rdp->nocb_p_count) -= c;
88649 - ACCESS_ONCE(rdp->nocb_p_count_lazy) -= cl;
88650 + ACCESS_ONCE_RW(rdp->nocb_p_count) -= c;
88651 + ACCESS_ONCE_RW(rdp->nocb_p_count_lazy) -= cl;
88652 rdp->n_nocbs_invoked += c;
88653 }
88654 return 0;
88655 @@ -2331,7 +2331,7 @@ static void __init rcu_spawn_nocb_kthreads(struct rcu_state *rsp)
88656 t = kthread_run(rcu_nocb_kthread, rdp,
88657 "rcuo%c/%d", rsp->abbr, cpu);
88658 BUG_ON(IS_ERR(t));
88659 - ACCESS_ONCE(rdp->nocb_kthread) = t;
88660 + ACCESS_ONCE_RW(rdp->nocb_kthread) = t;
88661 }
88662 }
88663
88664 @@ -2457,11 +2457,11 @@ static void rcu_sysidle_enter(struct rcu_dynticks *rdtp, int irq)
88665
88666 /* Record start of fully idle period. */
88667 j = jiffies;
88668 - ACCESS_ONCE(rdtp->dynticks_idle_jiffies) = j;
88669 + ACCESS_ONCE_RW(rdtp->dynticks_idle_jiffies) = j;
88670 smp_mb__before_atomic_inc();
88671 - atomic_inc(&rdtp->dynticks_idle);
88672 + atomic_inc_unchecked(&rdtp->dynticks_idle);
88673 smp_mb__after_atomic_inc();
88674 - WARN_ON_ONCE(atomic_read(&rdtp->dynticks_idle) & 0x1);
88675 + WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks_idle) & 0x1);
88676 }
88677
88678 /*
88679 @@ -2526,9 +2526,9 @@ static void rcu_sysidle_exit(struct rcu_dynticks *rdtp, int irq)
88680
88681 /* Record end of idle period. */
88682 smp_mb__before_atomic_inc();
88683 - atomic_inc(&rdtp->dynticks_idle);
88684 + atomic_inc_unchecked(&rdtp->dynticks_idle);
88685 smp_mb__after_atomic_inc();
88686 - WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks_idle) & 0x1));
88687 + WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks_idle) & 0x1));
88688
88689 /*
88690 * If we are the timekeeping CPU, we are permitted to be non-idle
88691 @@ -2569,7 +2569,7 @@ static void rcu_sysidle_check_cpu(struct rcu_data *rdp, bool *isidle,
88692 WARN_ON_ONCE(smp_processor_id() != tick_do_timer_cpu);
88693
88694 /* Pick up current idle and NMI-nesting counter and check. */
88695 - cur = atomic_read(&rdtp->dynticks_idle);
88696 + cur = atomic_read_unchecked(&rdtp->dynticks_idle);
88697 if (cur & 0x1) {
88698 *isidle = false; /* We are not idle! */
88699 return;
88700 @@ -2632,7 +2632,7 @@ static void rcu_sysidle(unsigned long j)
88701 case RCU_SYSIDLE_NOT:
88702
88703 /* First time all are idle, so note a short idle period. */
88704 - ACCESS_ONCE(full_sysidle_state) = RCU_SYSIDLE_SHORT;
88705 + ACCESS_ONCE_RW(full_sysidle_state) = RCU_SYSIDLE_SHORT;
88706 break;
88707
88708 case RCU_SYSIDLE_SHORT:
88709 @@ -2669,7 +2669,7 @@ static void rcu_sysidle(unsigned long j)
88710 static void rcu_sysidle_cancel(void)
88711 {
88712 smp_mb();
88713 - ACCESS_ONCE(full_sysidle_state) = RCU_SYSIDLE_NOT;
88714 + ACCESS_ONCE_RW(full_sysidle_state) = RCU_SYSIDLE_NOT;
88715 }
88716
88717 /*
88718 @@ -2717,7 +2717,7 @@ static void rcu_sysidle_cb(struct rcu_head *rhp)
88719 smp_mb(); /* grace period precedes setting inuse. */
88720
88721 rshp = container_of(rhp, struct rcu_sysidle_head, rh);
88722 - ACCESS_ONCE(rshp->inuse) = 0;
88723 + ACCESS_ONCE_RW(rshp->inuse) = 0;
88724 }
88725
88726 /*
88727 diff --git a/kernel/rcu/tree_trace.c b/kernel/rcu/tree_trace.c
88728 index 3596797..f78391c 100644
88729 --- a/kernel/rcu/tree_trace.c
88730 +++ b/kernel/rcu/tree_trace.c
88731 @@ -121,7 +121,7 @@ static void print_one_rcu_data(struct seq_file *m, struct rcu_data *rdp)
88732 ulong2long(rdp->completed), ulong2long(rdp->gpnum),
88733 rdp->passed_quiesce, rdp->qs_pending);
88734 seq_printf(m, " dt=%d/%llx/%d df=%lu",
88735 - atomic_read(&rdp->dynticks->dynticks),
88736 + atomic_read_unchecked(&rdp->dynticks->dynticks),
88737 rdp->dynticks->dynticks_nesting,
88738 rdp->dynticks->dynticks_nmi_nesting,
88739 rdp->dynticks_fqs);
88740 @@ -182,17 +182,17 @@ static int show_rcuexp(struct seq_file *m, void *v)
88741 struct rcu_state *rsp = (struct rcu_state *)m->private;
88742
88743 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",
88744 - atomic_long_read(&rsp->expedited_start),
88745 + atomic_long_read_unchecked(&rsp->expedited_start),
88746 atomic_long_read(&rsp->expedited_done),
88747 - atomic_long_read(&rsp->expedited_wrap),
88748 - atomic_long_read(&rsp->expedited_tryfail),
88749 - atomic_long_read(&rsp->expedited_workdone1),
88750 - atomic_long_read(&rsp->expedited_workdone2),
88751 - atomic_long_read(&rsp->expedited_normal),
88752 - atomic_long_read(&rsp->expedited_stoppedcpus),
88753 - atomic_long_read(&rsp->expedited_done_tries),
88754 - atomic_long_read(&rsp->expedited_done_lost),
88755 - atomic_long_read(&rsp->expedited_done_exit));
88756 + atomic_long_read_unchecked(&rsp->expedited_wrap),
88757 + atomic_long_read_unchecked(&rsp->expedited_tryfail),
88758 + atomic_long_read_unchecked(&rsp->expedited_workdone1),
88759 + atomic_long_read_unchecked(&rsp->expedited_workdone2),
88760 + atomic_long_read_unchecked(&rsp->expedited_normal),
88761 + atomic_long_read_unchecked(&rsp->expedited_stoppedcpus),
88762 + atomic_long_read_unchecked(&rsp->expedited_done_tries),
88763 + atomic_long_read_unchecked(&rsp->expedited_done_lost),
88764 + atomic_long_read_unchecked(&rsp->expedited_done_exit));
88765 return 0;
88766 }
88767
88768 diff --git a/kernel/rcu/update.c b/kernel/rcu/update.c
88769 index 6cb3dff..dc5710f 100644
88770 --- a/kernel/rcu/update.c
88771 +++ b/kernel/rcu/update.c
88772 @@ -318,10 +318,10 @@ int rcu_jiffies_till_stall_check(void)
88773 * for CONFIG_RCU_CPU_STALL_TIMEOUT.
88774 */
88775 if (till_stall_check < 3) {
88776 - ACCESS_ONCE(rcu_cpu_stall_timeout) = 3;
88777 + ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 3;
88778 till_stall_check = 3;
88779 } else if (till_stall_check > 300) {
88780 - ACCESS_ONCE(rcu_cpu_stall_timeout) = 300;
88781 + ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 300;
88782 till_stall_check = 300;
88783 }
88784 return till_stall_check * HZ + RCU_STALL_DELAY_DELTA;
88785 diff --git a/kernel/resource.c b/kernel/resource.c
88786 index 3f285dc..5755f62 100644
88787 --- a/kernel/resource.c
88788 +++ b/kernel/resource.c
88789 @@ -152,8 +152,18 @@ static const struct file_operations proc_iomem_operations = {
88790
88791 static int __init ioresources_init(void)
88792 {
88793 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
88794 +#ifdef CONFIG_GRKERNSEC_PROC_USER
88795 + proc_create("ioports", S_IRUSR, NULL, &proc_ioports_operations);
88796 + proc_create("iomem", S_IRUSR, NULL, &proc_iomem_operations);
88797 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
88798 + proc_create("ioports", S_IRUSR | S_IRGRP, NULL, &proc_ioports_operations);
88799 + proc_create("iomem", S_IRUSR | S_IRGRP, NULL, &proc_iomem_operations);
88800 +#endif
88801 +#else
88802 proc_create("ioports", 0, NULL, &proc_ioports_operations);
88803 proc_create("iomem", 0, NULL, &proc_iomem_operations);
88804 +#endif
88805 return 0;
88806 }
88807 __initcall(ioresources_init);
88808 diff --git a/kernel/sched/auto_group.c b/kernel/sched/auto_group.c
88809 index 4a07353..66b5291 100644
88810 --- a/kernel/sched/auto_group.c
88811 +++ b/kernel/sched/auto_group.c
88812 @@ -11,7 +11,7 @@
88813
88814 unsigned int __read_mostly sysctl_sched_autogroup_enabled = 1;
88815 static struct autogroup autogroup_default;
88816 -static atomic_t autogroup_seq_nr;
88817 +static atomic_unchecked_t autogroup_seq_nr;
88818
88819 void __init autogroup_init(struct task_struct *init_task)
88820 {
88821 @@ -79,7 +79,7 @@ static inline struct autogroup *autogroup_create(void)
88822
88823 kref_init(&ag->kref);
88824 init_rwsem(&ag->lock);
88825 - ag->id = atomic_inc_return(&autogroup_seq_nr);
88826 + ag->id = atomic_inc_return_unchecked(&autogroup_seq_nr);
88827 ag->tg = tg;
88828 #ifdef CONFIG_RT_GROUP_SCHED
88829 /*
88830 diff --git a/kernel/sched/completion.c b/kernel/sched/completion.c
88831 index a63f4dc..349bbb0 100644
88832 --- a/kernel/sched/completion.c
88833 +++ b/kernel/sched/completion.c
88834 @@ -204,7 +204,7 @@ EXPORT_SYMBOL(wait_for_completion_interruptible);
88835 * Return: -ERESTARTSYS if interrupted, 0 if timed out, positive (at least 1,
88836 * or number of jiffies left till timeout) if completed.
88837 */
88838 -long __sched
88839 +long __sched __intentional_overflow(-1)
88840 wait_for_completion_interruptible_timeout(struct completion *x,
88841 unsigned long timeout)
88842 {
88843 @@ -221,7 +221,7 @@ EXPORT_SYMBOL(wait_for_completion_interruptible_timeout);
88844 *
88845 * Return: -ERESTARTSYS if interrupted, 0 if completed.
88846 */
88847 -int __sched wait_for_completion_killable(struct completion *x)
88848 +int __sched __intentional_overflow(-1) wait_for_completion_killable(struct completion *x)
88849 {
88850 long t = wait_for_common(x, MAX_SCHEDULE_TIMEOUT, TASK_KILLABLE);
88851 if (t == -ERESTARTSYS)
88852 @@ -242,7 +242,7 @@ EXPORT_SYMBOL(wait_for_completion_killable);
88853 * Return: -ERESTARTSYS if interrupted, 0 if timed out, positive (at least 1,
88854 * or number of jiffies left till timeout) if completed.
88855 */
88856 -long __sched
88857 +long __sched __intentional_overflow(-1)
88858 wait_for_completion_killable_timeout(struct completion *x,
88859 unsigned long timeout)
88860 {
88861 diff --git a/kernel/sched/core.c b/kernel/sched/core.c
88862 index c677510..132bb14 100644
88863 --- a/kernel/sched/core.c
88864 +++ b/kernel/sched/core.c
88865 @@ -1768,7 +1768,7 @@ void set_numabalancing_state(bool enabled)
88866 int sysctl_numa_balancing(struct ctl_table *table, int write,
88867 void __user *buffer, size_t *lenp, loff_t *ppos)
88868 {
88869 - struct ctl_table t;
88870 + ctl_table_no_const t;
88871 int err;
88872 int state = numabalancing_enabled;
88873
88874 @@ -2893,6 +2893,8 @@ int can_nice(const struct task_struct *p, const int nice)
88875 /* convert nice value [19,-20] to rlimit style value [1,40] */
88876 int nice_rlim = 20 - nice;
88877
88878 + gr_learn_resource(p, RLIMIT_NICE, nice_rlim, 1);
88879 +
88880 return (nice_rlim <= task_rlimit(p, RLIMIT_NICE) ||
88881 capable(CAP_SYS_NICE));
88882 }
88883 @@ -2926,7 +2928,8 @@ SYSCALL_DEFINE1(nice, int, increment)
88884 if (nice > 19)
88885 nice = 19;
88886
88887 - if (increment < 0 && !can_nice(current, nice))
88888 + if (increment < 0 && (!can_nice(current, nice) ||
88889 + gr_handle_chroot_nice()))
88890 return -EPERM;
88891
88892 retval = security_task_setnice(current, nice);
88893 @@ -3088,6 +3091,7 @@ recheck:
88894 unsigned long rlim_rtprio =
88895 task_rlimit(p, RLIMIT_RTPRIO);
88896
88897 + gr_learn_resource(p, RLIMIT_RTPRIO, param->sched_priority, 1);
88898 /* can't set/change the rt policy */
88899 if (policy != p->policy && !rlim_rtprio)
88900 return -EPERM;
88901 @@ -4254,7 +4258,7 @@ static void migrate_tasks(unsigned int dead_cpu)
88902
88903 #if defined(CONFIG_SCHED_DEBUG) && defined(CONFIG_SYSCTL)
88904
88905 -static struct ctl_table sd_ctl_dir[] = {
88906 +static ctl_table_no_const sd_ctl_dir[] __read_only = {
88907 {
88908 .procname = "sched_domain",
88909 .mode = 0555,
88910 @@ -4271,17 +4275,17 @@ static struct ctl_table sd_ctl_root[] = {
88911 {}
88912 };
88913
88914 -static struct ctl_table *sd_alloc_ctl_entry(int n)
88915 +static ctl_table_no_const *sd_alloc_ctl_entry(int n)
88916 {
88917 - struct ctl_table *entry =
88918 + ctl_table_no_const *entry =
88919 kcalloc(n, sizeof(struct ctl_table), GFP_KERNEL);
88920
88921 return entry;
88922 }
88923
88924 -static void sd_free_ctl_entry(struct ctl_table **tablep)
88925 +static void sd_free_ctl_entry(ctl_table_no_const *tablep)
88926 {
88927 - struct ctl_table *entry;
88928 + ctl_table_no_const *entry;
88929
88930 /*
88931 * In the intermediate directories, both the child directory and
88932 @@ -4289,22 +4293,25 @@ static void sd_free_ctl_entry(struct ctl_table **tablep)
88933 * will always be set. In the lowest directory the names are
88934 * static strings and all have proc handlers.
88935 */
88936 - for (entry = *tablep; entry->mode; entry++) {
88937 - if (entry->child)
88938 - sd_free_ctl_entry(&entry->child);
88939 + for (entry = tablep; entry->mode; entry++) {
88940 + if (entry->child) {
88941 + sd_free_ctl_entry(entry->child);
88942 + pax_open_kernel();
88943 + entry->child = NULL;
88944 + pax_close_kernel();
88945 + }
88946 if (entry->proc_handler == NULL)
88947 kfree(entry->procname);
88948 }
88949
88950 - kfree(*tablep);
88951 - *tablep = NULL;
88952 + kfree(tablep);
88953 }
88954
88955 static int min_load_idx = 0;
88956 static int max_load_idx = CPU_LOAD_IDX_MAX-1;
88957
88958 static void
88959 -set_table_entry(struct ctl_table *entry,
88960 +set_table_entry(ctl_table_no_const *entry,
88961 const char *procname, void *data, int maxlen,
88962 umode_t mode, proc_handler *proc_handler,
88963 bool load_idx)
88964 @@ -4324,7 +4331,7 @@ set_table_entry(struct ctl_table *entry,
88965 static struct ctl_table *
88966 sd_alloc_ctl_domain_table(struct sched_domain *sd)
88967 {
88968 - struct ctl_table *table = sd_alloc_ctl_entry(13);
88969 + ctl_table_no_const *table = sd_alloc_ctl_entry(13);
88970
88971 if (table == NULL)
88972 return NULL;
88973 @@ -4359,9 +4366,9 @@ sd_alloc_ctl_domain_table(struct sched_domain *sd)
88974 return table;
88975 }
88976
88977 -static struct ctl_table *sd_alloc_ctl_cpu_table(int cpu)
88978 +static ctl_table_no_const *sd_alloc_ctl_cpu_table(int cpu)
88979 {
88980 - struct ctl_table *entry, *table;
88981 + ctl_table_no_const *entry, *table;
88982 struct sched_domain *sd;
88983 int domain_num = 0, i;
88984 char buf[32];
88985 @@ -4388,11 +4395,13 @@ static struct ctl_table_header *sd_sysctl_header;
88986 static void register_sched_domain_sysctl(void)
88987 {
88988 int i, cpu_num = num_possible_cpus();
88989 - struct ctl_table *entry = sd_alloc_ctl_entry(cpu_num + 1);
88990 + ctl_table_no_const *entry = sd_alloc_ctl_entry(cpu_num + 1);
88991 char buf[32];
88992
88993 WARN_ON(sd_ctl_dir[0].child);
88994 + pax_open_kernel();
88995 sd_ctl_dir[0].child = entry;
88996 + pax_close_kernel();
88997
88998 if (entry == NULL)
88999 return;
89000 @@ -4415,8 +4424,12 @@ static void unregister_sched_domain_sysctl(void)
89001 if (sd_sysctl_header)
89002 unregister_sysctl_table(sd_sysctl_header);
89003 sd_sysctl_header = NULL;
89004 - if (sd_ctl_dir[0].child)
89005 - sd_free_ctl_entry(&sd_ctl_dir[0].child);
89006 + if (sd_ctl_dir[0].child) {
89007 + sd_free_ctl_entry(sd_ctl_dir[0].child);
89008 + pax_open_kernel();
89009 + sd_ctl_dir[0].child = NULL;
89010 + pax_close_kernel();
89011 + }
89012 }
89013 #else
89014 static void register_sched_domain_sysctl(void)
89015 diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
89016 index ce501de..1805320 100644
89017 --- a/kernel/sched/fair.c
89018 +++ b/kernel/sched/fair.c
89019 @@ -1652,7 +1652,7 @@ void task_numa_fault(int last_cpupid, int node, int pages, int flags)
89020
89021 static void reset_ptenuma_scan(struct task_struct *p)
89022 {
89023 - ACCESS_ONCE(p->mm->numa_scan_seq)++;
89024 + ACCESS_ONCE_RW(p->mm->numa_scan_seq)++;
89025 p->mm->numa_scan_offset = 0;
89026 }
89027
89028 @@ -6863,7 +6863,7 @@ static void nohz_idle_balance(int this_cpu, enum cpu_idle_type idle) { }
89029 * run_rebalance_domains is triggered when needed from the scheduler tick.
89030 * Also triggered for nohz idle balancing (with nohz_balancing_kick set).
89031 */
89032 -static void run_rebalance_domains(struct softirq_action *h)
89033 +static __latent_entropy void run_rebalance_domains(void)
89034 {
89035 int this_cpu = smp_processor_id();
89036 struct rq *this_rq = cpu_rq(this_cpu);
89037 diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h
89038 index 88c85b2..a1dec86 100644
89039 --- a/kernel/sched/sched.h
89040 +++ b/kernel/sched/sched.h
89041 @@ -1035,7 +1035,7 @@ struct sched_class {
89042 #ifdef CONFIG_FAIR_GROUP_SCHED
89043 void (*task_move_group) (struct task_struct *p, int on_rq);
89044 #endif
89045 -};
89046 +} __do_const;
89047
89048 #define sched_class_highest (&stop_sched_class)
89049 #define for_each_class(class) \
89050 diff --git a/kernel/signal.c b/kernel/signal.c
89051 index 940b30e..7fd6041 100644
89052 --- a/kernel/signal.c
89053 +++ b/kernel/signal.c
89054 @@ -51,12 +51,12 @@ static struct kmem_cache *sigqueue_cachep;
89055
89056 int print_fatal_signals __read_mostly;
89057
89058 -static void __user *sig_handler(struct task_struct *t, int sig)
89059 +static __sighandler_t sig_handler(struct task_struct *t, int sig)
89060 {
89061 return t->sighand->action[sig - 1].sa.sa_handler;
89062 }
89063
89064 -static int sig_handler_ignored(void __user *handler, int sig)
89065 +static int sig_handler_ignored(__sighandler_t handler, int sig)
89066 {
89067 /* Is it explicitly or implicitly ignored? */
89068 return handler == SIG_IGN ||
89069 @@ -65,7 +65,7 @@ static int sig_handler_ignored(void __user *handler, int sig)
89070
89071 static int sig_task_ignored(struct task_struct *t, int sig, bool force)
89072 {
89073 - void __user *handler;
89074 + __sighandler_t handler;
89075
89076 handler = sig_handler(t, sig);
89077
89078 @@ -369,6 +369,9 @@ __sigqueue_alloc(int sig, struct task_struct *t, gfp_t flags, int override_rlimi
89079 atomic_inc(&user->sigpending);
89080 rcu_read_unlock();
89081
89082 + if (!override_rlimit)
89083 + gr_learn_resource(t, RLIMIT_SIGPENDING, atomic_read(&user->sigpending), 1);
89084 +
89085 if (override_rlimit ||
89086 atomic_read(&user->sigpending) <=
89087 task_rlimit(t, RLIMIT_SIGPENDING)) {
89088 @@ -496,7 +499,7 @@ flush_signal_handlers(struct task_struct *t, int force_default)
89089
89090 int unhandled_signal(struct task_struct *tsk, int sig)
89091 {
89092 - void __user *handler = tsk->sighand->action[sig-1].sa.sa_handler;
89093 + __sighandler_t handler = tsk->sighand->action[sig-1].sa.sa_handler;
89094 if (is_global_init(tsk))
89095 return 1;
89096 if (handler != SIG_IGN && handler != SIG_DFL)
89097 @@ -816,6 +819,13 @@ static int check_kill_permission(int sig, struct siginfo *info,
89098 }
89099 }
89100
89101 + /* allow glibc communication via tgkill to other threads in our
89102 + thread group */
89103 + if ((info == SEND_SIG_NOINFO || info->si_code != SI_TKILL ||
89104 + sig != (SIGRTMIN+1) || task_tgid_vnr(t) != info->si_pid)
89105 + && gr_handle_signal(t, sig))
89106 + return -EPERM;
89107 +
89108 return security_task_kill(t, info, sig, 0);
89109 }
89110
89111 @@ -1199,7 +1209,7 @@ __group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
89112 return send_signal(sig, info, p, 1);
89113 }
89114
89115 -static int
89116 +int
89117 specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t)
89118 {
89119 return send_signal(sig, info, t, 0);
89120 @@ -1236,6 +1246,7 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
89121 unsigned long int flags;
89122 int ret, blocked, ignored;
89123 struct k_sigaction *action;
89124 + int is_unhandled = 0;
89125
89126 spin_lock_irqsave(&t->sighand->siglock, flags);
89127 action = &t->sighand->action[sig-1];
89128 @@ -1250,9 +1261,18 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
89129 }
89130 if (action->sa.sa_handler == SIG_DFL)
89131 t->signal->flags &= ~SIGNAL_UNKILLABLE;
89132 + if (action->sa.sa_handler == SIG_IGN || action->sa.sa_handler == SIG_DFL)
89133 + is_unhandled = 1;
89134 ret = specific_send_sig_info(sig, info, t);
89135 spin_unlock_irqrestore(&t->sighand->siglock, flags);
89136
89137 + /* only deal with unhandled signals, java etc trigger SIGSEGV during
89138 + normal operation */
89139 + if (is_unhandled) {
89140 + gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, t);
89141 + gr_handle_crash(t, sig);
89142 + }
89143 +
89144 return ret;
89145 }
89146
89147 @@ -1319,8 +1339,11 @@ int group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
89148 ret = check_kill_permission(sig, info, p);
89149 rcu_read_unlock();
89150
89151 - if (!ret && sig)
89152 + if (!ret && sig) {
89153 ret = do_send_sig_info(sig, info, p, true);
89154 + if (!ret)
89155 + gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, p);
89156 + }
89157
89158 return ret;
89159 }
89160 @@ -2926,7 +2949,15 @@ do_send_specific(pid_t tgid, pid_t pid, int sig, struct siginfo *info)
89161 int error = -ESRCH;
89162
89163 rcu_read_lock();
89164 - p = find_task_by_vpid(pid);
89165 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
89166 + /* allow glibc communication via tgkill to other threads in our
89167 + thread group */
89168 + if (grsec_enable_chroot_findtask && info->si_code == SI_TKILL &&
89169 + sig == (SIGRTMIN+1) && tgid == info->si_pid)
89170 + p = find_task_by_vpid_unrestricted(pid);
89171 + else
89172 +#endif
89173 + p = find_task_by_vpid(pid);
89174 if (p && (tgid <= 0 || task_tgid_vnr(p) == tgid)) {
89175 error = check_kill_permission(sig, info, p);
89176 /*
89177 @@ -3240,8 +3271,8 @@ COMPAT_SYSCALL_DEFINE2(sigaltstack,
89178 }
89179 seg = get_fs();
89180 set_fs(KERNEL_DS);
89181 - ret = do_sigaltstack((stack_t __force __user *) (uss_ptr ? &uss : NULL),
89182 - (stack_t __force __user *) &uoss,
89183 + ret = do_sigaltstack((stack_t __force_user *) (uss_ptr ? &uss : NULL),
89184 + (stack_t __force_user *) &uoss,
89185 compat_user_stack_pointer());
89186 set_fs(seg);
89187 if (ret >= 0 && uoss_ptr) {
89188 diff --git a/kernel/smpboot.c b/kernel/smpboot.c
89189 index eb89e18..a4e6792 100644
89190 --- a/kernel/smpboot.c
89191 +++ b/kernel/smpboot.c
89192 @@ -288,7 +288,7 @@ int smpboot_register_percpu_thread(struct smp_hotplug_thread *plug_thread)
89193 }
89194 smpboot_unpark_thread(plug_thread, cpu);
89195 }
89196 - list_add(&plug_thread->list, &hotplug_threads);
89197 + pax_list_add(&plug_thread->list, &hotplug_threads);
89198 out:
89199 mutex_unlock(&smpboot_threads_lock);
89200 return ret;
89201 @@ -305,7 +305,7 @@ void smpboot_unregister_percpu_thread(struct smp_hotplug_thread *plug_thread)
89202 {
89203 get_online_cpus();
89204 mutex_lock(&smpboot_threads_lock);
89205 - list_del(&plug_thread->list);
89206 + pax_list_del(&plug_thread->list);
89207 smpboot_destroy_threads(plug_thread);
89208 mutex_unlock(&smpboot_threads_lock);
89209 put_online_cpus();
89210 diff --git a/kernel/softirq.c b/kernel/softirq.c
89211 index 11025cc..bc0e4dc 100644
89212 --- a/kernel/softirq.c
89213 +++ b/kernel/softirq.c
89214 @@ -50,11 +50,11 @@ irq_cpustat_t irq_stat[NR_CPUS] ____cacheline_aligned;
89215 EXPORT_SYMBOL(irq_stat);
89216 #endif
89217
89218 -static struct softirq_action softirq_vec[NR_SOFTIRQS] __cacheline_aligned_in_smp;
89219 +static struct softirq_action softirq_vec[NR_SOFTIRQS] __read_only __aligned(PAGE_SIZE);
89220
89221 DEFINE_PER_CPU(struct task_struct *, ksoftirqd);
89222
89223 -char *softirq_to_name[NR_SOFTIRQS] = {
89224 +const char * const softirq_to_name[NR_SOFTIRQS] = {
89225 "HI", "TIMER", "NET_TX", "NET_RX", "BLOCK", "BLOCK_IOPOLL",
89226 "TASKLET", "SCHED", "HRTIMER", "RCU"
89227 };
89228 @@ -250,7 +250,7 @@ restart:
89229 kstat_incr_softirqs_this_cpu(vec_nr);
89230
89231 trace_softirq_entry(vec_nr);
89232 - h->action(h);
89233 + h->action();
89234 trace_softirq_exit(vec_nr);
89235 if (unlikely(prev_count != preempt_count())) {
89236 printk(KERN_ERR "huh, entered softirq %u %s %p"
89237 @@ -419,7 +419,7 @@ void __raise_softirq_irqoff(unsigned int nr)
89238 or_softirq_pending(1UL << nr);
89239 }
89240
89241 -void open_softirq(int nr, void (*action)(struct softirq_action *))
89242 +void __init open_softirq(int nr, void (*action)(void))
89243 {
89244 softirq_vec[nr].action = action;
89245 }
89246 @@ -475,7 +475,7 @@ void __tasklet_hi_schedule_first(struct tasklet_struct *t)
89247
89248 EXPORT_SYMBOL(__tasklet_hi_schedule_first);
89249
89250 -static void tasklet_action(struct softirq_action *a)
89251 +static __latent_entropy void tasklet_action(void)
89252 {
89253 struct tasklet_struct *list;
89254
89255 @@ -510,7 +510,7 @@ static void tasklet_action(struct softirq_action *a)
89256 }
89257 }
89258
89259 -static void tasklet_hi_action(struct softirq_action *a)
89260 +static __latent_entropy void tasklet_hi_action(void)
89261 {
89262 struct tasklet_struct *list;
89263
89264 @@ -740,7 +740,7 @@ static struct notifier_block cpu_nfb = {
89265 .notifier_call = cpu_callback
89266 };
89267
89268 -static struct smp_hotplug_thread softirq_threads = {
89269 +static struct smp_hotplug_thread softirq_threads __read_only = {
89270 .store = &ksoftirqd,
89271 .thread_should_run = ksoftirqd_should_run,
89272 .thread_fn = run_ksoftirqd,
89273 diff --git a/kernel/sys.c b/kernel/sys.c
89274 index c723113..46bf922 100644
89275 --- a/kernel/sys.c
89276 +++ b/kernel/sys.c
89277 @@ -148,6 +148,12 @@ static int set_one_prio(struct task_struct *p, int niceval, int error)
89278 error = -EACCES;
89279 goto out;
89280 }
89281 +
89282 + if (gr_handle_chroot_setpriority(p, niceval)) {
89283 + error = -EACCES;
89284 + goto out;
89285 + }
89286 +
89287 no_nice = security_task_setnice(p, niceval);
89288 if (no_nice) {
89289 error = no_nice;
89290 @@ -351,6 +357,9 @@ SYSCALL_DEFINE2(setregid, gid_t, rgid, gid_t, egid)
89291 goto error;
89292 }
89293
89294 + if (gr_check_group_change(new->gid, new->egid, INVALID_GID))
89295 + goto error;
89296 +
89297 if (rgid != (gid_t) -1 ||
89298 (egid != (gid_t) -1 && !gid_eq(kegid, old->gid)))
89299 new->sgid = new->egid;
89300 @@ -386,6 +395,10 @@ SYSCALL_DEFINE1(setgid, gid_t, gid)
89301 old = current_cred();
89302
89303 retval = -EPERM;
89304 +
89305 + if (gr_check_group_change(kgid, kgid, kgid))
89306 + goto error;
89307 +
89308 if (ns_capable(old->user_ns, CAP_SETGID))
89309 new->gid = new->egid = new->sgid = new->fsgid = kgid;
89310 else if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->sgid))
89311 @@ -403,7 +416,7 @@ error:
89312 /*
89313 * change the user struct in a credentials set to match the new UID
89314 */
89315 -static int set_user(struct cred *new)
89316 +int set_user(struct cred *new)
89317 {
89318 struct user_struct *new_user;
89319
89320 @@ -483,6 +496,9 @@ SYSCALL_DEFINE2(setreuid, uid_t, ruid, uid_t, euid)
89321 goto error;
89322 }
89323
89324 + if (gr_check_user_change(new->uid, new->euid, INVALID_UID))
89325 + goto error;
89326 +
89327 if (!uid_eq(new->uid, old->uid)) {
89328 retval = set_user(new);
89329 if (retval < 0)
89330 @@ -533,6 +549,12 @@ SYSCALL_DEFINE1(setuid, uid_t, uid)
89331 old = current_cred();
89332
89333 retval = -EPERM;
89334 +
89335 + if (gr_check_crash_uid(kuid))
89336 + goto error;
89337 + if (gr_check_user_change(kuid, kuid, kuid))
89338 + goto error;
89339 +
89340 if (ns_capable(old->user_ns, CAP_SETUID)) {
89341 new->suid = new->uid = kuid;
89342 if (!uid_eq(kuid, old->uid)) {
89343 @@ -602,6 +624,9 @@ SYSCALL_DEFINE3(setresuid, uid_t, ruid, uid_t, euid, uid_t, suid)
89344 goto error;
89345 }
89346
89347 + if (gr_check_user_change(kruid, keuid, INVALID_UID))
89348 + goto error;
89349 +
89350 if (ruid != (uid_t) -1) {
89351 new->uid = kruid;
89352 if (!uid_eq(kruid, old->uid)) {
89353 @@ -684,6 +709,9 @@ SYSCALL_DEFINE3(setresgid, gid_t, rgid, gid_t, egid, gid_t, sgid)
89354 goto error;
89355 }
89356
89357 + if (gr_check_group_change(krgid, kegid, INVALID_GID))
89358 + goto error;
89359 +
89360 if (rgid != (gid_t) -1)
89361 new->gid = krgid;
89362 if (egid != (gid_t) -1)
89363 @@ -745,12 +773,16 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
89364 uid_eq(kuid, old->suid) || uid_eq(kuid, old->fsuid) ||
89365 ns_capable(old->user_ns, CAP_SETUID)) {
89366 if (!uid_eq(kuid, old->fsuid)) {
89367 + if (gr_check_user_change(INVALID_UID, INVALID_UID, kuid))
89368 + goto error;
89369 +
89370 new->fsuid = kuid;
89371 if (security_task_fix_setuid(new, old, LSM_SETID_FS) == 0)
89372 goto change_okay;
89373 }
89374 }
89375
89376 +error:
89377 abort_creds(new);
89378 return old_fsuid;
89379
89380 @@ -783,12 +815,16 @@ SYSCALL_DEFINE1(setfsgid, gid_t, gid)
89381 if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->egid) ||
89382 gid_eq(kgid, old->sgid) || gid_eq(kgid, old->fsgid) ||
89383 ns_capable(old->user_ns, CAP_SETGID)) {
89384 + if (gr_check_group_change(INVALID_GID, INVALID_GID, kgid))
89385 + goto error;
89386 +
89387 if (!gid_eq(kgid, old->fsgid)) {
89388 new->fsgid = kgid;
89389 goto change_okay;
89390 }
89391 }
89392
89393 +error:
89394 abort_creds(new);
89395 return old_fsgid;
89396
89397 @@ -1168,19 +1204,19 @@ SYSCALL_DEFINE1(olduname, struct oldold_utsname __user *, name)
89398 return -EFAULT;
89399
89400 down_read(&uts_sem);
89401 - error = __copy_to_user(&name->sysname, &utsname()->sysname,
89402 + error = __copy_to_user(name->sysname, &utsname()->sysname,
89403 __OLD_UTS_LEN);
89404 error |= __put_user(0, name->sysname + __OLD_UTS_LEN);
89405 - error |= __copy_to_user(&name->nodename, &utsname()->nodename,
89406 + error |= __copy_to_user(name->nodename, &utsname()->nodename,
89407 __OLD_UTS_LEN);
89408 error |= __put_user(0, name->nodename + __OLD_UTS_LEN);
89409 - error |= __copy_to_user(&name->release, &utsname()->release,
89410 + error |= __copy_to_user(name->release, &utsname()->release,
89411 __OLD_UTS_LEN);
89412 error |= __put_user(0, name->release + __OLD_UTS_LEN);
89413 - error |= __copy_to_user(&name->version, &utsname()->version,
89414 + error |= __copy_to_user(name->version, &utsname()->version,
89415 __OLD_UTS_LEN);
89416 error |= __put_user(0, name->version + __OLD_UTS_LEN);
89417 - error |= __copy_to_user(&name->machine, &utsname()->machine,
89418 + error |= __copy_to_user(name->machine, &utsname()->machine,
89419 __OLD_UTS_LEN);
89420 error |= __put_user(0, name->machine + __OLD_UTS_LEN);
89421 up_read(&uts_sem);
89422 @@ -1382,6 +1418,13 @@ int do_prlimit(struct task_struct *tsk, unsigned int resource,
89423 */
89424 new_rlim->rlim_cur = 1;
89425 }
89426 + /* Handle the case where a fork and setuid occur and then RLIMIT_NPROC
89427 + is changed to a lower value. Since tasks can be created by the same
89428 + user in between this limit change and an execve by this task, force
89429 + a recheck only for this task by setting PF_NPROC_EXCEEDED
89430 + */
89431 + if (resource == RLIMIT_NPROC && tsk->real_cred->user != INIT_USER)
89432 + tsk->flags |= PF_NPROC_EXCEEDED;
89433 }
89434 if (!retval) {
89435 if (old_rlim)
89436 diff --git a/kernel/sysctl.c b/kernel/sysctl.c
89437 index 06962ba..a54d45e 100644
89438 --- a/kernel/sysctl.c
89439 +++ b/kernel/sysctl.c
89440 @@ -93,7 +93,6 @@
89441
89442
89443 #if defined(CONFIG_SYSCTL)
89444 -
89445 /* External variables not in a header file. */
89446 extern int sysctl_overcommit_memory;
89447 extern int sysctl_overcommit_ratio;
89448 @@ -119,17 +118,18 @@ extern int blk_iopoll_enabled;
89449
89450 /* Constants used for minimum and maximum */
89451 #ifdef CONFIG_LOCKUP_DETECTOR
89452 -static int sixty = 60;
89453 +static int sixty __read_only = 60;
89454 #endif
89455
89456 -static int zero;
89457 -static int __maybe_unused one = 1;
89458 -static int __maybe_unused two = 2;
89459 -static int __maybe_unused three = 3;
89460 -static unsigned long one_ul = 1;
89461 -static int one_hundred = 100;
89462 +static int neg_one __read_only = -1;
89463 +static int zero __read_only = 0;
89464 +static int __maybe_unused one __read_only = 1;
89465 +static int __maybe_unused two __read_only = 2;
89466 +static int __maybe_unused three __read_only = 3;
89467 +static unsigned long one_ul __read_only = 1;
89468 +static int one_hundred __read_only = 100;
89469 #ifdef CONFIG_PRINTK
89470 -static int ten_thousand = 10000;
89471 +static int ten_thousand __read_only = 10000;
89472 #endif
89473
89474 /* this is needed for the proc_doulongvec_minmax of vm_dirty_bytes */
89475 @@ -176,10 +176,8 @@ static int proc_taint(struct ctl_table *table, int write,
89476 void __user *buffer, size_t *lenp, loff_t *ppos);
89477 #endif
89478
89479 -#ifdef CONFIG_PRINTK
89480 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
89481 void __user *buffer, size_t *lenp, loff_t *ppos);
89482 -#endif
89483
89484 static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
89485 void __user *buffer, size_t *lenp, loff_t *ppos);
89486 @@ -210,6 +208,8 @@ static int sysrq_sysctl_handler(ctl_table *table, int write,
89487
89488 #endif
89489
89490 +extern struct ctl_table grsecurity_table[];
89491 +
89492 static struct ctl_table kern_table[];
89493 static struct ctl_table vm_table[];
89494 static struct ctl_table fs_table[];
89495 @@ -224,6 +224,20 @@ extern struct ctl_table epoll_table[];
89496 int sysctl_legacy_va_layout;
89497 #endif
89498
89499 +#ifdef CONFIG_PAX_SOFTMODE
89500 +static ctl_table pax_table[] = {
89501 + {
89502 + .procname = "softmode",
89503 + .data = &pax_softmode,
89504 + .maxlen = sizeof(unsigned int),
89505 + .mode = 0600,
89506 + .proc_handler = &proc_dointvec,
89507 + },
89508 +
89509 + { }
89510 +};
89511 +#endif
89512 +
89513 /* The default sysctl tables: */
89514
89515 static struct ctl_table sysctl_base_table[] = {
89516 @@ -272,6 +286,22 @@ static int max_extfrag_threshold = 1000;
89517 #endif
89518
89519 static struct ctl_table kern_table[] = {
89520 +#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
89521 + {
89522 + .procname = "grsecurity",
89523 + .mode = 0500,
89524 + .child = grsecurity_table,
89525 + },
89526 +#endif
89527 +
89528 +#ifdef CONFIG_PAX_SOFTMODE
89529 + {
89530 + .procname = "pax",
89531 + .mode = 0500,
89532 + .child = pax_table,
89533 + },
89534 +#endif
89535 +
89536 {
89537 .procname = "sched_child_runs_first",
89538 .data = &sysctl_sched_child_runs_first,
89539 @@ -629,7 +659,7 @@ static struct ctl_table kern_table[] = {
89540 .data = &modprobe_path,
89541 .maxlen = KMOD_PATH_LEN,
89542 .mode = 0644,
89543 - .proc_handler = proc_dostring,
89544 + .proc_handler = proc_dostring_modpriv,
89545 },
89546 {
89547 .procname = "modules_disabled",
89548 @@ -796,16 +826,20 @@ static struct ctl_table kern_table[] = {
89549 .extra1 = &zero,
89550 .extra2 = &one,
89551 },
89552 +#endif
89553 {
89554 .procname = "kptr_restrict",
89555 .data = &kptr_restrict,
89556 .maxlen = sizeof(int),
89557 .mode = 0644,
89558 .proc_handler = proc_dointvec_minmax_sysadmin,
89559 +#ifdef CONFIG_GRKERNSEC_HIDESYM
89560 + .extra1 = &two,
89561 +#else
89562 .extra1 = &zero,
89563 +#endif
89564 .extra2 = &two,
89565 },
89566 -#endif
89567 {
89568 .procname = "ngroups_max",
89569 .data = &ngroups_max,
89570 @@ -1048,10 +1082,17 @@ static struct ctl_table kern_table[] = {
89571 */
89572 {
89573 .procname = "perf_event_paranoid",
89574 - .data = &sysctl_perf_event_paranoid,
89575 - .maxlen = sizeof(sysctl_perf_event_paranoid),
89576 + .data = &sysctl_perf_event_legitimately_concerned,
89577 + .maxlen = sizeof(sysctl_perf_event_legitimately_concerned),
89578 .mode = 0644,
89579 - .proc_handler = proc_dointvec,
89580 + /* go ahead, be a hero */
89581 + .proc_handler = proc_dointvec_minmax_sysadmin,
89582 + .extra1 = &neg_one,
89583 +#ifdef CONFIG_GRKERNSEC_PERF_HARDEN
89584 + .extra2 = &three,
89585 +#else
89586 + .extra2 = &two,
89587 +#endif
89588 },
89589 {
89590 .procname = "perf_event_mlock_kb",
89591 @@ -1315,6 +1356,13 @@ static struct ctl_table vm_table[] = {
89592 .proc_handler = proc_dointvec_minmax,
89593 .extra1 = &zero,
89594 },
89595 + {
89596 + .procname = "heap_stack_gap",
89597 + .data = &sysctl_heap_stack_gap,
89598 + .maxlen = sizeof(sysctl_heap_stack_gap),
89599 + .mode = 0644,
89600 + .proc_handler = proc_doulongvec_minmax,
89601 + },
89602 #else
89603 {
89604 .procname = "nr_trim_pages",
89605 @@ -1779,6 +1827,16 @@ int proc_dostring(struct ctl_table *table, int write,
89606 buffer, lenp, ppos);
89607 }
89608
89609 +int proc_dostring_modpriv(struct ctl_table *table, int write,
89610 + void __user *buffer, size_t *lenp, loff_t *ppos)
89611 +{
89612 + if (write && !capable(CAP_SYS_MODULE))
89613 + return -EPERM;
89614 +
89615 + return _proc_do_string(table->data, table->maxlen, write,
89616 + buffer, lenp, ppos);
89617 +}
89618 +
89619 static size_t proc_skip_spaces(char **buf)
89620 {
89621 size_t ret;
89622 @@ -1884,6 +1942,8 @@ static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
89623 len = strlen(tmp);
89624 if (len > *size)
89625 len = *size;
89626 + if (len > sizeof(tmp))
89627 + len = sizeof(tmp);
89628 if (copy_to_user(*buf, tmp, len))
89629 return -EFAULT;
89630 *size -= len;
89631 @@ -2048,7 +2108,7 @@ int proc_dointvec(struct ctl_table *table, int write,
89632 static int proc_taint(struct ctl_table *table, int write,
89633 void __user *buffer, size_t *lenp, loff_t *ppos)
89634 {
89635 - struct ctl_table t;
89636 + ctl_table_no_const t;
89637 unsigned long tmptaint = get_taint();
89638 int err;
89639
89640 @@ -2076,7 +2136,6 @@ static int proc_taint(struct ctl_table *table, int write,
89641 return err;
89642 }
89643
89644 -#ifdef CONFIG_PRINTK
89645 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
89646 void __user *buffer, size_t *lenp, loff_t *ppos)
89647 {
89648 @@ -2085,7 +2144,6 @@ static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
89649
89650 return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
89651 }
89652 -#endif
89653
89654 struct do_proc_dointvec_minmax_conv_param {
89655 int *min;
89656 @@ -2632,6 +2690,12 @@ int proc_dostring(struct ctl_table *table, int write,
89657 return -ENOSYS;
89658 }
89659
89660 +int proc_dostring_modpriv(struct ctl_table *table, int write,
89661 + void __user *buffer, size_t *lenp, loff_t *ppos)
89662 +{
89663 + return -ENOSYS;
89664 +}
89665 +
89666 int proc_dointvec(struct ctl_table *table, int write,
89667 void __user *buffer, size_t *lenp, loff_t *ppos)
89668 {
89669 @@ -2688,5 +2752,6 @@ EXPORT_SYMBOL(proc_dointvec_minmax);
89670 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
89671 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
89672 EXPORT_SYMBOL(proc_dostring);
89673 +EXPORT_SYMBOL(proc_dostring_modpriv);
89674 EXPORT_SYMBOL(proc_doulongvec_minmax);
89675 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
89676 diff --git a/kernel/taskstats.c b/kernel/taskstats.c
89677 index 13d2f7c..c93d0b0 100644
89678 --- a/kernel/taskstats.c
89679 +++ b/kernel/taskstats.c
89680 @@ -28,9 +28,12 @@
89681 #include <linux/fs.h>
89682 #include <linux/file.h>
89683 #include <linux/pid_namespace.h>
89684 +#include <linux/grsecurity.h>
89685 #include <net/genetlink.h>
89686 #include <linux/atomic.h>
89687
89688 +extern int gr_is_taskstats_denied(int pid);
89689 +
89690 /*
89691 * Maximum length of a cpumask that can be specified in
89692 * the TASKSTATS_CMD_ATTR_REGISTER/DEREGISTER_CPUMASK attribute
89693 @@ -576,6 +579,9 @@ err:
89694
89695 static int taskstats_user_cmd(struct sk_buff *skb, struct genl_info *info)
89696 {
89697 + if (gr_is_taskstats_denied(current->pid))
89698 + return -EACCES;
89699 +
89700 if (info->attrs[TASKSTATS_CMD_ATTR_REGISTER_CPUMASK])
89701 return cmd_attr_register_cpumask(info);
89702 else if (info->attrs[TASKSTATS_CMD_ATTR_DEREGISTER_CPUMASK])
89703 diff --git a/kernel/time.c b/kernel/time.c
89704 index 7c7964c..2a0d412 100644
89705 --- a/kernel/time.c
89706 +++ b/kernel/time.c
89707 @@ -172,6 +172,11 @@ int do_sys_settimeofday(const struct timespec *tv, const struct timezone *tz)
89708 return error;
89709
89710 if (tz) {
89711 + /* we log in do_settimeofday called below, so don't log twice
89712 + */
89713 + if (!tv)
89714 + gr_log_timechange();
89715 +
89716 sys_tz = *tz;
89717 update_vsyscall_tz();
89718 if (firsttime) {
89719 diff --git a/kernel/time/alarmtimer.c b/kernel/time/alarmtimer.c
89720 index 88c9c65..7497ebc 100644
89721 --- a/kernel/time/alarmtimer.c
89722 +++ b/kernel/time/alarmtimer.c
89723 @@ -795,7 +795,7 @@ static int __init alarmtimer_init(void)
89724 struct platform_device *pdev;
89725 int error = 0;
89726 int i;
89727 - struct k_clock alarm_clock = {
89728 + static struct k_clock alarm_clock = {
89729 .clock_getres = alarm_clock_getres,
89730 .clock_get = alarm_clock_get,
89731 .timer_create = alarm_timer_create,
89732 diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
89733 index b415457..c26876d 100644
89734 --- a/kernel/time/timekeeping.c
89735 +++ b/kernel/time/timekeeping.c
89736 @@ -15,6 +15,7 @@
89737 #include <linux/init.h>
89738 #include <linux/mm.h>
89739 #include <linux/sched.h>
89740 +#include <linux/grsecurity.h>
89741 #include <linux/syscore_ops.h>
89742 #include <linux/clocksource.h>
89743 #include <linux/jiffies.h>
89744 @@ -500,6 +501,8 @@ int do_settimeofday(const struct timespec *tv)
89745 if (!timespec_valid_strict(tv))
89746 return -EINVAL;
89747
89748 + gr_log_timechange();
89749 +
89750 raw_spin_lock_irqsave(&timekeeper_lock, flags);
89751 write_seqcount_begin(&timekeeper_seq);
89752
89753 diff --git a/kernel/time/timer_list.c b/kernel/time/timer_list.c
89754 index 61ed862..3b52c65 100644
89755 --- a/kernel/time/timer_list.c
89756 +++ b/kernel/time/timer_list.c
89757 @@ -45,12 +45,16 @@ DECLARE_PER_CPU(struct hrtimer_cpu_base, hrtimer_bases);
89758
89759 static void print_name_offset(struct seq_file *m, void *sym)
89760 {
89761 +#ifdef CONFIG_GRKERNSEC_HIDESYM
89762 + SEQ_printf(m, "<%p>", NULL);
89763 +#else
89764 char symname[KSYM_NAME_LEN];
89765
89766 if (lookup_symbol_name((unsigned long)sym, symname) < 0)
89767 SEQ_printf(m, "<%pK>", sym);
89768 else
89769 SEQ_printf(m, "%s", symname);
89770 +#endif
89771 }
89772
89773 static void
89774 @@ -119,7 +123,11 @@ next_one:
89775 static void
89776 print_base(struct seq_file *m, struct hrtimer_clock_base *base, u64 now)
89777 {
89778 +#ifdef CONFIG_GRKERNSEC_HIDESYM
89779 + SEQ_printf(m, " .base: %p\n", NULL);
89780 +#else
89781 SEQ_printf(m, " .base: %pK\n", base);
89782 +#endif
89783 SEQ_printf(m, " .index: %d\n",
89784 base->index);
89785 SEQ_printf(m, " .resolution: %Lu nsecs\n",
89786 @@ -362,7 +370,11 @@ static int __init init_timer_list_procfs(void)
89787 {
89788 struct proc_dir_entry *pe;
89789
89790 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
89791 + pe = proc_create("timer_list", 0400, NULL, &timer_list_fops);
89792 +#else
89793 pe = proc_create("timer_list", 0444, NULL, &timer_list_fops);
89794 +#endif
89795 if (!pe)
89796 return -ENOMEM;
89797 return 0;
89798 diff --git a/kernel/time/timer_stats.c b/kernel/time/timer_stats.c
89799 index 1fb08f2..ca4bb1e 100644
89800 --- a/kernel/time/timer_stats.c
89801 +++ b/kernel/time/timer_stats.c
89802 @@ -116,7 +116,7 @@ static ktime_t time_start, time_stop;
89803 static unsigned long nr_entries;
89804 static struct entry entries[MAX_ENTRIES];
89805
89806 -static atomic_t overflow_count;
89807 +static atomic_unchecked_t overflow_count;
89808
89809 /*
89810 * The entries are in a hash-table, for fast lookup:
89811 @@ -140,7 +140,7 @@ static void reset_entries(void)
89812 nr_entries = 0;
89813 memset(entries, 0, sizeof(entries));
89814 memset(tstat_hash_table, 0, sizeof(tstat_hash_table));
89815 - atomic_set(&overflow_count, 0);
89816 + atomic_set_unchecked(&overflow_count, 0);
89817 }
89818
89819 static struct entry *alloc_entry(void)
89820 @@ -261,7 +261,7 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
89821 if (likely(entry))
89822 entry->count++;
89823 else
89824 - atomic_inc(&overflow_count);
89825 + atomic_inc_unchecked(&overflow_count);
89826
89827 out_unlock:
89828 raw_spin_unlock_irqrestore(lock, flags);
89829 @@ -269,12 +269,16 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
89830
89831 static void print_name_offset(struct seq_file *m, unsigned long addr)
89832 {
89833 +#ifdef CONFIG_GRKERNSEC_HIDESYM
89834 + seq_printf(m, "<%p>", NULL);
89835 +#else
89836 char symname[KSYM_NAME_LEN];
89837
89838 if (lookup_symbol_name(addr, symname) < 0)
89839 - seq_printf(m, "<%p>", (void *)addr);
89840 + seq_printf(m, "<%pK>", (void *)addr);
89841 else
89842 seq_printf(m, "%s", symname);
89843 +#endif
89844 }
89845
89846 static int tstats_show(struct seq_file *m, void *v)
89847 @@ -300,8 +304,8 @@ static int tstats_show(struct seq_file *m, void *v)
89848
89849 seq_puts(m, "Timer Stats Version: v0.3\n");
89850 seq_printf(m, "Sample period: %ld.%03ld s\n", period.tv_sec, ms);
89851 - if (atomic_read(&overflow_count))
89852 - seq_printf(m, "Overflow: %d entries\n", atomic_read(&overflow_count));
89853 + if (atomic_read_unchecked(&overflow_count))
89854 + seq_printf(m, "Overflow: %d entries\n", atomic_read_unchecked(&overflow_count));
89855 seq_printf(m, "Collection: %s\n", timer_stats_active ? "active" : "inactive");
89856
89857 for (i = 0; i < nr_entries; i++) {
89858 @@ -417,7 +421,11 @@ static int __init init_tstats_procfs(void)
89859 {
89860 struct proc_dir_entry *pe;
89861
89862 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
89863 + pe = proc_create("timer_stats", 0600, NULL, &tstats_fops);
89864 +#else
89865 pe = proc_create("timer_stats", 0644, NULL, &tstats_fops);
89866 +#endif
89867 if (!pe)
89868 return -ENOMEM;
89869 return 0;
89870 diff --git a/kernel/timer.c b/kernel/timer.c
89871 index accfd24..e00f0c0 100644
89872 --- a/kernel/timer.c
89873 +++ b/kernel/timer.c
89874 @@ -1366,7 +1366,7 @@ void update_process_times(int user_tick)
89875 /*
89876 * This function runs timers and the timer-tq in bottom half context.
89877 */
89878 -static void run_timer_softirq(struct softirq_action *h)
89879 +static __latent_entropy void run_timer_softirq(void)
89880 {
89881 struct tvec_base *base = __this_cpu_read(tvec_bases);
89882
89883 @@ -1429,7 +1429,7 @@ static void process_timeout(unsigned long __data)
89884 *
89885 * In all cases the return value is guaranteed to be non-negative.
89886 */
89887 -signed long __sched schedule_timeout(signed long timeout)
89888 +signed long __sched __intentional_overflow(-1) schedule_timeout(signed long timeout)
89889 {
89890 struct timer_list timer;
89891 unsigned long expire;
89892 diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c
89893 index f785aef..59f1b18 100644
89894 --- a/kernel/trace/blktrace.c
89895 +++ b/kernel/trace/blktrace.c
89896 @@ -328,7 +328,7 @@ static ssize_t blk_dropped_read(struct file *filp, char __user *buffer,
89897 struct blk_trace *bt = filp->private_data;
89898 char buf[16];
89899
89900 - snprintf(buf, sizeof(buf), "%u\n", atomic_read(&bt->dropped));
89901 + snprintf(buf, sizeof(buf), "%u\n", atomic_read_unchecked(&bt->dropped));
89902
89903 return simple_read_from_buffer(buffer, count, ppos, buf, strlen(buf));
89904 }
89905 @@ -386,7 +386,7 @@ static int blk_subbuf_start_callback(struct rchan_buf *buf, void *subbuf,
89906 return 1;
89907
89908 bt = buf->chan->private_data;
89909 - atomic_inc(&bt->dropped);
89910 + atomic_inc_unchecked(&bt->dropped);
89911 return 0;
89912 }
89913
89914 @@ -487,7 +487,7 @@ int do_blk_trace_setup(struct request_queue *q, char *name, dev_t dev,
89915
89916 bt->dir = dir;
89917 bt->dev = dev;
89918 - atomic_set(&bt->dropped, 0);
89919 + atomic_set_unchecked(&bt->dropped, 0);
89920 INIT_LIST_HEAD(&bt->running_list);
89921
89922 ret = -EIO;
89923 diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
89924 index 38463d2..68abe92 100644
89925 --- a/kernel/trace/ftrace.c
89926 +++ b/kernel/trace/ftrace.c
89927 @@ -1978,12 +1978,17 @@ ftrace_code_disable(struct module *mod, struct dyn_ftrace *rec)
89928 if (unlikely(ftrace_disabled))
89929 return 0;
89930
89931 + ret = ftrace_arch_code_modify_prepare();
89932 + FTRACE_WARN_ON(ret);
89933 + if (ret)
89934 + return 0;
89935 +
89936 ret = ftrace_make_nop(mod, rec, MCOUNT_ADDR);
89937 + FTRACE_WARN_ON(ftrace_arch_code_modify_post_process());
89938 if (ret) {
89939 ftrace_bug(ret, ip);
89940 - return 0;
89941 }
89942 - return 1;
89943 + return ret ? 0 : 1;
89944 }
89945
89946 /*
89947 @@ -4190,8 +4195,10 @@ static int ftrace_process_locs(struct module *mod,
89948 if (!count)
89949 return 0;
89950
89951 + pax_open_kernel();
89952 sort(start, count, sizeof(*start),
89953 ftrace_cmp_ips, ftrace_swap_ips);
89954 + pax_close_kernel();
89955
89956 start_pg = ftrace_allocate_pages(count);
89957 if (!start_pg)
89958 @@ -4922,8 +4929,6 @@ ftrace_enable_sysctl(struct ctl_table *table, int write,
89959 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
89960
89961 static int ftrace_graph_active;
89962 -static struct notifier_block ftrace_suspend_notifier;
89963 -
89964 int ftrace_graph_entry_stub(struct ftrace_graph_ent *trace)
89965 {
89966 return 0;
89967 @@ -5099,6 +5104,10 @@ static void update_function_graph_func(void)
89968 ftrace_graph_entry = ftrace_graph_entry_test;
89969 }
89970
89971 +static struct notifier_block ftrace_suspend_notifier = {
89972 + .notifier_call = ftrace_suspend_notifier_call
89973 +};
89974 +
89975 int register_ftrace_graph(trace_func_graph_ret_t retfunc,
89976 trace_func_graph_ent_t entryfunc)
89977 {
89978 @@ -5112,7 +5121,6 @@ int register_ftrace_graph(trace_func_graph_ret_t retfunc,
89979 goto out;
89980 }
89981
89982 - ftrace_suspend_notifier.notifier_call = ftrace_suspend_notifier_call;
89983 register_pm_notifier(&ftrace_suspend_notifier);
89984
89985 ftrace_graph_active++;
89986 diff --git a/kernel/trace/ring_buffer.c b/kernel/trace/ring_buffer.c
89987 index 0e337ee..3370631 100644
89988 --- a/kernel/trace/ring_buffer.c
89989 +++ b/kernel/trace/ring_buffer.c
89990 @@ -352,9 +352,9 @@ struct buffer_data_page {
89991 */
89992 struct buffer_page {
89993 struct list_head list; /* list of buffer pages */
89994 - local_t write; /* index for next write */
89995 + local_unchecked_t write; /* index for next write */
89996 unsigned read; /* index for next read */
89997 - local_t entries; /* entries on this page */
89998 + local_unchecked_t entries; /* entries on this page */
89999 unsigned long real_end; /* real end of data */
90000 struct buffer_data_page *page; /* Actual data page */
90001 };
90002 @@ -473,8 +473,8 @@ struct ring_buffer_per_cpu {
90003 unsigned long last_overrun;
90004 local_t entries_bytes;
90005 local_t entries;
90006 - local_t overrun;
90007 - local_t commit_overrun;
90008 + local_unchecked_t overrun;
90009 + local_unchecked_t commit_overrun;
90010 local_t dropped_events;
90011 local_t committing;
90012 local_t commits;
90013 @@ -992,8 +992,8 @@ static int rb_tail_page_update(struct ring_buffer_per_cpu *cpu_buffer,
90014 *
90015 * We add a counter to the write field to denote this.
90016 */
90017 - old_write = local_add_return(RB_WRITE_INTCNT, &next_page->write);
90018 - old_entries = local_add_return(RB_WRITE_INTCNT, &next_page->entries);
90019 + old_write = local_add_return_unchecked(RB_WRITE_INTCNT, &next_page->write);
90020 + old_entries = local_add_return_unchecked(RB_WRITE_INTCNT, &next_page->entries);
90021
90022 /*
90023 * Just make sure we have seen our old_write and synchronize
90024 @@ -1021,8 +1021,8 @@ static int rb_tail_page_update(struct ring_buffer_per_cpu *cpu_buffer,
90025 * cmpxchg to only update if an interrupt did not already
90026 * do it for us. If the cmpxchg fails, we don't care.
90027 */
90028 - (void)local_cmpxchg(&next_page->write, old_write, val);
90029 - (void)local_cmpxchg(&next_page->entries, old_entries, eval);
90030 + (void)local_cmpxchg_unchecked(&next_page->write, old_write, val);
90031 + (void)local_cmpxchg_unchecked(&next_page->entries, old_entries, eval);
90032
90033 /*
90034 * No need to worry about races with clearing out the commit.
90035 @@ -1386,12 +1386,12 @@ static void rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer);
90036
90037 static inline unsigned long rb_page_entries(struct buffer_page *bpage)
90038 {
90039 - return local_read(&bpage->entries) & RB_WRITE_MASK;
90040 + return local_read_unchecked(&bpage->entries) & RB_WRITE_MASK;
90041 }
90042
90043 static inline unsigned long rb_page_write(struct buffer_page *bpage)
90044 {
90045 - return local_read(&bpage->write) & RB_WRITE_MASK;
90046 + return local_read_unchecked(&bpage->write) & RB_WRITE_MASK;
90047 }
90048
90049 static int
90050 @@ -1486,7 +1486,7 @@ rb_remove_pages(struct ring_buffer_per_cpu *cpu_buffer, unsigned int nr_pages)
90051 * bytes consumed in ring buffer from here.
90052 * Increment overrun to account for the lost events.
90053 */
90054 - local_add(page_entries, &cpu_buffer->overrun);
90055 + local_add_unchecked(page_entries, &cpu_buffer->overrun);
90056 local_sub(BUF_PAGE_SIZE, &cpu_buffer->entries_bytes);
90057 }
90058
90059 @@ -2064,7 +2064,7 @@ rb_handle_head_page(struct ring_buffer_per_cpu *cpu_buffer,
90060 * it is our responsibility to update
90061 * the counters.
90062 */
90063 - local_add(entries, &cpu_buffer->overrun);
90064 + local_add_unchecked(entries, &cpu_buffer->overrun);
90065 local_sub(BUF_PAGE_SIZE, &cpu_buffer->entries_bytes);
90066
90067 /*
90068 @@ -2214,7 +2214,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
90069 if (tail == BUF_PAGE_SIZE)
90070 tail_page->real_end = 0;
90071
90072 - local_sub(length, &tail_page->write);
90073 + local_sub_unchecked(length, &tail_page->write);
90074 return;
90075 }
90076
90077 @@ -2249,7 +2249,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
90078 rb_event_set_padding(event);
90079
90080 /* Set the write back to the previous setting */
90081 - local_sub(length, &tail_page->write);
90082 + local_sub_unchecked(length, &tail_page->write);
90083 return;
90084 }
90085
90086 @@ -2261,7 +2261,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
90087
90088 /* Set write to end of buffer */
90089 length = (tail + length) - BUF_PAGE_SIZE;
90090 - local_sub(length, &tail_page->write);
90091 + local_sub_unchecked(length, &tail_page->write);
90092 }
90093
90094 /*
90095 @@ -2287,7 +2287,7 @@ rb_move_tail(struct ring_buffer_per_cpu *cpu_buffer,
90096 * about it.
90097 */
90098 if (unlikely(next_page == commit_page)) {
90099 - local_inc(&cpu_buffer->commit_overrun);
90100 + local_inc_unchecked(&cpu_buffer->commit_overrun);
90101 goto out_reset;
90102 }
90103
90104 @@ -2343,7 +2343,7 @@ rb_move_tail(struct ring_buffer_per_cpu *cpu_buffer,
90105 cpu_buffer->tail_page) &&
90106 (cpu_buffer->commit_page ==
90107 cpu_buffer->reader_page))) {
90108 - local_inc(&cpu_buffer->commit_overrun);
90109 + local_inc_unchecked(&cpu_buffer->commit_overrun);
90110 goto out_reset;
90111 }
90112 }
90113 @@ -2391,7 +2391,7 @@ __rb_reserve_next(struct ring_buffer_per_cpu *cpu_buffer,
90114 length += RB_LEN_TIME_EXTEND;
90115
90116 tail_page = cpu_buffer->tail_page;
90117 - write = local_add_return(length, &tail_page->write);
90118 + write = local_add_return_unchecked(length, &tail_page->write);
90119
90120 /* set write to only the index of the write */
90121 write &= RB_WRITE_MASK;
90122 @@ -2415,7 +2415,7 @@ __rb_reserve_next(struct ring_buffer_per_cpu *cpu_buffer,
90123 kmemcheck_annotate_bitfield(event, bitfield);
90124 rb_update_event(cpu_buffer, event, length, add_timestamp, delta);
90125
90126 - local_inc(&tail_page->entries);
90127 + local_inc_unchecked(&tail_page->entries);
90128
90129 /*
90130 * If this is the first commit on the page, then update
90131 @@ -2448,7 +2448,7 @@ rb_try_to_discard(struct ring_buffer_per_cpu *cpu_buffer,
90132
90133 if (bpage->page == (void *)addr && rb_page_write(bpage) == old_index) {
90134 unsigned long write_mask =
90135 - local_read(&bpage->write) & ~RB_WRITE_MASK;
90136 + local_read_unchecked(&bpage->write) & ~RB_WRITE_MASK;
90137 unsigned long event_length = rb_event_length(event);
90138 /*
90139 * This is on the tail page. It is possible that
90140 @@ -2458,7 +2458,7 @@ rb_try_to_discard(struct ring_buffer_per_cpu *cpu_buffer,
90141 */
90142 old_index += write_mask;
90143 new_index += write_mask;
90144 - index = local_cmpxchg(&bpage->write, old_index, new_index);
90145 + index = local_cmpxchg_unchecked(&bpage->write, old_index, new_index);
90146 if (index == old_index) {
90147 /* update counters */
90148 local_sub(event_length, &cpu_buffer->entries_bytes);
90149 @@ -2850,7 +2850,7 @@ rb_decrement_entry(struct ring_buffer_per_cpu *cpu_buffer,
90150
90151 /* Do the likely case first */
90152 if (likely(bpage->page == (void *)addr)) {
90153 - local_dec(&bpage->entries);
90154 + local_dec_unchecked(&bpage->entries);
90155 return;
90156 }
90157
90158 @@ -2862,7 +2862,7 @@ rb_decrement_entry(struct ring_buffer_per_cpu *cpu_buffer,
90159 start = bpage;
90160 do {
90161 if (bpage->page == (void *)addr) {
90162 - local_dec(&bpage->entries);
90163 + local_dec_unchecked(&bpage->entries);
90164 return;
90165 }
90166 rb_inc_page(cpu_buffer, &bpage);
90167 @@ -3146,7 +3146,7 @@ static inline unsigned long
90168 rb_num_of_entries(struct ring_buffer_per_cpu *cpu_buffer)
90169 {
90170 return local_read(&cpu_buffer->entries) -
90171 - (local_read(&cpu_buffer->overrun) + cpu_buffer->read);
90172 + (local_read_unchecked(&cpu_buffer->overrun) + cpu_buffer->read);
90173 }
90174
90175 /**
90176 @@ -3235,7 +3235,7 @@ unsigned long ring_buffer_overrun_cpu(struct ring_buffer *buffer, int cpu)
90177 return 0;
90178
90179 cpu_buffer = buffer->buffers[cpu];
90180 - ret = local_read(&cpu_buffer->overrun);
90181 + ret = local_read_unchecked(&cpu_buffer->overrun);
90182
90183 return ret;
90184 }
90185 @@ -3258,7 +3258,7 @@ ring_buffer_commit_overrun_cpu(struct ring_buffer *buffer, int cpu)
90186 return 0;
90187
90188 cpu_buffer = buffer->buffers[cpu];
90189 - ret = local_read(&cpu_buffer->commit_overrun);
90190 + ret = local_read_unchecked(&cpu_buffer->commit_overrun);
90191
90192 return ret;
90193 }
90194 @@ -3343,7 +3343,7 @@ unsigned long ring_buffer_overruns(struct ring_buffer *buffer)
90195 /* if you care about this being correct, lock the buffer */
90196 for_each_buffer_cpu(buffer, cpu) {
90197 cpu_buffer = buffer->buffers[cpu];
90198 - overruns += local_read(&cpu_buffer->overrun);
90199 + overruns += local_read_unchecked(&cpu_buffer->overrun);
90200 }
90201
90202 return overruns;
90203 @@ -3519,8 +3519,8 @@ rb_get_reader_page(struct ring_buffer_per_cpu *cpu_buffer)
90204 /*
90205 * Reset the reader page to size zero.
90206 */
90207 - local_set(&cpu_buffer->reader_page->write, 0);
90208 - local_set(&cpu_buffer->reader_page->entries, 0);
90209 + local_set_unchecked(&cpu_buffer->reader_page->write, 0);
90210 + local_set_unchecked(&cpu_buffer->reader_page->entries, 0);
90211 local_set(&cpu_buffer->reader_page->page->commit, 0);
90212 cpu_buffer->reader_page->real_end = 0;
90213
90214 @@ -3554,7 +3554,7 @@ rb_get_reader_page(struct ring_buffer_per_cpu *cpu_buffer)
90215 * want to compare with the last_overrun.
90216 */
90217 smp_mb();
90218 - overwrite = local_read(&(cpu_buffer->overrun));
90219 + overwrite = local_read_unchecked(&(cpu_buffer->overrun));
90220
90221 /*
90222 * Here's the tricky part.
90223 @@ -4124,8 +4124,8 @@ rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer)
90224
90225 cpu_buffer->head_page
90226 = list_entry(cpu_buffer->pages, struct buffer_page, list);
90227 - local_set(&cpu_buffer->head_page->write, 0);
90228 - local_set(&cpu_buffer->head_page->entries, 0);
90229 + local_set_unchecked(&cpu_buffer->head_page->write, 0);
90230 + local_set_unchecked(&cpu_buffer->head_page->entries, 0);
90231 local_set(&cpu_buffer->head_page->page->commit, 0);
90232
90233 cpu_buffer->head_page->read = 0;
90234 @@ -4135,14 +4135,14 @@ rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer)
90235
90236 INIT_LIST_HEAD(&cpu_buffer->reader_page->list);
90237 INIT_LIST_HEAD(&cpu_buffer->new_pages);
90238 - local_set(&cpu_buffer->reader_page->write, 0);
90239 - local_set(&cpu_buffer->reader_page->entries, 0);
90240 + local_set_unchecked(&cpu_buffer->reader_page->write, 0);
90241 + local_set_unchecked(&cpu_buffer->reader_page->entries, 0);
90242 local_set(&cpu_buffer->reader_page->page->commit, 0);
90243 cpu_buffer->reader_page->read = 0;
90244
90245 local_set(&cpu_buffer->entries_bytes, 0);
90246 - local_set(&cpu_buffer->overrun, 0);
90247 - local_set(&cpu_buffer->commit_overrun, 0);
90248 + local_set_unchecked(&cpu_buffer->overrun, 0);
90249 + local_set_unchecked(&cpu_buffer->commit_overrun, 0);
90250 local_set(&cpu_buffer->dropped_events, 0);
90251 local_set(&cpu_buffer->entries, 0);
90252 local_set(&cpu_buffer->committing, 0);
90253 @@ -4547,8 +4547,8 @@ int ring_buffer_read_page(struct ring_buffer *buffer,
90254 rb_init_page(bpage);
90255 bpage = reader->page;
90256 reader->page = *data_page;
90257 - local_set(&reader->write, 0);
90258 - local_set(&reader->entries, 0);
90259 + local_set_unchecked(&reader->write, 0);
90260 + local_set_unchecked(&reader->entries, 0);
90261 reader->read = 0;
90262 *data_page = bpage;
90263
90264 diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
90265 index 0a360ce..7bd800e 100644
90266 --- a/kernel/trace/trace.c
90267 +++ b/kernel/trace/trace.c
90268 @@ -3352,7 +3352,7 @@ int trace_keep_overwrite(struct tracer *tracer, u32 mask, int set)
90269 return 0;
90270 }
90271
90272 -int set_tracer_flag(struct trace_array *tr, unsigned int mask, int enabled)
90273 +int set_tracer_flag(struct trace_array *tr, unsigned long mask, int enabled)
90274 {
90275 /* do nothing if flag is already set */
90276 if (!!(trace_flags & mask) == !!enabled)
90277 diff --git a/kernel/trace/trace.h b/kernel/trace/trace.h
90278 index ea189e0..a5b48c4 100644
90279 --- a/kernel/trace/trace.h
90280 +++ b/kernel/trace/trace.h
90281 @@ -1040,7 +1040,7 @@ extern const char *__stop___tracepoint_str[];
90282 void trace_printk_init_buffers(void);
90283 void trace_printk_start_comm(void);
90284 int trace_keep_overwrite(struct tracer *tracer, u32 mask, int set);
90285 -int set_tracer_flag(struct trace_array *tr, unsigned int mask, int enabled);
90286 +int set_tracer_flag(struct trace_array *tr, unsigned long mask, int enabled);
90287
90288 /*
90289 * Normal trace_printk() and friends allocates special buffers
90290 diff --git a/kernel/trace/trace_clock.c b/kernel/trace/trace_clock.c
90291 index 26dc348..8708ca7 100644
90292 --- a/kernel/trace/trace_clock.c
90293 +++ b/kernel/trace/trace_clock.c
90294 @@ -123,7 +123,7 @@ u64 notrace trace_clock_global(void)
90295 return now;
90296 }
90297
90298 -static atomic64_t trace_counter;
90299 +static atomic64_unchecked_t trace_counter;
90300
90301 /*
90302 * trace_clock_counter(): simply an atomic counter.
90303 @@ -132,5 +132,5 @@ static atomic64_t trace_counter;
90304 */
90305 u64 notrace trace_clock_counter(void)
90306 {
90307 - return atomic64_add_return(1, &trace_counter);
90308 + return atomic64_inc_return_unchecked(&trace_counter);
90309 }
90310 diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c
90311 index ba983dc..911aaf9 100644
90312 --- a/kernel/trace/trace_events.c
90313 +++ b/kernel/trace/trace_events.c
90314 @@ -1675,7 +1675,6 @@ __trace_early_add_new_event(struct ftrace_event_call *call,
90315 return 0;
90316 }
90317
90318 -struct ftrace_module_file_ops;
90319 static void __add_event_to_tracers(struct ftrace_event_call *call);
90320
90321 /* Add an additional event_call dynamically */
90322 diff --git a/kernel/trace/trace_mmiotrace.c b/kernel/trace/trace_mmiotrace.c
90323 index 0abd9b8..6a663a2 100644
90324 --- a/kernel/trace/trace_mmiotrace.c
90325 +++ b/kernel/trace/trace_mmiotrace.c
90326 @@ -24,7 +24,7 @@ struct header_iter {
90327 static struct trace_array *mmio_trace_array;
90328 static bool overrun_detected;
90329 static unsigned long prev_overruns;
90330 -static atomic_t dropped_count;
90331 +static atomic_unchecked_t dropped_count;
90332
90333 static void mmio_reset_data(struct trace_array *tr)
90334 {
90335 @@ -127,7 +127,7 @@ static void mmio_close(struct trace_iterator *iter)
90336
90337 static unsigned long count_overruns(struct trace_iterator *iter)
90338 {
90339 - unsigned long cnt = atomic_xchg(&dropped_count, 0);
90340 + unsigned long cnt = atomic_xchg_unchecked(&dropped_count, 0);
90341 unsigned long over = ring_buffer_overruns(iter->trace_buffer->buffer);
90342
90343 if (over > prev_overruns)
90344 @@ -317,7 +317,7 @@ static void __trace_mmiotrace_rw(struct trace_array *tr,
90345 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_RW,
90346 sizeof(*entry), 0, pc);
90347 if (!event) {
90348 - atomic_inc(&dropped_count);
90349 + atomic_inc_unchecked(&dropped_count);
90350 return;
90351 }
90352 entry = ring_buffer_event_data(event);
90353 @@ -347,7 +347,7 @@ static void __trace_mmiotrace_map(struct trace_array *tr,
90354 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_MAP,
90355 sizeof(*entry), 0, pc);
90356 if (!event) {
90357 - atomic_inc(&dropped_count);
90358 + atomic_inc_unchecked(&dropped_count);
90359 return;
90360 }
90361 entry = ring_buffer_event_data(event);
90362 diff --git a/kernel/trace/trace_output.c b/kernel/trace/trace_output.c
90363 index ed32284..884d6c3 100644
90364 --- a/kernel/trace/trace_output.c
90365 +++ b/kernel/trace/trace_output.c
90366 @@ -294,7 +294,7 @@ int trace_seq_path(struct trace_seq *s, const struct path *path)
90367
90368 p = d_path(path, s->buffer + s->len, PAGE_SIZE - s->len);
90369 if (!IS_ERR(p)) {
90370 - p = mangle_path(s->buffer + s->len, p, "\n");
90371 + p = mangle_path(s->buffer + s->len, p, "\n\\");
90372 if (p) {
90373 s->len = p - s->buffer;
90374 return 1;
90375 @@ -908,14 +908,16 @@ int register_ftrace_event(struct trace_event *event)
90376 goto out;
90377 }
90378
90379 + pax_open_kernel();
90380 if (event->funcs->trace == NULL)
90381 - event->funcs->trace = trace_nop_print;
90382 + *(void **)&event->funcs->trace = trace_nop_print;
90383 if (event->funcs->raw == NULL)
90384 - event->funcs->raw = trace_nop_print;
90385 + *(void **)&event->funcs->raw = trace_nop_print;
90386 if (event->funcs->hex == NULL)
90387 - event->funcs->hex = trace_nop_print;
90388 + *(void **)&event->funcs->hex = trace_nop_print;
90389 if (event->funcs->binary == NULL)
90390 - event->funcs->binary = trace_nop_print;
90391 + *(void **)&event->funcs->binary = trace_nop_print;
90392 + pax_close_kernel();
90393
90394 key = event->type & (EVENT_HASHSIZE - 1);
90395
90396 diff --git a/kernel/trace/trace_stack.c b/kernel/trace/trace_stack.c
90397 index b20428c..4845a10 100644
90398 --- a/kernel/trace/trace_stack.c
90399 +++ b/kernel/trace/trace_stack.c
90400 @@ -68,7 +68,7 @@ check_stack(unsigned long ip, unsigned long *stack)
90401 return;
90402
90403 /* we do not handle interrupt stacks yet */
90404 - if (!object_is_on_stack(stack))
90405 + if (!object_starts_on_stack(stack))
90406 return;
90407
90408 local_irq_save(flags);
90409 diff --git a/kernel/user_namespace.c b/kernel/user_namespace.c
90410 index 240fb62..583473e 100644
90411 --- a/kernel/user_namespace.c
90412 +++ b/kernel/user_namespace.c
90413 @@ -82,6 +82,21 @@ int create_user_ns(struct cred *new)
90414 !kgid_has_mapping(parent_ns, group))
90415 return -EPERM;
90416
90417 +#ifdef CONFIG_GRKERNSEC
90418 + /*
90419 + * This doesn't really inspire confidence:
90420 + * http://marc.info/?l=linux-kernel&m=135543612731939&w=2
90421 + * http://marc.info/?l=linux-kernel&m=135545831607095&w=2
90422 + * Increases kernel attack surface in areas developers
90423 + * previously cared little about ("low importance due
90424 + * to requiring "root" capability")
90425 + * To be removed when this code receives *proper* review
90426 + */
90427 + if (!capable(CAP_SYS_ADMIN) || !capable(CAP_SETUID) ||
90428 + !capable(CAP_SETGID))
90429 + return -EPERM;
90430 +#endif
90431 +
90432 ns = kmem_cache_zalloc(user_ns_cachep, GFP_KERNEL);
90433 if (!ns)
90434 return -ENOMEM;
90435 @@ -866,7 +881,7 @@ static int userns_install(struct nsproxy *nsproxy, void *ns)
90436 if (atomic_read(&current->mm->mm_users) > 1)
90437 return -EINVAL;
90438
90439 - if (current->fs->users != 1)
90440 + if (atomic_read(&current->fs->users) != 1)
90441 return -EINVAL;
90442
90443 if (!ns_capable(user_ns, CAP_SYS_ADMIN))
90444 diff --git a/kernel/utsname_sysctl.c b/kernel/utsname_sysctl.c
90445 index 4f69f9a..7c6f8f8 100644
90446 --- a/kernel/utsname_sysctl.c
90447 +++ b/kernel/utsname_sysctl.c
90448 @@ -47,7 +47,7 @@ static void put_uts(ctl_table *table, int write, void *which)
90449 static int proc_do_uts_string(ctl_table *table, int write,
90450 void __user *buffer, size_t *lenp, loff_t *ppos)
90451 {
90452 - struct ctl_table uts_table;
90453 + ctl_table_no_const uts_table;
90454 int r;
90455 memcpy(&uts_table, table, sizeof(uts_table));
90456 uts_table.data = get_uts(table, write);
90457 diff --git a/kernel/watchdog.c b/kernel/watchdog.c
90458 index 4431610..4265616 100644
90459 --- a/kernel/watchdog.c
90460 +++ b/kernel/watchdog.c
90461 @@ -475,7 +475,7 @@ static int watchdog_nmi_enable(unsigned int cpu) { return 0; }
90462 static void watchdog_nmi_disable(unsigned int cpu) { return; }
90463 #endif /* CONFIG_HARDLOCKUP_DETECTOR */
90464
90465 -static struct smp_hotplug_thread watchdog_threads = {
90466 +static struct smp_hotplug_thread watchdog_threads __read_only = {
90467 .store = &softlockup_watchdog,
90468 .thread_should_run = watchdog_should_run,
90469 .thread_fn = watchdog,
90470 diff --git a/kernel/workqueue.c b/kernel/workqueue.c
90471 index a8381cf..1ce1331 100644
90472 --- a/kernel/workqueue.c
90473 +++ b/kernel/workqueue.c
90474 @@ -4678,7 +4678,7 @@ static void rebind_workers(struct worker_pool *pool)
90475 WARN_ON_ONCE(!(worker_flags & WORKER_UNBOUND));
90476 worker_flags |= WORKER_REBOUND;
90477 worker_flags &= ~WORKER_UNBOUND;
90478 - ACCESS_ONCE(worker->flags) = worker_flags;
90479 + ACCESS_ONCE_RW(worker->flags) = worker_flags;
90480 }
90481
90482 spin_unlock_irq(&pool->lock);
90483 diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
90484 index db25707..8b16430 100644
90485 --- a/lib/Kconfig.debug
90486 +++ b/lib/Kconfig.debug
90487 @@ -845,7 +845,7 @@ config DEBUG_MUTEXES
90488
90489 config DEBUG_WW_MUTEX_SLOWPATH
90490 bool "Wait/wound mutex debugging: Slowpath testing"
90491 - depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
90492 + depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
90493 select DEBUG_LOCK_ALLOC
90494 select DEBUG_SPINLOCK
90495 select DEBUG_MUTEXES
90496 @@ -858,7 +858,7 @@ config DEBUG_WW_MUTEX_SLOWPATH
90497
90498 config DEBUG_LOCK_ALLOC
90499 bool "Lock debugging: detect incorrect freeing of live locks"
90500 - depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
90501 + depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
90502 select DEBUG_SPINLOCK
90503 select DEBUG_MUTEXES
90504 select LOCKDEP
90505 @@ -872,7 +872,7 @@ config DEBUG_LOCK_ALLOC
90506
90507 config PROVE_LOCKING
90508 bool "Lock debugging: prove locking correctness"
90509 - depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
90510 + depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
90511 select LOCKDEP
90512 select DEBUG_SPINLOCK
90513 select DEBUG_MUTEXES
90514 @@ -923,7 +923,7 @@ config LOCKDEP
90515
90516 config LOCK_STAT
90517 bool "Lock usage statistics"
90518 - depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
90519 + depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
90520 select LOCKDEP
90521 select DEBUG_SPINLOCK
90522 select DEBUG_MUTEXES
90523 @@ -1385,6 +1385,7 @@ config LATENCYTOP
90524 depends on DEBUG_KERNEL
90525 depends on STACKTRACE_SUPPORT
90526 depends on PROC_FS
90527 + depends on !GRKERNSEC_HIDESYM
90528 select FRAME_POINTER if !MIPS && !PPC && !S390 && !MICROBLAZE && !ARM_UNWIND && !ARC
90529 select KALLSYMS
90530 select KALLSYMS_ALL
90531 @@ -1401,7 +1402,7 @@ config ARCH_HAS_DEBUG_STRICT_USER_COPY_CHECKS
90532 config DEBUG_STRICT_USER_COPY_CHECKS
90533 bool "Strict user copy size checks"
90534 depends on ARCH_HAS_DEBUG_STRICT_USER_COPY_CHECKS
90535 - depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING
90536 + depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING && !PAX_SIZE_OVERFLOW
90537 help
90538 Enabling this option turns a certain set of sanity checks for user
90539 copy operations into compile time failures.
90540 @@ -1520,7 +1521,7 @@ endmenu # runtime tests
90541
90542 config PROVIDE_OHCI1394_DMA_INIT
90543 bool "Remote debugging over FireWire early on boot"
90544 - depends on PCI && X86
90545 + depends on PCI && X86 && !GRKERNSEC
90546 help
90547 If you want to debug problems which hang or crash the kernel early
90548 on boot and the crashing machine has a FireWire port, you can use
90549 @@ -1549,7 +1550,7 @@ config PROVIDE_OHCI1394_DMA_INIT
90550
90551 config FIREWIRE_OHCI_REMOTE_DMA
90552 bool "Remote debugging over FireWire with firewire-ohci"
90553 - depends on FIREWIRE_OHCI
90554 + depends on FIREWIRE_OHCI && !GRKERNSEC
90555 help
90556 This option lets you use the FireWire bus for remote debugging
90557 with help of the firewire-ohci driver. It enables unfiltered
90558 diff --git a/lib/Makefile b/lib/Makefile
90559 index 04944e9..f43eabe 100644
90560 --- a/lib/Makefile
90561 +++ b/lib/Makefile
90562 @@ -50,7 +50,7 @@ obj-$(CONFIG_GENERIC_HWEIGHT) += hweight.o
90563 obj-$(CONFIG_BTREE) += btree.o
90564 obj-$(CONFIG_ASSOCIATIVE_ARRAY) += assoc_array.o
90565 obj-$(CONFIG_DEBUG_PREEMPT) += smp_processor_id.o
90566 -obj-$(CONFIG_DEBUG_LIST) += list_debug.o
90567 +obj-y += list_debug.o
90568 obj-$(CONFIG_DEBUG_OBJECTS) += debugobjects.o
90569
90570 ifneq ($(CONFIG_HAVE_DEC_LOCK),y)
90571 diff --git a/lib/bitmap.c b/lib/bitmap.c
90572 index 06f7e4f..f3cf2b0 100644
90573 --- a/lib/bitmap.c
90574 +++ b/lib/bitmap.c
90575 @@ -422,7 +422,7 @@ int __bitmap_parse(const char *buf, unsigned int buflen,
90576 {
90577 int c, old_c, totaldigits, ndigits, nchunks, nbits;
90578 u32 chunk;
90579 - const char __user __force *ubuf = (const char __user __force *)buf;
90580 + const char __user *ubuf = (const char __force_user *)buf;
90581
90582 bitmap_zero(maskp, nmaskbits);
90583
90584 @@ -507,7 +507,7 @@ int bitmap_parse_user(const char __user *ubuf,
90585 {
90586 if (!access_ok(VERIFY_READ, ubuf, ulen))
90587 return -EFAULT;
90588 - return __bitmap_parse((const char __force *)ubuf,
90589 + return __bitmap_parse((const char __force_kernel *)ubuf,
90590 ulen, 1, maskp, nmaskbits);
90591
90592 }
90593 @@ -598,7 +598,7 @@ static int __bitmap_parselist(const char *buf, unsigned int buflen,
90594 {
90595 unsigned a, b;
90596 int c, old_c, totaldigits;
90597 - const char __user __force *ubuf = (const char __user __force *)buf;
90598 + const char __user *ubuf = (const char __force_user *)buf;
90599 int exp_digit, in_range;
90600
90601 totaldigits = c = 0;
90602 @@ -698,7 +698,7 @@ int bitmap_parselist_user(const char __user *ubuf,
90603 {
90604 if (!access_ok(VERIFY_READ, ubuf, ulen))
90605 return -EFAULT;
90606 - return __bitmap_parselist((const char __force *)ubuf,
90607 + return __bitmap_parselist((const char __force_kernel *)ubuf,
90608 ulen, 1, maskp, nmaskbits);
90609 }
90610 EXPORT_SYMBOL(bitmap_parselist_user);
90611 diff --git a/lib/bug.c b/lib/bug.c
90612 index 1686034..a9c00c8 100644
90613 --- a/lib/bug.c
90614 +++ b/lib/bug.c
90615 @@ -134,6 +134,8 @@ enum bug_trap_type report_bug(unsigned long bugaddr, struct pt_regs *regs)
90616 return BUG_TRAP_TYPE_NONE;
90617
90618 bug = find_bug(bugaddr);
90619 + if (!bug)
90620 + return BUG_TRAP_TYPE_NONE;
90621
90622 file = NULL;
90623 line = 0;
90624 diff --git a/lib/debugobjects.c b/lib/debugobjects.c
90625 index e0731c3..ad66444 100644
90626 --- a/lib/debugobjects.c
90627 +++ b/lib/debugobjects.c
90628 @@ -286,7 +286,7 @@ static void debug_object_is_on_stack(void *addr, int onstack)
90629 if (limit > 4)
90630 return;
90631
90632 - is_on_stack = object_is_on_stack(addr);
90633 + is_on_stack = object_starts_on_stack(addr);
90634 if (is_on_stack == onstack)
90635 return;
90636
90637 diff --git a/lib/devres.c b/lib/devres.c
90638 index 8235331..5881053 100644
90639 --- a/lib/devres.c
90640 +++ b/lib/devres.c
90641 @@ -81,7 +81,7 @@ EXPORT_SYMBOL(devm_ioremap_nocache);
90642 void devm_iounmap(struct device *dev, void __iomem *addr)
90643 {
90644 WARN_ON(devres_destroy(dev, devm_ioremap_release, devm_ioremap_match,
90645 - (void *)addr));
90646 + (void __force *)addr));
90647 iounmap(addr);
90648 }
90649 EXPORT_SYMBOL(devm_iounmap);
90650 @@ -224,7 +224,7 @@ void devm_ioport_unmap(struct device *dev, void __iomem *addr)
90651 {
90652 ioport_unmap(addr);
90653 WARN_ON(devres_destroy(dev, devm_ioport_map_release,
90654 - devm_ioport_map_match, (void *)addr));
90655 + devm_ioport_map_match, (void __force *)addr));
90656 }
90657 EXPORT_SYMBOL(devm_ioport_unmap);
90658 #endif /* CONFIG_HAS_IOPORT */
90659 diff --git a/lib/div64.c b/lib/div64.c
90660 index 4382ad7..08aa558 100644
90661 --- a/lib/div64.c
90662 +++ b/lib/div64.c
90663 @@ -59,7 +59,7 @@ uint32_t __attribute__((weak)) __div64_32(uint64_t *n, uint32_t base)
90664 EXPORT_SYMBOL(__div64_32);
90665
90666 #ifndef div_s64_rem
90667 -s64 div_s64_rem(s64 dividend, s32 divisor, s32 *remainder)
90668 +s64 __intentional_overflow(-1) div_s64_rem(s64 dividend, s32 divisor, s32 *remainder)
90669 {
90670 u64 quotient;
90671
90672 @@ -130,7 +130,7 @@ EXPORT_SYMBOL(div64_u64_rem);
90673 * 'http://www.hackersdelight.org/HDcode/newCode/divDouble.c.txt'
90674 */
90675 #ifndef div64_u64
90676 -u64 div64_u64(u64 dividend, u64 divisor)
90677 +u64 __intentional_overflow(-1) div64_u64(u64 dividend, u64 divisor)
90678 {
90679 u32 high = divisor >> 32;
90680 u64 quot;
90681 diff --git a/lib/dma-debug.c b/lib/dma-debug.c
90682 index d87a17a..ac0d79a 100644
90683 --- a/lib/dma-debug.c
90684 +++ b/lib/dma-debug.c
90685 @@ -768,7 +768,7 @@ static int dma_debug_device_change(struct notifier_block *nb, unsigned long acti
90686
90687 void dma_debug_add_bus(struct bus_type *bus)
90688 {
90689 - struct notifier_block *nb;
90690 + notifier_block_no_const *nb;
90691
90692 if (global_disable)
90693 return;
90694 @@ -945,7 +945,7 @@ static void check_unmap(struct dma_debug_entry *ref)
90695
90696 static void check_for_stack(struct device *dev, void *addr)
90697 {
90698 - if (object_is_on_stack(addr))
90699 + if (object_starts_on_stack(addr))
90700 err_printk(dev, NULL, "DMA-API: device driver maps memory from"
90701 "stack [addr=%p]\n", addr);
90702 }
90703 diff --git a/lib/inflate.c b/lib/inflate.c
90704 index 013a761..c28f3fc 100644
90705 --- a/lib/inflate.c
90706 +++ b/lib/inflate.c
90707 @@ -269,7 +269,7 @@ static void free(void *where)
90708 malloc_ptr = free_mem_ptr;
90709 }
90710 #else
90711 -#define malloc(a) kmalloc(a, GFP_KERNEL)
90712 +#define malloc(a) kmalloc((a), GFP_KERNEL)
90713 #define free(a) kfree(a)
90714 #endif
90715
90716 diff --git a/lib/ioremap.c b/lib/ioremap.c
90717 index 0c9216c..863bd89 100644
90718 --- a/lib/ioremap.c
90719 +++ b/lib/ioremap.c
90720 @@ -38,7 +38,7 @@ static inline int ioremap_pmd_range(pud_t *pud, unsigned long addr,
90721 unsigned long next;
90722
90723 phys_addr -= addr;
90724 - pmd = pmd_alloc(&init_mm, pud, addr);
90725 + pmd = pmd_alloc_kernel(&init_mm, pud, addr);
90726 if (!pmd)
90727 return -ENOMEM;
90728 do {
90729 @@ -56,7 +56,7 @@ static inline int ioremap_pud_range(pgd_t *pgd, unsigned long addr,
90730 unsigned long next;
90731
90732 phys_addr -= addr;
90733 - pud = pud_alloc(&init_mm, pgd, addr);
90734 + pud = pud_alloc_kernel(&init_mm, pgd, addr);
90735 if (!pud)
90736 return -ENOMEM;
90737 do {
90738 diff --git a/lib/is_single_threaded.c b/lib/is_single_threaded.c
90739 index bd2bea9..6b3c95e 100644
90740 --- a/lib/is_single_threaded.c
90741 +++ b/lib/is_single_threaded.c
90742 @@ -22,6 +22,9 @@ bool current_is_single_threaded(void)
90743 struct task_struct *p, *t;
90744 bool ret;
90745
90746 + if (!mm)
90747 + return true;
90748 +
90749 if (atomic_read(&task->signal->live) != 1)
90750 return false;
90751
90752 diff --git a/lib/kobject.c b/lib/kobject.c
90753 index 5b4b888..c2950f7 100644
90754 --- a/lib/kobject.c
90755 +++ b/lib/kobject.c
90756 @@ -957,9 +957,9 @@ EXPORT_SYMBOL_GPL(kset_create_and_add);
90757
90758
90759 static DEFINE_SPINLOCK(kobj_ns_type_lock);
90760 -static const struct kobj_ns_type_operations *kobj_ns_ops_tbl[KOBJ_NS_TYPES];
90761 +static const struct kobj_ns_type_operations *kobj_ns_ops_tbl[KOBJ_NS_TYPES] __read_only;
90762
90763 -int kobj_ns_type_register(const struct kobj_ns_type_operations *ops)
90764 +int __init kobj_ns_type_register(const struct kobj_ns_type_operations *ops)
90765 {
90766 enum kobj_ns_type type = ops->type;
90767 int error;
90768 diff --git a/lib/list_debug.c b/lib/list_debug.c
90769 index c24c2f7..f0296f4 100644
90770 --- a/lib/list_debug.c
90771 +++ b/lib/list_debug.c
90772 @@ -11,7 +11,9 @@
90773 #include <linux/bug.h>
90774 #include <linux/kernel.h>
90775 #include <linux/rculist.h>
90776 +#include <linux/mm.h>
90777
90778 +#ifdef CONFIG_DEBUG_LIST
90779 /*
90780 * Insert a new entry between two known consecutive entries.
90781 *
90782 @@ -19,21 +21,40 @@
90783 * the prev/next entries already!
90784 */
90785
90786 +static bool __list_add_debug(struct list_head *new,
90787 + struct list_head *prev,
90788 + struct list_head *next)
90789 +{
90790 + if (unlikely(next->prev != prev)) {
90791 + printk(KERN_ERR "list_add corruption. next->prev should be "
90792 + "prev (%p), but was %p. (next=%p).\n",
90793 + prev, next->prev, next);
90794 + BUG();
90795 + return false;
90796 + }
90797 + if (unlikely(prev->next != next)) {
90798 + printk(KERN_ERR "list_add corruption. prev->next should be "
90799 + "next (%p), but was %p. (prev=%p).\n",
90800 + next, prev->next, prev);
90801 + BUG();
90802 + return false;
90803 + }
90804 + if (unlikely(new == prev || new == next)) {
90805 + printk(KERN_ERR "list_add double add: new=%p, prev=%p, next=%p.\n",
90806 + new, prev, next);
90807 + BUG();
90808 + return false;
90809 + }
90810 + return true;
90811 +}
90812 +
90813 void __list_add(struct list_head *new,
90814 - struct list_head *prev,
90815 - struct list_head *next)
90816 + struct list_head *prev,
90817 + struct list_head *next)
90818 {
90819 - WARN(next->prev != prev,
90820 - "list_add corruption. next->prev should be "
90821 - "prev (%p), but was %p. (next=%p).\n",
90822 - prev, next->prev, next);
90823 - WARN(prev->next != next,
90824 - "list_add corruption. prev->next should be "
90825 - "next (%p), but was %p. (prev=%p).\n",
90826 - next, prev->next, prev);
90827 - WARN(new == prev || new == next,
90828 - "list_add double add: new=%p, prev=%p, next=%p.\n",
90829 - new, prev, next);
90830 + if (!__list_add_debug(new, prev, next))
90831 + return;
90832 +
90833 next->prev = new;
90834 new->next = next;
90835 new->prev = prev;
90836 @@ -41,28 +62,46 @@ void __list_add(struct list_head *new,
90837 }
90838 EXPORT_SYMBOL(__list_add);
90839
90840 -void __list_del_entry(struct list_head *entry)
90841 +static bool __list_del_entry_debug(struct list_head *entry)
90842 {
90843 struct list_head *prev, *next;
90844
90845 prev = entry->prev;
90846 next = entry->next;
90847
90848 - if (WARN(next == LIST_POISON1,
90849 - "list_del corruption, %p->next is LIST_POISON1 (%p)\n",
90850 - entry, LIST_POISON1) ||
90851 - WARN(prev == LIST_POISON2,
90852 - "list_del corruption, %p->prev is LIST_POISON2 (%p)\n",
90853 - entry, LIST_POISON2) ||
90854 - WARN(prev->next != entry,
90855 - "list_del corruption. prev->next should be %p, "
90856 - "but was %p\n", entry, prev->next) ||
90857 - WARN(next->prev != entry,
90858 - "list_del corruption. next->prev should be %p, "
90859 - "but was %p\n", entry, next->prev))
90860 + if (unlikely(next == LIST_POISON1)) {
90861 + printk(KERN_ERR "list_del corruption, %p->next is LIST_POISON1 (%p)\n",
90862 + entry, LIST_POISON1);
90863 + BUG();
90864 + return false;
90865 + }
90866 + if (unlikely(prev == LIST_POISON2)) {
90867 + printk(KERN_ERR "list_del corruption, %p->prev is LIST_POISON2 (%p)\n",
90868 + entry, LIST_POISON2);
90869 + BUG();
90870 + return false;
90871 + }
90872 + if (unlikely(entry->prev->next != entry)) {
90873 + printk(KERN_ERR "list_del corruption. prev->next should be %p, "
90874 + "but was %p\n", entry, prev->next);
90875 + BUG();
90876 + return false;
90877 + }
90878 + if (unlikely(entry->next->prev != entry)) {
90879 + printk(KERN_ERR "list_del corruption. next->prev should be %p, "
90880 + "but was %p\n", entry, next->prev);
90881 + BUG();
90882 + return false;
90883 + }
90884 + return true;
90885 +}
90886 +
90887 +void __list_del_entry(struct list_head *entry)
90888 +{
90889 + if (!__list_del_entry_debug(entry))
90890 return;
90891
90892 - __list_del(prev, next);
90893 + __list_del(entry->prev, entry->next);
90894 }
90895 EXPORT_SYMBOL(__list_del_entry);
90896
90897 @@ -86,15 +125,85 @@ EXPORT_SYMBOL(list_del);
90898 void __list_add_rcu(struct list_head *new,
90899 struct list_head *prev, struct list_head *next)
90900 {
90901 - WARN(next->prev != prev,
90902 - "list_add_rcu corruption. next->prev should be prev (%p), but was %p. (next=%p).\n",
90903 - prev, next->prev, next);
90904 - WARN(prev->next != next,
90905 - "list_add_rcu corruption. prev->next should be next (%p), but was %p. (prev=%p).\n",
90906 - next, prev->next, prev);
90907 + if (!__list_add_debug(new, prev, next))
90908 + return;
90909 +
90910 new->next = next;
90911 new->prev = prev;
90912 rcu_assign_pointer(list_next_rcu(prev), new);
90913 next->prev = new;
90914 }
90915 EXPORT_SYMBOL(__list_add_rcu);
90916 +#endif
90917 +
90918 +void __pax_list_add(struct list_head *new, struct list_head *prev, struct list_head *next)
90919 +{
90920 +#ifdef CONFIG_DEBUG_LIST
90921 + if (!__list_add_debug(new, prev, next))
90922 + return;
90923 +#endif
90924 +
90925 + pax_open_kernel();
90926 + next->prev = new;
90927 + new->next = next;
90928 + new->prev = prev;
90929 + prev->next = new;
90930 + pax_close_kernel();
90931 +}
90932 +EXPORT_SYMBOL(__pax_list_add);
90933 +
90934 +void pax_list_del(struct list_head *entry)
90935 +{
90936 +#ifdef CONFIG_DEBUG_LIST
90937 + if (!__list_del_entry_debug(entry))
90938 + return;
90939 +#endif
90940 +
90941 + pax_open_kernel();
90942 + __list_del(entry->prev, entry->next);
90943 + entry->next = LIST_POISON1;
90944 + entry->prev = LIST_POISON2;
90945 + pax_close_kernel();
90946 +}
90947 +EXPORT_SYMBOL(pax_list_del);
90948 +
90949 +void pax_list_del_init(struct list_head *entry)
90950 +{
90951 + pax_open_kernel();
90952 + __list_del(entry->prev, entry->next);
90953 + INIT_LIST_HEAD(entry);
90954 + pax_close_kernel();
90955 +}
90956 +EXPORT_SYMBOL(pax_list_del_init);
90957 +
90958 +void __pax_list_add_rcu(struct list_head *new,
90959 + struct list_head *prev, struct list_head *next)
90960 +{
90961 +#ifdef CONFIG_DEBUG_LIST
90962 + if (!__list_add_debug(new, prev, next))
90963 + return;
90964 +#endif
90965 +
90966 + pax_open_kernel();
90967 + new->next = next;
90968 + new->prev = prev;
90969 + rcu_assign_pointer(list_next_rcu(prev), new);
90970 + next->prev = new;
90971 + pax_close_kernel();
90972 +}
90973 +EXPORT_SYMBOL(__pax_list_add_rcu);
90974 +
90975 +void pax_list_del_rcu(struct list_head *entry)
90976 +{
90977 +#ifdef CONFIG_DEBUG_LIST
90978 + if (!__list_del_entry_debug(entry))
90979 + return;
90980 +#endif
90981 +
90982 + pax_open_kernel();
90983 + __list_del(entry->prev, entry->next);
90984 + entry->next = LIST_POISON1;
90985 + entry->prev = LIST_POISON2;
90986 + pax_close_kernel();
90987 +}
90988 +EXPORT_SYMBOL(pax_list_del_rcu);
90989 diff --git a/lib/percpu-refcount.c b/lib/percpu-refcount.c
90990 index 1a53d49..ace934c 100644
90991 --- a/lib/percpu-refcount.c
90992 +++ b/lib/percpu-refcount.c
90993 @@ -29,7 +29,7 @@
90994 * can't hit 0 before we've added up all the percpu refs.
90995 */
90996
90997 -#define PCPU_COUNT_BIAS (1U << 31)
90998 +#define PCPU_COUNT_BIAS (1U << 30)
90999
91000 /**
91001 * percpu_ref_init - initialize a percpu refcount
91002 diff --git a/lib/radix-tree.c b/lib/radix-tree.c
91003 index 7811ed3..f80ca19 100644
91004 --- a/lib/radix-tree.c
91005 +++ b/lib/radix-tree.c
91006 @@ -93,7 +93,7 @@ struct radix_tree_preload {
91007 int nr;
91008 struct radix_tree_node *nodes[RADIX_TREE_PRELOAD_SIZE];
91009 };
91010 -static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads) = { 0, };
91011 +static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads);
91012
91013 static inline void *ptr_to_indirect(void *ptr)
91014 {
91015 diff --git a/lib/random32.c b/lib/random32.c
91016 index 6148967..009bfe8 100644
91017 --- a/lib/random32.c
91018 +++ b/lib/random32.c
91019 @@ -44,7 +44,7 @@
91020 static void __init prandom_state_selftest(void);
91021 #endif
91022
91023 -static DEFINE_PER_CPU(struct rnd_state, net_rand_state);
91024 +static DEFINE_PER_CPU(struct rnd_state, net_rand_state) __latent_entropy;
91025
91026 /**
91027 * prandom_u32_state - seeded pseudo-random number generator.
91028 diff --git a/lib/rbtree.c b/lib/rbtree.c
91029 index 65f4eff..2cfa167 100644
91030 --- a/lib/rbtree.c
91031 +++ b/lib/rbtree.c
91032 @@ -380,7 +380,9 @@ static inline void dummy_copy(struct rb_node *old, struct rb_node *new) {}
91033 static inline void dummy_rotate(struct rb_node *old, struct rb_node *new) {}
91034
91035 static const struct rb_augment_callbacks dummy_callbacks = {
91036 - dummy_propagate, dummy_copy, dummy_rotate
91037 + .propagate = dummy_propagate,
91038 + .copy = dummy_copy,
91039 + .rotate = dummy_rotate
91040 };
91041
91042 void rb_insert_color(struct rb_node *node, struct rb_root *root)
91043 diff --git a/lib/strncpy_from_user.c b/lib/strncpy_from_user.c
91044 index bb2b201..46abaf9 100644
91045 --- a/lib/strncpy_from_user.c
91046 +++ b/lib/strncpy_from_user.c
91047 @@ -21,7 +21,7 @@
91048 */
91049 static inline long do_strncpy_from_user(char *dst, const char __user *src, long count, unsigned long max)
91050 {
91051 - const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
91052 + static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
91053 long res = 0;
91054
91055 /*
91056 diff --git a/lib/strnlen_user.c b/lib/strnlen_user.c
91057 index a28df52..3d55877 100644
91058 --- a/lib/strnlen_user.c
91059 +++ b/lib/strnlen_user.c
91060 @@ -26,7 +26,7 @@
91061 */
91062 static inline long do_strnlen_user(const char __user *src, unsigned long count, unsigned long max)
91063 {
91064 - const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
91065 + static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
91066 long align, res = 0;
91067 unsigned long c;
91068
91069 diff --git a/lib/swiotlb.c b/lib/swiotlb.c
91070 index e4399fa..5e8b214 100644
91071 --- a/lib/swiotlb.c
91072 +++ b/lib/swiotlb.c
91073 @@ -668,7 +668,7 @@ EXPORT_SYMBOL(swiotlb_alloc_coherent);
91074
91075 void
91076 swiotlb_free_coherent(struct device *hwdev, size_t size, void *vaddr,
91077 - dma_addr_t dev_addr)
91078 + dma_addr_t dev_addr, struct dma_attrs *attrs)
91079 {
91080 phys_addr_t paddr = dma_to_phys(hwdev, dev_addr);
91081
91082 diff --git a/lib/usercopy.c b/lib/usercopy.c
91083 index 4f5b1dd..7cab418 100644
91084 --- a/lib/usercopy.c
91085 +++ b/lib/usercopy.c
91086 @@ -7,3 +7,9 @@ void copy_from_user_overflow(void)
91087 WARN(1, "Buffer overflow detected!\n");
91088 }
91089 EXPORT_SYMBOL(copy_from_user_overflow);
91090 +
91091 +void copy_to_user_overflow(void)
91092 +{
91093 + WARN(1, "Buffer overflow detected!\n");
91094 +}
91095 +EXPORT_SYMBOL(copy_to_user_overflow);
91096 diff --git a/lib/vsprintf.c b/lib/vsprintf.c
91097 index 10909c5..653e1b8 100644
91098 --- a/lib/vsprintf.c
91099 +++ b/lib/vsprintf.c
91100 @@ -16,6 +16,9 @@
91101 * - scnprintf and vscnprintf
91102 */
91103
91104 +#ifdef CONFIG_GRKERNSEC_HIDESYM
91105 +#define __INCLUDED_BY_HIDESYM 1
91106 +#endif
91107 #include <stdarg.h>
91108 #include <linux/module.h> /* for KSYM_SYMBOL_LEN */
91109 #include <linux/types.h>
91110 @@ -1155,7 +1158,11 @@ char *netdev_feature_string(char *buf, char *end, const u8 *addr,
91111 return number(buf, end, *(const netdev_features_t *)addr, spec);
91112 }
91113
91114 +#ifdef CONFIG_GRKERNSEC_HIDESYM
91115 +int kptr_restrict __read_mostly = 2;
91116 +#else
91117 int kptr_restrict __read_mostly;
91118 +#endif
91119
91120 /*
91121 * Show a '%p' thing. A kernel extension is that the '%p' is followed
91122 @@ -1168,6 +1175,7 @@ int kptr_restrict __read_mostly;
91123 * - 'f' For simple symbolic function names without offset
91124 * - 'S' For symbolic direct pointers with offset
91125 * - 's' For symbolic direct pointers without offset
91126 + * - 'A' For symbolic direct pointers with offset approved for use with GRKERNSEC_HIDESYM
91127 * - '[FfSs]R' as above with __builtin_extract_return_addr() translation
91128 * - 'B' For backtraced symbolic direct pointers with offset
91129 * - 'R' For decoded struct resource, e.g., [mem 0x0-0x1f 64bit pref]
91130 @@ -1234,12 +1242,12 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
91131
91132 if (!ptr && *fmt != 'K') {
91133 /*
91134 - * Print (null) with the same width as a pointer so it makes
91135 + * Print (nil) with the same width as a pointer so it makes
91136 * tabular output look nice.
91137 */
91138 if (spec.field_width == -1)
91139 spec.field_width = default_width;
91140 - return string(buf, end, "(null)", spec);
91141 + return string(buf, end, "(nil)", spec);
91142 }
91143
91144 switch (*fmt) {
91145 @@ -1249,6 +1257,12 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
91146 /* Fallthrough */
91147 case 'S':
91148 case 's':
91149 +#ifdef CONFIG_GRKERNSEC_HIDESYM
91150 + break;
91151 +#else
91152 + return symbol_string(buf, end, ptr, spec, fmt);
91153 +#endif
91154 + case 'A':
91155 case 'B':
91156 return symbol_string(buf, end, ptr, spec, fmt);
91157 case 'R':
91158 @@ -1304,6 +1318,8 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
91159 va_end(va);
91160 return buf;
91161 }
91162 + case 'P':
91163 + break;
91164 case 'K':
91165 /*
91166 * %pK cannot be used in IRQ context because its test
91167 @@ -1365,6 +1381,21 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
91168 ((const struct file *)ptr)->f_path.dentry,
91169 spec, fmt);
91170 }
91171 +
91172 +#ifdef CONFIG_GRKERNSEC_HIDESYM
91173 + /* 'P' = approved pointers to copy to userland,
91174 + as in the /proc/kallsyms case, as we make it display nothing
91175 + for non-root users, and the real contents for root users
91176 + Also ignore 'K' pointers, since we force their NULLing for non-root users
91177 + above
91178 + */
91179 + if ((unsigned long)ptr > TASK_SIZE && *fmt != 'P' && *fmt != 'K' && is_usercopy_object(buf)) {
91180 + printk(KERN_ALERT "grsec: kernel infoleak detected! Please report this log to spender@grsecurity.net.\n");
91181 + dump_stack();
91182 + ptr = NULL;
91183 + }
91184 +#endif
91185 +
91186 spec.flags |= SMALL;
91187 if (spec.field_width == -1) {
91188 spec.field_width = default_width;
91189 @@ -2086,11 +2117,11 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
91190 typeof(type) value; \
91191 if (sizeof(type) == 8) { \
91192 args = PTR_ALIGN(args, sizeof(u32)); \
91193 - *(u32 *)&value = *(u32 *)args; \
91194 - *((u32 *)&value + 1) = *(u32 *)(args + 4); \
91195 + *(u32 *)&value = *(const u32 *)args; \
91196 + *((u32 *)&value + 1) = *(const u32 *)(args + 4); \
91197 } else { \
91198 args = PTR_ALIGN(args, sizeof(type)); \
91199 - value = *(typeof(type) *)args; \
91200 + value = *(const typeof(type) *)args; \
91201 } \
91202 args += sizeof(type); \
91203 value; \
91204 @@ -2153,7 +2184,7 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
91205 case FORMAT_TYPE_STR: {
91206 const char *str_arg = args;
91207 args += strlen(str_arg) + 1;
91208 - str = string(str, end, (char *)str_arg, spec);
91209 + str = string(str, end, str_arg, spec);
91210 break;
91211 }
91212
91213 diff --git a/localversion-grsec b/localversion-grsec
91214 new file mode 100644
91215 index 0000000..7cd6065
91216 --- /dev/null
91217 +++ b/localversion-grsec
91218 @@ -0,0 +1 @@
91219 +-grsec
91220 diff --git a/mm/Kconfig b/mm/Kconfig
91221 index 723bbe0..ea624b1 100644
91222 --- a/mm/Kconfig
91223 +++ b/mm/Kconfig
91224 @@ -326,10 +326,11 @@ config KSM
91225 root has set /sys/kernel/mm/ksm/run to 1 (if CONFIG_SYSFS is set).
91226
91227 config DEFAULT_MMAP_MIN_ADDR
91228 - int "Low address space to protect from user allocation"
91229 + int "Low address space to protect from user allocation"
91230 depends on MMU
91231 - default 4096
91232 - help
91233 + default 32768 if ALPHA || ARM || PARISC || SPARC32
91234 + default 65536
91235 + help
91236 This is the portion of low virtual memory which should be protected
91237 from userspace allocation. Keeping a user from writing to low pages
91238 can help reduce the impact of kernel NULL pointer bugs.
91239 @@ -360,7 +361,7 @@ config MEMORY_FAILURE
91240
91241 config HWPOISON_INJECT
91242 tristate "HWPoison pages injector"
91243 - depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS
91244 + depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS && !GRKERNSEC
91245 select PROC_PAGE_MONITOR
91246
91247 config NOMMU_INITIAL_TRIM_EXCESS
91248 diff --git a/mm/backing-dev.c b/mm/backing-dev.c
91249 index ce682f7..1fb54f9 100644
91250 --- a/mm/backing-dev.c
91251 +++ b/mm/backing-dev.c
91252 @@ -12,7 +12,7 @@
91253 #include <linux/device.h>
91254 #include <trace/events/writeback.h>
91255
91256 -static atomic_long_t bdi_seq = ATOMIC_LONG_INIT(0);
91257 +static atomic_long_unchecked_t bdi_seq = ATOMIC_LONG_INIT(0);
91258
91259 struct backing_dev_info default_backing_dev_info = {
91260 .name = "default",
91261 @@ -525,7 +525,7 @@ int bdi_setup_and_register(struct backing_dev_info *bdi, char *name,
91262 return err;
91263
91264 err = bdi_register(bdi, NULL, "%.28s-%ld", name,
91265 - atomic_long_inc_return(&bdi_seq));
91266 + atomic_long_inc_return_unchecked(&bdi_seq));
91267 if (err) {
91268 bdi_destroy(bdi);
91269 return err;
91270 diff --git a/mm/filemap.c b/mm/filemap.c
91271 index b7749a9..50d1123 100644
91272 --- a/mm/filemap.c
91273 +++ b/mm/filemap.c
91274 @@ -1768,7 +1768,7 @@ int generic_file_mmap(struct file * file, struct vm_area_struct * vma)
91275 struct address_space *mapping = file->f_mapping;
91276
91277 if (!mapping->a_ops->readpage)
91278 - return -ENOEXEC;
91279 + return -ENODEV;
91280 file_accessed(file);
91281 vma->vm_ops = &generic_file_vm_ops;
91282 return 0;
91283 @@ -1950,7 +1950,7 @@ static size_t __iovec_copy_from_user_inatomic(char *vaddr,
91284
91285 while (bytes) {
91286 char __user *buf = iov->iov_base + base;
91287 - int copy = min(bytes, iov->iov_len - base);
91288 + size_t copy = min(bytes, iov->iov_len - base);
91289
91290 base = 0;
91291 left = __copy_from_user_inatomic(vaddr, buf, copy);
91292 @@ -1979,7 +1979,7 @@ size_t iov_iter_copy_from_user_atomic(struct page *page,
91293 BUG_ON(!in_atomic());
91294 kaddr = kmap_atomic(page);
91295 if (likely(i->nr_segs == 1)) {
91296 - int left;
91297 + size_t left;
91298 char __user *buf = i->iov->iov_base + i->iov_offset;
91299 left = __copy_from_user_inatomic(kaddr + offset, buf, bytes);
91300 copied = bytes - left;
91301 @@ -2007,7 +2007,7 @@ size_t iov_iter_copy_from_user(struct page *page,
91302
91303 kaddr = kmap(page);
91304 if (likely(i->nr_segs == 1)) {
91305 - int left;
91306 + size_t left;
91307 char __user *buf = i->iov->iov_base + i->iov_offset;
91308 left = __copy_from_user(kaddr + offset, buf, bytes);
91309 copied = bytes - left;
91310 @@ -2037,7 +2037,7 @@ void iov_iter_advance(struct iov_iter *i, size_t bytes)
91311 * zero-length segments (without overruning the iovec).
91312 */
91313 while (bytes || unlikely(i->count && !iov->iov_len)) {
91314 - int copy;
91315 + size_t copy;
91316
91317 copy = min(bytes, iov->iov_len - base);
91318 BUG_ON(!i->count || i->count < copy);
91319 @@ -2108,6 +2108,7 @@ inline int generic_write_checks(struct file *file, loff_t *pos, size_t *count, i
91320 *pos = i_size_read(inode);
91321
91322 if (limit != RLIM_INFINITY) {
91323 + gr_learn_resource(current, RLIMIT_FSIZE,*pos, 0);
91324 if (*pos >= limit) {
91325 send_sig(SIGXFSZ, current, 0);
91326 return -EFBIG;
91327 diff --git a/mm/fremap.c b/mm/fremap.c
91328 index bbc4d66..117b798 100644
91329 --- a/mm/fremap.c
91330 +++ b/mm/fremap.c
91331 @@ -163,6 +163,11 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
91332 retry:
91333 vma = find_vma(mm, start);
91334
91335 +#ifdef CONFIG_PAX_SEGMEXEC
91336 + if (vma && (mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_MAYEXEC))
91337 + goto out;
91338 +#endif
91339 +
91340 /*
91341 * Make sure the vma is shared, that it supports prefaulting,
91342 * and that the remapped range is valid and fully within
91343 diff --git a/mm/highmem.c b/mm/highmem.c
91344 index b32b70c..e512eb0 100644
91345 --- a/mm/highmem.c
91346 +++ b/mm/highmem.c
91347 @@ -138,8 +138,9 @@ static void flush_all_zero_pkmaps(void)
91348 * So no dangers, even with speculative execution.
91349 */
91350 page = pte_page(pkmap_page_table[i]);
91351 + pax_open_kernel();
91352 pte_clear(&init_mm, PKMAP_ADDR(i), &pkmap_page_table[i]);
91353 -
91354 + pax_close_kernel();
91355 set_page_address(page, NULL);
91356 need_flush = 1;
91357 }
91358 @@ -198,9 +199,11 @@ start:
91359 }
91360 }
91361 vaddr = PKMAP_ADDR(last_pkmap_nr);
91362 +
91363 + pax_open_kernel();
91364 set_pte_at(&init_mm, vaddr,
91365 &(pkmap_page_table[last_pkmap_nr]), mk_pte(page, kmap_prot));
91366 -
91367 + pax_close_kernel();
91368 pkmap_count[last_pkmap_nr] = 1;
91369 set_page_address(page, (void *)vaddr);
91370
91371 diff --git a/mm/hugetlb.c b/mm/hugetlb.c
91372 index dee6cf4..52b94f7 100644
91373 --- a/mm/hugetlb.c
91374 +++ b/mm/hugetlb.c
91375 @@ -2077,15 +2077,17 @@ static int hugetlb_sysctl_handler_common(bool obey_mempolicy,
91376 struct hstate *h = &default_hstate;
91377 unsigned long tmp;
91378 int ret;
91379 + ctl_table_no_const hugetlb_table;
91380
91381 tmp = h->max_huge_pages;
91382
91383 if (write && h->order >= MAX_ORDER)
91384 return -EINVAL;
91385
91386 - table->data = &tmp;
91387 - table->maxlen = sizeof(unsigned long);
91388 - ret = proc_doulongvec_minmax(table, write, buffer, length, ppos);
91389 + hugetlb_table = *table;
91390 + hugetlb_table.data = &tmp;
91391 + hugetlb_table.maxlen = sizeof(unsigned long);
91392 + ret = proc_doulongvec_minmax(&hugetlb_table, write, buffer, length, ppos);
91393 if (ret)
91394 goto out;
91395
91396 @@ -2130,15 +2132,17 @@ int hugetlb_overcommit_handler(struct ctl_table *table, int write,
91397 struct hstate *h = &default_hstate;
91398 unsigned long tmp;
91399 int ret;
91400 + ctl_table_no_const hugetlb_table;
91401
91402 tmp = h->nr_overcommit_huge_pages;
91403
91404 if (write && h->order >= MAX_ORDER)
91405 return -EINVAL;
91406
91407 - table->data = &tmp;
91408 - table->maxlen = sizeof(unsigned long);
91409 - ret = proc_doulongvec_minmax(table, write, buffer, length, ppos);
91410 + hugetlb_table = *table;
91411 + hugetlb_table.data = &tmp;
91412 + hugetlb_table.maxlen = sizeof(unsigned long);
91413 + ret = proc_doulongvec_minmax(&hugetlb_table, write, buffer, length, ppos);
91414 if (ret)
91415 goto out;
91416
91417 @@ -2596,6 +2600,27 @@ static int unmap_ref_private(struct mm_struct *mm, struct vm_area_struct *vma,
91418 return 1;
91419 }
91420
91421 +#ifdef CONFIG_PAX_SEGMEXEC
91422 +static void pax_mirror_huge_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m)
91423 +{
91424 + struct mm_struct *mm = vma->vm_mm;
91425 + struct vm_area_struct *vma_m;
91426 + unsigned long address_m;
91427 + pte_t *ptep_m;
91428 +
91429 + vma_m = pax_find_mirror_vma(vma);
91430 + if (!vma_m)
91431 + return;
91432 +
91433 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
91434 + address_m = address + SEGMEXEC_TASK_SIZE;
91435 + ptep_m = huge_pte_offset(mm, address_m & HPAGE_MASK);
91436 + get_page(page_m);
91437 + hugepage_add_anon_rmap(page_m, vma_m, address_m);
91438 + set_huge_pte_at(mm, address_m, ptep_m, make_huge_pte(vma_m, page_m, 0));
91439 +}
91440 +#endif
91441 +
91442 /*
91443 * Hugetlb_cow() should be called with page lock of the original hugepage held.
91444 * Called with hugetlb_instantiation_mutex held and pte_page locked so we
91445 @@ -2712,6 +2737,11 @@ retry_avoidcopy:
91446 make_huge_pte(vma, new_page, 1));
91447 page_remove_rmap(old_page);
91448 hugepage_add_new_anon_rmap(new_page, vma, address);
91449 +
91450 +#ifdef CONFIG_PAX_SEGMEXEC
91451 + pax_mirror_huge_pte(vma, address, new_page);
91452 +#endif
91453 +
91454 /* Make the old page be freed below */
91455 new_page = old_page;
91456 }
91457 @@ -2876,6 +2906,10 @@ retry:
91458 && (vma->vm_flags & VM_SHARED)));
91459 set_huge_pte_at(mm, address, ptep, new_pte);
91460
91461 +#ifdef CONFIG_PAX_SEGMEXEC
91462 + pax_mirror_huge_pte(vma, address, page);
91463 +#endif
91464 +
91465 if ((flags & FAULT_FLAG_WRITE) && !(vma->vm_flags & VM_SHARED)) {
91466 /* Optimization, do the COW without a second fault */
91467 ret = hugetlb_cow(mm, vma, address, ptep, new_pte, page, ptl);
91468 @@ -2906,6 +2940,10 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
91469 static DEFINE_MUTEX(hugetlb_instantiation_mutex);
91470 struct hstate *h = hstate_vma(vma);
91471
91472 +#ifdef CONFIG_PAX_SEGMEXEC
91473 + struct vm_area_struct *vma_m;
91474 +#endif
91475 +
91476 address &= huge_page_mask(h);
91477
91478 ptep = huge_pte_offset(mm, address);
91479 @@ -2919,6 +2957,26 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
91480 VM_FAULT_SET_HINDEX(hstate_index(h));
91481 }
91482
91483 +#ifdef CONFIG_PAX_SEGMEXEC
91484 + vma_m = pax_find_mirror_vma(vma);
91485 + if (vma_m) {
91486 + unsigned long address_m;
91487 +
91488 + if (vma->vm_start > vma_m->vm_start) {
91489 + address_m = address;
91490 + address -= SEGMEXEC_TASK_SIZE;
91491 + vma = vma_m;
91492 + h = hstate_vma(vma);
91493 + } else
91494 + address_m = address + SEGMEXEC_TASK_SIZE;
91495 +
91496 + if (!huge_pte_alloc(mm, address_m, huge_page_size(h)))
91497 + return VM_FAULT_OOM;
91498 + address_m &= HPAGE_MASK;
91499 + unmap_hugepage_range(vma, address_m, address_m + HPAGE_SIZE, NULL);
91500 + }
91501 +#endif
91502 +
91503 ptep = huge_pte_alloc(mm, address, huge_page_size(h));
91504 if (!ptep)
91505 return VM_FAULT_OOM;
91506 diff --git a/mm/internal.h b/mm/internal.h
91507 index 8b6cfd6..ec809a6 100644
91508 --- a/mm/internal.h
91509 +++ b/mm/internal.h
91510 @@ -96,6 +96,7 @@ extern pmd_t *mm_find_pmd(struct mm_struct *mm, unsigned long address);
91511 * in mm/page_alloc.c
91512 */
91513 extern void __free_pages_bootmem(struct page *page, unsigned int order);
91514 +extern void free_compound_page(struct page *page);
91515 extern void prep_compound_page(struct page *page, unsigned long order);
91516 #ifdef CONFIG_MEMORY_FAILURE
91517 extern bool is_free_buddy_page(struct page *page);
91518 @@ -351,7 +352,7 @@ extern u32 hwpoison_filter_enable;
91519
91520 extern unsigned long vm_mmap_pgoff(struct file *, unsigned long,
91521 unsigned long, unsigned long,
91522 - unsigned long, unsigned long);
91523 + unsigned long, unsigned long) __intentional_overflow(-1);
91524
91525 extern void set_pageblock_order(void);
91526 unsigned long reclaim_clean_pages_from_list(struct zone *zone,
91527 diff --git a/mm/kmemleak.c b/mm/kmemleak.c
91528 index 31f01c5..7015178 100644
91529 --- a/mm/kmemleak.c
91530 +++ b/mm/kmemleak.c
91531 @@ -363,7 +363,7 @@ static void print_unreferenced(struct seq_file *seq,
91532
91533 for (i = 0; i < object->trace_len; i++) {
91534 void *ptr = (void *)object->trace[i];
91535 - seq_printf(seq, " [<%p>] %pS\n", ptr, ptr);
91536 + seq_printf(seq, " [<%pP>] %pA\n", ptr, ptr);
91537 }
91538 }
91539
91540 @@ -1853,7 +1853,7 @@ static int __init kmemleak_late_init(void)
91541 return -ENOMEM;
91542 }
91543
91544 - dentry = debugfs_create_file("kmemleak", S_IRUGO, NULL, NULL,
91545 + dentry = debugfs_create_file("kmemleak", S_IRUSR, NULL, NULL,
91546 &kmemleak_fops);
91547 if (!dentry)
91548 pr_warning("Failed to create the debugfs kmemleak file\n");
91549 diff --git a/mm/maccess.c b/mm/maccess.c
91550 index d53adf9..03a24bf 100644
91551 --- a/mm/maccess.c
91552 +++ b/mm/maccess.c
91553 @@ -26,7 +26,7 @@ long __probe_kernel_read(void *dst, const void *src, size_t size)
91554 set_fs(KERNEL_DS);
91555 pagefault_disable();
91556 ret = __copy_from_user_inatomic(dst,
91557 - (__force const void __user *)src, size);
91558 + (const void __force_user *)src, size);
91559 pagefault_enable();
91560 set_fs(old_fs);
91561
91562 @@ -53,7 +53,7 @@ long __probe_kernel_write(void *dst, const void *src, size_t size)
91563
91564 set_fs(KERNEL_DS);
91565 pagefault_disable();
91566 - ret = __copy_to_user_inatomic((__force void __user *)dst, src, size);
91567 + ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
91568 pagefault_enable();
91569 set_fs(old_fs);
91570
91571 diff --git a/mm/madvise.c b/mm/madvise.c
91572 index 539eeb9..e24a987 100644
91573 --- a/mm/madvise.c
91574 +++ b/mm/madvise.c
91575 @@ -51,6 +51,10 @@ static long madvise_behavior(struct vm_area_struct *vma,
91576 pgoff_t pgoff;
91577 unsigned long new_flags = vma->vm_flags;
91578
91579 +#ifdef CONFIG_PAX_SEGMEXEC
91580 + struct vm_area_struct *vma_m;
91581 +#endif
91582 +
91583 switch (behavior) {
91584 case MADV_NORMAL:
91585 new_flags = new_flags & ~VM_RAND_READ & ~VM_SEQ_READ;
91586 @@ -126,6 +130,13 @@ success:
91587 /*
91588 * vm_flags is protected by the mmap_sem held in write mode.
91589 */
91590 +
91591 +#ifdef CONFIG_PAX_SEGMEXEC
91592 + vma_m = pax_find_mirror_vma(vma);
91593 + if (vma_m)
91594 + vma_m->vm_flags = new_flags & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT);
91595 +#endif
91596 +
91597 vma->vm_flags = new_flags;
91598
91599 out:
91600 @@ -274,6 +285,11 @@ static long madvise_dontneed(struct vm_area_struct *vma,
91601 struct vm_area_struct **prev,
91602 unsigned long start, unsigned long end)
91603 {
91604 +
91605 +#ifdef CONFIG_PAX_SEGMEXEC
91606 + struct vm_area_struct *vma_m;
91607 +#endif
91608 +
91609 *prev = vma;
91610 if (vma->vm_flags & (VM_LOCKED|VM_HUGETLB|VM_PFNMAP))
91611 return -EINVAL;
91612 @@ -286,6 +302,21 @@ static long madvise_dontneed(struct vm_area_struct *vma,
91613 zap_page_range(vma, start, end - start, &details);
91614 } else
91615 zap_page_range(vma, start, end - start, NULL);
91616 +
91617 +#ifdef CONFIG_PAX_SEGMEXEC
91618 + vma_m = pax_find_mirror_vma(vma);
91619 + if (vma_m) {
91620 + if (unlikely(vma->vm_flags & VM_NONLINEAR)) {
91621 + struct zap_details details = {
91622 + .nonlinear_vma = vma_m,
91623 + .last_index = ULONG_MAX,
91624 + };
91625 + zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, &details);
91626 + } else
91627 + zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, NULL);
91628 + }
91629 +#endif
91630 +
91631 return 0;
91632 }
91633
91634 @@ -491,6 +522,16 @@ SYSCALL_DEFINE3(madvise, unsigned long, start, size_t, len_in, int, behavior)
91635 if (end < start)
91636 return error;
91637
91638 +#ifdef CONFIG_PAX_SEGMEXEC
91639 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
91640 + if (end > SEGMEXEC_TASK_SIZE)
91641 + return error;
91642 + } else
91643 +#endif
91644 +
91645 + if (end > TASK_SIZE)
91646 + return error;
91647 +
91648 error = 0;
91649 if (end == start)
91650 return error;
91651 diff --git a/mm/memory-failure.c b/mm/memory-failure.c
91652 index 4566e8f..46be98c 100644
91653 --- a/mm/memory-failure.c
91654 +++ b/mm/memory-failure.c
91655 @@ -61,7 +61,7 @@ int sysctl_memory_failure_early_kill __read_mostly = 0;
91656
91657 int sysctl_memory_failure_recovery __read_mostly = 1;
91658
91659 -atomic_long_t num_poisoned_pages __read_mostly = ATOMIC_LONG_INIT(0);
91660 +atomic_long_unchecked_t num_poisoned_pages __read_mostly = ATOMIC_LONG_INIT(0);
91661
91662 #if defined(CONFIG_HWPOISON_INJECT) || defined(CONFIG_HWPOISON_INJECT_MODULE)
91663
91664 @@ -202,7 +202,7 @@ static int kill_proc(struct task_struct *t, unsigned long addr, int trapno,
91665 pfn, t->comm, t->pid);
91666 si.si_signo = SIGBUS;
91667 si.si_errno = 0;
91668 - si.si_addr = (void *)addr;
91669 + si.si_addr = (void __user *)addr;
91670 #ifdef __ARCH_SI_TRAPNO
91671 si.si_trapno = trapno;
91672 #endif
91673 @@ -762,7 +762,7 @@ static struct page_state {
91674 unsigned long res;
91675 char *msg;
91676 int (*action)(struct page *p, unsigned long pfn);
91677 -} error_states[] = {
91678 +} __do_const error_states[] = {
91679 { reserved, reserved, "reserved kernel", me_kernel },
91680 /*
91681 * free pages are specially detected outside this table:
91682 @@ -1062,7 +1062,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
91683 nr_pages = 1 << compound_order(hpage);
91684 else /* normal page or thp */
91685 nr_pages = 1;
91686 - atomic_long_add(nr_pages, &num_poisoned_pages);
91687 + atomic_long_add_unchecked(nr_pages, &num_poisoned_pages);
91688
91689 /*
91690 * We need/can do nothing about count=0 pages.
91691 @@ -1092,7 +1092,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
91692 if (!PageHWPoison(hpage)
91693 || (hwpoison_filter(p) && TestClearPageHWPoison(p))
91694 || (p != hpage && TestSetPageHWPoison(hpage))) {
91695 - atomic_long_sub(nr_pages, &num_poisoned_pages);
91696 + atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
91697 return 0;
91698 }
91699 set_page_hwpoison_huge_page(hpage);
91700 @@ -1161,7 +1161,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
91701 }
91702 if (hwpoison_filter(p)) {
91703 if (TestClearPageHWPoison(p))
91704 - atomic_long_sub(nr_pages, &num_poisoned_pages);
91705 + atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
91706 unlock_page(hpage);
91707 put_page(hpage);
91708 return 0;
91709 @@ -1383,7 +1383,7 @@ int unpoison_memory(unsigned long pfn)
91710 return 0;
91711 }
91712 if (TestClearPageHWPoison(p))
91713 - atomic_long_dec(&num_poisoned_pages);
91714 + atomic_long_dec_unchecked(&num_poisoned_pages);
91715 pr_info("MCE: Software-unpoisoned free page %#lx\n", pfn);
91716 return 0;
91717 }
91718 @@ -1397,7 +1397,7 @@ int unpoison_memory(unsigned long pfn)
91719 */
91720 if (TestClearPageHWPoison(page)) {
91721 pr_info("MCE: Software-unpoisoned page %#lx\n", pfn);
91722 - atomic_long_sub(nr_pages, &num_poisoned_pages);
91723 + atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
91724 freeit = 1;
91725 if (PageHuge(page))
91726 clear_page_hwpoison_huge_page(page);
91727 @@ -1522,11 +1522,11 @@ static int soft_offline_huge_page(struct page *page, int flags)
91728 if (PageHuge(page)) {
91729 set_page_hwpoison_huge_page(hpage);
91730 dequeue_hwpoisoned_huge_page(hpage);
91731 - atomic_long_add(1 << compound_order(hpage),
91732 + atomic_long_add_unchecked(1 << compound_order(hpage),
91733 &num_poisoned_pages);
91734 } else {
91735 SetPageHWPoison(page);
91736 - atomic_long_inc(&num_poisoned_pages);
91737 + atomic_long_inc_unchecked(&num_poisoned_pages);
91738 }
91739 }
91740 return ret;
91741 @@ -1565,7 +1565,7 @@ static int __soft_offline_page(struct page *page, int flags)
91742 put_page(page);
91743 pr_info("soft_offline: %#lx: invalidated\n", pfn);
91744 SetPageHWPoison(page);
91745 - atomic_long_inc(&num_poisoned_pages);
91746 + atomic_long_inc_unchecked(&num_poisoned_pages);
91747 return 0;
91748 }
91749
91750 @@ -1610,7 +1610,7 @@ static int __soft_offline_page(struct page *page, int flags)
91751 if (!is_free_buddy_page(page))
91752 pr_info("soft offline: %#lx: page leaked\n",
91753 pfn);
91754 - atomic_long_inc(&num_poisoned_pages);
91755 + atomic_long_inc_unchecked(&num_poisoned_pages);
91756 }
91757 } else {
91758 pr_info("soft offline: %#lx: isolation failed: %d, page count %d, type %lx\n",
91759 @@ -1684,11 +1684,11 @@ int soft_offline_page(struct page *page, int flags)
91760 if (PageHuge(page)) {
91761 set_page_hwpoison_huge_page(hpage);
91762 dequeue_hwpoisoned_huge_page(hpage);
91763 - atomic_long_add(1 << compound_order(hpage),
91764 + atomic_long_add_unchecked(1 << compound_order(hpage),
91765 &num_poisoned_pages);
91766 } else {
91767 SetPageHWPoison(page);
91768 - atomic_long_inc(&num_poisoned_pages);
91769 + atomic_long_inc_unchecked(&num_poisoned_pages);
91770 }
91771 }
91772 unset_migratetype_isolate(page, MIGRATE_MOVABLE);
91773 diff --git a/mm/memory.c b/mm/memory.c
91774 index dda27b9..c56b9d6 100644
91775 --- a/mm/memory.c
91776 +++ b/mm/memory.c
91777 @@ -402,6 +402,7 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
91778 free_pte_range(tlb, pmd, addr);
91779 } while (pmd++, addr = next, addr != end);
91780
91781 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_PER_CPU_PGD)
91782 start &= PUD_MASK;
91783 if (start < floor)
91784 return;
91785 @@ -416,6 +417,8 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
91786 pmd = pmd_offset(pud, start);
91787 pud_clear(pud);
91788 pmd_free_tlb(tlb, pmd, start);
91789 +#endif
91790 +
91791 }
91792
91793 static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
91794 @@ -435,6 +438,7 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
91795 free_pmd_range(tlb, pud, addr, next, floor, ceiling);
91796 } while (pud++, addr = next, addr != end);
91797
91798 +#if !defined(CONFIG_X86_64) || !defined(CONFIG_PAX_PER_CPU_PGD)
91799 start &= PGDIR_MASK;
91800 if (start < floor)
91801 return;
91802 @@ -449,6 +453,8 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
91803 pud = pud_offset(pgd, start);
91804 pgd_clear(pgd);
91805 pud_free_tlb(tlb, pud, start);
91806 +#endif
91807 +
91808 }
91809
91810 /*
91811 @@ -1635,12 +1641,6 @@ no_page_table:
91812 return page;
91813 }
91814
91815 -static inline int stack_guard_page(struct vm_area_struct *vma, unsigned long addr)
91816 -{
91817 - return stack_guard_page_start(vma, addr) ||
91818 - stack_guard_page_end(vma, addr+PAGE_SIZE);
91819 -}
91820 -
91821 /**
91822 * __get_user_pages() - pin user pages in memory
91823 * @tsk: task_struct of target task
91824 @@ -1727,10 +1727,10 @@ long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
91825
91826 i = 0;
91827
91828 - do {
91829 + while (nr_pages) {
91830 struct vm_area_struct *vma;
91831
91832 - vma = find_extend_vma(mm, start);
91833 + vma = find_vma(mm, start);
91834 if (!vma && in_gate_area(mm, start)) {
91835 unsigned long pg = start & PAGE_MASK;
91836 pgd_t *pgd;
91837 @@ -1779,7 +1779,7 @@ long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
91838 goto next_page;
91839 }
91840
91841 - if (!vma ||
91842 + if (!vma || start < vma->vm_start ||
91843 (vma->vm_flags & (VM_IO | VM_PFNMAP)) ||
91844 !(vm_flags & vma->vm_flags))
91845 return i ? : -EFAULT;
91846 @@ -1808,11 +1808,6 @@ long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
91847 int ret;
91848 unsigned int fault_flags = 0;
91849
91850 - /* For mlock, just skip the stack guard page. */
91851 - if (foll_flags & FOLL_MLOCK) {
91852 - if (stack_guard_page(vma, start))
91853 - goto next_page;
91854 - }
91855 if (foll_flags & FOLL_WRITE)
91856 fault_flags |= FAULT_FLAG_WRITE;
91857 if (nonblocking)
91858 @@ -1892,7 +1887,7 @@ next_page:
91859 start += page_increm * PAGE_SIZE;
91860 nr_pages -= page_increm;
91861 } while (nr_pages && start < vma->vm_end);
91862 - } while (nr_pages);
91863 + }
91864 return i;
91865 }
91866 EXPORT_SYMBOL(__get_user_pages);
91867 @@ -2099,6 +2094,10 @@ static int insert_page(struct vm_area_struct *vma, unsigned long addr,
91868 page_add_file_rmap(page);
91869 set_pte_at(mm, addr, pte, mk_pte(page, prot));
91870
91871 +#ifdef CONFIG_PAX_SEGMEXEC
91872 + pax_mirror_file_pte(vma, addr, page, ptl);
91873 +#endif
91874 +
91875 retval = 0;
91876 pte_unmap_unlock(pte, ptl);
91877 return retval;
91878 @@ -2143,9 +2142,21 @@ int vm_insert_page(struct vm_area_struct *vma, unsigned long addr,
91879 if (!page_count(page))
91880 return -EINVAL;
91881 if (!(vma->vm_flags & VM_MIXEDMAP)) {
91882 +
91883 +#ifdef CONFIG_PAX_SEGMEXEC
91884 + struct vm_area_struct *vma_m;
91885 +#endif
91886 +
91887 BUG_ON(down_read_trylock(&vma->vm_mm->mmap_sem));
91888 BUG_ON(vma->vm_flags & VM_PFNMAP);
91889 vma->vm_flags |= VM_MIXEDMAP;
91890 +
91891 +#ifdef CONFIG_PAX_SEGMEXEC
91892 + vma_m = pax_find_mirror_vma(vma);
91893 + if (vma_m)
91894 + vma_m->vm_flags |= VM_MIXEDMAP;
91895 +#endif
91896 +
91897 }
91898 return insert_page(vma, addr, page, vma->vm_page_prot);
91899 }
91900 @@ -2228,6 +2239,7 @@ int vm_insert_mixed(struct vm_area_struct *vma, unsigned long addr,
91901 unsigned long pfn)
91902 {
91903 BUG_ON(!(vma->vm_flags & VM_MIXEDMAP));
91904 + BUG_ON(vma->vm_mirror);
91905
91906 if (addr < vma->vm_start || addr >= vma->vm_end)
91907 return -EFAULT;
91908 @@ -2475,7 +2487,9 @@ static int apply_to_pmd_range(struct mm_struct *mm, pud_t *pud,
91909
91910 BUG_ON(pud_huge(*pud));
91911
91912 - pmd = pmd_alloc(mm, pud, addr);
91913 + pmd = (mm == &init_mm) ?
91914 + pmd_alloc_kernel(mm, pud, addr) :
91915 + pmd_alloc(mm, pud, addr);
91916 if (!pmd)
91917 return -ENOMEM;
91918 do {
91919 @@ -2495,7 +2509,9 @@ static int apply_to_pud_range(struct mm_struct *mm, pgd_t *pgd,
91920 unsigned long next;
91921 int err;
91922
91923 - pud = pud_alloc(mm, pgd, addr);
91924 + pud = (mm == &init_mm) ?
91925 + pud_alloc_kernel(mm, pgd, addr) :
91926 + pud_alloc(mm, pgd, addr);
91927 if (!pud)
91928 return -ENOMEM;
91929 do {
91930 @@ -2583,6 +2599,186 @@ static inline void cow_user_page(struct page *dst, struct page *src, unsigned lo
91931 copy_user_highpage(dst, src, va, vma);
91932 }
91933
91934 +#ifdef CONFIG_PAX_SEGMEXEC
91935 +static void pax_unmap_mirror_pte(struct vm_area_struct *vma, unsigned long address, pmd_t *pmd)
91936 +{
91937 + struct mm_struct *mm = vma->vm_mm;
91938 + spinlock_t *ptl;
91939 + pte_t *pte, entry;
91940 +
91941 + pte = pte_offset_map_lock(mm, pmd, address, &ptl);
91942 + entry = *pte;
91943 + if (!pte_present(entry)) {
91944 + if (!pte_none(entry)) {
91945 + BUG_ON(pte_file(entry));
91946 + free_swap_and_cache(pte_to_swp_entry(entry));
91947 + pte_clear_not_present_full(mm, address, pte, 0);
91948 + }
91949 + } else {
91950 + struct page *page;
91951 +
91952 + flush_cache_page(vma, address, pte_pfn(entry));
91953 + entry = ptep_clear_flush(vma, address, pte);
91954 + BUG_ON(pte_dirty(entry));
91955 + page = vm_normal_page(vma, address, entry);
91956 + if (page) {
91957 + update_hiwater_rss(mm);
91958 + if (PageAnon(page))
91959 + dec_mm_counter_fast(mm, MM_ANONPAGES);
91960 + else
91961 + dec_mm_counter_fast(mm, MM_FILEPAGES);
91962 + page_remove_rmap(page);
91963 + page_cache_release(page);
91964 + }
91965 + }
91966 + pte_unmap_unlock(pte, ptl);
91967 +}
91968 +
91969 +/* PaX: if vma is mirrored, synchronize the mirror's PTE
91970 + *
91971 + * the ptl of the lower mapped page is held on entry and is not released on exit
91972 + * or inside to ensure atomic changes to the PTE states (swapout, mremap, munmap, etc)
91973 + */
91974 +static void pax_mirror_anon_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
91975 +{
91976 + struct mm_struct *mm = vma->vm_mm;
91977 + unsigned long address_m;
91978 + spinlock_t *ptl_m;
91979 + struct vm_area_struct *vma_m;
91980 + pmd_t *pmd_m;
91981 + pte_t *pte_m, entry_m;
91982 +
91983 + BUG_ON(!page_m || !PageAnon(page_m));
91984 +
91985 + vma_m = pax_find_mirror_vma(vma);
91986 + if (!vma_m)
91987 + return;
91988 +
91989 + BUG_ON(!PageLocked(page_m));
91990 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
91991 + address_m = address + SEGMEXEC_TASK_SIZE;
91992 + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
91993 + pte_m = pte_offset_map(pmd_m, address_m);
91994 + ptl_m = pte_lockptr(mm, pmd_m);
91995 + if (ptl != ptl_m) {
91996 + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
91997 + if (!pte_none(*pte_m))
91998 + goto out;
91999 + }
92000 +
92001 + entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
92002 + page_cache_get(page_m);
92003 + page_add_anon_rmap(page_m, vma_m, address_m);
92004 + inc_mm_counter_fast(mm, MM_ANONPAGES);
92005 + set_pte_at(mm, address_m, pte_m, entry_m);
92006 + update_mmu_cache(vma_m, address_m, pte_m);
92007 +out:
92008 + if (ptl != ptl_m)
92009 + spin_unlock(ptl_m);
92010 + pte_unmap(pte_m);
92011 + unlock_page(page_m);
92012 +}
92013 +
92014 +void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
92015 +{
92016 + struct mm_struct *mm = vma->vm_mm;
92017 + unsigned long address_m;
92018 + spinlock_t *ptl_m;
92019 + struct vm_area_struct *vma_m;
92020 + pmd_t *pmd_m;
92021 + pte_t *pte_m, entry_m;
92022 +
92023 + BUG_ON(!page_m || PageAnon(page_m));
92024 +
92025 + vma_m = pax_find_mirror_vma(vma);
92026 + if (!vma_m)
92027 + return;
92028 +
92029 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
92030 + address_m = address + SEGMEXEC_TASK_SIZE;
92031 + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
92032 + pte_m = pte_offset_map(pmd_m, address_m);
92033 + ptl_m = pte_lockptr(mm, pmd_m);
92034 + if (ptl != ptl_m) {
92035 + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
92036 + if (!pte_none(*pte_m))
92037 + goto out;
92038 + }
92039 +
92040 + entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
92041 + page_cache_get(page_m);
92042 + page_add_file_rmap(page_m);
92043 + inc_mm_counter_fast(mm, MM_FILEPAGES);
92044 + set_pte_at(mm, address_m, pte_m, entry_m);
92045 + update_mmu_cache(vma_m, address_m, pte_m);
92046 +out:
92047 + if (ptl != ptl_m)
92048 + spin_unlock(ptl_m);
92049 + pte_unmap(pte_m);
92050 +}
92051 +
92052 +static void pax_mirror_pfn_pte(struct vm_area_struct *vma, unsigned long address, unsigned long pfn_m, spinlock_t *ptl)
92053 +{
92054 + struct mm_struct *mm = vma->vm_mm;
92055 + unsigned long address_m;
92056 + spinlock_t *ptl_m;
92057 + struct vm_area_struct *vma_m;
92058 + pmd_t *pmd_m;
92059 + pte_t *pte_m, entry_m;
92060 +
92061 + vma_m = pax_find_mirror_vma(vma);
92062 + if (!vma_m)
92063 + return;
92064 +
92065 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
92066 + address_m = address + SEGMEXEC_TASK_SIZE;
92067 + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
92068 + pte_m = pte_offset_map(pmd_m, address_m);
92069 + ptl_m = pte_lockptr(mm, pmd_m);
92070 + if (ptl != ptl_m) {
92071 + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
92072 + if (!pte_none(*pte_m))
92073 + goto out;
92074 + }
92075 +
92076 + entry_m = pfn_pte(pfn_m, vma_m->vm_page_prot);
92077 + set_pte_at(mm, address_m, pte_m, entry_m);
92078 +out:
92079 + if (ptl != ptl_m)
92080 + spin_unlock(ptl_m);
92081 + pte_unmap(pte_m);
92082 +}
92083 +
92084 +static void pax_mirror_pte(struct vm_area_struct *vma, unsigned long address, pte_t *pte, pmd_t *pmd, spinlock_t *ptl)
92085 +{
92086 + struct page *page_m;
92087 + pte_t entry;
92088 +
92089 + if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC))
92090 + goto out;
92091 +
92092 + entry = *pte;
92093 + page_m = vm_normal_page(vma, address, entry);
92094 + if (!page_m)
92095 + pax_mirror_pfn_pte(vma, address, pte_pfn(entry), ptl);
92096 + else if (PageAnon(page_m)) {
92097 + if (pax_find_mirror_vma(vma)) {
92098 + pte_unmap_unlock(pte, ptl);
92099 + lock_page(page_m);
92100 + pte = pte_offset_map_lock(vma->vm_mm, pmd, address, &ptl);
92101 + if (pte_same(entry, *pte))
92102 + pax_mirror_anon_pte(vma, address, page_m, ptl);
92103 + else
92104 + unlock_page(page_m);
92105 + }
92106 + } else
92107 + pax_mirror_file_pte(vma, address, page_m, ptl);
92108 +
92109 +out:
92110 + pte_unmap_unlock(pte, ptl);
92111 +}
92112 +#endif
92113 +
92114 /*
92115 * This routine handles present pages, when users try to write
92116 * to a shared page. It is done by copying the page to a new address
92117 @@ -2807,6 +3003,12 @@ gotten:
92118 */
92119 page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
92120 if (likely(pte_same(*page_table, orig_pte))) {
92121 +
92122 +#ifdef CONFIG_PAX_SEGMEXEC
92123 + if (pax_find_mirror_vma(vma))
92124 + BUG_ON(!trylock_page(new_page));
92125 +#endif
92126 +
92127 if (old_page) {
92128 if (!PageAnon(old_page)) {
92129 dec_mm_counter_fast(mm, MM_FILEPAGES);
92130 @@ -2858,6 +3060,10 @@ gotten:
92131 page_remove_rmap(old_page);
92132 }
92133
92134 +#ifdef CONFIG_PAX_SEGMEXEC
92135 + pax_mirror_anon_pte(vma, address, new_page, ptl);
92136 +#endif
92137 +
92138 /* Free the old page.. */
92139 new_page = old_page;
92140 ret |= VM_FAULT_WRITE;
92141 @@ -3135,6 +3341,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
92142 swap_free(entry);
92143 if (vm_swap_full() || (vma->vm_flags & VM_LOCKED) || PageMlocked(page))
92144 try_to_free_swap(page);
92145 +
92146 +#ifdef CONFIG_PAX_SEGMEXEC
92147 + if ((flags & FAULT_FLAG_WRITE) || !pax_find_mirror_vma(vma))
92148 +#endif
92149 +
92150 unlock_page(page);
92151 if (page != swapcache) {
92152 /*
92153 @@ -3158,6 +3369,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
92154
92155 /* No need to invalidate - it was non-present before */
92156 update_mmu_cache(vma, address, page_table);
92157 +
92158 +#ifdef CONFIG_PAX_SEGMEXEC
92159 + pax_mirror_anon_pte(vma, address, page, ptl);
92160 +#endif
92161 +
92162 unlock:
92163 pte_unmap_unlock(page_table, ptl);
92164 out:
92165 @@ -3177,40 +3393,6 @@ out_release:
92166 }
92167
92168 /*
92169 - * This is like a special single-page "expand_{down|up}wards()",
92170 - * except we must first make sure that 'address{-|+}PAGE_SIZE'
92171 - * doesn't hit another vma.
92172 - */
92173 -static inline int check_stack_guard_page(struct vm_area_struct *vma, unsigned long address)
92174 -{
92175 - address &= PAGE_MASK;
92176 - if ((vma->vm_flags & VM_GROWSDOWN) && address == vma->vm_start) {
92177 - struct vm_area_struct *prev = vma->vm_prev;
92178 -
92179 - /*
92180 - * Is there a mapping abutting this one below?
92181 - *
92182 - * That's only ok if it's the same stack mapping
92183 - * that has gotten split..
92184 - */
92185 - if (prev && prev->vm_end == address)
92186 - return prev->vm_flags & VM_GROWSDOWN ? 0 : -ENOMEM;
92187 -
92188 - expand_downwards(vma, address - PAGE_SIZE);
92189 - }
92190 - if ((vma->vm_flags & VM_GROWSUP) && address + PAGE_SIZE == vma->vm_end) {
92191 - struct vm_area_struct *next = vma->vm_next;
92192 -
92193 - /* As VM_GROWSDOWN but s/below/above/ */
92194 - if (next && next->vm_start == address + PAGE_SIZE)
92195 - return next->vm_flags & VM_GROWSUP ? 0 : -ENOMEM;
92196 -
92197 - expand_upwards(vma, address + PAGE_SIZE);
92198 - }
92199 - return 0;
92200 -}
92201 -
92202 -/*
92203 * We enter with non-exclusive mmap_sem (to exclude vma changes,
92204 * but allow concurrent faults), and pte mapped but not yet locked.
92205 * We return with mmap_sem still held, but pte unmapped and unlocked.
92206 @@ -3219,27 +3401,23 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
92207 unsigned long address, pte_t *page_table, pmd_t *pmd,
92208 unsigned int flags)
92209 {
92210 - struct page *page;
92211 + struct page *page = NULL;
92212 spinlock_t *ptl;
92213 pte_t entry;
92214
92215 - pte_unmap(page_table);
92216 -
92217 - /* Check if we need to add a guard page to the stack */
92218 - if (check_stack_guard_page(vma, address) < 0)
92219 - return VM_FAULT_SIGBUS;
92220 -
92221 - /* Use the zero-page for reads */
92222 if (!(flags & FAULT_FLAG_WRITE)) {
92223 entry = pte_mkspecial(pfn_pte(my_zero_pfn(address),
92224 vma->vm_page_prot));
92225 - page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
92226 + ptl = pte_lockptr(mm, pmd);
92227 + spin_lock(ptl);
92228 if (!pte_none(*page_table))
92229 goto unlock;
92230 goto setpte;
92231 }
92232
92233 /* Allocate our own private page. */
92234 + pte_unmap(page_table);
92235 +
92236 if (unlikely(anon_vma_prepare(vma)))
92237 goto oom;
92238 page = alloc_zeroed_user_highpage_movable(vma, address);
92239 @@ -3263,6 +3441,11 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
92240 if (!pte_none(*page_table))
92241 goto release;
92242
92243 +#ifdef CONFIG_PAX_SEGMEXEC
92244 + if (pax_find_mirror_vma(vma))
92245 + BUG_ON(!trylock_page(page));
92246 +#endif
92247 +
92248 inc_mm_counter_fast(mm, MM_ANONPAGES);
92249 page_add_new_anon_rmap(page, vma, address);
92250 setpte:
92251 @@ -3270,6 +3453,12 @@ setpte:
92252
92253 /* No need to invalidate - it was non-present before */
92254 update_mmu_cache(vma, address, page_table);
92255 +
92256 +#ifdef CONFIG_PAX_SEGMEXEC
92257 + if (page)
92258 + pax_mirror_anon_pte(vma, address, page, ptl);
92259 +#endif
92260 +
92261 unlock:
92262 pte_unmap_unlock(page_table, ptl);
92263 return 0;
92264 @@ -3413,6 +3602,12 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
92265 */
92266 /* Only go through if we didn't race with anybody else... */
92267 if (likely(pte_same(*page_table, orig_pte))) {
92268 +
92269 +#ifdef CONFIG_PAX_SEGMEXEC
92270 + if (anon && pax_find_mirror_vma(vma))
92271 + BUG_ON(!trylock_page(page));
92272 +#endif
92273 +
92274 flush_icache_page(vma, page);
92275 entry = mk_pte(page, vma->vm_page_prot);
92276 if (flags & FAULT_FLAG_WRITE)
92277 @@ -3434,6 +3629,14 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
92278
92279 /* no need to invalidate: a not-present page won't be cached */
92280 update_mmu_cache(vma, address, page_table);
92281 +
92282 +#ifdef CONFIG_PAX_SEGMEXEC
92283 + if (anon)
92284 + pax_mirror_anon_pte(vma, address, page, ptl);
92285 + else
92286 + pax_mirror_file_pte(vma, address, page, ptl);
92287 +#endif
92288 +
92289 } else {
92290 if (cow_page)
92291 mem_cgroup_uncharge_page(cow_page);
92292 @@ -3681,6 +3884,12 @@ static int handle_pte_fault(struct mm_struct *mm,
92293 if (flags & FAULT_FLAG_WRITE)
92294 flush_tlb_fix_spurious_fault(vma, address);
92295 }
92296 +
92297 +#ifdef CONFIG_PAX_SEGMEXEC
92298 + pax_mirror_pte(vma, address, pte, pmd, ptl);
92299 + return 0;
92300 +#endif
92301 +
92302 unlock:
92303 pte_unmap_unlock(pte, ptl);
92304 return 0;
92305 @@ -3697,9 +3906,41 @@ static int __handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
92306 pmd_t *pmd;
92307 pte_t *pte;
92308
92309 +#ifdef CONFIG_PAX_SEGMEXEC
92310 + struct vm_area_struct *vma_m;
92311 +#endif
92312 +
92313 if (unlikely(is_vm_hugetlb_page(vma)))
92314 return hugetlb_fault(mm, vma, address, flags);
92315
92316 +#ifdef CONFIG_PAX_SEGMEXEC
92317 + vma_m = pax_find_mirror_vma(vma);
92318 + if (vma_m) {
92319 + unsigned long address_m;
92320 + pgd_t *pgd_m;
92321 + pud_t *pud_m;
92322 + pmd_t *pmd_m;
92323 +
92324 + if (vma->vm_start > vma_m->vm_start) {
92325 + address_m = address;
92326 + address -= SEGMEXEC_TASK_SIZE;
92327 + vma = vma_m;
92328 + } else
92329 + address_m = address + SEGMEXEC_TASK_SIZE;
92330 +
92331 + pgd_m = pgd_offset(mm, address_m);
92332 + pud_m = pud_alloc(mm, pgd_m, address_m);
92333 + if (!pud_m)
92334 + return VM_FAULT_OOM;
92335 + pmd_m = pmd_alloc(mm, pud_m, address_m);
92336 + if (!pmd_m)
92337 + return VM_FAULT_OOM;
92338 + if (!pmd_present(*pmd_m) && __pte_alloc(mm, vma_m, pmd_m, address_m))
92339 + return VM_FAULT_OOM;
92340 + pax_unmap_mirror_pte(vma_m, address_m, pmd_m);
92341 + }
92342 +#endif
92343 +
92344 pgd = pgd_offset(mm, address);
92345 pud = pud_alloc(mm, pgd, address);
92346 if (!pud)
92347 @@ -3830,6 +4071,23 @@ int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
92348 spin_unlock(&mm->page_table_lock);
92349 return 0;
92350 }
92351 +
92352 +int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
92353 +{
92354 + pud_t *new = pud_alloc_one(mm, address);
92355 + if (!new)
92356 + return -ENOMEM;
92357 +
92358 + smp_wmb(); /* See comment in __pte_alloc */
92359 +
92360 + spin_lock(&mm->page_table_lock);
92361 + if (pgd_present(*pgd)) /* Another has populated it */
92362 + pud_free(mm, new);
92363 + else
92364 + pgd_populate_kernel(mm, pgd, new);
92365 + spin_unlock(&mm->page_table_lock);
92366 + return 0;
92367 +}
92368 #endif /* __PAGETABLE_PUD_FOLDED */
92369
92370 #ifndef __PAGETABLE_PMD_FOLDED
92371 @@ -3860,6 +4118,30 @@ int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
92372 spin_unlock(&mm->page_table_lock);
92373 return 0;
92374 }
92375 +
92376 +int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
92377 +{
92378 + pmd_t *new = pmd_alloc_one(mm, address);
92379 + if (!new)
92380 + return -ENOMEM;
92381 +
92382 + smp_wmb(); /* See comment in __pte_alloc */
92383 +
92384 + spin_lock(&mm->page_table_lock);
92385 +#ifndef __ARCH_HAS_4LEVEL_HACK
92386 + if (pud_present(*pud)) /* Another has populated it */
92387 + pmd_free(mm, new);
92388 + else
92389 + pud_populate_kernel(mm, pud, new);
92390 +#else
92391 + if (pgd_present(*pud)) /* Another has populated it */
92392 + pmd_free(mm, new);
92393 + else
92394 + pgd_populate_kernel(mm, pud, new);
92395 +#endif /* __ARCH_HAS_4LEVEL_HACK */
92396 + spin_unlock(&mm->page_table_lock);
92397 + return 0;
92398 +}
92399 #endif /* __PAGETABLE_PMD_FOLDED */
92400
92401 #if !defined(__HAVE_ARCH_GATE_AREA)
92402 @@ -3873,7 +4155,7 @@ static int __init gate_vma_init(void)
92403 gate_vma.vm_start = FIXADDR_USER_START;
92404 gate_vma.vm_end = FIXADDR_USER_END;
92405 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
92406 - gate_vma.vm_page_prot = __P101;
92407 + gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
92408
92409 return 0;
92410 }
92411 @@ -4007,8 +4289,8 @@ out:
92412 return ret;
92413 }
92414
92415 -int generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
92416 - void *buf, int len, int write)
92417 +ssize_t generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
92418 + void *buf, size_t len, int write)
92419 {
92420 resource_size_t phys_addr;
92421 unsigned long prot = 0;
92422 @@ -4034,8 +4316,8 @@ EXPORT_SYMBOL_GPL(generic_access_phys);
92423 * Access another process' address space as given in mm. If non-NULL, use the
92424 * given task for page fault accounting.
92425 */
92426 -static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
92427 - unsigned long addr, void *buf, int len, int write)
92428 +static ssize_t __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
92429 + unsigned long addr, void *buf, size_t len, int write)
92430 {
92431 struct vm_area_struct *vma;
92432 void *old_buf = buf;
92433 @@ -4043,7 +4325,7 @@ static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
92434 down_read(&mm->mmap_sem);
92435 /* ignore errors, just check how much was successfully transferred */
92436 while (len) {
92437 - int bytes, ret, offset;
92438 + ssize_t bytes, ret, offset;
92439 void *maddr;
92440 struct page *page = NULL;
92441
92442 @@ -4102,8 +4384,8 @@ static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
92443 *
92444 * The caller must hold a reference on @mm.
92445 */
92446 -int access_remote_vm(struct mm_struct *mm, unsigned long addr,
92447 - void *buf, int len, int write)
92448 +ssize_t access_remote_vm(struct mm_struct *mm, unsigned long addr,
92449 + void *buf, size_t len, int write)
92450 {
92451 return __access_remote_vm(NULL, mm, addr, buf, len, write);
92452 }
92453 @@ -4113,11 +4395,11 @@ int access_remote_vm(struct mm_struct *mm, unsigned long addr,
92454 * Source/target buffer must be kernel space,
92455 * Do not walk the page table directly, use get_user_pages
92456 */
92457 -int access_process_vm(struct task_struct *tsk, unsigned long addr,
92458 - void *buf, int len, int write)
92459 +ssize_t access_process_vm(struct task_struct *tsk, unsigned long addr,
92460 + void *buf, size_t len, int write)
92461 {
92462 struct mm_struct *mm;
92463 - int ret;
92464 + ssize_t ret;
92465
92466 mm = get_task_mm(tsk);
92467 if (!mm)
92468 diff --git a/mm/mempolicy.c b/mm/mempolicy.c
92469 index cb2f3dd..fb80468 100644
92470 --- a/mm/mempolicy.c
92471 +++ b/mm/mempolicy.c
92472 @@ -747,6 +747,10 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
92473 unsigned long vmstart;
92474 unsigned long vmend;
92475
92476 +#ifdef CONFIG_PAX_SEGMEXEC
92477 + struct vm_area_struct *vma_m;
92478 +#endif
92479 +
92480 vma = find_vma(mm, start);
92481 if (!vma || vma->vm_start > start)
92482 return -EFAULT;
92483 @@ -790,6 +794,16 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
92484 err = vma_replace_policy(vma, new_pol);
92485 if (err)
92486 goto out;
92487 +
92488 +#ifdef CONFIG_PAX_SEGMEXEC
92489 + vma_m = pax_find_mirror_vma(vma);
92490 + if (vma_m) {
92491 + err = vma_replace_policy(vma_m, new_pol);
92492 + if (err)
92493 + goto out;
92494 + }
92495 +#endif
92496 +
92497 }
92498
92499 out:
92500 @@ -1255,6 +1269,17 @@ static long do_mbind(unsigned long start, unsigned long len,
92501
92502 if (end < start)
92503 return -EINVAL;
92504 +
92505 +#ifdef CONFIG_PAX_SEGMEXEC
92506 + if (mm->pax_flags & MF_PAX_SEGMEXEC) {
92507 + if (end > SEGMEXEC_TASK_SIZE)
92508 + return -EINVAL;
92509 + } else
92510 +#endif
92511 +
92512 + if (end > TASK_SIZE)
92513 + return -EINVAL;
92514 +
92515 if (end == start)
92516 return 0;
92517
92518 @@ -1483,8 +1508,7 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
92519 */
92520 tcred = __task_cred(task);
92521 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
92522 - !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
92523 - !capable(CAP_SYS_NICE)) {
92524 + !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
92525 rcu_read_unlock();
92526 err = -EPERM;
92527 goto out_put;
92528 @@ -1515,6 +1539,15 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
92529 goto out;
92530 }
92531
92532 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
92533 + if (mm != current->mm &&
92534 + (mm->pax_flags & MF_PAX_RANDMMAP || mm->pax_flags & MF_PAX_SEGMEXEC)) {
92535 + mmput(mm);
92536 + err = -EPERM;
92537 + goto out;
92538 + }
92539 +#endif
92540 +
92541 err = do_migrate_pages(mm, old, new,
92542 capable(CAP_SYS_NICE) ? MPOL_MF_MOVE_ALL : MPOL_MF_MOVE);
92543
92544 diff --git a/mm/migrate.c b/mm/migrate.c
92545 index 9194375..75c81e2 100644
92546 --- a/mm/migrate.c
92547 +++ b/mm/migrate.c
92548 @@ -1464,8 +1464,7 @@ SYSCALL_DEFINE6(move_pages, pid_t, pid, unsigned long, nr_pages,
92549 */
92550 tcred = __task_cred(task);
92551 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
92552 - !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
92553 - !capable(CAP_SYS_NICE)) {
92554 + !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
92555 rcu_read_unlock();
92556 err = -EPERM;
92557 goto out;
92558 diff --git a/mm/mlock.c b/mm/mlock.c
92559 index 192e6ee..b044449 100644
92560 --- a/mm/mlock.c
92561 +++ b/mm/mlock.c
92562 @@ -14,6 +14,7 @@
92563 #include <linux/pagevec.h>
92564 #include <linux/mempolicy.h>
92565 #include <linux/syscalls.h>
92566 +#include <linux/security.h>
92567 #include <linux/sched.h>
92568 #include <linux/export.h>
92569 #include <linux/rmap.h>
92570 @@ -588,7 +589,7 @@ static int do_mlock(unsigned long start, size_t len, int on)
92571 {
92572 unsigned long nstart, end, tmp;
92573 struct vm_area_struct * vma, * prev;
92574 - int error;
92575 + int error = 0;
92576
92577 VM_BUG_ON(start & ~PAGE_MASK);
92578 VM_BUG_ON(len != PAGE_ALIGN(len));
92579 @@ -597,6 +598,9 @@ static int do_mlock(unsigned long start, size_t len, int on)
92580 return -EINVAL;
92581 if (end == start)
92582 return 0;
92583 + if (end > TASK_SIZE)
92584 + return -EINVAL;
92585 +
92586 vma = find_vma(current->mm, start);
92587 if (!vma || vma->vm_start > start)
92588 return -ENOMEM;
92589 @@ -608,6 +612,11 @@ static int do_mlock(unsigned long start, size_t len, int on)
92590 for (nstart = start ; ; ) {
92591 vm_flags_t newflags;
92592
92593 +#ifdef CONFIG_PAX_SEGMEXEC
92594 + if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
92595 + break;
92596 +#endif
92597 +
92598 /* Here we know that vma->vm_start <= nstart < vma->vm_end. */
92599
92600 newflags = vma->vm_flags & ~VM_LOCKED;
92601 @@ -720,6 +729,7 @@ SYSCALL_DEFINE2(mlock, unsigned long, start, size_t, len)
92602 lock_limit >>= PAGE_SHIFT;
92603
92604 /* check against resource limits */
92605 + gr_learn_resource(current, RLIMIT_MEMLOCK, (current->mm->locked_vm << PAGE_SHIFT) + len, 1);
92606 if ((locked <= lock_limit) || capable(CAP_IPC_LOCK))
92607 error = do_mlock(start, len, 1);
92608 up_write(&current->mm->mmap_sem);
92609 @@ -754,6 +764,11 @@ static int do_mlockall(int flags)
92610 for (vma = current->mm->mmap; vma ; vma = prev->vm_next) {
92611 vm_flags_t newflags;
92612
92613 +#ifdef CONFIG_PAX_SEGMEXEC
92614 + if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
92615 + break;
92616 +#endif
92617 +
92618 newflags = vma->vm_flags & ~VM_LOCKED;
92619 if (flags & MCL_CURRENT)
92620 newflags |= VM_LOCKED;
92621 @@ -787,6 +802,7 @@ SYSCALL_DEFINE1(mlockall, int, flags)
92622 lock_limit >>= PAGE_SHIFT;
92623
92624 ret = -ENOMEM;
92625 + gr_learn_resource(current, RLIMIT_MEMLOCK, current->mm->total_vm << PAGE_SHIFT, 1);
92626 if (!(flags & MCL_CURRENT) || (current->mm->total_vm <= lock_limit) ||
92627 capable(CAP_IPC_LOCK))
92628 ret = do_mlockall(flags);
92629 diff --git a/mm/mmap.c b/mm/mmap.c
92630 index 546db74..650d1b9 100644
92631 --- a/mm/mmap.c
92632 +++ b/mm/mmap.c
92633 @@ -36,6 +36,7 @@
92634 #include <linux/sched/sysctl.h>
92635 #include <linux/notifier.h>
92636 #include <linux/memory.h>
92637 +#include <linux/random.h>
92638
92639 #include <asm/uaccess.h>
92640 #include <asm/cacheflush.h>
92641 @@ -52,6 +53,16 @@
92642 #define arch_rebalance_pgtables(addr, len) (addr)
92643 #endif
92644
92645 +static inline void verify_mm_writelocked(struct mm_struct *mm)
92646 +{
92647 +#if defined(CONFIG_DEBUG_VM) || defined(CONFIG_PAX)
92648 + if (unlikely(down_read_trylock(&mm->mmap_sem))) {
92649 + up_read(&mm->mmap_sem);
92650 + BUG();
92651 + }
92652 +#endif
92653 +}
92654 +
92655 static void unmap_region(struct mm_struct *mm,
92656 struct vm_area_struct *vma, struct vm_area_struct *prev,
92657 unsigned long start, unsigned long end);
92658 @@ -71,16 +82,25 @@ static void unmap_region(struct mm_struct *mm,
92659 * x: (no) no x: (no) yes x: (no) yes x: (yes) yes
92660 *
92661 */
92662 -pgprot_t protection_map[16] = {
92663 +pgprot_t protection_map[16] __read_only = {
92664 __P000, __P001, __P010, __P011, __P100, __P101, __P110, __P111,
92665 __S000, __S001, __S010, __S011, __S100, __S101, __S110, __S111
92666 };
92667
92668 -pgprot_t vm_get_page_prot(unsigned long vm_flags)
92669 +pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
92670 {
92671 - return __pgprot(pgprot_val(protection_map[vm_flags &
92672 + pgprot_t prot = __pgprot(pgprot_val(protection_map[vm_flags &
92673 (VM_READ|VM_WRITE|VM_EXEC|VM_SHARED)]) |
92674 pgprot_val(arch_vm_get_page_prot(vm_flags)));
92675 +
92676 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
92677 + if (!(__supported_pte_mask & _PAGE_NX) &&
92678 + (vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC &&
92679 + (vm_flags & (VM_READ | VM_WRITE)))
92680 + prot = __pgprot(pte_val(pte_exprotect(__pte(pgprot_val(prot)))));
92681 +#endif
92682 +
92683 + return prot;
92684 }
92685 EXPORT_SYMBOL(vm_get_page_prot);
92686
92687 @@ -89,6 +109,7 @@ int sysctl_overcommit_ratio __read_mostly = 50; /* default is 50% */
92688 int sysctl_max_map_count __read_mostly = DEFAULT_MAX_MAP_COUNT;
92689 unsigned long sysctl_user_reserve_kbytes __read_mostly = 1UL << 17; /* 128MB */
92690 unsigned long sysctl_admin_reserve_kbytes __read_mostly = 1UL << 13; /* 8MB */
92691 +unsigned long sysctl_heap_stack_gap __read_mostly = 64*1024;
92692 /*
92693 * Make sure vm_committed_as in one cacheline and not cacheline shared with
92694 * other variables. It can be updated by several CPUs frequently.
92695 @@ -245,6 +266,7 @@ static struct vm_area_struct *remove_vma(struct vm_area_struct *vma)
92696 struct vm_area_struct *next = vma->vm_next;
92697
92698 might_sleep();
92699 + BUG_ON(vma->vm_mirror);
92700 if (vma->vm_ops && vma->vm_ops->close)
92701 vma->vm_ops->close(vma);
92702 if (vma->vm_file)
92703 @@ -289,6 +311,7 @@ SYSCALL_DEFINE1(brk, unsigned long, brk)
92704 * not page aligned -Ram Gupta
92705 */
92706 rlim = rlimit(RLIMIT_DATA);
92707 + gr_learn_resource(current, RLIMIT_DATA, (brk - mm->start_brk) + (mm->end_data - mm->start_data), 1);
92708 if (rlim < RLIM_INFINITY && (brk - mm->start_brk) +
92709 (mm->end_data - mm->start_data) > rlim)
92710 goto out;
92711 @@ -939,6 +962,12 @@ static int
92712 can_vma_merge_before(struct vm_area_struct *vma, unsigned long vm_flags,
92713 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
92714 {
92715 +
92716 +#ifdef CONFIG_PAX_SEGMEXEC
92717 + if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_start == SEGMEXEC_TASK_SIZE)
92718 + return 0;
92719 +#endif
92720 +
92721 if (is_mergeable_vma(vma, file, vm_flags) &&
92722 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
92723 if (vma->vm_pgoff == vm_pgoff)
92724 @@ -958,6 +987,12 @@ static int
92725 can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
92726 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
92727 {
92728 +
92729 +#ifdef CONFIG_PAX_SEGMEXEC
92730 + if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end == SEGMEXEC_TASK_SIZE)
92731 + return 0;
92732 +#endif
92733 +
92734 if (is_mergeable_vma(vma, file, vm_flags) &&
92735 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
92736 pgoff_t vm_pglen;
92737 @@ -1000,13 +1035,20 @@ can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
92738 struct vm_area_struct *vma_merge(struct mm_struct *mm,
92739 struct vm_area_struct *prev, unsigned long addr,
92740 unsigned long end, unsigned long vm_flags,
92741 - struct anon_vma *anon_vma, struct file *file,
92742 + struct anon_vma *anon_vma, struct file *file,
92743 pgoff_t pgoff, struct mempolicy *policy)
92744 {
92745 pgoff_t pglen = (end - addr) >> PAGE_SHIFT;
92746 struct vm_area_struct *area, *next;
92747 int err;
92748
92749 +#ifdef CONFIG_PAX_SEGMEXEC
92750 + unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE, end_m = end + SEGMEXEC_TASK_SIZE;
92751 + struct vm_area_struct *area_m = NULL, *next_m = NULL, *prev_m = NULL;
92752 +
92753 + BUG_ON((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE < end);
92754 +#endif
92755 +
92756 /*
92757 * We later require that vma->vm_flags == vm_flags,
92758 * so this tests vma->vm_flags & VM_SPECIAL, too.
92759 @@ -1022,6 +1064,15 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
92760 if (next && next->vm_end == end) /* cases 6, 7, 8 */
92761 next = next->vm_next;
92762
92763 +#ifdef CONFIG_PAX_SEGMEXEC
92764 + if (prev)
92765 + prev_m = pax_find_mirror_vma(prev);
92766 + if (area)
92767 + area_m = pax_find_mirror_vma(area);
92768 + if (next)
92769 + next_m = pax_find_mirror_vma(next);
92770 +#endif
92771 +
92772 /*
92773 * Can it merge with the predecessor?
92774 */
92775 @@ -1041,9 +1092,24 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
92776 /* cases 1, 6 */
92777 err = vma_adjust(prev, prev->vm_start,
92778 next->vm_end, prev->vm_pgoff, NULL);
92779 - } else /* cases 2, 5, 7 */
92780 +
92781 +#ifdef CONFIG_PAX_SEGMEXEC
92782 + if (!err && prev_m)
92783 + err = vma_adjust(prev_m, prev_m->vm_start,
92784 + next_m->vm_end, prev_m->vm_pgoff, NULL);
92785 +#endif
92786 +
92787 + } else { /* cases 2, 5, 7 */
92788 err = vma_adjust(prev, prev->vm_start,
92789 end, prev->vm_pgoff, NULL);
92790 +
92791 +#ifdef CONFIG_PAX_SEGMEXEC
92792 + if (!err && prev_m)
92793 + err = vma_adjust(prev_m, prev_m->vm_start,
92794 + end_m, prev_m->vm_pgoff, NULL);
92795 +#endif
92796 +
92797 + }
92798 if (err)
92799 return NULL;
92800 khugepaged_enter_vma_merge(prev);
92801 @@ -1057,12 +1123,27 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
92802 mpol_equal(policy, vma_policy(next)) &&
92803 can_vma_merge_before(next, vm_flags,
92804 anon_vma, file, pgoff+pglen)) {
92805 - if (prev && addr < prev->vm_end) /* case 4 */
92806 + if (prev && addr < prev->vm_end) { /* case 4 */
92807 err = vma_adjust(prev, prev->vm_start,
92808 addr, prev->vm_pgoff, NULL);
92809 - else /* cases 3, 8 */
92810 +
92811 +#ifdef CONFIG_PAX_SEGMEXEC
92812 + if (!err && prev_m)
92813 + err = vma_adjust(prev_m, prev_m->vm_start,
92814 + addr_m, prev_m->vm_pgoff, NULL);
92815 +#endif
92816 +
92817 + } else { /* cases 3, 8 */
92818 err = vma_adjust(area, addr, next->vm_end,
92819 next->vm_pgoff - pglen, NULL);
92820 +
92821 +#ifdef CONFIG_PAX_SEGMEXEC
92822 + if (!err && area_m)
92823 + err = vma_adjust(area_m, addr_m, next_m->vm_end,
92824 + next_m->vm_pgoff - pglen, NULL);
92825 +#endif
92826 +
92827 + }
92828 if (err)
92829 return NULL;
92830 khugepaged_enter_vma_merge(area);
92831 @@ -1171,8 +1252,10 @@ none:
92832 void vm_stat_account(struct mm_struct *mm, unsigned long flags,
92833 struct file *file, long pages)
92834 {
92835 - const unsigned long stack_flags
92836 - = VM_STACK_FLAGS & (VM_GROWSUP|VM_GROWSDOWN);
92837 +
92838 +#ifdef CONFIG_PAX_RANDMMAP
92839 + if (!(mm->pax_flags & MF_PAX_RANDMMAP) || (flags & (VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)))
92840 +#endif
92841
92842 mm->total_vm += pages;
92843
92844 @@ -1180,7 +1263,7 @@ void vm_stat_account(struct mm_struct *mm, unsigned long flags,
92845 mm->shared_vm += pages;
92846 if ((flags & (VM_EXEC|VM_WRITE)) == VM_EXEC)
92847 mm->exec_vm += pages;
92848 - } else if (flags & stack_flags)
92849 + } else if (flags & (VM_GROWSUP|VM_GROWSDOWN))
92850 mm->stack_vm += pages;
92851 }
92852 #endif /* CONFIG_PROC_FS */
92853 @@ -1218,7 +1301,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
92854 * (the exception is when the underlying filesystem is noexec
92855 * mounted, in which case we dont add PROT_EXEC.)
92856 */
92857 - if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
92858 + if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
92859 if (!(file && (file->f_path.mnt->mnt_flags & MNT_NOEXEC)))
92860 prot |= PROT_EXEC;
92861
92862 @@ -1244,7 +1327,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
92863 /* Obtain the address to map to. we verify (or select) it and ensure
92864 * that it represents a valid section of the address space.
92865 */
92866 - addr = get_unmapped_area(file, addr, len, pgoff, flags);
92867 + addr = get_unmapped_area(file, addr, len, pgoff, flags | ((prot & PROT_EXEC) ? MAP_EXECUTABLE : 0));
92868 if (addr & ~PAGE_MASK)
92869 return addr;
92870
92871 @@ -1255,6 +1338,43 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
92872 vm_flags = calc_vm_prot_bits(prot) | calc_vm_flag_bits(flags) |
92873 mm->def_flags | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC;
92874
92875 +#ifdef CONFIG_PAX_MPROTECT
92876 + if (mm->pax_flags & MF_PAX_MPROTECT) {
92877 +
92878 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
92879 + if (file && !pgoff && (vm_flags & VM_EXEC) && mm->binfmt &&
92880 + mm->binfmt->handle_mmap)
92881 + mm->binfmt->handle_mmap(file);
92882 +#endif
92883 +
92884 +#ifndef CONFIG_PAX_MPROTECT_COMPAT
92885 + if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC)) {
92886 + gr_log_rwxmmap(file);
92887 +
92888 +#ifdef CONFIG_PAX_EMUPLT
92889 + vm_flags &= ~VM_EXEC;
92890 +#else
92891 + return -EPERM;
92892 +#endif
92893 +
92894 + }
92895 +
92896 + if (!(vm_flags & VM_EXEC))
92897 + vm_flags &= ~VM_MAYEXEC;
92898 +#else
92899 + if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
92900 + vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
92901 +#endif
92902 + else
92903 + vm_flags &= ~VM_MAYWRITE;
92904 + }
92905 +#endif
92906 +
92907 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
92908 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && file)
92909 + vm_flags &= ~VM_PAGEEXEC;
92910 +#endif
92911 +
92912 if (flags & MAP_LOCKED)
92913 if (!can_do_mlock())
92914 return -EPERM;
92915 @@ -1266,6 +1386,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
92916 locked += mm->locked_vm;
92917 lock_limit = rlimit(RLIMIT_MEMLOCK);
92918 lock_limit >>= PAGE_SHIFT;
92919 + gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
92920 if (locked > lock_limit && !capable(CAP_IPC_LOCK))
92921 return -EAGAIN;
92922 }
92923 @@ -1350,6 +1471,9 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
92924 vm_flags |= VM_NORESERVE;
92925 }
92926
92927 + if (!gr_acl_handle_mmap(file, prot))
92928 + return -EACCES;
92929 +
92930 addr = mmap_region(file, addr, len, vm_flags, pgoff);
92931 if (!IS_ERR_VALUE(addr) &&
92932 ((vm_flags & VM_LOCKED) ||
92933 @@ -1443,7 +1567,7 @@ int vma_wants_writenotify(struct vm_area_struct *vma)
92934 vm_flags_t vm_flags = vma->vm_flags;
92935
92936 /* If it was private or non-writable, the write bit is already clear */
92937 - if ((vm_flags & (VM_WRITE|VM_SHARED)) != ((VM_WRITE|VM_SHARED)))
92938 + if ((vm_flags & (VM_WRITE|VM_SHARED)) != (VM_WRITE|VM_SHARED))
92939 return 0;
92940
92941 /* The backer wishes to know when pages are first written to? */
92942 @@ -1489,7 +1613,22 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
92943 struct rb_node **rb_link, *rb_parent;
92944 unsigned long charged = 0;
92945
92946 +#ifdef CONFIG_PAX_SEGMEXEC
92947 + struct vm_area_struct *vma_m = NULL;
92948 +#endif
92949 +
92950 + /*
92951 + * mm->mmap_sem is required to protect against another thread
92952 + * changing the mappings in case we sleep.
92953 + */
92954 + verify_mm_writelocked(mm);
92955 +
92956 /* Check against address space limit. */
92957 +
92958 +#ifdef CONFIG_PAX_RANDMMAP
92959 + if (!(mm->pax_flags & MF_PAX_RANDMMAP) || (vm_flags & (VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)))
92960 +#endif
92961 +
92962 if (!may_expand_vm(mm, len >> PAGE_SHIFT)) {
92963 unsigned long nr_pages;
92964
92965 @@ -1508,11 +1647,10 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
92966
92967 /* Clear old maps */
92968 error = -ENOMEM;
92969 -munmap_back:
92970 if (find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent)) {
92971 if (do_munmap(mm, addr, len))
92972 return -ENOMEM;
92973 - goto munmap_back;
92974 + BUG_ON(find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent));
92975 }
92976
92977 /*
92978 @@ -1543,6 +1681,16 @@ munmap_back:
92979 goto unacct_error;
92980 }
92981
92982 +#ifdef CONFIG_PAX_SEGMEXEC
92983 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vm_flags & VM_EXEC)) {
92984 + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
92985 + if (!vma_m) {
92986 + error = -ENOMEM;
92987 + goto free_vma;
92988 + }
92989 + }
92990 +#endif
92991 +
92992 vma->vm_mm = mm;
92993 vma->vm_start = addr;
92994 vma->vm_end = addr + len;
92995 @@ -1562,6 +1710,13 @@ munmap_back:
92996 if (error)
92997 goto unmap_and_free_vma;
92998
92999 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
93000 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && !(vma->vm_flags & VM_SPECIAL)) {
93001 + vma->vm_flags |= VM_PAGEEXEC;
93002 + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
93003 + }
93004 +#endif
93005 +
93006 /* Can addr have changed??
93007 *
93008 * Answer: Yes, several device drivers can do it in their
93009 @@ -1595,6 +1750,12 @@ munmap_back:
93010 }
93011
93012 vma_link(mm, vma, prev, rb_link, rb_parent);
93013 +
93014 +#ifdef CONFIG_PAX_SEGMEXEC
93015 + if (vma_m)
93016 + BUG_ON(pax_mirror_vma(vma_m, vma));
93017 +#endif
93018 +
93019 /* Once vma denies write, undo our temporary denial count */
93020 if (vm_flags & VM_DENYWRITE)
93021 allow_write_access(file);
93022 @@ -1603,6 +1764,7 @@ out:
93023 perf_event_mmap(vma);
93024
93025 vm_stat_account(mm, vm_flags, file, len >> PAGE_SHIFT);
93026 + track_exec_limit(mm, addr, addr + len, vm_flags);
93027 if (vm_flags & VM_LOCKED) {
93028 if (!((vm_flags & VM_SPECIAL) || is_vm_hugetlb_page(vma) ||
93029 vma == get_gate_vma(current->mm)))
93030 @@ -1635,6 +1797,12 @@ unmap_and_free_vma:
93031 unmap_region(mm, vma, prev, vma->vm_start, vma->vm_end);
93032 charged = 0;
93033 free_vma:
93034 +
93035 +#ifdef CONFIG_PAX_SEGMEXEC
93036 + if (vma_m)
93037 + kmem_cache_free(vm_area_cachep, vma_m);
93038 +#endif
93039 +
93040 kmem_cache_free(vm_area_cachep, vma);
93041 unacct_error:
93042 if (charged)
93043 @@ -1642,7 +1810,63 @@ unacct_error:
93044 return error;
93045 }
93046
93047 -unsigned long unmapped_area(struct vm_unmapped_area_info *info)
93048 +#ifdef CONFIG_GRKERNSEC_RAND_THREADSTACK
93049 +unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags)
93050 +{
93051 + if ((mm->pax_flags & MF_PAX_RANDMMAP) && !filp && (flags & MAP_STACK))
93052 + return ((prandom_u32() & 0xFF) + 1) << PAGE_SHIFT;
93053 +
93054 + return 0;
93055 +}
93056 +#endif
93057 +
93058 +bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len, unsigned long offset)
93059 +{
93060 + if (!vma) {
93061 +#ifdef CONFIG_STACK_GROWSUP
93062 + if (addr > sysctl_heap_stack_gap)
93063 + vma = find_vma(current->mm, addr - sysctl_heap_stack_gap);
93064 + else
93065 + vma = find_vma(current->mm, 0);
93066 + if (vma && (vma->vm_flags & VM_GROWSUP))
93067 + return false;
93068 +#endif
93069 + return true;
93070 + }
93071 +
93072 + if (addr + len > vma->vm_start)
93073 + return false;
93074 +
93075 + if (vma->vm_flags & VM_GROWSDOWN)
93076 + return sysctl_heap_stack_gap <= vma->vm_start - addr - len;
93077 +#ifdef CONFIG_STACK_GROWSUP
93078 + else if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP))
93079 + return addr - vma->vm_prev->vm_end >= sysctl_heap_stack_gap;
93080 +#endif
93081 + else if (offset)
93082 + return offset <= vma->vm_start - addr - len;
93083 +
93084 + return true;
93085 +}
93086 +
93087 +unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len, unsigned long offset)
93088 +{
93089 + if (vma->vm_start < len)
93090 + return -ENOMEM;
93091 +
93092 + if (!(vma->vm_flags & VM_GROWSDOWN)) {
93093 + if (offset <= vma->vm_start - len)
93094 + return vma->vm_start - len - offset;
93095 + else
93096 + return -ENOMEM;
93097 + }
93098 +
93099 + if (sysctl_heap_stack_gap <= vma->vm_start - len)
93100 + return vma->vm_start - len - sysctl_heap_stack_gap;
93101 + return -ENOMEM;
93102 +}
93103 +
93104 +unsigned long unmapped_area(const struct vm_unmapped_area_info *info)
93105 {
93106 /*
93107 * We implement the search by looking for an rbtree node that
93108 @@ -1690,11 +1914,29 @@ unsigned long unmapped_area(struct vm_unmapped_area_info *info)
93109 }
93110 }
93111
93112 - gap_start = vma->vm_prev ? vma->vm_prev->vm_end : 0;
93113 + gap_start = vma->vm_prev ? vma->vm_prev->vm_end: 0;
93114 check_current:
93115 /* Check if current node has a suitable gap */
93116 if (gap_start > high_limit)
93117 return -ENOMEM;
93118 +
93119 + if (gap_end - gap_start > info->threadstack_offset)
93120 + gap_start += info->threadstack_offset;
93121 + else
93122 + gap_start = gap_end;
93123 +
93124 + if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP)) {
93125 + if (gap_end - gap_start > sysctl_heap_stack_gap)
93126 + gap_start += sysctl_heap_stack_gap;
93127 + else
93128 + gap_start = gap_end;
93129 + }
93130 + if (vma->vm_flags & VM_GROWSDOWN) {
93131 + if (gap_end - gap_start > sysctl_heap_stack_gap)
93132 + gap_end -= sysctl_heap_stack_gap;
93133 + else
93134 + gap_end = gap_start;
93135 + }
93136 if (gap_end >= low_limit && gap_end - gap_start >= length)
93137 goto found;
93138
93139 @@ -1744,7 +1986,7 @@ found:
93140 return gap_start;
93141 }
93142
93143 -unsigned long unmapped_area_topdown(struct vm_unmapped_area_info *info)
93144 +unsigned long unmapped_area_topdown(const struct vm_unmapped_area_info *info)
93145 {
93146 struct mm_struct *mm = current->mm;
93147 struct vm_area_struct *vma;
93148 @@ -1798,6 +2040,24 @@ check_current:
93149 gap_end = vma->vm_start;
93150 if (gap_end < low_limit)
93151 return -ENOMEM;
93152 +
93153 + if (gap_end - gap_start > info->threadstack_offset)
93154 + gap_end -= info->threadstack_offset;
93155 + else
93156 + gap_end = gap_start;
93157 +
93158 + if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP)) {
93159 + if (gap_end - gap_start > sysctl_heap_stack_gap)
93160 + gap_start += sysctl_heap_stack_gap;
93161 + else
93162 + gap_start = gap_end;
93163 + }
93164 + if (vma->vm_flags & VM_GROWSDOWN) {
93165 + if (gap_end - gap_start > sysctl_heap_stack_gap)
93166 + gap_end -= sysctl_heap_stack_gap;
93167 + else
93168 + gap_end = gap_start;
93169 + }
93170 if (gap_start <= high_limit && gap_end - gap_start >= length)
93171 goto found;
93172
93173 @@ -1861,6 +2121,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
93174 struct mm_struct *mm = current->mm;
93175 struct vm_area_struct *vma;
93176 struct vm_unmapped_area_info info;
93177 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
93178
93179 if (len > TASK_SIZE - mmap_min_addr)
93180 return -ENOMEM;
93181 @@ -1868,11 +2129,15 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
93182 if (flags & MAP_FIXED)
93183 return addr;
93184
93185 +#ifdef CONFIG_PAX_RANDMMAP
93186 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
93187 +#endif
93188 +
93189 if (addr) {
93190 addr = PAGE_ALIGN(addr);
93191 vma = find_vma(mm, addr);
93192 if (TASK_SIZE - len >= addr && addr >= mmap_min_addr &&
93193 - (!vma || addr + len <= vma->vm_start))
93194 + check_heap_stack_gap(vma, addr, len, offset))
93195 return addr;
93196 }
93197
93198 @@ -1881,6 +2146,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
93199 info.low_limit = mm->mmap_base;
93200 info.high_limit = TASK_SIZE;
93201 info.align_mask = 0;
93202 + info.threadstack_offset = offset;
93203 return vm_unmapped_area(&info);
93204 }
93205 #endif
93206 @@ -1899,6 +2165,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
93207 struct mm_struct *mm = current->mm;
93208 unsigned long addr = addr0;
93209 struct vm_unmapped_area_info info;
93210 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
93211
93212 /* requested length too big for entire address space */
93213 if (len > TASK_SIZE - mmap_min_addr)
93214 @@ -1907,12 +2174,16 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
93215 if (flags & MAP_FIXED)
93216 return addr;
93217
93218 +#ifdef CONFIG_PAX_RANDMMAP
93219 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
93220 +#endif
93221 +
93222 /* requesting a specific address */
93223 if (addr) {
93224 addr = PAGE_ALIGN(addr);
93225 vma = find_vma(mm, addr);
93226 if (TASK_SIZE - len >= addr && addr >= mmap_min_addr &&
93227 - (!vma || addr + len <= vma->vm_start))
93228 + check_heap_stack_gap(vma, addr, len, offset))
93229 return addr;
93230 }
93231
93232 @@ -1921,6 +2192,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
93233 info.low_limit = max(PAGE_SIZE, mmap_min_addr);
93234 info.high_limit = mm->mmap_base;
93235 info.align_mask = 0;
93236 + info.threadstack_offset = offset;
93237 addr = vm_unmapped_area(&info);
93238
93239 /*
93240 @@ -1933,6 +2205,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
93241 VM_BUG_ON(addr != -ENOMEM);
93242 info.flags = 0;
93243 info.low_limit = TASK_UNMAPPED_BASE;
93244 +
93245 +#ifdef CONFIG_PAX_RANDMMAP
93246 + if (mm->pax_flags & MF_PAX_RANDMMAP)
93247 + info.low_limit += mm->delta_mmap;
93248 +#endif
93249 +
93250 info.high_limit = TASK_SIZE;
93251 addr = vm_unmapped_area(&info);
93252 }
93253 @@ -2034,6 +2312,28 @@ find_vma_prev(struct mm_struct *mm, unsigned long addr,
93254 return vma;
93255 }
93256
93257 +#ifdef CONFIG_PAX_SEGMEXEC
93258 +struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma)
93259 +{
93260 + struct vm_area_struct *vma_m;
93261 +
93262 + BUG_ON(!vma || vma->vm_start >= vma->vm_end);
93263 + if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC)) {
93264 + BUG_ON(vma->vm_mirror);
93265 + return NULL;
93266 + }
93267 + BUG_ON(vma->vm_start < SEGMEXEC_TASK_SIZE && SEGMEXEC_TASK_SIZE < vma->vm_end);
93268 + vma_m = vma->vm_mirror;
93269 + BUG_ON(!vma_m || vma_m->vm_mirror != vma);
93270 + BUG_ON(vma->vm_file != vma_m->vm_file);
93271 + BUG_ON(vma->vm_end - vma->vm_start != vma_m->vm_end - vma_m->vm_start);
93272 + BUG_ON(vma->vm_pgoff != vma_m->vm_pgoff);
93273 + BUG_ON(vma->anon_vma != vma_m->anon_vma && vma->anon_vma->root != vma_m->anon_vma->root);
93274 + BUG_ON((vma->vm_flags ^ vma_m->vm_flags) & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED));
93275 + return vma_m;
93276 +}
93277 +#endif
93278 +
93279 /*
93280 * Verify that the stack growth is acceptable and
93281 * update accounting. This is shared with both the
93282 @@ -2050,6 +2350,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
93283 return -ENOMEM;
93284
93285 /* Stack limit test */
93286 + gr_learn_resource(current, RLIMIT_STACK, size, 1);
93287 if (size > ACCESS_ONCE(rlim[RLIMIT_STACK].rlim_cur))
93288 return -ENOMEM;
93289
93290 @@ -2060,6 +2361,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
93291 locked = mm->locked_vm + grow;
93292 limit = ACCESS_ONCE(rlim[RLIMIT_MEMLOCK].rlim_cur);
93293 limit >>= PAGE_SHIFT;
93294 + gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
93295 if (locked > limit && !capable(CAP_IPC_LOCK))
93296 return -ENOMEM;
93297 }
93298 @@ -2089,37 +2391,48 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
93299 * PA-RISC uses this for its stack; IA64 for its Register Backing Store.
93300 * vma is the last one with address > vma->vm_end. Have to extend vma.
93301 */
93302 +#ifndef CONFIG_IA64
93303 +static
93304 +#endif
93305 int expand_upwards(struct vm_area_struct *vma, unsigned long address)
93306 {
93307 int error;
93308 + bool locknext;
93309
93310 if (!(vma->vm_flags & VM_GROWSUP))
93311 return -EFAULT;
93312
93313 + /* Also guard against wrapping around to address 0. */
93314 + if (address < PAGE_ALIGN(address+1))
93315 + address = PAGE_ALIGN(address+1);
93316 + else
93317 + return -ENOMEM;
93318 +
93319 /*
93320 * We must make sure the anon_vma is allocated
93321 * so that the anon_vma locking is not a noop.
93322 */
93323 if (unlikely(anon_vma_prepare(vma)))
93324 return -ENOMEM;
93325 + locknext = vma->vm_next && (vma->vm_next->vm_flags & VM_GROWSDOWN);
93326 + if (locknext && anon_vma_prepare(vma->vm_next))
93327 + return -ENOMEM;
93328 vma_lock_anon_vma(vma);
93329 + if (locknext)
93330 + vma_lock_anon_vma(vma->vm_next);
93331
93332 /*
93333 * vma->vm_start/vm_end cannot change under us because the caller
93334 * is required to hold the mmap_sem in read mode. We need the
93335 - * anon_vma lock to serialize against concurrent expand_stacks.
93336 - * Also guard against wrapping around to address 0.
93337 + * anon_vma locks to serialize against concurrent expand_stacks
93338 + * and expand_upwards.
93339 */
93340 - if (address < PAGE_ALIGN(address+4))
93341 - address = PAGE_ALIGN(address+4);
93342 - else {
93343 - vma_unlock_anon_vma(vma);
93344 - return -ENOMEM;
93345 - }
93346 error = 0;
93347
93348 /* Somebody else might have raced and expanded it already */
93349 - if (address > vma->vm_end) {
93350 + 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)
93351 + error = -ENOMEM;
93352 + else if (address > vma->vm_end && (!locknext || vma->vm_next->vm_start >= address)) {
93353 unsigned long size, grow;
93354
93355 size = address - vma->vm_start;
93356 @@ -2154,6 +2467,8 @@ int expand_upwards(struct vm_area_struct *vma, unsigned long address)
93357 }
93358 }
93359 }
93360 + if (locknext)
93361 + vma_unlock_anon_vma(vma->vm_next);
93362 vma_unlock_anon_vma(vma);
93363 khugepaged_enter_vma_merge(vma);
93364 validate_mm(vma->vm_mm);
93365 @@ -2168,6 +2483,8 @@ int expand_downwards(struct vm_area_struct *vma,
93366 unsigned long address)
93367 {
93368 int error;
93369 + bool lockprev = false;
93370 + struct vm_area_struct *prev;
93371
93372 /*
93373 * We must make sure the anon_vma is allocated
93374 @@ -2181,6 +2498,15 @@ int expand_downwards(struct vm_area_struct *vma,
93375 if (error)
93376 return error;
93377
93378 + prev = vma->vm_prev;
93379 +#if defined(CONFIG_STACK_GROWSUP) || defined(CONFIG_IA64)
93380 + lockprev = prev && (prev->vm_flags & VM_GROWSUP);
93381 +#endif
93382 + if (lockprev && anon_vma_prepare(prev))
93383 + return -ENOMEM;
93384 + if (lockprev)
93385 + vma_lock_anon_vma(prev);
93386 +
93387 vma_lock_anon_vma(vma);
93388
93389 /*
93390 @@ -2190,9 +2516,17 @@ int expand_downwards(struct vm_area_struct *vma,
93391 */
93392
93393 /* Somebody else might have raced and expanded it already */
93394 - if (address < vma->vm_start) {
93395 + if (prev && (prev->vm_flags & (VM_READ | VM_WRITE | VM_EXEC)) && address - prev->vm_end < sysctl_heap_stack_gap)
93396 + error = -ENOMEM;
93397 + else if (address < vma->vm_start && (!lockprev || prev->vm_end <= address)) {
93398 unsigned long size, grow;
93399
93400 +#ifdef CONFIG_PAX_SEGMEXEC
93401 + struct vm_area_struct *vma_m;
93402 +
93403 + vma_m = pax_find_mirror_vma(vma);
93404 +#endif
93405 +
93406 size = vma->vm_end - address;
93407 grow = (vma->vm_start - address) >> PAGE_SHIFT;
93408
93409 @@ -2217,13 +2551,27 @@ int expand_downwards(struct vm_area_struct *vma,
93410 vma->vm_pgoff -= grow;
93411 anon_vma_interval_tree_post_update_vma(vma);
93412 vma_gap_update(vma);
93413 +
93414 +#ifdef CONFIG_PAX_SEGMEXEC
93415 + if (vma_m) {
93416 + anon_vma_interval_tree_pre_update_vma(vma_m);
93417 + vma_m->vm_start -= grow << PAGE_SHIFT;
93418 + vma_m->vm_pgoff -= grow;
93419 + anon_vma_interval_tree_post_update_vma(vma_m);
93420 + vma_gap_update(vma_m);
93421 + }
93422 +#endif
93423 +
93424 spin_unlock(&vma->vm_mm->page_table_lock);
93425
93426 + track_exec_limit(vma->vm_mm, vma->vm_start, vma->vm_end, vma->vm_flags);
93427 perf_event_mmap(vma);
93428 }
93429 }
93430 }
93431 vma_unlock_anon_vma(vma);
93432 + if (lockprev)
93433 + vma_unlock_anon_vma(prev);
93434 khugepaged_enter_vma_merge(vma);
93435 validate_mm(vma->vm_mm);
93436 return error;
93437 @@ -2321,6 +2669,13 @@ static void remove_vma_list(struct mm_struct *mm, struct vm_area_struct *vma)
93438 do {
93439 long nrpages = vma_pages(vma);
93440
93441 +#ifdef CONFIG_PAX_SEGMEXEC
93442 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE)) {
93443 + vma = remove_vma(vma);
93444 + continue;
93445 + }
93446 +#endif
93447 +
93448 if (vma->vm_flags & VM_ACCOUNT)
93449 nr_accounted += nrpages;
93450 vm_stat_account(mm, vma->vm_flags, vma->vm_file, -nrpages);
93451 @@ -2365,6 +2720,16 @@ detach_vmas_to_be_unmapped(struct mm_struct *mm, struct vm_area_struct *vma,
93452 insertion_point = (prev ? &prev->vm_next : &mm->mmap);
93453 vma->vm_prev = NULL;
93454 do {
93455 +
93456 +#ifdef CONFIG_PAX_SEGMEXEC
93457 + if (vma->vm_mirror) {
93458 + BUG_ON(!vma->vm_mirror->vm_mirror || vma->vm_mirror->vm_mirror != vma);
93459 + vma->vm_mirror->vm_mirror = NULL;
93460 + vma->vm_mirror->vm_flags &= ~VM_EXEC;
93461 + vma->vm_mirror = NULL;
93462 + }
93463 +#endif
93464 +
93465 vma_rb_erase(vma, &mm->mm_rb);
93466 mm->map_count--;
93467 tail_vma = vma;
93468 @@ -2390,14 +2755,33 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
93469 struct vm_area_struct *new;
93470 int err = -ENOMEM;
93471
93472 +#ifdef CONFIG_PAX_SEGMEXEC
93473 + struct vm_area_struct *vma_m, *new_m = NULL;
93474 + unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE;
93475 +#endif
93476 +
93477 if (is_vm_hugetlb_page(vma) && (addr &
93478 ~(huge_page_mask(hstate_vma(vma)))))
93479 return -EINVAL;
93480
93481 +#ifdef CONFIG_PAX_SEGMEXEC
93482 + vma_m = pax_find_mirror_vma(vma);
93483 +#endif
93484 +
93485 new = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
93486 if (!new)
93487 goto out_err;
93488
93489 +#ifdef CONFIG_PAX_SEGMEXEC
93490 + if (vma_m) {
93491 + new_m = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
93492 + if (!new_m) {
93493 + kmem_cache_free(vm_area_cachep, new);
93494 + goto out_err;
93495 + }
93496 + }
93497 +#endif
93498 +
93499 /* most fields are the same, copy all, and then fixup */
93500 *new = *vma;
93501
93502 @@ -2410,6 +2794,22 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
93503 new->vm_pgoff += ((addr - vma->vm_start) >> PAGE_SHIFT);
93504 }
93505
93506 +#ifdef CONFIG_PAX_SEGMEXEC
93507 + if (vma_m) {
93508 + *new_m = *vma_m;
93509 + INIT_LIST_HEAD(&new_m->anon_vma_chain);
93510 + new_m->vm_mirror = new;
93511 + new->vm_mirror = new_m;
93512 +
93513 + if (new_below)
93514 + new_m->vm_end = addr_m;
93515 + else {
93516 + new_m->vm_start = addr_m;
93517 + new_m->vm_pgoff += ((addr_m - vma_m->vm_start) >> PAGE_SHIFT);
93518 + }
93519 + }
93520 +#endif
93521 +
93522 err = vma_dup_policy(vma, new);
93523 if (err)
93524 goto out_free_vma;
93525 @@ -2429,6 +2829,38 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
93526 else
93527 err = vma_adjust(vma, vma->vm_start, addr, vma->vm_pgoff, new);
93528
93529 +#ifdef CONFIG_PAX_SEGMEXEC
93530 + if (!err && vma_m) {
93531 + struct mempolicy *pol = vma_policy(new);
93532 +
93533 + if (anon_vma_clone(new_m, vma_m))
93534 + goto out_free_mpol;
93535 +
93536 + mpol_get(pol);
93537 + set_vma_policy(new_m, pol);
93538 +
93539 + if (new_m->vm_file)
93540 + get_file(new_m->vm_file);
93541 +
93542 + if (new_m->vm_ops && new_m->vm_ops->open)
93543 + new_m->vm_ops->open(new_m);
93544 +
93545 + if (new_below)
93546 + err = vma_adjust(vma_m, addr_m, vma_m->vm_end, vma_m->vm_pgoff +
93547 + ((addr_m - new_m->vm_start) >> PAGE_SHIFT), new_m);
93548 + else
93549 + err = vma_adjust(vma_m, vma_m->vm_start, addr_m, vma_m->vm_pgoff, new_m);
93550 +
93551 + if (err) {
93552 + if (new_m->vm_ops && new_m->vm_ops->close)
93553 + new_m->vm_ops->close(new_m);
93554 + if (new_m->vm_file)
93555 + fput(new_m->vm_file);
93556 + mpol_put(pol);
93557 + }
93558 + }
93559 +#endif
93560 +
93561 /* Success. */
93562 if (!err)
93563 return 0;
93564 @@ -2438,10 +2870,18 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
93565 new->vm_ops->close(new);
93566 if (new->vm_file)
93567 fput(new->vm_file);
93568 - unlink_anon_vmas(new);
93569 out_free_mpol:
93570 mpol_put(vma_policy(new));
93571 out_free_vma:
93572 +
93573 +#ifdef CONFIG_PAX_SEGMEXEC
93574 + if (new_m) {
93575 + unlink_anon_vmas(new_m);
93576 + kmem_cache_free(vm_area_cachep, new_m);
93577 + }
93578 +#endif
93579 +
93580 + unlink_anon_vmas(new);
93581 kmem_cache_free(vm_area_cachep, new);
93582 out_err:
93583 return err;
93584 @@ -2454,6 +2894,15 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
93585 int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
93586 unsigned long addr, int new_below)
93587 {
93588 +
93589 +#ifdef CONFIG_PAX_SEGMEXEC
93590 + if (mm->pax_flags & MF_PAX_SEGMEXEC) {
93591 + BUG_ON(vma->vm_end > SEGMEXEC_TASK_SIZE);
93592 + if (mm->map_count >= sysctl_max_map_count-1)
93593 + return -ENOMEM;
93594 + } else
93595 +#endif
93596 +
93597 if (mm->map_count >= sysctl_max_map_count)
93598 return -ENOMEM;
93599
93600 @@ -2465,11 +2914,30 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
93601 * work. This now handles partial unmappings.
93602 * Jeremy Fitzhardinge <jeremy@goop.org>
93603 */
93604 +#ifdef CONFIG_PAX_SEGMEXEC
93605 int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
93606 {
93607 + int ret = __do_munmap(mm, start, len);
93608 + if (ret || !(mm->pax_flags & MF_PAX_SEGMEXEC))
93609 + return ret;
93610 +
93611 + return __do_munmap(mm, start + SEGMEXEC_TASK_SIZE, len);
93612 +}
93613 +
93614 +int __do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
93615 +#else
93616 +int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
93617 +#endif
93618 +{
93619 unsigned long end;
93620 struct vm_area_struct *vma, *prev, *last;
93621
93622 + /*
93623 + * mm->mmap_sem is required to protect against another thread
93624 + * changing the mappings in case we sleep.
93625 + */
93626 + verify_mm_writelocked(mm);
93627 +
93628 if ((start & ~PAGE_MASK) || start > TASK_SIZE || len > TASK_SIZE-start)
93629 return -EINVAL;
93630
93631 @@ -2544,6 +3012,8 @@ int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
93632 /* Fix up all other VM information */
93633 remove_vma_list(mm, vma);
93634
93635 + track_exec_limit(mm, start, end, 0UL);
93636 +
93637 return 0;
93638 }
93639
93640 @@ -2552,6 +3022,13 @@ int vm_munmap(unsigned long start, size_t len)
93641 int ret;
93642 struct mm_struct *mm = current->mm;
93643
93644 +
93645 +#ifdef CONFIG_PAX_SEGMEXEC
93646 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) &&
93647 + (len > SEGMEXEC_TASK_SIZE || start > SEGMEXEC_TASK_SIZE-len))
93648 + return -EINVAL;
93649 +#endif
93650 +
93651 down_write(&mm->mmap_sem);
93652 ret = do_munmap(mm, start, len);
93653 up_write(&mm->mmap_sem);
93654 @@ -2565,16 +3042,6 @@ SYSCALL_DEFINE2(munmap, unsigned long, addr, size_t, len)
93655 return vm_munmap(addr, len);
93656 }
93657
93658 -static inline void verify_mm_writelocked(struct mm_struct *mm)
93659 -{
93660 -#ifdef CONFIG_DEBUG_VM
93661 - if (unlikely(down_read_trylock(&mm->mmap_sem))) {
93662 - WARN_ON(1);
93663 - up_read(&mm->mmap_sem);
93664 - }
93665 -#endif
93666 -}
93667 -
93668 /*
93669 * this is really a simplified "do_mmap". it only handles
93670 * anonymous maps. eventually we may be able to do some
93671 @@ -2588,6 +3055,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
93672 struct rb_node ** rb_link, * rb_parent;
93673 pgoff_t pgoff = addr >> PAGE_SHIFT;
93674 int error;
93675 + unsigned long charged;
93676
93677 len = PAGE_ALIGN(len);
93678 if (!len)
93679 @@ -2595,16 +3063,30 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
93680
93681 flags = VM_DATA_DEFAULT_FLAGS | VM_ACCOUNT | mm->def_flags;
93682
93683 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
93684 + if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
93685 + flags &= ~VM_EXEC;
93686 +
93687 +#ifdef CONFIG_PAX_MPROTECT
93688 + if (mm->pax_flags & MF_PAX_MPROTECT)
93689 + flags &= ~VM_MAYEXEC;
93690 +#endif
93691 +
93692 + }
93693 +#endif
93694 +
93695 error = get_unmapped_area(NULL, addr, len, 0, MAP_FIXED);
93696 if (error & ~PAGE_MASK)
93697 return error;
93698
93699 + charged = len >> PAGE_SHIFT;
93700 +
93701 /*
93702 * mlock MCL_FUTURE?
93703 */
93704 if (mm->def_flags & VM_LOCKED) {
93705 unsigned long locked, lock_limit;
93706 - locked = len >> PAGE_SHIFT;
93707 + locked = charged;
93708 locked += mm->locked_vm;
93709 lock_limit = rlimit(RLIMIT_MEMLOCK);
93710 lock_limit >>= PAGE_SHIFT;
93711 @@ -2621,21 +3103,20 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
93712 /*
93713 * Clear old maps. this also does some error checking for us
93714 */
93715 - munmap_back:
93716 if (find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent)) {
93717 if (do_munmap(mm, addr, len))
93718 return -ENOMEM;
93719 - goto munmap_back;
93720 + BUG_ON(find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent));
93721 }
93722
93723 /* Check against address space limits *after* clearing old maps... */
93724 - if (!may_expand_vm(mm, len >> PAGE_SHIFT))
93725 + if (!may_expand_vm(mm, charged))
93726 return -ENOMEM;
93727
93728 if (mm->map_count > sysctl_max_map_count)
93729 return -ENOMEM;
93730
93731 - if (security_vm_enough_memory_mm(mm, len >> PAGE_SHIFT))
93732 + if (security_vm_enough_memory_mm(mm, charged))
93733 return -ENOMEM;
93734
93735 /* Can we just expand an old private anonymous mapping? */
93736 @@ -2649,7 +3130,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
93737 */
93738 vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
93739 if (!vma) {
93740 - vm_unacct_memory(len >> PAGE_SHIFT);
93741 + vm_unacct_memory(charged);
93742 return -ENOMEM;
93743 }
93744
93745 @@ -2663,10 +3144,11 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
93746 vma_link(mm, vma, prev, rb_link, rb_parent);
93747 out:
93748 perf_event_mmap(vma);
93749 - mm->total_vm += len >> PAGE_SHIFT;
93750 + mm->total_vm += charged;
93751 if (flags & VM_LOCKED)
93752 - mm->locked_vm += (len >> PAGE_SHIFT);
93753 + mm->locked_vm += charged;
93754 vma->vm_flags |= VM_SOFTDIRTY;
93755 + track_exec_limit(mm, addr, addr + len, flags);
93756 return addr;
93757 }
93758
93759 @@ -2728,6 +3210,7 @@ void exit_mmap(struct mm_struct *mm)
93760 while (vma) {
93761 if (vma->vm_flags & VM_ACCOUNT)
93762 nr_accounted += vma_pages(vma);
93763 + vma->vm_mirror = NULL;
93764 vma = remove_vma(vma);
93765 }
93766 vm_unacct_memory(nr_accounted);
93767 @@ -2745,6 +3228,13 @@ int insert_vm_struct(struct mm_struct *mm, struct vm_area_struct *vma)
93768 struct vm_area_struct *prev;
93769 struct rb_node **rb_link, *rb_parent;
93770
93771 +#ifdef CONFIG_PAX_SEGMEXEC
93772 + struct vm_area_struct *vma_m = NULL;
93773 +#endif
93774 +
93775 + if (security_mmap_addr(vma->vm_start))
93776 + return -EPERM;
93777 +
93778 /*
93779 * The vm_pgoff of a purely anonymous vma should be irrelevant
93780 * until its first write fault, when page's anon_vma and index
93781 @@ -2768,7 +3258,21 @@ int insert_vm_struct(struct mm_struct *mm, struct vm_area_struct *vma)
93782 security_vm_enough_memory_mm(mm, vma_pages(vma)))
93783 return -ENOMEM;
93784
93785 +#ifdef CONFIG_PAX_SEGMEXEC
93786 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_EXEC)) {
93787 + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
93788 + if (!vma_m)
93789 + return -ENOMEM;
93790 + }
93791 +#endif
93792 +
93793 vma_link(mm, vma, prev, rb_link, rb_parent);
93794 +
93795 +#ifdef CONFIG_PAX_SEGMEXEC
93796 + if (vma_m)
93797 + BUG_ON(pax_mirror_vma(vma_m, vma));
93798 +#endif
93799 +
93800 return 0;
93801 }
93802
93803 @@ -2787,6 +3291,8 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
93804 struct rb_node **rb_link, *rb_parent;
93805 bool faulted_in_anon_vma = true;
93806
93807 + BUG_ON(vma->vm_mirror);
93808 +
93809 /*
93810 * If anonymous vma has not yet been faulted, update new pgoff
93811 * to match new location, to increase its chance of merging.
93812 @@ -2851,6 +3357,39 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
93813 return NULL;
93814 }
93815
93816 +#ifdef CONFIG_PAX_SEGMEXEC
93817 +long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma)
93818 +{
93819 + struct vm_area_struct *prev_m;
93820 + struct rb_node **rb_link_m, *rb_parent_m;
93821 + struct mempolicy *pol_m;
93822 +
93823 + BUG_ON(!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC));
93824 + BUG_ON(vma->vm_mirror || vma_m->vm_mirror);
93825 + BUG_ON(!mpol_equal(vma_policy(vma), vma_policy(vma_m)));
93826 + *vma_m = *vma;
93827 + INIT_LIST_HEAD(&vma_m->anon_vma_chain);
93828 + if (anon_vma_clone(vma_m, vma))
93829 + return -ENOMEM;
93830 + pol_m = vma_policy(vma_m);
93831 + mpol_get(pol_m);
93832 + set_vma_policy(vma_m, pol_m);
93833 + vma_m->vm_start += SEGMEXEC_TASK_SIZE;
93834 + vma_m->vm_end += SEGMEXEC_TASK_SIZE;
93835 + vma_m->vm_flags &= ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED);
93836 + vma_m->vm_page_prot = vm_get_page_prot(vma_m->vm_flags);
93837 + if (vma_m->vm_file)
93838 + get_file(vma_m->vm_file);
93839 + if (vma_m->vm_ops && vma_m->vm_ops->open)
93840 + vma_m->vm_ops->open(vma_m);
93841 + BUG_ON(find_vma_links(vma->vm_mm, vma_m->vm_start, vma_m->vm_end, &prev_m, &rb_link_m, &rb_parent_m));
93842 + vma_link(vma->vm_mm, vma_m, prev_m, rb_link_m, rb_parent_m);
93843 + vma_m->vm_mirror = vma;
93844 + vma->vm_mirror = vma_m;
93845 + return 0;
93846 +}
93847 +#endif
93848 +
93849 /*
93850 * Return true if the calling process may expand its vm space by the passed
93851 * number of pages
93852 @@ -2862,6 +3401,7 @@ int may_expand_vm(struct mm_struct *mm, unsigned long npages)
93853
93854 lim = rlimit(RLIMIT_AS) >> PAGE_SHIFT;
93855
93856 + gr_learn_resource(current, RLIMIT_AS, (cur + npages) << PAGE_SHIFT, 1);
93857 if (cur + npages > lim)
93858 return 0;
93859 return 1;
93860 @@ -2932,6 +3472,22 @@ int install_special_mapping(struct mm_struct *mm,
93861 vma->vm_start = addr;
93862 vma->vm_end = addr + len;
93863
93864 +#ifdef CONFIG_PAX_MPROTECT
93865 + if (mm->pax_flags & MF_PAX_MPROTECT) {
93866 +#ifndef CONFIG_PAX_MPROTECT_COMPAT
93867 + if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC))
93868 + return -EPERM;
93869 + if (!(vm_flags & VM_EXEC))
93870 + vm_flags &= ~VM_MAYEXEC;
93871 +#else
93872 + if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
93873 + vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
93874 +#endif
93875 + else
93876 + vm_flags &= ~VM_MAYWRITE;
93877 + }
93878 +#endif
93879 +
93880 vma->vm_flags = vm_flags | mm->def_flags | VM_DONTEXPAND | VM_SOFTDIRTY;
93881 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
93882
93883 diff --git a/mm/mprotect.c b/mm/mprotect.c
93884 index bb53a65..249c052 100644
93885 --- a/mm/mprotect.c
93886 +++ b/mm/mprotect.c
93887 @@ -23,10 +23,18 @@
93888 #include <linux/mmu_notifier.h>
93889 #include <linux/migrate.h>
93890 #include <linux/perf_event.h>
93891 +#include <linux/sched/sysctl.h>
93892 +
93893 +#ifdef CONFIG_PAX_MPROTECT
93894 +#include <linux/elf.h>
93895 +#include <linux/binfmts.h>
93896 +#endif
93897 +
93898 #include <asm/uaccess.h>
93899 #include <asm/pgtable.h>
93900 #include <asm/cacheflush.h>
93901 #include <asm/tlbflush.h>
93902 +#include <asm/mmu_context.h>
93903
93904 #ifndef pgprot_modify
93905 static inline pgprot_t pgprot_modify(pgprot_t oldprot, pgprot_t newprot)
93906 @@ -222,6 +230,48 @@ unsigned long change_protection(struct vm_area_struct *vma, unsigned long start,
93907 return pages;
93908 }
93909
93910 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
93911 +/* called while holding the mmap semaphor for writing except stack expansion */
93912 +void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot)
93913 +{
93914 + unsigned long oldlimit, newlimit = 0UL;
93915 +
93916 + if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || (__supported_pte_mask & _PAGE_NX))
93917 + return;
93918 +
93919 + spin_lock(&mm->page_table_lock);
93920 + oldlimit = mm->context.user_cs_limit;
93921 + if ((prot & VM_EXEC) && oldlimit < end)
93922 + /* USER_CS limit moved up */
93923 + newlimit = end;
93924 + else if (!(prot & VM_EXEC) && start < oldlimit && oldlimit <= end)
93925 + /* USER_CS limit moved down */
93926 + newlimit = start;
93927 +
93928 + if (newlimit) {
93929 + mm->context.user_cs_limit = newlimit;
93930 +
93931 +#ifdef CONFIG_SMP
93932 + wmb();
93933 + cpus_clear(mm->context.cpu_user_cs_mask);
93934 + cpu_set(smp_processor_id(), mm->context.cpu_user_cs_mask);
93935 +#endif
93936 +
93937 + set_user_cs(mm->context.user_cs_base, mm->context.user_cs_limit, smp_processor_id());
93938 + }
93939 + spin_unlock(&mm->page_table_lock);
93940 + if (newlimit == end) {
93941 + struct vm_area_struct *vma = find_vma(mm, oldlimit);
93942 +
93943 + for (; vma && vma->vm_start < end; vma = vma->vm_next)
93944 + if (is_vm_hugetlb_page(vma))
93945 + hugetlb_change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot);
93946 + else
93947 + change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot, vma_wants_writenotify(vma), 0);
93948 + }
93949 +}
93950 +#endif
93951 +
93952 int
93953 mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
93954 unsigned long start, unsigned long end, unsigned long newflags)
93955 @@ -234,11 +284,29 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
93956 int error;
93957 int dirty_accountable = 0;
93958
93959 +#ifdef CONFIG_PAX_SEGMEXEC
93960 + struct vm_area_struct *vma_m = NULL;
93961 + unsigned long start_m, end_m;
93962 +
93963 + start_m = start + SEGMEXEC_TASK_SIZE;
93964 + end_m = end + SEGMEXEC_TASK_SIZE;
93965 +#endif
93966 +
93967 if (newflags == oldflags) {
93968 *pprev = vma;
93969 return 0;
93970 }
93971
93972 + if (newflags & (VM_READ | VM_WRITE | VM_EXEC)) {
93973 + struct vm_area_struct *prev = vma->vm_prev, *next = vma->vm_next;
93974 +
93975 + if (next && (next->vm_flags & VM_GROWSDOWN) && sysctl_heap_stack_gap > next->vm_start - end)
93976 + return -ENOMEM;
93977 +
93978 + if (prev && (prev->vm_flags & VM_GROWSUP) && sysctl_heap_stack_gap > start - prev->vm_end)
93979 + return -ENOMEM;
93980 + }
93981 +
93982 /*
93983 * If we make a private mapping writable we increase our commit;
93984 * but (without finer accounting) cannot reduce our commit if we
93985 @@ -255,6 +323,42 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
93986 }
93987 }
93988
93989 +#ifdef CONFIG_PAX_SEGMEXEC
93990 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && ((oldflags ^ newflags) & VM_EXEC)) {
93991 + if (start != vma->vm_start) {
93992 + error = split_vma(mm, vma, start, 1);
93993 + if (error)
93994 + goto fail;
93995 + BUG_ON(!*pprev || (*pprev)->vm_next == vma);
93996 + *pprev = (*pprev)->vm_next;
93997 + }
93998 +
93999 + if (end != vma->vm_end) {
94000 + error = split_vma(mm, vma, end, 0);
94001 + if (error)
94002 + goto fail;
94003 + }
94004 +
94005 + if (pax_find_mirror_vma(vma)) {
94006 + error = __do_munmap(mm, start_m, end_m - start_m);
94007 + if (error)
94008 + goto fail;
94009 + } else {
94010 + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
94011 + if (!vma_m) {
94012 + error = -ENOMEM;
94013 + goto fail;
94014 + }
94015 + vma->vm_flags = newflags;
94016 + error = pax_mirror_vma(vma_m, vma);
94017 + if (error) {
94018 + vma->vm_flags = oldflags;
94019 + goto fail;
94020 + }
94021 + }
94022 + }
94023 +#endif
94024 +
94025 /*
94026 * First try to merge with previous and/or next vma.
94027 */
94028 @@ -285,9 +389,21 @@ success:
94029 * vm_flags and vm_page_prot are protected by the mmap_sem
94030 * held in write mode.
94031 */
94032 +
94033 +#ifdef CONFIG_PAX_SEGMEXEC
94034 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (newflags & VM_EXEC) && ((vma->vm_flags ^ newflags) & VM_READ))
94035 + pax_find_mirror_vma(vma)->vm_flags ^= VM_READ;
94036 +#endif
94037 +
94038 vma->vm_flags = newflags;
94039 +
94040 +#ifdef CONFIG_PAX_MPROTECT
94041 + if (mm->binfmt && mm->binfmt->handle_mprotect)
94042 + mm->binfmt->handle_mprotect(vma, newflags);
94043 +#endif
94044 +
94045 vma->vm_page_prot = pgprot_modify(vma->vm_page_prot,
94046 - vm_get_page_prot(newflags));
94047 + vm_get_page_prot(vma->vm_flags));
94048
94049 if (vma_wants_writenotify(vma)) {
94050 vma->vm_page_prot = vm_get_page_prot(newflags & ~VM_SHARED);
94051 @@ -326,6 +442,17 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
94052 end = start + len;
94053 if (end <= start)
94054 return -ENOMEM;
94055 +
94056 +#ifdef CONFIG_PAX_SEGMEXEC
94057 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
94058 + if (end > SEGMEXEC_TASK_SIZE)
94059 + return -EINVAL;
94060 + } else
94061 +#endif
94062 +
94063 + if (end > TASK_SIZE)
94064 + return -EINVAL;
94065 +
94066 if (!arch_validate_prot(prot))
94067 return -EINVAL;
94068
94069 @@ -333,7 +460,7 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
94070 /*
94071 * Does the application expect PROT_READ to imply PROT_EXEC:
94072 */
94073 - if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
94074 + if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
94075 prot |= PROT_EXEC;
94076
94077 vm_flags = calc_vm_prot_bits(prot);
94078 @@ -365,6 +492,11 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
94079 if (start > vma->vm_start)
94080 prev = vma;
94081
94082 +#ifdef CONFIG_PAX_MPROTECT
94083 + if (current->mm->binfmt && current->mm->binfmt->handle_mprotect)
94084 + current->mm->binfmt->handle_mprotect(vma, vm_flags);
94085 +#endif
94086 +
94087 for (nstart = start ; ; ) {
94088 unsigned long newflags;
94089
94090 @@ -375,6 +507,14 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
94091
94092 /* newflags >> 4 shift VM_MAY% in place of VM_% */
94093 if ((newflags & ~(newflags >> 4)) & (VM_READ | VM_WRITE | VM_EXEC)) {
94094 + if (prot & (PROT_WRITE | PROT_EXEC))
94095 + gr_log_rwxmprotect(vma);
94096 +
94097 + error = -EACCES;
94098 + goto out;
94099 + }
94100 +
94101 + if (!gr_acl_handle_mprotect(vma->vm_file, prot)) {
94102 error = -EACCES;
94103 goto out;
94104 }
94105 @@ -389,6 +529,9 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
94106 error = mprotect_fixup(vma, &prev, nstart, tmp, newflags);
94107 if (error)
94108 goto out;
94109 +
94110 + track_exec_limit(current->mm, nstart, tmp, vm_flags);
94111 +
94112 nstart = tmp;
94113
94114 if (nstart < prev->vm_end)
94115 diff --git a/mm/mremap.c b/mm/mremap.c
94116 index 0843feb..4f5b2e6 100644
94117 --- a/mm/mremap.c
94118 +++ b/mm/mremap.c
94119 @@ -144,6 +144,12 @@ static void move_ptes(struct vm_area_struct *vma, pmd_t *old_pmd,
94120 continue;
94121 pte = ptep_get_and_clear(mm, old_addr, old_pte);
94122 pte = move_pte(pte, new_vma->vm_page_prot, old_addr, new_addr);
94123 +
94124 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
94125 + if (!(__supported_pte_mask & _PAGE_NX) && pte_present(pte) && (new_vma->vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC)
94126 + pte = pte_exprotect(pte);
94127 +#endif
94128 +
94129 pte = move_soft_dirty_pte(pte);
94130 set_pte_at(mm, new_addr, new_pte, pte);
94131 }
94132 @@ -337,6 +343,11 @@ static struct vm_area_struct *vma_to_resize(unsigned long addr,
94133 if (is_vm_hugetlb_page(vma))
94134 goto Einval;
94135
94136 +#ifdef CONFIG_PAX_SEGMEXEC
94137 + if (pax_find_mirror_vma(vma))
94138 + goto Einval;
94139 +#endif
94140 +
94141 /* We can't remap across vm area boundaries */
94142 if (old_len > vma->vm_end - addr)
94143 goto Efault;
94144 @@ -392,20 +403,25 @@ static unsigned long mremap_to(unsigned long addr, unsigned long old_len,
94145 unsigned long ret = -EINVAL;
94146 unsigned long charged = 0;
94147 unsigned long map_flags;
94148 + unsigned long pax_task_size = TASK_SIZE;
94149
94150 if (new_addr & ~PAGE_MASK)
94151 goto out;
94152
94153 - if (new_len > TASK_SIZE || new_addr > TASK_SIZE - new_len)
94154 +#ifdef CONFIG_PAX_SEGMEXEC
94155 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
94156 + pax_task_size = SEGMEXEC_TASK_SIZE;
94157 +#endif
94158 +
94159 + pax_task_size -= PAGE_SIZE;
94160 +
94161 + if (new_len > TASK_SIZE || new_addr > pax_task_size - new_len)
94162 goto out;
94163
94164 /* Check if the location we're moving into overlaps the
94165 * old location at all, and fail if it does.
94166 */
94167 - if ((new_addr <= addr) && (new_addr+new_len) > addr)
94168 - goto out;
94169 -
94170 - if ((addr <= new_addr) && (addr+old_len) > new_addr)
94171 + if (addr + old_len > new_addr && new_addr + new_len > addr)
94172 goto out;
94173
94174 ret = do_munmap(mm, new_addr, new_len);
94175 @@ -474,6 +490,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
94176 unsigned long ret = -EINVAL;
94177 unsigned long charged = 0;
94178 bool locked = false;
94179 + unsigned long pax_task_size = TASK_SIZE;
94180
94181 if (flags & ~(MREMAP_FIXED | MREMAP_MAYMOVE))
94182 return ret;
94183 @@ -495,6 +512,17 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
94184 if (!new_len)
94185 return ret;
94186
94187 +#ifdef CONFIG_PAX_SEGMEXEC
94188 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
94189 + pax_task_size = SEGMEXEC_TASK_SIZE;
94190 +#endif
94191 +
94192 + pax_task_size -= PAGE_SIZE;
94193 +
94194 + if (new_len > pax_task_size || addr > pax_task_size-new_len ||
94195 + old_len > pax_task_size || addr > pax_task_size-old_len)
94196 + return ret;
94197 +
94198 down_write(&current->mm->mmap_sem);
94199
94200 if (flags & MREMAP_FIXED) {
94201 @@ -545,6 +573,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
94202 new_addr = addr;
94203 }
94204 ret = addr;
94205 + track_exec_limit(vma->vm_mm, vma->vm_start, addr + new_len, vma->vm_flags);
94206 goto out;
94207 }
94208 }
94209 @@ -568,7 +597,12 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
94210 goto out;
94211 }
94212
94213 + map_flags = vma->vm_flags;
94214 ret = move_vma(vma, addr, old_len, new_len, new_addr, &locked);
94215 + if (!(ret & ~PAGE_MASK)) {
94216 + track_exec_limit(current->mm, addr, addr + old_len, 0UL);
94217 + track_exec_limit(current->mm, new_addr, new_addr + new_len, map_flags);
94218 + }
94219 }
94220 out:
94221 if (ret & ~PAGE_MASK)
94222 diff --git a/mm/nommu.c b/mm/nommu.c
94223 index fec093a..8162f74 100644
94224 --- a/mm/nommu.c
94225 +++ b/mm/nommu.c
94226 @@ -64,7 +64,6 @@ int sysctl_max_map_count = DEFAULT_MAX_MAP_COUNT;
94227 int sysctl_nr_trim_pages = CONFIG_NOMMU_INITIAL_TRIM_EXCESS;
94228 unsigned long sysctl_user_reserve_kbytes __read_mostly = 1UL << 17; /* 128MB */
94229 unsigned long sysctl_admin_reserve_kbytes __read_mostly = 1UL << 13; /* 8MB */
94230 -int heap_stack_gap = 0;
94231
94232 atomic_long_t mmap_pages_allocated;
94233
94234 @@ -844,15 +843,6 @@ struct vm_area_struct *find_vma(struct mm_struct *mm, unsigned long addr)
94235 EXPORT_SYMBOL(find_vma);
94236
94237 /*
94238 - * find a VMA
94239 - * - we don't extend stack VMAs under NOMMU conditions
94240 - */
94241 -struct vm_area_struct *find_extend_vma(struct mm_struct *mm, unsigned long addr)
94242 -{
94243 - return find_vma(mm, addr);
94244 -}
94245 -
94246 -/*
94247 * expand a stack to a given address
94248 * - not supported under NOMMU conditions
94249 */
94250 @@ -1563,6 +1553,7 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
94251
94252 /* most fields are the same, copy all, and then fixup */
94253 *new = *vma;
94254 + INIT_LIST_HEAD(&new->anon_vma_chain);
94255 *region = *vma->vm_region;
94256 new->vm_region = region;
94257
94258 @@ -1992,8 +1983,8 @@ int generic_file_remap_pages(struct vm_area_struct *vma, unsigned long addr,
94259 }
94260 EXPORT_SYMBOL(generic_file_remap_pages);
94261
94262 -static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
94263 - unsigned long addr, void *buf, int len, int write)
94264 +static ssize_t __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
94265 + unsigned long addr, void *buf, size_t len, int write)
94266 {
94267 struct vm_area_struct *vma;
94268
94269 @@ -2034,8 +2025,8 @@ static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
94270 *
94271 * The caller must hold a reference on @mm.
94272 */
94273 -int access_remote_vm(struct mm_struct *mm, unsigned long addr,
94274 - void *buf, int len, int write)
94275 +ssize_t access_remote_vm(struct mm_struct *mm, unsigned long addr,
94276 + void *buf, size_t len, int write)
94277 {
94278 return __access_remote_vm(NULL, mm, addr, buf, len, write);
94279 }
94280 @@ -2044,7 +2035,7 @@ int access_remote_vm(struct mm_struct *mm, unsigned long addr,
94281 * Access another process' address space.
94282 * - source/target buffer must be kernel space
94283 */
94284 -int access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, int len, int write)
94285 +ssize_t access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, size_t len, int write)
94286 {
94287 struct mm_struct *mm;
94288
94289 diff --git a/mm/page-writeback.c b/mm/page-writeback.c
94290 index 7106cb1..0805f48 100644
94291 --- a/mm/page-writeback.c
94292 +++ b/mm/page-writeback.c
94293 @@ -685,7 +685,7 @@ static inline long long pos_ratio_polynom(unsigned long setpoint,
94294 * card's bdi_dirty may rush to many times higher than bdi_setpoint.
94295 * - the bdi dirty thresh drops quickly due to change of JBOD workload
94296 */
94297 -static unsigned long bdi_position_ratio(struct backing_dev_info *bdi,
94298 +static unsigned long __intentional_overflow(-1) bdi_position_ratio(struct backing_dev_info *bdi,
94299 unsigned long thresh,
94300 unsigned long bg_thresh,
94301 unsigned long dirty,
94302 diff --git a/mm/page_alloc.c b/mm/page_alloc.c
94303 index 589521d..314053a 100644
94304 --- a/mm/page_alloc.c
94305 +++ b/mm/page_alloc.c
94306 @@ -61,6 +61,7 @@
94307 #include <linux/page-debug-flags.h>
94308 #include <linux/hugetlb.h>
94309 #include <linux/sched/rt.h>
94310 +#include <linux/random.h>
94311
94312 #include <asm/sections.h>
94313 #include <asm/tlbflush.h>
94314 @@ -354,7 +355,7 @@ out:
94315 * This usage means that zero-order pages may not be compound.
94316 */
94317
94318 -static void free_compound_page(struct page *page)
94319 +void free_compound_page(struct page *page)
94320 {
94321 __free_pages_ok(page, compound_order(page));
94322 }
94323 @@ -714,6 +715,10 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
94324 int i;
94325 int bad = 0;
94326
94327 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
94328 + unsigned long index = 1UL << order;
94329 +#endif
94330 +
94331 trace_mm_page_free(page, order);
94332 kmemcheck_free_shadow(page, order);
94333
94334 @@ -730,6 +735,12 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
94335 debug_check_no_obj_freed(page_address(page),
94336 PAGE_SIZE << order);
94337 }
94338 +
94339 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
94340 + for (; index; --index)
94341 + sanitize_highpage(page + index - 1);
94342 +#endif
94343 +
94344 arch_free_page(page, order);
94345 kernel_map_pages(page, 1 << order, 0);
94346
94347 @@ -752,6 +763,20 @@ static void __free_pages_ok(struct page *page, unsigned int order)
94348 local_irq_restore(flags);
94349 }
94350
94351 +#ifdef CONFIG_PAX_LATENT_ENTROPY
94352 +bool __meminitdata extra_latent_entropy;
94353 +
94354 +static int __init setup_pax_extra_latent_entropy(char *str)
94355 +{
94356 + extra_latent_entropy = true;
94357 + return 0;
94358 +}
94359 +early_param("pax_extra_latent_entropy", setup_pax_extra_latent_entropy);
94360 +
94361 +volatile u64 latent_entropy __latent_entropy;
94362 +EXPORT_SYMBOL(latent_entropy);
94363 +#endif
94364 +
94365 void __init __free_pages_bootmem(struct page *page, unsigned int order)
94366 {
94367 unsigned int nr_pages = 1 << order;
94368 @@ -767,6 +792,19 @@ void __init __free_pages_bootmem(struct page *page, unsigned int order)
94369 __ClearPageReserved(p);
94370 set_page_count(p, 0);
94371
94372 +#ifdef CONFIG_PAX_LATENT_ENTROPY
94373 + if (extra_latent_entropy && !PageHighMem(page) && page_to_pfn(page) < 0x100000) {
94374 + u64 hash = 0;
94375 + size_t index, end = PAGE_SIZE * nr_pages / sizeof hash;
94376 + const u64 *data = lowmem_page_address(page);
94377 +
94378 + for (index = 0; index < end; index++)
94379 + hash ^= hash + data[index];
94380 + latent_entropy ^= hash;
94381 + add_device_randomness((const void *)&latent_entropy, sizeof(latent_entropy));
94382 + }
94383 +#endif
94384 +
94385 page_zone(page)->managed_pages += nr_pages;
94386 set_page_refcounted(page);
94387 __free_pages(page, order);
94388 @@ -872,8 +910,10 @@ static int prep_new_page(struct page *page, int order, gfp_t gfp_flags)
94389 arch_alloc_page(page, order);
94390 kernel_map_pages(page, 1 << order, 1);
94391
94392 +#ifndef CONFIG_PAX_MEMORY_SANITIZE
94393 if (gfp_flags & __GFP_ZERO)
94394 prep_zero_page(page, order, gfp_flags);
94395 +#endif
94396
94397 if (order && (gfp_flags & __GFP_COMP))
94398 prep_compound_page(page, order);
94399 diff --git a/mm/page_io.c b/mm/page_io.c
94400 index 8c79a47..a689e0d 100644
94401 --- a/mm/page_io.c
94402 +++ b/mm/page_io.c
94403 @@ -260,7 +260,7 @@ int __swap_writepage(struct page *page, struct writeback_control *wbc,
94404 struct file *swap_file = sis->swap_file;
94405 struct address_space *mapping = swap_file->f_mapping;
94406 struct iovec iov = {
94407 - .iov_base = kmap(page),
94408 + .iov_base = (void __force_user *)kmap(page),
94409 .iov_len = PAGE_SIZE,
94410 };
94411
94412 diff --git a/mm/percpu.c b/mm/percpu.c
94413 index 0d10def..6dc822d 100644
94414 --- a/mm/percpu.c
94415 +++ b/mm/percpu.c
94416 @@ -122,7 +122,7 @@ static unsigned int pcpu_low_unit_cpu __read_mostly;
94417 static unsigned int pcpu_high_unit_cpu __read_mostly;
94418
94419 /* the address of the first chunk which starts with the kernel static area */
94420 -void *pcpu_base_addr __read_mostly;
94421 +void *pcpu_base_addr __read_only;
94422 EXPORT_SYMBOL_GPL(pcpu_base_addr);
94423
94424 static const int *pcpu_unit_map __read_mostly; /* cpu -> unit */
94425 diff --git a/mm/process_vm_access.c b/mm/process_vm_access.c
94426 index fd26d04..0cea1b0 100644
94427 --- a/mm/process_vm_access.c
94428 +++ b/mm/process_vm_access.c
94429 @@ -13,6 +13,7 @@
94430 #include <linux/uio.h>
94431 #include <linux/sched.h>
94432 #include <linux/highmem.h>
94433 +#include <linux/security.h>
94434 #include <linux/ptrace.h>
94435 #include <linux/slab.h>
94436 #include <linux/syscalls.h>
94437 @@ -258,19 +259,19 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
94438 size_t iov_l_curr_offset = 0;
94439 ssize_t iov_len;
94440
94441 + return -ENOSYS; // PaX: until properly audited
94442 +
94443 /*
94444 * Work out how many pages of struct pages we're going to need
94445 * when eventually calling get_user_pages
94446 */
94447 for (i = 0; i < riovcnt; i++) {
94448 iov_len = rvec[i].iov_len;
94449 - if (iov_len > 0) {
94450 - nr_pages_iov = ((unsigned long)rvec[i].iov_base
94451 - + iov_len)
94452 - / PAGE_SIZE - (unsigned long)rvec[i].iov_base
94453 - / PAGE_SIZE + 1;
94454 - nr_pages = max(nr_pages, nr_pages_iov);
94455 - }
94456 + if (iov_len <= 0)
94457 + continue;
94458 + nr_pages_iov = ((unsigned long)rvec[i].iov_base + iov_len) / PAGE_SIZE -
94459 + (unsigned long)rvec[i].iov_base / PAGE_SIZE + 1;
94460 + nr_pages = max(nr_pages, nr_pages_iov);
94461 }
94462
94463 if (nr_pages == 0)
94464 @@ -298,6 +299,11 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
94465 goto free_proc_pages;
94466 }
94467
94468 + if (gr_handle_ptrace(task, vm_write ? PTRACE_POKETEXT : PTRACE_ATTACH)) {
94469 + rc = -EPERM;
94470 + goto put_task_struct;
94471 + }
94472 +
94473 mm = mm_access(task, PTRACE_MODE_ATTACH);
94474 if (!mm || IS_ERR(mm)) {
94475 rc = IS_ERR(mm) ? PTR_ERR(mm) : -ESRCH;
94476 diff --git a/mm/rmap.c b/mm/rmap.c
94477 index 068522d..f539f21 100644
94478 --- a/mm/rmap.c
94479 +++ b/mm/rmap.c
94480 @@ -163,6 +163,10 @@ int anon_vma_prepare(struct vm_area_struct *vma)
94481 struct anon_vma *anon_vma = vma->anon_vma;
94482 struct anon_vma_chain *avc;
94483
94484 +#ifdef CONFIG_PAX_SEGMEXEC
94485 + struct anon_vma_chain *avc_m = NULL;
94486 +#endif
94487 +
94488 might_sleep();
94489 if (unlikely(!anon_vma)) {
94490 struct mm_struct *mm = vma->vm_mm;
94491 @@ -172,6 +176,12 @@ int anon_vma_prepare(struct vm_area_struct *vma)
94492 if (!avc)
94493 goto out_enomem;
94494
94495 +#ifdef CONFIG_PAX_SEGMEXEC
94496 + avc_m = anon_vma_chain_alloc(GFP_KERNEL);
94497 + if (!avc_m)
94498 + goto out_enomem_free_avc;
94499 +#endif
94500 +
94501 anon_vma = find_mergeable_anon_vma(vma);
94502 allocated = NULL;
94503 if (!anon_vma) {
94504 @@ -185,6 +195,18 @@ int anon_vma_prepare(struct vm_area_struct *vma)
94505 /* page_table_lock to protect against threads */
94506 spin_lock(&mm->page_table_lock);
94507 if (likely(!vma->anon_vma)) {
94508 +
94509 +#ifdef CONFIG_PAX_SEGMEXEC
94510 + struct vm_area_struct *vma_m = pax_find_mirror_vma(vma);
94511 +
94512 + if (vma_m) {
94513 + BUG_ON(vma_m->anon_vma);
94514 + vma_m->anon_vma = anon_vma;
94515 + anon_vma_chain_link(vma_m, avc_m, anon_vma);
94516 + avc_m = NULL;
94517 + }
94518 +#endif
94519 +
94520 vma->anon_vma = anon_vma;
94521 anon_vma_chain_link(vma, avc, anon_vma);
94522 allocated = NULL;
94523 @@ -195,12 +217,24 @@ int anon_vma_prepare(struct vm_area_struct *vma)
94524
94525 if (unlikely(allocated))
94526 put_anon_vma(allocated);
94527 +
94528 +#ifdef CONFIG_PAX_SEGMEXEC
94529 + if (unlikely(avc_m))
94530 + anon_vma_chain_free(avc_m);
94531 +#endif
94532 +
94533 if (unlikely(avc))
94534 anon_vma_chain_free(avc);
94535 }
94536 return 0;
94537
94538 out_enomem_free_avc:
94539 +
94540 +#ifdef CONFIG_PAX_SEGMEXEC
94541 + if (avc_m)
94542 + anon_vma_chain_free(avc_m);
94543 +#endif
94544 +
94545 anon_vma_chain_free(avc);
94546 out_enomem:
94547 return -ENOMEM;
94548 @@ -236,7 +270,7 @@ static inline void unlock_anon_vma_root(struct anon_vma *root)
94549 * Attach the anon_vmas from src to dst.
94550 * Returns 0 on success, -ENOMEM on failure.
94551 */
94552 -int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
94553 +int anon_vma_clone(struct vm_area_struct *dst, const struct vm_area_struct *src)
94554 {
94555 struct anon_vma_chain *avc, *pavc;
94556 struct anon_vma *root = NULL;
94557 @@ -269,7 +303,7 @@ int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
94558 * the corresponding VMA in the parent process is attached to.
94559 * Returns 0 on success, non-zero on failure.
94560 */
94561 -int anon_vma_fork(struct vm_area_struct *vma, struct vm_area_struct *pvma)
94562 +int anon_vma_fork(struct vm_area_struct *vma, const struct vm_area_struct *pvma)
94563 {
94564 struct anon_vma_chain *avc;
94565 struct anon_vma *anon_vma;
94566 @@ -373,8 +407,10 @@ static void anon_vma_ctor(void *data)
94567 void __init anon_vma_init(void)
94568 {
94569 anon_vma_cachep = kmem_cache_create("anon_vma", sizeof(struct anon_vma),
94570 - 0, SLAB_DESTROY_BY_RCU|SLAB_PANIC, anon_vma_ctor);
94571 - anon_vma_chain_cachep = KMEM_CACHE(anon_vma_chain, SLAB_PANIC);
94572 + 0, SLAB_DESTROY_BY_RCU|SLAB_PANIC|SLAB_NO_SANITIZE,
94573 + anon_vma_ctor);
94574 + anon_vma_chain_cachep = KMEM_CACHE(anon_vma_chain,
94575 + SLAB_PANIC|SLAB_NO_SANITIZE);
94576 }
94577
94578 /*
94579 diff --git a/mm/shmem.c b/mm/shmem.c
94580 index 902a148..58f9d59 100644
94581 --- a/mm/shmem.c
94582 +++ b/mm/shmem.c
94583 @@ -33,7 +33,7 @@
94584 #include <linux/swap.h>
94585 #include <linux/aio.h>
94586
94587 -static struct vfsmount *shm_mnt;
94588 +struct vfsmount *shm_mnt;
94589
94590 #ifdef CONFIG_SHMEM
94591 /*
94592 @@ -77,7 +77,7 @@ static struct vfsmount *shm_mnt;
94593 #define BOGO_DIRENT_SIZE 20
94594
94595 /* Symlink up to this size is kmalloc'ed instead of using a swappable page */
94596 -#define SHORT_SYMLINK_LEN 128
94597 +#define SHORT_SYMLINK_LEN 64
94598
94599 /*
94600 * shmem_fallocate and shmem_writepage communicate via inode->i_private
94601 @@ -2232,6 +2232,11 @@ static const struct xattr_handler *shmem_xattr_handlers[] = {
94602 static int shmem_xattr_validate(const char *name)
94603 {
94604 struct { const char *prefix; size_t len; } arr[] = {
94605 +
94606 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
94607 + { XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN},
94608 +#endif
94609 +
94610 { XATTR_SECURITY_PREFIX, XATTR_SECURITY_PREFIX_LEN },
94611 { XATTR_TRUSTED_PREFIX, XATTR_TRUSTED_PREFIX_LEN }
94612 };
94613 @@ -2287,6 +2292,15 @@ static int shmem_setxattr(struct dentry *dentry, const char *name,
94614 if (err)
94615 return err;
94616
94617 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
94618 + if (!strncmp(name, XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN)) {
94619 + if (strcmp(name, XATTR_NAME_PAX_FLAGS))
94620 + return -EOPNOTSUPP;
94621 + if (size > 8)
94622 + return -EINVAL;
94623 + }
94624 +#endif
94625 +
94626 return simple_xattr_set(&info->xattrs, name, value, size, flags);
94627 }
94628
94629 @@ -2599,8 +2613,7 @@ int shmem_fill_super(struct super_block *sb, void *data, int silent)
94630 int err = -ENOMEM;
94631
94632 /* Round up to L1_CACHE_BYTES to resist false sharing */
94633 - sbinfo = kzalloc(max((int)sizeof(struct shmem_sb_info),
94634 - L1_CACHE_BYTES), GFP_KERNEL);
94635 + sbinfo = kzalloc(max(sizeof(struct shmem_sb_info), L1_CACHE_BYTES), GFP_KERNEL);
94636 if (!sbinfo)
94637 return -ENOMEM;
94638
94639 diff --git a/mm/slab.c b/mm/slab.c
94640 index eb043bf..d82f5a8 100644
94641 --- a/mm/slab.c
94642 +++ b/mm/slab.c
94643 @@ -300,10 +300,12 @@ static void kmem_cache_node_init(struct kmem_cache_node *parent)
94644 if ((x)->max_freeable < i) \
94645 (x)->max_freeable = i; \
94646 } while (0)
94647 -#define STATS_INC_ALLOCHIT(x) atomic_inc(&(x)->allochit)
94648 -#define STATS_INC_ALLOCMISS(x) atomic_inc(&(x)->allocmiss)
94649 -#define STATS_INC_FREEHIT(x) atomic_inc(&(x)->freehit)
94650 -#define STATS_INC_FREEMISS(x) atomic_inc(&(x)->freemiss)
94651 +#define STATS_INC_ALLOCHIT(x) atomic_inc_unchecked(&(x)->allochit)
94652 +#define STATS_INC_ALLOCMISS(x) atomic_inc_unchecked(&(x)->allocmiss)
94653 +#define STATS_INC_FREEHIT(x) atomic_inc_unchecked(&(x)->freehit)
94654 +#define STATS_INC_FREEMISS(x) atomic_inc_unchecked(&(x)->freemiss)
94655 +#define STATS_INC_SANITIZED(x) atomic_inc_unchecked(&(x)->sanitized)
94656 +#define STATS_INC_NOT_SANITIZED(x) atomic_inc_unchecked(&(x)->not_sanitized)
94657 #else
94658 #define STATS_INC_ACTIVE(x) do { } while (0)
94659 #define STATS_DEC_ACTIVE(x) do { } while (0)
94660 @@ -320,6 +322,8 @@ static void kmem_cache_node_init(struct kmem_cache_node *parent)
94661 #define STATS_INC_ALLOCMISS(x) do { } while (0)
94662 #define STATS_INC_FREEHIT(x) do { } while (0)
94663 #define STATS_INC_FREEMISS(x) do { } while (0)
94664 +#define STATS_INC_SANITIZED(x) do { } while (0)
94665 +#define STATS_INC_NOT_SANITIZED(x) do { } while (0)
94666 #endif
94667
94668 #if DEBUG
94669 @@ -403,7 +407,7 @@ static inline void *index_to_obj(struct kmem_cache *cache, struct page *page,
94670 * reciprocal_divide(offset, cache->reciprocal_buffer_size)
94671 */
94672 static inline unsigned int obj_to_index(const struct kmem_cache *cache,
94673 - const struct page *page, void *obj)
94674 + const struct page *page, const void *obj)
94675 {
94676 u32 offset = (obj - page->s_mem);
94677 return reciprocal_divide(offset, cache->reciprocal_buffer_size);
94678 @@ -1489,12 +1493,12 @@ void __init kmem_cache_init(void)
94679 */
94680
94681 kmalloc_caches[INDEX_AC] = create_kmalloc_cache("kmalloc-ac",
94682 - kmalloc_size(INDEX_AC), ARCH_KMALLOC_FLAGS);
94683 + kmalloc_size(INDEX_AC), SLAB_USERCOPY | ARCH_KMALLOC_FLAGS);
94684
94685 if (INDEX_AC != INDEX_NODE)
94686 kmalloc_caches[INDEX_NODE] =
94687 create_kmalloc_cache("kmalloc-node",
94688 - kmalloc_size(INDEX_NODE), ARCH_KMALLOC_FLAGS);
94689 + kmalloc_size(INDEX_NODE), SLAB_USERCOPY | ARCH_KMALLOC_FLAGS);
94690
94691 slab_early_init = 0;
94692
94693 @@ -3428,6 +3432,21 @@ static inline void __cache_free(struct kmem_cache *cachep, void *objp,
94694 struct array_cache *ac = cpu_cache_get(cachep);
94695
94696 check_irq_off();
94697 +
94698 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
94699 + if (pax_sanitize_slab) {
94700 + if (!(cachep->flags & (SLAB_POISON | SLAB_NO_SANITIZE))) {
94701 + memset(objp, PAX_MEMORY_SANITIZE_VALUE, cachep->object_size);
94702 +
94703 + if (cachep->ctor)
94704 + cachep->ctor(objp);
94705 +
94706 + STATS_INC_SANITIZED(cachep);
94707 + } else
94708 + STATS_INC_NOT_SANITIZED(cachep);
94709 + }
94710 +#endif
94711 +
94712 kmemleak_free_recursive(objp, cachep->flags);
94713 objp = cache_free_debugcheck(cachep, objp, caller);
94714
94715 @@ -3656,6 +3675,7 @@ void kfree(const void *objp)
94716
94717 if (unlikely(ZERO_OR_NULL_PTR(objp)))
94718 return;
94719 + VM_BUG_ON(!virt_addr_valid(objp));
94720 local_irq_save(flags);
94721 kfree_debugcheck(objp);
94722 c = virt_to_cache(objp);
94723 @@ -4097,14 +4117,22 @@ void slabinfo_show_stats(struct seq_file *m, struct kmem_cache *cachep)
94724 }
94725 /* cpu stats */
94726 {
94727 - unsigned long allochit = atomic_read(&cachep->allochit);
94728 - unsigned long allocmiss = atomic_read(&cachep->allocmiss);
94729 - unsigned long freehit = atomic_read(&cachep->freehit);
94730 - unsigned long freemiss = atomic_read(&cachep->freemiss);
94731 + unsigned long allochit = atomic_read_unchecked(&cachep->allochit);
94732 + unsigned long allocmiss = atomic_read_unchecked(&cachep->allocmiss);
94733 + unsigned long freehit = atomic_read_unchecked(&cachep->freehit);
94734 + unsigned long freemiss = atomic_read_unchecked(&cachep->freemiss);
94735
94736 seq_printf(m, " : cpustat %6lu %6lu %6lu %6lu",
94737 allochit, allocmiss, freehit, freemiss);
94738 }
94739 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
94740 + {
94741 + unsigned long sanitized = atomic_read_unchecked(&cachep->sanitized);
94742 + unsigned long not_sanitized = atomic_read_unchecked(&cachep->not_sanitized);
94743 +
94744 + seq_printf(m, " : pax %6lu %6lu", sanitized, not_sanitized);
94745 + }
94746 +#endif
94747 #endif
94748 }
94749
94750 @@ -4334,13 +4362,69 @@ static const struct file_operations proc_slabstats_operations = {
94751 static int __init slab_proc_init(void)
94752 {
94753 #ifdef CONFIG_DEBUG_SLAB_LEAK
94754 - proc_create("slab_allocators", 0, NULL, &proc_slabstats_operations);
94755 + proc_create("slab_allocators", S_IRUSR, NULL, &proc_slabstats_operations);
94756 #endif
94757 return 0;
94758 }
94759 module_init(slab_proc_init);
94760 #endif
94761
94762 +bool is_usercopy_object(const void *ptr)
94763 +{
94764 + struct page *page;
94765 + struct kmem_cache *cachep;
94766 +
94767 + if (ZERO_OR_NULL_PTR(ptr))
94768 + return false;
94769 +
94770 + if (!slab_is_available())
94771 + return false;
94772 +
94773 + if (!virt_addr_valid(ptr))
94774 + return false;
94775 +
94776 + page = virt_to_head_page(ptr);
94777 +
94778 + if (!PageSlab(page))
94779 + return false;
94780 +
94781 + cachep = page->slab_cache;
94782 + return cachep->flags & SLAB_USERCOPY;
94783 +}
94784 +
94785 +#ifdef CONFIG_PAX_USERCOPY
94786 +const char *check_heap_object(const void *ptr, unsigned long n)
94787 +{
94788 + struct page *page;
94789 + struct kmem_cache *cachep;
94790 + unsigned int objnr;
94791 + unsigned long offset;
94792 +
94793 + if (ZERO_OR_NULL_PTR(ptr))
94794 + return "<null>";
94795 +
94796 + if (!virt_addr_valid(ptr))
94797 + return NULL;
94798 +
94799 + page = virt_to_head_page(ptr);
94800 +
94801 + if (!PageSlab(page))
94802 + return NULL;
94803 +
94804 + cachep = page->slab_cache;
94805 + if (!(cachep->flags & SLAB_USERCOPY))
94806 + return cachep->name;
94807 +
94808 + objnr = obj_to_index(cachep, page, ptr);
94809 + BUG_ON(objnr >= cachep->num);
94810 + offset = ptr - index_to_obj(cachep, page, objnr) - obj_offset(cachep);
94811 + if (offset <= cachep->object_size && n <= cachep->object_size - offset)
94812 + return NULL;
94813 +
94814 + return cachep->name;
94815 +}
94816 +#endif
94817 +
94818 /**
94819 * ksize - get the actual amount of memory allocated for a given object
94820 * @objp: Pointer to the object
94821 diff --git a/mm/slab.h b/mm/slab.h
94822 index 0859c42..2f7b737 100644
94823 --- a/mm/slab.h
94824 +++ b/mm/slab.h
94825 @@ -32,6 +32,15 @@ extern struct list_head slab_caches;
94826 /* The slab cache that manages slab cache information */
94827 extern struct kmem_cache *kmem_cache;
94828
94829 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
94830 +#ifdef CONFIG_X86_64
94831 +#define PAX_MEMORY_SANITIZE_VALUE '\xfe'
94832 +#else
94833 +#define PAX_MEMORY_SANITIZE_VALUE '\xff'
94834 +#endif
94835 +extern bool pax_sanitize_slab;
94836 +#endif
94837 +
94838 unsigned long calculate_alignment(unsigned long flags,
94839 unsigned long align, unsigned long size);
94840
94841 @@ -67,7 +76,8 @@ __kmem_cache_alias(struct mem_cgroup *memcg, const char *name, size_t size,
94842
94843 /* Legal flag mask for kmem_cache_create(), for various configurations */
94844 #define SLAB_CORE_FLAGS (SLAB_HWCACHE_ALIGN | SLAB_CACHE_DMA | SLAB_PANIC | \
94845 - SLAB_DESTROY_BY_RCU | SLAB_DEBUG_OBJECTS )
94846 + SLAB_DESTROY_BY_RCU | SLAB_DEBUG_OBJECTS | \
94847 + SLAB_USERCOPY | SLAB_NO_SANITIZE)
94848
94849 #if defined(CONFIG_DEBUG_SLAB)
94850 #define SLAB_DEBUG_FLAGS (SLAB_RED_ZONE | SLAB_POISON | SLAB_STORE_USER)
94851 @@ -233,6 +243,9 @@ static inline struct kmem_cache *cache_from_obj(struct kmem_cache *s, void *x)
94852 return s;
94853
94854 page = virt_to_head_page(x);
94855 +
94856 + BUG_ON(!PageSlab(page));
94857 +
94858 cachep = page->slab_cache;
94859 if (slab_equal_or_root(cachep, s))
94860 return cachep;
94861 diff --git a/mm/slab_common.c b/mm/slab_common.c
94862 index 0b7bb39..334c328 100644
94863 --- a/mm/slab_common.c
94864 +++ b/mm/slab_common.c
94865 @@ -23,11 +23,22 @@
94866
94867 #include "slab.h"
94868
94869 -enum slab_state slab_state;
94870 +enum slab_state slab_state __read_only;
94871 LIST_HEAD(slab_caches);
94872 DEFINE_MUTEX(slab_mutex);
94873 struct kmem_cache *kmem_cache;
94874
94875 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
94876 +bool pax_sanitize_slab __read_only = true;
94877 +static int __init pax_sanitize_slab_setup(char *str)
94878 +{
94879 + pax_sanitize_slab = !!simple_strtol(str, NULL, 0);
94880 + printk("%sabled PaX slab sanitization\n", pax_sanitize_slab ? "En" : "Dis");
94881 + return 1;
94882 +}
94883 +__setup("pax_sanitize_slab=", pax_sanitize_slab_setup);
94884 +#endif
94885 +
94886 #ifdef CONFIG_DEBUG_VM
94887 static int kmem_cache_sanity_check(struct mem_cgroup *memcg, const char *name,
94888 size_t size)
94889 @@ -212,7 +223,7 @@ kmem_cache_create_memcg(struct mem_cgroup *memcg, const char *name, size_t size,
94890
94891 err = __kmem_cache_create(s, flags);
94892 if (!err) {
94893 - s->refcount = 1;
94894 + atomic_set(&s->refcount, 1);
94895 list_add(&s->list, &slab_caches);
94896 memcg_cache_list_add(memcg, s);
94897 } else {
94898 @@ -258,8 +269,7 @@ void kmem_cache_destroy(struct kmem_cache *s)
94899
94900 get_online_cpus();
94901 mutex_lock(&slab_mutex);
94902 - s->refcount--;
94903 - if (!s->refcount) {
94904 + if (atomic_dec_and_test(&s->refcount)) {
94905 list_del(&s->list);
94906
94907 if (!__kmem_cache_shutdown(s)) {
94908 @@ -305,7 +315,7 @@ void __init create_boot_cache(struct kmem_cache *s, const char *name, size_t siz
94909 panic("Creation of kmalloc slab %s size=%zu failed. Reason %d\n",
94910 name, size, err);
94911
94912 - s->refcount = -1; /* Exempt from merging for now */
94913 + atomic_set(&s->refcount, -1); /* Exempt from merging for now */
94914 }
94915
94916 struct kmem_cache *__init create_kmalloc_cache(const char *name, size_t size,
94917 @@ -318,7 +328,7 @@ struct kmem_cache *__init create_kmalloc_cache(const char *name, size_t size,
94918
94919 create_boot_cache(s, name, size, flags);
94920 list_add(&s->list, &slab_caches);
94921 - s->refcount = 1;
94922 + atomic_set(&s->refcount, 1);
94923 return s;
94924 }
94925
94926 @@ -330,6 +340,11 @@ struct kmem_cache *kmalloc_dma_caches[KMALLOC_SHIFT_HIGH + 1];
94927 EXPORT_SYMBOL(kmalloc_dma_caches);
94928 #endif
94929
94930 +#ifdef CONFIG_PAX_USERCOPY_SLABS
94931 +struct kmem_cache *kmalloc_usercopy_caches[KMALLOC_SHIFT_HIGH + 1];
94932 +EXPORT_SYMBOL(kmalloc_usercopy_caches);
94933 +#endif
94934 +
94935 /*
94936 * Conversion table for small slabs sizes / 8 to the index in the
94937 * kmalloc array. This is necessary for slabs < 192 since we have non power
94938 @@ -394,6 +409,13 @@ struct kmem_cache *kmalloc_slab(size_t size, gfp_t flags)
94939 return kmalloc_dma_caches[index];
94940
94941 #endif
94942 +
94943 +#ifdef CONFIG_PAX_USERCOPY_SLABS
94944 + if (unlikely((flags & GFP_USERCOPY)))
94945 + return kmalloc_usercopy_caches[index];
94946 +
94947 +#endif
94948 +
94949 return kmalloc_caches[index];
94950 }
94951
94952 @@ -450,7 +472,7 @@ void __init create_kmalloc_caches(unsigned long flags)
94953 for (i = KMALLOC_SHIFT_LOW; i <= KMALLOC_SHIFT_HIGH; i++) {
94954 if (!kmalloc_caches[i]) {
94955 kmalloc_caches[i] = create_kmalloc_cache(NULL,
94956 - 1 << i, flags);
94957 + 1 << i, SLAB_USERCOPY | flags);
94958 }
94959
94960 /*
94961 @@ -459,10 +481,10 @@ void __init create_kmalloc_caches(unsigned long flags)
94962 * earlier power of two caches
94963 */
94964 if (KMALLOC_MIN_SIZE <= 32 && !kmalloc_caches[1] && i == 6)
94965 - kmalloc_caches[1] = create_kmalloc_cache(NULL, 96, flags);
94966 + kmalloc_caches[1] = create_kmalloc_cache(NULL, 96, SLAB_USERCOPY | flags);
94967
94968 if (KMALLOC_MIN_SIZE <= 64 && !kmalloc_caches[2] && i == 7)
94969 - kmalloc_caches[2] = create_kmalloc_cache(NULL, 192, flags);
94970 + kmalloc_caches[2] = create_kmalloc_cache(NULL, 192, SLAB_USERCOPY | flags);
94971 }
94972
94973 /* Kmalloc array is now usable */
94974 @@ -495,6 +517,23 @@ void __init create_kmalloc_caches(unsigned long flags)
94975 }
94976 }
94977 #endif
94978 +
94979 +#ifdef CONFIG_PAX_USERCOPY_SLABS
94980 + for (i = 0; i <= KMALLOC_SHIFT_HIGH; i++) {
94981 + struct kmem_cache *s = kmalloc_caches[i];
94982 +
94983 + if (s) {
94984 + int size = kmalloc_size(i);
94985 + char *n = kasprintf(GFP_NOWAIT,
94986 + "usercopy-kmalloc-%d", size);
94987 +
94988 + BUG_ON(!n);
94989 + kmalloc_usercopy_caches[i] = create_kmalloc_cache(n,
94990 + size, SLAB_USERCOPY | flags);
94991 + }
94992 + }
94993 +#endif
94994 +
94995 }
94996 #endif /* !CONFIG_SLOB */
94997
94998 @@ -535,6 +574,9 @@ void print_slabinfo_header(struct seq_file *m)
94999 seq_puts(m, " : globalstat <listallocs> <maxobjs> <grown> <reaped> "
95000 "<error> <maxfreeable> <nodeallocs> <remotefrees> <alienoverflow>");
95001 seq_puts(m, " : cpustat <allochit> <allocmiss> <freehit> <freemiss>");
95002 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
95003 + seq_puts(m, " : pax <sanitized> <not_sanitized>");
95004 +#endif
95005 #endif
95006 seq_putc(m, '\n');
95007 }
95008 diff --git a/mm/slob.c b/mm/slob.c
95009 index 4bf8809..98a6914 100644
95010 --- a/mm/slob.c
95011 +++ b/mm/slob.c
95012 @@ -157,7 +157,7 @@ static void set_slob(slob_t *s, slobidx_t size, slob_t *next)
95013 /*
95014 * Return the size of a slob block.
95015 */
95016 -static slobidx_t slob_units(slob_t *s)
95017 +static slobidx_t slob_units(const slob_t *s)
95018 {
95019 if (s->units > 0)
95020 return s->units;
95021 @@ -167,7 +167,7 @@ static slobidx_t slob_units(slob_t *s)
95022 /*
95023 * Return the next free slob block pointer after this one.
95024 */
95025 -static slob_t *slob_next(slob_t *s)
95026 +static slob_t *slob_next(const slob_t *s)
95027 {
95028 slob_t *base = (slob_t *)((unsigned long)s & PAGE_MASK);
95029 slobidx_t next;
95030 @@ -182,14 +182,14 @@ static slob_t *slob_next(slob_t *s)
95031 /*
95032 * Returns true if s is the last free block in its page.
95033 */
95034 -static int slob_last(slob_t *s)
95035 +static int slob_last(const slob_t *s)
95036 {
95037 return !((unsigned long)slob_next(s) & ~PAGE_MASK);
95038 }
95039
95040 -static void *slob_new_pages(gfp_t gfp, int order, int node)
95041 +static struct page *slob_new_pages(gfp_t gfp, unsigned int order, int node)
95042 {
95043 - void *page;
95044 + struct page *page;
95045
95046 #ifdef CONFIG_NUMA
95047 if (node != NUMA_NO_NODE)
95048 @@ -201,14 +201,18 @@ static void *slob_new_pages(gfp_t gfp, int order, int node)
95049 if (!page)
95050 return NULL;
95051
95052 - return page_address(page);
95053 + __SetPageSlab(page);
95054 + return page;
95055 }
95056
95057 -static void slob_free_pages(void *b, int order)
95058 +static void slob_free_pages(struct page *sp, int order)
95059 {
95060 if (current->reclaim_state)
95061 current->reclaim_state->reclaimed_slab += 1 << order;
95062 - free_pages((unsigned long)b, order);
95063 + __ClearPageSlab(sp);
95064 + page_mapcount_reset(sp);
95065 + sp->private = 0;
95066 + __free_pages(sp, order);
95067 }
95068
95069 /*
95070 @@ -313,15 +317,15 @@ static void *slob_alloc(size_t size, gfp_t gfp, int align, int node)
95071
95072 /* Not enough space: must allocate a new page */
95073 if (!b) {
95074 - b = slob_new_pages(gfp & ~__GFP_ZERO, 0, node);
95075 - if (!b)
95076 + sp = slob_new_pages(gfp & ~__GFP_ZERO, 0, node);
95077 + if (!sp)
95078 return NULL;
95079 - sp = virt_to_page(b);
95080 - __SetPageSlab(sp);
95081 + b = page_address(sp);
95082
95083 spin_lock_irqsave(&slob_lock, flags);
95084 sp->units = SLOB_UNITS(PAGE_SIZE);
95085 sp->freelist = b;
95086 + sp->private = 0;
95087 INIT_LIST_HEAD(&sp->list);
95088 set_slob(b, SLOB_UNITS(PAGE_SIZE), b + SLOB_UNITS(PAGE_SIZE));
95089 set_slob_page_free(sp, slob_list);
95090 @@ -359,12 +363,15 @@ static void slob_free(void *block, int size)
95091 if (slob_page_free(sp))
95092 clear_slob_page_free(sp);
95093 spin_unlock_irqrestore(&slob_lock, flags);
95094 - __ClearPageSlab(sp);
95095 - page_mapcount_reset(sp);
95096 - slob_free_pages(b, 0);
95097 + slob_free_pages(sp, 0);
95098 return;
95099 }
95100
95101 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
95102 + if (pax_sanitize_slab)
95103 + memset(block, PAX_MEMORY_SANITIZE_VALUE, size);
95104 +#endif
95105 +
95106 if (!slob_page_free(sp)) {
95107 /* This slob page is about to become partially free. Easy! */
95108 sp->units = units;
95109 @@ -424,11 +431,10 @@ out:
95110 */
95111
95112 static __always_inline void *
95113 -__do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
95114 +__do_kmalloc_node_align(size_t size, gfp_t gfp, int node, unsigned long caller, int align)
95115 {
95116 - unsigned int *m;
95117 - int align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
95118 - void *ret;
95119 + slob_t *m;
95120 + void *ret = NULL;
95121
95122 gfp &= gfp_allowed_mask;
95123
95124 @@ -442,23 +448,41 @@ __do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
95125
95126 if (!m)
95127 return NULL;
95128 - *m = size;
95129 + BUILD_BUG_ON(ARCH_KMALLOC_MINALIGN < 2 * SLOB_UNIT);
95130 + BUILD_BUG_ON(ARCH_SLAB_MINALIGN < 2 * SLOB_UNIT);
95131 + m[0].units = size;
95132 + m[1].units = align;
95133 ret = (void *)m + align;
95134
95135 trace_kmalloc_node(caller, ret,
95136 size, size + align, gfp, node);
95137 } else {
95138 unsigned int order = get_order(size);
95139 + struct page *page;
95140
95141 if (likely(order))
95142 gfp |= __GFP_COMP;
95143 - ret = slob_new_pages(gfp, order, node);
95144 + page = slob_new_pages(gfp, order, node);
95145 + if (page) {
95146 + ret = page_address(page);
95147 + page->private = size;
95148 + }
95149
95150 trace_kmalloc_node(caller, ret,
95151 size, PAGE_SIZE << order, gfp, node);
95152 }
95153
95154 - kmemleak_alloc(ret, size, 1, gfp);
95155 + return ret;
95156 +}
95157 +
95158 +static __always_inline void *
95159 +__do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
95160 +{
95161 + int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
95162 + void *ret = __do_kmalloc_node_align(size, gfp, node, caller, align);
95163 +
95164 + if (!ZERO_OR_NULL_PTR(ret))
95165 + kmemleak_alloc(ret, size, 1, gfp);
95166 return ret;
95167 }
95168
95169 @@ -493,34 +517,112 @@ void kfree(const void *block)
95170 return;
95171 kmemleak_free(block);
95172
95173 + VM_BUG_ON(!virt_addr_valid(block));
95174 sp = virt_to_page(block);
95175 - if (PageSlab(sp)) {
95176 + VM_BUG_ON(!PageSlab(sp));
95177 + if (!sp->private) {
95178 int align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
95179 - unsigned int *m = (unsigned int *)(block - align);
95180 - slob_free(m, *m + align);
95181 - } else
95182 + slob_t *m = (slob_t *)(block - align);
95183 + slob_free(m, m[0].units + align);
95184 + } else {
95185 + __ClearPageSlab(sp);
95186 + page_mapcount_reset(sp);
95187 + sp->private = 0;
95188 __free_pages(sp, compound_order(sp));
95189 + }
95190 }
95191 EXPORT_SYMBOL(kfree);
95192
95193 +bool is_usercopy_object(const void *ptr)
95194 +{
95195 + if (!slab_is_available())
95196 + return false;
95197 +
95198 + // PAX: TODO
95199 +
95200 + return false;
95201 +}
95202 +
95203 +#ifdef CONFIG_PAX_USERCOPY
95204 +const char *check_heap_object(const void *ptr, unsigned long n)
95205 +{
95206 + struct page *page;
95207 + const slob_t *free;
95208 + const void *base;
95209 + unsigned long flags;
95210 +
95211 + if (ZERO_OR_NULL_PTR(ptr))
95212 + return "<null>";
95213 +
95214 + if (!virt_addr_valid(ptr))
95215 + return NULL;
95216 +
95217 + page = virt_to_head_page(ptr);
95218 + if (!PageSlab(page))
95219 + return NULL;
95220 +
95221 + if (page->private) {
95222 + base = page;
95223 + if (base <= ptr && n <= page->private - (ptr - base))
95224 + return NULL;
95225 + return "<slob>";
95226 + }
95227 +
95228 + /* some tricky double walking to find the chunk */
95229 + spin_lock_irqsave(&slob_lock, flags);
95230 + base = (void *)((unsigned long)ptr & PAGE_MASK);
95231 + free = page->freelist;
95232 +
95233 + while (!slob_last(free) && (void *)free <= ptr) {
95234 + base = free + slob_units(free);
95235 + free = slob_next(free);
95236 + }
95237 +
95238 + while (base < (void *)free) {
95239 + slobidx_t m = ((slob_t *)base)[0].units, align = ((slob_t *)base)[1].units;
95240 + int size = SLOB_UNIT * SLOB_UNITS(m + align);
95241 + int offset;
95242 +
95243 + if (ptr < base + align)
95244 + break;
95245 +
95246 + offset = ptr - base - align;
95247 + if (offset >= m) {
95248 + base += size;
95249 + continue;
95250 + }
95251 +
95252 + if (n > m - offset)
95253 + break;
95254 +
95255 + spin_unlock_irqrestore(&slob_lock, flags);
95256 + return NULL;
95257 + }
95258 +
95259 + spin_unlock_irqrestore(&slob_lock, flags);
95260 + return "<slob>";
95261 +}
95262 +#endif
95263 +
95264 /* can't use ksize for kmem_cache_alloc memory, only kmalloc */
95265 size_t ksize(const void *block)
95266 {
95267 struct page *sp;
95268 int align;
95269 - unsigned int *m;
95270 + slob_t *m;
95271
95272 BUG_ON(!block);
95273 if (unlikely(block == ZERO_SIZE_PTR))
95274 return 0;
95275
95276 sp = virt_to_page(block);
95277 - if (unlikely(!PageSlab(sp)))
95278 - return PAGE_SIZE << compound_order(sp);
95279 + VM_BUG_ON(!PageSlab(sp));
95280 + if (sp->private)
95281 + return sp->private;
95282
95283 align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
95284 - m = (unsigned int *)(block - align);
95285 - return SLOB_UNITS(*m) * SLOB_UNIT;
95286 + m = (slob_t *)(block - align);
95287 + return SLOB_UNITS(m[0].units) * SLOB_UNIT;
95288 }
95289 EXPORT_SYMBOL(ksize);
95290
95291 @@ -536,23 +638,33 @@ int __kmem_cache_create(struct kmem_cache *c, unsigned long flags)
95292
95293 void *slob_alloc_node(struct kmem_cache *c, gfp_t flags, int node)
95294 {
95295 - void *b;
95296 + void *b = NULL;
95297
95298 flags &= gfp_allowed_mask;
95299
95300 lockdep_trace_alloc(flags);
95301
95302 +#ifdef CONFIG_PAX_USERCOPY_SLABS
95303 + b = __do_kmalloc_node_align(c->size, flags, node, _RET_IP_, c->align);
95304 +#else
95305 if (c->size < PAGE_SIZE) {
95306 b = slob_alloc(c->size, flags, c->align, node);
95307 trace_kmem_cache_alloc_node(_RET_IP_, b, c->object_size,
95308 SLOB_UNITS(c->size) * SLOB_UNIT,
95309 flags, node);
95310 } else {
95311 - b = slob_new_pages(flags, get_order(c->size), node);
95312 + struct page *sp;
95313 +
95314 + sp = slob_new_pages(flags, get_order(c->size), node);
95315 + if (sp) {
95316 + b = page_address(sp);
95317 + sp->private = c->size;
95318 + }
95319 trace_kmem_cache_alloc_node(_RET_IP_, b, c->object_size,
95320 PAGE_SIZE << get_order(c->size),
95321 flags, node);
95322 }
95323 +#endif
95324
95325 if (b && c->ctor)
95326 c->ctor(b);
95327 @@ -584,10 +696,14 @@ EXPORT_SYMBOL(kmem_cache_alloc_node);
95328
95329 static void __kmem_cache_free(void *b, int size)
95330 {
95331 - if (size < PAGE_SIZE)
95332 + struct page *sp;
95333 +
95334 + sp = virt_to_page(b);
95335 + BUG_ON(!PageSlab(sp));
95336 + if (!sp->private)
95337 slob_free(b, size);
95338 else
95339 - slob_free_pages(b, get_order(size));
95340 + slob_free_pages(sp, get_order(size));
95341 }
95342
95343 static void kmem_rcu_free(struct rcu_head *head)
95344 @@ -600,17 +716,31 @@ static void kmem_rcu_free(struct rcu_head *head)
95345
95346 void kmem_cache_free(struct kmem_cache *c, void *b)
95347 {
95348 + int size = c->size;
95349 +
95350 +#ifdef CONFIG_PAX_USERCOPY_SLABS
95351 + if (size + c->align < PAGE_SIZE) {
95352 + size += c->align;
95353 + b -= c->align;
95354 + }
95355 +#endif
95356 +
95357 kmemleak_free_recursive(b, c->flags);
95358 if (unlikely(c->flags & SLAB_DESTROY_BY_RCU)) {
95359 struct slob_rcu *slob_rcu;
95360 - slob_rcu = b + (c->size - sizeof(struct slob_rcu));
95361 - slob_rcu->size = c->size;
95362 + slob_rcu = b + (size - sizeof(struct slob_rcu));
95363 + slob_rcu->size = size;
95364 call_rcu(&slob_rcu->head, kmem_rcu_free);
95365 } else {
95366 - __kmem_cache_free(b, c->size);
95367 + __kmem_cache_free(b, size);
95368 }
95369
95370 +#ifdef CONFIG_PAX_USERCOPY_SLABS
95371 + trace_kfree(_RET_IP_, b);
95372 +#else
95373 trace_kmem_cache_free(_RET_IP_, b);
95374 +#endif
95375 +
95376 }
95377 EXPORT_SYMBOL(kmem_cache_free);
95378
95379 diff --git a/mm/slub.c b/mm/slub.c
95380 index 89490d9..c7b226a 100644
95381 --- a/mm/slub.c
95382 +++ b/mm/slub.c
95383 @@ -207,7 +207,7 @@ struct track {
95384
95385 enum track_item { TRACK_ALLOC, TRACK_FREE };
95386
95387 -#ifdef CONFIG_SYSFS
95388 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
95389 static int sysfs_slab_add(struct kmem_cache *);
95390 static int sysfs_slab_alias(struct kmem_cache *, const char *);
95391 static void sysfs_slab_remove(struct kmem_cache *);
95392 @@ -530,7 +530,7 @@ static void print_track(const char *s, struct track *t)
95393 if (!t->addr)
95394 return;
95395
95396 - printk(KERN_ERR "INFO: %s in %pS age=%lu cpu=%u pid=%d\n",
95397 + printk(KERN_ERR "INFO: %s in %pA age=%lu cpu=%u pid=%d\n",
95398 s, (void *)t->addr, jiffies - t->when, t->cpu, t->pid);
95399 #ifdef CONFIG_STACKTRACE
95400 {
95401 @@ -2643,6 +2643,14 @@ static __always_inline void slab_free(struct kmem_cache *s,
95402
95403 slab_free_hook(s, x);
95404
95405 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
95406 + if (pax_sanitize_slab && !(s->flags & SLAB_NO_SANITIZE)) {
95407 + memset(x, PAX_MEMORY_SANITIZE_VALUE, s->object_size);
95408 + if (s->ctor)
95409 + s->ctor(x);
95410 + }
95411 +#endif
95412 +
95413 redo:
95414 /*
95415 * Determine the currently cpus per cpu slab.
95416 @@ -2710,7 +2718,7 @@ static int slub_min_objects;
95417 * Merge control. If this is set then no merging of slab caches will occur.
95418 * (Could be removed. This was introduced to pacify the merge skeptics.)
95419 */
95420 -static int slub_nomerge;
95421 +static int slub_nomerge = 1;
95422
95423 /*
95424 * Calculate the order of allocation given an slab object size.
95425 @@ -2987,6 +2995,9 @@ static int calculate_sizes(struct kmem_cache *s, int forced_order)
95426 s->inuse = size;
95427
95428 if (((flags & (SLAB_DESTROY_BY_RCU | SLAB_POISON)) ||
95429 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
95430 + (pax_sanitize_slab && !(flags & SLAB_NO_SANITIZE)) ||
95431 +#endif
95432 s->ctor)) {
95433 /*
95434 * Relocate free pointer after the object if it is not
95435 @@ -3332,6 +3343,59 @@ void *__kmalloc_node(size_t size, gfp_t flags, int node)
95436 EXPORT_SYMBOL(__kmalloc_node);
95437 #endif
95438
95439 +bool is_usercopy_object(const void *ptr)
95440 +{
95441 + struct page *page;
95442 + struct kmem_cache *s;
95443 +
95444 + if (ZERO_OR_NULL_PTR(ptr))
95445 + return false;
95446 +
95447 + if (!slab_is_available())
95448 + return false;
95449 +
95450 + if (!virt_addr_valid(ptr))
95451 + return false;
95452 +
95453 + page = virt_to_head_page(ptr);
95454 +
95455 + if (!PageSlab(page))
95456 + return false;
95457 +
95458 + s = page->slab_cache;
95459 + return s->flags & SLAB_USERCOPY;
95460 +}
95461 +
95462 +#ifdef CONFIG_PAX_USERCOPY
95463 +const char *check_heap_object(const void *ptr, unsigned long n)
95464 +{
95465 + struct page *page;
95466 + struct kmem_cache *s;
95467 + unsigned long offset;
95468 +
95469 + if (ZERO_OR_NULL_PTR(ptr))
95470 + return "<null>";
95471 +
95472 + if (!virt_addr_valid(ptr))
95473 + return NULL;
95474 +
95475 + page = virt_to_head_page(ptr);
95476 +
95477 + if (!PageSlab(page))
95478 + return NULL;
95479 +
95480 + s = page->slab_cache;
95481 + if (!(s->flags & SLAB_USERCOPY))
95482 + return s->name;
95483 +
95484 + offset = (ptr - page_address(page)) % s->size;
95485 + if (offset <= s->object_size && n <= s->object_size - offset)
95486 + return NULL;
95487 +
95488 + return s->name;
95489 +}
95490 +#endif
95491 +
95492 size_t ksize(const void *object)
95493 {
95494 struct page *page;
95495 @@ -3360,6 +3424,7 @@ void kfree(const void *x)
95496 if (unlikely(ZERO_OR_NULL_PTR(x)))
95497 return;
95498
95499 + VM_BUG_ON(!virt_addr_valid(x));
95500 page = virt_to_head_page(x);
95501 if (unlikely(!PageSlab(page))) {
95502 BUG_ON(!PageCompound(page));
95503 @@ -3665,7 +3730,7 @@ static int slab_unmergeable(struct kmem_cache *s)
95504 /*
95505 * We may have set a slab to be unmergeable during bootstrap.
95506 */
95507 - if (s->refcount < 0)
95508 + if (atomic_read(&s->refcount) < 0)
95509 return 1;
95510
95511 return 0;
95512 @@ -3723,7 +3788,7 @@ __kmem_cache_alias(struct mem_cgroup *memcg, const char *name, size_t size,
95513
95514 s = find_mergeable(memcg, size, align, flags, name, ctor);
95515 if (s) {
95516 - s->refcount++;
95517 + atomic_inc(&s->refcount);
95518 /*
95519 * Adjust the object sizes so that we clear
95520 * the complete object on kzalloc.
95521 @@ -3732,7 +3797,7 @@ __kmem_cache_alias(struct mem_cgroup *memcg, const char *name, size_t size,
95522 s->inuse = max_t(int, s->inuse, ALIGN(size, sizeof(void *)));
95523
95524 if (sysfs_slab_alias(s, name)) {
95525 - s->refcount--;
95526 + atomic_dec(&s->refcount);
95527 s = NULL;
95528 }
95529 }
95530 @@ -3852,7 +3917,7 @@ void *__kmalloc_node_track_caller(size_t size, gfp_t gfpflags,
95531 }
95532 #endif
95533
95534 -#ifdef CONFIG_SYSFS
95535 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
95536 static int count_inuse(struct page *page)
95537 {
95538 return page->inuse;
95539 @@ -4241,12 +4306,12 @@ static void resiliency_test(void)
95540 validate_slab_cache(kmalloc_caches[9]);
95541 }
95542 #else
95543 -#ifdef CONFIG_SYSFS
95544 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
95545 static void resiliency_test(void) {};
95546 #endif
95547 #endif
95548
95549 -#ifdef CONFIG_SYSFS
95550 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
95551 enum slab_stat_type {
95552 SL_ALL, /* All slabs */
95553 SL_PARTIAL, /* Only partially allocated slabs */
95554 @@ -4492,7 +4557,7 @@ SLAB_ATTR_RO(ctor);
95555
95556 static ssize_t aliases_show(struct kmem_cache *s, char *buf)
95557 {
95558 - return sprintf(buf, "%d\n", s->refcount - 1);
95559 + return sprintf(buf, "%d\n", atomic_read(&s->refcount) - 1);
95560 }
95561 SLAB_ATTR_RO(aliases);
95562
95563 @@ -4580,6 +4645,14 @@ static ssize_t cache_dma_show(struct kmem_cache *s, char *buf)
95564 SLAB_ATTR_RO(cache_dma);
95565 #endif
95566
95567 +#ifdef CONFIG_PAX_USERCOPY_SLABS
95568 +static ssize_t usercopy_show(struct kmem_cache *s, char *buf)
95569 +{
95570 + return sprintf(buf, "%d\n", !!(s->flags & SLAB_USERCOPY));
95571 +}
95572 +SLAB_ATTR_RO(usercopy);
95573 +#endif
95574 +
95575 static ssize_t destroy_by_rcu_show(struct kmem_cache *s, char *buf)
95576 {
95577 return sprintf(buf, "%d\n", !!(s->flags & SLAB_DESTROY_BY_RCU));
95578 @@ -4914,6 +4987,9 @@ static struct attribute *slab_attrs[] = {
95579 #ifdef CONFIG_ZONE_DMA
95580 &cache_dma_attr.attr,
95581 #endif
95582 +#ifdef CONFIG_PAX_USERCOPY_SLABS
95583 + &usercopy_attr.attr,
95584 +#endif
95585 #ifdef CONFIG_NUMA
95586 &remote_node_defrag_ratio_attr.attr,
95587 #endif
95588 @@ -5146,6 +5222,7 @@ static char *create_unique_id(struct kmem_cache *s)
95589 return name;
95590 }
95591
95592 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
95593 static int sysfs_slab_add(struct kmem_cache *s)
95594 {
95595 int err;
95596 @@ -5169,7 +5246,7 @@ static int sysfs_slab_add(struct kmem_cache *s)
95597 }
95598
95599 s->kobj.kset = slab_kset;
95600 - err = kobject_init_and_add(&s->kobj, &slab_ktype, NULL, name);
95601 + err = kobject_init_and_add(&s->kobj, &slab_ktype, NULL, "%s", name);
95602 if (err) {
95603 kobject_put(&s->kobj);
95604 return err;
95605 @@ -5203,6 +5280,7 @@ static void sysfs_slab_remove(struct kmem_cache *s)
95606 kobject_del(&s->kobj);
95607 kobject_put(&s->kobj);
95608 }
95609 +#endif
95610
95611 /*
95612 * Need to buffer aliases during bootup until sysfs becomes
95613 @@ -5216,6 +5294,7 @@ struct saved_alias {
95614
95615 static struct saved_alias *alias_list;
95616
95617 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
95618 static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
95619 {
95620 struct saved_alias *al;
95621 @@ -5238,6 +5317,7 @@ static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
95622 alias_list = al;
95623 return 0;
95624 }
95625 +#endif
95626
95627 static int __init slab_sysfs_init(void)
95628 {
95629 diff --git a/mm/sparse-vmemmap.c b/mm/sparse-vmemmap.c
95630 index 27eeab3..7c3f7f2 100644
95631 --- a/mm/sparse-vmemmap.c
95632 +++ b/mm/sparse-vmemmap.c
95633 @@ -130,7 +130,7 @@ pud_t * __meminit vmemmap_pud_populate(pgd_t *pgd, unsigned long addr, int node)
95634 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
95635 if (!p)
95636 return NULL;
95637 - pud_populate(&init_mm, pud, p);
95638 + pud_populate_kernel(&init_mm, pud, p);
95639 }
95640 return pud;
95641 }
95642 @@ -142,7 +142,7 @@ pgd_t * __meminit vmemmap_pgd_populate(unsigned long addr, int node)
95643 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
95644 if (!p)
95645 return NULL;
95646 - pgd_populate(&init_mm, pgd, p);
95647 + pgd_populate_kernel(&init_mm, pgd, p);
95648 }
95649 return pgd;
95650 }
95651 diff --git a/mm/sparse.c b/mm/sparse.c
95652 index 8cc7be0..d0f7d7a 100644
95653 --- a/mm/sparse.c
95654 +++ b/mm/sparse.c
95655 @@ -745,7 +745,7 @@ static void clear_hwpoisoned_pages(struct page *memmap, int nr_pages)
95656
95657 for (i = 0; i < PAGES_PER_SECTION; i++) {
95658 if (PageHWPoison(&memmap[i])) {
95659 - atomic_long_sub(1, &num_poisoned_pages);
95660 + atomic_long_sub_unchecked(1, &num_poisoned_pages);
95661 ClearPageHWPoison(&memmap[i]);
95662 }
95663 }
95664 diff --git a/mm/swap.c b/mm/swap.c
95665 index 7010cf4..f0a56a4 100644
95666 --- a/mm/swap.c
95667 +++ b/mm/swap.c
95668 @@ -77,6 +77,8 @@ static void __put_compound_page(struct page *page)
95669
95670 __page_cache_release(page);
95671 dtor = get_compound_page_dtor(page);
95672 + if (!PageHuge(page))
95673 + BUG_ON(dtor != free_compound_page);
95674 (*dtor)(page);
95675 }
95676
95677 diff --git a/mm/swapfile.c b/mm/swapfile.c
95678 index 461fce2..363ae44 100644
95679 --- a/mm/swapfile.c
95680 +++ b/mm/swapfile.c
95681 @@ -66,7 +66,7 @@ static DEFINE_MUTEX(swapon_mutex);
95682
95683 static DECLARE_WAIT_QUEUE_HEAD(proc_poll_wait);
95684 /* Activity counter to indicate that a swapon or swapoff has occurred */
95685 -static atomic_t proc_poll_event = ATOMIC_INIT(0);
95686 +static atomic_unchecked_t proc_poll_event = ATOMIC_INIT(0);
95687
95688 static inline unsigned char swap_count(unsigned char ent)
95689 {
95690 @@ -1958,7 +1958,7 @@ SYSCALL_DEFINE1(swapoff, const char __user *, specialfile)
95691 spin_unlock(&swap_lock);
95692
95693 err = 0;
95694 - atomic_inc(&proc_poll_event);
95695 + atomic_inc_unchecked(&proc_poll_event);
95696 wake_up_interruptible(&proc_poll_wait);
95697
95698 out_dput:
95699 @@ -1975,8 +1975,8 @@ static unsigned swaps_poll(struct file *file, poll_table *wait)
95700
95701 poll_wait(file, &proc_poll_wait, wait);
95702
95703 - if (seq->poll_event != atomic_read(&proc_poll_event)) {
95704 - seq->poll_event = atomic_read(&proc_poll_event);
95705 + if (seq->poll_event != atomic_read_unchecked(&proc_poll_event)) {
95706 + seq->poll_event = atomic_read_unchecked(&proc_poll_event);
95707 return POLLIN | POLLRDNORM | POLLERR | POLLPRI;
95708 }
95709
95710 @@ -2074,7 +2074,7 @@ static int swaps_open(struct inode *inode, struct file *file)
95711 return ret;
95712
95713 seq = file->private_data;
95714 - seq->poll_event = atomic_read(&proc_poll_event);
95715 + seq->poll_event = atomic_read_unchecked(&proc_poll_event);
95716 return 0;
95717 }
95718
95719 @@ -2533,7 +2533,7 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags)
95720 (frontswap_map) ? "FS" : "");
95721
95722 mutex_unlock(&swapon_mutex);
95723 - atomic_inc(&proc_poll_event);
95724 + atomic_inc_unchecked(&proc_poll_event);
95725 wake_up_interruptible(&proc_poll_wait);
95726
95727 if (S_ISREG(inode->i_mode))
95728 diff --git a/mm/util.c b/mm/util.c
95729 index 808f375..e4764b5 100644
95730 --- a/mm/util.c
95731 +++ b/mm/util.c
95732 @@ -297,6 +297,12 @@ done:
95733 void arch_pick_mmap_layout(struct mm_struct *mm)
95734 {
95735 mm->mmap_base = TASK_UNMAPPED_BASE;
95736 +
95737 +#ifdef CONFIG_PAX_RANDMMAP
95738 + if (mm->pax_flags & MF_PAX_RANDMMAP)
95739 + mm->mmap_base += mm->delta_mmap;
95740 +#endif
95741 +
95742 mm->get_unmapped_area = arch_get_unmapped_area;
95743 }
95744 #endif
95745 diff --git a/mm/vmalloc.c b/mm/vmalloc.c
95746 index 0fdf968..d6686e8 100644
95747 --- a/mm/vmalloc.c
95748 +++ b/mm/vmalloc.c
95749 @@ -59,8 +59,19 @@ static void vunmap_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end)
95750
95751 pte = pte_offset_kernel(pmd, addr);
95752 do {
95753 - pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
95754 - WARN_ON(!pte_none(ptent) && !pte_present(ptent));
95755 +
95756 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
95757 + if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr < (unsigned long)MODULES_EXEC_END) {
95758 + BUG_ON(!pte_exec(*pte));
95759 + set_pte_at(&init_mm, addr, pte, pfn_pte(__pa(addr) >> PAGE_SHIFT, PAGE_KERNEL_EXEC));
95760 + continue;
95761 + }
95762 +#endif
95763 +
95764 + {
95765 + pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
95766 + WARN_ON(!pte_none(ptent) && !pte_present(ptent));
95767 + }
95768 } while (pte++, addr += PAGE_SIZE, addr != end);
95769 }
95770
95771 @@ -120,16 +131,29 @@ static int vmap_pte_range(pmd_t *pmd, unsigned long addr,
95772 pte = pte_alloc_kernel(pmd, addr);
95773 if (!pte)
95774 return -ENOMEM;
95775 +
95776 + pax_open_kernel();
95777 do {
95778 struct page *page = pages[*nr];
95779
95780 - if (WARN_ON(!pte_none(*pte)))
95781 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
95782 + if (pgprot_val(prot) & _PAGE_NX)
95783 +#endif
95784 +
95785 + if (!pte_none(*pte)) {
95786 + pax_close_kernel();
95787 + WARN_ON(1);
95788 return -EBUSY;
95789 - if (WARN_ON(!page))
95790 + }
95791 + if (!page) {
95792 + pax_close_kernel();
95793 + WARN_ON(1);
95794 return -ENOMEM;
95795 + }
95796 set_pte_at(&init_mm, addr, pte, mk_pte(page, prot));
95797 (*nr)++;
95798 } while (pte++, addr += PAGE_SIZE, addr != end);
95799 + pax_close_kernel();
95800 return 0;
95801 }
95802
95803 @@ -139,7 +163,7 @@ static int vmap_pmd_range(pud_t *pud, unsigned long addr,
95804 pmd_t *pmd;
95805 unsigned long next;
95806
95807 - pmd = pmd_alloc(&init_mm, pud, addr);
95808 + pmd = pmd_alloc_kernel(&init_mm, pud, addr);
95809 if (!pmd)
95810 return -ENOMEM;
95811 do {
95812 @@ -156,7 +180,7 @@ static int vmap_pud_range(pgd_t *pgd, unsigned long addr,
95813 pud_t *pud;
95814 unsigned long next;
95815
95816 - pud = pud_alloc(&init_mm, pgd, addr);
95817 + pud = pud_alloc_kernel(&init_mm, pgd, addr);
95818 if (!pud)
95819 return -ENOMEM;
95820 do {
95821 @@ -216,6 +240,12 @@ int is_vmalloc_or_module_addr(const void *x)
95822 if (addr >= MODULES_VADDR && addr < MODULES_END)
95823 return 1;
95824 #endif
95825 +
95826 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
95827 + if (x >= (const void *)MODULES_EXEC_VADDR && x < (const void *)MODULES_EXEC_END)
95828 + return 1;
95829 +#endif
95830 +
95831 return is_vmalloc_addr(x);
95832 }
95833
95834 @@ -236,8 +266,14 @@ struct page *vmalloc_to_page(const void *vmalloc_addr)
95835
95836 if (!pgd_none(*pgd)) {
95837 pud_t *pud = pud_offset(pgd, addr);
95838 +#ifdef CONFIG_X86
95839 + if (!pud_large(*pud))
95840 +#endif
95841 if (!pud_none(*pud)) {
95842 pmd_t *pmd = pmd_offset(pud, addr);
95843 +#ifdef CONFIG_X86
95844 + if (!pmd_large(*pmd))
95845 +#endif
95846 if (!pmd_none(*pmd)) {
95847 pte_t *ptep, pte;
95848
95849 @@ -1309,6 +1345,16 @@ static struct vm_struct *__get_vm_area_node(unsigned long size,
95850 struct vm_struct *area;
95851
95852 BUG_ON(in_interrupt());
95853 +
95854 +#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
95855 + if (flags & VM_KERNEXEC) {
95856 + if (start != VMALLOC_START || end != VMALLOC_END)
95857 + return NULL;
95858 + start = (unsigned long)MODULES_EXEC_VADDR;
95859 + end = (unsigned long)MODULES_EXEC_END;
95860 + }
95861 +#endif
95862 +
95863 if (flags & VM_IOREMAP)
95864 align = 1ul << clamp(fls(size), PAGE_SHIFT, IOREMAP_MAX_ORDER);
95865
95866 @@ -1534,6 +1580,11 @@ void *vmap(struct page **pages, unsigned int count,
95867 if (count > totalram_pages)
95868 return NULL;
95869
95870 +#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
95871 + if (!(pgprot_val(prot) & _PAGE_NX))
95872 + flags |= VM_KERNEXEC;
95873 +#endif
95874 +
95875 area = get_vm_area_caller((count << PAGE_SHIFT), flags,
95876 __builtin_return_address(0));
95877 if (!area)
95878 @@ -1634,6 +1685,13 @@ void *__vmalloc_node_range(unsigned long size, unsigned long align,
95879 if (!size || (size >> PAGE_SHIFT) > totalram_pages)
95880 goto fail;
95881
95882 +#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
95883 + if (!(pgprot_val(prot) & _PAGE_NX))
95884 + area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNINITIALIZED | VM_KERNEXEC,
95885 + VMALLOC_START, VMALLOC_END, node, gfp_mask, caller);
95886 + else
95887 +#endif
95888 +
95889 area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNINITIALIZED,
95890 start, end, node, gfp_mask, caller);
95891 if (!area)
95892 @@ -1810,10 +1868,9 @@ EXPORT_SYMBOL(vzalloc_node);
95893 * For tight control over page level allocator and protection flags
95894 * use __vmalloc() instead.
95895 */
95896 -
95897 void *vmalloc_exec(unsigned long size)
95898 {
95899 - return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
95900 + return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, PAGE_KERNEL_EXEC,
95901 NUMA_NO_NODE, __builtin_return_address(0));
95902 }
95903
95904 @@ -2120,6 +2177,8 @@ int remap_vmalloc_range_partial(struct vm_area_struct *vma, unsigned long uaddr,
95905 {
95906 struct vm_struct *area;
95907
95908 + BUG_ON(vma->vm_mirror);
95909 +
95910 size = PAGE_ALIGN(size);
95911
95912 if (!PAGE_ALIGNED(uaddr) || !PAGE_ALIGNED(kaddr))
95913 @@ -2602,7 +2661,11 @@ static int s_show(struct seq_file *m, void *p)
95914 v->addr, v->addr + v->size, v->size);
95915
95916 if (v->caller)
95917 +#ifdef CONFIG_GRKERNSEC_HIDESYM
95918 + seq_printf(m, " %pK", v->caller);
95919 +#else
95920 seq_printf(m, " %pS", v->caller);
95921 +#endif
95922
95923 if (v->nr_pages)
95924 seq_printf(m, " pages=%d", v->nr_pages);
95925 diff --git a/mm/vmstat.c b/mm/vmstat.c
95926 index 7249614..2639fc7 100644
95927 --- a/mm/vmstat.c
95928 +++ b/mm/vmstat.c
95929 @@ -20,6 +20,7 @@
95930 #include <linux/writeback.h>
95931 #include <linux/compaction.h>
95932 #include <linux/mm_inline.h>
95933 +#include <linux/grsecurity.h>
95934
95935 #include "internal.h"
95936
95937 @@ -79,7 +80,7 @@ void vm_events_fold_cpu(int cpu)
95938 *
95939 * vm_stat contains the global counters
95940 */
95941 -atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
95942 +atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
95943 EXPORT_SYMBOL(vm_stat);
95944
95945 #ifdef CONFIG_SMP
95946 @@ -423,7 +424,7 @@ static inline void fold_diff(int *diff)
95947
95948 for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++)
95949 if (diff[i])
95950 - atomic_long_add(diff[i], &vm_stat[i]);
95951 + atomic_long_add_unchecked(diff[i], &vm_stat[i]);
95952 }
95953
95954 /*
95955 @@ -455,7 +456,7 @@ static void refresh_cpu_vm_stats(void)
95956 v = this_cpu_xchg(p->vm_stat_diff[i], 0);
95957 if (v) {
95958
95959 - atomic_long_add(v, &zone->vm_stat[i]);
95960 + atomic_long_add_unchecked(v, &zone->vm_stat[i]);
95961 global_diff[i] += v;
95962 #ifdef CONFIG_NUMA
95963 /* 3 seconds idle till flush */
95964 @@ -517,7 +518,7 @@ void cpu_vm_stats_fold(int cpu)
95965
95966 v = p->vm_stat_diff[i];
95967 p->vm_stat_diff[i] = 0;
95968 - atomic_long_add(v, &zone->vm_stat[i]);
95969 + atomic_long_add_unchecked(v, &zone->vm_stat[i]);
95970 global_diff[i] += v;
95971 }
95972 }
95973 @@ -537,8 +538,8 @@ void drain_zonestat(struct zone *zone, struct per_cpu_pageset *pset)
95974 if (pset->vm_stat_diff[i]) {
95975 int v = pset->vm_stat_diff[i];
95976 pset->vm_stat_diff[i] = 0;
95977 - atomic_long_add(v, &zone->vm_stat[i]);
95978 - atomic_long_add(v, &vm_stat[i]);
95979 + atomic_long_add_unchecked(v, &zone->vm_stat[i]);
95980 + atomic_long_add_unchecked(v, &vm_stat[i]);
95981 }
95982 }
95983 #endif
95984 @@ -1148,10 +1149,22 @@ static void *vmstat_start(struct seq_file *m, loff_t *pos)
95985 stat_items_size += sizeof(struct vm_event_state);
95986 #endif
95987
95988 - v = kmalloc(stat_items_size, GFP_KERNEL);
95989 + v = kzalloc(stat_items_size, GFP_KERNEL);
95990 m->private = v;
95991 if (!v)
95992 return ERR_PTR(-ENOMEM);
95993 +
95994 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
95995 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
95996 + if (!uid_eq(current_uid(), GLOBAL_ROOT_UID)
95997 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
95998 + && !in_group_p(grsec_proc_gid)
95999 +#endif
96000 + )
96001 + return (unsigned long *)m->private + *pos;
96002 +#endif
96003 +#endif
96004 +
96005 for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++)
96006 v[i] = global_page_state(i);
96007 v += NR_VM_ZONE_STAT_ITEMS;
96008 @@ -1300,10 +1313,16 @@ static int __init setup_vmstat(void)
96009 put_online_cpus();
96010 #endif
96011 #ifdef CONFIG_PROC_FS
96012 - proc_create("buddyinfo", S_IRUGO, NULL, &fragmentation_file_operations);
96013 - proc_create("pagetypeinfo", S_IRUGO, NULL, &pagetypeinfo_file_ops);
96014 - proc_create("vmstat", S_IRUGO, NULL, &proc_vmstat_file_operations);
96015 - proc_create("zoneinfo", S_IRUGO, NULL, &proc_zoneinfo_file_operations);
96016 + {
96017 + mode_t gr_mode = S_IRUGO;
96018 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
96019 + gr_mode = S_IRUSR;
96020 +#endif
96021 + proc_create("buddyinfo", gr_mode, NULL, &fragmentation_file_operations);
96022 + proc_create("pagetypeinfo", gr_mode, NULL, &pagetypeinfo_file_ops);
96023 + proc_create("vmstat", S_IRUGO, NULL, &proc_vmstat_file_operations);
96024 + proc_create("zoneinfo", gr_mode, NULL, &proc_zoneinfo_file_operations);
96025 + }
96026 #endif
96027 return 0;
96028 }
96029 diff --git a/net/8021q/vlan.c b/net/8021q/vlan.c
96030 index 9a87f5a..67aeeb2 100644
96031 --- a/net/8021q/vlan.c
96032 +++ b/net/8021q/vlan.c
96033 @@ -474,7 +474,7 @@ out:
96034 return NOTIFY_DONE;
96035 }
96036
96037 -static struct notifier_block vlan_notifier_block __read_mostly = {
96038 +static struct notifier_block vlan_notifier_block = {
96039 .notifier_call = vlan_device_event,
96040 };
96041
96042 @@ -549,8 +549,7 @@ static int vlan_ioctl_handler(struct net *net, void __user *arg)
96043 err = -EPERM;
96044 if (!ns_capable(net->user_ns, CAP_NET_ADMIN))
96045 break;
96046 - if ((args.u.name_type >= 0) &&
96047 - (args.u.name_type < VLAN_NAME_TYPE_HIGHEST)) {
96048 + if (args.u.name_type < VLAN_NAME_TYPE_HIGHEST) {
96049 struct vlan_net *vn;
96050
96051 vn = net_generic(net, vlan_net_id);
96052 diff --git a/net/9p/client.c b/net/9p/client.c
96053 index ee8fd6b..0469d50 100644
96054 --- a/net/9p/client.c
96055 +++ b/net/9p/client.c
96056 @@ -588,7 +588,7 @@ static int p9_check_zc_errors(struct p9_client *c, struct p9_req_t *req,
96057 len - inline_len);
96058 } else {
96059 err = copy_from_user(ename + inline_len,
96060 - uidata, len - inline_len);
96061 + (char __force_user *)uidata, len - inline_len);
96062 if (err) {
96063 err = -EFAULT;
96064 goto out_err;
96065 @@ -1563,7 +1563,7 @@ p9_client_read(struct p9_fid *fid, char *data, char __user *udata, u64 offset,
96066 kernel_buf = 1;
96067 indata = data;
96068 } else
96069 - indata = (__force char *)udata;
96070 + indata = (__force_kernel char *)udata;
96071 /*
96072 * response header len is 11
96073 * PDU Header(7) + IO Size (4)
96074 @@ -1638,7 +1638,7 @@ p9_client_write(struct p9_fid *fid, char *data, const char __user *udata,
96075 kernel_buf = 1;
96076 odata = data;
96077 } else
96078 - odata = (char *)udata;
96079 + odata = (char __force_kernel *)udata;
96080 req = p9_client_zc_rpc(clnt, P9_TWRITE, NULL, odata, 0, rsize,
96081 P9_ZC_HDR_SZ, kernel_buf, "dqd",
96082 fid->fid, offset, rsize);
96083 diff --git a/net/9p/mod.c b/net/9p/mod.c
96084 index 6ab36ae..6f1841b 100644
96085 --- a/net/9p/mod.c
96086 +++ b/net/9p/mod.c
96087 @@ -84,7 +84,7 @@ static LIST_HEAD(v9fs_trans_list);
96088 void v9fs_register_trans(struct p9_trans_module *m)
96089 {
96090 spin_lock(&v9fs_trans_lock);
96091 - list_add_tail(&m->list, &v9fs_trans_list);
96092 + pax_list_add_tail((struct list_head *)&m->list, &v9fs_trans_list);
96093 spin_unlock(&v9fs_trans_lock);
96094 }
96095 EXPORT_SYMBOL(v9fs_register_trans);
96096 @@ -97,7 +97,7 @@ EXPORT_SYMBOL(v9fs_register_trans);
96097 void v9fs_unregister_trans(struct p9_trans_module *m)
96098 {
96099 spin_lock(&v9fs_trans_lock);
96100 - list_del_init(&m->list);
96101 + pax_list_del_init((struct list_head *)&m->list);
96102 spin_unlock(&v9fs_trans_lock);
96103 }
96104 EXPORT_SYMBOL(v9fs_unregister_trans);
96105 diff --git a/net/9p/trans_fd.c b/net/9p/trans_fd.c
96106 index 9321a77..ed2f256 100644
96107 --- a/net/9p/trans_fd.c
96108 +++ b/net/9p/trans_fd.c
96109 @@ -432,7 +432,7 @@ static int p9_fd_write(struct p9_client *client, void *v, int len)
96110 oldfs = get_fs();
96111 set_fs(get_ds());
96112 /* The cast to a user pointer is valid due to the set_fs() */
96113 - ret = vfs_write(ts->wr, (__force void __user *)v, len, &ts->wr->f_pos);
96114 + ret = vfs_write(ts->wr, (void __force_user *)v, len, &ts->wr->f_pos);
96115 set_fs(oldfs);
96116
96117 if (ret <= 0 && ret != -ERESTARTSYS && ret != -EAGAIN)
96118 diff --git a/net/atm/atm_misc.c b/net/atm/atm_misc.c
96119 index 876fbe8..8bbea9f 100644
96120 --- a/net/atm/atm_misc.c
96121 +++ b/net/atm/atm_misc.c
96122 @@ -17,7 +17,7 @@ int atm_charge(struct atm_vcc *vcc, int truesize)
96123 if (atomic_read(&sk_atm(vcc)->sk_rmem_alloc) <= sk_atm(vcc)->sk_rcvbuf)
96124 return 1;
96125 atm_return(vcc, truesize);
96126 - atomic_inc(&vcc->stats->rx_drop);
96127 + atomic_inc_unchecked(&vcc->stats->rx_drop);
96128 return 0;
96129 }
96130 EXPORT_SYMBOL(atm_charge);
96131 @@ -39,7 +39,7 @@ struct sk_buff *atm_alloc_charge(struct atm_vcc *vcc, int pdu_size,
96132 }
96133 }
96134 atm_return(vcc, guess);
96135 - atomic_inc(&vcc->stats->rx_drop);
96136 + atomic_inc_unchecked(&vcc->stats->rx_drop);
96137 return NULL;
96138 }
96139 EXPORT_SYMBOL(atm_alloc_charge);
96140 @@ -86,7 +86,7 @@ EXPORT_SYMBOL(atm_pcr_goal);
96141
96142 void sonet_copy_stats(struct k_sonet_stats *from, struct sonet_stats *to)
96143 {
96144 -#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
96145 +#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
96146 __SONET_ITEMS
96147 #undef __HANDLE_ITEM
96148 }
96149 @@ -94,7 +94,7 @@ EXPORT_SYMBOL(sonet_copy_stats);
96150
96151 void sonet_subtract_stats(struct k_sonet_stats *from, struct sonet_stats *to)
96152 {
96153 -#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
96154 +#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i,&from->i)
96155 __SONET_ITEMS
96156 #undef __HANDLE_ITEM
96157 }
96158 diff --git a/net/atm/lec.c b/net/atm/lec.c
96159 index f23916b..dd4d26b 100644
96160 --- a/net/atm/lec.c
96161 +++ b/net/atm/lec.c
96162 @@ -111,9 +111,9 @@ static inline void lec_arp_put(struct lec_arp_table *entry)
96163 }
96164
96165 static struct lane2_ops lane2_ops = {
96166 - lane2_resolve, /* resolve, spec 3.1.3 */
96167 - lane2_associate_req, /* associate_req, spec 3.1.4 */
96168 - NULL /* associate indicator, spec 3.1.5 */
96169 + .resolve = lane2_resolve,
96170 + .associate_req = lane2_associate_req,
96171 + .associate_indicator = NULL
96172 };
96173
96174 static unsigned char bus_mac[ETH_ALEN] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
96175 diff --git a/net/atm/lec.h b/net/atm/lec.h
96176 index 4149db1..f2ab682 100644
96177 --- a/net/atm/lec.h
96178 +++ b/net/atm/lec.h
96179 @@ -48,7 +48,7 @@ struct lane2_ops {
96180 const u8 *tlvs, u32 sizeoftlvs);
96181 void (*associate_indicator) (struct net_device *dev, const u8 *mac_addr,
96182 const u8 *tlvs, u32 sizeoftlvs);
96183 -};
96184 +} __no_const;
96185
96186 /*
96187 * ATM LAN Emulation supports both LLC & Dix Ethernet EtherType
96188 diff --git a/net/atm/mpoa_caches.c b/net/atm/mpoa_caches.c
96189 index d1b2d9a..d549f7f 100644
96190 --- a/net/atm/mpoa_caches.c
96191 +++ b/net/atm/mpoa_caches.c
96192 @@ -535,30 +535,30 @@ static void eg_destroy_cache(struct mpoa_client *mpc)
96193
96194
96195 static struct in_cache_ops ingress_ops = {
96196 - in_cache_add_entry, /* add_entry */
96197 - in_cache_get, /* get */
96198 - in_cache_get_with_mask, /* get_with_mask */
96199 - in_cache_get_by_vcc, /* get_by_vcc */
96200 - in_cache_put, /* put */
96201 - in_cache_remove_entry, /* remove_entry */
96202 - cache_hit, /* cache_hit */
96203 - clear_count_and_expired, /* clear_count */
96204 - check_resolving_entries, /* check_resolving */
96205 - refresh_entries, /* refresh */
96206 - in_destroy_cache /* destroy_cache */
96207 + .add_entry = in_cache_add_entry,
96208 + .get = in_cache_get,
96209 + .get_with_mask = in_cache_get_with_mask,
96210 + .get_by_vcc = in_cache_get_by_vcc,
96211 + .put = in_cache_put,
96212 + .remove_entry = in_cache_remove_entry,
96213 + .cache_hit = cache_hit,
96214 + .clear_count = clear_count_and_expired,
96215 + .check_resolving = check_resolving_entries,
96216 + .refresh = refresh_entries,
96217 + .destroy_cache = in_destroy_cache
96218 };
96219
96220 static struct eg_cache_ops egress_ops = {
96221 - eg_cache_add_entry, /* add_entry */
96222 - eg_cache_get_by_cache_id, /* get_by_cache_id */
96223 - eg_cache_get_by_tag, /* get_by_tag */
96224 - eg_cache_get_by_vcc, /* get_by_vcc */
96225 - eg_cache_get_by_src_ip, /* get_by_src_ip */
96226 - eg_cache_put, /* put */
96227 - eg_cache_remove_entry, /* remove_entry */
96228 - update_eg_cache_entry, /* update */
96229 - clear_expired, /* clear_expired */
96230 - eg_destroy_cache /* destroy_cache */
96231 + .add_entry = eg_cache_add_entry,
96232 + .get_by_cache_id = eg_cache_get_by_cache_id,
96233 + .get_by_tag = eg_cache_get_by_tag,
96234 + .get_by_vcc = eg_cache_get_by_vcc,
96235 + .get_by_src_ip = eg_cache_get_by_src_ip,
96236 + .put = eg_cache_put,
96237 + .remove_entry = eg_cache_remove_entry,
96238 + .update = update_eg_cache_entry,
96239 + .clear_expired = clear_expired,
96240 + .destroy_cache = eg_destroy_cache
96241 };
96242
96243
96244 diff --git a/net/atm/proc.c b/net/atm/proc.c
96245 index bbb6461..cf04016 100644
96246 --- a/net/atm/proc.c
96247 +++ b/net/atm/proc.c
96248 @@ -45,9 +45,9 @@ static void add_stats(struct seq_file *seq, const char *aal,
96249 const struct k_atm_aal_stats *stats)
96250 {
96251 seq_printf(seq, "%s ( %d %d %d %d %d )", aal,
96252 - atomic_read(&stats->tx), atomic_read(&stats->tx_err),
96253 - atomic_read(&stats->rx), atomic_read(&stats->rx_err),
96254 - atomic_read(&stats->rx_drop));
96255 + atomic_read_unchecked(&stats->tx),atomic_read_unchecked(&stats->tx_err),
96256 + atomic_read_unchecked(&stats->rx),atomic_read_unchecked(&stats->rx_err),
96257 + atomic_read_unchecked(&stats->rx_drop));
96258 }
96259
96260 static void atm_dev_info(struct seq_file *seq, const struct atm_dev *dev)
96261 diff --git a/net/atm/resources.c b/net/atm/resources.c
96262 index 0447d5d..3cf4728 100644
96263 --- a/net/atm/resources.c
96264 +++ b/net/atm/resources.c
96265 @@ -160,7 +160,7 @@ EXPORT_SYMBOL(atm_dev_deregister);
96266 static void copy_aal_stats(struct k_atm_aal_stats *from,
96267 struct atm_aal_stats *to)
96268 {
96269 -#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
96270 +#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
96271 __AAL_STAT_ITEMS
96272 #undef __HANDLE_ITEM
96273 }
96274 @@ -168,7 +168,7 @@ static void copy_aal_stats(struct k_atm_aal_stats *from,
96275 static void subtract_aal_stats(struct k_atm_aal_stats *from,
96276 struct atm_aal_stats *to)
96277 {
96278 -#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
96279 +#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i, &from->i)
96280 __AAL_STAT_ITEMS
96281 #undef __HANDLE_ITEM
96282 }
96283 diff --git a/net/ax25/sysctl_net_ax25.c b/net/ax25/sysctl_net_ax25.c
96284 index 919a5ce..cc6b444 100644
96285 --- a/net/ax25/sysctl_net_ax25.c
96286 +++ b/net/ax25/sysctl_net_ax25.c
96287 @@ -152,7 +152,7 @@ int ax25_register_dev_sysctl(ax25_dev *ax25_dev)
96288 {
96289 char path[sizeof("net/ax25/") + IFNAMSIZ];
96290 int k;
96291 - struct ctl_table *table;
96292 + ctl_table_no_const *table;
96293
96294 table = kmemdup(ax25_param_table, sizeof(ax25_param_table), GFP_KERNEL);
96295 if (!table)
96296 diff --git a/net/batman-adv/bat_iv_ogm.c b/net/batman-adv/bat_iv_ogm.c
96297 index f7270b9..cd0d879 100644
96298 --- a/net/batman-adv/bat_iv_ogm.c
96299 +++ b/net/batman-adv/bat_iv_ogm.c
96300 @@ -307,7 +307,7 @@ static int batadv_iv_ogm_iface_enable(struct batadv_hard_iface *hard_iface)
96301
96302 /* randomize initial seqno to avoid collision */
96303 get_random_bytes(&random_seqno, sizeof(random_seqno));
96304 - atomic_set(&hard_iface->bat_iv.ogm_seqno, random_seqno);
96305 + atomic_set_unchecked(&hard_iface->bat_iv.ogm_seqno, random_seqno);
96306
96307 hard_iface->bat_iv.ogm_buff_len = BATADV_OGM_HLEN;
96308 ogm_buff = kmalloc(hard_iface->bat_iv.ogm_buff_len, GFP_ATOMIC);
96309 @@ -894,9 +894,9 @@ static void batadv_iv_ogm_schedule(struct batadv_hard_iface *hard_iface)
96310 batadv_ogm_packet->tvlv_len = htons(tvlv_len);
96311
96312 /* change sequence number to network order */
96313 - seqno = (uint32_t)atomic_read(&hard_iface->bat_iv.ogm_seqno);
96314 + seqno = (uint32_t)atomic_read_unchecked(&hard_iface->bat_iv.ogm_seqno);
96315 batadv_ogm_packet->seqno = htonl(seqno);
96316 - atomic_inc(&hard_iface->bat_iv.ogm_seqno);
96317 + atomic_inc_unchecked(&hard_iface->bat_iv.ogm_seqno);
96318
96319 batadv_iv_ogm_slide_own_bcast_window(hard_iface);
96320 batadv_iv_ogm_queue_add(bat_priv, hard_iface->bat_iv.ogm_buff,
96321 @@ -1261,7 +1261,7 @@ static void batadv_iv_ogm_process(const struct ethhdr *ethhdr,
96322 return;
96323
96324 /* could be changed by schedule_own_packet() */
96325 - if_incoming_seqno = atomic_read(&if_incoming->bat_iv.ogm_seqno);
96326 + if_incoming_seqno = atomic_read_unchecked(&if_incoming->bat_iv.ogm_seqno);
96327
96328 if (batadv_ogm_packet->flags & BATADV_DIRECTLINK)
96329 has_directlink_flag = 1;
96330 diff --git a/net/batman-adv/fragmentation.c b/net/batman-adv/fragmentation.c
96331 index 6ddb614..ca7e886 100644
96332 --- a/net/batman-adv/fragmentation.c
96333 +++ b/net/batman-adv/fragmentation.c
96334 @@ -447,7 +447,7 @@ bool batadv_frag_send_packet(struct sk_buff *skb,
96335 frag_header.packet_type = BATADV_UNICAST_FRAG;
96336 frag_header.version = BATADV_COMPAT_VERSION;
96337 frag_header.ttl = BATADV_TTL;
96338 - frag_header.seqno = htons(atomic_inc_return(&bat_priv->frag_seqno));
96339 + frag_header.seqno = htons(atomic_inc_return_unchecked(&bat_priv->frag_seqno));
96340 frag_header.reserved = 0;
96341 frag_header.no = 0;
96342 frag_header.total_size = htons(skb->len);
96343 diff --git a/net/batman-adv/soft-interface.c b/net/batman-adv/soft-interface.c
96344 index a8f99d1..11797ef 100644
96345 --- a/net/batman-adv/soft-interface.c
96346 +++ b/net/batman-adv/soft-interface.c
96347 @@ -278,7 +278,7 @@ static int batadv_interface_tx(struct sk_buff *skb,
96348 primary_if->net_dev->dev_addr, ETH_ALEN);
96349
96350 /* set broadcast sequence number */
96351 - seqno = atomic_inc_return(&bat_priv->bcast_seqno);
96352 + seqno = atomic_inc_return_unchecked(&bat_priv->bcast_seqno);
96353 bcast_packet->seqno = htonl(seqno);
96354
96355 batadv_add_bcast_packet_to_list(bat_priv, skb, brd_delay);
96356 @@ -688,7 +688,7 @@ static int batadv_softif_init_late(struct net_device *dev)
96357 atomic_set(&bat_priv->batman_queue_left, BATADV_BATMAN_QUEUE_LEN);
96358
96359 atomic_set(&bat_priv->mesh_state, BATADV_MESH_INACTIVE);
96360 - atomic_set(&bat_priv->bcast_seqno, 1);
96361 + atomic_set_unchecked(&bat_priv->bcast_seqno, 1);
96362 atomic_set(&bat_priv->tt.vn, 0);
96363 atomic_set(&bat_priv->tt.local_changes, 0);
96364 atomic_set(&bat_priv->tt.ogm_append_cnt, 0);
96365 @@ -700,7 +700,7 @@ static int batadv_softif_init_late(struct net_device *dev)
96366
96367 /* randomize initial seqno to avoid collision */
96368 get_random_bytes(&random_seqno, sizeof(random_seqno));
96369 - atomic_set(&bat_priv->frag_seqno, random_seqno);
96370 + atomic_set_unchecked(&bat_priv->frag_seqno, random_seqno);
96371
96372 bat_priv->primary_if = NULL;
96373 bat_priv->num_ifaces = 0;
96374 diff --git a/net/batman-adv/types.h b/net/batman-adv/types.h
96375 index 91dd369..9c25750 100644
96376 --- a/net/batman-adv/types.h
96377 +++ b/net/batman-adv/types.h
96378 @@ -56,7 +56,7 @@
96379 struct batadv_hard_iface_bat_iv {
96380 unsigned char *ogm_buff;
96381 int ogm_buff_len;
96382 - atomic_t ogm_seqno;
96383 + atomic_unchecked_t ogm_seqno;
96384 };
96385
96386 /**
96387 @@ -673,7 +673,7 @@ struct batadv_priv {
96388 atomic_t bonding;
96389 atomic_t fragmentation;
96390 atomic_t packet_size_max;
96391 - atomic_t frag_seqno;
96392 + atomic_unchecked_t frag_seqno;
96393 #ifdef CONFIG_BATMAN_ADV_BLA
96394 atomic_t bridge_loop_avoidance;
96395 #endif
96396 @@ -687,7 +687,7 @@ struct batadv_priv {
96397 #ifdef CONFIG_BATMAN_ADV_DEBUG
96398 atomic_t log_level;
96399 #endif
96400 - atomic_t bcast_seqno;
96401 + atomic_unchecked_t bcast_seqno;
96402 atomic_t bcast_queue_left;
96403 atomic_t batman_queue_left;
96404 char num_ifaces;
96405 diff --git a/net/bluetooth/hci_sock.c b/net/bluetooth/hci_sock.c
96406 index 7552f9e..074ce29 100644
96407 --- a/net/bluetooth/hci_sock.c
96408 +++ b/net/bluetooth/hci_sock.c
96409 @@ -1052,7 +1052,7 @@ static int hci_sock_setsockopt(struct socket *sock, int level, int optname,
96410 uf.event_mask[1] = *((u32 *) f->event_mask + 1);
96411 }
96412
96413 - len = min_t(unsigned int, len, sizeof(uf));
96414 + len = min((size_t)len, sizeof(uf));
96415 if (copy_from_user(&uf, optval, len)) {
96416 err = -EFAULT;
96417 break;
96418 diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
96419 index 4af3821..f2ba46c 100644
96420 --- a/net/bluetooth/l2cap_core.c
96421 +++ b/net/bluetooth/l2cap_core.c
96422 @@ -3500,8 +3500,10 @@ static int l2cap_parse_conf_rsp(struct l2cap_chan *chan, void *rsp, int len,
96423 break;
96424
96425 case L2CAP_CONF_RFC:
96426 - if (olen == sizeof(rfc))
96427 - memcpy(&rfc, (void *)val, olen);
96428 + if (olen != sizeof(rfc))
96429 + break;
96430 +
96431 + memcpy(&rfc, (void *)val, olen);
96432
96433 if (test_bit(CONF_STATE2_DEVICE, &chan->conf_state) &&
96434 rfc.mode != chan->mode)
96435 diff --git a/net/bluetooth/l2cap_sock.c b/net/bluetooth/l2cap_sock.c
96436 index 7cc24d2..e83f531 100644
96437 --- a/net/bluetooth/l2cap_sock.c
96438 +++ b/net/bluetooth/l2cap_sock.c
96439 @@ -545,7 +545,8 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname,
96440 struct sock *sk = sock->sk;
96441 struct l2cap_chan *chan = l2cap_pi(sk)->chan;
96442 struct l2cap_options opts;
96443 - int len, err = 0;
96444 + int err = 0;
96445 + size_t len = optlen;
96446 u32 opt;
96447
96448 BT_DBG("sk %p", sk);
96449 @@ -567,7 +568,7 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname,
96450 opts.max_tx = chan->max_tx;
96451 opts.txwin_size = chan->tx_win;
96452
96453 - len = min_t(unsigned int, sizeof(opts), optlen);
96454 + len = min(sizeof(opts), len);
96455 if (copy_from_user((char *) &opts, optval, len)) {
96456 err = -EFAULT;
96457 break;
96458 @@ -647,7 +648,8 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
96459 struct bt_security sec;
96460 struct bt_power pwr;
96461 struct l2cap_conn *conn;
96462 - int len, err = 0;
96463 + int err = 0;
96464 + size_t len = optlen;
96465 u32 opt;
96466
96467 BT_DBG("sk %p", sk);
96468 @@ -670,7 +672,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
96469
96470 sec.level = BT_SECURITY_LOW;
96471
96472 - len = min_t(unsigned int, sizeof(sec), optlen);
96473 + len = min(sizeof(sec), len);
96474 if (copy_from_user((char *) &sec, optval, len)) {
96475 err = -EFAULT;
96476 break;
96477 @@ -770,7 +772,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
96478
96479 pwr.force_active = BT_POWER_FORCE_ACTIVE_ON;
96480
96481 - len = min_t(unsigned int, sizeof(pwr), optlen);
96482 + len = min(sizeof(pwr), len);
96483 if (copy_from_user((char *) &pwr, optval, len)) {
96484 err = -EFAULT;
96485 break;
96486 diff --git a/net/bluetooth/rfcomm/sock.c b/net/bluetooth/rfcomm/sock.c
96487 index 3c2d3e4..884855a 100644
96488 --- a/net/bluetooth/rfcomm/sock.c
96489 +++ b/net/bluetooth/rfcomm/sock.c
96490 @@ -672,7 +672,7 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, c
96491 struct sock *sk = sock->sk;
96492 struct bt_security sec;
96493 int err = 0;
96494 - size_t len;
96495 + size_t len = optlen;
96496 u32 opt;
96497
96498 BT_DBG("sk %p", sk);
96499 @@ -694,7 +694,7 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, c
96500
96501 sec.level = BT_SECURITY_LOW;
96502
96503 - len = min_t(unsigned int, sizeof(sec), optlen);
96504 + len = min(sizeof(sec), len);
96505 if (copy_from_user((char *) &sec, optval, len)) {
96506 err = -EFAULT;
96507 break;
96508 diff --git a/net/bluetooth/rfcomm/tty.c b/net/bluetooth/rfcomm/tty.c
96509 index 84fcf9f..e389b27 100644
96510 --- a/net/bluetooth/rfcomm/tty.c
96511 +++ b/net/bluetooth/rfcomm/tty.c
96512 @@ -684,7 +684,7 @@ static int rfcomm_tty_open(struct tty_struct *tty, struct file *filp)
96513 BT_DBG("tty %p id %d", tty, tty->index);
96514
96515 BT_DBG("dev %p dst %pMR channel %d opened %d", dev, &dev->dst,
96516 - dev->channel, dev->port.count);
96517 + dev->channel, atomic_read(&dev->port.count));
96518
96519 err = tty_port_open(&dev->port, tty, filp);
96520 if (err)
96521 @@ -707,7 +707,7 @@ static void rfcomm_tty_close(struct tty_struct *tty, struct file *filp)
96522 struct rfcomm_dev *dev = (struct rfcomm_dev *) tty->driver_data;
96523
96524 BT_DBG("tty %p dev %p dlc %p opened %d", tty, dev, dev->dlc,
96525 - dev->port.count);
96526 + atomic_read(&dev->port.count));
96527
96528 tty_port_close(&dev->port, tty, filp);
96529 }
96530 diff --git a/net/bridge/netfilter/ebtables.c b/net/bridge/netfilter/ebtables.c
96531 index ac78024..161a80c 100644
96532 --- a/net/bridge/netfilter/ebtables.c
96533 +++ b/net/bridge/netfilter/ebtables.c
96534 @@ -1525,7 +1525,7 @@ static int do_ebt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
96535 tmp.valid_hooks = t->table->valid_hooks;
96536 }
96537 mutex_unlock(&ebt_mutex);
96538 - if (copy_to_user(user, &tmp, *len) != 0){
96539 + if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0){
96540 BUGPRINT("c2u Didn't work\n");
96541 ret = -EFAULT;
96542 break;
96543 @@ -2331,7 +2331,7 @@ static int compat_do_ebt_get_ctl(struct sock *sk, int cmd,
96544 goto out;
96545 tmp.valid_hooks = t->valid_hooks;
96546
96547 - if (copy_to_user(user, &tmp, *len) != 0) {
96548 + if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
96549 ret = -EFAULT;
96550 break;
96551 }
96552 @@ -2342,7 +2342,7 @@ static int compat_do_ebt_get_ctl(struct sock *sk, int cmd,
96553 tmp.entries_size = t->table->entries_size;
96554 tmp.valid_hooks = t->table->valid_hooks;
96555
96556 - if (copy_to_user(user, &tmp, *len) != 0) {
96557 + if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
96558 ret = -EFAULT;
96559 break;
96560 }
96561 diff --git a/net/caif/cfctrl.c b/net/caif/cfctrl.c
96562 index 0f45522..dab651f 100644
96563 --- a/net/caif/cfctrl.c
96564 +++ b/net/caif/cfctrl.c
96565 @@ -10,6 +10,7 @@
96566 #include <linux/spinlock.h>
96567 #include <linux/slab.h>
96568 #include <linux/pkt_sched.h>
96569 +#include <linux/sched.h>
96570 #include <net/caif/caif_layer.h>
96571 #include <net/caif/cfpkt.h>
96572 #include <net/caif/cfctrl.h>
96573 @@ -43,8 +44,8 @@ struct cflayer *cfctrl_create(void)
96574 memset(&dev_info, 0, sizeof(dev_info));
96575 dev_info.id = 0xff;
96576 cfsrvl_init(&this->serv, 0, &dev_info, false);
96577 - atomic_set(&this->req_seq_no, 1);
96578 - atomic_set(&this->rsp_seq_no, 1);
96579 + atomic_set_unchecked(&this->req_seq_no, 1);
96580 + atomic_set_unchecked(&this->rsp_seq_no, 1);
96581 this->serv.layer.receive = cfctrl_recv;
96582 sprintf(this->serv.layer.name, "ctrl");
96583 this->serv.layer.ctrlcmd = cfctrl_ctrlcmd;
96584 @@ -130,8 +131,8 @@ static void cfctrl_insert_req(struct cfctrl *ctrl,
96585 struct cfctrl_request_info *req)
96586 {
96587 spin_lock_bh(&ctrl->info_list_lock);
96588 - atomic_inc(&ctrl->req_seq_no);
96589 - req->sequence_no = atomic_read(&ctrl->req_seq_no);
96590 + atomic_inc_unchecked(&ctrl->req_seq_no);
96591 + req->sequence_no = atomic_read_unchecked(&ctrl->req_seq_no);
96592 list_add_tail(&req->list, &ctrl->list);
96593 spin_unlock_bh(&ctrl->info_list_lock);
96594 }
96595 @@ -149,7 +150,7 @@ static struct cfctrl_request_info *cfctrl_remove_req(struct cfctrl *ctrl,
96596 if (p != first)
96597 pr_warn("Requests are not received in order\n");
96598
96599 - atomic_set(&ctrl->rsp_seq_no,
96600 + atomic_set_unchecked(&ctrl->rsp_seq_no,
96601 p->sequence_no);
96602 list_del(&p->list);
96603 goto out;
96604 diff --git a/net/can/af_can.c b/net/can/af_can.c
96605 index a27f8aa..67174a3 100644
96606 --- a/net/can/af_can.c
96607 +++ b/net/can/af_can.c
96608 @@ -863,7 +863,7 @@ static const struct net_proto_family can_family_ops = {
96609 };
96610
96611 /* notifier block for netdevice event */
96612 -static struct notifier_block can_netdev_notifier __read_mostly = {
96613 +static struct notifier_block can_netdev_notifier = {
96614 .notifier_call = can_notifier,
96615 };
96616
96617 diff --git a/net/can/gw.c b/net/can/gw.c
96618 index 3f9b0f3..fc6d4fa 100644
96619 --- a/net/can/gw.c
96620 +++ b/net/can/gw.c
96621 @@ -80,7 +80,6 @@ MODULE_PARM_DESC(max_hops,
96622 "default: " __stringify(CGW_DEFAULT_HOPS) ")");
96623
96624 static HLIST_HEAD(cgw_list);
96625 -static struct notifier_block notifier;
96626
96627 static struct kmem_cache *cgw_cache __read_mostly;
96628
96629 @@ -954,6 +953,10 @@ static int cgw_remove_job(struct sk_buff *skb, struct nlmsghdr *nlh)
96630 return err;
96631 }
96632
96633 +static struct notifier_block notifier = {
96634 + .notifier_call = cgw_notifier
96635 +};
96636 +
96637 static __init int cgw_module_init(void)
96638 {
96639 /* sanitize given module parameter */
96640 @@ -969,7 +972,6 @@ static __init int cgw_module_init(void)
96641 return -ENOMEM;
96642
96643 /* set notifier */
96644 - notifier.notifier_call = cgw_notifier;
96645 register_netdevice_notifier(&notifier);
96646
96647 if (__rtnl_register(PF_CAN, RTM_GETROUTE, NULL, cgw_dump_jobs, NULL)) {
96648 diff --git a/net/ceph/messenger.c b/net/ceph/messenger.c
96649 index 464303f..9c30218 100644
96650 --- a/net/ceph/messenger.c
96651 +++ b/net/ceph/messenger.c
96652 @@ -186,7 +186,7 @@ static void con_fault(struct ceph_connection *con);
96653 #define MAX_ADDR_STR_LEN 64 /* 54 is enough */
96654
96655 static char addr_str[ADDR_STR_COUNT][MAX_ADDR_STR_LEN];
96656 -static atomic_t addr_str_seq = ATOMIC_INIT(0);
96657 +static atomic_unchecked_t addr_str_seq = ATOMIC_INIT(0);
96658
96659 static struct page *zero_page; /* used in certain error cases */
96660
96661 @@ -197,7 +197,7 @@ const char *ceph_pr_addr(const struct sockaddr_storage *ss)
96662 struct sockaddr_in *in4 = (struct sockaddr_in *) ss;
96663 struct sockaddr_in6 *in6 = (struct sockaddr_in6 *) ss;
96664
96665 - i = atomic_inc_return(&addr_str_seq) & ADDR_STR_COUNT_MASK;
96666 + i = atomic_inc_return_unchecked(&addr_str_seq) & ADDR_STR_COUNT_MASK;
96667 s = addr_str[i];
96668
96669 switch (ss->ss_family) {
96670 diff --git a/net/compat.c b/net/compat.c
96671 index f50161f..94fa415 100644
96672 --- a/net/compat.c
96673 +++ b/net/compat.c
96674 @@ -73,9 +73,9 @@ int get_compat_msghdr(struct msghdr *kmsg, struct compat_msghdr __user *umsg)
96675 return -EFAULT;
96676 if (kmsg->msg_namelen > sizeof(struct sockaddr_storage))
96677 kmsg->msg_namelen = sizeof(struct sockaddr_storage);
96678 - kmsg->msg_name = compat_ptr(tmp1);
96679 - kmsg->msg_iov = compat_ptr(tmp2);
96680 - kmsg->msg_control = compat_ptr(tmp3);
96681 + kmsg->msg_name = (void __force_kernel *)compat_ptr(tmp1);
96682 + kmsg->msg_iov = (void __force_kernel *)compat_ptr(tmp2);
96683 + kmsg->msg_control = (void __force_kernel *)compat_ptr(tmp3);
96684 return 0;
96685 }
96686
96687 @@ -87,7 +87,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
96688
96689 if (kern_msg->msg_namelen) {
96690 if (mode == VERIFY_READ) {
96691 - int err = move_addr_to_kernel(kern_msg->msg_name,
96692 + int err = move_addr_to_kernel((void __force_user *)kern_msg->msg_name,
96693 kern_msg->msg_namelen,
96694 kern_address);
96695 if (err < 0)
96696 @@ -99,7 +99,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
96697 kern_msg->msg_name = NULL;
96698
96699 tot_len = iov_from_user_compat_to_kern(kern_iov,
96700 - (struct compat_iovec __user *)kern_msg->msg_iov,
96701 + (struct compat_iovec __force_user *)kern_msg->msg_iov,
96702 kern_msg->msg_iovlen);
96703 if (tot_len >= 0)
96704 kern_msg->msg_iov = kern_iov;
96705 @@ -119,20 +119,20 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
96706
96707 #define CMSG_COMPAT_FIRSTHDR(msg) \
96708 (((msg)->msg_controllen) >= sizeof(struct compat_cmsghdr) ? \
96709 - (struct compat_cmsghdr __user *)((msg)->msg_control) : \
96710 + (struct compat_cmsghdr __force_user *)((msg)->msg_control) : \
96711 (struct compat_cmsghdr __user *)NULL)
96712
96713 #define CMSG_COMPAT_OK(ucmlen, ucmsg, mhdr) \
96714 ((ucmlen) >= sizeof(struct compat_cmsghdr) && \
96715 (ucmlen) <= (unsigned long) \
96716 ((mhdr)->msg_controllen - \
96717 - ((char *)(ucmsg) - (char *)(mhdr)->msg_control)))
96718 + ((char __force_kernel *)(ucmsg) - (char *)(mhdr)->msg_control)))
96719
96720 static inline struct compat_cmsghdr __user *cmsg_compat_nxthdr(struct msghdr *msg,
96721 struct compat_cmsghdr __user *cmsg, int cmsg_len)
96722 {
96723 char __user *ptr = (char __user *)cmsg + CMSG_COMPAT_ALIGN(cmsg_len);
96724 - if ((unsigned long)(ptr + 1 - (char __user *)msg->msg_control) >
96725 + if ((unsigned long)(ptr + 1 - (char __force_user *)msg->msg_control) >
96726 msg->msg_controllen)
96727 return NULL;
96728 return (struct compat_cmsghdr __user *)ptr;
96729 @@ -222,7 +222,7 @@ Efault:
96730
96731 int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *data)
96732 {
96733 - struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
96734 + struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
96735 struct compat_cmsghdr cmhdr;
96736 struct compat_timeval ctv;
96737 struct compat_timespec cts[3];
96738 @@ -278,7 +278,7 @@ int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *dat
96739
96740 void scm_detach_fds_compat(struct msghdr *kmsg, struct scm_cookie *scm)
96741 {
96742 - struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
96743 + struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
96744 int fdmax = (kmsg->msg_controllen - sizeof(struct compat_cmsghdr)) / sizeof(int);
96745 int fdnum = scm->fp->count;
96746 struct file **fp = scm->fp->fp;
96747 @@ -366,7 +366,7 @@ static int do_set_sock_timeout(struct socket *sock, int level,
96748 return -EFAULT;
96749 old_fs = get_fs();
96750 set_fs(KERNEL_DS);
96751 - err = sock_setsockopt(sock, level, optname, (char *)&ktime, sizeof(ktime));
96752 + err = sock_setsockopt(sock, level, optname, (char __force_user *)&ktime, sizeof(ktime));
96753 set_fs(old_fs);
96754
96755 return err;
96756 @@ -427,7 +427,7 @@ static int do_get_sock_timeout(struct socket *sock, int level, int optname,
96757 len = sizeof(ktime);
96758 old_fs = get_fs();
96759 set_fs(KERNEL_DS);
96760 - err = sock_getsockopt(sock, level, optname, (char *) &ktime, &len);
96761 + err = sock_getsockopt(sock, level, optname, (char __force_user *) &ktime, (int __force_user *)&len);
96762 set_fs(old_fs);
96763
96764 if (!err) {
96765 @@ -570,7 +570,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
96766 case MCAST_JOIN_GROUP:
96767 case MCAST_LEAVE_GROUP:
96768 {
96769 - struct compat_group_req __user *gr32 = (void *)optval;
96770 + struct compat_group_req __user *gr32 = (void __user *)optval;
96771 struct group_req __user *kgr =
96772 compat_alloc_user_space(sizeof(struct group_req));
96773 u32 interface;
96774 @@ -591,7 +591,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
96775 case MCAST_BLOCK_SOURCE:
96776 case MCAST_UNBLOCK_SOURCE:
96777 {
96778 - struct compat_group_source_req __user *gsr32 = (void *)optval;
96779 + struct compat_group_source_req __user *gsr32 = (void __user *)optval;
96780 struct group_source_req __user *kgsr = compat_alloc_user_space(
96781 sizeof(struct group_source_req));
96782 u32 interface;
96783 @@ -612,7 +612,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
96784 }
96785 case MCAST_MSFILTER:
96786 {
96787 - struct compat_group_filter __user *gf32 = (void *)optval;
96788 + struct compat_group_filter __user *gf32 = (void __user *)optval;
96789 struct group_filter __user *kgf;
96790 u32 interface, fmode, numsrc;
96791
96792 @@ -650,7 +650,7 @@ int compat_mc_getsockopt(struct sock *sock, int level, int optname,
96793 char __user *optval, int __user *optlen,
96794 int (*getsockopt)(struct sock *, int, int, char __user *, int __user *))
96795 {
96796 - struct compat_group_filter __user *gf32 = (void *)optval;
96797 + struct compat_group_filter __user *gf32 = (void __user *)optval;
96798 struct group_filter __user *kgf;
96799 int __user *koptlen;
96800 u32 interface, fmode, numsrc;
96801 @@ -803,7 +803,7 @@ asmlinkage long compat_sys_socketcall(int call, u32 __user *args)
96802
96803 if (call < SYS_SOCKET || call > SYS_SENDMMSG)
96804 return -EINVAL;
96805 - if (copy_from_user(a, args, nas[call]))
96806 + if (nas[call] > sizeof a || copy_from_user(a, args, nas[call]))
96807 return -EFAULT;
96808 a0 = a[0];
96809 a1 = a[1];
96810 diff --git a/net/core/datagram.c b/net/core/datagram.c
96811 index a16ed7b..eb44d17 100644
96812 --- a/net/core/datagram.c
96813 +++ b/net/core/datagram.c
96814 @@ -301,7 +301,7 @@ int skb_kill_datagram(struct sock *sk, struct sk_buff *skb, unsigned int flags)
96815 }
96816
96817 kfree_skb(skb);
96818 - atomic_inc(&sk->sk_drops);
96819 + atomic_inc_unchecked(&sk->sk_drops);
96820 sk_mem_reclaim_partial(sk);
96821
96822 return err;
96823 diff --git a/net/core/dev.c b/net/core/dev.c
96824 index 616eccf..31832d38 100644
96825 --- a/net/core/dev.c
96826 +++ b/net/core/dev.c
96827 @@ -1684,14 +1684,14 @@ int dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
96828 {
96829 if (skb_shinfo(skb)->tx_flags & SKBTX_DEV_ZEROCOPY) {
96830 if (skb_copy_ubufs(skb, GFP_ATOMIC)) {
96831 - atomic_long_inc(&dev->rx_dropped);
96832 + atomic_long_inc_unchecked(&dev->rx_dropped);
96833 kfree_skb(skb);
96834 return NET_RX_DROP;
96835 }
96836 }
96837
96838 if (unlikely(!is_skb_forwardable(dev, skb))) {
96839 - atomic_long_inc(&dev->rx_dropped);
96840 + atomic_long_inc_unchecked(&dev->rx_dropped);
96841 kfree_skb(skb);
96842 return NET_RX_DROP;
96843 }
96844 @@ -2434,7 +2434,7 @@ static int illegal_highdma(const struct net_device *dev, struct sk_buff *skb)
96845
96846 struct dev_gso_cb {
96847 void (*destructor)(struct sk_buff *skb);
96848 -};
96849 +} __no_const;
96850
96851 #define DEV_GSO_CB(skb) ((struct dev_gso_cb *)(skb)->cb)
96852
96853 @@ -3224,7 +3224,7 @@ enqueue:
96854
96855 local_irq_restore(flags);
96856
96857 - atomic_long_inc(&skb->dev->rx_dropped);
96858 + atomic_long_inc_unchecked(&skb->dev->rx_dropped);
96859 kfree_skb(skb);
96860 return NET_RX_DROP;
96861 }
96862 @@ -3296,7 +3296,7 @@ int netif_rx_ni(struct sk_buff *skb)
96863 }
96864 EXPORT_SYMBOL(netif_rx_ni);
96865
96866 -static void net_tx_action(struct softirq_action *h)
96867 +static __latent_entropy void net_tx_action(void)
96868 {
96869 struct softnet_data *sd = &__get_cpu_var(softnet_data);
96870
96871 @@ -3630,7 +3630,7 @@ ncls:
96872 ret = pt_prev->func(skb, skb->dev, pt_prev, orig_dev);
96873 } else {
96874 drop:
96875 - atomic_long_inc(&skb->dev->rx_dropped);
96876 + atomic_long_inc_unchecked(&skb->dev->rx_dropped);
96877 kfree_skb(skb);
96878 /* Jamal, now you will not able to escape explaining
96879 * me how you were going to use this. :-)
96880 @@ -4290,7 +4290,7 @@ void netif_napi_del(struct napi_struct *napi)
96881 }
96882 EXPORT_SYMBOL(netif_napi_del);
96883
96884 -static void net_rx_action(struct softirq_action *h)
96885 +static __latent_entropy void net_rx_action(void)
96886 {
96887 struct softnet_data *sd = &__get_cpu_var(softnet_data);
96888 unsigned long time_limit = jiffies + 2;
96889 @@ -6179,7 +6179,7 @@ struct rtnl_link_stats64 *dev_get_stats(struct net_device *dev,
96890 } else {
96891 netdev_stats_to_stats64(storage, &dev->stats);
96892 }
96893 - storage->rx_dropped += atomic_long_read(&dev->rx_dropped);
96894 + storage->rx_dropped += atomic_long_read_unchecked(&dev->rx_dropped);
96895 return storage;
96896 }
96897 EXPORT_SYMBOL(dev_get_stats);
96898 diff --git a/net/core/dev_ioctl.c b/net/core/dev_ioctl.c
96899 index 5b7d0e1..cb960fc 100644
96900 --- a/net/core/dev_ioctl.c
96901 +++ b/net/core/dev_ioctl.c
96902 @@ -365,9 +365,13 @@ void dev_load(struct net *net, const char *name)
96903 if (no_module && capable(CAP_NET_ADMIN))
96904 no_module = request_module("netdev-%s", name);
96905 if (no_module && capable(CAP_SYS_MODULE)) {
96906 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
96907 + ___request_module(true, "grsec_modharden_netdev", "%s", name);
96908 +#else
96909 if (!request_module("%s", name))
96910 pr_warn("Loading kernel module for a network device with CAP_SYS_MODULE (deprecated). Use CAP_NET_ADMIN and alias netdev-%s instead.\n",
96911 name);
96912 +#endif
96913 }
96914 }
96915 EXPORT_SYMBOL(dev_load);
96916 diff --git a/net/core/filter.c b/net/core/filter.c
96917 index ad30d62..21c0743 100644
96918 --- a/net/core/filter.c
96919 +++ b/net/core/filter.c
96920 @@ -126,7 +126,7 @@ unsigned int sk_run_filter(const struct sk_buff *skb,
96921 void *ptr;
96922 u32 A = 0; /* Accumulator */
96923 u32 X = 0; /* Index Register */
96924 - u32 mem[BPF_MEMWORDS]; /* Scratch Memory Store */
96925 + u32 mem[BPF_MEMWORDS] = {}; /* Scratch Memory Store */
96926 u32 tmp;
96927 int k;
96928
96929 @@ -292,10 +292,10 @@ load_b:
96930 X = K;
96931 continue;
96932 case BPF_S_LD_MEM:
96933 - A = mem[K];
96934 + A = mem[K&15];
96935 continue;
96936 case BPF_S_LDX_MEM:
96937 - X = mem[K];
96938 + X = mem[K&15];
96939 continue;
96940 case BPF_S_MISC_TAX:
96941 X = A;
96942 @@ -308,10 +308,10 @@ load_b:
96943 case BPF_S_RET_A:
96944 return A;
96945 case BPF_S_ST:
96946 - mem[K] = A;
96947 + mem[K&15] = A;
96948 continue;
96949 case BPF_S_STX:
96950 - mem[K] = X;
96951 + mem[K&15] = X;
96952 continue;
96953 case BPF_S_ANC_PROTOCOL:
96954 A = ntohs(skb->protocol);
96955 @@ -355,6 +355,10 @@ load_b:
96956
96957 if (skb_is_nonlinear(skb))
96958 return 0;
96959 +
96960 + if (skb->len < sizeof(struct nlattr))
96961 + return 0;
96962 +
96963 if (A > skb->len - sizeof(struct nlattr))
96964 return 0;
96965
96966 @@ -371,11 +375,15 @@ load_b:
96967
96968 if (skb_is_nonlinear(skb))
96969 return 0;
96970 +
96971 + if (skb->len < sizeof(struct nlattr))
96972 + return 0;
96973 +
96974 if (A > skb->len - sizeof(struct nlattr))
96975 return 0;
96976
96977 nla = (struct nlattr *)&skb->data[A];
96978 - if (nla->nla_len > A - skb->len)
96979 + if (nla->nla_len > skb->len - A)
96980 return 0;
96981
96982 nla = nla_find_nested(nla, X);
96983 @@ -391,9 +399,10 @@ load_b:
96984 continue;
96985 #endif
96986 default:
96987 - WARN_RATELIMIT(1, "Unknown code:%u jt:%u tf:%u k:%u\n",
96988 + WARN(1, KERN_ALERT "Unknown sock filter code:%u jt:%u tf:%u k:%u\n",
96989 fentry->code, fentry->jt,
96990 fentry->jf, fentry->k);
96991 + BUG();
96992 return 0;
96993 }
96994 }
96995 @@ -416,7 +425,7 @@ static int check_load_and_stores(struct sock_filter *filter, int flen)
96996 u16 *masks, memvalid = 0; /* one bit per cell, 16 cells */
96997 int pc, ret = 0;
96998
96999 - BUILD_BUG_ON(BPF_MEMWORDS > 16);
97000 + BUILD_BUG_ON(BPF_MEMWORDS != 16);
97001 masks = kmalloc(flen * sizeof(*masks), GFP_KERNEL);
97002 if (!masks)
97003 return -ENOMEM;
97004 @@ -679,7 +688,7 @@ int sk_unattached_filter_create(struct sk_filter **pfp,
97005 fp = kmalloc(sk_filter_size(fprog->len), GFP_KERNEL);
97006 if (!fp)
97007 return -ENOMEM;
97008 - memcpy(fp->insns, fprog->filter, fsize);
97009 + memcpy(fp->insns, (void __force_kernel *)fprog->filter, fsize);
97010
97011 atomic_set(&fp->refcnt, 1);
97012 fp->len = fprog->len;
97013 diff --git a/net/core/flow.c b/net/core/flow.c
97014 index dfa602c..3103d88 100644
97015 --- a/net/core/flow.c
97016 +++ b/net/core/flow.c
97017 @@ -61,7 +61,7 @@ struct flow_cache {
97018 struct timer_list rnd_timer;
97019 };
97020
97021 -atomic_t flow_cache_genid = ATOMIC_INIT(0);
97022 +atomic_unchecked_t flow_cache_genid = ATOMIC_INIT(0);
97023 EXPORT_SYMBOL(flow_cache_genid);
97024 static struct flow_cache flow_cache_global;
97025 static struct kmem_cache *flow_cachep __read_mostly;
97026 @@ -86,7 +86,7 @@ static void flow_cache_new_hashrnd(unsigned long arg)
97027
97028 static int flow_entry_valid(struct flow_cache_entry *fle)
97029 {
97030 - if (atomic_read(&flow_cache_genid) != fle->genid)
97031 + if (atomic_read_unchecked(&flow_cache_genid) != fle->genid)
97032 return 0;
97033 if (fle->object && !fle->object->ops->check(fle->object))
97034 return 0;
97035 @@ -258,7 +258,7 @@ flow_cache_lookup(struct net *net, const struct flowi *key, u16 family, u8 dir,
97036 hlist_add_head(&fle->u.hlist, &fcp->hash_table[hash]);
97037 fcp->hash_count++;
97038 }
97039 - } else if (likely(fle->genid == atomic_read(&flow_cache_genid))) {
97040 + } else if (likely(fle->genid == atomic_read_unchecked(&flow_cache_genid))) {
97041 flo = fle->object;
97042 if (!flo)
97043 goto ret_object;
97044 @@ -279,7 +279,7 @@ nocache:
97045 }
97046 flo = resolver(net, key, family, dir, flo, ctx);
97047 if (fle) {
97048 - fle->genid = atomic_read(&flow_cache_genid);
97049 + fle->genid = atomic_read_unchecked(&flow_cache_genid);
97050 if (!IS_ERR(flo))
97051 fle->object = flo;
97052 else
97053 diff --git a/net/core/iovec.c b/net/core/iovec.c
97054 index b618694..192bbba 100644
97055 --- a/net/core/iovec.c
97056 +++ b/net/core/iovec.c
97057 @@ -42,7 +42,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
97058 if (m->msg_namelen) {
97059 if (mode == VERIFY_READ) {
97060 void __user *namep;
97061 - namep = (void __user __force *) m->msg_name;
97062 + namep = (void __force_user *) m->msg_name;
97063 err = move_addr_to_kernel(namep, m->msg_namelen,
97064 address);
97065 if (err < 0)
97066 @@ -55,7 +55,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
97067 }
97068
97069 size = m->msg_iovlen * sizeof(struct iovec);
97070 - if (copy_from_user(iov, (void __user __force *) m->msg_iov, size))
97071 + if (copy_from_user(iov, (void __force_user *) m->msg_iov, size))
97072 return -EFAULT;
97073
97074 m->msg_iov = iov;
97075 diff --git a/net/core/neighbour.c b/net/core/neighbour.c
97076 index 43128dd..e4d4311 100644
97077 --- a/net/core/neighbour.c
97078 +++ b/net/core/neighbour.c
97079 @@ -2775,7 +2775,7 @@ static int proc_unres_qlen(struct ctl_table *ctl, int write,
97080 void __user *buffer, size_t *lenp, loff_t *ppos)
97081 {
97082 int size, ret;
97083 - struct ctl_table tmp = *ctl;
97084 + ctl_table_no_const tmp = *ctl;
97085
97086 tmp.extra1 = &zero;
97087 tmp.extra2 = &unres_qlen_max;
97088 @@ -2983,11 +2983,12 @@ int neigh_sysctl_register(struct net_device *dev, struct neigh_parms *p,
97089 memset(&t->neigh_vars[NEIGH_VAR_GC_INTERVAL], 0,
97090 sizeof(t->neigh_vars[NEIGH_VAR_GC_INTERVAL]));
97091 } else {
97092 + struct neigh_table *ntable = container_of(p, struct neigh_table, parms);
97093 dev_name_source = "default";
97094 - t->neigh_vars[NEIGH_VAR_GC_INTERVAL].data = (int *)(p + 1);
97095 - t->neigh_vars[NEIGH_VAR_GC_THRESH1].data = (int *)(p + 1) + 1;
97096 - t->neigh_vars[NEIGH_VAR_GC_THRESH2].data = (int *)(p + 1) + 2;
97097 - t->neigh_vars[NEIGH_VAR_GC_THRESH3].data = (int *)(p + 1) + 3;
97098 + t->neigh_vars[NEIGH_VAR_GC_INTERVAL].data = &ntable->gc_interval;
97099 + t->neigh_vars[NEIGH_VAR_GC_THRESH1].data = &ntable->gc_thresh1;
97100 + t->neigh_vars[NEIGH_VAR_GC_THRESH2].data = &ntable->gc_thresh2;
97101 + t->neigh_vars[NEIGH_VAR_GC_THRESH3].data = &ntable->gc_thresh3;
97102 }
97103
97104
97105 diff --git a/net/core/net-procfs.c b/net/core/net-procfs.c
97106 index 2bf8329..7960607 100644
97107 --- a/net/core/net-procfs.c
97108 +++ b/net/core/net-procfs.c
97109 @@ -283,8 +283,13 @@ static int ptype_seq_show(struct seq_file *seq, void *v)
97110 else
97111 seq_printf(seq, "%04x", ntohs(pt->type));
97112
97113 +#ifdef CONFIG_GRKERNSEC_HIDESYM
97114 + seq_printf(seq, " %-8s %pf\n",
97115 + pt->dev ? pt->dev->name : "", NULL);
97116 +#else
97117 seq_printf(seq, " %-8s %pf\n",
97118 pt->dev ? pt->dev->name : "", pt->func);
97119 +#endif
97120 }
97121
97122 return 0;
97123 diff --git a/net/core/net-sysfs.c b/net/core/net-sysfs.c
97124 index f3edf96..3cd8b40 100644
97125 --- a/net/core/net-sysfs.c
97126 +++ b/net/core/net-sysfs.c
97127 @@ -1358,7 +1358,7 @@ void netdev_class_remove_file_ns(struct class_attribute *class_attr,
97128 }
97129 EXPORT_SYMBOL(netdev_class_remove_file_ns);
97130
97131 -int netdev_kobject_init(void)
97132 +int __init netdev_kobject_init(void)
97133 {
97134 kobj_ns_type_register(&net_ns_type_operations);
97135 return class_register(&net_class);
97136 diff --git a/net/core/net_namespace.c b/net/core/net_namespace.c
97137 index 81d3a9a..a0bd7a8 100644
97138 --- a/net/core/net_namespace.c
97139 +++ b/net/core/net_namespace.c
97140 @@ -443,7 +443,7 @@ static int __register_pernet_operations(struct list_head *list,
97141 int error;
97142 LIST_HEAD(net_exit_list);
97143
97144 - list_add_tail(&ops->list, list);
97145 + pax_list_add_tail((struct list_head *)&ops->list, list);
97146 if (ops->init || (ops->id && ops->size)) {
97147 for_each_net(net) {
97148 error = ops_init(ops, net);
97149 @@ -456,7 +456,7 @@ static int __register_pernet_operations(struct list_head *list,
97150
97151 out_undo:
97152 /* If I have an error cleanup all namespaces I initialized */
97153 - list_del(&ops->list);
97154 + pax_list_del((struct list_head *)&ops->list);
97155 ops_exit_list(ops, &net_exit_list);
97156 ops_free_list(ops, &net_exit_list);
97157 return error;
97158 @@ -467,7 +467,7 @@ static void __unregister_pernet_operations(struct pernet_operations *ops)
97159 struct net *net;
97160 LIST_HEAD(net_exit_list);
97161
97162 - list_del(&ops->list);
97163 + pax_list_del((struct list_head *)&ops->list);
97164 for_each_net(net)
97165 list_add_tail(&net->exit_list, &net_exit_list);
97166 ops_exit_list(ops, &net_exit_list);
97167 @@ -601,7 +601,7 @@ int register_pernet_device(struct pernet_operations *ops)
97168 mutex_lock(&net_mutex);
97169 error = register_pernet_operations(&pernet_list, ops);
97170 if (!error && (first_device == &pernet_list))
97171 - first_device = &ops->list;
97172 + first_device = (struct list_head *)&ops->list;
97173 mutex_unlock(&net_mutex);
97174 return error;
97175 }
97176 diff --git a/net/core/netpoll.c b/net/core/netpoll.c
97177 index 9a46671..6b8cb72 100644
97178 --- a/net/core/netpoll.c
97179 +++ b/net/core/netpoll.c
97180 @@ -435,7 +435,7 @@ void netpoll_send_udp(struct netpoll *np, const char *msg, int len)
97181 struct udphdr *udph;
97182 struct iphdr *iph;
97183 struct ethhdr *eth;
97184 - static atomic_t ip_ident;
97185 + static atomic_unchecked_t ip_ident;
97186 struct ipv6hdr *ip6h;
97187
97188 udp_len = len + sizeof(*udph);
97189 @@ -506,7 +506,7 @@ void netpoll_send_udp(struct netpoll *np, const char *msg, int len)
97190 put_unaligned(0x45, (unsigned char *)iph);
97191 iph->tos = 0;
97192 put_unaligned(htons(ip_len), &(iph->tot_len));
97193 - iph->id = htons(atomic_inc_return(&ip_ident));
97194 + iph->id = htons(atomic_inc_return_unchecked(&ip_ident));
97195 iph->frag_off = 0;
97196 iph->ttl = 64;
97197 iph->protocol = IPPROTO_UDP;
97198 diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
97199 index cc706c9..21fcd84 100644
97200 --- a/net/core/rtnetlink.c
97201 +++ b/net/core/rtnetlink.c
97202 @@ -58,7 +58,7 @@ struct rtnl_link {
97203 rtnl_doit_func doit;
97204 rtnl_dumpit_func dumpit;
97205 rtnl_calcit_func calcit;
97206 -};
97207 +} __no_const;
97208
97209 static DEFINE_MUTEX(rtnl_mutex);
97210
97211 @@ -299,10 +299,13 @@ int __rtnl_link_register(struct rtnl_link_ops *ops)
97212 if (rtnl_link_ops_get(ops->kind))
97213 return -EEXIST;
97214
97215 - if (!ops->dellink)
97216 - ops->dellink = unregister_netdevice_queue;
97217 + if (!ops->dellink) {
97218 + pax_open_kernel();
97219 + *(void **)&ops->dellink = unregister_netdevice_queue;
97220 + pax_close_kernel();
97221 + }
97222
97223 - list_add_tail(&ops->list, &link_ops);
97224 + pax_list_add_tail((struct list_head *)&ops->list, &link_ops);
97225 return 0;
97226 }
97227 EXPORT_SYMBOL_GPL(__rtnl_link_register);
97228 @@ -349,7 +352,7 @@ void __rtnl_link_unregister(struct rtnl_link_ops *ops)
97229 for_each_net(net) {
97230 __rtnl_kill_links(net, ops);
97231 }
97232 - list_del(&ops->list);
97233 + pax_list_del((struct list_head *)&ops->list);
97234 }
97235 EXPORT_SYMBOL_GPL(__rtnl_link_unregister);
97236
97237 diff --git a/net/core/scm.c b/net/core/scm.c
97238 index b442e7e..6f5b5a2 100644
97239 --- a/net/core/scm.c
97240 +++ b/net/core/scm.c
97241 @@ -210,7 +210,7 @@ EXPORT_SYMBOL(__scm_send);
97242 int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
97243 {
97244 struct cmsghdr __user *cm
97245 - = (__force struct cmsghdr __user *)msg->msg_control;
97246 + = (struct cmsghdr __force_user *)msg->msg_control;
97247 struct cmsghdr cmhdr;
97248 int cmlen = CMSG_LEN(len);
97249 int err;
97250 @@ -233,7 +233,7 @@ int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
97251 err = -EFAULT;
97252 if (copy_to_user(cm, &cmhdr, sizeof cmhdr))
97253 goto out;
97254 - if (copy_to_user(CMSG_DATA(cm), data, cmlen - sizeof(struct cmsghdr)))
97255 + if (copy_to_user((void __force_user *)CMSG_DATA((void __force_kernel *)cm), data, cmlen - sizeof(struct cmsghdr)))
97256 goto out;
97257 cmlen = CMSG_SPACE(len);
97258 if (msg->msg_controllen < cmlen)
97259 @@ -249,7 +249,7 @@ EXPORT_SYMBOL(put_cmsg);
97260 void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
97261 {
97262 struct cmsghdr __user *cm
97263 - = (__force struct cmsghdr __user*)msg->msg_control;
97264 + = (struct cmsghdr __force_user *)msg->msg_control;
97265
97266 int fdmax = 0;
97267 int fdnum = scm->fp->count;
97268 @@ -269,7 +269,7 @@ void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
97269 if (fdnum < fdmax)
97270 fdmax = fdnum;
97271
97272 - for (i=0, cmfptr=(__force int __user *)CMSG_DATA(cm); i<fdmax;
97273 + for (i=0, cmfptr=(int __force_user *)CMSG_DATA((void __force_kernel *)cm); i<fdmax;
97274 i++, cmfptr++)
97275 {
97276 struct socket *sock;
97277 diff --git a/net/core/skbuff.c b/net/core/skbuff.c
97278 index 9a9898e..38cc3e3 100644
97279 --- a/net/core/skbuff.c
97280 +++ b/net/core/skbuff.c
97281 @@ -2006,7 +2006,7 @@ EXPORT_SYMBOL(__skb_checksum);
97282 __wsum skb_checksum(const struct sk_buff *skb, int offset,
97283 int len, __wsum csum)
97284 {
97285 - const struct skb_checksum_ops ops = {
97286 + static const struct skb_checksum_ops ops = {
97287 .update = csum_partial_ext,
97288 .combine = csum_block_add_ext,
97289 };
97290 @@ -3124,13 +3124,15 @@ void __init skb_init(void)
97291 skbuff_head_cache = kmem_cache_create("skbuff_head_cache",
97292 sizeof(struct sk_buff),
97293 0,
97294 - SLAB_HWCACHE_ALIGN|SLAB_PANIC,
97295 + SLAB_HWCACHE_ALIGN|SLAB_PANIC|
97296 + SLAB_NO_SANITIZE,
97297 NULL);
97298 skbuff_fclone_cache = kmem_cache_create("skbuff_fclone_cache",
97299 (2*sizeof(struct sk_buff)) +
97300 sizeof(atomic_t),
97301 0,
97302 - SLAB_HWCACHE_ALIGN|SLAB_PANIC,
97303 + SLAB_HWCACHE_ALIGN|SLAB_PANIC|
97304 + SLAB_NO_SANITIZE,
97305 NULL);
97306 }
97307
97308 diff --git a/net/core/sock.c b/net/core/sock.c
97309 index 50db733..8e4aeb4 100644
97310 --- a/net/core/sock.c
97311 +++ b/net/core/sock.c
97312 @@ -393,7 +393,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
97313 struct sk_buff_head *list = &sk->sk_receive_queue;
97314
97315 if (atomic_read(&sk->sk_rmem_alloc) >= sk->sk_rcvbuf) {
97316 - atomic_inc(&sk->sk_drops);
97317 + atomic_inc_unchecked(&sk->sk_drops);
97318 trace_sock_rcvqueue_full(sk, skb);
97319 return -ENOMEM;
97320 }
97321 @@ -403,7 +403,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
97322 return err;
97323
97324 if (!sk_rmem_schedule(sk, skb, skb->truesize)) {
97325 - atomic_inc(&sk->sk_drops);
97326 + atomic_inc_unchecked(&sk->sk_drops);
97327 return -ENOBUFS;
97328 }
97329
97330 @@ -423,7 +423,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
97331 skb_dst_force(skb);
97332
97333 spin_lock_irqsave(&list->lock, flags);
97334 - skb->dropcount = atomic_read(&sk->sk_drops);
97335 + skb->dropcount = atomic_read_unchecked(&sk->sk_drops);
97336 __skb_queue_tail(list, skb);
97337 spin_unlock_irqrestore(&list->lock, flags);
97338
97339 @@ -443,7 +443,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
97340 skb->dev = NULL;
97341
97342 if (sk_rcvqueues_full(sk, skb, sk->sk_rcvbuf)) {
97343 - atomic_inc(&sk->sk_drops);
97344 + atomic_inc_unchecked(&sk->sk_drops);
97345 goto discard_and_relse;
97346 }
97347 if (nested)
97348 @@ -461,7 +461,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
97349 mutex_release(&sk->sk_lock.dep_map, 1, _RET_IP_);
97350 } else if (sk_add_backlog(sk, skb, sk->sk_rcvbuf)) {
97351 bh_unlock_sock(sk);
97352 - atomic_inc(&sk->sk_drops);
97353 + atomic_inc_unchecked(&sk->sk_drops);
97354 goto discard_and_relse;
97355 }
97356
97357 @@ -950,12 +950,12 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
97358 struct timeval tm;
97359 } v;
97360
97361 - int lv = sizeof(int);
97362 - int len;
97363 + unsigned int lv = sizeof(int);
97364 + unsigned int len;
97365
97366 if (get_user(len, optlen))
97367 return -EFAULT;
97368 - if (len < 0)
97369 + if (len > INT_MAX)
97370 return -EINVAL;
97371
97372 memset(&v, 0, sizeof(v));
97373 @@ -1107,11 +1107,11 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
97374
97375 case SO_PEERNAME:
97376 {
97377 - char address[128];
97378 + char address[_K_SS_MAXSIZE];
97379
97380 if (sock->ops->getname(sock, (struct sockaddr *)address, &lv, 2))
97381 return -ENOTCONN;
97382 - if (lv < len)
97383 + if (lv < len || sizeof address < len)
97384 return -EINVAL;
97385 if (copy_to_user(optval, address, len))
97386 return -EFAULT;
97387 @@ -1188,7 +1188,7 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
97388
97389 if (len > lv)
97390 len = lv;
97391 - if (copy_to_user(optval, &v, len))
97392 + if (len > sizeof(v) || copy_to_user(optval, &v, len))
97393 return -EFAULT;
97394 lenout:
97395 if (put_user(len, optlen))
97396 @@ -2353,7 +2353,7 @@ void sock_init_data(struct socket *sock, struct sock *sk)
97397 */
97398 smp_wmb();
97399 atomic_set(&sk->sk_refcnt, 1);
97400 - atomic_set(&sk->sk_drops, 0);
97401 + atomic_set_unchecked(&sk->sk_drops, 0);
97402 }
97403 EXPORT_SYMBOL(sock_init_data);
97404
97405 @@ -2481,6 +2481,7 @@ void sock_enable_timestamp(struct sock *sk, int flag)
97406 int sock_recv_errqueue(struct sock *sk, struct msghdr *msg, int len,
97407 int level, int type)
97408 {
97409 + struct sock_extended_err ee;
97410 struct sock_exterr_skb *serr;
97411 struct sk_buff *skb, *skb2;
97412 int copied, err;
97413 @@ -2502,7 +2503,8 @@ int sock_recv_errqueue(struct sock *sk, struct msghdr *msg, int len,
97414 sock_recv_timestamp(msg, sk, skb);
97415
97416 serr = SKB_EXT_ERR(skb);
97417 - put_cmsg(msg, level, type, sizeof(serr->ee), &serr->ee);
97418 + ee = serr->ee;
97419 + put_cmsg(msg, level, type, sizeof ee, &ee);
97420
97421 msg->msg_flags |= MSG_ERRQUEUE;
97422 err = copied;
97423 diff --git a/net/core/sock_diag.c b/net/core/sock_diag.c
97424 index a0e9cf6..ef7f9ed 100644
97425 --- a/net/core/sock_diag.c
97426 +++ b/net/core/sock_diag.c
97427 @@ -9,26 +9,33 @@
97428 #include <linux/inet_diag.h>
97429 #include <linux/sock_diag.h>
97430
97431 -static const struct sock_diag_handler *sock_diag_handlers[AF_MAX];
97432 +static const struct sock_diag_handler *sock_diag_handlers[AF_MAX] __read_only;
97433 static int (*inet_rcv_compat)(struct sk_buff *skb, struct nlmsghdr *nlh);
97434 static DEFINE_MUTEX(sock_diag_table_mutex);
97435
97436 int sock_diag_check_cookie(void *sk, __u32 *cookie)
97437 {
97438 +#ifndef CONFIG_GRKERNSEC_HIDESYM
97439 if ((cookie[0] != INET_DIAG_NOCOOKIE ||
97440 cookie[1] != INET_DIAG_NOCOOKIE) &&
97441 ((u32)(unsigned long)sk != cookie[0] ||
97442 (u32)((((unsigned long)sk) >> 31) >> 1) != cookie[1]))
97443 return -ESTALE;
97444 else
97445 +#endif
97446 return 0;
97447 }
97448 EXPORT_SYMBOL_GPL(sock_diag_check_cookie);
97449
97450 void sock_diag_save_cookie(void *sk, __u32 *cookie)
97451 {
97452 +#ifdef CONFIG_GRKERNSEC_HIDESYM
97453 + cookie[0] = 0;
97454 + cookie[1] = 0;
97455 +#else
97456 cookie[0] = (u32)(unsigned long)sk;
97457 cookie[1] = (u32)(((unsigned long)sk >> 31) >> 1);
97458 +#endif
97459 }
97460 EXPORT_SYMBOL_GPL(sock_diag_save_cookie);
97461
97462 @@ -113,8 +120,11 @@ int sock_diag_register(const struct sock_diag_handler *hndl)
97463 mutex_lock(&sock_diag_table_mutex);
97464 if (sock_diag_handlers[hndl->family])
97465 err = -EBUSY;
97466 - else
97467 + else {
97468 + pax_open_kernel();
97469 sock_diag_handlers[hndl->family] = hndl;
97470 + pax_close_kernel();
97471 + }
97472 mutex_unlock(&sock_diag_table_mutex);
97473
97474 return err;
97475 @@ -130,7 +140,9 @@ void sock_diag_unregister(const struct sock_diag_handler *hnld)
97476
97477 mutex_lock(&sock_diag_table_mutex);
97478 BUG_ON(sock_diag_handlers[family] != hnld);
97479 + pax_open_kernel();
97480 sock_diag_handlers[family] = NULL;
97481 + pax_close_kernel();
97482 mutex_unlock(&sock_diag_table_mutex);
97483 }
97484 EXPORT_SYMBOL_GPL(sock_diag_unregister);
97485 diff --git a/net/core/sysctl_net_core.c b/net/core/sysctl_net_core.c
97486 index cca4441..5e616de 100644
97487 --- a/net/core/sysctl_net_core.c
97488 +++ b/net/core/sysctl_net_core.c
97489 @@ -32,7 +32,7 @@ static int rps_sock_flow_sysctl(struct ctl_table *table, int write,
97490 {
97491 unsigned int orig_size, size;
97492 int ret, i;
97493 - struct ctl_table tmp = {
97494 + ctl_table_no_const tmp = {
97495 .data = &size,
97496 .maxlen = sizeof(size),
97497 .mode = table->mode
97498 @@ -199,7 +199,7 @@ static int set_default_qdisc(struct ctl_table *table, int write,
97499 void __user *buffer, size_t *lenp, loff_t *ppos)
97500 {
97501 char id[IFNAMSIZ];
97502 - struct ctl_table tbl = {
97503 + ctl_table_no_const tbl = {
97504 .data = id,
97505 .maxlen = IFNAMSIZ,
97506 };
97507 @@ -378,13 +378,12 @@ static struct ctl_table netns_core_table[] = {
97508
97509 static __net_init int sysctl_core_net_init(struct net *net)
97510 {
97511 - struct ctl_table *tbl;
97512 + ctl_table_no_const *tbl = NULL;
97513
97514 net->core.sysctl_somaxconn = SOMAXCONN;
97515
97516 - tbl = netns_core_table;
97517 if (!net_eq(net, &init_net)) {
97518 - tbl = kmemdup(tbl, sizeof(netns_core_table), GFP_KERNEL);
97519 + tbl = kmemdup(netns_core_table, sizeof(netns_core_table), GFP_KERNEL);
97520 if (tbl == NULL)
97521 goto err_dup;
97522
97523 @@ -394,17 +393,16 @@ static __net_init int sysctl_core_net_init(struct net *net)
97524 if (net->user_ns != &init_user_ns) {
97525 tbl[0].procname = NULL;
97526 }
97527 - }
97528 -
97529 - net->core.sysctl_hdr = register_net_sysctl(net, "net/core", tbl);
97530 + net->core.sysctl_hdr = register_net_sysctl(net, "net/core", tbl);
97531 + } else
97532 + net->core.sysctl_hdr = register_net_sysctl(net, "net/core", netns_core_table);
97533 if (net->core.sysctl_hdr == NULL)
97534 goto err_reg;
97535
97536 return 0;
97537
97538 err_reg:
97539 - if (tbl != netns_core_table)
97540 - kfree(tbl);
97541 + kfree(tbl);
97542 err_dup:
97543 return -ENOMEM;
97544 }
97545 @@ -419,7 +417,7 @@ static __net_exit void sysctl_core_net_exit(struct net *net)
97546 kfree(tbl);
97547 }
97548
97549 -static __net_initdata struct pernet_operations sysctl_core_ops = {
97550 +static __net_initconst struct pernet_operations sysctl_core_ops = {
97551 .init = sysctl_core_net_init,
97552 .exit = sysctl_core_net_exit,
97553 };
97554 diff --git a/net/decnet/af_decnet.c b/net/decnet/af_decnet.c
97555 index dd4d506..fb2fb87 100644
97556 --- a/net/decnet/af_decnet.c
97557 +++ b/net/decnet/af_decnet.c
97558 @@ -465,6 +465,7 @@ static struct proto dn_proto = {
97559 .sysctl_rmem = sysctl_decnet_rmem,
97560 .max_header = DN_MAX_NSP_DATA_HEADER + 64,
97561 .obj_size = sizeof(struct dn_sock),
97562 + .slab_flags = SLAB_USERCOPY,
97563 };
97564
97565 static struct sock *dn_alloc_sock(struct net *net, struct socket *sock, gfp_t gfp)
97566 diff --git a/net/decnet/dn_dev.c b/net/decnet/dn_dev.c
97567 index dd0dfb2..fdbc764 100644
97568 --- a/net/decnet/dn_dev.c
97569 +++ b/net/decnet/dn_dev.c
97570 @@ -200,7 +200,7 @@ static struct dn_dev_sysctl_table {
97571 .extra1 = &min_t3,
97572 .extra2 = &max_t3
97573 },
97574 - {0}
97575 + { }
97576 },
97577 };
97578
97579 diff --git a/net/decnet/sysctl_net_decnet.c b/net/decnet/sysctl_net_decnet.c
97580 index 5325b54..a0d4d69 100644
97581 --- a/net/decnet/sysctl_net_decnet.c
97582 +++ b/net/decnet/sysctl_net_decnet.c
97583 @@ -174,7 +174,7 @@ static int dn_node_address_handler(struct ctl_table *table, int write,
97584
97585 if (len > *lenp) len = *lenp;
97586
97587 - if (copy_to_user(buffer, addr, len))
97588 + if (len > sizeof addr || copy_to_user(buffer, addr, len))
97589 return -EFAULT;
97590
97591 *lenp = len;
97592 @@ -237,7 +237,7 @@ static int dn_def_dev_handler(struct ctl_table *table, int write,
97593
97594 if (len > *lenp) len = *lenp;
97595
97596 - if (copy_to_user(buffer, devname, len))
97597 + if (len > sizeof devname || copy_to_user(buffer, devname, len))
97598 return -EFAULT;
97599
97600 *lenp = len;
97601 diff --git a/net/ieee802154/dgram.c b/net/ieee802154/dgram.c
97602 index 1865fdf..581a595 100644
97603 --- a/net/ieee802154/dgram.c
97604 +++ b/net/ieee802154/dgram.c
97605 @@ -315,8 +315,9 @@ static int dgram_recvmsg(struct kiocb *iocb, struct sock *sk,
97606 if (saddr) {
97607 saddr->family = AF_IEEE802154;
97608 saddr->addr = mac_cb(skb)->sa;
97609 + }
97610 + if (addr_len)
97611 *addr_len = sizeof(*saddr);
97612 - }
97613
97614 if (flags & MSG_TRUNC)
97615 copied = skb->len;
97616 diff --git a/net/ipv4/af_inet.c b/net/ipv4/af_inet.c
97617 index e4d96d4..e1651da 100644
97618 --- a/net/ipv4/af_inet.c
97619 +++ b/net/ipv4/af_inet.c
97620 @@ -1686,13 +1686,9 @@ static int __init inet_init(void)
97621
97622 BUILD_BUG_ON(sizeof(struct inet_skb_parm) > FIELD_SIZEOF(struct sk_buff, cb));
97623
97624 - sysctl_local_reserved_ports = kzalloc(65536 / 8, GFP_KERNEL);
97625 - if (!sysctl_local_reserved_ports)
97626 - goto out;
97627 -
97628 rc = proto_register(&tcp_prot, 1);
97629 if (rc)
97630 - goto out_free_reserved_ports;
97631 + goto out;
97632
97633 rc = proto_register(&udp_prot, 1);
97634 if (rc)
97635 @@ -1799,8 +1795,6 @@ out_unregister_udp_proto:
97636 proto_unregister(&udp_prot);
97637 out_unregister_tcp_proto:
97638 proto_unregister(&tcp_prot);
97639 -out_free_reserved_ports:
97640 - kfree(sysctl_local_reserved_ports);
97641 goto out;
97642 }
97643
97644 diff --git a/net/ipv4/devinet.c b/net/ipv4/devinet.c
97645 index f4b34d8..c54a163 100644
97646 --- a/net/ipv4/devinet.c
97647 +++ b/net/ipv4/devinet.c
97648 @@ -1534,7 +1534,7 @@ static int inet_dump_ifaddr(struct sk_buff *skb, struct netlink_callback *cb)
97649 idx = 0;
97650 head = &net->dev_index_head[h];
97651 rcu_read_lock();
97652 - cb->seq = atomic_read(&net->ipv4.dev_addr_genid) ^
97653 + cb->seq = atomic_read_unchecked(&net->ipv4.dev_addr_genid) ^
97654 net->dev_base_seq;
97655 hlist_for_each_entry_rcu(dev, head, index_hlist) {
97656 if (idx < s_idx)
97657 @@ -1845,7 +1845,7 @@ static int inet_netconf_dump_devconf(struct sk_buff *skb,
97658 idx = 0;
97659 head = &net->dev_index_head[h];
97660 rcu_read_lock();
97661 - cb->seq = atomic_read(&net->ipv4.dev_addr_genid) ^
97662 + cb->seq = atomic_read_unchecked(&net->ipv4.dev_addr_genid) ^
97663 net->dev_base_seq;
97664 hlist_for_each_entry_rcu(dev, head, index_hlist) {
97665 if (idx < s_idx)
97666 @@ -2070,7 +2070,7 @@ static int ipv4_doint_and_flush(struct ctl_table *ctl, int write,
97667 #define DEVINET_SYSCTL_FLUSHING_ENTRY(attr, name) \
97668 DEVINET_SYSCTL_COMPLEX_ENTRY(attr, name, ipv4_doint_and_flush)
97669
97670 -static struct devinet_sysctl_table {
97671 +static const struct devinet_sysctl_table {
97672 struct ctl_table_header *sysctl_header;
97673 struct ctl_table devinet_vars[__IPV4_DEVCONF_MAX];
97674 } devinet_sysctl = {
97675 @@ -2192,7 +2192,7 @@ static __net_init int devinet_init_net(struct net *net)
97676 int err;
97677 struct ipv4_devconf *all, *dflt;
97678 #ifdef CONFIG_SYSCTL
97679 - struct ctl_table *tbl = ctl_forward_entry;
97680 + ctl_table_no_const *tbl = NULL;
97681 struct ctl_table_header *forw_hdr;
97682 #endif
97683
97684 @@ -2210,7 +2210,7 @@ static __net_init int devinet_init_net(struct net *net)
97685 goto err_alloc_dflt;
97686
97687 #ifdef CONFIG_SYSCTL
97688 - tbl = kmemdup(tbl, sizeof(ctl_forward_entry), GFP_KERNEL);
97689 + tbl = kmemdup(ctl_forward_entry, sizeof(ctl_forward_entry), GFP_KERNEL);
97690 if (tbl == NULL)
97691 goto err_alloc_ctl;
97692
97693 @@ -2230,7 +2230,10 @@ static __net_init int devinet_init_net(struct net *net)
97694 goto err_reg_dflt;
97695
97696 err = -ENOMEM;
97697 - forw_hdr = register_net_sysctl(net, "net/ipv4", tbl);
97698 + if (!net_eq(net, &init_net))
97699 + forw_hdr = register_net_sysctl(net, "net/ipv4", tbl);
97700 + else
97701 + forw_hdr = register_net_sysctl(net, "net/ipv4", ctl_forward_entry);
97702 if (forw_hdr == NULL)
97703 goto err_reg_ctl;
97704 net->ipv4.forw_hdr = forw_hdr;
97705 @@ -2246,8 +2249,7 @@ err_reg_ctl:
97706 err_reg_dflt:
97707 __devinet_sysctl_unregister(all);
97708 err_reg_all:
97709 - if (tbl != ctl_forward_entry)
97710 - kfree(tbl);
97711 + kfree(tbl);
97712 err_alloc_ctl:
97713 #endif
97714 if (dflt != &ipv4_devconf_dflt)
97715 diff --git a/net/ipv4/fib_frontend.c b/net/ipv4/fib_frontend.c
97716 index c7539e2..b455e51 100644
97717 --- a/net/ipv4/fib_frontend.c
97718 +++ b/net/ipv4/fib_frontend.c
97719 @@ -1015,12 +1015,12 @@ static int fib_inetaddr_event(struct notifier_block *this, unsigned long event,
97720 #ifdef CONFIG_IP_ROUTE_MULTIPATH
97721 fib_sync_up(dev);
97722 #endif
97723 - atomic_inc(&net->ipv4.dev_addr_genid);
97724 + atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
97725 rt_cache_flush(dev_net(dev));
97726 break;
97727 case NETDEV_DOWN:
97728 fib_del_ifaddr(ifa, NULL);
97729 - atomic_inc(&net->ipv4.dev_addr_genid);
97730 + atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
97731 if (ifa->ifa_dev->ifa_list == NULL) {
97732 /* Last address was deleted from this interface.
97733 * Disable IP.
97734 @@ -1058,7 +1058,7 @@ static int fib_netdev_event(struct notifier_block *this, unsigned long event, vo
97735 #ifdef CONFIG_IP_ROUTE_MULTIPATH
97736 fib_sync_up(dev);
97737 #endif
97738 - atomic_inc(&net->ipv4.dev_addr_genid);
97739 + atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
97740 rt_cache_flush(net);
97741 break;
97742 case NETDEV_DOWN:
97743 diff --git a/net/ipv4/fib_semantics.c b/net/ipv4/fib_semantics.c
97744 index e63f47a..e5c531d 100644
97745 --- a/net/ipv4/fib_semantics.c
97746 +++ b/net/ipv4/fib_semantics.c
97747 @@ -766,7 +766,7 @@ __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh)
97748 nh->nh_saddr = inet_select_addr(nh->nh_dev,
97749 nh->nh_gw,
97750 nh->nh_parent->fib_scope);
97751 - nh->nh_saddr_genid = atomic_read(&net->ipv4.dev_addr_genid);
97752 + nh->nh_saddr_genid = atomic_read_unchecked(&net->ipv4.dev_addr_genid);
97753
97754 return nh->nh_saddr;
97755 }
97756 diff --git a/net/ipv4/inet_connection_sock.c b/net/ipv4/inet_connection_sock.c
97757 index fc0e649..febfa65 100644
97758 --- a/net/ipv4/inet_connection_sock.c
97759 +++ b/net/ipv4/inet_connection_sock.c
97760 @@ -29,7 +29,7 @@ const char inet_csk_timer_bug_msg[] = "inet_csk BUG: unknown timer value\n";
97761 EXPORT_SYMBOL(inet_csk_timer_bug_msg);
97762 #endif
97763
97764 -unsigned long *sysctl_local_reserved_ports;
97765 +unsigned long sysctl_local_reserved_ports[65536 / 8 / sizeof(unsigned long)];
97766 EXPORT_SYMBOL(sysctl_local_reserved_ports);
97767
97768 void inet_get_local_port_range(struct net *net, int *low, int *high)
97769 diff --git a/net/ipv4/inet_hashtables.c b/net/ipv4/inet_hashtables.c
97770 index 8b9cf27..0d8d592 100644
97771 --- a/net/ipv4/inet_hashtables.c
97772 +++ b/net/ipv4/inet_hashtables.c
97773 @@ -18,6 +18,7 @@
97774 #include <linux/sched.h>
97775 #include <linux/slab.h>
97776 #include <linux/wait.h>
97777 +#include <linux/security.h>
97778
97779 #include <net/inet_connection_sock.h>
97780 #include <net/inet_hashtables.h>
97781 @@ -49,6 +50,8 @@ static unsigned int inet_sk_ehashfn(const struct sock *sk)
97782 return inet_ehashfn(net, laddr, lport, faddr, fport);
97783 }
97784
97785 +extern void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet);
97786 +
97787 /*
97788 * Allocate and initialize a new local port bind bucket.
97789 * The bindhash mutex for snum's hash chain must be held here.
97790 @@ -554,6 +557,8 @@ ok:
97791 twrefcnt += inet_twsk_bind_unhash(tw, hinfo);
97792 spin_unlock(&head->lock);
97793
97794 + gr_update_task_in_ip_table(current, inet_sk(sk));
97795 +
97796 if (tw) {
97797 inet_twsk_deschedule(tw, death_row);
97798 while (twrefcnt) {
97799 diff --git a/net/ipv4/inetpeer.c b/net/ipv4/inetpeer.c
97800 index 33d5537..da337a4 100644
97801 --- a/net/ipv4/inetpeer.c
97802 +++ b/net/ipv4/inetpeer.c
97803 @@ -503,8 +503,8 @@ relookup:
97804 if (p) {
97805 p->daddr = *daddr;
97806 atomic_set(&p->refcnt, 1);
97807 - atomic_set(&p->rid, 0);
97808 - atomic_set(&p->ip_id_count,
97809 + atomic_set_unchecked(&p->rid, 0);
97810 + atomic_set_unchecked(&p->ip_id_count,
97811 (daddr->family == AF_INET) ?
97812 secure_ip_id(daddr->addr.a4) :
97813 secure_ipv6_id(daddr->addr.a6));
97814 diff --git a/net/ipv4/ip_fragment.c b/net/ipv4/ip_fragment.c
97815 index 2481993..2d9a7a7 100644
97816 --- a/net/ipv4/ip_fragment.c
97817 +++ b/net/ipv4/ip_fragment.c
97818 @@ -283,7 +283,7 @@ static inline int ip_frag_too_far(struct ipq *qp)
97819 return 0;
97820
97821 start = qp->rid;
97822 - end = atomic_inc_return(&peer->rid);
97823 + end = atomic_inc_return_unchecked(&peer->rid);
97824 qp->rid = end;
97825
97826 rc = qp->q.fragments && (end - start) > max;
97827 @@ -760,12 +760,11 @@ static struct ctl_table ip4_frags_ctl_table[] = {
97828
97829 static int __net_init ip4_frags_ns_ctl_register(struct net *net)
97830 {
97831 - struct ctl_table *table;
97832 + ctl_table_no_const *table = NULL;
97833 struct ctl_table_header *hdr;
97834
97835 - table = ip4_frags_ns_ctl_table;
97836 if (!net_eq(net, &init_net)) {
97837 - table = kmemdup(table, sizeof(ip4_frags_ns_ctl_table), GFP_KERNEL);
97838 + table = kmemdup(ip4_frags_ns_ctl_table, sizeof(ip4_frags_ns_ctl_table), GFP_KERNEL);
97839 if (table == NULL)
97840 goto err_alloc;
97841
97842 @@ -776,9 +775,10 @@ static int __net_init ip4_frags_ns_ctl_register(struct net *net)
97843 /* Don't export sysctls to unprivileged users */
97844 if (net->user_ns != &init_user_ns)
97845 table[0].procname = NULL;
97846 - }
97847 + hdr = register_net_sysctl(net, "net/ipv4", table);
97848 + } else
97849 + hdr = register_net_sysctl(net, "net/ipv4", ip4_frags_ns_ctl_table);
97850
97851 - hdr = register_net_sysctl(net, "net/ipv4", table);
97852 if (hdr == NULL)
97853 goto err_reg;
97854
97855 @@ -786,8 +786,7 @@ static int __net_init ip4_frags_ns_ctl_register(struct net *net)
97856 return 0;
97857
97858 err_reg:
97859 - if (!net_eq(net, &init_net))
97860 - kfree(table);
97861 + kfree(table);
97862 err_alloc:
97863 return -ENOMEM;
97864 }
97865 diff --git a/net/ipv4/ip_gre.c b/net/ipv4/ip_gre.c
97866 index d306360..1c1a1f1 100644
97867 --- a/net/ipv4/ip_gre.c
97868 +++ b/net/ipv4/ip_gre.c
97869 @@ -115,7 +115,7 @@ static bool log_ecn_error = true;
97870 module_param(log_ecn_error, bool, 0644);
97871 MODULE_PARM_DESC(log_ecn_error, "Log packets received with corrupted ECN");
97872
97873 -static struct rtnl_link_ops ipgre_link_ops __read_mostly;
97874 +static struct rtnl_link_ops ipgre_link_ops;
97875 static int ipgre_tunnel_init(struct net_device *dev);
97876
97877 static int ipgre_net_id __read_mostly;
97878 @@ -732,7 +732,7 @@ static const struct nla_policy ipgre_policy[IFLA_GRE_MAX + 1] = {
97879 [IFLA_GRE_PMTUDISC] = { .type = NLA_U8 },
97880 };
97881
97882 -static struct rtnl_link_ops ipgre_link_ops __read_mostly = {
97883 +static struct rtnl_link_ops ipgre_link_ops = {
97884 .kind = "gre",
97885 .maxtype = IFLA_GRE_MAX,
97886 .policy = ipgre_policy,
97887 @@ -746,7 +746,7 @@ static struct rtnl_link_ops ipgre_link_ops __read_mostly = {
97888 .fill_info = ipgre_fill_info,
97889 };
97890
97891 -static struct rtnl_link_ops ipgre_tap_ops __read_mostly = {
97892 +static struct rtnl_link_ops ipgre_tap_ops = {
97893 .kind = "gretap",
97894 .maxtype = IFLA_GRE_MAX,
97895 .policy = ipgre_policy,
97896 diff --git a/net/ipv4/ip_sockglue.c b/net/ipv4/ip_sockglue.c
97897 index ddf32a6..3fdeea9 100644
97898 --- a/net/ipv4/ip_sockglue.c
97899 +++ b/net/ipv4/ip_sockglue.c
97900 @@ -1172,7 +1172,8 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
97901 len = min_t(unsigned int, len, opt->optlen);
97902 if (put_user(len, optlen))
97903 return -EFAULT;
97904 - if (copy_to_user(optval, opt->__data, len))
97905 + if ((len > (sizeof(optbuf) - sizeof(struct ip_options))) ||
97906 + copy_to_user(optval, opt->__data, len))
97907 return -EFAULT;
97908 return 0;
97909 }
97910 @@ -1303,7 +1304,7 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
97911 if (sk->sk_type != SOCK_STREAM)
97912 return -ENOPROTOOPT;
97913
97914 - msg.msg_control = optval;
97915 + msg.msg_control = (void __force_kernel *)optval;
97916 msg.msg_controllen = len;
97917 msg.msg_flags = flags;
97918
97919 diff --git a/net/ipv4/ip_vti.c b/net/ipv4/ip_vti.c
97920 index 52b802a..b725179 100644
97921 --- a/net/ipv4/ip_vti.c
97922 +++ b/net/ipv4/ip_vti.c
97923 @@ -44,7 +44,7 @@
97924 #include <net/net_namespace.h>
97925 #include <net/netns/generic.h>
97926
97927 -static struct rtnl_link_ops vti_link_ops __read_mostly;
97928 +static struct rtnl_link_ops vti_link_ops;
97929
97930 static int vti_net_id __read_mostly;
97931 static int vti_tunnel_init(struct net_device *dev);
97932 @@ -360,7 +360,7 @@ static const struct nla_policy vti_policy[IFLA_VTI_MAX + 1] = {
97933 [IFLA_VTI_REMOTE] = { .len = FIELD_SIZEOF(struct iphdr, daddr) },
97934 };
97935
97936 -static struct rtnl_link_ops vti_link_ops __read_mostly = {
97937 +static struct rtnl_link_ops vti_link_ops = {
97938 .kind = "vti",
97939 .maxtype = IFLA_VTI_MAX,
97940 .policy = vti_policy,
97941 diff --git a/net/ipv4/ipconfig.c b/net/ipv4/ipconfig.c
97942 index efa1138..20dbba0 100644
97943 --- a/net/ipv4/ipconfig.c
97944 +++ b/net/ipv4/ipconfig.c
97945 @@ -334,7 +334,7 @@ static int __init ic_devinet_ioctl(unsigned int cmd, struct ifreq *arg)
97946
97947 mm_segment_t oldfs = get_fs();
97948 set_fs(get_ds());
97949 - res = devinet_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
97950 + res = devinet_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
97951 set_fs(oldfs);
97952 return res;
97953 }
97954 @@ -345,7 +345,7 @@ static int __init ic_dev_ioctl(unsigned int cmd, struct ifreq *arg)
97955
97956 mm_segment_t oldfs = get_fs();
97957 set_fs(get_ds());
97958 - res = dev_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
97959 + res = dev_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
97960 set_fs(oldfs);
97961 return res;
97962 }
97963 @@ -356,7 +356,7 @@ static int __init ic_route_ioctl(unsigned int cmd, struct rtentry *arg)
97964
97965 mm_segment_t oldfs = get_fs();
97966 set_fs(get_ds());
97967 - res = ip_rt_ioctl(&init_net, cmd, (void __user *) arg);
97968 + res = ip_rt_ioctl(&init_net, cmd, (void __force_user *) arg);
97969 set_fs(oldfs);
97970 return res;
97971 }
97972 diff --git a/net/ipv4/ipip.c b/net/ipv4/ipip.c
97973 index fe3e9f7..4956990 100644
97974 --- a/net/ipv4/ipip.c
97975 +++ b/net/ipv4/ipip.c
97976 @@ -124,7 +124,7 @@ MODULE_PARM_DESC(log_ecn_error, "Log packets received with corrupted ECN");
97977 static int ipip_net_id __read_mostly;
97978
97979 static int ipip_tunnel_init(struct net_device *dev);
97980 -static struct rtnl_link_ops ipip_link_ops __read_mostly;
97981 +static struct rtnl_link_ops ipip_link_ops;
97982
97983 static int ipip_err(struct sk_buff *skb, u32 info)
97984 {
97985 @@ -409,7 +409,7 @@ static const struct nla_policy ipip_policy[IFLA_IPTUN_MAX + 1] = {
97986 [IFLA_IPTUN_PMTUDISC] = { .type = NLA_U8 },
97987 };
97988
97989 -static struct rtnl_link_ops ipip_link_ops __read_mostly = {
97990 +static struct rtnl_link_ops ipip_link_ops = {
97991 .kind = "ipip",
97992 .maxtype = IFLA_IPTUN_MAX,
97993 .policy = ipip_policy,
97994 diff --git a/net/ipv4/netfilter/arp_tables.c b/net/ipv4/netfilter/arp_tables.c
97995 index 59da7cd..e318de1 100644
97996 --- a/net/ipv4/netfilter/arp_tables.c
97997 +++ b/net/ipv4/netfilter/arp_tables.c
97998 @@ -885,14 +885,14 @@ static int compat_table_info(const struct xt_table_info *info,
97999 #endif
98000
98001 static int get_info(struct net *net, void __user *user,
98002 - const int *len, int compat)
98003 + int len, int compat)
98004 {
98005 char name[XT_TABLE_MAXNAMELEN];
98006 struct xt_table *t;
98007 int ret;
98008
98009 - if (*len != sizeof(struct arpt_getinfo)) {
98010 - duprintf("length %u != %Zu\n", *len,
98011 + if (len != sizeof(struct arpt_getinfo)) {
98012 + duprintf("length %u != %Zu\n", len,
98013 sizeof(struct arpt_getinfo));
98014 return -EINVAL;
98015 }
98016 @@ -929,7 +929,7 @@ static int get_info(struct net *net, void __user *user,
98017 info.size = private->size;
98018 strcpy(info.name, name);
98019
98020 - if (copy_to_user(user, &info, *len) != 0)
98021 + if (copy_to_user(user, &info, len) != 0)
98022 ret = -EFAULT;
98023 else
98024 ret = 0;
98025 @@ -1688,7 +1688,7 @@ static int compat_do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user,
98026
98027 switch (cmd) {
98028 case ARPT_SO_GET_INFO:
98029 - ret = get_info(sock_net(sk), user, len, 1);
98030 + ret = get_info(sock_net(sk), user, *len, 1);
98031 break;
98032 case ARPT_SO_GET_ENTRIES:
98033 ret = compat_get_entries(sock_net(sk), user, len);
98034 @@ -1733,7 +1733,7 @@ static int do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len
98035
98036 switch (cmd) {
98037 case ARPT_SO_GET_INFO:
98038 - ret = get_info(sock_net(sk), user, len, 0);
98039 + ret = get_info(sock_net(sk), user, *len, 0);
98040 break;
98041
98042 case ARPT_SO_GET_ENTRIES:
98043 diff --git a/net/ipv4/netfilter/ip_tables.c b/net/ipv4/netfilter/ip_tables.c
98044 index 718dfbd..cef4152 100644
98045 --- a/net/ipv4/netfilter/ip_tables.c
98046 +++ b/net/ipv4/netfilter/ip_tables.c
98047 @@ -1073,14 +1073,14 @@ static int compat_table_info(const struct xt_table_info *info,
98048 #endif
98049
98050 static int get_info(struct net *net, void __user *user,
98051 - const int *len, int compat)
98052 + int len, int compat)
98053 {
98054 char name[XT_TABLE_MAXNAMELEN];
98055 struct xt_table *t;
98056 int ret;
98057
98058 - if (*len != sizeof(struct ipt_getinfo)) {
98059 - duprintf("length %u != %zu\n", *len,
98060 + if (len != sizeof(struct ipt_getinfo)) {
98061 + duprintf("length %u != %zu\n", len,
98062 sizeof(struct ipt_getinfo));
98063 return -EINVAL;
98064 }
98065 @@ -1117,7 +1117,7 @@ static int get_info(struct net *net, void __user *user,
98066 info.size = private->size;
98067 strcpy(info.name, name);
98068
98069 - if (copy_to_user(user, &info, *len) != 0)
98070 + if (copy_to_user(user, &info, len) != 0)
98071 ret = -EFAULT;
98072 else
98073 ret = 0;
98074 @@ -1971,7 +1971,7 @@ compat_do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
98075
98076 switch (cmd) {
98077 case IPT_SO_GET_INFO:
98078 - ret = get_info(sock_net(sk), user, len, 1);
98079 + ret = get_info(sock_net(sk), user, *len, 1);
98080 break;
98081 case IPT_SO_GET_ENTRIES:
98082 ret = compat_get_entries(sock_net(sk), user, len);
98083 @@ -2018,7 +2018,7 @@ do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
98084
98085 switch (cmd) {
98086 case IPT_SO_GET_INFO:
98087 - ret = get_info(sock_net(sk), user, len, 0);
98088 + ret = get_info(sock_net(sk), user, *len, 0);
98089 break;
98090
98091 case IPT_SO_GET_ENTRIES:
98092 diff --git a/net/ipv4/ping.c b/net/ipv4/ping.c
98093 index 242e7f4..76cc7ee 100644
98094 --- a/net/ipv4/ping.c
98095 +++ b/net/ipv4/ping.c
98096 @@ -55,7 +55,7 @@
98097
98098
98099 struct ping_table ping_table;
98100 -struct pingv6_ops pingv6_ops;
98101 +struct pingv6_ops *pingv6_ops;
98102 EXPORT_SYMBOL_GPL(pingv6_ops);
98103
98104 static u16 ping_port_rover;
98105 @@ -251,23 +251,28 @@ int ping_init_sock(struct sock *sk)
98106 struct group_info *group_info = get_current_groups();
98107 int i, j, count = group_info->ngroups;
98108 kgid_t low, high;
98109 + int ret = 0;
98110
98111 inet_get_ping_group_range_net(net, &low, &high);
98112 if (gid_lte(low, group) && gid_lte(group, high))
98113 - return 0;
98114 + goto out_release_group;
98115
98116 for (i = 0; i < group_info->nblocks; i++) {
98117 int cp_count = min_t(int, NGROUPS_PER_BLOCK, count);
98118 for (j = 0; j < cp_count; j++) {
98119 kgid_t gid = group_info->blocks[i][j];
98120 if (gid_lte(low, gid) && gid_lte(gid, high))
98121 - return 0;
98122 + goto out_release_group;
98123 }
98124
98125 count -= cp_count;
98126 }
98127
98128 - return -EACCES;
98129 + ret = -EACCES;
98130 +
98131 +out_release_group:
98132 + put_group_info(group_info);
98133 + return ret;
98134 }
98135 EXPORT_SYMBOL_GPL(ping_init_sock);
98136
98137 @@ -334,7 +339,7 @@ static int ping_check_bind_addr(struct sock *sk, struct inet_sock *isk,
98138 return -ENODEV;
98139 }
98140 }
98141 - has_addr = pingv6_ops.ipv6_chk_addr(net, &addr->sin6_addr, dev,
98142 + has_addr = pingv6_ops->ipv6_chk_addr(net, &addr->sin6_addr, dev,
98143 scoped);
98144 rcu_read_unlock();
98145
98146 @@ -542,7 +547,7 @@ void ping_err(struct sk_buff *skb, int offset, u32 info)
98147 }
98148 #if IS_ENABLED(CONFIG_IPV6)
98149 } else if (skb->protocol == htons(ETH_P_IPV6)) {
98150 - harderr = pingv6_ops.icmpv6_err_convert(type, code, &err);
98151 + harderr = pingv6_ops->icmpv6_err_convert(type, code, &err);
98152 #endif
98153 }
98154
98155 @@ -560,7 +565,7 @@ void ping_err(struct sk_buff *skb, int offset, u32 info)
98156 info, (u8 *)icmph);
98157 #if IS_ENABLED(CONFIG_IPV6)
98158 } else if (family == AF_INET6) {
98159 - pingv6_ops.ipv6_icmp_error(sk, skb, err, 0,
98160 + pingv6_ops->ipv6_icmp_error(sk, skb, err, 0,
98161 info, (u8 *)icmph);
98162 #endif
98163 }
98164 @@ -830,6 +835,8 @@ int ping_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
98165 {
98166 struct inet_sock *isk = inet_sk(sk);
98167 int family = sk->sk_family;
98168 + struct sockaddr_in *sin;
98169 + struct sockaddr_in6 *sin6;
98170 struct sk_buff *skb;
98171 int copied, err;
98172
98173 @@ -839,12 +846,19 @@ int ping_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
98174 if (flags & MSG_OOB)
98175 goto out;
98176
98177 + if (addr_len) {
98178 + if (family == AF_INET)
98179 + *addr_len = sizeof(*sin);
98180 + else if (family == AF_INET6 && addr_len)
98181 + *addr_len = sizeof(*sin6);
98182 + }
98183 +
98184 if (flags & MSG_ERRQUEUE) {
98185 if (family == AF_INET) {
98186 return ip_recv_error(sk, msg, len, addr_len);
98187 #if IS_ENABLED(CONFIG_IPV6)
98188 } else if (family == AF_INET6) {
98189 - return pingv6_ops.ipv6_recv_error(sk, msg, len,
98190 + return pingv6_ops->ipv6_recv_error(sk, msg, len,
98191 addr_len);
98192 #endif
98193 }
98194 @@ -876,7 +890,6 @@ int ping_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
98195 sin->sin_port = 0 /* skb->h.uh->source */;
98196 sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
98197 memset(sin->sin_zero, 0, sizeof(sin->sin_zero));
98198 - *addr_len = sizeof(*sin);
98199 }
98200
98201 if (isk->cmsg_flags)
98202 @@ -899,11 +912,10 @@ int ping_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
98203 sin6->sin6_scope_id =
98204 ipv6_iface_scope_id(&sin6->sin6_addr,
98205 IP6CB(skb)->iif);
98206 - *addr_len = sizeof(*sin6);
98207 }
98208
98209 if (inet6_sk(sk)->rxopt.all)
98210 - pingv6_ops.ip6_datagram_recv_ctl(sk, msg, skb);
98211 + pingv6_ops->ip6_datagram_recv_ctl(sk, msg, skb);
98212 #endif
98213 } else {
98214 BUG();
98215 @@ -1093,7 +1105,7 @@ static void ping_v4_format_sock(struct sock *sp, struct seq_file *f,
98216 from_kuid_munged(seq_user_ns(f), sock_i_uid(sp)),
98217 0, sock_i_ino(sp),
98218 atomic_read(&sp->sk_refcnt), sp,
98219 - atomic_read(&sp->sk_drops));
98220 + atomic_read_unchecked(&sp->sk_drops));
98221 }
98222
98223 static int ping_v4_seq_show(struct seq_file *seq, void *v)
98224 diff --git a/net/ipv4/raw.c b/net/ipv4/raw.c
98225 index 23c3e5b..cdb8b36 100644
98226 --- a/net/ipv4/raw.c
98227 +++ b/net/ipv4/raw.c
98228 @@ -311,7 +311,7 @@ static int raw_rcv_skb(struct sock *sk, struct sk_buff *skb)
98229 int raw_rcv(struct sock *sk, struct sk_buff *skb)
98230 {
98231 if (!xfrm4_policy_check(sk, XFRM_POLICY_IN, skb)) {
98232 - atomic_inc(&sk->sk_drops);
98233 + atomic_inc_unchecked(&sk->sk_drops);
98234 kfree_skb(skb);
98235 return NET_RX_DROP;
98236 }
98237 @@ -696,6 +696,9 @@ static int raw_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
98238 if (flags & MSG_OOB)
98239 goto out;
98240
98241 + if (addr_len)
98242 + *addr_len = sizeof(*sin);
98243 +
98244 if (flags & MSG_ERRQUEUE) {
98245 err = ip_recv_error(sk, msg, len, addr_len);
98246 goto out;
98247 @@ -723,7 +726,6 @@ static int raw_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
98248 sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
98249 sin->sin_port = 0;
98250 memset(&sin->sin_zero, 0, sizeof(sin->sin_zero));
98251 - *addr_len = sizeof(*sin);
98252 }
98253 if (inet->cmsg_flags)
98254 ip_cmsg_recv(msg, skb);
98255 @@ -748,16 +750,20 @@ static int raw_init(struct sock *sk)
98256
98257 static int raw_seticmpfilter(struct sock *sk, char __user *optval, int optlen)
98258 {
98259 + struct icmp_filter filter;
98260 +
98261 if (optlen > sizeof(struct icmp_filter))
98262 optlen = sizeof(struct icmp_filter);
98263 - if (copy_from_user(&raw_sk(sk)->filter, optval, optlen))
98264 + if (copy_from_user(&filter, optval, optlen))
98265 return -EFAULT;
98266 + raw_sk(sk)->filter = filter;
98267 return 0;
98268 }
98269
98270 static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *optlen)
98271 {
98272 int len, ret = -EFAULT;
98273 + struct icmp_filter filter;
98274
98275 if (get_user(len, optlen))
98276 goto out;
98277 @@ -767,8 +773,8 @@ static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *o
98278 if (len > sizeof(struct icmp_filter))
98279 len = sizeof(struct icmp_filter);
98280 ret = -EFAULT;
98281 - if (put_user(len, optlen) ||
98282 - copy_to_user(optval, &raw_sk(sk)->filter, len))
98283 + filter = raw_sk(sk)->filter;
98284 + if (put_user(len, optlen) || len > sizeof filter || copy_to_user(optval, &filter, len))
98285 goto out;
98286 ret = 0;
98287 out: return ret;
98288 @@ -997,7 +1003,7 @@ static void raw_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
98289 0, 0L, 0,
98290 from_kuid_munged(seq_user_ns(seq), sock_i_uid(sp)),
98291 0, sock_i_ino(sp),
98292 - atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
98293 + atomic_read(&sp->sk_refcnt), sp, atomic_read_unchecked(&sp->sk_drops));
98294 }
98295
98296 static int raw_seq_show(struct seq_file *seq, void *v)
98297 diff --git a/net/ipv4/route.c b/net/ipv4/route.c
98298 index e611651f..0c17263 100644
98299 --- a/net/ipv4/route.c
98300 +++ b/net/ipv4/route.c
98301 @@ -2621,34 +2621,34 @@ static struct ctl_table ipv4_route_flush_table[] = {
98302 .maxlen = sizeof(int),
98303 .mode = 0200,
98304 .proc_handler = ipv4_sysctl_rtcache_flush,
98305 + .extra1 = &init_net,
98306 },
98307 { },
98308 };
98309
98310 static __net_init int sysctl_route_net_init(struct net *net)
98311 {
98312 - struct ctl_table *tbl;
98313 + ctl_table_no_const *tbl = NULL;
98314
98315 - tbl = ipv4_route_flush_table;
98316 if (!net_eq(net, &init_net)) {
98317 - tbl = kmemdup(tbl, sizeof(ipv4_route_flush_table), GFP_KERNEL);
98318 + tbl = kmemdup(ipv4_route_flush_table, sizeof(ipv4_route_flush_table), GFP_KERNEL);
98319 if (tbl == NULL)
98320 goto err_dup;
98321
98322 /* Don't export sysctls to unprivileged users */
98323 if (net->user_ns != &init_user_ns)
98324 tbl[0].procname = NULL;
98325 - }
98326 - tbl[0].extra1 = net;
98327 + tbl[0].extra1 = net;
98328 + net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", tbl);
98329 + } else
98330 + net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", ipv4_route_flush_table);
98331
98332 - net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", tbl);
98333 if (net->ipv4.route_hdr == NULL)
98334 goto err_reg;
98335 return 0;
98336
98337 err_reg:
98338 - if (tbl != ipv4_route_flush_table)
98339 - kfree(tbl);
98340 + kfree(tbl);
98341 err_dup:
98342 return -ENOMEM;
98343 }
98344 @@ -2671,8 +2671,8 @@ static __net_initdata struct pernet_operations sysctl_route_ops = {
98345
98346 static __net_init int rt_genid_init(struct net *net)
98347 {
98348 - atomic_set(&net->ipv4.rt_genid, 0);
98349 - atomic_set(&net->fnhe_genid, 0);
98350 + atomic_set_unchecked(&net->ipv4.rt_genid, 0);
98351 + atomic_set_unchecked(&net->fnhe_genid, 0);
98352 get_random_bytes(&net->ipv4.dev_addr_genid,
98353 sizeof(net->ipv4.dev_addr_genid));
98354 return 0;
98355 diff --git a/net/ipv4/sysctl_net_ipv4.c b/net/ipv4/sysctl_net_ipv4.c
98356 index 3d69ec8..57207b4 100644
98357 --- a/net/ipv4/sysctl_net_ipv4.c
98358 +++ b/net/ipv4/sysctl_net_ipv4.c
98359 @@ -60,7 +60,7 @@ static int ipv4_local_port_range(struct ctl_table *table, int write,
98360 container_of(table->data, struct net, ipv4.sysctl_local_ports.range);
98361 int ret;
98362 int range[2];
98363 - struct ctl_table tmp = {
98364 + ctl_table_no_const tmp = {
98365 .data = &range,
98366 .maxlen = sizeof(range),
98367 .mode = table->mode,
98368 @@ -118,7 +118,7 @@ static int ipv4_ping_group_range(struct ctl_table *table, int write,
98369 int ret;
98370 gid_t urange[2];
98371 kgid_t low, high;
98372 - struct ctl_table tmp = {
98373 + ctl_table_no_const tmp = {
98374 .data = &urange,
98375 .maxlen = sizeof(urange),
98376 .mode = table->mode,
98377 @@ -149,7 +149,7 @@ static int proc_tcp_congestion_control(struct ctl_table *ctl, int write,
98378 void __user *buffer, size_t *lenp, loff_t *ppos)
98379 {
98380 char val[TCP_CA_NAME_MAX];
98381 - struct ctl_table tbl = {
98382 + ctl_table_no_const tbl = {
98383 .data = val,
98384 .maxlen = TCP_CA_NAME_MAX,
98385 };
98386 @@ -168,7 +168,7 @@ static int proc_tcp_available_congestion_control(struct ctl_table *ctl,
98387 void __user *buffer, size_t *lenp,
98388 loff_t *ppos)
98389 {
98390 - struct ctl_table tbl = { .maxlen = TCP_CA_BUF_MAX, };
98391 + ctl_table_no_const tbl = { .maxlen = TCP_CA_BUF_MAX, };
98392 int ret;
98393
98394 tbl.data = kmalloc(tbl.maxlen, GFP_USER);
98395 @@ -185,7 +185,7 @@ static int proc_allowed_congestion_control(struct ctl_table *ctl,
98396 void __user *buffer, size_t *lenp,
98397 loff_t *ppos)
98398 {
98399 - struct ctl_table tbl = { .maxlen = TCP_CA_BUF_MAX };
98400 + ctl_table_no_const tbl = { .maxlen = TCP_CA_BUF_MAX };
98401 int ret;
98402
98403 tbl.data = kmalloc(tbl.maxlen, GFP_USER);
98404 @@ -204,7 +204,7 @@ static int proc_tcp_fastopen_key(struct ctl_table *ctl, int write,
98405 void __user *buffer, size_t *lenp,
98406 loff_t *ppos)
98407 {
98408 - struct ctl_table tbl = { .maxlen = (TCP_FASTOPEN_KEY_LENGTH * 2 + 10) };
98409 + ctl_table_no_const tbl = { .maxlen = (TCP_FASTOPEN_KEY_LENGTH * 2 + 10) };
98410 struct tcp_fastopen_context *ctxt;
98411 int ret;
98412 u32 user_key[4]; /* 16 bytes, matching TCP_FASTOPEN_KEY_LENGTH */
98413 @@ -445,7 +445,7 @@ static struct ctl_table ipv4_table[] = {
98414 },
98415 {
98416 .procname = "ip_local_reserved_ports",
98417 - .data = NULL, /* initialized in sysctl_ipv4_init */
98418 + .data = sysctl_local_reserved_ports,
98419 .maxlen = 65536,
98420 .mode = 0644,
98421 .proc_handler = proc_do_large_bitmap,
98422 @@ -827,13 +827,12 @@ static struct ctl_table ipv4_net_table[] = {
98423
98424 static __net_init int ipv4_sysctl_init_net(struct net *net)
98425 {
98426 - struct ctl_table *table;
98427 + ctl_table_no_const *table = NULL;
98428
98429 - table = ipv4_net_table;
98430 if (!net_eq(net, &init_net)) {
98431 int i;
98432
98433 - table = kmemdup(table, sizeof(ipv4_net_table), GFP_KERNEL);
98434 + table = kmemdup(ipv4_net_table, sizeof(ipv4_net_table), GFP_KERNEL);
98435 if (table == NULL)
98436 goto err_alloc;
98437
98438 @@ -856,15 +855,17 @@ static __net_init int ipv4_sysctl_init_net(struct net *net)
98439 net->ipv4.sysctl_local_ports.range[0] = 32768;
98440 net->ipv4.sysctl_local_ports.range[1] = 61000;
98441
98442 - net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", table);
98443 + if (!net_eq(net, &init_net))
98444 + net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", table);
98445 + else
98446 + net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", ipv4_net_table);
98447 if (net->ipv4.ipv4_hdr == NULL)
98448 goto err_reg;
98449
98450 return 0;
98451
98452 err_reg:
98453 - if (!net_eq(net, &init_net))
98454 - kfree(table);
98455 + kfree(table);
98456 err_alloc:
98457 return -ENOMEM;
98458 }
98459 @@ -886,16 +887,6 @@ static __net_initdata struct pernet_operations ipv4_sysctl_ops = {
98460 static __init int sysctl_ipv4_init(void)
98461 {
98462 struct ctl_table_header *hdr;
98463 - struct ctl_table *i;
98464 -
98465 - for (i = ipv4_table; i->procname; i++) {
98466 - if (strcmp(i->procname, "ip_local_reserved_ports") == 0) {
98467 - i->data = sysctl_local_reserved_ports;
98468 - break;
98469 - }
98470 - }
98471 - if (!i->procname)
98472 - return -EINVAL;
98473
98474 hdr = register_net_sysctl(&init_net, "net/ipv4", ipv4_table);
98475 if (hdr == NULL)
98476 diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c
98477 index c53b7f3..a89aadd 100644
98478 --- a/net/ipv4/tcp_input.c
98479 +++ b/net/ipv4/tcp_input.c
98480 @@ -759,7 +759,7 @@ static void tcp_update_pacing_rate(struct sock *sk)
98481 * without any lock. We want to make sure compiler wont store
98482 * intermediate values in this location.
98483 */
98484 - ACCESS_ONCE(sk->sk_pacing_rate) = min_t(u64, rate,
98485 + ACCESS_ONCE_RW(sk->sk_pacing_rate) = min_t(u64, rate,
98486 sk->sk_max_pacing_rate);
98487 }
98488
98489 @@ -4482,7 +4482,7 @@ static struct sk_buff *tcp_collapse_one(struct sock *sk, struct sk_buff *skb,
98490 * simplifies code)
98491 */
98492 static void
98493 -tcp_collapse(struct sock *sk, struct sk_buff_head *list,
98494 +__intentional_overflow(5,6) tcp_collapse(struct sock *sk, struct sk_buff_head *list,
98495 struct sk_buff *head, struct sk_buff *tail,
98496 u32 start, u32 end)
98497 {
98498 @@ -5559,6 +5559,7 @@ discard:
98499 tcp_paws_reject(&tp->rx_opt, 0))
98500 goto discard_and_undo;
98501
98502 +#ifndef CONFIG_GRKERNSEC_NO_SIMULT_CONNECT
98503 if (th->syn) {
98504 /* We see SYN without ACK. It is attempt of
98505 * simultaneous connect with crossed SYNs.
98506 @@ -5609,6 +5610,7 @@ discard:
98507 goto discard;
98508 #endif
98509 }
98510 +#endif
98511 /* "fifth, if neither of the SYN or RST bits is set then
98512 * drop the segment and return."
98513 */
98514 @@ -5655,7 +5657,7 @@ int tcp_rcv_state_process(struct sock *sk, struct sk_buff *skb,
98515 goto discard;
98516
98517 if (th->syn) {
98518 - if (th->fin)
98519 + if (th->fin || th->urg || th->psh)
98520 goto discard;
98521 if (icsk->icsk_af_ops->conn_request(sk, skb) < 0)
98522 return 1;
98523 diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c
98524 index 1d7b9dd..66749f8 100644
98525 --- a/net/ipv4/tcp_ipv4.c
98526 +++ b/net/ipv4/tcp_ipv4.c
98527 @@ -91,6 +91,10 @@ int sysctl_tcp_low_latency __read_mostly;
98528 EXPORT_SYMBOL(sysctl_tcp_low_latency);
98529
98530
98531 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
98532 +extern int grsec_enable_blackhole;
98533 +#endif
98534 +
98535 #ifdef CONFIG_TCP_MD5SIG
98536 static int tcp_v4_md5_hash_hdr(char *md5_hash, const struct tcp_md5sig_key *key,
98537 __be32 daddr, __be32 saddr, const struct tcphdr *th);
98538 @@ -1830,6 +1834,9 @@ int tcp_v4_do_rcv(struct sock *sk, struct sk_buff *skb)
98539 return 0;
98540
98541 reset:
98542 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
98543 + if (!grsec_enable_blackhole)
98544 +#endif
98545 tcp_v4_send_reset(rsk, skb);
98546 discard:
98547 kfree_skb(skb);
98548 @@ -1975,12 +1982,19 @@ int tcp_v4_rcv(struct sk_buff *skb)
98549 TCP_SKB_CB(skb)->sacked = 0;
98550
98551 sk = __inet_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
98552 - if (!sk)
98553 + if (!sk) {
98554 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
98555 + ret = 1;
98556 +#endif
98557 goto no_tcp_socket;
98558 -
98559 + }
98560 process:
98561 - if (sk->sk_state == TCP_TIME_WAIT)
98562 + if (sk->sk_state == TCP_TIME_WAIT) {
98563 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
98564 + ret = 2;
98565 +#endif
98566 goto do_time_wait;
98567 + }
98568
98569 if (unlikely(iph->ttl < inet_sk(sk)->min_ttl)) {
98570 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
98571 @@ -2034,6 +2048,10 @@ csum_error:
98572 bad_packet:
98573 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
98574 } else {
98575 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
98576 + if (!grsec_enable_blackhole || (ret == 1 &&
98577 + (skb->dev->flags & IFF_LOOPBACK)))
98578 +#endif
98579 tcp_v4_send_reset(NULL, skb);
98580 }
98581
98582 diff --git a/net/ipv4/tcp_minisocks.c b/net/ipv4/tcp_minisocks.c
98583 index 97b6841..0893357 100644
98584 --- a/net/ipv4/tcp_minisocks.c
98585 +++ b/net/ipv4/tcp_minisocks.c
98586 @@ -27,6 +27,10 @@
98587 #include <net/inet_common.h>
98588 #include <net/xfrm.h>
98589
98590 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
98591 +extern int grsec_enable_blackhole;
98592 +#endif
98593 +
98594 int sysctl_tcp_syncookies __read_mostly = 1;
98595 EXPORT_SYMBOL(sysctl_tcp_syncookies);
98596
98597 @@ -708,7 +712,10 @@ embryonic_reset:
98598 * avoid becoming vulnerable to outside attack aiming at
98599 * resetting legit local connections.
98600 */
98601 - req->rsk_ops->send_reset(sk, skb);
98602 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
98603 + if (!grsec_enable_blackhole)
98604 +#endif
98605 + req->rsk_ops->send_reset(sk, skb);
98606 } else if (fastopen) { /* received a valid RST pkt */
98607 reqsk_fastopen_remove(sk, req, true);
98608 tcp_reset(sk);
98609 diff --git a/net/ipv4/tcp_probe.c b/net/ipv4/tcp_probe.c
98610 index 8b97d71..9d7ccf5 100644
98611 --- a/net/ipv4/tcp_probe.c
98612 +++ b/net/ipv4/tcp_probe.c
98613 @@ -238,7 +238,7 @@ static ssize_t tcpprobe_read(struct file *file, char __user *buf,
98614 if (cnt + width >= len)
98615 break;
98616
98617 - if (copy_to_user(buf + cnt, tbuf, width))
98618 + if (width > sizeof tbuf || copy_to_user(buf + cnt, tbuf, width))
98619 return -EFAULT;
98620 cnt += width;
98621 }
98622 diff --git a/net/ipv4/tcp_timer.c b/net/ipv4/tcp_timer.c
98623 index 64f0354..a81b39d 100644
98624 --- a/net/ipv4/tcp_timer.c
98625 +++ b/net/ipv4/tcp_timer.c
98626 @@ -22,6 +22,10 @@
98627 #include <linux/gfp.h>
98628 #include <net/tcp.h>
98629
98630 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
98631 +extern int grsec_lastack_retries;
98632 +#endif
98633 +
98634 int sysctl_tcp_syn_retries __read_mostly = TCP_SYN_RETRIES;
98635 int sysctl_tcp_synack_retries __read_mostly = TCP_SYNACK_RETRIES;
98636 int sysctl_tcp_keepalive_time __read_mostly = TCP_KEEPALIVE_TIME;
98637 @@ -189,6 +193,13 @@ static int tcp_write_timeout(struct sock *sk)
98638 }
98639 }
98640
98641 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
98642 + if ((sk->sk_state == TCP_LAST_ACK) &&
98643 + (grsec_lastack_retries > 0) &&
98644 + (grsec_lastack_retries < retry_until))
98645 + retry_until = grsec_lastack_retries;
98646 +#endif
98647 +
98648 if (retransmits_timed_out(sk, retry_until,
98649 syn_set ? 0 : icsk->icsk_user_timeout, syn_set)) {
98650 /* Has it gone just too far? */
98651 diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c
98652 index a7e4729..2758946 100644
98653 --- a/net/ipv4/udp.c
98654 +++ b/net/ipv4/udp.c
98655 @@ -87,6 +87,7 @@
98656 #include <linux/types.h>
98657 #include <linux/fcntl.h>
98658 #include <linux/module.h>
98659 +#include <linux/security.h>
98660 #include <linux/socket.h>
98661 #include <linux/sockios.h>
98662 #include <linux/igmp.h>
98663 @@ -113,6 +114,10 @@
98664 #include <net/busy_poll.h>
98665 #include "udp_impl.h"
98666
98667 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
98668 +extern int grsec_enable_blackhole;
98669 +#endif
98670 +
98671 struct udp_table udp_table __read_mostly;
98672 EXPORT_SYMBOL(udp_table);
98673
98674 @@ -615,6 +620,9 @@ found:
98675 return s;
98676 }
98677
98678 +extern int gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb);
98679 +extern int gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr);
98680 +
98681 /*
98682 * This routine is called by the ICMP module when it gets some
98683 * sort of error condition. If err < 0 then the socket should
98684 @@ -914,9 +922,18 @@ int udp_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
98685 dport = usin->sin_port;
98686 if (dport == 0)
98687 return -EINVAL;
98688 +
98689 + err = gr_search_udp_sendmsg(sk, usin);
98690 + if (err)
98691 + return err;
98692 } else {
98693 if (sk->sk_state != TCP_ESTABLISHED)
98694 return -EDESTADDRREQ;
98695 +
98696 + err = gr_search_udp_sendmsg(sk, NULL);
98697 + if (err)
98698 + return err;
98699 +
98700 daddr = inet->inet_daddr;
98701 dport = inet->inet_dport;
98702 /* Open fast path for connected socket.
98703 @@ -1163,7 +1180,7 @@ static unsigned int first_packet_length(struct sock *sk)
98704 IS_UDPLITE(sk));
98705 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
98706 IS_UDPLITE(sk));
98707 - atomic_inc(&sk->sk_drops);
98708 + atomic_inc_unchecked(&sk->sk_drops);
98709 __skb_unlink(skb, rcvq);
98710 __skb_queue_tail(&list_kill, skb);
98711 }
98712 @@ -1234,6 +1251,12 @@ int udp_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
98713 int is_udplite = IS_UDPLITE(sk);
98714 bool slow;
98715
98716 + /*
98717 + * Check any passed addresses
98718 + */
98719 + if (addr_len)
98720 + *addr_len = sizeof(*sin);
98721 +
98722 if (flags & MSG_ERRQUEUE)
98723 return ip_recv_error(sk, msg, len, addr_len);
98724
98725 @@ -1243,6 +1266,10 @@ try_again:
98726 if (!skb)
98727 goto out;
98728
98729 + err = gr_search_udp_recvmsg(sk, skb);
98730 + if (err)
98731 + goto out_free;
98732 +
98733 ulen = skb->len - sizeof(struct udphdr);
98734 copied = len;
98735 if (copied > ulen)
98736 @@ -1276,7 +1303,7 @@ try_again:
98737 if (unlikely(err)) {
98738 trace_kfree_skb(skb, udp_recvmsg);
98739 if (!peeked) {
98740 - atomic_inc(&sk->sk_drops);
98741 + atomic_inc_unchecked(&sk->sk_drops);
98742 UDP_INC_STATS_USER(sock_net(sk),
98743 UDP_MIB_INERRORS, is_udplite);
98744 }
98745 @@ -1295,7 +1322,6 @@ try_again:
98746 sin->sin_port = udp_hdr(skb)->source;
98747 sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
98748 memset(sin->sin_zero, 0, sizeof(sin->sin_zero));
98749 - *addr_len = sizeof(*sin);
98750 }
98751 if (inet->cmsg_flags)
98752 ip_cmsg_recv(msg, skb);
98753 @@ -1566,7 +1592,7 @@ csum_error:
98754 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_CSUMERRORS, is_udplite);
98755 drop:
98756 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
98757 - atomic_inc(&sk->sk_drops);
98758 + atomic_inc_unchecked(&sk->sk_drops);
98759 kfree_skb(skb);
98760 return -1;
98761 }
98762 @@ -1585,7 +1611,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
98763 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
98764
98765 if (!skb1) {
98766 - atomic_inc(&sk->sk_drops);
98767 + atomic_inc_unchecked(&sk->sk_drops);
98768 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
98769 IS_UDPLITE(sk));
98770 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
98771 @@ -1786,6 +1812,9 @@ int __udp4_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
98772 goto csum_error;
98773
98774 UDP_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
98775 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
98776 + if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
98777 +#endif
98778 icmp_send(skb, ICMP_DEST_UNREACH, ICMP_PORT_UNREACH, 0);
98779
98780 /*
98781 @@ -2350,7 +2379,7 @@ static void udp4_format_sock(struct sock *sp, struct seq_file *f,
98782 from_kuid_munged(seq_user_ns(f), sock_i_uid(sp)),
98783 0, sock_i_ino(sp),
98784 atomic_read(&sp->sk_refcnt), sp,
98785 - atomic_read(&sp->sk_drops));
98786 + atomic_read_unchecked(&sp->sk_drops));
98787 }
98788
98789 int udp4_seq_show(struct seq_file *seq, void *v)
98790 diff --git a/net/ipv4/xfrm4_policy.c b/net/ipv4/xfrm4_policy.c
98791 index e1a6393..f634ce5 100644
98792 --- a/net/ipv4/xfrm4_policy.c
98793 +++ b/net/ipv4/xfrm4_policy.c
98794 @@ -186,11 +186,11 @@ _decode_session4(struct sk_buff *skb, struct flowi *fl, int reverse)
98795 fl4->flowi4_tos = iph->tos;
98796 }
98797
98798 -static inline int xfrm4_garbage_collect(struct dst_ops *ops)
98799 +static int xfrm4_garbage_collect(struct dst_ops *ops)
98800 {
98801 struct net *net = container_of(ops, struct net, xfrm.xfrm4_dst_ops);
98802
98803 - xfrm4_policy_afinfo.garbage_collect(net);
98804 + xfrm_garbage_collect_deferred(net);
98805 return (dst_entries_get_slow(ops) > ops->gc_thresh * 2);
98806 }
98807
98808 @@ -269,19 +269,18 @@ static struct ctl_table xfrm4_policy_table[] = {
98809
98810 static int __net_init xfrm4_net_init(struct net *net)
98811 {
98812 - struct ctl_table *table;
98813 + ctl_table_no_const *table = NULL;
98814 struct ctl_table_header *hdr;
98815
98816 - table = xfrm4_policy_table;
98817 if (!net_eq(net, &init_net)) {
98818 - table = kmemdup(table, sizeof(xfrm4_policy_table), GFP_KERNEL);
98819 + table = kmemdup(xfrm4_policy_table, sizeof(xfrm4_policy_table), GFP_KERNEL);
98820 if (!table)
98821 goto err_alloc;
98822
98823 table[0].data = &net->xfrm.xfrm4_dst_ops.gc_thresh;
98824 - }
98825 -
98826 - hdr = register_net_sysctl(net, "net/ipv4", table);
98827 + hdr = register_net_sysctl(net, "net/ipv4", table);
98828 + } else
98829 + hdr = register_net_sysctl(net, "net/ipv4", xfrm4_policy_table);
98830 if (!hdr)
98831 goto err_reg;
98832
98833 @@ -289,8 +288,7 @@ static int __net_init xfrm4_net_init(struct net *net)
98834 return 0;
98835
98836 err_reg:
98837 - if (!net_eq(net, &init_net))
98838 - kfree(table);
98839 + kfree(table);
98840 err_alloc:
98841 return -ENOMEM;
98842 }
98843 diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c
98844 index 0e8ae69..0fc7350 100644
98845 --- a/net/ipv6/addrconf.c
98846 +++ b/net/ipv6/addrconf.c
98847 @@ -589,7 +589,7 @@ static int inet6_netconf_dump_devconf(struct sk_buff *skb,
98848 idx = 0;
98849 head = &net->dev_index_head[h];
98850 rcu_read_lock();
98851 - cb->seq = atomic_read(&net->ipv6.dev_addr_genid) ^
98852 + cb->seq = atomic_read_unchecked(&net->ipv6.dev_addr_genid) ^
98853 net->dev_base_seq;
98854 hlist_for_each_entry_rcu(dev, head, index_hlist) {
98855 if (idx < s_idx)
98856 @@ -2337,7 +2337,7 @@ int addrconf_set_dstaddr(struct net *net, void __user *arg)
98857 p.iph.ihl = 5;
98858 p.iph.protocol = IPPROTO_IPV6;
98859 p.iph.ttl = 64;
98860 - ifr.ifr_ifru.ifru_data = (__force void __user *)&p;
98861 + ifr.ifr_ifru.ifru_data = (void __force_user *)&p;
98862
98863 if (ops->ndo_do_ioctl) {
98864 mm_segment_t oldfs = get_fs();
98865 @@ -3967,7 +3967,7 @@ static int inet6_dump_addr(struct sk_buff *skb, struct netlink_callback *cb,
98866 s_ip_idx = ip_idx = cb->args[2];
98867
98868 rcu_read_lock();
98869 - cb->seq = atomic_read(&net->ipv6.dev_addr_genid) ^ net->dev_base_seq;
98870 + cb->seq = atomic_read_unchecked(&net->ipv6.dev_addr_genid) ^ net->dev_base_seq;
98871 for (h = s_h; h < NETDEV_HASHENTRIES; h++, s_idx = 0) {
98872 idx = 0;
98873 head = &net->dev_index_head[h];
98874 @@ -4574,7 +4574,7 @@ static void __ipv6_ifa_notify(int event, struct inet6_ifaddr *ifp)
98875 dst_free(&ifp->rt->dst);
98876 break;
98877 }
98878 - atomic_inc(&net->ipv6.dev_addr_genid);
98879 + atomic_inc_unchecked(&net->ipv6.dev_addr_genid);
98880 rt_genid_bump_ipv6(net);
98881 }
98882
98883 @@ -4595,7 +4595,7 @@ int addrconf_sysctl_forward(struct ctl_table *ctl, int write,
98884 int *valp = ctl->data;
98885 int val = *valp;
98886 loff_t pos = *ppos;
98887 - struct ctl_table lctl;
98888 + ctl_table_no_const lctl;
98889 int ret;
98890
98891 /*
98892 @@ -4680,7 +4680,7 @@ int addrconf_sysctl_disable(struct ctl_table *ctl, int write,
98893 int *valp = ctl->data;
98894 int val = *valp;
98895 loff_t pos = *ppos;
98896 - struct ctl_table lctl;
98897 + ctl_table_no_const lctl;
98898 int ret;
98899
98900 /*
98901 diff --git a/net/ipv6/af_inet6.c b/net/ipv6/af_inet6.c
98902 index 4fbdb70..f6411f2 100644
98903 --- a/net/ipv6/af_inet6.c
98904 +++ b/net/ipv6/af_inet6.c
98905 @@ -776,7 +776,7 @@ static int __net_init inet6_net_init(struct net *net)
98906
98907 net->ipv6.sysctl.bindv6only = 0;
98908 net->ipv6.sysctl.icmpv6_time = 1*HZ;
98909 - atomic_set(&net->ipv6.rt_genid, 0);
98910 + atomic_set_unchecked(&net->ipv6.rt_genid, 0);
98911
98912 err = ipv6_init_mibs(net);
98913 if (err)
98914 diff --git a/net/ipv6/datagram.c b/net/ipv6/datagram.c
98915 index 93b1aa3..e902855 100644
98916 --- a/net/ipv6/datagram.c
98917 +++ b/net/ipv6/datagram.c
98918 @@ -906,5 +906,5 @@ void ip6_dgram_sock_seq_show(struct seq_file *seq, struct sock *sp,
98919 0,
98920 sock_i_ino(sp),
98921 atomic_read(&sp->sk_refcnt), sp,
98922 - atomic_read(&sp->sk_drops));
98923 + atomic_read_unchecked(&sp->sk_drops));
98924 }
98925 diff --git a/net/ipv6/icmp.c b/net/ipv6/icmp.c
98926 index e2c9ff8..1e40285 100644
98927 --- a/net/ipv6/icmp.c
98928 +++ b/net/ipv6/icmp.c
98929 @@ -997,7 +997,7 @@ struct ctl_table ipv6_icmp_table_template[] = {
98930
98931 struct ctl_table * __net_init ipv6_icmp_sysctl_init(struct net *net)
98932 {
98933 - struct ctl_table *table;
98934 + ctl_table_no_const *table;
98935
98936 table = kmemdup(ipv6_icmp_table_template,
98937 sizeof(ipv6_icmp_table_template),
98938 diff --git a/net/ipv6/ip6_gre.c b/net/ipv6/ip6_gre.c
98939 index 8acb286..840dd06 100644
98940 --- a/net/ipv6/ip6_gre.c
98941 +++ b/net/ipv6/ip6_gre.c
98942 @@ -74,7 +74,7 @@ struct ip6gre_net {
98943 struct net_device *fb_tunnel_dev;
98944 };
98945
98946 -static struct rtnl_link_ops ip6gre_link_ops __read_mostly;
98947 +static struct rtnl_link_ops ip6gre_link_ops;
98948 static int ip6gre_tunnel_init(struct net_device *dev);
98949 static void ip6gre_tunnel_setup(struct net_device *dev);
98950 static void ip6gre_tunnel_link(struct ip6gre_net *ign, struct ip6_tnl *t);
98951 @@ -1294,7 +1294,7 @@ static void ip6gre_fb_tunnel_init(struct net_device *dev)
98952 }
98953
98954
98955 -static struct inet6_protocol ip6gre_protocol __read_mostly = {
98956 +static struct inet6_protocol ip6gre_protocol = {
98957 .handler = ip6gre_rcv,
98958 .err_handler = ip6gre_err,
98959 .flags = INET6_PROTO_NOPOLICY|INET6_PROTO_FINAL,
98960 @@ -1637,7 +1637,7 @@ static const struct nla_policy ip6gre_policy[IFLA_GRE_MAX + 1] = {
98961 [IFLA_GRE_FLAGS] = { .type = NLA_U32 },
98962 };
98963
98964 -static struct rtnl_link_ops ip6gre_link_ops __read_mostly = {
98965 +static struct rtnl_link_ops ip6gre_link_ops = {
98966 .kind = "ip6gre",
98967 .maxtype = IFLA_GRE_MAX,
98968 .policy = ip6gre_policy,
98969 @@ -1650,7 +1650,7 @@ static struct rtnl_link_ops ip6gre_link_ops __read_mostly = {
98970 .fill_info = ip6gre_fill_info,
98971 };
98972
98973 -static struct rtnl_link_ops ip6gre_tap_ops __read_mostly = {
98974 +static struct rtnl_link_ops ip6gre_tap_ops = {
98975 .kind = "ip6gretap",
98976 .maxtype = IFLA_GRE_MAX,
98977 .policy = ip6gre_policy,
98978 diff --git a/net/ipv6/ip6_tunnel.c b/net/ipv6/ip6_tunnel.c
98979 index 7881965..9cf62c4 100644
98980 --- a/net/ipv6/ip6_tunnel.c
98981 +++ b/net/ipv6/ip6_tunnel.c
98982 @@ -89,7 +89,7 @@ static u32 HASH(const struct in6_addr *addr1, const struct in6_addr *addr2)
98983
98984 static int ip6_tnl_dev_init(struct net_device *dev);
98985 static void ip6_tnl_dev_setup(struct net_device *dev);
98986 -static struct rtnl_link_ops ip6_link_ops __read_mostly;
98987 +static struct rtnl_link_ops ip6_link_ops;
98988
98989 static int ip6_tnl_net_id __read_mostly;
98990 struct ip6_tnl_net {
98991 @@ -1717,7 +1717,7 @@ static const struct nla_policy ip6_tnl_policy[IFLA_IPTUN_MAX + 1] = {
98992 [IFLA_IPTUN_PROTO] = { .type = NLA_U8 },
98993 };
98994
98995 -static struct rtnl_link_ops ip6_link_ops __read_mostly = {
98996 +static struct rtnl_link_ops ip6_link_ops = {
98997 .kind = "ip6tnl",
98998 .maxtype = IFLA_IPTUN_MAX,
98999 .policy = ip6_tnl_policy,
99000 diff --git a/net/ipv6/ip6_vti.c b/net/ipv6/ip6_vti.c
99001 index 7b42d5e..1eff693 100644
99002 --- a/net/ipv6/ip6_vti.c
99003 +++ b/net/ipv6/ip6_vti.c
99004 @@ -63,7 +63,7 @@ static u32 HASH(const struct in6_addr *addr1, const struct in6_addr *addr2)
99005
99006 static int vti6_dev_init(struct net_device *dev);
99007 static void vti6_dev_setup(struct net_device *dev);
99008 -static struct rtnl_link_ops vti6_link_ops __read_mostly;
99009 +static struct rtnl_link_ops vti6_link_ops;
99010
99011 static int vti6_net_id __read_mostly;
99012 struct vti6_net {
99013 @@ -902,7 +902,7 @@ static const struct nla_policy vti6_policy[IFLA_VTI_MAX + 1] = {
99014 [IFLA_VTI_OKEY] = { .type = NLA_U32 },
99015 };
99016
99017 -static struct rtnl_link_ops vti6_link_ops __read_mostly = {
99018 +static struct rtnl_link_ops vti6_link_ops = {
99019 .kind = "vti6",
99020 .maxtype = IFLA_VTI_MAX,
99021 .policy = vti6_policy,
99022 diff --git a/net/ipv6/ipv6_sockglue.c b/net/ipv6/ipv6_sockglue.c
99023 index 1c6ce31..299e566 100644
99024 --- a/net/ipv6/ipv6_sockglue.c
99025 +++ b/net/ipv6/ipv6_sockglue.c
99026 @@ -991,7 +991,7 @@ static int do_ipv6_getsockopt(struct sock *sk, int level, int optname,
99027 if (sk->sk_type != SOCK_STREAM)
99028 return -ENOPROTOOPT;
99029
99030 - msg.msg_control = optval;
99031 + msg.msg_control = (void __force_kernel *)optval;
99032 msg.msg_controllen = len;
99033 msg.msg_flags = flags;
99034
99035 diff --git a/net/ipv6/netfilter/ip6_tables.c b/net/ipv6/netfilter/ip6_tables.c
99036 index 710238f..0fd1816 100644
99037 --- a/net/ipv6/netfilter/ip6_tables.c
99038 +++ b/net/ipv6/netfilter/ip6_tables.c
99039 @@ -1083,14 +1083,14 @@ static int compat_table_info(const struct xt_table_info *info,
99040 #endif
99041
99042 static int get_info(struct net *net, void __user *user,
99043 - const int *len, int compat)
99044 + int len, int compat)
99045 {
99046 char name[XT_TABLE_MAXNAMELEN];
99047 struct xt_table *t;
99048 int ret;
99049
99050 - if (*len != sizeof(struct ip6t_getinfo)) {
99051 - duprintf("length %u != %zu\n", *len,
99052 + if (len != sizeof(struct ip6t_getinfo)) {
99053 + duprintf("length %u != %zu\n", len,
99054 sizeof(struct ip6t_getinfo));
99055 return -EINVAL;
99056 }
99057 @@ -1127,7 +1127,7 @@ static int get_info(struct net *net, void __user *user,
99058 info.size = private->size;
99059 strcpy(info.name, name);
99060
99061 - if (copy_to_user(user, &info, *len) != 0)
99062 + if (copy_to_user(user, &info, len) != 0)
99063 ret = -EFAULT;
99064 else
99065 ret = 0;
99066 @@ -1981,7 +1981,7 @@ compat_do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
99067
99068 switch (cmd) {
99069 case IP6T_SO_GET_INFO:
99070 - ret = get_info(sock_net(sk), user, len, 1);
99071 + ret = get_info(sock_net(sk), user, *len, 1);
99072 break;
99073 case IP6T_SO_GET_ENTRIES:
99074 ret = compat_get_entries(sock_net(sk), user, len);
99075 @@ -2028,7 +2028,7 @@ do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
99076
99077 switch (cmd) {
99078 case IP6T_SO_GET_INFO:
99079 - ret = get_info(sock_net(sk), user, len, 0);
99080 + ret = get_info(sock_net(sk), user, *len, 0);
99081 break;
99082
99083 case IP6T_SO_GET_ENTRIES:
99084 diff --git a/net/ipv6/netfilter/nf_conntrack_reasm.c b/net/ipv6/netfilter/nf_conntrack_reasm.c
99085 index 767ab8d..c5ec70a 100644
99086 --- a/net/ipv6/netfilter/nf_conntrack_reasm.c
99087 +++ b/net/ipv6/netfilter/nf_conntrack_reasm.c
99088 @@ -90,12 +90,11 @@ static struct ctl_table nf_ct_frag6_sysctl_table[] = {
99089
99090 static int nf_ct_frag6_sysctl_register(struct net *net)
99091 {
99092 - struct ctl_table *table;
99093 + ctl_table_no_const *table = NULL;
99094 struct ctl_table_header *hdr;
99095
99096 - table = nf_ct_frag6_sysctl_table;
99097 if (!net_eq(net, &init_net)) {
99098 - table = kmemdup(table, sizeof(nf_ct_frag6_sysctl_table),
99099 + table = kmemdup(nf_ct_frag6_sysctl_table, sizeof(nf_ct_frag6_sysctl_table),
99100 GFP_KERNEL);
99101 if (table == NULL)
99102 goto err_alloc;
99103 @@ -103,9 +102,9 @@ static int nf_ct_frag6_sysctl_register(struct net *net)
99104 table[0].data = &net->nf_frag.frags.timeout;
99105 table[1].data = &net->nf_frag.frags.low_thresh;
99106 table[2].data = &net->nf_frag.frags.high_thresh;
99107 - }
99108 -
99109 - hdr = register_net_sysctl(net, "net/netfilter", table);
99110 + hdr = register_net_sysctl(net, "net/netfilter", table);
99111 + } else
99112 + hdr = register_net_sysctl(net, "net/netfilter", nf_ct_frag6_sysctl_table);
99113 if (hdr == NULL)
99114 goto err_reg;
99115
99116 @@ -113,8 +112,7 @@ static int nf_ct_frag6_sysctl_register(struct net *net)
99117 return 0;
99118
99119 err_reg:
99120 - if (!net_eq(net, &init_net))
99121 - kfree(table);
99122 + kfree(table);
99123 err_alloc:
99124 return -ENOMEM;
99125 }
99126 diff --git a/net/ipv6/output_core.c b/net/ipv6/output_core.c
99127 index 827f795..7e28e82 100644
99128 --- a/net/ipv6/output_core.c
99129 +++ b/net/ipv6/output_core.c
99130 @@ -9,8 +9,8 @@
99131
99132 void ipv6_select_ident(struct frag_hdr *fhdr, struct rt6_info *rt)
99133 {
99134 - static atomic_t ipv6_fragmentation_id;
99135 - int old, new;
99136 + static atomic_unchecked_t ipv6_fragmentation_id;
99137 + int id;
99138
99139 #if IS_ENABLED(CONFIG_IPV6)
99140 if (rt && !(rt->dst.flags & DST_NOPEER)) {
99141 @@ -26,13 +26,10 @@ void ipv6_select_ident(struct frag_hdr *fhdr, struct rt6_info *rt)
99142 }
99143 }
99144 #endif
99145 - do {
99146 - old = atomic_read(&ipv6_fragmentation_id);
99147 - new = old + 1;
99148 - if (!new)
99149 - new = 1;
99150 - } while (atomic_cmpxchg(&ipv6_fragmentation_id, old, new) != old);
99151 - fhdr->identification = htonl(new);
99152 + id = atomic_inc_return_unchecked(&ipv6_fragmentation_id);
99153 + if (!id)
99154 + id = atomic_inc_return_unchecked(&ipv6_fragmentation_id);
99155 + fhdr->identification = htonl(id);
99156 }
99157 EXPORT_SYMBOL(ipv6_select_ident);
99158
99159 diff --git a/net/ipv6/ping.c b/net/ipv6/ping.c
99160 index 3a1f1f3..11d95bf 100644
99161 --- a/net/ipv6/ping.c
99162 +++ b/net/ipv6/ping.c
99163 @@ -246,6 +246,22 @@ static struct pernet_operations ping_v6_net_ops = {
99164 };
99165 #endif
99166
99167 +static struct pingv6_ops real_pingv6_ops = {
99168 + .ipv6_recv_error = ipv6_recv_error,
99169 + .ip6_datagram_recv_ctl = ip6_datagram_recv_ctl,
99170 + .icmpv6_err_convert = icmpv6_err_convert,
99171 + .ipv6_icmp_error = ipv6_icmp_error,
99172 + .ipv6_chk_addr = ipv6_chk_addr,
99173 +};
99174 +
99175 +static struct pingv6_ops dummy_pingv6_ops = {
99176 + .ipv6_recv_error = dummy_ipv6_recv_error,
99177 + .ip6_datagram_recv_ctl = dummy_ip6_datagram_recv_ctl,
99178 + .icmpv6_err_convert = dummy_icmpv6_err_convert,
99179 + .ipv6_icmp_error = dummy_ipv6_icmp_error,
99180 + .ipv6_chk_addr = dummy_ipv6_chk_addr,
99181 +};
99182 +
99183 int __init pingv6_init(void)
99184 {
99185 #ifdef CONFIG_PROC_FS
99186 @@ -253,11 +269,7 @@ int __init pingv6_init(void)
99187 if (ret)
99188 return ret;
99189 #endif
99190 - pingv6_ops.ipv6_recv_error = ipv6_recv_error;
99191 - pingv6_ops.ip6_datagram_recv_ctl = ip6_datagram_recv_ctl;
99192 - pingv6_ops.icmpv6_err_convert = icmpv6_err_convert;
99193 - pingv6_ops.ipv6_icmp_error = ipv6_icmp_error;
99194 - pingv6_ops.ipv6_chk_addr = ipv6_chk_addr;
99195 + pingv6_ops = &real_pingv6_ops;
99196 return inet6_register_protosw(&pingv6_protosw);
99197 }
99198
99199 @@ -266,11 +278,7 @@ int __init pingv6_init(void)
99200 */
99201 void pingv6_exit(void)
99202 {
99203 - pingv6_ops.ipv6_recv_error = dummy_ipv6_recv_error;
99204 - pingv6_ops.ip6_datagram_recv_ctl = dummy_ip6_datagram_recv_ctl;
99205 - pingv6_ops.icmpv6_err_convert = dummy_icmpv6_err_convert;
99206 - pingv6_ops.ipv6_icmp_error = dummy_ipv6_icmp_error;
99207 - pingv6_ops.ipv6_chk_addr = dummy_ipv6_chk_addr;
99208 + pingv6_ops = &dummy_pingv6_ops;
99209 #ifdef CONFIG_PROC_FS
99210 unregister_pernet_subsys(&ping_v6_net_ops);
99211 #endif
99212 diff --git a/net/ipv6/raw.c b/net/ipv6/raw.c
99213 index b6bb87e..06cc9ed 100644
99214 --- a/net/ipv6/raw.c
99215 +++ b/net/ipv6/raw.c
99216 @@ -384,7 +384,7 @@ static inline int rawv6_rcv_skb(struct sock *sk, struct sk_buff *skb)
99217 {
99218 if ((raw6_sk(sk)->checksum || rcu_access_pointer(sk->sk_filter)) &&
99219 skb_checksum_complete(skb)) {
99220 - atomic_inc(&sk->sk_drops);
99221 + atomic_inc_unchecked(&sk->sk_drops);
99222 kfree_skb(skb);
99223 return NET_RX_DROP;
99224 }
99225 @@ -412,7 +412,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
99226 struct raw6_sock *rp = raw6_sk(sk);
99227
99228 if (!xfrm6_policy_check(sk, XFRM_POLICY_IN, skb)) {
99229 - atomic_inc(&sk->sk_drops);
99230 + atomic_inc_unchecked(&sk->sk_drops);
99231 kfree_skb(skb);
99232 return NET_RX_DROP;
99233 }
99234 @@ -436,7 +436,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
99235
99236 if (inet->hdrincl) {
99237 if (skb_checksum_complete(skb)) {
99238 - atomic_inc(&sk->sk_drops);
99239 + atomic_inc_unchecked(&sk->sk_drops);
99240 kfree_skb(skb);
99241 return NET_RX_DROP;
99242 }
99243 @@ -465,6 +465,9 @@ static int rawv6_recvmsg(struct kiocb *iocb, struct sock *sk,
99244 if (flags & MSG_OOB)
99245 return -EOPNOTSUPP;
99246
99247 + if (addr_len)
99248 + *addr_len=sizeof(*sin6);
99249 +
99250 if (flags & MSG_ERRQUEUE)
99251 return ipv6_recv_error(sk, msg, len, addr_len);
99252
99253 @@ -503,7 +506,6 @@ static int rawv6_recvmsg(struct kiocb *iocb, struct sock *sk,
99254 sin6->sin6_flowinfo = 0;
99255 sin6->sin6_scope_id = ipv6_iface_scope_id(&sin6->sin6_addr,
99256 IP6CB(skb)->iif);
99257 - *addr_len = sizeof(*sin6);
99258 }
99259
99260 sock_recv_ts_and_drops(msg, sk, skb);
99261 @@ -606,7 +608,7 @@ out:
99262 return err;
99263 }
99264
99265 -static int rawv6_send_hdrinc(struct sock *sk, void *from, int length,
99266 +static int rawv6_send_hdrinc(struct sock *sk, void *from, unsigned int length,
99267 struct flowi6 *fl6, struct dst_entry **dstp,
99268 unsigned int flags)
99269 {
99270 @@ -918,12 +920,15 @@ do_confirm:
99271 static int rawv6_seticmpfilter(struct sock *sk, int level, int optname,
99272 char __user *optval, int optlen)
99273 {
99274 + struct icmp6_filter filter;
99275 +
99276 switch (optname) {
99277 case ICMPV6_FILTER:
99278 if (optlen > sizeof(struct icmp6_filter))
99279 optlen = sizeof(struct icmp6_filter);
99280 - if (copy_from_user(&raw6_sk(sk)->filter, optval, optlen))
99281 + if (copy_from_user(&filter, optval, optlen))
99282 return -EFAULT;
99283 + raw6_sk(sk)->filter = filter;
99284 return 0;
99285 default:
99286 return -ENOPROTOOPT;
99287 @@ -936,6 +941,7 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
99288 char __user *optval, int __user *optlen)
99289 {
99290 int len;
99291 + struct icmp6_filter filter;
99292
99293 switch (optname) {
99294 case ICMPV6_FILTER:
99295 @@ -947,7 +953,8 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
99296 len = sizeof(struct icmp6_filter);
99297 if (put_user(len, optlen))
99298 return -EFAULT;
99299 - if (copy_to_user(optval, &raw6_sk(sk)->filter, len))
99300 + filter = raw6_sk(sk)->filter;
99301 + if (len > sizeof filter || copy_to_user(optval, &filter, len))
99302 return -EFAULT;
99303 return 0;
99304 default:
99305 diff --git a/net/ipv6/reassembly.c b/net/ipv6/reassembly.c
99306 index cc85a9b..526a133 100644
99307 --- a/net/ipv6/reassembly.c
99308 +++ b/net/ipv6/reassembly.c
99309 @@ -626,12 +626,11 @@ static struct ctl_table ip6_frags_ctl_table[] = {
99310
99311 static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
99312 {
99313 - struct ctl_table *table;
99314 + ctl_table_no_const *table = NULL;
99315 struct ctl_table_header *hdr;
99316
99317 - table = ip6_frags_ns_ctl_table;
99318 if (!net_eq(net, &init_net)) {
99319 - table = kmemdup(table, sizeof(ip6_frags_ns_ctl_table), GFP_KERNEL);
99320 + table = kmemdup(ip6_frags_ns_ctl_table, sizeof(ip6_frags_ns_ctl_table), GFP_KERNEL);
99321 if (table == NULL)
99322 goto err_alloc;
99323
99324 @@ -642,9 +641,10 @@ static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
99325 /* Don't export sysctls to unprivileged users */
99326 if (net->user_ns != &init_user_ns)
99327 table[0].procname = NULL;
99328 - }
99329 + hdr = register_net_sysctl(net, "net/ipv6", table);
99330 + } else
99331 + hdr = register_net_sysctl(net, "net/ipv6", ip6_frags_ns_ctl_table);
99332
99333 - hdr = register_net_sysctl(net, "net/ipv6", table);
99334 if (hdr == NULL)
99335 goto err_reg;
99336
99337 @@ -652,8 +652,7 @@ static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
99338 return 0;
99339
99340 err_reg:
99341 - if (!net_eq(net, &init_net))
99342 - kfree(table);
99343 + kfree(table);
99344 err_alloc:
99345 return -ENOMEM;
99346 }
99347 diff --git a/net/ipv6/route.c b/net/ipv6/route.c
99348 index 40b6e69..d346b14 100644
99349 --- a/net/ipv6/route.c
99350 +++ b/net/ipv6/route.c
99351 @@ -2954,7 +2954,7 @@ struct ctl_table ipv6_route_table_template[] = {
99352
99353 struct ctl_table * __net_init ipv6_route_sysctl_init(struct net *net)
99354 {
99355 - struct ctl_table *table;
99356 + ctl_table_no_const *table;
99357
99358 table = kmemdup(ipv6_route_table_template,
99359 sizeof(ipv6_route_table_template),
99360 diff --git a/net/ipv6/sit.c b/net/ipv6/sit.c
99361 index d3005b3..b36df4a 100644
99362 --- a/net/ipv6/sit.c
99363 +++ b/net/ipv6/sit.c
99364 @@ -74,7 +74,7 @@ static void ipip6_tunnel_setup(struct net_device *dev);
99365 static void ipip6_dev_free(struct net_device *dev);
99366 static bool check_6rd(struct ip_tunnel *tunnel, const struct in6_addr *v6dst,
99367 __be32 *v4dst);
99368 -static struct rtnl_link_ops sit_link_ops __read_mostly;
99369 +static struct rtnl_link_ops sit_link_ops;
99370
99371 static int sit_net_id __read_mostly;
99372 struct sit_net {
99373 @@ -1664,7 +1664,7 @@ static void ipip6_dellink(struct net_device *dev, struct list_head *head)
99374 unregister_netdevice_queue(dev, head);
99375 }
99376
99377 -static struct rtnl_link_ops sit_link_ops __read_mostly = {
99378 +static struct rtnl_link_ops sit_link_ops = {
99379 .kind = "sit",
99380 .maxtype = IFLA_IPTUN_MAX,
99381 .policy = ipip6_policy,
99382 diff --git a/net/ipv6/sysctl_net_ipv6.c b/net/ipv6/sysctl_net_ipv6.c
99383 index 107b2f1..72741a9 100644
99384 --- a/net/ipv6/sysctl_net_ipv6.c
99385 +++ b/net/ipv6/sysctl_net_ipv6.c
99386 @@ -40,7 +40,7 @@ static struct ctl_table ipv6_rotable[] = {
99387
99388 static int __net_init ipv6_sysctl_net_init(struct net *net)
99389 {
99390 - struct ctl_table *ipv6_table;
99391 + ctl_table_no_const *ipv6_table;
99392 struct ctl_table *ipv6_route_table;
99393 struct ctl_table *ipv6_icmp_table;
99394 int err;
99395 diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c
99396 index f67033b..6f974fc 100644
99397 --- a/net/ipv6/tcp_ipv6.c
99398 +++ b/net/ipv6/tcp_ipv6.c
99399 @@ -104,6 +104,10 @@ static void inet6_sk_rx_dst_set(struct sock *sk, const struct sk_buff *skb)
99400 inet6_sk(sk)->rx_dst_cookie = rt->rt6i_node->fn_sernum;
99401 }
99402
99403 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
99404 +extern int grsec_enable_blackhole;
99405 +#endif
99406 +
99407 static void tcp_v6_hash(struct sock *sk)
99408 {
99409 if (sk->sk_state != TCP_CLOSE) {
99410 @@ -1397,6 +1401,9 @@ static int tcp_v6_do_rcv(struct sock *sk, struct sk_buff *skb)
99411 return 0;
99412
99413 reset:
99414 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
99415 + if (!grsec_enable_blackhole)
99416 +#endif
99417 tcp_v6_send_reset(sk, skb);
99418 discard:
99419 if (opt_skb)
99420 @@ -1479,12 +1486,20 @@ static int tcp_v6_rcv(struct sk_buff *skb)
99421 TCP_SKB_CB(skb)->sacked = 0;
99422
99423 sk = __inet6_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
99424 - if (!sk)
99425 + if (!sk) {
99426 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
99427 + ret = 1;
99428 +#endif
99429 goto no_tcp_socket;
99430 + }
99431
99432 process:
99433 - if (sk->sk_state == TCP_TIME_WAIT)
99434 + if (sk->sk_state == TCP_TIME_WAIT) {
99435 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
99436 + ret = 2;
99437 +#endif
99438 goto do_time_wait;
99439 + }
99440
99441 if (hdr->hop_limit < inet6_sk(sk)->min_hopcount) {
99442 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
99443 @@ -1536,6 +1551,10 @@ csum_error:
99444 bad_packet:
99445 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
99446 } else {
99447 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
99448 + if (!grsec_enable_blackhole || (ret == 1 &&
99449 + (skb->dev->flags & IFF_LOOPBACK)))
99450 +#endif
99451 tcp_v6_send_reset(NULL, skb);
99452 }
99453
99454 diff --git a/net/ipv6/udp.c b/net/ipv6/udp.c
99455 index 089c741..cfee117 100644
99456 --- a/net/ipv6/udp.c
99457 +++ b/net/ipv6/udp.c
99458 @@ -76,6 +76,10 @@ static unsigned int udp6_ehashfn(struct net *net,
99459 udp_ipv6_hash_secret + net_hash_mix(net));
99460 }
99461
99462 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
99463 +extern int grsec_enable_blackhole;
99464 +#endif
99465 +
99466 int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2)
99467 {
99468 const struct in6_addr *sk2_rcv_saddr6 = inet6_rcv_saddr(sk2);
99469 @@ -392,6 +396,9 @@ int udpv6_recvmsg(struct kiocb *iocb, struct sock *sk,
99470 int is_udp4;
99471 bool slow;
99472
99473 + if (addr_len)
99474 + *addr_len = sizeof(struct sockaddr_in6);
99475 +
99476 if (flags & MSG_ERRQUEUE)
99477 return ipv6_recv_error(sk, msg, len, addr_len);
99478
99479 @@ -435,7 +442,7 @@ try_again:
99480 if (unlikely(err)) {
99481 trace_kfree_skb(skb, udpv6_recvmsg);
99482 if (!peeked) {
99483 - atomic_inc(&sk->sk_drops);
99484 + atomic_inc_unchecked(&sk->sk_drops);
99485 if (is_udp4)
99486 UDP_INC_STATS_USER(sock_net(sk),
99487 UDP_MIB_INERRORS,
99488 @@ -477,7 +484,7 @@ try_again:
99489 ipv6_iface_scope_id(&sin6->sin6_addr,
99490 IP6CB(skb)->iif);
99491 }
99492 - *addr_len = sizeof(*sin6);
99493 +
99494 }
99495 if (is_udp4) {
99496 if (inet->cmsg_flags)
99497 @@ -685,7 +692,7 @@ csum_error:
99498 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_CSUMERRORS, is_udplite);
99499 drop:
99500 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
99501 - atomic_inc(&sk->sk_drops);
99502 + atomic_inc_unchecked(&sk->sk_drops);
99503 kfree_skb(skb);
99504 return -1;
99505 }
99506 @@ -742,7 +749,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
99507 if (likely(skb1 == NULL))
99508 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
99509 if (!skb1) {
99510 - atomic_inc(&sk->sk_drops);
99511 + atomic_inc_unchecked(&sk->sk_drops);
99512 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
99513 IS_UDPLITE(sk));
99514 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
99515 @@ -881,6 +888,9 @@ int __udp6_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
99516 goto csum_error;
99517
99518 UDP6_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
99519 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
99520 + if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
99521 +#endif
99522 icmpv6_send(skb, ICMPV6_DEST_UNREACH, ICMPV6_PORT_UNREACH, 0);
99523
99524 kfree_skb(skb);
99525 diff --git a/net/ipv6/xfrm6_policy.c b/net/ipv6/xfrm6_policy.c
99526 index 5f8e128..865d38e 100644
99527 --- a/net/ipv6/xfrm6_policy.c
99528 +++ b/net/ipv6/xfrm6_policy.c
99529 @@ -212,11 +212,11 @@ _decode_session6(struct sk_buff *skb, struct flowi *fl, int reverse)
99530 }
99531 }
99532
99533 -static inline int xfrm6_garbage_collect(struct dst_ops *ops)
99534 +static int xfrm6_garbage_collect(struct dst_ops *ops)
99535 {
99536 struct net *net = container_of(ops, struct net, xfrm.xfrm6_dst_ops);
99537
99538 - xfrm6_policy_afinfo.garbage_collect(net);
99539 + xfrm_garbage_collect_deferred(net);
99540 return dst_entries_get_fast(ops) > ops->gc_thresh * 2;
99541 }
99542
99543 @@ -329,19 +329,19 @@ static struct ctl_table xfrm6_policy_table[] = {
99544
99545 static int __net_init xfrm6_net_init(struct net *net)
99546 {
99547 - struct ctl_table *table;
99548 + ctl_table_no_const *table = NULL;
99549 struct ctl_table_header *hdr;
99550
99551 - table = xfrm6_policy_table;
99552 if (!net_eq(net, &init_net)) {
99553 - table = kmemdup(table, sizeof(xfrm6_policy_table), GFP_KERNEL);
99554 + table = kmemdup(xfrm6_policy_table, sizeof(xfrm6_policy_table), GFP_KERNEL);
99555 if (!table)
99556 goto err_alloc;
99557
99558 table[0].data = &net->xfrm.xfrm6_dst_ops.gc_thresh;
99559 - }
99560 + hdr = register_net_sysctl(net, "net/ipv6", table);
99561 + } else
99562 + hdr = register_net_sysctl(net, "net/ipv6", xfrm6_policy_table);
99563
99564 - hdr = register_net_sysctl(net, "net/ipv6", table);
99565 if (!hdr)
99566 goto err_reg;
99567
99568 @@ -349,8 +349,7 @@ static int __net_init xfrm6_net_init(struct net *net)
99569 return 0;
99570
99571 err_reg:
99572 - if (!net_eq(net, &init_net))
99573 - kfree(table);
99574 + kfree(table);
99575 err_alloc:
99576 return -ENOMEM;
99577 }
99578 diff --git a/net/irda/ircomm/ircomm_tty.c b/net/irda/ircomm/ircomm_tty.c
99579 index 41ac7938..75e3bb1 100644
99580 --- a/net/irda/ircomm/ircomm_tty.c
99581 +++ b/net/irda/ircomm/ircomm_tty.c
99582 @@ -319,11 +319,11 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
99583 add_wait_queue(&port->open_wait, &wait);
99584
99585 IRDA_DEBUG(2, "%s(%d):block_til_ready before block on %s open_count=%d\n",
99586 - __FILE__, __LINE__, tty->driver->name, port->count);
99587 + __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
99588
99589 spin_lock_irqsave(&port->lock, flags);
99590 if (!tty_hung_up_p(filp))
99591 - port->count--;
99592 + atomic_dec(&port->count);
99593 port->blocked_open++;
99594 spin_unlock_irqrestore(&port->lock, flags);
99595
99596 @@ -358,7 +358,7 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
99597 }
99598
99599 IRDA_DEBUG(1, "%s(%d):block_til_ready blocking on %s open_count=%d\n",
99600 - __FILE__, __LINE__, tty->driver->name, port->count);
99601 + __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
99602
99603 schedule();
99604 }
99605 @@ -368,12 +368,12 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
99606
99607 spin_lock_irqsave(&port->lock, flags);
99608 if (!tty_hung_up_p(filp))
99609 - port->count++;
99610 + atomic_inc(&port->count);
99611 port->blocked_open--;
99612 spin_unlock_irqrestore(&port->lock, flags);
99613
99614 IRDA_DEBUG(1, "%s(%d):block_til_ready after blocking on %s open_count=%d\n",
99615 - __FILE__, __LINE__, tty->driver->name, port->count);
99616 + __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
99617
99618 if (!retval)
99619 port->flags |= ASYNC_NORMAL_ACTIVE;
99620 @@ -447,12 +447,12 @@ static int ircomm_tty_open(struct tty_struct *tty, struct file *filp)
99621
99622 /* ++ is not atomic, so this should be protected - Jean II */
99623 spin_lock_irqsave(&self->port.lock, flags);
99624 - self->port.count++;
99625 + atomic_inc(&self->port.count);
99626 spin_unlock_irqrestore(&self->port.lock, flags);
99627 tty_port_tty_set(&self->port, tty);
99628
99629 IRDA_DEBUG(1, "%s(), %s%d, count = %d\n", __func__ , tty->driver->name,
99630 - self->line, self->port.count);
99631 + self->line, atomic_read(&self->port.count));
99632
99633 /* Not really used by us, but lets do it anyway */
99634 self->port.low_latency = (self->port.flags & ASYNC_LOW_LATENCY) ? 1 : 0;
99635 @@ -989,7 +989,7 @@ static void ircomm_tty_hangup(struct tty_struct *tty)
99636 tty_kref_put(port->tty);
99637 }
99638 port->tty = NULL;
99639 - port->count = 0;
99640 + atomic_set(&port->count, 0);
99641 spin_unlock_irqrestore(&port->lock, flags);
99642
99643 wake_up_interruptible(&port->open_wait);
99644 @@ -1346,7 +1346,7 @@ static void ircomm_tty_line_info(struct ircomm_tty_cb *self, struct seq_file *m)
99645 seq_putc(m, '\n');
99646
99647 seq_printf(m, "Role: %s\n", self->client ? "client" : "server");
99648 - seq_printf(m, "Open count: %d\n", self->port.count);
99649 + seq_printf(m, "Open count: %d\n", atomic_read(&self->port.count));
99650 seq_printf(m, "Max data size: %d\n", self->max_data_size);
99651 seq_printf(m, "Max header size: %d\n", self->max_header_size);
99652
99653 diff --git a/net/iucv/af_iucv.c b/net/iucv/af_iucv.c
99654 index c4b7218..3e83259 100644
99655 --- a/net/iucv/af_iucv.c
99656 +++ b/net/iucv/af_iucv.c
99657 @@ -773,10 +773,10 @@ static int iucv_sock_autobind(struct sock *sk)
99658
99659 write_lock_bh(&iucv_sk_list.lock);
99660
99661 - sprintf(name, "%08x", atomic_inc_return(&iucv_sk_list.autobind_name));
99662 + sprintf(name, "%08x", atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
99663 while (__iucv_get_sock_by_name(name)) {
99664 sprintf(name, "%08x",
99665 - atomic_inc_return(&iucv_sk_list.autobind_name));
99666 + atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
99667 }
99668
99669 write_unlock_bh(&iucv_sk_list.lock);
99670 diff --git a/net/iucv/iucv.c b/net/iucv/iucv.c
99671 index cd5b8ec..f205e6b 100644
99672 --- a/net/iucv/iucv.c
99673 +++ b/net/iucv/iucv.c
99674 @@ -690,7 +690,7 @@ static int iucv_cpu_notify(struct notifier_block *self,
99675 return NOTIFY_OK;
99676 }
99677
99678 -static struct notifier_block __refdata iucv_cpu_notifier = {
99679 +static struct notifier_block iucv_cpu_notifier = {
99680 .notifier_call = iucv_cpu_notify,
99681 };
99682
99683 diff --git a/net/key/af_key.c b/net/key/af_key.c
99684 index 545f047..9757a9d 100644
99685 --- a/net/key/af_key.c
99686 +++ b/net/key/af_key.c
99687 @@ -3041,10 +3041,10 @@ static int pfkey_send_policy_notify(struct xfrm_policy *xp, int dir, const struc
99688 static u32 get_acqseq(void)
99689 {
99690 u32 res;
99691 - static atomic_t acqseq;
99692 + static atomic_unchecked_t acqseq;
99693
99694 do {
99695 - res = atomic_inc_return(&acqseq);
99696 + res = atomic_inc_return_unchecked(&acqseq);
99697 } while (!res);
99698 return res;
99699 }
99700 diff --git a/net/l2tp/l2tp_ip.c b/net/l2tp/l2tp_ip.c
99701 index da1a1ce..571db8d 100644
99702 --- a/net/l2tp/l2tp_ip.c
99703 +++ b/net/l2tp/l2tp_ip.c
99704 @@ -518,6 +518,9 @@ static int l2tp_ip_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *m
99705 if (flags & MSG_OOB)
99706 goto out;
99707
99708 + if (addr_len)
99709 + *addr_len = sizeof(*sin);
99710 +
99711 skb = skb_recv_datagram(sk, flags, noblock, &err);
99712 if (!skb)
99713 goto out;
99714 @@ -540,7 +543,6 @@ static int l2tp_ip_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *m
99715 sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
99716 sin->sin_port = 0;
99717 memset(&sin->sin_zero, 0, sizeof(sin->sin_zero));
99718 - *addr_len = sizeof(*sin);
99719 }
99720 if (inet->cmsg_flags)
99721 ip_cmsg_recv(msg, skb);
99722 diff --git a/net/mac80211/cfg.c b/net/mac80211/cfg.c
99723 index b4b61b2..ac84a257 100644
99724 --- a/net/mac80211/cfg.c
99725 +++ b/net/mac80211/cfg.c
99726 @@ -826,7 +826,7 @@ static int ieee80211_set_monitor_channel(struct wiphy *wiphy,
99727 ret = ieee80211_vif_use_channel(sdata, chandef,
99728 IEEE80211_CHANCTX_EXCLUSIVE);
99729 }
99730 - } else if (local->open_count == local->monitors) {
99731 + } else if (local_read(&local->open_count) == local->monitors) {
99732 local->_oper_chandef = *chandef;
99733 ieee80211_hw_config(local, 0);
99734 }
99735 @@ -3311,7 +3311,7 @@ static void ieee80211_mgmt_frame_register(struct wiphy *wiphy,
99736 else
99737 local->probe_req_reg--;
99738
99739 - if (!local->open_count)
99740 + if (!local_read(&local->open_count))
99741 break;
99742
99743 ieee80211_queue_work(&local->hw, &local->reconfig_filter);
99744 @@ -3774,8 +3774,8 @@ static int ieee80211_cfg_get_channel(struct wiphy *wiphy,
99745 if (chanctx_conf) {
99746 *chandef = chanctx_conf->def;
99747 ret = 0;
99748 - } else if (local->open_count > 0 &&
99749 - local->open_count == local->monitors &&
99750 + } else if (local_read(&local->open_count) > 0 &&
99751 + local_read(&local->open_count) == local->monitors &&
99752 sdata->vif.type == NL80211_IFTYPE_MONITOR) {
99753 if (local->use_chanctx)
99754 *chandef = local->monitor_chandef;
99755 diff --git a/net/mac80211/ieee80211_i.h b/net/mac80211/ieee80211_i.h
99756 index 4aea4e7..9e698d1 100644
99757 --- a/net/mac80211/ieee80211_i.h
99758 +++ b/net/mac80211/ieee80211_i.h
99759 @@ -28,6 +28,7 @@
99760 #include <net/ieee80211_radiotap.h>
99761 #include <net/cfg80211.h>
99762 #include <net/mac80211.h>
99763 +#include <asm/local.h>
99764 #include "key.h"
99765 #include "sta_info.h"
99766 #include "debug.h"
99767 @@ -961,7 +962,7 @@ struct ieee80211_local {
99768 /* also used to protect ampdu_ac_queue and amdpu_ac_stop_refcnt */
99769 spinlock_t queue_stop_reason_lock;
99770
99771 - int open_count;
99772 + local_t open_count;
99773 int monitors, cooked_mntrs;
99774 /* number of interfaces with corresponding FIF_ flags */
99775 int fif_fcsfail, fif_plcpfail, fif_control, fif_other_bss, fif_pspoll,
99776 diff --git a/net/mac80211/iface.c b/net/mac80211/iface.c
99777 index a075791..1d0027f 100644
99778 --- a/net/mac80211/iface.c
99779 +++ b/net/mac80211/iface.c
99780 @@ -519,7 +519,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
99781 break;
99782 }
99783
99784 - if (local->open_count == 0) {
99785 + if (local_read(&local->open_count) == 0) {
99786 res = drv_start(local);
99787 if (res)
99788 goto err_del_bss;
99789 @@ -566,7 +566,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
99790 res = drv_add_interface(local, sdata);
99791 if (res)
99792 goto err_stop;
99793 - } else if (local->monitors == 0 && local->open_count == 0) {
99794 + } else if (local->monitors == 0 && local_read(&local->open_count) == 0) {
99795 res = ieee80211_add_virtual_monitor(local);
99796 if (res)
99797 goto err_stop;
99798 @@ -675,7 +675,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
99799 atomic_inc(&local->iff_promiscs);
99800
99801 if (coming_up)
99802 - local->open_count++;
99803 + local_inc(&local->open_count);
99804
99805 if (hw_reconf_flags)
99806 ieee80211_hw_config(local, hw_reconf_flags);
99807 @@ -713,7 +713,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
99808 err_del_interface:
99809 drv_remove_interface(local, sdata);
99810 err_stop:
99811 - if (!local->open_count)
99812 + if (!local_read(&local->open_count))
99813 drv_stop(local);
99814 err_del_bss:
99815 sdata->bss = NULL;
99816 @@ -856,7 +856,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
99817 }
99818
99819 if (going_down)
99820 - local->open_count--;
99821 + local_dec(&local->open_count);
99822
99823 switch (sdata->vif.type) {
99824 case NL80211_IFTYPE_AP_VLAN:
99825 @@ -923,7 +923,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
99826 }
99827 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
99828
99829 - if (local->open_count == 0)
99830 + if (local_read(&local->open_count) == 0)
99831 ieee80211_clear_tx_pending(local);
99832
99833 /*
99834 @@ -963,7 +963,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
99835
99836 ieee80211_recalc_ps(local, -1);
99837
99838 - if (local->open_count == 0) {
99839 + if (local_read(&local->open_count) == 0) {
99840 ieee80211_stop_device(local);
99841
99842 /* no reconfiguring after stop! */
99843 @@ -974,7 +974,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
99844 ieee80211_configure_filter(local);
99845 ieee80211_hw_config(local, hw_reconf_flags);
99846
99847 - if (local->monitors == local->open_count)
99848 + if (local->monitors == local_read(&local->open_count))
99849 ieee80211_add_virtual_monitor(local);
99850 }
99851
99852 diff --git a/net/mac80211/main.c b/net/mac80211/main.c
99853 index 7d1c3ac..b62dd29 100644
99854 --- a/net/mac80211/main.c
99855 +++ b/net/mac80211/main.c
99856 @@ -172,7 +172,7 @@ int ieee80211_hw_config(struct ieee80211_local *local, u32 changed)
99857 changed &= ~(IEEE80211_CONF_CHANGE_CHANNEL |
99858 IEEE80211_CONF_CHANGE_POWER);
99859
99860 - if (changed && local->open_count) {
99861 + if (changed && local_read(&local->open_count)) {
99862 ret = drv_config(local, changed);
99863 /*
99864 * Goal:
99865 diff --git a/net/mac80211/pm.c b/net/mac80211/pm.c
99866 index 3401262..d5cd68d 100644
99867 --- a/net/mac80211/pm.c
99868 +++ b/net/mac80211/pm.c
99869 @@ -12,7 +12,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
99870 struct ieee80211_sub_if_data *sdata;
99871 struct sta_info *sta;
99872
99873 - if (!local->open_count)
99874 + if (!local_read(&local->open_count))
99875 goto suspend;
99876
99877 ieee80211_scan_cancel(local);
99878 @@ -59,7 +59,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
99879 cancel_work_sync(&local->dynamic_ps_enable_work);
99880 del_timer_sync(&local->dynamic_ps_timer);
99881
99882 - local->wowlan = wowlan && local->open_count;
99883 + local->wowlan = wowlan && local_read(&local->open_count);
99884 if (local->wowlan) {
99885 int err = drv_suspend(local, wowlan);
99886 if (err < 0) {
99887 @@ -116,7 +116,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
99888 WARN_ON(!list_empty(&local->chanctx_list));
99889
99890 /* stop hardware - this must stop RX */
99891 - if (local->open_count)
99892 + if (local_read(&local->open_count))
99893 ieee80211_stop_device(local);
99894
99895 suspend:
99896 diff --git a/net/mac80211/rate.c b/net/mac80211/rate.c
99897 index 22b223f..ab70070 100644
99898 --- a/net/mac80211/rate.c
99899 +++ b/net/mac80211/rate.c
99900 @@ -734,7 +734,7 @@ int ieee80211_init_rate_ctrl_alg(struct ieee80211_local *local,
99901
99902 ASSERT_RTNL();
99903
99904 - if (local->open_count)
99905 + if (local_read(&local->open_count))
99906 return -EBUSY;
99907
99908 if (local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL) {
99909 diff --git a/net/mac80211/rc80211_pid_debugfs.c b/net/mac80211/rc80211_pid_debugfs.c
99910 index 6ff1346..936ca9a 100644
99911 --- a/net/mac80211/rc80211_pid_debugfs.c
99912 +++ b/net/mac80211/rc80211_pid_debugfs.c
99913 @@ -193,7 +193,7 @@ static ssize_t rate_control_pid_events_read(struct file *file, char __user *buf,
99914
99915 spin_unlock_irqrestore(&events->lock, status);
99916
99917 - if (copy_to_user(buf, pb, p))
99918 + if (p > sizeof(pb) || copy_to_user(buf, pb, p))
99919 return -EFAULT;
99920
99921 return p;
99922 diff --git a/net/mac80211/util.c b/net/mac80211/util.c
99923 index 9f9b9bd..d6fcf59 100644
99924 --- a/net/mac80211/util.c
99925 +++ b/net/mac80211/util.c
99926 @@ -1474,7 +1474,7 @@ int ieee80211_reconfig(struct ieee80211_local *local)
99927 }
99928 #endif
99929 /* everything else happens only if HW was up & running */
99930 - if (!local->open_count)
99931 + if (!local_read(&local->open_count))
99932 goto wake_up;
99933
99934 /*
99935 @@ -1699,7 +1699,7 @@ int ieee80211_reconfig(struct ieee80211_local *local)
99936 local->in_reconfig = false;
99937 barrier();
99938
99939 - if (local->monitors == local->open_count && local->monitors > 0)
99940 + if (local->monitors == local_read(&local->open_count) && local->monitors > 0)
99941 ieee80211_add_virtual_monitor(local);
99942
99943 /*
99944 diff --git a/net/netfilter/Kconfig b/net/netfilter/Kconfig
99945 index c3398cd..98ad3b4 100644
99946 --- a/net/netfilter/Kconfig
99947 +++ b/net/netfilter/Kconfig
99948 @@ -1002,6 +1002,16 @@ config NETFILTER_XT_MATCH_ESP
99949
99950 To compile it as a module, choose M here. If unsure, say N.
99951
99952 +config NETFILTER_XT_MATCH_GRADM
99953 + tristate '"gradm" match support'
99954 + depends on NETFILTER_XTABLES && NETFILTER_ADVANCED
99955 + depends on GRKERNSEC && !GRKERNSEC_NO_RBAC
99956 + ---help---
99957 + The gradm match allows to match on grsecurity RBAC being enabled.
99958 + It is useful when iptables rules are applied early on bootup to
99959 + prevent connections to the machine (except from a trusted host)
99960 + while the RBAC system is disabled.
99961 +
99962 config NETFILTER_XT_MATCH_HASHLIMIT
99963 tristate '"hashlimit" match support'
99964 depends on (IP6_NF_IPTABLES || IP6_NF_IPTABLES=n)
99965 diff --git a/net/netfilter/Makefile b/net/netfilter/Makefile
99966 index 394483b..ed51f2d 100644
99967 --- a/net/netfilter/Makefile
99968 +++ b/net/netfilter/Makefile
99969 @@ -130,6 +130,7 @@ obj-$(CONFIG_NETFILTER_XT_MATCH_DEVGROUP) += xt_devgroup.o
99970 obj-$(CONFIG_NETFILTER_XT_MATCH_DSCP) += xt_dscp.o
99971 obj-$(CONFIG_NETFILTER_XT_MATCH_ECN) += xt_ecn.o
99972 obj-$(CONFIG_NETFILTER_XT_MATCH_ESP) += xt_esp.o
99973 +obj-$(CONFIG_NETFILTER_XT_MATCH_GRADM) += xt_gradm.o
99974 obj-$(CONFIG_NETFILTER_XT_MATCH_HASHLIMIT) += xt_hashlimit.o
99975 obj-$(CONFIG_NETFILTER_XT_MATCH_HELPER) += xt_helper.o
99976 obj-$(CONFIG_NETFILTER_XT_MATCH_HL) += xt_hl.o
99977 diff --git a/net/netfilter/ipset/ip_set_core.c b/net/netfilter/ipset/ip_set_core.c
99978 index bac7e01..1d7a31a 100644
99979 --- a/net/netfilter/ipset/ip_set_core.c
99980 +++ b/net/netfilter/ipset/ip_set_core.c
99981 @@ -1950,7 +1950,7 @@ done:
99982 return ret;
99983 }
99984
99985 -static struct nf_sockopt_ops so_set __read_mostly = {
99986 +static struct nf_sockopt_ops so_set = {
99987 .pf = PF_INET,
99988 .get_optmin = SO_IP_SET,
99989 .get_optmax = SO_IP_SET + 1,
99990 diff --git a/net/netfilter/ipvs/ip_vs_conn.c b/net/netfilter/ipvs/ip_vs_conn.c
99991 index 4c8e5c0..5a79b4d 100644
99992 --- a/net/netfilter/ipvs/ip_vs_conn.c
99993 +++ b/net/netfilter/ipvs/ip_vs_conn.c
99994 @@ -556,7 +556,7 @@ ip_vs_bind_dest(struct ip_vs_conn *cp, struct ip_vs_dest *dest)
99995 /* Increase the refcnt counter of the dest */
99996 ip_vs_dest_hold(dest);
99997
99998 - conn_flags = atomic_read(&dest->conn_flags);
99999 + conn_flags = atomic_read_unchecked(&dest->conn_flags);
100000 if (cp->protocol != IPPROTO_UDP)
100001 conn_flags &= ~IP_VS_CONN_F_ONE_PACKET;
100002 flags = cp->flags;
100003 @@ -900,7 +900,7 @@ ip_vs_conn_new(const struct ip_vs_conn_param *p,
100004
100005 cp->control = NULL;
100006 atomic_set(&cp->n_control, 0);
100007 - atomic_set(&cp->in_pkts, 0);
100008 + atomic_set_unchecked(&cp->in_pkts, 0);
100009
100010 cp->packet_xmit = NULL;
100011 cp->app = NULL;
100012 @@ -1188,7 +1188,7 @@ static inline int todrop_entry(struct ip_vs_conn *cp)
100013
100014 /* Don't drop the entry if its number of incoming packets is not
100015 located in [0, 8] */
100016 - i = atomic_read(&cp->in_pkts);
100017 + i = atomic_read_unchecked(&cp->in_pkts);
100018 if (i > 8 || i < 0) return 0;
100019
100020 if (!todrop_rate[i]) return 0;
100021 diff --git a/net/netfilter/ipvs/ip_vs_core.c b/net/netfilter/ipvs/ip_vs_core.c
100022 index 4f26ee4..6a9d7c3 100644
100023 --- a/net/netfilter/ipvs/ip_vs_core.c
100024 +++ b/net/netfilter/ipvs/ip_vs_core.c
100025 @@ -567,7 +567,7 @@ int ip_vs_leave(struct ip_vs_service *svc, struct sk_buff *skb,
100026 ret = cp->packet_xmit(skb, cp, pd->pp, iph);
100027 /* do not touch skb anymore */
100028
100029 - atomic_inc(&cp->in_pkts);
100030 + atomic_inc_unchecked(&cp->in_pkts);
100031 ip_vs_conn_put(cp);
100032 return ret;
100033 }
100034 @@ -1706,7 +1706,7 @@ ip_vs_in(unsigned int hooknum, struct sk_buff *skb, int af)
100035 if (cp->flags & IP_VS_CONN_F_ONE_PACKET)
100036 pkts = sysctl_sync_threshold(ipvs);
100037 else
100038 - pkts = atomic_add_return(1, &cp->in_pkts);
100039 + pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
100040
100041 if (ipvs->sync_state & IP_VS_STATE_MASTER)
100042 ip_vs_sync_conn(net, cp, pkts);
100043 diff --git a/net/netfilter/ipvs/ip_vs_ctl.c b/net/netfilter/ipvs/ip_vs_ctl.c
100044 index 35be035..50f8834 100644
100045 --- a/net/netfilter/ipvs/ip_vs_ctl.c
100046 +++ b/net/netfilter/ipvs/ip_vs_ctl.c
100047 @@ -794,7 +794,7 @@ __ip_vs_update_dest(struct ip_vs_service *svc, struct ip_vs_dest *dest,
100048 */
100049 ip_vs_rs_hash(ipvs, dest);
100050 }
100051 - atomic_set(&dest->conn_flags, conn_flags);
100052 + atomic_set_unchecked(&dest->conn_flags, conn_flags);
100053
100054 /* bind the service */
100055 old_svc = rcu_dereference_protected(dest->svc, 1);
100056 @@ -1654,7 +1654,7 @@ proc_do_sync_ports(struct ctl_table *table, int write,
100057 * align with netns init in ip_vs_control_net_init()
100058 */
100059
100060 -static struct ctl_table vs_vars[] = {
100061 +static ctl_table_no_const vs_vars[] __read_only = {
100062 {
100063 .procname = "amemthresh",
100064 .maxlen = sizeof(int),
100065 @@ -2075,7 +2075,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
100066 " %-7s %-6d %-10d %-10d\n",
100067 &dest->addr.in6,
100068 ntohs(dest->port),
100069 - ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
100070 + ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
100071 atomic_read(&dest->weight),
100072 atomic_read(&dest->activeconns),
100073 atomic_read(&dest->inactconns));
100074 @@ -2086,7 +2086,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
100075 "%-7s %-6d %-10d %-10d\n",
100076 ntohl(dest->addr.ip),
100077 ntohs(dest->port),
100078 - ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
100079 + ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
100080 atomic_read(&dest->weight),
100081 atomic_read(&dest->activeconns),
100082 atomic_read(&dest->inactconns));
100083 @@ -2564,7 +2564,7 @@ __ip_vs_get_dest_entries(struct net *net, const struct ip_vs_get_dests *get,
100084
100085 entry.addr = dest->addr.ip;
100086 entry.port = dest->port;
100087 - entry.conn_flags = atomic_read(&dest->conn_flags);
100088 + entry.conn_flags = atomic_read_unchecked(&dest->conn_flags);
100089 entry.weight = atomic_read(&dest->weight);
100090 entry.u_threshold = dest->u_threshold;
100091 entry.l_threshold = dest->l_threshold;
100092 @@ -3107,7 +3107,7 @@ static int ip_vs_genl_fill_dest(struct sk_buff *skb, struct ip_vs_dest *dest)
100093 if (nla_put(skb, IPVS_DEST_ATTR_ADDR, sizeof(dest->addr), &dest->addr) ||
100094 nla_put_be16(skb, IPVS_DEST_ATTR_PORT, dest->port) ||
100095 nla_put_u32(skb, IPVS_DEST_ATTR_FWD_METHOD,
100096 - (atomic_read(&dest->conn_flags) &
100097 + (atomic_read_unchecked(&dest->conn_flags) &
100098 IP_VS_CONN_F_FWD_MASK)) ||
100099 nla_put_u32(skb, IPVS_DEST_ATTR_WEIGHT,
100100 atomic_read(&dest->weight)) ||
100101 @@ -3580,7 +3580,7 @@ out:
100102 }
100103
100104
100105 -static const struct genl_ops ip_vs_genl_ops[] __read_mostly = {
100106 +static const struct genl_ops ip_vs_genl_ops[] = {
100107 {
100108 .cmd = IPVS_CMD_NEW_SERVICE,
100109 .flags = GENL_ADMIN_PERM,
100110 @@ -3697,7 +3697,7 @@ static int __net_init ip_vs_control_net_init_sysctl(struct net *net)
100111 {
100112 int idx;
100113 struct netns_ipvs *ipvs = net_ipvs(net);
100114 - struct ctl_table *tbl;
100115 + ctl_table_no_const *tbl;
100116
100117 atomic_set(&ipvs->dropentry, 0);
100118 spin_lock_init(&ipvs->dropentry_lock);
100119 diff --git a/net/netfilter/ipvs/ip_vs_lblc.c b/net/netfilter/ipvs/ip_vs_lblc.c
100120 index ca056a3..9cf01ef 100644
100121 --- a/net/netfilter/ipvs/ip_vs_lblc.c
100122 +++ b/net/netfilter/ipvs/ip_vs_lblc.c
100123 @@ -118,7 +118,7 @@ struct ip_vs_lblc_table {
100124 * IPVS LBLC sysctl table
100125 */
100126 #ifdef CONFIG_SYSCTL
100127 -static struct ctl_table vs_vars_table[] = {
100128 +static ctl_table_no_const vs_vars_table[] __read_only = {
100129 {
100130 .procname = "lblc_expiration",
100131 .data = NULL,
100132 diff --git a/net/netfilter/ipvs/ip_vs_lblcr.c b/net/netfilter/ipvs/ip_vs_lblcr.c
100133 index 3f21a2f..a112e85 100644
100134 --- a/net/netfilter/ipvs/ip_vs_lblcr.c
100135 +++ b/net/netfilter/ipvs/ip_vs_lblcr.c
100136 @@ -289,7 +289,7 @@ struct ip_vs_lblcr_table {
100137 * IPVS LBLCR sysctl table
100138 */
100139
100140 -static struct ctl_table vs_vars_table[] = {
100141 +static ctl_table_no_const vs_vars_table[] __read_only = {
100142 {
100143 .procname = "lblcr_expiration",
100144 .data = NULL,
100145 diff --git a/net/netfilter/ipvs/ip_vs_sync.c b/net/netfilter/ipvs/ip_vs_sync.c
100146 index f63c238..1b87f8a 100644
100147 --- a/net/netfilter/ipvs/ip_vs_sync.c
100148 +++ b/net/netfilter/ipvs/ip_vs_sync.c
100149 @@ -609,7 +609,7 @@ static void ip_vs_sync_conn_v0(struct net *net, struct ip_vs_conn *cp,
100150 cp = cp->control;
100151 if (cp) {
100152 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
100153 - pkts = atomic_add_return(1, &cp->in_pkts);
100154 + pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
100155 else
100156 pkts = sysctl_sync_threshold(ipvs);
100157 ip_vs_sync_conn(net, cp->control, pkts);
100158 @@ -771,7 +771,7 @@ control:
100159 if (!cp)
100160 return;
100161 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
100162 - pkts = atomic_add_return(1, &cp->in_pkts);
100163 + pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
100164 else
100165 pkts = sysctl_sync_threshold(ipvs);
100166 goto sloop;
100167 @@ -895,7 +895,7 @@ static void ip_vs_proc_conn(struct net *net, struct ip_vs_conn_param *param,
100168
100169 if (opt)
100170 memcpy(&cp->in_seq, opt, sizeof(*opt));
100171 - atomic_set(&cp->in_pkts, sysctl_sync_threshold(ipvs));
100172 + atomic_set_unchecked(&cp->in_pkts, sysctl_sync_threshold(ipvs));
100173 cp->state = state;
100174 cp->old_state = cp->state;
100175 /*
100176 diff --git a/net/netfilter/ipvs/ip_vs_xmit.c b/net/netfilter/ipvs/ip_vs_xmit.c
100177 index c47444e..b0961c6 100644
100178 --- a/net/netfilter/ipvs/ip_vs_xmit.c
100179 +++ b/net/netfilter/ipvs/ip_vs_xmit.c
100180 @@ -1102,7 +1102,7 @@ ip_vs_icmp_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
100181 else
100182 rc = NF_ACCEPT;
100183 /* do not touch skb anymore */
100184 - atomic_inc(&cp->in_pkts);
100185 + atomic_inc_unchecked(&cp->in_pkts);
100186 goto out;
100187 }
100188
100189 @@ -1194,7 +1194,7 @@ ip_vs_icmp_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
100190 else
100191 rc = NF_ACCEPT;
100192 /* do not touch skb anymore */
100193 - atomic_inc(&cp->in_pkts);
100194 + atomic_inc_unchecked(&cp->in_pkts);
100195 goto out;
100196 }
100197
100198 diff --git a/net/netfilter/nf_conntrack_acct.c b/net/netfilter/nf_conntrack_acct.c
100199 index a4b5e2a..13b1de3 100644
100200 --- a/net/netfilter/nf_conntrack_acct.c
100201 +++ b/net/netfilter/nf_conntrack_acct.c
100202 @@ -62,7 +62,7 @@ static struct nf_ct_ext_type acct_extend __read_mostly = {
100203 #ifdef CONFIG_SYSCTL
100204 static int nf_conntrack_acct_init_sysctl(struct net *net)
100205 {
100206 - struct ctl_table *table;
100207 + ctl_table_no_const *table;
100208
100209 table = kmemdup(acct_sysctl_table, sizeof(acct_sysctl_table),
100210 GFP_KERNEL);
100211 diff --git a/net/netfilter/nf_conntrack_core.c b/net/netfilter/nf_conntrack_core.c
100212 index 43549eb..0bbeace 100644
100213 --- a/net/netfilter/nf_conntrack_core.c
100214 +++ b/net/netfilter/nf_conntrack_core.c
100215 @@ -1605,6 +1605,10 @@ void nf_conntrack_init_end(void)
100216 #define DYING_NULLS_VAL ((1<<30)+1)
100217 #define TEMPLATE_NULLS_VAL ((1<<30)+2)
100218
100219 +#ifdef CONFIG_GRKERNSEC_HIDESYM
100220 +static atomic_unchecked_t conntrack_cache_id = ATOMIC_INIT(0);
100221 +#endif
100222 +
100223 int nf_conntrack_init_net(struct net *net)
100224 {
100225 int ret;
100226 @@ -1619,7 +1623,11 @@ int nf_conntrack_init_net(struct net *net)
100227 goto err_stat;
100228 }
100229
100230 +#ifdef CONFIG_GRKERNSEC_HIDESYM
100231 + net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%08lx", atomic_inc_return_unchecked(&conntrack_cache_id));
100232 +#else
100233 net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%p", net);
100234 +#endif
100235 if (!net->ct.slabname) {
100236 ret = -ENOMEM;
100237 goto err_slabname;
100238 diff --git a/net/netfilter/nf_conntrack_ecache.c b/net/netfilter/nf_conntrack_ecache.c
100239 index 1df1761..ce8b88a 100644
100240 --- a/net/netfilter/nf_conntrack_ecache.c
100241 +++ b/net/netfilter/nf_conntrack_ecache.c
100242 @@ -188,7 +188,7 @@ static struct nf_ct_ext_type event_extend __read_mostly = {
100243 #ifdef CONFIG_SYSCTL
100244 static int nf_conntrack_event_init_sysctl(struct net *net)
100245 {
100246 - struct ctl_table *table;
100247 + ctl_table_no_const *table;
100248
100249 table = kmemdup(event_sysctl_table, sizeof(event_sysctl_table),
100250 GFP_KERNEL);
100251 diff --git a/net/netfilter/nf_conntrack_helper.c b/net/netfilter/nf_conntrack_helper.c
100252 index 974a2a4..52cc6ff 100644
100253 --- a/net/netfilter/nf_conntrack_helper.c
100254 +++ b/net/netfilter/nf_conntrack_helper.c
100255 @@ -57,7 +57,7 @@ static struct ctl_table helper_sysctl_table[] = {
100256
100257 static int nf_conntrack_helper_init_sysctl(struct net *net)
100258 {
100259 - struct ctl_table *table;
100260 + ctl_table_no_const *table;
100261
100262 table = kmemdup(helper_sysctl_table, sizeof(helper_sysctl_table),
100263 GFP_KERNEL);
100264 diff --git a/net/netfilter/nf_conntrack_proto.c b/net/netfilter/nf_conntrack_proto.c
100265 index ce30041..3861b5d 100644
100266 --- a/net/netfilter/nf_conntrack_proto.c
100267 +++ b/net/netfilter/nf_conntrack_proto.c
100268 @@ -52,7 +52,7 @@ nf_ct_register_sysctl(struct net *net,
100269
100270 static void
100271 nf_ct_unregister_sysctl(struct ctl_table_header **header,
100272 - struct ctl_table **table,
100273 + ctl_table_no_const **table,
100274 unsigned int users)
100275 {
100276 if (users > 0)
100277 diff --git a/net/netfilter/nf_conntrack_proto_dccp.c b/net/netfilter/nf_conntrack_proto_dccp.c
100278 index 59359be..cb372f9 100644
100279 --- a/net/netfilter/nf_conntrack_proto_dccp.c
100280 +++ b/net/netfilter/nf_conntrack_proto_dccp.c
100281 @@ -457,7 +457,7 @@ static bool dccp_new(struct nf_conn *ct, const struct sk_buff *skb,
100282 out_invalid:
100283 if (LOG_INVALID(net, IPPROTO_DCCP))
100284 nf_log_packet(net, nf_ct_l3num(ct), 0, skb, NULL, NULL,
100285 - NULL, msg);
100286 + NULL, "%s", msg);
100287 return false;
100288 }
100289
100290 @@ -614,7 +614,7 @@ static int dccp_error(struct net *net, struct nf_conn *tmpl,
100291
100292 out_invalid:
100293 if (LOG_INVALID(net, IPPROTO_DCCP))
100294 - nf_log_packet(net, pf, 0, skb, NULL, NULL, NULL, msg);
100295 + nf_log_packet(net, pf, 0, skb, NULL, NULL, NULL, "%s", msg);
100296 return -NF_ACCEPT;
100297 }
100298
100299 diff --git a/net/netfilter/nf_conntrack_standalone.c b/net/netfilter/nf_conntrack_standalone.c
100300 index f641751..d3c5b51 100644
100301 --- a/net/netfilter/nf_conntrack_standalone.c
100302 +++ b/net/netfilter/nf_conntrack_standalone.c
100303 @@ -471,7 +471,7 @@ static struct ctl_table nf_ct_netfilter_table[] = {
100304
100305 static int nf_conntrack_standalone_init_sysctl(struct net *net)
100306 {
100307 - struct ctl_table *table;
100308 + ctl_table_no_const *table;
100309
100310 table = kmemdup(nf_ct_sysctl_table, sizeof(nf_ct_sysctl_table),
100311 GFP_KERNEL);
100312 diff --git a/net/netfilter/nf_conntrack_timestamp.c b/net/netfilter/nf_conntrack_timestamp.c
100313 index 7a394df..bd91a8a 100644
100314 --- a/net/netfilter/nf_conntrack_timestamp.c
100315 +++ b/net/netfilter/nf_conntrack_timestamp.c
100316 @@ -42,7 +42,7 @@ static struct nf_ct_ext_type tstamp_extend __read_mostly = {
100317 #ifdef CONFIG_SYSCTL
100318 static int nf_conntrack_tstamp_init_sysctl(struct net *net)
100319 {
100320 - struct ctl_table *table;
100321 + ctl_table_no_const *table;
100322
100323 table = kmemdup(tstamp_sysctl_table, sizeof(tstamp_sysctl_table),
100324 GFP_KERNEL);
100325 diff --git a/net/netfilter/nf_log.c b/net/netfilter/nf_log.c
100326 index 85296d4..8becdec 100644
100327 --- a/net/netfilter/nf_log.c
100328 +++ b/net/netfilter/nf_log.c
100329 @@ -243,7 +243,7 @@ static const struct file_operations nflog_file_ops = {
100330
100331 #ifdef CONFIG_SYSCTL
100332 static char nf_log_sysctl_fnames[NFPROTO_NUMPROTO-NFPROTO_UNSPEC][3];
100333 -static struct ctl_table nf_log_sysctl_table[NFPROTO_NUMPROTO+1];
100334 +static ctl_table_no_const nf_log_sysctl_table[NFPROTO_NUMPROTO+1] __read_only;
100335
100336 static int nf_log_proc_dostring(struct ctl_table *table, int write,
100337 void __user *buffer, size_t *lenp, loff_t *ppos)
100338 @@ -274,14 +274,16 @@ static int nf_log_proc_dostring(struct ctl_table *table, int write,
100339 rcu_assign_pointer(net->nf.nf_loggers[tindex], logger);
100340 mutex_unlock(&nf_log_mutex);
100341 } else {
100342 + ctl_table_no_const nf_log_table = *table;
100343 +
100344 mutex_lock(&nf_log_mutex);
100345 logger = rcu_dereference_protected(net->nf.nf_loggers[tindex],
100346 lockdep_is_held(&nf_log_mutex));
100347 if (!logger)
100348 - table->data = "NONE";
100349 + nf_log_table.data = "NONE";
100350 else
100351 - table->data = logger->name;
100352 - r = proc_dostring(table, write, buffer, lenp, ppos);
100353 + nf_log_table.data = logger->name;
100354 + r = proc_dostring(&nf_log_table, write, buffer, lenp, ppos);
100355 mutex_unlock(&nf_log_mutex);
100356 }
100357
100358 diff --git a/net/netfilter/nf_sockopt.c b/net/netfilter/nf_sockopt.c
100359 index f042ae5..30ea486 100644
100360 --- a/net/netfilter/nf_sockopt.c
100361 +++ b/net/netfilter/nf_sockopt.c
100362 @@ -45,7 +45,7 @@ int nf_register_sockopt(struct nf_sockopt_ops *reg)
100363 }
100364 }
100365
100366 - list_add(&reg->list, &nf_sockopts);
100367 + pax_list_add((struct list_head *)&reg->list, &nf_sockopts);
100368 out:
100369 mutex_unlock(&nf_sockopt_mutex);
100370 return ret;
100371 @@ -55,7 +55,7 @@ EXPORT_SYMBOL(nf_register_sockopt);
100372 void nf_unregister_sockopt(struct nf_sockopt_ops *reg)
100373 {
100374 mutex_lock(&nf_sockopt_mutex);
100375 - list_del(&reg->list);
100376 + pax_list_del((struct list_head *)&reg->list);
100377 mutex_unlock(&nf_sockopt_mutex);
100378 }
100379 EXPORT_SYMBOL(nf_unregister_sockopt);
100380 diff --git a/net/netfilter/nf_tables_api.c b/net/netfilter/nf_tables_api.c
100381 index 71a9f49..c09b60c 100644
100382 --- a/net/netfilter/nf_tables_api.c
100383 +++ b/net/netfilter/nf_tables_api.c
100384 @@ -148,8 +148,8 @@ static int nf_tables_chain_type_lookup(const struct nft_af_info *afi,
100385 #ifdef CONFIG_MODULES
100386 if (type < 0 && autoload) {
100387 nfnl_unlock(NFNL_SUBSYS_NFTABLES);
100388 - request_module("nft-chain-%u-%*.s", afi->family,
100389 - nla_len(nla)-1, (const char *)nla_data(nla));
100390 + request_module("nft-chain-%u-%.*s", afi->family,
100391 + nla_len(nla), (const char *)nla_data(nla));
100392 nfnl_lock(NFNL_SUBSYS_NFTABLES);
100393 type = __nf_tables_chain_type_lookup(afi->family, nla);
100394 }
100395 @@ -1916,7 +1916,8 @@ static const struct nft_set_ops *nft_select_set_ops(const struct nlattr * const
100396
100397 static const struct nla_policy nft_set_policy[NFTA_SET_MAX + 1] = {
100398 [NFTA_SET_TABLE] = { .type = NLA_STRING },
100399 - [NFTA_SET_NAME] = { .type = NLA_STRING },
100400 + [NFTA_SET_NAME] = { .type = NLA_STRING,
100401 + .len = IFNAMSIZ - 1 },
100402 [NFTA_SET_FLAGS] = { .type = NLA_U32 },
100403 [NFTA_SET_KEY_TYPE] = { .type = NLA_U32 },
100404 [NFTA_SET_KEY_LEN] = { .type = NLA_U32 },
100405 diff --git a/net/netfilter/nfnetlink_log.c b/net/netfilter/nfnetlink_log.c
100406 index a155d19..726b0f2 100644
100407 --- a/net/netfilter/nfnetlink_log.c
100408 +++ b/net/netfilter/nfnetlink_log.c
100409 @@ -82,7 +82,7 @@ static int nfnl_log_net_id __read_mostly;
100410 struct nfnl_log_net {
100411 spinlock_t instances_lock;
100412 struct hlist_head instance_table[INSTANCE_BUCKETS];
100413 - atomic_t global_seq;
100414 + atomic_unchecked_t global_seq;
100415 };
100416
100417 static struct nfnl_log_net *nfnl_log_pernet(struct net *net)
100418 @@ -564,7 +564,7 @@ __build_packet_message(struct nfnl_log_net *log,
100419 /* global sequence number */
100420 if ((inst->flags & NFULNL_CFG_F_SEQ_GLOBAL) &&
100421 nla_put_be32(inst->skb, NFULA_SEQ_GLOBAL,
100422 - htonl(atomic_inc_return(&log->global_seq))))
100423 + htonl(atomic_inc_return_unchecked(&log->global_seq))))
100424 goto nla_put_failure;
100425
100426 if (data_len) {
100427 diff --git a/net/netfilter/nft_compat.c b/net/netfilter/nft_compat.c
100428 index da0c1f4..f79737a 100644
100429 --- a/net/netfilter/nft_compat.c
100430 +++ b/net/netfilter/nft_compat.c
100431 @@ -216,7 +216,7 @@ target_dump_info(struct sk_buff *skb, const struct xt_target *t, const void *in)
100432 /* We want to reuse existing compat_to_user */
100433 old_fs = get_fs();
100434 set_fs(KERNEL_DS);
100435 - t->compat_to_user(out, in);
100436 + t->compat_to_user((void __force_user *)out, in);
100437 set_fs(old_fs);
100438 ret = nla_put(skb, NFTA_TARGET_INFO, XT_ALIGN(t->targetsize), out);
100439 kfree(out);
100440 @@ -403,7 +403,7 @@ match_dump_info(struct sk_buff *skb, const struct xt_match *m, const void *in)
100441 /* We want to reuse existing compat_to_user */
100442 old_fs = get_fs();
100443 set_fs(KERNEL_DS);
100444 - m->compat_to_user(out, in);
100445 + m->compat_to_user((void __force_user *)out, in);
100446 set_fs(old_fs);
100447 ret = nla_put(skb, NFTA_MATCH_INFO, XT_ALIGN(m->matchsize), out);
100448 kfree(out);
100449 diff --git a/net/netfilter/xt_gradm.c b/net/netfilter/xt_gradm.c
100450 new file mode 100644
100451 index 0000000..c566332
100452 --- /dev/null
100453 +++ b/net/netfilter/xt_gradm.c
100454 @@ -0,0 +1,51 @@
100455 +/*
100456 + * gradm match for netfilter
100457 + * Copyright © Zbigniew Krzystolik, 2010
100458 + *
100459 + * This program is free software; you can redistribute it and/or modify
100460 + * it under the terms of the GNU General Public License; either version
100461 + * 2 or 3 as published by the Free Software Foundation.
100462 + */
100463 +#include <linux/module.h>
100464 +#include <linux/moduleparam.h>
100465 +#include <linux/skbuff.h>
100466 +#include <linux/netfilter/x_tables.h>
100467 +#include <linux/grsecurity.h>
100468 +#include <linux/netfilter/xt_gradm.h>
100469 +
100470 +static bool
100471 +gradm_mt(const struct sk_buff *skb, struct xt_action_param *par)
100472 +{
100473 + const struct xt_gradm_mtinfo *info = par->matchinfo;
100474 + bool retval = false;
100475 + if (gr_acl_is_enabled())
100476 + retval = true;
100477 + return retval ^ info->invflags;
100478 +}
100479 +
100480 +static struct xt_match gradm_mt_reg __read_mostly = {
100481 + .name = "gradm",
100482 + .revision = 0,
100483 + .family = NFPROTO_UNSPEC,
100484 + .match = gradm_mt,
100485 + .matchsize = XT_ALIGN(sizeof(struct xt_gradm_mtinfo)),
100486 + .me = THIS_MODULE,
100487 +};
100488 +
100489 +static int __init gradm_mt_init(void)
100490 +{
100491 + return xt_register_match(&gradm_mt_reg);
100492 +}
100493 +
100494 +static void __exit gradm_mt_exit(void)
100495 +{
100496 + xt_unregister_match(&gradm_mt_reg);
100497 +}
100498 +
100499 +module_init(gradm_mt_init);
100500 +module_exit(gradm_mt_exit);
100501 +MODULE_AUTHOR("Zbigniew Krzystolik <zbyniu@destrukcja.pl>");
100502 +MODULE_DESCRIPTION("Xtables: Grsecurity RBAC match");
100503 +MODULE_LICENSE("GPL");
100504 +MODULE_ALIAS("ipt_gradm");
100505 +MODULE_ALIAS("ip6t_gradm");
100506 diff --git a/net/netfilter/xt_statistic.c b/net/netfilter/xt_statistic.c
100507 index 4fe4fb4..87a89e5 100644
100508 --- a/net/netfilter/xt_statistic.c
100509 +++ b/net/netfilter/xt_statistic.c
100510 @@ -19,7 +19,7 @@
100511 #include <linux/module.h>
100512
100513 struct xt_statistic_priv {
100514 - atomic_t count;
100515 + atomic_unchecked_t count;
100516 } ____cacheline_aligned_in_smp;
100517
100518 MODULE_LICENSE("GPL");
100519 @@ -42,9 +42,9 @@ statistic_mt(const struct sk_buff *skb, struct xt_action_param *par)
100520 break;
100521 case XT_STATISTIC_MODE_NTH:
100522 do {
100523 - oval = atomic_read(&info->master->count);
100524 + oval = atomic_read_unchecked(&info->master->count);
100525 nval = (oval == info->u.nth.every) ? 0 : oval + 1;
100526 - } while (atomic_cmpxchg(&info->master->count, oval, nval) != oval);
100527 + } while (atomic_cmpxchg_unchecked(&info->master->count, oval, nval) != oval);
100528 if (nval == 0)
100529 ret = !ret;
100530 break;
100531 @@ -64,7 +64,7 @@ static int statistic_mt_check(const struct xt_mtchk_param *par)
100532 info->master = kzalloc(sizeof(*info->master), GFP_KERNEL);
100533 if (info->master == NULL)
100534 return -ENOMEM;
100535 - atomic_set(&info->master->count, info->u.nth.count);
100536 + atomic_set_unchecked(&info->master->count, info->u.nth.count);
100537
100538 return 0;
100539 }
100540 diff --git a/net/netlink/af_netlink.c b/net/netlink/af_netlink.c
100541 index bca50b9..782ec12 100644
100542 --- a/net/netlink/af_netlink.c
100543 +++ b/net/netlink/af_netlink.c
100544 @@ -249,7 +249,7 @@ static void netlink_overrun(struct sock *sk)
100545 sk->sk_error_report(sk);
100546 }
100547 }
100548 - atomic_inc(&sk->sk_drops);
100549 + atomic_inc_unchecked(&sk->sk_drops);
100550 }
100551
100552 static void netlink_rcv_wake(struct sock *sk)
100553 @@ -1481,8 +1481,8 @@ static int netlink_connect(struct socket *sock, struct sockaddr *addr,
100554 if (addr->sa_family != AF_NETLINK)
100555 return -EINVAL;
100556
100557 - /* Only superuser is allowed to send multicasts */
100558 - if (nladdr->nl_groups && !netlink_capable(sock, NL_CFG_F_NONROOT_SEND))
100559 + if ((nladdr->nl_groups || nladdr->nl_pid) &&
100560 + !netlink_capable(sock, NL_CFG_F_NONROOT_SEND))
100561 return -EPERM;
100562
100563 if (!nlk->portid)
100564 @@ -2940,7 +2940,7 @@ static int netlink_seq_show(struct seq_file *seq, void *v)
100565 sk_wmem_alloc_get(s),
100566 nlk->cb_running,
100567 atomic_read(&s->sk_refcnt),
100568 - atomic_read(&s->sk_drops),
100569 + atomic_read_unchecked(&s->sk_drops),
100570 sock_i_ino(s)
100571 );
100572
100573 diff --git a/net/netrom/af_netrom.c b/net/netrom/af_netrom.c
100574 index 53c19a3..b0ac04a 100644
100575 --- a/net/netrom/af_netrom.c
100576 +++ b/net/netrom/af_netrom.c
100577 @@ -850,7 +850,6 @@ static int nr_getname(struct socket *sock, struct sockaddr *uaddr,
100578 *uaddr_len = sizeof(struct full_sockaddr_ax25);
100579 } else {
100580 sax->fsa_ax25.sax25_family = AF_NETROM;
100581 - sax->fsa_ax25.sax25_ndigis = 0;
100582 sax->fsa_ax25.sax25_call = nr->source_addr;
100583 *uaddr_len = sizeof(struct sockaddr_ax25);
100584 }
100585 diff --git a/net/packet/af_packet.c b/net/packet/af_packet.c
100586 index 88cfbc1..05d73f5 100644
100587 --- a/net/packet/af_packet.c
100588 +++ b/net/packet/af_packet.c
100589 @@ -1720,7 +1720,7 @@ static int packet_rcv(struct sk_buff *skb, struct net_device *dev,
100590
100591 spin_lock(&sk->sk_receive_queue.lock);
100592 po->stats.stats1.tp_packets++;
100593 - skb->dropcount = atomic_read(&sk->sk_drops);
100594 + skb->dropcount = atomic_read_unchecked(&sk->sk_drops);
100595 __skb_queue_tail(&sk->sk_receive_queue, skb);
100596 spin_unlock(&sk->sk_receive_queue.lock);
100597 sk->sk_data_ready(sk, skb->len);
100598 @@ -1729,7 +1729,7 @@ static int packet_rcv(struct sk_buff *skb, struct net_device *dev,
100599 drop_n_acct:
100600 spin_lock(&sk->sk_receive_queue.lock);
100601 po->stats.stats1.tp_drops++;
100602 - atomic_inc(&sk->sk_drops);
100603 + atomic_inc_unchecked(&sk->sk_drops);
100604 spin_unlock(&sk->sk_receive_queue.lock);
100605
100606 drop_n_restore:
100607 @@ -3275,7 +3275,7 @@ static int packet_getsockopt(struct socket *sock, int level, int optname,
100608 case PACKET_HDRLEN:
100609 if (len > sizeof(int))
100610 len = sizeof(int);
100611 - if (copy_from_user(&val, optval, len))
100612 + if (len > sizeof(val) || copy_from_user(&val, optval, len))
100613 return -EFAULT;
100614 switch (val) {
100615 case TPACKET_V1:
100616 @@ -3318,7 +3318,7 @@ static int packet_getsockopt(struct socket *sock, int level, int optname,
100617 len = lv;
100618 if (put_user(len, optlen))
100619 return -EFAULT;
100620 - if (copy_to_user(optval, data, len))
100621 + if (len > sizeof(st) || copy_to_user(optval, data, len))
100622 return -EFAULT;
100623 return 0;
100624 }
100625 diff --git a/net/phonet/datagram.c b/net/phonet/datagram.c
100626 index 38946b2..12c30f3 100644
100627 --- a/net/phonet/datagram.c
100628 +++ b/net/phonet/datagram.c
100629 @@ -139,6 +139,9 @@ static int pn_recvmsg(struct kiocb *iocb, struct sock *sk,
100630 MSG_CMSG_COMPAT))
100631 goto out_nofree;
100632
100633 + if (addr_len)
100634 + *addr_len = sizeof(sa);
100635 +
100636 skb = skb_recv_datagram(sk, flags, noblock, &rval);
100637 if (skb == NULL)
100638 goto out_nofree;
100639 @@ -159,10 +162,8 @@ static int pn_recvmsg(struct kiocb *iocb, struct sock *sk,
100640
100641 rval = (flags & MSG_TRUNC) ? skb->len : copylen;
100642
100643 - if (msg->msg_name != NULL) {
100644 - memcpy(msg->msg_name, &sa, sizeof(sa));
100645 - *addr_len = sizeof(sa);
100646 - }
100647 + if (msg->msg_name != NULL)
100648 + memcpy(msg->msg_name, &sa, sizeof(struct sockaddr_pn));
100649
100650 out:
100651 skb_free_datagram(sk, skb);
100652 diff --git a/net/phonet/pep.c b/net/phonet/pep.c
100653 index e774117..900b8b7 100644
100654 --- a/net/phonet/pep.c
100655 +++ b/net/phonet/pep.c
100656 @@ -388,7 +388,7 @@ static int pipe_do_rcv(struct sock *sk, struct sk_buff *skb)
100657
100658 case PNS_PEP_CTRL_REQ:
100659 if (skb_queue_len(&pn->ctrlreq_queue) >= PNPIPE_CTRLREQ_MAX) {
100660 - atomic_inc(&sk->sk_drops);
100661 + atomic_inc_unchecked(&sk->sk_drops);
100662 break;
100663 }
100664 __skb_pull(skb, 4);
100665 @@ -409,7 +409,7 @@ static int pipe_do_rcv(struct sock *sk, struct sk_buff *skb)
100666 }
100667
100668 if (pn->rx_credits == 0) {
100669 - atomic_inc(&sk->sk_drops);
100670 + atomic_inc_unchecked(&sk->sk_drops);
100671 err = -ENOBUFS;
100672 break;
100673 }
100674 @@ -580,7 +580,7 @@ static int pipe_handler_do_rcv(struct sock *sk, struct sk_buff *skb)
100675 }
100676
100677 if (pn->rx_credits == 0) {
100678 - atomic_inc(&sk->sk_drops);
100679 + atomic_inc_unchecked(&sk->sk_drops);
100680 err = NET_RX_DROP;
100681 break;
100682 }
100683 diff --git a/net/phonet/socket.c b/net/phonet/socket.c
100684 index 008214a..bb68240 100644
100685 --- a/net/phonet/socket.c
100686 +++ b/net/phonet/socket.c
100687 @@ -611,7 +611,7 @@ static int pn_sock_seq_show(struct seq_file *seq, void *v)
100688 from_kuid_munged(seq_user_ns(seq), sock_i_uid(sk)),
100689 sock_i_ino(sk),
100690 atomic_read(&sk->sk_refcnt), sk,
100691 - atomic_read(&sk->sk_drops));
100692 + atomic_read_unchecked(&sk->sk_drops));
100693 }
100694 seq_pad(seq, '\n');
100695 return 0;
100696 diff --git a/net/phonet/sysctl.c b/net/phonet/sysctl.c
100697 index c02a8c4..3c5b600 100644
100698 --- a/net/phonet/sysctl.c
100699 +++ b/net/phonet/sysctl.c
100700 @@ -67,7 +67,7 @@ static int proc_local_port_range(struct ctl_table *table, int write,
100701 {
100702 int ret;
100703 int range[2] = {local_port_range[0], local_port_range[1]};
100704 - struct ctl_table tmp = {
100705 + ctl_table_no_const tmp = {
100706 .data = &range,
100707 .maxlen = sizeof(range),
100708 .mode = table->mode,
100709 diff --git a/net/rds/cong.c b/net/rds/cong.c
100710 index e5b65ac..f3b6fb7 100644
100711 --- a/net/rds/cong.c
100712 +++ b/net/rds/cong.c
100713 @@ -78,7 +78,7 @@
100714 * finds that the saved generation number is smaller than the global generation
100715 * number, it wakes up the process.
100716 */
100717 -static atomic_t rds_cong_generation = ATOMIC_INIT(0);
100718 +static atomic_unchecked_t rds_cong_generation = ATOMIC_INIT(0);
100719
100720 /*
100721 * Congestion monitoring
100722 @@ -233,7 +233,7 @@ void rds_cong_map_updated(struct rds_cong_map *map, uint64_t portmask)
100723 rdsdebug("waking map %p for %pI4\n",
100724 map, &map->m_addr);
100725 rds_stats_inc(s_cong_update_received);
100726 - atomic_inc(&rds_cong_generation);
100727 + atomic_inc_unchecked(&rds_cong_generation);
100728 if (waitqueue_active(&map->m_waitq))
100729 wake_up(&map->m_waitq);
100730 if (waitqueue_active(&rds_poll_waitq))
100731 @@ -259,7 +259,7 @@ EXPORT_SYMBOL_GPL(rds_cong_map_updated);
100732
100733 int rds_cong_updated_since(unsigned long *recent)
100734 {
100735 - unsigned long gen = atomic_read(&rds_cong_generation);
100736 + unsigned long gen = atomic_read_unchecked(&rds_cong_generation);
100737
100738 if (likely(*recent == gen))
100739 return 0;
100740 diff --git a/net/rds/ib.h b/net/rds/ib.h
100741 index 7280ab8..e04f4ea 100644
100742 --- a/net/rds/ib.h
100743 +++ b/net/rds/ib.h
100744 @@ -128,7 +128,7 @@ struct rds_ib_connection {
100745 /* sending acks */
100746 unsigned long i_ack_flags;
100747 #ifdef KERNEL_HAS_ATOMIC64
100748 - atomic64_t i_ack_next; /* next ACK to send */
100749 + atomic64_unchecked_t i_ack_next; /* next ACK to send */
100750 #else
100751 spinlock_t i_ack_lock; /* protect i_ack_next */
100752 u64 i_ack_next; /* next ACK to send */
100753 diff --git a/net/rds/ib_cm.c b/net/rds/ib_cm.c
100754 index 31b74f5..dc1fbfa 100644
100755 --- a/net/rds/ib_cm.c
100756 +++ b/net/rds/ib_cm.c
100757 @@ -717,7 +717,7 @@ void rds_ib_conn_shutdown(struct rds_connection *conn)
100758 /* Clear the ACK state */
100759 clear_bit(IB_ACK_IN_FLIGHT, &ic->i_ack_flags);
100760 #ifdef KERNEL_HAS_ATOMIC64
100761 - atomic64_set(&ic->i_ack_next, 0);
100762 + atomic64_set_unchecked(&ic->i_ack_next, 0);
100763 #else
100764 ic->i_ack_next = 0;
100765 #endif
100766 diff --git a/net/rds/ib_recv.c b/net/rds/ib_recv.c
100767 index b7ebe23..b6352f6 100644
100768 --- a/net/rds/ib_recv.c
100769 +++ b/net/rds/ib_recv.c
100770 @@ -596,7 +596,7 @@ static u64 rds_ib_get_ack(struct rds_ib_connection *ic)
100771 static void rds_ib_set_ack(struct rds_ib_connection *ic, u64 seq,
100772 int ack_required)
100773 {
100774 - atomic64_set(&ic->i_ack_next, seq);
100775 + atomic64_set_unchecked(&ic->i_ack_next, seq);
100776 if (ack_required) {
100777 smp_mb__before_clear_bit();
100778 set_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
100779 @@ -608,7 +608,7 @@ static u64 rds_ib_get_ack(struct rds_ib_connection *ic)
100780 clear_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
100781 smp_mb__after_clear_bit();
100782
100783 - return atomic64_read(&ic->i_ack_next);
100784 + return atomic64_read_unchecked(&ic->i_ack_next);
100785 }
100786 #endif
100787
100788 diff --git a/net/rds/iw.h b/net/rds/iw.h
100789 index 04ce3b1..48119a6 100644
100790 --- a/net/rds/iw.h
100791 +++ b/net/rds/iw.h
100792 @@ -134,7 +134,7 @@ struct rds_iw_connection {
100793 /* sending acks */
100794 unsigned long i_ack_flags;
100795 #ifdef KERNEL_HAS_ATOMIC64
100796 - atomic64_t i_ack_next; /* next ACK to send */
100797 + atomic64_unchecked_t i_ack_next; /* next ACK to send */
100798 #else
100799 spinlock_t i_ack_lock; /* protect i_ack_next */
100800 u64 i_ack_next; /* next ACK to send */
100801 diff --git a/net/rds/iw_cm.c b/net/rds/iw_cm.c
100802 index a91e1db..cf3053f 100644
100803 --- a/net/rds/iw_cm.c
100804 +++ b/net/rds/iw_cm.c
100805 @@ -663,7 +663,7 @@ void rds_iw_conn_shutdown(struct rds_connection *conn)
100806 /* Clear the ACK state */
100807 clear_bit(IB_ACK_IN_FLIGHT, &ic->i_ack_flags);
100808 #ifdef KERNEL_HAS_ATOMIC64
100809 - atomic64_set(&ic->i_ack_next, 0);
100810 + atomic64_set_unchecked(&ic->i_ack_next, 0);
100811 #else
100812 ic->i_ack_next = 0;
100813 #endif
100814 diff --git a/net/rds/iw_recv.c b/net/rds/iw_recv.c
100815 index 4503335..db566b4 100644
100816 --- a/net/rds/iw_recv.c
100817 +++ b/net/rds/iw_recv.c
100818 @@ -427,7 +427,7 @@ static u64 rds_iw_get_ack(struct rds_iw_connection *ic)
100819 static void rds_iw_set_ack(struct rds_iw_connection *ic, u64 seq,
100820 int ack_required)
100821 {
100822 - atomic64_set(&ic->i_ack_next, seq);
100823 + atomic64_set_unchecked(&ic->i_ack_next, seq);
100824 if (ack_required) {
100825 smp_mb__before_clear_bit();
100826 set_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
100827 @@ -439,7 +439,7 @@ static u64 rds_iw_get_ack(struct rds_iw_connection *ic)
100828 clear_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
100829 smp_mb__after_clear_bit();
100830
100831 - return atomic64_read(&ic->i_ack_next);
100832 + return atomic64_read_unchecked(&ic->i_ack_next);
100833 }
100834 #endif
100835
100836 diff --git a/net/rds/rds.h b/net/rds/rds.h
100837 index 48f8ffc..0ef3eec 100644
100838 --- a/net/rds/rds.h
100839 +++ b/net/rds/rds.h
100840 @@ -449,7 +449,7 @@ struct rds_transport {
100841 void (*sync_mr)(void *trans_private, int direction);
100842 void (*free_mr)(void *trans_private, int invalidate);
100843 void (*flush_mrs)(void);
100844 -};
100845 +} __do_const;
100846
100847 struct rds_sock {
100848 struct sock rs_sk;
100849 diff --git a/net/rds/tcp.c b/net/rds/tcp.c
100850 index edac9ef..16bcb98 100644
100851 --- a/net/rds/tcp.c
100852 +++ b/net/rds/tcp.c
100853 @@ -59,7 +59,7 @@ void rds_tcp_nonagle(struct socket *sock)
100854 int val = 1;
100855
100856 set_fs(KERNEL_DS);
100857 - sock->ops->setsockopt(sock, SOL_TCP, TCP_NODELAY, (char __user *)&val,
100858 + sock->ops->setsockopt(sock, SOL_TCP, TCP_NODELAY, (char __force_user *)&val,
100859 sizeof(val));
100860 set_fs(oldfs);
100861 }
100862 diff --git a/net/rds/tcp_send.c b/net/rds/tcp_send.c
100863 index 81cf5a4..b5826ff 100644
100864 --- a/net/rds/tcp_send.c
100865 +++ b/net/rds/tcp_send.c
100866 @@ -43,7 +43,7 @@ static void rds_tcp_cork(struct socket *sock, int val)
100867
100868 oldfs = get_fs();
100869 set_fs(KERNEL_DS);
100870 - sock->ops->setsockopt(sock, SOL_TCP, TCP_CORK, (char __user *)&val,
100871 + sock->ops->setsockopt(sock, SOL_TCP, TCP_CORK, (char __force_user *)&val,
100872 sizeof(val));
100873 set_fs(oldfs);
100874 }
100875 diff --git a/net/rxrpc/af_rxrpc.c b/net/rxrpc/af_rxrpc.c
100876 index e61aa60..f07cc89 100644
100877 --- a/net/rxrpc/af_rxrpc.c
100878 +++ b/net/rxrpc/af_rxrpc.c
100879 @@ -40,7 +40,7 @@ static const struct proto_ops rxrpc_rpc_ops;
100880 __be32 rxrpc_epoch;
100881
100882 /* current debugging ID */
100883 -atomic_t rxrpc_debug_id;
100884 +atomic_unchecked_t rxrpc_debug_id;
100885
100886 /* count of skbs currently in use */
100887 atomic_t rxrpc_n_skbs;
100888 diff --git a/net/rxrpc/ar-ack.c b/net/rxrpc/ar-ack.c
100889 index e4d9cbc..b229649 100644
100890 --- a/net/rxrpc/ar-ack.c
100891 +++ b/net/rxrpc/ar-ack.c
100892 @@ -175,7 +175,7 @@ static void rxrpc_resend(struct rxrpc_call *call)
100893
100894 _enter("{%d,%d,%d,%d},",
100895 call->acks_hard, call->acks_unacked,
100896 - atomic_read(&call->sequence),
100897 + atomic_read_unchecked(&call->sequence),
100898 CIRC_CNT(call->acks_head, call->acks_tail, call->acks_winsz));
100899
100900 stop = 0;
100901 @@ -199,7 +199,7 @@ static void rxrpc_resend(struct rxrpc_call *call)
100902
100903 /* each Tx packet has a new serial number */
100904 sp->hdr.serial =
100905 - htonl(atomic_inc_return(&call->conn->serial));
100906 + htonl(atomic_inc_return_unchecked(&call->conn->serial));
100907
100908 hdr = (struct rxrpc_header *) txb->head;
100909 hdr->serial = sp->hdr.serial;
100910 @@ -403,7 +403,7 @@ static void rxrpc_rotate_tx_window(struct rxrpc_call *call, u32 hard)
100911 */
100912 static void rxrpc_clear_tx_window(struct rxrpc_call *call)
100913 {
100914 - rxrpc_rotate_tx_window(call, atomic_read(&call->sequence));
100915 + rxrpc_rotate_tx_window(call, atomic_read_unchecked(&call->sequence));
100916 }
100917
100918 /*
100919 @@ -629,7 +629,7 @@ process_further:
100920
100921 latest = ntohl(sp->hdr.serial);
100922 hard = ntohl(ack.firstPacket);
100923 - tx = atomic_read(&call->sequence);
100924 + tx = atomic_read_unchecked(&call->sequence);
100925
100926 _proto("Rx ACK %%%u { m=%hu f=#%u p=#%u s=%%%u r=%s n=%u }",
100927 latest,
100928 @@ -1161,7 +1161,7 @@ void rxrpc_process_call(struct work_struct *work)
100929 goto maybe_reschedule;
100930
100931 send_ACK_with_skew:
100932 - ack.maxSkew = htons(atomic_read(&call->conn->hi_serial) -
100933 + ack.maxSkew = htons(atomic_read_unchecked(&call->conn->hi_serial) -
100934 ntohl(ack.serial));
100935 send_ACK:
100936 mtu = call->conn->trans->peer->if_mtu;
100937 @@ -1173,7 +1173,7 @@ send_ACK:
100938 ackinfo.rxMTU = htonl(5692);
100939 ackinfo.jumbo_max = htonl(4);
100940
100941 - hdr.serial = htonl(atomic_inc_return(&call->conn->serial));
100942 + hdr.serial = htonl(atomic_inc_return_unchecked(&call->conn->serial));
100943 _proto("Tx ACK %%%u { m=%hu f=#%u p=#%u s=%%%u r=%s n=%u }",
100944 ntohl(hdr.serial),
100945 ntohs(ack.maxSkew),
100946 @@ -1191,7 +1191,7 @@ send_ACK:
100947 send_message:
100948 _debug("send message");
100949
100950 - hdr.serial = htonl(atomic_inc_return(&call->conn->serial));
100951 + hdr.serial = htonl(atomic_inc_return_unchecked(&call->conn->serial));
100952 _proto("Tx %s %%%u", rxrpc_pkts[hdr.type], ntohl(hdr.serial));
100953 send_message_2:
100954
100955 diff --git a/net/rxrpc/ar-call.c b/net/rxrpc/ar-call.c
100956 index a3bbb36..3341fb9 100644
100957 --- a/net/rxrpc/ar-call.c
100958 +++ b/net/rxrpc/ar-call.c
100959 @@ -83,7 +83,7 @@ static struct rxrpc_call *rxrpc_alloc_call(gfp_t gfp)
100960 spin_lock_init(&call->lock);
100961 rwlock_init(&call->state_lock);
100962 atomic_set(&call->usage, 1);
100963 - call->debug_id = atomic_inc_return(&rxrpc_debug_id);
100964 + call->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
100965 call->state = RXRPC_CALL_CLIENT_SEND_REQUEST;
100966
100967 memset(&call->sock_node, 0xed, sizeof(call->sock_node));
100968 diff --git a/net/rxrpc/ar-connection.c b/net/rxrpc/ar-connection.c
100969 index 4106ca9..a338d7a 100644
100970 --- a/net/rxrpc/ar-connection.c
100971 +++ b/net/rxrpc/ar-connection.c
100972 @@ -206,7 +206,7 @@ static struct rxrpc_connection *rxrpc_alloc_connection(gfp_t gfp)
100973 rwlock_init(&conn->lock);
100974 spin_lock_init(&conn->state_lock);
100975 atomic_set(&conn->usage, 1);
100976 - conn->debug_id = atomic_inc_return(&rxrpc_debug_id);
100977 + conn->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
100978 conn->avail_calls = RXRPC_MAXCALLS;
100979 conn->size_align = 4;
100980 conn->header_size = sizeof(struct rxrpc_header);
100981 diff --git a/net/rxrpc/ar-connevent.c b/net/rxrpc/ar-connevent.c
100982 index e7ed43a..6afa140 100644
100983 --- a/net/rxrpc/ar-connevent.c
100984 +++ b/net/rxrpc/ar-connevent.c
100985 @@ -109,7 +109,7 @@ static int rxrpc_abort_connection(struct rxrpc_connection *conn,
100986
100987 len = iov[0].iov_len + iov[1].iov_len;
100988
100989 - hdr.serial = htonl(atomic_inc_return(&conn->serial));
100990 + hdr.serial = htonl(atomic_inc_return_unchecked(&conn->serial));
100991 _proto("Tx CONN ABORT %%%u { %d }", ntohl(hdr.serial), abort_code);
100992
100993 ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 2, len);
100994 diff --git a/net/rxrpc/ar-input.c b/net/rxrpc/ar-input.c
100995 index 529572f..c758ca7 100644
100996 --- a/net/rxrpc/ar-input.c
100997 +++ b/net/rxrpc/ar-input.c
100998 @@ -340,9 +340,9 @@ void rxrpc_fast_process_packet(struct rxrpc_call *call, struct sk_buff *skb)
100999 /* track the latest serial number on this connection for ACK packet
101000 * information */
101001 serial = ntohl(sp->hdr.serial);
101002 - hi_serial = atomic_read(&call->conn->hi_serial);
101003 + hi_serial = atomic_read_unchecked(&call->conn->hi_serial);
101004 while (serial > hi_serial)
101005 - hi_serial = atomic_cmpxchg(&call->conn->hi_serial, hi_serial,
101006 + hi_serial = atomic_cmpxchg_unchecked(&call->conn->hi_serial, hi_serial,
101007 serial);
101008
101009 /* request ACK generation for any ACK or DATA packet that requests
101010 diff --git a/net/rxrpc/ar-internal.h b/net/rxrpc/ar-internal.h
101011 index 5f43675..ca07817 100644
101012 --- a/net/rxrpc/ar-internal.h
101013 +++ b/net/rxrpc/ar-internal.h
101014 @@ -272,8 +272,8 @@ struct rxrpc_connection {
101015 int error; /* error code for local abort */
101016 int debug_id; /* debug ID for printks */
101017 unsigned int call_counter; /* call ID counter */
101018 - atomic_t serial; /* packet serial number counter */
101019 - atomic_t hi_serial; /* highest serial number received */
101020 + atomic_unchecked_t serial; /* packet serial number counter */
101021 + atomic_unchecked_t hi_serial; /* highest serial number received */
101022 u8 avail_calls; /* number of calls available */
101023 u8 size_align; /* data size alignment (for security) */
101024 u8 header_size; /* rxrpc + security header size */
101025 @@ -346,7 +346,7 @@ struct rxrpc_call {
101026 spinlock_t lock;
101027 rwlock_t state_lock; /* lock for state transition */
101028 atomic_t usage;
101029 - atomic_t sequence; /* Tx data packet sequence counter */
101030 + atomic_unchecked_t sequence; /* Tx data packet sequence counter */
101031 u32 abort_code; /* local/remote abort code */
101032 enum { /* current state of call */
101033 RXRPC_CALL_CLIENT_SEND_REQUEST, /* - client sending request phase */
101034 @@ -420,7 +420,7 @@ static inline void rxrpc_abort_call(struct rxrpc_call *call, u32 abort_code)
101035 */
101036 extern atomic_t rxrpc_n_skbs;
101037 extern __be32 rxrpc_epoch;
101038 -extern atomic_t rxrpc_debug_id;
101039 +extern atomic_unchecked_t rxrpc_debug_id;
101040 extern struct workqueue_struct *rxrpc_workqueue;
101041
101042 /*
101043 diff --git a/net/rxrpc/ar-local.c b/net/rxrpc/ar-local.c
101044 index 87f7135..74d3703 100644
101045 --- a/net/rxrpc/ar-local.c
101046 +++ b/net/rxrpc/ar-local.c
101047 @@ -45,7 +45,7 @@ struct rxrpc_local *rxrpc_alloc_local(struct sockaddr_rxrpc *srx)
101048 spin_lock_init(&local->lock);
101049 rwlock_init(&local->services_lock);
101050 atomic_set(&local->usage, 1);
101051 - local->debug_id = atomic_inc_return(&rxrpc_debug_id);
101052 + local->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
101053 memcpy(&local->srx, srx, sizeof(*srx));
101054 }
101055
101056 diff --git a/net/rxrpc/ar-output.c b/net/rxrpc/ar-output.c
101057 index e1ac183..b43e10e 100644
101058 --- a/net/rxrpc/ar-output.c
101059 +++ b/net/rxrpc/ar-output.c
101060 @@ -682,9 +682,9 @@ static int rxrpc_send_data(struct kiocb *iocb,
101061 sp->hdr.cid = call->cid;
101062 sp->hdr.callNumber = call->call_id;
101063 sp->hdr.seq =
101064 - htonl(atomic_inc_return(&call->sequence));
101065 + htonl(atomic_inc_return_unchecked(&call->sequence));
101066 sp->hdr.serial =
101067 - htonl(atomic_inc_return(&conn->serial));
101068 + htonl(atomic_inc_return_unchecked(&conn->serial));
101069 sp->hdr.type = RXRPC_PACKET_TYPE_DATA;
101070 sp->hdr.userStatus = 0;
101071 sp->hdr.securityIndex = conn->security_ix;
101072 diff --git a/net/rxrpc/ar-peer.c b/net/rxrpc/ar-peer.c
101073 index bebaa43..2644591 100644
101074 --- a/net/rxrpc/ar-peer.c
101075 +++ b/net/rxrpc/ar-peer.c
101076 @@ -72,7 +72,7 @@ static struct rxrpc_peer *rxrpc_alloc_peer(struct sockaddr_rxrpc *srx,
101077 INIT_LIST_HEAD(&peer->error_targets);
101078 spin_lock_init(&peer->lock);
101079 atomic_set(&peer->usage, 1);
101080 - peer->debug_id = atomic_inc_return(&rxrpc_debug_id);
101081 + peer->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
101082 memcpy(&peer->srx, srx, sizeof(*srx));
101083
101084 rxrpc_assess_MTU_size(peer);
101085 diff --git a/net/rxrpc/ar-proc.c b/net/rxrpc/ar-proc.c
101086 index 38047f7..9f48511 100644
101087 --- a/net/rxrpc/ar-proc.c
101088 +++ b/net/rxrpc/ar-proc.c
101089 @@ -164,8 +164,8 @@ static int rxrpc_connection_seq_show(struct seq_file *seq, void *v)
101090 atomic_read(&conn->usage),
101091 rxrpc_conn_states[conn->state],
101092 key_serial(conn->key),
101093 - atomic_read(&conn->serial),
101094 - atomic_read(&conn->hi_serial));
101095 + atomic_read_unchecked(&conn->serial),
101096 + atomic_read_unchecked(&conn->hi_serial));
101097
101098 return 0;
101099 }
101100 diff --git a/net/rxrpc/ar-transport.c b/net/rxrpc/ar-transport.c
101101 index 92df566..87ec1bf 100644
101102 --- a/net/rxrpc/ar-transport.c
101103 +++ b/net/rxrpc/ar-transport.c
101104 @@ -47,7 +47,7 @@ static struct rxrpc_transport *rxrpc_alloc_transport(struct rxrpc_local *local,
101105 spin_lock_init(&trans->client_lock);
101106 rwlock_init(&trans->conn_lock);
101107 atomic_set(&trans->usage, 1);
101108 - trans->debug_id = atomic_inc_return(&rxrpc_debug_id);
101109 + trans->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
101110
101111 if (peer->srx.transport.family == AF_INET) {
101112 switch (peer->srx.transport_type) {
101113 diff --git a/net/rxrpc/rxkad.c b/net/rxrpc/rxkad.c
101114 index f226709..0e735a8 100644
101115 --- a/net/rxrpc/rxkad.c
101116 +++ b/net/rxrpc/rxkad.c
101117 @@ -610,7 +610,7 @@ static int rxkad_issue_challenge(struct rxrpc_connection *conn)
101118
101119 len = iov[0].iov_len + iov[1].iov_len;
101120
101121 - hdr.serial = htonl(atomic_inc_return(&conn->serial));
101122 + hdr.serial = htonl(atomic_inc_return_unchecked(&conn->serial));
101123 _proto("Tx CHALLENGE %%%u", ntohl(hdr.serial));
101124
101125 ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 2, len);
101126 @@ -660,7 +660,7 @@ static int rxkad_send_response(struct rxrpc_connection *conn,
101127
101128 len = iov[0].iov_len + iov[1].iov_len + iov[2].iov_len;
101129
101130 - hdr->serial = htonl(atomic_inc_return(&conn->serial));
101131 + hdr->serial = htonl(atomic_inc_return_unchecked(&conn->serial));
101132 _proto("Tx RESPONSE %%%u", ntohl(hdr->serial));
101133
101134 ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 3, len);
101135 diff --git a/net/sctp/ipv6.c b/net/sctp/ipv6.c
101136 index 7567e6f..299382b 100644
101137 --- a/net/sctp/ipv6.c
101138 +++ b/net/sctp/ipv6.c
101139 @@ -964,7 +964,7 @@ static const struct inet6_protocol sctpv6_protocol = {
101140 .flags = INET6_PROTO_NOPOLICY | INET6_PROTO_FINAL,
101141 };
101142
101143 -static struct sctp_af sctp_af_inet6 = {
101144 +static struct sctp_af sctp_af_inet6 __read_only = {
101145 .sa_family = AF_INET6,
101146 .sctp_xmit = sctp_v6_xmit,
101147 .setsockopt = ipv6_setsockopt,
101148 @@ -996,7 +996,7 @@ static struct sctp_af sctp_af_inet6 = {
101149 #endif
101150 };
101151
101152 -static struct sctp_pf sctp_pf_inet6 = {
101153 +static struct sctp_pf sctp_pf_inet6 __read_only = {
101154 .event_msgname = sctp_inet6_event_msgname,
101155 .skb_msgname = sctp_inet6_skb_msgname,
101156 .af_supported = sctp_inet6_af_supported,
101157 @@ -1021,7 +1021,7 @@ void sctp_v6_pf_init(void)
101158
101159 void sctp_v6_pf_exit(void)
101160 {
101161 - list_del(&sctp_af_inet6.list);
101162 + pax_list_del(&sctp_af_inet6.list);
101163 }
101164
101165 /* Initialize IPv6 support and register with socket layer. */
101166 diff --git a/net/sctp/protocol.c b/net/sctp/protocol.c
101167 index 5e17092..19be1d4 100644
101168 --- a/net/sctp/protocol.c
101169 +++ b/net/sctp/protocol.c
101170 @@ -832,8 +832,10 @@ int sctp_register_af(struct sctp_af *af)
101171 return 0;
101172 }
101173
101174 + pax_open_kernel();
101175 INIT_LIST_HEAD(&af->list);
101176 - list_add_tail(&af->list, &sctp_address_families);
101177 + pax_close_kernel();
101178 + pax_list_add_tail(&af->list, &sctp_address_families);
101179 return 1;
101180 }
101181
101182 @@ -963,7 +965,7 @@ static inline int sctp_v4_xmit(struct sk_buff *skb,
101183
101184 static struct sctp_af sctp_af_inet;
101185
101186 -static struct sctp_pf sctp_pf_inet = {
101187 +static struct sctp_pf sctp_pf_inet __read_only = {
101188 .event_msgname = sctp_inet_event_msgname,
101189 .skb_msgname = sctp_inet_skb_msgname,
101190 .af_supported = sctp_inet_af_supported,
101191 @@ -1034,7 +1036,7 @@ static const struct net_protocol sctp_protocol = {
101192 };
101193
101194 /* IPv4 address related functions. */
101195 -static struct sctp_af sctp_af_inet = {
101196 +static struct sctp_af sctp_af_inet __read_only = {
101197 .sa_family = AF_INET,
101198 .sctp_xmit = sctp_v4_xmit,
101199 .setsockopt = ip_setsockopt,
101200 @@ -1119,7 +1121,7 @@ static void sctp_v4_pf_init(void)
101201
101202 static void sctp_v4_pf_exit(void)
101203 {
101204 - list_del(&sctp_af_inet.list);
101205 + pax_list_del(&sctp_af_inet.list);
101206 }
101207
101208 static int sctp_v4_protosw_init(void)
101209 diff --git a/net/sctp/sm_sideeffect.c b/net/sctp/sm_sideeffect.c
101210 index 1a6eef3..17e898f 100644
101211 --- a/net/sctp/sm_sideeffect.c
101212 +++ b/net/sctp/sm_sideeffect.c
101213 @@ -440,7 +440,7 @@ static void sctp_generate_sack_event(unsigned long data)
101214 sctp_generate_timeout_event(asoc, SCTP_EVENT_TIMEOUT_SACK);
101215 }
101216
101217 -sctp_timer_event_t *sctp_timer_events[SCTP_NUM_TIMEOUT_TYPES] = {
101218 +sctp_timer_event_t * const sctp_timer_events[SCTP_NUM_TIMEOUT_TYPES] = {
101219 NULL,
101220 sctp_generate_t1_cookie_event,
101221 sctp_generate_t1_init_event,
101222 diff --git a/net/sctp/socket.c b/net/sctp/socket.c
101223 index 146b35d..1021a34 100644
101224 --- a/net/sctp/socket.c
101225 +++ b/net/sctp/socket.c
101226 @@ -2176,11 +2176,13 @@ static int sctp_setsockopt_events(struct sock *sk, char __user *optval,
101227 {
101228 struct sctp_association *asoc;
101229 struct sctp_ulpevent *event;
101230 + struct sctp_event_subscribe subscribe;
101231
101232 if (optlen > sizeof(struct sctp_event_subscribe))
101233 return -EINVAL;
101234 - if (copy_from_user(&sctp_sk(sk)->subscribe, optval, optlen))
101235 + if (copy_from_user(&subscribe, optval, optlen))
101236 return -EFAULT;
101237 + sctp_sk(sk)->subscribe = subscribe;
101238
101239 /*
101240 * At the time when a user app subscribes to SCTP_SENDER_DRY_EVENT,
101241 @@ -4252,13 +4254,16 @@ static int sctp_getsockopt_disable_fragments(struct sock *sk, int len,
101242 static int sctp_getsockopt_events(struct sock *sk, int len, char __user *optval,
101243 int __user *optlen)
101244 {
101245 + struct sctp_event_subscribe subscribe;
101246 +
101247 if (len <= 0)
101248 return -EINVAL;
101249 if (len > sizeof(struct sctp_event_subscribe))
101250 len = sizeof(struct sctp_event_subscribe);
101251 if (put_user(len, optlen))
101252 return -EFAULT;
101253 - if (copy_to_user(optval, &sctp_sk(sk)->subscribe, len))
101254 + subscribe = sctp_sk(sk)->subscribe;
101255 + if (copy_to_user(optval, &subscribe, len))
101256 return -EFAULT;
101257 return 0;
101258 }
101259 @@ -4276,6 +4281,8 @@ static int sctp_getsockopt_events(struct sock *sk, int len, char __user *optval,
101260 */
101261 static int sctp_getsockopt_autoclose(struct sock *sk, int len, char __user *optval, int __user *optlen)
101262 {
101263 + __u32 autoclose;
101264 +
101265 /* Applicable to UDP-style socket only */
101266 if (sctp_style(sk, TCP))
101267 return -EOPNOTSUPP;
101268 @@ -4284,7 +4291,8 @@ static int sctp_getsockopt_autoclose(struct sock *sk, int len, char __user *optv
101269 len = sizeof(int);
101270 if (put_user(len, optlen))
101271 return -EFAULT;
101272 - if (copy_to_user(optval, &sctp_sk(sk)->autoclose, sizeof(int)))
101273 + autoclose = sctp_sk(sk)->autoclose;
101274 + if (copy_to_user(optval, &autoclose, sizeof(int)))
101275 return -EFAULT;
101276 return 0;
101277 }
101278 @@ -4656,12 +4664,15 @@ static int sctp_getsockopt_delayed_ack(struct sock *sk, int len,
101279 */
101280 static int sctp_getsockopt_initmsg(struct sock *sk, int len, char __user *optval, int __user *optlen)
101281 {
101282 + struct sctp_initmsg initmsg;
101283 +
101284 if (len < sizeof(struct sctp_initmsg))
101285 return -EINVAL;
101286 len = sizeof(struct sctp_initmsg);
101287 if (put_user(len, optlen))
101288 return -EFAULT;
101289 - if (copy_to_user(optval, &sctp_sk(sk)->initmsg, len))
101290 + initmsg = sctp_sk(sk)->initmsg;
101291 + if (copy_to_user(optval, &initmsg, len))
101292 return -EFAULT;
101293 return 0;
101294 }
101295 @@ -4702,6 +4713,8 @@ static int sctp_getsockopt_peer_addrs(struct sock *sk, int len,
101296 addrlen = sctp_get_af_specific(temp.sa.sa_family)->sockaddr_len;
101297 if (space_left < addrlen)
101298 return -ENOMEM;
101299 + if (addrlen > sizeof(temp) || addrlen < 0)
101300 + return -EFAULT;
101301 if (copy_to_user(to, &temp, addrlen))
101302 return -EFAULT;
101303 to += addrlen;
101304 diff --git a/net/sctp/sysctl.c b/net/sctp/sysctl.c
101305 index b0565af..d135e6e 100644
101306 --- a/net/sctp/sysctl.c
101307 +++ b/net/sctp/sysctl.c
101308 @@ -305,7 +305,7 @@ static int proc_sctp_do_hmac_alg(struct ctl_table *ctl, int write,
101309 {
101310 struct net *net = current->nsproxy->net_ns;
101311 char tmp[8];
101312 - struct ctl_table tbl;
101313 + ctl_table_no_const tbl;
101314 int ret;
101315 int changed = 0;
101316 char *none = "none";
101317 @@ -352,7 +352,7 @@ static int proc_sctp_do_rto_min(struct ctl_table *ctl, int write,
101318 {
101319 struct net *net = current->nsproxy->net_ns;
101320 int new_value;
101321 - struct ctl_table tbl;
101322 + ctl_table_no_const tbl;
101323 unsigned int min = *(unsigned int *) ctl->extra1;
101324 unsigned int max = *(unsigned int *) ctl->extra2;
101325 int ret;
101326 @@ -379,7 +379,7 @@ static int proc_sctp_do_rto_max(struct ctl_table *ctl, int write,
101327 {
101328 struct net *net = current->nsproxy->net_ns;
101329 int new_value;
101330 - struct ctl_table tbl;
101331 + ctl_table_no_const tbl;
101332 unsigned int min = *(unsigned int *) ctl->extra1;
101333 unsigned int max = *(unsigned int *) ctl->extra2;
101334 int ret;
101335 @@ -402,7 +402,7 @@ static int proc_sctp_do_rto_max(struct ctl_table *ctl, int write,
101336
101337 int sctp_sysctl_net_register(struct net *net)
101338 {
101339 - struct ctl_table *table;
101340 + ctl_table_no_const *table;
101341 int i;
101342
101343 table = kmemdup(sctp_net_table, sizeof(sctp_net_table), GFP_KERNEL);
101344 diff --git a/net/socket.c b/net/socket.c
101345 index dc57dae..5b883e0 100644
101346 --- a/net/socket.c
101347 +++ b/net/socket.c
101348 @@ -88,6 +88,7 @@
101349 #include <linux/magic.h>
101350 #include <linux/slab.h>
101351 #include <linux/xattr.h>
101352 +#include <linux/in.h>
101353
101354 #include <asm/uaccess.h>
101355 #include <asm/unistd.h>
101356 @@ -111,6 +112,8 @@ unsigned int sysctl_net_busy_read __read_mostly;
101357 unsigned int sysctl_net_busy_poll __read_mostly;
101358 #endif
101359
101360 +#include <linux/grsock.h>
101361 +
101362 static int sock_no_open(struct inode *irrelevant, struct file *dontcare);
101363 static ssize_t sock_aio_read(struct kiocb *iocb, const struct iovec *iov,
101364 unsigned long nr_segs, loff_t pos);
101365 @@ -162,7 +165,7 @@ static const struct file_operations socket_file_ops = {
101366 */
101367
101368 static DEFINE_SPINLOCK(net_family_lock);
101369 -static const struct net_proto_family __rcu *net_families[NPROTO] __read_mostly;
101370 +const struct net_proto_family __rcu *net_families[NPROTO] __read_mostly;
101371
101372 /*
101373 * Statistics counters of the socket lists
101374 @@ -328,7 +331,7 @@ static struct dentry *sockfs_mount(struct file_system_type *fs_type,
101375 &sockfs_dentry_operations, SOCKFS_MAGIC);
101376 }
101377
101378 -static struct vfsmount *sock_mnt __read_mostly;
101379 +struct vfsmount *sock_mnt __read_mostly;
101380
101381 static struct file_system_type sock_fs_type = {
101382 .name = "sockfs",
101383 @@ -1255,6 +1258,8 @@ int __sock_create(struct net *net, int family, int type, int protocol,
101384 return -EAFNOSUPPORT;
101385 if (type < 0 || type >= SOCK_MAX)
101386 return -EINVAL;
101387 + if (protocol < 0)
101388 + return -EINVAL;
101389
101390 /* Compatibility.
101391
101392 @@ -1275,6 +1280,20 @@ int __sock_create(struct net *net, int family, int type, int protocol,
101393 if (err)
101394 return err;
101395
101396 + if(!kern && !gr_search_socket(family, type, protocol)) {
101397 + if (rcu_access_pointer(net_families[family]) == NULL)
101398 + return -EAFNOSUPPORT;
101399 + else
101400 + return -EACCES;
101401 + }
101402 +
101403 + if (!kern && gr_handle_sock_all(family, type, protocol)) {
101404 + if (rcu_access_pointer(net_families[family]) == NULL)
101405 + return -EAFNOSUPPORT;
101406 + else
101407 + return -EACCES;
101408 + }
101409 +
101410 /*
101411 * Allocate the socket and allow the family to set things up. if
101412 * the protocol is 0, the family is instructed to select an appropriate
101413 @@ -1513,6 +1532,14 @@ SYSCALL_DEFINE3(bind, int, fd, struct sockaddr __user *, umyaddr, int, addrlen)
101414 if (sock) {
101415 err = move_addr_to_kernel(umyaddr, addrlen, &address);
101416 if (err >= 0) {
101417 + if (gr_handle_sock_server((struct sockaddr *)&address)) {
101418 + err = -EACCES;
101419 + goto error;
101420 + }
101421 + err = gr_search_bind(sock, (struct sockaddr_in *)&address);
101422 + if (err)
101423 + goto error;
101424 +
101425 err = security_socket_bind(sock,
101426 (struct sockaddr *)&address,
101427 addrlen);
101428 @@ -1521,6 +1548,7 @@ SYSCALL_DEFINE3(bind, int, fd, struct sockaddr __user *, umyaddr, int, addrlen)
101429 (struct sockaddr *)
101430 &address, addrlen);
101431 }
101432 +error:
101433 fput_light(sock->file, fput_needed);
101434 }
101435 return err;
101436 @@ -1544,10 +1572,20 @@ SYSCALL_DEFINE2(listen, int, fd, int, backlog)
101437 if ((unsigned int)backlog > somaxconn)
101438 backlog = somaxconn;
101439
101440 + if (gr_handle_sock_server_other(sock->sk)) {
101441 + err = -EPERM;
101442 + goto error;
101443 + }
101444 +
101445 + err = gr_search_listen(sock);
101446 + if (err)
101447 + goto error;
101448 +
101449 err = security_socket_listen(sock, backlog);
101450 if (!err)
101451 err = sock->ops->listen(sock, backlog);
101452
101453 +error:
101454 fput_light(sock->file, fput_needed);
101455 }
101456 return err;
101457 @@ -1591,6 +1629,18 @@ SYSCALL_DEFINE4(accept4, int, fd, struct sockaddr __user *, upeer_sockaddr,
101458 newsock->type = sock->type;
101459 newsock->ops = sock->ops;
101460
101461 + if (gr_handle_sock_server_other(sock->sk)) {
101462 + err = -EPERM;
101463 + sock_release(newsock);
101464 + goto out_put;
101465 + }
101466 +
101467 + err = gr_search_accept(sock);
101468 + if (err) {
101469 + sock_release(newsock);
101470 + goto out_put;
101471 + }
101472 +
101473 /*
101474 * We don't need try_module_get here, as the listening socket (sock)
101475 * has the protocol module (sock->ops->owner) held.
101476 @@ -1636,6 +1686,8 @@ SYSCALL_DEFINE4(accept4, int, fd, struct sockaddr __user *, upeer_sockaddr,
101477 fd_install(newfd, newfile);
101478 err = newfd;
101479
101480 + gr_attach_curr_ip(newsock->sk);
101481 +
101482 out_put:
101483 fput_light(sock->file, fput_needed);
101484 out:
101485 @@ -1668,6 +1720,7 @@ SYSCALL_DEFINE3(connect, int, fd, struct sockaddr __user *, uservaddr,
101486 int, addrlen)
101487 {
101488 struct socket *sock;
101489 + struct sockaddr *sck;
101490 struct sockaddr_storage address;
101491 int err, fput_needed;
101492
101493 @@ -1678,6 +1731,17 @@ SYSCALL_DEFINE3(connect, int, fd, struct sockaddr __user *, uservaddr,
101494 if (err < 0)
101495 goto out_put;
101496
101497 + sck = (struct sockaddr *)&address;
101498 +
101499 + if (gr_handle_sock_client(sck)) {
101500 + err = -EACCES;
101501 + goto out_put;
101502 + }
101503 +
101504 + err = gr_search_connect(sock, (struct sockaddr_in *)sck);
101505 + if (err)
101506 + goto out_put;
101507 +
101508 err =
101509 security_socket_connect(sock, (struct sockaddr *)&address, addrlen);
101510 if (err)
101511 @@ -1759,6 +1823,8 @@ SYSCALL_DEFINE3(getpeername, int, fd, struct sockaddr __user *, usockaddr,
101512 * the protocol.
101513 */
101514
101515 +asmlinkage long sys_sendto(int, void __user *, size_t, unsigned, struct sockaddr __user *, int);
101516 +
101517 SYSCALL_DEFINE6(sendto, int, fd, void __user *, buff, size_t, len,
101518 unsigned int, flags, struct sockaddr __user *, addr,
101519 int, addr_len)
101520 @@ -1825,7 +1891,7 @@ SYSCALL_DEFINE6(recvfrom, int, fd, void __user *, ubuf, size_t, size,
101521 struct socket *sock;
101522 struct iovec iov;
101523 struct msghdr msg;
101524 - struct sockaddr_storage address;
101525 + struct sockaddr_storage address = { };
101526 int err, err2;
101527 int fput_needed;
101528
101529 @@ -2051,7 +2117,7 @@ static int ___sys_sendmsg(struct socket *sock, struct msghdr __user *msg,
101530 * checking falls down on this.
101531 */
101532 if (copy_from_user(ctl_buf,
101533 - (void __user __force *)msg_sys->msg_control,
101534 + (void __force_user *)msg_sys->msg_control,
101535 ctl_len))
101536 goto out_freectl;
101537 msg_sys->msg_control = ctl_buf;
101538 @@ -2202,7 +2268,7 @@ static int ___sys_recvmsg(struct socket *sock, struct msghdr __user *msg,
101539 int err, total_len, len;
101540
101541 /* kernel mode address */
101542 - struct sockaddr_storage addr;
101543 + struct sockaddr_storage addr = { };
101544
101545 /* user mode address pointers */
101546 struct sockaddr __user *uaddr;
101547 @@ -2231,7 +2297,7 @@ static int ___sys_recvmsg(struct socket *sock, struct msghdr __user *msg,
101548 /* Save the user-mode address (verify_iovec will change the
101549 * kernel msghdr to use the kernel address space)
101550 */
101551 - uaddr = (__force void __user *)msg_sys->msg_name;
101552 + uaddr = (void __force_user *)msg_sys->msg_name;
101553 uaddr_len = COMPAT_NAMELEN(msg);
101554 if (MSG_CMSG_COMPAT & flags)
101555 err = verify_compat_iovec(msg_sys, iov, &addr, VERIFY_WRITE);
101556 @@ -2875,7 +2941,7 @@ static int ethtool_ioctl(struct net *net, struct compat_ifreq __user *ifr32)
101557 ifr = compat_alloc_user_space(buf_size);
101558 rxnfc = (void __user *)ifr + ALIGN(sizeof(struct ifreq), 8);
101559
101560 - if (copy_in_user(&ifr->ifr_name, &ifr32->ifr_name, IFNAMSIZ))
101561 + if (copy_in_user(ifr->ifr_name, ifr32->ifr_name, IFNAMSIZ))
101562 return -EFAULT;
101563
101564 if (put_user(convert_in ? rxnfc : compat_ptr(data),
101565 @@ -2989,14 +3055,14 @@ static int bond_ioctl(struct net *net, unsigned int cmd,
101566 old_fs = get_fs();
101567 set_fs(KERNEL_DS);
101568 err = dev_ioctl(net, cmd,
101569 - (struct ifreq __user __force *) &kifr);
101570 + (struct ifreq __force_user *) &kifr);
101571 set_fs(old_fs);
101572
101573 return err;
101574 case SIOCBONDSLAVEINFOQUERY:
101575 case SIOCBONDINFOQUERY:
101576 uifr = compat_alloc_user_space(sizeof(*uifr));
101577 - if (copy_in_user(&uifr->ifr_name, &ifr32->ifr_name, IFNAMSIZ))
101578 + if (copy_in_user(uifr->ifr_name, ifr32->ifr_name, IFNAMSIZ))
101579 return -EFAULT;
101580
101581 if (get_user(data, &ifr32->ifr_ifru.ifru_data))
101582 @@ -3098,7 +3164,7 @@ static int compat_sioc_ifmap(struct net *net, unsigned int cmd,
101583
101584 old_fs = get_fs();
101585 set_fs(KERNEL_DS);
101586 - err = dev_ioctl(net, cmd, (void __user __force *)&ifr);
101587 + err = dev_ioctl(net, cmd, (void __force_user *)&ifr);
101588 set_fs(old_fs);
101589
101590 if (cmd == SIOCGIFMAP && !err) {
101591 @@ -3203,7 +3269,7 @@ static int routing_ioctl(struct net *net, struct socket *sock,
101592 ret |= get_user(rtdev, &(ur4->rt_dev));
101593 if (rtdev) {
101594 ret |= copy_from_user(devname, compat_ptr(rtdev), 15);
101595 - r4.rt_dev = (char __user __force *)devname;
101596 + r4.rt_dev = (char __force_user *)devname;
101597 devname[15] = 0;
101598 } else
101599 r4.rt_dev = NULL;
101600 @@ -3429,8 +3495,8 @@ int kernel_getsockopt(struct socket *sock, int level, int optname,
101601 int __user *uoptlen;
101602 int err;
101603
101604 - uoptval = (char __user __force *) optval;
101605 - uoptlen = (int __user __force *) optlen;
101606 + uoptval = (char __force_user *) optval;
101607 + uoptlen = (int __force_user *) optlen;
101608
101609 set_fs(KERNEL_DS);
101610 if (level == SOL_SOCKET)
101611 @@ -3450,7 +3516,7 @@ int kernel_setsockopt(struct socket *sock, int level, int optname,
101612 char __user *uoptval;
101613 int err;
101614
101615 - uoptval = (char __user __force *) optval;
101616 + uoptval = (char __force_user *) optval;
101617
101618 set_fs(KERNEL_DS);
101619 if (level == SOL_SOCKET)
101620 diff --git a/net/sunrpc/auth_gss/svcauth_gss.c b/net/sunrpc/auth_gss/svcauth_gss.c
101621 index 1b94a9c..496f7f5 100644
101622 --- a/net/sunrpc/auth_gss/svcauth_gss.c
101623 +++ b/net/sunrpc/auth_gss/svcauth_gss.c
101624 @@ -1140,7 +1140,7 @@ static int gss_proxy_save_rsc(struct cache_detail *cd,
101625 uint64_t *handle)
101626 {
101627 struct rsc rsci, *rscp = NULL;
101628 - static atomic64_t ctxhctr;
101629 + static atomic64_unchecked_t ctxhctr = ATOMIC64_INIT(0);
101630 long long ctxh;
101631 struct gss_api_mech *gm = NULL;
101632 time_t expiry;
101633 @@ -1151,7 +1151,7 @@ static int gss_proxy_save_rsc(struct cache_detail *cd,
101634 status = -ENOMEM;
101635 /* the handle needs to be just a unique id,
101636 * use a static counter */
101637 - ctxh = atomic64_inc_return(&ctxhctr);
101638 + ctxh = atomic64_inc_return_unchecked(&ctxhctr);
101639
101640 /* make a copy for the caller */
101641 *handle = ctxh;
101642 diff --git a/net/sunrpc/backchannel_rqst.c b/net/sunrpc/backchannel_rqst.c
101643 index 890a299..e860d4f 100644
101644 --- a/net/sunrpc/backchannel_rqst.c
101645 +++ b/net/sunrpc/backchannel_rqst.c
101646 @@ -64,7 +64,6 @@ static void xprt_free_allocation(struct rpc_rqst *req)
101647 free_page((unsigned long)xbufp->head[0].iov_base);
101648 xbufp = &req->rq_snd_buf;
101649 free_page((unsigned long)xbufp->head[0].iov_base);
101650 - list_del(&req->rq_bc_pa_list);
101651 kfree(req);
101652 }
101653
101654 @@ -168,8 +167,10 @@ out_free:
101655 /*
101656 * Memory allocation failed, free the temporary list
101657 */
101658 - list_for_each_entry_safe(req, tmp, &tmp_list, rq_bc_pa_list)
101659 + list_for_each_entry_safe(req, tmp, &tmp_list, rq_bc_pa_list) {
101660 + list_del(&req->rq_bc_pa_list);
101661 xprt_free_allocation(req);
101662 + }
101663
101664 dprintk("RPC: setup backchannel transport failed\n");
101665 return -ENOMEM;
101666 @@ -198,6 +199,7 @@ void xprt_destroy_backchannel(struct rpc_xprt *xprt, unsigned int max_reqs)
101667 xprt_dec_alloc_count(xprt, max_reqs);
101668 list_for_each_entry_safe(req, tmp, &xprt->bc_pa_list, rq_bc_pa_list) {
101669 dprintk("RPC: req=%p\n", req);
101670 + list_del(&req->rq_bc_pa_list);
101671 xprt_free_allocation(req);
101672 if (--max_reqs == 0)
101673 break;
101674 diff --git a/net/sunrpc/clnt.c b/net/sunrpc/clnt.c
101675 index e726e16..393c39e 100644
101676 --- a/net/sunrpc/clnt.c
101677 +++ b/net/sunrpc/clnt.c
101678 @@ -1415,7 +1415,9 @@ call_start(struct rpc_task *task)
101679 (RPC_IS_ASYNC(task) ? "async" : "sync"));
101680
101681 /* Increment call count */
101682 - task->tk_msg.rpc_proc->p_count++;
101683 + pax_open_kernel();
101684 + (*(unsigned int *)&task->tk_msg.rpc_proc->p_count)++;
101685 + pax_close_kernel();
101686 clnt->cl_stats->rpccnt++;
101687 task->tk_action = call_reserve;
101688 }
101689 diff --git a/net/sunrpc/sched.c b/net/sunrpc/sched.c
101690 index ff3cc4b..7612a9e 100644
101691 --- a/net/sunrpc/sched.c
101692 +++ b/net/sunrpc/sched.c
101693 @@ -261,9 +261,9 @@ static int rpc_wait_bit_killable(void *word)
101694 #if defined(RPC_DEBUG) || defined(RPC_TRACEPOINTS)
101695 static void rpc_task_set_debuginfo(struct rpc_task *task)
101696 {
101697 - static atomic_t rpc_pid;
101698 + static atomic_unchecked_t rpc_pid;
101699
101700 - task->tk_pid = atomic_inc_return(&rpc_pid);
101701 + task->tk_pid = atomic_inc_return_unchecked(&rpc_pid);
101702 }
101703 #else
101704 static inline void rpc_task_set_debuginfo(struct rpc_task *task)
101705 diff --git a/net/sunrpc/svc.c b/net/sunrpc/svc.c
101706 index e7fbe36..8052603 100644
101707 --- a/net/sunrpc/svc.c
101708 +++ b/net/sunrpc/svc.c
101709 @@ -1158,7 +1158,9 @@ svc_process_common(struct svc_rqst *rqstp, struct kvec *argv, struct kvec *resv)
101710 svc_putnl(resv, RPC_SUCCESS);
101711
101712 /* Bump per-procedure stats counter */
101713 - procp->pc_count++;
101714 + pax_open_kernel();
101715 + (*(unsigned int *)&procp->pc_count)++;
101716 + pax_close_kernel();
101717
101718 /* Initialize storage for argp and resp */
101719 memset(rqstp->rq_argp, 0, procp->pc_argsize);
101720 diff --git a/net/sunrpc/svcauth_unix.c b/net/sunrpc/svcauth_unix.c
101721 index 621ca7b..59421dd 100644
101722 --- a/net/sunrpc/svcauth_unix.c
101723 +++ b/net/sunrpc/svcauth_unix.c
101724 @@ -414,7 +414,7 @@ struct unix_gid {
101725 struct group_info *gi;
101726 };
101727
101728 -static int unix_gid_hash(kuid_t uid)
101729 +static int __intentional_overflow(-1) unix_gid_hash(kuid_t uid)
101730 {
101731 return hash_long(from_kuid(&init_user_ns, uid), GID_HASHBITS);
101732 }
101733 @@ -470,7 +470,7 @@ static void unix_gid_request(struct cache_detail *cd,
101734 (*bpp)[-1] = '\n';
101735 }
101736
101737 -static struct unix_gid *unix_gid_lookup(struct cache_detail *cd, kuid_t uid);
101738 +static struct unix_gid * __intentional_overflow(-1) unix_gid_lookup(struct cache_detail *cd, kuid_t uid);
101739
101740 static int unix_gid_parse(struct cache_detail *cd,
101741 char *mesg, int mlen)
101742 diff --git a/net/sunrpc/xprtrdma/svc_rdma.c b/net/sunrpc/xprtrdma/svc_rdma.c
101743 index c1b6270..05089c1 100644
101744 --- a/net/sunrpc/xprtrdma/svc_rdma.c
101745 +++ b/net/sunrpc/xprtrdma/svc_rdma.c
101746 @@ -62,15 +62,15 @@ unsigned int svcrdma_max_req_size = RPCRDMA_MAX_REQ_SIZE;
101747 static unsigned int min_max_inline = 4096;
101748 static unsigned int max_max_inline = 65536;
101749
101750 -atomic_t rdma_stat_recv;
101751 -atomic_t rdma_stat_read;
101752 -atomic_t rdma_stat_write;
101753 -atomic_t rdma_stat_sq_starve;
101754 -atomic_t rdma_stat_rq_starve;
101755 -atomic_t rdma_stat_rq_poll;
101756 -atomic_t rdma_stat_rq_prod;
101757 -atomic_t rdma_stat_sq_poll;
101758 -atomic_t rdma_stat_sq_prod;
101759 +atomic_unchecked_t rdma_stat_recv;
101760 +atomic_unchecked_t rdma_stat_read;
101761 +atomic_unchecked_t rdma_stat_write;
101762 +atomic_unchecked_t rdma_stat_sq_starve;
101763 +atomic_unchecked_t rdma_stat_rq_starve;
101764 +atomic_unchecked_t rdma_stat_rq_poll;
101765 +atomic_unchecked_t rdma_stat_rq_prod;
101766 +atomic_unchecked_t rdma_stat_sq_poll;
101767 +atomic_unchecked_t rdma_stat_sq_prod;
101768
101769 /* Temporary NFS request map and context caches */
101770 struct kmem_cache *svc_rdma_map_cachep;
101771 @@ -110,7 +110,7 @@ static int read_reset_stat(struct ctl_table *table, int write,
101772 len -= *ppos;
101773 if (len > *lenp)
101774 len = *lenp;
101775 - if (len && copy_to_user(buffer, str_buf, len))
101776 + if (len > sizeof str_buf || (len && copy_to_user(buffer, str_buf, len)))
101777 return -EFAULT;
101778 *lenp = len;
101779 *ppos += len;
101780 @@ -151,63 +151,63 @@ static struct ctl_table svcrdma_parm_table[] = {
101781 {
101782 .procname = "rdma_stat_read",
101783 .data = &rdma_stat_read,
101784 - .maxlen = sizeof(atomic_t),
101785 + .maxlen = sizeof(atomic_unchecked_t),
101786 .mode = 0644,
101787 .proc_handler = read_reset_stat,
101788 },
101789 {
101790 .procname = "rdma_stat_recv",
101791 .data = &rdma_stat_recv,
101792 - .maxlen = sizeof(atomic_t),
101793 + .maxlen = sizeof(atomic_unchecked_t),
101794 .mode = 0644,
101795 .proc_handler = read_reset_stat,
101796 },
101797 {
101798 .procname = "rdma_stat_write",
101799 .data = &rdma_stat_write,
101800 - .maxlen = sizeof(atomic_t),
101801 + .maxlen = sizeof(atomic_unchecked_t),
101802 .mode = 0644,
101803 .proc_handler = read_reset_stat,
101804 },
101805 {
101806 .procname = "rdma_stat_sq_starve",
101807 .data = &rdma_stat_sq_starve,
101808 - .maxlen = sizeof(atomic_t),
101809 + .maxlen = sizeof(atomic_unchecked_t),
101810 .mode = 0644,
101811 .proc_handler = read_reset_stat,
101812 },
101813 {
101814 .procname = "rdma_stat_rq_starve",
101815 .data = &rdma_stat_rq_starve,
101816 - .maxlen = sizeof(atomic_t),
101817 + .maxlen = sizeof(atomic_unchecked_t),
101818 .mode = 0644,
101819 .proc_handler = read_reset_stat,
101820 },
101821 {
101822 .procname = "rdma_stat_rq_poll",
101823 .data = &rdma_stat_rq_poll,
101824 - .maxlen = sizeof(atomic_t),
101825 + .maxlen = sizeof(atomic_unchecked_t),
101826 .mode = 0644,
101827 .proc_handler = read_reset_stat,
101828 },
101829 {
101830 .procname = "rdma_stat_rq_prod",
101831 .data = &rdma_stat_rq_prod,
101832 - .maxlen = sizeof(atomic_t),
101833 + .maxlen = sizeof(atomic_unchecked_t),
101834 .mode = 0644,
101835 .proc_handler = read_reset_stat,
101836 },
101837 {
101838 .procname = "rdma_stat_sq_poll",
101839 .data = &rdma_stat_sq_poll,
101840 - .maxlen = sizeof(atomic_t),
101841 + .maxlen = sizeof(atomic_unchecked_t),
101842 .mode = 0644,
101843 .proc_handler = read_reset_stat,
101844 },
101845 {
101846 .procname = "rdma_stat_sq_prod",
101847 .data = &rdma_stat_sq_prod,
101848 - .maxlen = sizeof(atomic_t),
101849 + .maxlen = sizeof(atomic_unchecked_t),
101850 .mode = 0644,
101851 .proc_handler = read_reset_stat,
101852 },
101853 diff --git a/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c b/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
101854 index 0ce7552..d074459 100644
101855 --- a/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
101856 +++ b/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
101857 @@ -501,7 +501,7 @@ next_sge:
101858 svc_rdma_put_context(ctxt, 0);
101859 goto out;
101860 }
101861 - atomic_inc(&rdma_stat_read);
101862 + atomic_inc_unchecked(&rdma_stat_read);
101863
101864 if (read_wr.num_sge < chl_map->ch[ch_no].count) {
101865 chl_map->ch[ch_no].count -= read_wr.num_sge;
101866 @@ -611,7 +611,7 @@ int svc_rdma_recvfrom(struct svc_rqst *rqstp)
101867 dto_q);
101868 list_del_init(&ctxt->dto_q);
101869 } else {
101870 - atomic_inc(&rdma_stat_rq_starve);
101871 + atomic_inc_unchecked(&rdma_stat_rq_starve);
101872 clear_bit(XPT_DATA, &xprt->xpt_flags);
101873 ctxt = NULL;
101874 }
101875 @@ -631,7 +631,7 @@ int svc_rdma_recvfrom(struct svc_rqst *rqstp)
101876 dprintk("svcrdma: processing ctxt=%p on xprt=%p, rqstp=%p, status=%d\n",
101877 ctxt, rdma_xprt, rqstp, ctxt->wc_status);
101878 BUG_ON(ctxt->wc_status != IB_WC_SUCCESS);
101879 - atomic_inc(&rdma_stat_recv);
101880 + atomic_inc_unchecked(&rdma_stat_recv);
101881
101882 /* Build up the XDR from the receive buffers. */
101883 rdma_build_arg_xdr(rqstp, ctxt, ctxt->byte_len);
101884 diff --git a/net/sunrpc/xprtrdma/svc_rdma_sendto.c b/net/sunrpc/xprtrdma/svc_rdma_sendto.c
101885 index c1d124d..acfc59e 100644
101886 --- a/net/sunrpc/xprtrdma/svc_rdma_sendto.c
101887 +++ b/net/sunrpc/xprtrdma/svc_rdma_sendto.c
101888 @@ -362,7 +362,7 @@ static int send_write(struct svcxprt_rdma *xprt, struct svc_rqst *rqstp,
101889 write_wr.wr.rdma.remote_addr = to;
101890
101891 /* Post It */
101892 - atomic_inc(&rdma_stat_write);
101893 + atomic_inc_unchecked(&rdma_stat_write);
101894 if (svc_rdma_send(xprt, &write_wr))
101895 goto err;
101896 return 0;
101897 diff --git a/net/sunrpc/xprtrdma/svc_rdma_transport.c b/net/sunrpc/xprtrdma/svc_rdma_transport.c
101898 index 62e4f9b..dd3f2d7 100644
101899 --- a/net/sunrpc/xprtrdma/svc_rdma_transport.c
101900 +++ b/net/sunrpc/xprtrdma/svc_rdma_transport.c
101901 @@ -292,7 +292,7 @@ static void rq_cq_reap(struct svcxprt_rdma *xprt)
101902 return;
101903
101904 ib_req_notify_cq(xprt->sc_rq_cq, IB_CQ_NEXT_COMP);
101905 - atomic_inc(&rdma_stat_rq_poll);
101906 + atomic_inc_unchecked(&rdma_stat_rq_poll);
101907
101908 while ((ret = ib_poll_cq(xprt->sc_rq_cq, 1, &wc)) > 0) {
101909 ctxt = (struct svc_rdma_op_ctxt *)(unsigned long)wc.wr_id;
101910 @@ -314,7 +314,7 @@ static void rq_cq_reap(struct svcxprt_rdma *xprt)
101911 }
101912
101913 if (ctxt)
101914 - atomic_inc(&rdma_stat_rq_prod);
101915 + atomic_inc_unchecked(&rdma_stat_rq_prod);
101916
101917 set_bit(XPT_DATA, &xprt->sc_xprt.xpt_flags);
101918 /*
101919 @@ -386,7 +386,7 @@ static void sq_cq_reap(struct svcxprt_rdma *xprt)
101920 return;
101921
101922 ib_req_notify_cq(xprt->sc_sq_cq, IB_CQ_NEXT_COMP);
101923 - atomic_inc(&rdma_stat_sq_poll);
101924 + atomic_inc_unchecked(&rdma_stat_sq_poll);
101925 while ((ret = ib_poll_cq(cq, 1, &wc)) > 0) {
101926 if (wc.status != IB_WC_SUCCESS)
101927 /* Close the transport */
101928 @@ -404,7 +404,7 @@ static void sq_cq_reap(struct svcxprt_rdma *xprt)
101929 }
101930
101931 if (ctxt)
101932 - atomic_inc(&rdma_stat_sq_prod);
101933 + atomic_inc_unchecked(&rdma_stat_sq_prod);
101934 }
101935
101936 static void sq_comp_handler(struct ib_cq *cq, void *cq_context)
101937 @@ -1262,7 +1262,7 @@ int svc_rdma_send(struct svcxprt_rdma *xprt, struct ib_send_wr *wr)
101938 spin_lock_bh(&xprt->sc_lock);
101939 if (xprt->sc_sq_depth < atomic_read(&xprt->sc_sq_count) + wr_count) {
101940 spin_unlock_bh(&xprt->sc_lock);
101941 - atomic_inc(&rdma_stat_sq_starve);
101942 + atomic_inc_unchecked(&rdma_stat_sq_starve);
101943
101944 /* See if we can opportunistically reap SQ WR to make room */
101945 sq_cq_reap(xprt);
101946 diff --git a/net/sysctl_net.c b/net/sysctl_net.c
101947 index e7000be..e3b0ba7 100644
101948 --- a/net/sysctl_net.c
101949 +++ b/net/sysctl_net.c
101950 @@ -46,7 +46,7 @@ static int net_ctl_permissions(struct ctl_table_header *head,
101951 kgid_t root_gid = make_kgid(net->user_ns, 0);
101952
101953 /* Allow network administrator to have same access as root. */
101954 - if (ns_capable(net->user_ns, CAP_NET_ADMIN) ||
101955 + if (ns_capable_nolog(net->user_ns, CAP_NET_ADMIN) ||
101956 uid_eq(root_uid, current_euid())) {
101957 int mode = (table->mode >> 6) & 7;
101958 return (mode << 6) | (mode << 3) | mode;
101959 diff --git a/net/tipc/subscr.c b/net/tipc/subscr.c
101960 index c2a37aa..c195fef 100644
101961 --- a/net/tipc/subscr.c
101962 +++ b/net/tipc/subscr.c
101963 @@ -97,7 +97,7 @@ static void subscr_send_event(struct tipc_subscription *sub, u32 found_lower,
101964 struct tipc_subscriber *subscriber = sub->subscriber;
101965 struct kvec msg_sect;
101966
101967 - msg_sect.iov_base = (void *)&sub->evt;
101968 + msg_sect.iov_base = &sub->evt;
101969 msg_sect.iov_len = sizeof(struct tipc_event);
101970 sub->evt.event = htohl(event, sub->swap);
101971 sub->evt.found_lower = htohl(found_lower, sub->swap);
101972 diff --git a/net/unix/af_unix.c b/net/unix/af_unix.c
101973 index c3975bc..b0fc322 100644
101974 --- a/net/unix/af_unix.c
101975 +++ b/net/unix/af_unix.c
101976 @@ -789,6 +789,12 @@ static struct sock *unix_find_other(struct net *net,
101977 err = -ECONNREFUSED;
101978 if (!S_ISSOCK(inode->i_mode))
101979 goto put_fail;
101980 +
101981 + if (!gr_acl_handle_unix(path.dentry, path.mnt)) {
101982 + err = -EACCES;
101983 + goto put_fail;
101984 + }
101985 +
101986 u = unix_find_socket_byinode(inode);
101987 if (!u)
101988 goto put_fail;
101989 @@ -809,6 +815,13 @@ static struct sock *unix_find_other(struct net *net,
101990 if (u) {
101991 struct dentry *dentry;
101992 dentry = unix_sk(u)->path.dentry;
101993 +
101994 + if (!gr_handle_chroot_unix(pid_vnr(u->sk_peer_pid))) {
101995 + err = -EPERM;
101996 + sock_put(u);
101997 + goto fail;
101998 + }
101999 +
102000 if (dentry)
102001 touch_atime(&unix_sk(u)->path);
102002 } else
102003 @@ -842,12 +855,18 @@ static int unix_mknod(const char *sun_path, umode_t mode, struct path *res)
102004 */
102005 err = security_path_mknod(&path, dentry, mode, 0);
102006 if (!err) {
102007 + if (!gr_acl_handle_mknod(dentry, path.dentry, path.mnt, mode)) {
102008 + err = -EACCES;
102009 + goto out;
102010 + }
102011 err = vfs_mknod(path.dentry->d_inode, dentry, mode, 0);
102012 if (!err) {
102013 res->mnt = mntget(path.mnt);
102014 res->dentry = dget(dentry);
102015 + gr_handle_create(dentry, path.mnt);
102016 }
102017 }
102018 +out:
102019 done_path_create(&path, dentry);
102020 return err;
102021 }
102022 @@ -2342,9 +2361,13 @@ static int unix_seq_show(struct seq_file *seq, void *v)
102023 seq_puts(seq, "Num RefCount Protocol Flags Type St "
102024 "Inode Path\n");
102025 else {
102026 - struct sock *s = v;
102027 + struct sock *s = v, *peer;
102028 struct unix_sock *u = unix_sk(s);
102029 unix_state_lock(s);
102030 + peer = unix_peer(s);
102031 + unix_state_unlock(s);
102032 +
102033 + unix_state_double_lock(s, peer);
102034
102035 seq_printf(seq, "%pK: %08X %08X %08X %04X %02X %5lu",
102036 s,
102037 @@ -2371,8 +2394,10 @@ static int unix_seq_show(struct seq_file *seq, void *v)
102038 }
102039 for ( ; i < len; i++)
102040 seq_putc(seq, u->addr->name->sun_path[i]);
102041 - }
102042 - unix_state_unlock(s);
102043 + } else if (peer)
102044 + seq_printf(seq, " P%lu", sock_i_ino(peer));
102045 +
102046 + unix_state_double_unlock(s, peer);
102047 seq_putc(seq, '\n');
102048 }
102049
102050 diff --git a/net/unix/sysctl_net_unix.c b/net/unix/sysctl_net_unix.c
102051 index b3d5150..ff3a837 100644
102052 --- a/net/unix/sysctl_net_unix.c
102053 +++ b/net/unix/sysctl_net_unix.c
102054 @@ -28,7 +28,7 @@ static struct ctl_table unix_table[] = {
102055
102056 int __net_init unix_sysctl_register(struct net *net)
102057 {
102058 - struct ctl_table *table;
102059 + ctl_table_no_const *table;
102060
102061 table = kmemdup(unix_table, sizeof(unix_table), GFP_KERNEL);
102062 if (table == NULL)
102063 diff --git a/net/vmw_vsock/vmci_transport_notify.c b/net/vmw_vsock/vmci_transport_notify.c
102064 index 9a73074..aecba9a 100644
102065 --- a/net/vmw_vsock/vmci_transport_notify.c
102066 +++ b/net/vmw_vsock/vmci_transport_notify.c
102067 @@ -662,19 +662,19 @@ static void vmci_transport_notify_pkt_process_negotiate(struct sock *sk)
102068
102069 /* Socket control packet based operations. */
102070 struct vmci_transport_notify_ops vmci_transport_notify_pkt_ops = {
102071 - vmci_transport_notify_pkt_socket_init,
102072 - vmci_transport_notify_pkt_socket_destruct,
102073 - vmci_transport_notify_pkt_poll_in,
102074 - vmci_transport_notify_pkt_poll_out,
102075 - vmci_transport_notify_pkt_handle_pkt,
102076 - vmci_transport_notify_pkt_recv_init,
102077 - vmci_transport_notify_pkt_recv_pre_block,
102078 - vmci_transport_notify_pkt_recv_pre_dequeue,
102079 - vmci_transport_notify_pkt_recv_post_dequeue,
102080 - vmci_transport_notify_pkt_send_init,
102081 - vmci_transport_notify_pkt_send_pre_block,
102082 - vmci_transport_notify_pkt_send_pre_enqueue,
102083 - vmci_transport_notify_pkt_send_post_enqueue,
102084 - vmci_transport_notify_pkt_process_request,
102085 - vmci_transport_notify_pkt_process_negotiate,
102086 + .socket_init = vmci_transport_notify_pkt_socket_init,
102087 + .socket_destruct = vmci_transport_notify_pkt_socket_destruct,
102088 + .poll_in = vmci_transport_notify_pkt_poll_in,
102089 + .poll_out = vmci_transport_notify_pkt_poll_out,
102090 + .handle_notify_pkt = vmci_transport_notify_pkt_handle_pkt,
102091 + .recv_init = vmci_transport_notify_pkt_recv_init,
102092 + .recv_pre_block = vmci_transport_notify_pkt_recv_pre_block,
102093 + .recv_pre_dequeue = vmci_transport_notify_pkt_recv_pre_dequeue,
102094 + .recv_post_dequeue = vmci_transport_notify_pkt_recv_post_dequeue,
102095 + .send_init = vmci_transport_notify_pkt_send_init,
102096 + .send_pre_block = vmci_transport_notify_pkt_send_pre_block,
102097 + .send_pre_enqueue = vmci_transport_notify_pkt_send_pre_enqueue,
102098 + .send_post_enqueue = vmci_transport_notify_pkt_send_post_enqueue,
102099 + .process_request = vmci_transport_notify_pkt_process_request,
102100 + .process_negotiate = vmci_transport_notify_pkt_process_negotiate,
102101 };
102102 diff --git a/net/vmw_vsock/vmci_transport_notify_qstate.c b/net/vmw_vsock/vmci_transport_notify_qstate.c
102103 index 622bd7a..b92086c 100644
102104 --- a/net/vmw_vsock/vmci_transport_notify_qstate.c
102105 +++ b/net/vmw_vsock/vmci_transport_notify_qstate.c
102106 @@ -420,19 +420,19 @@ vmci_transport_notify_pkt_send_pre_enqueue(
102107
102108 /* Socket always on control packet based operations. */
102109 struct vmci_transport_notify_ops vmci_transport_notify_pkt_q_state_ops = {
102110 - vmci_transport_notify_pkt_socket_init,
102111 - vmci_transport_notify_pkt_socket_destruct,
102112 - vmci_transport_notify_pkt_poll_in,
102113 - vmci_transport_notify_pkt_poll_out,
102114 - vmci_transport_notify_pkt_handle_pkt,
102115 - vmci_transport_notify_pkt_recv_init,
102116 - vmci_transport_notify_pkt_recv_pre_block,
102117 - vmci_transport_notify_pkt_recv_pre_dequeue,
102118 - vmci_transport_notify_pkt_recv_post_dequeue,
102119 - vmci_transport_notify_pkt_send_init,
102120 - vmci_transport_notify_pkt_send_pre_block,
102121 - vmci_transport_notify_pkt_send_pre_enqueue,
102122 - vmci_transport_notify_pkt_send_post_enqueue,
102123 - vmci_transport_notify_pkt_process_request,
102124 - vmci_transport_notify_pkt_process_negotiate,
102125 + .socket_init = vmci_transport_notify_pkt_socket_init,
102126 + .socket_destruct = vmci_transport_notify_pkt_socket_destruct,
102127 + .poll_in = vmci_transport_notify_pkt_poll_in,
102128 + .poll_out = vmci_transport_notify_pkt_poll_out,
102129 + .handle_notify_pkt = vmci_transport_notify_pkt_handle_pkt,
102130 + .recv_init = vmci_transport_notify_pkt_recv_init,
102131 + .recv_pre_block = vmci_transport_notify_pkt_recv_pre_block,
102132 + .recv_pre_dequeue = vmci_transport_notify_pkt_recv_pre_dequeue,
102133 + .recv_post_dequeue = vmci_transport_notify_pkt_recv_post_dequeue,
102134 + .send_init = vmci_transport_notify_pkt_send_init,
102135 + .send_pre_block = vmci_transport_notify_pkt_send_pre_block,
102136 + .send_pre_enqueue = vmci_transport_notify_pkt_send_pre_enqueue,
102137 + .send_post_enqueue = vmci_transport_notify_pkt_send_post_enqueue,
102138 + .process_request = vmci_transport_notify_pkt_process_request,
102139 + .process_negotiate = vmci_transport_notify_pkt_process_negotiate,
102140 };
102141 diff --git a/net/wireless/wext-core.c b/net/wireless/wext-core.c
102142 index c8717c1..08539f5 100644
102143 --- a/net/wireless/wext-core.c
102144 +++ b/net/wireless/wext-core.c
102145 @@ -748,8 +748,7 @@ static int ioctl_standard_iw_point(struct iw_point *iwp, unsigned int cmd,
102146 */
102147
102148 /* Support for very large requests */
102149 - if ((descr->flags & IW_DESCR_FLAG_NOMAX) &&
102150 - (user_length > descr->max_tokens)) {
102151 + if (user_length > descr->max_tokens) {
102152 /* Allow userspace to GET more than max so
102153 * we can support any size GET requests.
102154 * There is still a limit : -ENOMEM.
102155 @@ -788,22 +787,6 @@ static int ioctl_standard_iw_point(struct iw_point *iwp, unsigned int cmd,
102156 }
102157 }
102158
102159 - if (IW_IS_GET(cmd) && !(descr->flags & IW_DESCR_FLAG_NOMAX)) {
102160 - /*
102161 - * If this is a GET, but not NOMAX, it means that the extra
102162 - * data is not bounded by userspace, but by max_tokens. Thus
102163 - * set the length to max_tokens. This matches the extra data
102164 - * allocation.
102165 - * The driver should fill it with the number of tokens it
102166 - * provided, and it may check iwp->length rather than having
102167 - * knowledge of max_tokens. If the driver doesn't change the
102168 - * iwp->length, this ioctl just copies back max_token tokens
102169 - * filled with zeroes. Hopefully the driver isn't claiming
102170 - * them to be valid data.
102171 - */
102172 - iwp->length = descr->max_tokens;
102173 - }
102174 -
102175 err = handler(dev, info, (union iwreq_data *) iwp, extra);
102176
102177 iwp->length += essid_compat;
102178 diff --git a/net/x25/sysctl_net_x25.c b/net/x25/sysctl_net_x25.c
102179 index 4323952..a06dfe1 100644
102180 --- a/net/x25/sysctl_net_x25.c
102181 +++ b/net/x25/sysctl_net_x25.c
102182 @@ -70,7 +70,7 @@ static struct ctl_table x25_table[] = {
102183 .mode = 0644,
102184 .proc_handler = proc_dointvec,
102185 },
102186 - { 0, },
102187 + { },
102188 };
102189
102190 void __init x25_register_sysctl(void)
102191 diff --git a/net/xfrm/xfrm_policy.c b/net/xfrm/xfrm_policy.c
102192 index 9a91f74..502f6605 100644
102193 --- a/net/xfrm/xfrm_policy.c
102194 +++ b/net/xfrm/xfrm_policy.c
102195 @@ -332,7 +332,7 @@ static void xfrm_policy_kill(struct xfrm_policy *policy)
102196 {
102197 policy->walk.dead = 1;
102198
102199 - atomic_inc(&policy->genid);
102200 + atomic_inc_unchecked(&policy->genid);
102201
102202 if (del_timer(&policy->polq.hold_timer))
102203 xfrm_pol_put(policy);
102204 @@ -660,7 +660,7 @@ int xfrm_policy_insert(int dir, struct xfrm_policy *policy, int excl)
102205 hlist_add_head(&policy->bydst, chain);
102206 xfrm_pol_hold(policy);
102207 net->xfrm.policy_count[dir]++;
102208 - atomic_inc(&flow_cache_genid);
102209 + atomic_inc_unchecked(&flow_cache_genid);
102210
102211 /* After previous checking, family can either be AF_INET or AF_INET6 */
102212 if (policy->family == AF_INET)
102213 @@ -1636,7 +1636,7 @@ free_dst:
102214 goto out;
102215 }
102216
102217 -static int inline
102218 +static inline int
102219 xfrm_dst_alloc_copy(void **target, const void *src, int size)
102220 {
102221 if (!*target) {
102222 @@ -1648,7 +1648,7 @@ xfrm_dst_alloc_copy(void **target, const void *src, int size)
102223 return 0;
102224 }
102225
102226 -static int inline
102227 +static inline int
102228 xfrm_dst_update_parent(struct dst_entry *dst, const struct xfrm_selector *sel)
102229 {
102230 #ifdef CONFIG_XFRM_SUB_POLICY
102231 @@ -1660,7 +1660,7 @@ xfrm_dst_update_parent(struct dst_entry *dst, const struct xfrm_selector *sel)
102232 #endif
102233 }
102234
102235 -static int inline
102236 +static inline int
102237 xfrm_dst_update_origin(struct dst_entry *dst, const struct flowi *fl)
102238 {
102239 #ifdef CONFIG_XFRM_SUB_POLICY
102240 @@ -1754,7 +1754,7 @@ xfrm_resolve_and_create_bundle(struct xfrm_policy **pols, int num_pols,
102241
102242 xdst->num_pols = num_pols;
102243 memcpy(xdst->pols, pols, sizeof(struct xfrm_policy*) * num_pols);
102244 - xdst->policy_genid = atomic_read(&pols[0]->genid);
102245 + xdst->policy_genid = atomic_read_unchecked(&pols[0]->genid);
102246
102247 return xdst;
102248 }
102249 @@ -2582,11 +2582,12 @@ void xfrm_garbage_collect(struct net *net)
102250 }
102251 EXPORT_SYMBOL(xfrm_garbage_collect);
102252
102253 -static void xfrm_garbage_collect_deferred(struct net *net)
102254 +void xfrm_garbage_collect_deferred(struct net *net)
102255 {
102256 flow_cache_flush_deferred();
102257 __xfrm_garbage_collect(net);
102258 }
102259 +EXPORT_SYMBOL(xfrm_garbage_collect_deferred);
102260
102261 static void xfrm_init_pmtu(struct dst_entry *dst)
102262 {
102263 @@ -2636,7 +2637,7 @@ static int xfrm_bundle_ok(struct xfrm_dst *first)
102264 if (xdst->xfrm_genid != dst->xfrm->genid)
102265 return 0;
102266 if (xdst->num_pols > 0 &&
102267 - xdst->policy_genid != atomic_read(&xdst->pols[0]->genid))
102268 + xdst->policy_genid != atomic_read_unchecked(&xdst->pols[0]->genid))
102269 return 0;
102270
102271 mtu = dst_mtu(dst->child);
102272 @@ -2724,8 +2725,6 @@ int xfrm_policy_register_afinfo(struct xfrm_policy_afinfo *afinfo)
102273 dst_ops->link_failure = xfrm_link_failure;
102274 if (likely(dst_ops->neigh_lookup == NULL))
102275 dst_ops->neigh_lookup = xfrm_neigh_lookup;
102276 - if (likely(afinfo->garbage_collect == NULL))
102277 - afinfo->garbage_collect = xfrm_garbage_collect_deferred;
102278 rcu_assign_pointer(xfrm_policy_afinfo[afinfo->family], afinfo);
102279 }
102280 spin_unlock(&xfrm_policy_afinfo_lock);
102281 @@ -2779,7 +2778,6 @@ int xfrm_policy_unregister_afinfo(struct xfrm_policy_afinfo *afinfo)
102282 dst_ops->check = NULL;
102283 dst_ops->negative_advice = NULL;
102284 dst_ops->link_failure = NULL;
102285 - afinfo->garbage_collect = NULL;
102286 }
102287 return err;
102288 }
102289 @@ -3162,7 +3160,7 @@ static int xfrm_policy_migrate(struct xfrm_policy *pol,
102290 sizeof(pol->xfrm_vec[i].saddr));
102291 pol->xfrm_vec[i].encap_family = mp->new_family;
102292 /* flush bundles */
102293 - atomic_inc(&pol->genid);
102294 + atomic_inc_unchecked(&pol->genid);
102295 }
102296 }
102297
102298 diff --git a/net/xfrm/xfrm_state.c b/net/xfrm/xfrm_state.c
102299 index 68c2f35..9eb05ca 100644
102300 --- a/net/xfrm/xfrm_state.c
102301 +++ b/net/xfrm/xfrm_state.c
102302 @@ -174,12 +174,14 @@ int xfrm_register_type(const struct xfrm_type *type, unsigned short family)
102303
102304 if (unlikely(afinfo == NULL))
102305 return -EAFNOSUPPORT;
102306 - typemap = afinfo->type_map;
102307 + typemap = (const struct xfrm_type **)afinfo->type_map;
102308 spin_lock_bh(&xfrm_type_lock);
102309
102310 - if (likely(typemap[type->proto] == NULL))
102311 + if (likely(typemap[type->proto] == NULL)) {
102312 + pax_open_kernel();
102313 typemap[type->proto] = type;
102314 - else
102315 + pax_close_kernel();
102316 + } else
102317 err = -EEXIST;
102318 spin_unlock_bh(&xfrm_type_lock);
102319 xfrm_state_put_afinfo(afinfo);
102320 @@ -195,13 +197,16 @@ int xfrm_unregister_type(const struct xfrm_type *type, unsigned short family)
102321
102322 if (unlikely(afinfo == NULL))
102323 return -EAFNOSUPPORT;
102324 - typemap = afinfo->type_map;
102325 + typemap = (const struct xfrm_type **)afinfo->type_map;
102326 spin_lock_bh(&xfrm_type_lock);
102327
102328 if (unlikely(typemap[type->proto] != type))
102329 err = -ENOENT;
102330 - else
102331 + else {
102332 + pax_open_kernel();
102333 typemap[type->proto] = NULL;
102334 + pax_close_kernel();
102335 + }
102336 spin_unlock_bh(&xfrm_type_lock);
102337 xfrm_state_put_afinfo(afinfo);
102338 return err;
102339 @@ -211,7 +216,6 @@ EXPORT_SYMBOL(xfrm_unregister_type);
102340 static const struct xfrm_type *xfrm_get_type(u8 proto, unsigned short family)
102341 {
102342 struct xfrm_state_afinfo *afinfo;
102343 - const struct xfrm_type **typemap;
102344 const struct xfrm_type *type;
102345 int modload_attempted = 0;
102346
102347 @@ -219,9 +223,8 @@ retry:
102348 afinfo = xfrm_state_get_afinfo(family);
102349 if (unlikely(afinfo == NULL))
102350 return NULL;
102351 - typemap = afinfo->type_map;
102352
102353 - type = typemap[proto];
102354 + type = afinfo->type_map[proto];
102355 if (unlikely(type && !try_module_get(type->owner)))
102356 type = NULL;
102357 if (!type && !modload_attempted) {
102358 @@ -255,7 +258,7 @@ int xfrm_register_mode(struct xfrm_mode *mode, int family)
102359 return -EAFNOSUPPORT;
102360
102361 err = -EEXIST;
102362 - modemap = afinfo->mode_map;
102363 + modemap = (struct xfrm_mode **)afinfo->mode_map;
102364 spin_lock_bh(&xfrm_mode_lock);
102365 if (modemap[mode->encap])
102366 goto out;
102367 @@ -264,8 +267,10 @@ int xfrm_register_mode(struct xfrm_mode *mode, int family)
102368 if (!try_module_get(afinfo->owner))
102369 goto out;
102370
102371 - mode->afinfo = afinfo;
102372 + pax_open_kernel();
102373 + *(const void **)&mode->afinfo = afinfo;
102374 modemap[mode->encap] = mode;
102375 + pax_close_kernel();
102376 err = 0;
102377
102378 out:
102379 @@ -289,10 +294,12 @@ int xfrm_unregister_mode(struct xfrm_mode *mode, int family)
102380 return -EAFNOSUPPORT;
102381
102382 err = -ENOENT;
102383 - modemap = afinfo->mode_map;
102384 + modemap = (struct xfrm_mode **)afinfo->mode_map;
102385 spin_lock_bh(&xfrm_mode_lock);
102386 if (likely(modemap[mode->encap] == mode)) {
102387 + pax_open_kernel();
102388 modemap[mode->encap] = NULL;
102389 + pax_close_kernel();
102390 module_put(mode->afinfo->owner);
102391 err = 0;
102392 }
102393 @@ -1486,10 +1493,10 @@ EXPORT_SYMBOL(xfrm_find_acq_byseq);
102394 u32 xfrm_get_acqseq(void)
102395 {
102396 u32 res;
102397 - static atomic_t acqseq;
102398 + static atomic_unchecked_t acqseq;
102399
102400 do {
102401 - res = atomic_inc_return(&acqseq);
102402 + res = atomic_inc_return_unchecked(&acqseq);
102403 } while (!res);
102404
102405 return res;
102406 diff --git a/net/xfrm/xfrm_sysctl.c b/net/xfrm/xfrm_sysctl.c
102407 index 05a6e3d..6716ec9 100644
102408 --- a/net/xfrm/xfrm_sysctl.c
102409 +++ b/net/xfrm/xfrm_sysctl.c
102410 @@ -42,7 +42,7 @@ static struct ctl_table xfrm_table[] = {
102411
102412 int __net_init xfrm_sysctl_init(struct net *net)
102413 {
102414 - struct ctl_table *table;
102415 + ctl_table_no_const *table;
102416
102417 __xfrm_sysctl_init(net);
102418
102419 diff --git a/scripts/Makefile b/scripts/Makefile
102420 index 01e7adb..6176d5d 100644
102421 --- a/scripts/Makefile
102422 +++ b/scripts/Makefile
102423 @@ -40,3 +40,5 @@ subdir-$(CONFIG_DTC) += dtc
102424
102425 # Let clean descend into subdirs
102426 subdir- += basic kconfig package selinux
102427 +
102428 +clean-files := randstruct.seed
102429 diff --git a/scripts/Makefile.build b/scripts/Makefile.build
102430 index d5d859c..781cbcb 100644
102431 --- a/scripts/Makefile.build
102432 +++ b/scripts/Makefile.build
102433 @@ -111,7 +111,7 @@ endif
102434 endif
102435
102436 # Do not include host rules unless needed
102437 -ifneq ($(hostprogs-y)$(hostprogs-m),)
102438 +ifneq ($(hostprogs-y)$(hostprogs-m)$(hostlibs-y)$(hostlibs-m)$(hostcxxlibs-y)$(hostcxxlibs-m),)
102439 include scripts/Makefile.host
102440 endif
102441
102442 diff --git a/scripts/Makefile.clean b/scripts/Makefile.clean
102443 index 686cb0d..9d653bf 100644
102444 --- a/scripts/Makefile.clean
102445 +++ b/scripts/Makefile.clean
102446 @@ -43,7 +43,8 @@ subdir-ymn := $(addprefix $(obj)/,$(subdir-ymn))
102447 __clean-files := $(extra-y) $(always) \
102448 $(targets) $(clean-files) \
102449 $(host-progs) \
102450 - $(hostprogs-y) $(hostprogs-m) $(hostprogs-)
102451 + $(hostprogs-y) $(hostprogs-m) $(hostprogs-) \
102452 + $(hostlibs-y) $(hostlibs-m) $(hostlibs-)
102453
102454 __clean-files := $(filter-out $(no-clean-files), $(__clean-files))
102455
102456 diff --git a/scripts/Makefile.host b/scripts/Makefile.host
102457 index 1ac414f..38575f7 100644
102458 --- a/scripts/Makefile.host
102459 +++ b/scripts/Makefile.host
102460 @@ -31,6 +31,8 @@
102461 # Note: Shared libraries consisting of C++ files are not supported
102462
102463 __hostprogs := $(sort $(hostprogs-y) $(hostprogs-m))
102464 +__hostlibs := $(sort $(hostlibs-y) $(hostlibs-m))
102465 +__hostcxxlibs := $(sort $(hostcxxlibs-y) $(hostcxxlibs-m))
102466
102467 # C code
102468 # Executables compiled from a single .c file
102469 @@ -54,11 +56,15 @@ host-cxxobjs := $(sort $(foreach m,$(host-cxxmulti),$($(m)-cxxobjs)))
102470 # Shared libaries (only .c supported)
102471 # Shared libraries (.so) - all .so files referenced in "xxx-objs"
102472 host-cshlib := $(sort $(filter %.so, $(host-cobjs)))
102473 +host-cshlib += $(sort $(filter %.so, $(__hostlibs)))
102474 +host-cxxshlib := $(sort $(filter %.so, $(__hostcxxlibs)))
102475 # Remove .so files from "xxx-objs"
102476 host-cobjs := $(filter-out %.so,$(host-cobjs))
102477 +host-cxxobjs := $(filter-out %.so,$(host-cxxobjs))
102478
102479 -#Object (.o) files used by the shared libaries
102480 +# Object (.o) files used by the shared libaries
102481 host-cshobjs := $(sort $(foreach m,$(host-cshlib),$($(m:.so=-objs))))
102482 +host-cxxshobjs := $(sort $(foreach m,$(host-cxxshlib),$($(m:.so=-objs))))
102483
102484 # output directory for programs/.o files
102485 # hostprogs-y := tools/build may have been specified. Retrieve directory
102486 @@ -82,7 +88,9 @@ host-cobjs := $(addprefix $(obj)/,$(host-cobjs))
102487 host-cxxmulti := $(addprefix $(obj)/,$(host-cxxmulti))
102488 host-cxxobjs := $(addprefix $(obj)/,$(host-cxxobjs))
102489 host-cshlib := $(addprefix $(obj)/,$(host-cshlib))
102490 +host-cxxshlib := $(addprefix $(obj)/,$(host-cxxshlib))
102491 host-cshobjs := $(addprefix $(obj)/,$(host-cshobjs))
102492 +host-cxxshobjs := $(addprefix $(obj)/,$(host-cxxshobjs))
102493 host-objdirs := $(addprefix $(obj)/,$(host-objdirs))
102494
102495 obj-dirs += $(host-objdirs)
102496 @@ -156,6 +164,13 @@ quiet_cmd_host-cshobjs = HOSTCC -fPIC $@
102497 $(host-cshobjs): $(obj)/%.o: $(src)/%.c FORCE
102498 $(call if_changed_dep,host-cshobjs)
102499
102500 +# Compile .c file, create position independent .o file
102501 +# host-cxxshobjs -> .o
102502 +quiet_cmd_host-cxxshobjs = HOSTCXX -fPIC $@
102503 + cmd_host-cxxshobjs = $(HOSTCXX) $(hostcxx_flags) -fPIC -c -o $@ $<
102504 +$(host-cxxshobjs): $(obj)/%.o: $(src)/%.c FORCE
102505 + $(call if_changed_dep,host-cxxshobjs)
102506 +
102507 # Link a shared library, based on position independent .o files
102508 # *.o -> .so shared library (host-cshlib)
102509 quiet_cmd_host-cshlib = HOSTLLD -shared $@
102510 @@ -165,6 +180,15 @@ quiet_cmd_host-cshlib = HOSTLLD -shared $@
102511 $(host-cshlib): $(obj)/%: $(host-cshobjs) FORCE
102512 $(call if_changed,host-cshlib)
102513
102514 +# Link a shared library, based on position independent .o files
102515 +# *.o -> .so shared library (host-cxxshlib)
102516 +quiet_cmd_host-cxxshlib = HOSTLLD -shared $@
102517 + cmd_host-cxxshlib = $(HOSTCXX) $(HOSTLDFLAGS) -shared -o $@ \
102518 + $(addprefix $(obj)/,$($(@F:.so=-objs))) \
102519 + $(HOST_LOADLIBES) $(HOSTLOADLIBES_$(@F))
102520 +$(host-cxxshlib): $(obj)/%: $(host-cxxshobjs) FORCE
102521 + $(call if_changed,host-cxxshlib)
102522 +
102523 targets += $(host-csingle) $(host-cmulti) $(host-cobjs)\
102524 - $(host-cxxmulti) $(host-cxxobjs) $(host-cshlib) $(host-cshobjs)
102525 + $(host-cxxmulti) $(host-cxxobjs) $(host-cshlib) $(host-cshobjs) $(host-cxxshlib) $(host-cxxshobjs)
102526
102527 diff --git a/scripts/basic/fixdep.c b/scripts/basic/fixdep.c
102528 index 078fe1d..fbdb363 100644
102529 --- a/scripts/basic/fixdep.c
102530 +++ b/scripts/basic/fixdep.c
102531 @@ -161,7 +161,7 @@ static unsigned int strhash(const char *str, unsigned int sz)
102532 /*
102533 * Lookup a value in the configuration string.
102534 */
102535 -static int is_defined_config(const char *name, int len, unsigned int hash)
102536 +static int is_defined_config(const char *name, unsigned int len, unsigned int hash)
102537 {
102538 struct item *aux;
102539
102540 @@ -211,10 +211,10 @@ static void clear_config(void)
102541 /*
102542 * Record the use of a CONFIG_* word.
102543 */
102544 -static void use_config(const char *m, int slen)
102545 +static void use_config(const char *m, unsigned int slen)
102546 {
102547 unsigned int hash = strhash(m, slen);
102548 - int c, i;
102549 + unsigned int c, i;
102550
102551 if (is_defined_config(m, slen, hash))
102552 return;
102553 @@ -235,9 +235,9 @@ static void use_config(const char *m, int slen)
102554
102555 static void parse_config_file(const char *map, size_t len)
102556 {
102557 - const int *end = (const int *) (map + len);
102558 + const unsigned int *end = (const unsigned int *) (map + len);
102559 /* start at +1, so that p can never be < map */
102560 - const int *m = (const int *) map + 1;
102561 + const unsigned int *m = (const unsigned int *) map + 1;
102562 const char *p, *q;
102563
102564 for (; m < end; m++) {
102565 @@ -435,7 +435,7 @@ static void print_deps(void)
102566 static void traps(void)
102567 {
102568 static char test[] __attribute__((aligned(sizeof(int)))) = "CONF";
102569 - int *p = (int *)test;
102570 + unsigned int *p = (unsigned int *)test;
102571
102572 if (*p != INT_CONF) {
102573 fprintf(stderr, "fixdep: sizeof(int) != 4 or wrong endianness? %#x\n",
102574 diff --git a/scripts/gcc-plugin.sh b/scripts/gcc-plugin.sh
102575 new file mode 100644
102576 index 0000000..edcbc3a
102577 --- /dev/null
102578 +++ b/scripts/gcc-plugin.sh
102579 @@ -0,0 +1,16 @@
102580 +#!/bin/bash
102581 +srctree=$(dirname "$0")
102582 +gccplugins_dir=$($3 -print-file-name=plugin)
102583 +plugincc=$($1 -E -shared - -o /dev/null -I${srctree}/../tools/gcc -I${gccplugins_dir}/include 2>&1 <<EOF
102584 +#include "gcc-common.h"
102585 +#if BUILDING_GCC_VERSION >= 4008 || defined(ENABLE_BUILD_WITH_CXX)
102586 +#warning $2
102587 +#else
102588 +#warning $1
102589 +#endif
102590 +EOF
102591 +)
102592 +if [ $? -eq 0 ]
102593 +then
102594 + ( [[ "$plugincc" =~ "$1" ]] && echo "$1" ) || ( [[ "$plugincc" =~ "$2" ]] && echo "$2" )
102595 +fi
102596 diff --git a/scripts/headers_install.sh b/scripts/headers_install.sh
102597 index 5de5660..d3deb89 100644
102598 --- a/scripts/headers_install.sh
102599 +++ b/scripts/headers_install.sh
102600 @@ -32,6 +32,7 @@ do
102601 FILE="$(basename "$i")"
102602 sed -r \
102603 -e 's/([ \t(])(__user|__force|__iomem)[ \t]/\1/g' \
102604 + -e 's/__intentional_overflow\([- \t,0-9]*\)//g' \
102605 -e 's/__attribute_const__([ \t]|$)/\1/g' \
102606 -e 's@^#include <linux/compiler.h>@@' \
102607 -e 's/(^|[^a-zA-Z0-9])__packed([^a-zA-Z0-9_]|$)/\1__attribute__((packed))\2/g' \
102608 diff --git a/scripts/link-vmlinux.sh b/scripts/link-vmlinux.sh
102609 index 2dcb377..a82c500 100644
102610 --- a/scripts/link-vmlinux.sh
102611 +++ b/scripts/link-vmlinux.sh
102612 @@ -162,7 +162,7 @@ else
102613 fi;
102614
102615 # final build of init/
102616 -${MAKE} -f "${srctree}/scripts/Makefile.build" obj=init
102617 +${MAKE} -f "${srctree}/scripts/Makefile.build" obj=init GCC_PLUGINS_CFLAGS="${GCC_PLUGINS_CFLAGS}" GCC_PLUGINS_AFLAGS="${GCC_PLUGINS_AFLAGS}"
102618
102619 kallsymso=""
102620 kallsyms_vmlinux=""
102621 diff --git a/scripts/mod/file2alias.c b/scripts/mod/file2alias.c
102622 index 25e5cb0..6e85821 100644
102623 --- a/scripts/mod/file2alias.c
102624 +++ b/scripts/mod/file2alias.c
102625 @@ -142,7 +142,7 @@ static void device_id_check(const char *modname, const char *device_id,
102626 unsigned long size, unsigned long id_size,
102627 void *symval)
102628 {
102629 - int i;
102630 + unsigned int i;
102631
102632 if (size % id_size || size < id_size) {
102633 fatal("%s: sizeof(struct %s_device_id)=%lu is not a modulo "
102634 @@ -170,7 +170,7 @@ static void device_id_check(const char *modname, const char *device_id,
102635 /* USB is special because the bcdDevice can be matched against a numeric range */
102636 /* Looks like "usb:vNpNdNdcNdscNdpNicNiscNipNinN" */
102637 static void do_usb_entry(void *symval,
102638 - unsigned int bcdDevice_initial, int bcdDevice_initial_digits,
102639 + unsigned int bcdDevice_initial, unsigned int bcdDevice_initial_digits,
102640 unsigned char range_lo, unsigned char range_hi,
102641 unsigned char max, struct module *mod)
102642 {
102643 @@ -280,7 +280,7 @@ static void do_usb_entry_multi(void *symval, struct module *mod)
102644 {
102645 unsigned int devlo, devhi;
102646 unsigned char chi, clo, max;
102647 - int ndigits;
102648 + unsigned int ndigits;
102649
102650 DEF_FIELD(symval, usb_device_id, match_flags);
102651 DEF_FIELD(symval, usb_device_id, idVendor);
102652 @@ -533,7 +533,7 @@ static void do_pnp_device_entry(void *symval, unsigned long size,
102653 for (i = 0; i < count; i++) {
102654 DEF_FIELD_ADDR(symval + i*id_size, pnp_device_id, id);
102655 char acpi_id[sizeof(*id)];
102656 - int j;
102657 + unsigned int j;
102658
102659 buf_printf(&mod->dev_table_buf,
102660 "MODULE_ALIAS(\"pnp:d%s*\");\n", *id);
102661 @@ -562,7 +562,7 @@ static void do_pnp_card_entries(void *symval, unsigned long size,
102662
102663 for (j = 0; j < PNP_MAX_DEVICES; j++) {
102664 const char *id = (char *)(*devs)[j].id;
102665 - int i2, j2;
102666 + unsigned int i2, j2;
102667 int dup = 0;
102668
102669 if (!id[0])
102670 @@ -588,7 +588,7 @@ static void do_pnp_card_entries(void *symval, unsigned long size,
102671 /* add an individual alias for every device entry */
102672 if (!dup) {
102673 char acpi_id[PNP_ID_LEN];
102674 - int k;
102675 + unsigned int k;
102676
102677 buf_printf(&mod->dev_table_buf,
102678 "MODULE_ALIAS(\"pnp:d%s*\");\n", id);
102679 @@ -940,7 +940,7 @@ static void dmi_ascii_filter(char *d, const char *s)
102680 static int do_dmi_entry(const char *filename, void *symval,
102681 char *alias)
102682 {
102683 - int i, j;
102684 + unsigned int i, j;
102685 DEF_FIELD_ADDR(symval, dmi_system_id, matches);
102686 sprintf(alias, "dmi*");
102687
102688 diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c
102689 index 1785576..5e8e06a 100644
102690 --- a/scripts/mod/modpost.c
102691 +++ b/scripts/mod/modpost.c
102692 @@ -941,6 +941,7 @@ enum mismatch {
102693 ANY_INIT_TO_ANY_EXIT,
102694 ANY_EXIT_TO_ANY_INIT,
102695 EXPORT_TO_INIT_EXIT,
102696 + DATA_TO_TEXT
102697 };
102698
102699 struct sectioncheck {
102700 @@ -1027,6 +1028,12 @@ const struct sectioncheck sectioncheck[] = {
102701 .tosec = { INIT_SECTIONS, EXIT_SECTIONS, NULL },
102702 .mismatch = EXPORT_TO_INIT_EXIT,
102703 .symbol_white_list = { DEFAULT_SYMBOL_WHITE_LIST, NULL },
102704 +},
102705 +/* Do not reference code from writable data */
102706 +{
102707 + .fromsec = { DATA_SECTIONS, NULL },
102708 + .tosec = { TEXT_SECTIONS, NULL },
102709 + .mismatch = DATA_TO_TEXT
102710 }
102711 };
102712
102713 @@ -1147,10 +1154,10 @@ static Elf_Sym *find_elf_symbol(struct elf_info *elf, Elf64_Sword addr,
102714 continue;
102715 if (ELF_ST_TYPE(sym->st_info) == STT_SECTION)
102716 continue;
102717 - if (sym->st_value == addr)
102718 - return sym;
102719 /* Find a symbol nearby - addr are maybe negative */
102720 d = sym->st_value - addr;
102721 + if (d == 0)
102722 + return sym;
102723 if (d < 0)
102724 d = addr - sym->st_value;
102725 if (d < distance) {
102726 @@ -1428,6 +1435,14 @@ static void report_sec_mismatch(const char *modname,
102727 tosym, prl_to, prl_to, tosym);
102728 free(prl_to);
102729 break;
102730 + case DATA_TO_TEXT:
102731 +#if 0
102732 + fprintf(stderr,
102733 + "The %s %s:%s references\n"
102734 + "the %s %s:%s%s\n",
102735 + from, fromsec, fromsym, to, tosec, tosym, to_p);
102736 +#endif
102737 + break;
102738 }
102739 fprintf(stderr, "\n");
102740 }
102741 @@ -1662,7 +1677,7 @@ static void section_rel(const char *modname, struct elf_info *elf,
102742 static void check_sec_ref(struct module *mod, const char *modname,
102743 struct elf_info *elf)
102744 {
102745 - int i;
102746 + unsigned int i;
102747 Elf_Shdr *sechdrs = elf->sechdrs;
102748
102749 /* Walk through all sections */
102750 @@ -1781,7 +1796,7 @@ void __attribute__((format(printf, 2, 3))) buf_printf(struct buffer *buf,
102751 va_end(ap);
102752 }
102753
102754 -void buf_write(struct buffer *buf, const char *s, int len)
102755 +void buf_write(struct buffer *buf, const char *s, unsigned int len)
102756 {
102757 if (buf->size - buf->pos < len) {
102758 buf->size += len + SZ;
102759 @@ -2000,7 +2015,7 @@ static void write_if_changed(struct buffer *b, const char *fname)
102760 if (fstat(fileno(file), &st) < 0)
102761 goto close_write;
102762
102763 - if (st.st_size != b->pos)
102764 + if (st.st_size != (off_t)b->pos)
102765 goto close_write;
102766
102767 tmp = NOFAIL(malloc(b->pos));
102768 diff --git a/scripts/mod/modpost.h b/scripts/mod/modpost.h
102769 index 51207e4..f7d603d 100644
102770 --- a/scripts/mod/modpost.h
102771 +++ b/scripts/mod/modpost.h
102772 @@ -92,15 +92,15 @@ void *do_nofail(void *ptr, const char *expr);
102773
102774 struct buffer {
102775 char *p;
102776 - int pos;
102777 - int size;
102778 + unsigned int pos;
102779 + unsigned int size;
102780 };
102781
102782 void __attribute__((format(printf, 2, 3)))
102783 buf_printf(struct buffer *buf, const char *fmt, ...);
102784
102785 void
102786 -buf_write(struct buffer *buf, const char *s, int len);
102787 +buf_write(struct buffer *buf, const char *s, unsigned int len);
102788
102789 struct module {
102790 struct module *next;
102791 diff --git a/scripts/mod/sumversion.c b/scripts/mod/sumversion.c
102792 index deb2994..af4f63e 100644
102793 --- a/scripts/mod/sumversion.c
102794 +++ b/scripts/mod/sumversion.c
102795 @@ -470,7 +470,7 @@ static void write_version(const char *filename, const char *sum,
102796 goto out;
102797 }
102798
102799 - if (write(fd, sum, strlen(sum)+1) != strlen(sum)+1) {
102800 + if (write(fd, sum, strlen(sum)+1) != (ssize_t)strlen(sum)+1) {
102801 warn("writing sum in %s failed: %s\n",
102802 filename, strerror(errno));
102803 goto out;
102804 diff --git a/scripts/module-common.lds b/scripts/module-common.lds
102805 index 0865b3e..7235dd4 100644
102806 --- a/scripts/module-common.lds
102807 +++ b/scripts/module-common.lds
102808 @@ -6,6 +6,10 @@
102809 SECTIONS {
102810 /DISCARD/ : { *(.discard) }
102811
102812 + .rodata : {
102813 + *(.rodata) *(.rodata.*)
102814 + *(.data..read_only)
102815 + }
102816 __ksymtab : { *(SORT(___ksymtab+*)) }
102817 __ksymtab_gpl : { *(SORT(___ksymtab_gpl+*)) }
102818 __ksymtab_unused : { *(SORT(___ksymtab_unused+*)) }
102819 diff --git a/scripts/package/builddeb b/scripts/package/builddeb
102820 index c1bb9be..63aed853 100644
102821 --- a/scripts/package/builddeb
102822 +++ b/scripts/package/builddeb
102823 @@ -281,6 +281,7 @@ fi
102824 (cd $srctree; find . -name Makefile\* -o -name Kconfig\* -o -name \*.pl > "$objtree/debian/hdrsrcfiles")
102825 (cd $srctree; find arch/$SRCARCH/include include scripts -type f >> "$objtree/debian/hdrsrcfiles")
102826 (cd $objtree; find arch/$SRCARCH/include Module.symvers include scripts -type f >> "$objtree/debian/hdrobjfiles")
102827 +(cd $objtree; find tools/gcc -name \*.so >> "$objtree/debian/hdrobjfiles")
102828 destdir=$kernel_headers_dir/usr/src/linux-headers-$version
102829 mkdir -p "$destdir"
102830 (cd $srctree; tar -c -f - -T "$objtree/debian/hdrsrcfiles") | (cd $destdir; tar -xf -)
102831 diff --git a/scripts/pnmtologo.c b/scripts/pnmtologo.c
102832 index 68bb4ef..2f419e1 100644
102833 --- a/scripts/pnmtologo.c
102834 +++ b/scripts/pnmtologo.c
102835 @@ -244,14 +244,14 @@ static void write_header(void)
102836 fprintf(out, " * Linux logo %s\n", logoname);
102837 fputs(" */\n\n", out);
102838 fputs("#include <linux/linux_logo.h>\n\n", out);
102839 - fprintf(out, "static unsigned char %s_data[] __initdata = {\n",
102840 + fprintf(out, "static unsigned char %s_data[] = {\n",
102841 logoname);
102842 }
102843
102844 static void write_footer(void)
102845 {
102846 fputs("\n};\n\n", out);
102847 - fprintf(out, "const struct linux_logo %s __initconst = {\n", logoname);
102848 + fprintf(out, "const struct linux_logo %s = {\n", logoname);
102849 fprintf(out, "\t.type\t\t= %s,\n", logo_types[logo_type]);
102850 fprintf(out, "\t.width\t\t= %d,\n", logo_width);
102851 fprintf(out, "\t.height\t\t= %d,\n", logo_height);
102852 @@ -381,7 +381,7 @@ static void write_logo_clut224(void)
102853 fputs("\n};\n\n", out);
102854
102855 /* write logo clut */
102856 - fprintf(out, "static unsigned char %s_clut[] __initdata = {\n",
102857 + fprintf(out, "static unsigned char %s_clut[] = {\n",
102858 logoname);
102859 write_hex_cnt = 0;
102860 for (i = 0; i < logo_clutsize; i++) {
102861 diff --git a/scripts/sortextable.h b/scripts/sortextable.h
102862 index 8fac3fd..32ff38d 100644
102863 --- a/scripts/sortextable.h
102864 +++ b/scripts/sortextable.h
102865 @@ -108,9 +108,9 @@ do_func(Elf_Ehdr *ehdr, char const *const fname, table_sort_t custom_sort)
102866 const char *secstrtab;
102867 const char *strtab;
102868 char *extab_image;
102869 - int extab_index = 0;
102870 - int i;
102871 - int idx;
102872 + unsigned int extab_index = 0;
102873 + unsigned int i;
102874 + unsigned int idx;
102875 unsigned int num_sections;
102876 unsigned int secindex_strings;
102877
102878 diff --git a/security/Kconfig b/security/Kconfig
102879 index e9c6ac7..75578c4 100644
102880 --- a/security/Kconfig
102881 +++ b/security/Kconfig
102882 @@ -4,6 +4,960 @@
102883
102884 menu "Security options"
102885
102886 +menu "Grsecurity"
102887 +
102888 + config ARCH_TRACK_EXEC_LIMIT
102889 + bool
102890 +
102891 + config PAX_KERNEXEC_PLUGIN
102892 + bool
102893 +
102894 + config PAX_PER_CPU_PGD
102895 + bool
102896 +
102897 + config TASK_SIZE_MAX_SHIFT
102898 + int
102899 + depends on X86_64
102900 + default 47 if !PAX_PER_CPU_PGD
102901 + default 42 if PAX_PER_CPU_PGD
102902 +
102903 + config PAX_ENABLE_PAE
102904 + bool
102905 + default y if (X86_32 && (MPENTIUM4 || MK8 || MPSC || MCORE2 || MATOM))
102906 +
102907 + config PAX_USERCOPY_SLABS
102908 + bool
102909 +
102910 +config GRKERNSEC
102911 + bool "Grsecurity"
102912 + select CRYPTO
102913 + select CRYPTO_SHA256
102914 + select PROC_FS
102915 + select STOP_MACHINE
102916 + select TTY
102917 + select DEBUG_KERNEL
102918 + select DEBUG_LIST
102919 + help
102920 + If you say Y here, you will be able to configure many features
102921 + that will enhance the security of your system. It is highly
102922 + recommended that you say Y here and read through the help
102923 + for each option so that you fully understand the features and
102924 + can evaluate their usefulness for your machine.
102925 +
102926 +choice
102927 + prompt "Configuration Method"
102928 + depends on GRKERNSEC
102929 + default GRKERNSEC_CONFIG_CUSTOM
102930 + help
102931 +
102932 +config GRKERNSEC_CONFIG_AUTO
102933 + bool "Automatic"
102934 + help
102935 + If you choose this configuration method, you'll be able to answer a small
102936 + number of simple questions about how you plan to use this kernel.
102937 + The settings of grsecurity and PaX will be automatically configured for
102938 + the highest commonly-used settings within the provided constraints.
102939 +
102940 + If you require additional configuration, custom changes can still be made
102941 + from the "custom configuration" menu.
102942 +
102943 +config GRKERNSEC_CONFIG_CUSTOM
102944 + bool "Custom"
102945 + help
102946 + If you choose this configuration method, you'll be able to configure all
102947 + grsecurity and PaX settings manually. Via this method, no options are
102948 + automatically enabled.
102949 +
102950 +endchoice
102951 +
102952 +choice
102953 + prompt "Usage Type"
102954 + depends on (GRKERNSEC && GRKERNSEC_CONFIG_AUTO)
102955 + default GRKERNSEC_CONFIG_SERVER
102956 + help
102957 +
102958 +config GRKERNSEC_CONFIG_SERVER
102959 + bool "Server"
102960 + help
102961 + Choose this option if you plan to use this kernel on a server.
102962 +
102963 +config GRKERNSEC_CONFIG_DESKTOP
102964 + bool "Desktop"
102965 + help
102966 + Choose this option if you plan to use this kernel on a desktop.
102967 +
102968 +endchoice
102969 +
102970 +choice
102971 + prompt "Virtualization Type"
102972 + depends on (GRKERNSEC && X86 && GRKERNSEC_CONFIG_AUTO)
102973 + default GRKERNSEC_CONFIG_VIRT_NONE
102974 + help
102975 +
102976 +config GRKERNSEC_CONFIG_VIRT_NONE
102977 + bool "None"
102978 + help
102979 + Choose this option if this kernel will be run on bare metal.
102980 +
102981 +config GRKERNSEC_CONFIG_VIRT_GUEST
102982 + bool "Guest"
102983 + help
102984 + Choose this option if this kernel will be run as a VM guest.
102985 +
102986 +config GRKERNSEC_CONFIG_VIRT_HOST
102987 + bool "Host"
102988 + help
102989 + Choose this option if this kernel will be run as a VM host.
102990 +
102991 +endchoice
102992 +
102993 +choice
102994 + prompt "Virtualization Hardware"
102995 + depends on (GRKERNSEC && X86 && GRKERNSEC_CONFIG_AUTO && (GRKERNSEC_CONFIG_VIRT_GUEST || GRKERNSEC_CONFIG_VIRT_HOST))
102996 + help
102997 +
102998 +config GRKERNSEC_CONFIG_VIRT_EPT
102999 + bool "EPT/RVI Processor Support"
103000 + depends on X86
103001 + help
103002 + Choose this option if your CPU supports the EPT or RVI features of 2nd-gen
103003 + hardware virtualization. This allows for additional kernel hardening protections
103004 + to operate without additional performance impact.
103005 +
103006 + To see if your Intel processor supports EPT, see:
103007 + http://ark.intel.com/Products/VirtualizationTechnology
103008 + (Most Core i3/5/7 support EPT)
103009 +
103010 + To see if your AMD processor supports RVI, see:
103011 + http://support.amd.com/us/kbarticles/Pages/GPU120AMDRVICPUsHyperVWin8.aspx
103012 +
103013 +config GRKERNSEC_CONFIG_VIRT_SOFT
103014 + bool "First-gen/No Hardware Virtualization"
103015 + help
103016 + Choose this option if you use an Atom/Pentium/Core 2 processor that either doesn't
103017 + support hardware virtualization or doesn't support the EPT/RVI extensions.
103018 +
103019 +endchoice
103020 +
103021 +choice
103022 + prompt "Virtualization Software"
103023 + depends on (GRKERNSEC && GRKERNSEC_CONFIG_AUTO && (GRKERNSEC_CONFIG_VIRT_GUEST || GRKERNSEC_CONFIG_VIRT_HOST))
103024 + help
103025 +
103026 +config GRKERNSEC_CONFIG_VIRT_XEN
103027 + bool "Xen"
103028 + help
103029 + Choose this option if this kernel is running as a Xen guest or host.
103030 +
103031 +config GRKERNSEC_CONFIG_VIRT_VMWARE
103032 + bool "VMWare"
103033 + help
103034 + Choose this option if this kernel is running as a VMWare guest or host.
103035 +
103036 +config GRKERNSEC_CONFIG_VIRT_KVM
103037 + bool "KVM"
103038 + help
103039 + Choose this option if this kernel is running as a KVM guest or host.
103040 +
103041 +config GRKERNSEC_CONFIG_VIRT_VIRTUALBOX
103042 + bool "VirtualBox"
103043 + help
103044 + Choose this option if this kernel is running as a VirtualBox guest or host.
103045 +
103046 +endchoice
103047 +
103048 +choice
103049 + prompt "Required Priorities"
103050 + depends on (GRKERNSEC && GRKERNSEC_CONFIG_AUTO)
103051 + default GRKERNSEC_CONFIG_PRIORITY_PERF
103052 + help
103053 +
103054 +config GRKERNSEC_CONFIG_PRIORITY_PERF
103055 + bool "Performance"
103056 + help
103057 + Choose this option if performance is of highest priority for this deployment
103058 + of grsecurity. Features like UDEREF on a 64bit kernel, kernel stack clearing,
103059 + clearing of structures intended for userland, and freed memory sanitizing will
103060 + be disabled.
103061 +
103062 +config GRKERNSEC_CONFIG_PRIORITY_SECURITY
103063 + bool "Security"
103064 + help
103065 + Choose this option if security is of highest priority for this deployment of
103066 + grsecurity. UDEREF, kernel stack clearing, clearing of structures intended
103067 + for userland, and freed memory sanitizing will be enabled for this kernel.
103068 + In a worst-case scenario, these features can introduce a 20% performance hit
103069 + (UDEREF on x64 contributing half of this hit).
103070 +
103071 +endchoice
103072 +
103073 +menu "Default Special Groups"
103074 +depends on (GRKERNSEC && GRKERNSEC_CONFIG_AUTO)
103075 +
103076 +config GRKERNSEC_PROC_GID
103077 + int "GID exempted from /proc restrictions"
103078 + default 1001
103079 + help
103080 + Setting this GID determines which group will be exempted from
103081 + grsecurity's /proc restrictions, allowing users of the specified
103082 + group to view network statistics and the existence of other users'
103083 + processes on the system. This GID may also be chosen at boot time
103084 + via "grsec_proc_gid=" on the kernel commandline.
103085 +
103086 +config GRKERNSEC_TPE_UNTRUSTED_GID
103087 + int "GID for TPE-untrusted users"
103088 + depends on GRKERNSEC_CONFIG_SERVER && GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT
103089 + default 1005
103090 + help
103091 + Setting this GID determines which group untrusted users should
103092 + be added to. These users will be placed under grsecurity's Trusted Path
103093 + Execution mechanism, preventing them from executing their own binaries.
103094 + The users will only be able to execute binaries in directories owned and
103095 + writable only by the root user. If the sysctl option is enabled, a sysctl
103096 + option with name "tpe_gid" is created.
103097 +
103098 +config GRKERNSEC_TPE_TRUSTED_GID
103099 + int "GID for TPE-trusted users"
103100 + depends on GRKERNSEC_CONFIG_SERVER && GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT
103101 + default 1005
103102 + help
103103 + Setting this GID determines what group TPE restrictions will be
103104 + *disabled* for. If the sysctl option is enabled, a sysctl option
103105 + with name "tpe_gid" is created.
103106 +
103107 +config GRKERNSEC_SYMLINKOWN_GID
103108 + int "GID for users with kernel-enforced SymlinksIfOwnerMatch"
103109 + depends on GRKERNSEC_CONFIG_SERVER
103110 + default 1006
103111 + help
103112 + Setting this GID determines what group kernel-enforced
103113 + SymlinksIfOwnerMatch will be enabled for. If the sysctl option
103114 + is enabled, a sysctl option with name "symlinkown_gid" is created.
103115 +
103116 +
103117 +endmenu
103118 +
103119 +menu "Customize Configuration"
103120 +depends on GRKERNSEC
103121 +
103122 +menu "PaX"
103123 +
103124 +config PAX
103125 + bool "Enable various PaX features"
103126 + default y if GRKERNSEC_CONFIG_AUTO
103127 + depends on GRKERNSEC && (ALPHA || ARM || AVR32 || IA64 || MIPS || PARISC || PPC || SPARC || X86)
103128 + help
103129 + This allows you to enable various PaX features. PaX adds
103130 + intrusion prevention mechanisms to the kernel that reduce
103131 + the risks posed by exploitable memory corruption bugs.
103132 +
103133 +menu "PaX Control"
103134 + depends on PAX
103135 +
103136 +config PAX_SOFTMODE
103137 + bool 'Support soft mode'
103138 + help
103139 + Enabling this option will allow you to run PaX in soft mode, that
103140 + is, PaX features will not be enforced by default, only on executables
103141 + marked explicitly. You must also enable PT_PAX_FLAGS or XATTR_PAX_FLAGS
103142 + support as they are the only way to mark executables for soft mode use.
103143 +
103144 + Soft mode can be activated by using the "pax_softmode=1" kernel command
103145 + line option on boot. Furthermore you can control various PaX features
103146 + at runtime via the entries in /proc/sys/kernel/pax.
103147 +
103148 +config PAX_EI_PAX
103149 + bool 'Use legacy ELF header marking'
103150 + default y if GRKERNSEC_CONFIG_AUTO
103151 + help
103152 + Enabling this option will allow you to control PaX features on
103153 + a per executable basis via the 'chpax' utility available at
103154 + http://pax.grsecurity.net/. The control flags will be read from
103155 + an otherwise reserved part of the ELF header. This marking has
103156 + numerous drawbacks (no support for soft-mode, toolchain does not
103157 + know about the non-standard use of the ELF header) therefore it
103158 + has been deprecated in favour of PT_PAX_FLAGS and XATTR_PAX_FLAGS
103159 + support.
103160 +
103161 + Note that if you enable PT_PAX_FLAGS or XATTR_PAX_FLAGS marking
103162 + support as well, they will override the legacy EI_PAX marks.
103163 +
103164 + If you enable none of the marking options then all applications
103165 + will run with PaX enabled on them by default.
103166 +
103167 +config PAX_PT_PAX_FLAGS
103168 + bool 'Use ELF program header marking'
103169 + default y if GRKERNSEC_CONFIG_AUTO
103170 + help
103171 + Enabling this option will allow you to control PaX features on
103172 + a per executable basis via the 'paxctl' utility available at
103173 + http://pax.grsecurity.net/. The control flags will be read from
103174 + a PaX specific ELF program header (PT_PAX_FLAGS). This marking
103175 + has the benefits of supporting both soft mode and being fully
103176 + integrated into the toolchain (the binutils patch is available
103177 + from http://pax.grsecurity.net).
103178 +
103179 + Note that if you enable the legacy EI_PAX marking support as well,
103180 + the EI_PAX marks will be overridden by the PT_PAX_FLAGS marks.
103181 +
103182 + If you enable both PT_PAX_FLAGS and XATTR_PAX_FLAGS support then you
103183 + must make sure that the marks are the same if a binary has both marks.
103184 +
103185 + If you enable none of the marking options then all applications
103186 + will run with PaX enabled on them by default.
103187 +
103188 +config PAX_XATTR_PAX_FLAGS
103189 + bool 'Use filesystem extended attributes marking'
103190 + default y if GRKERNSEC_CONFIG_AUTO
103191 + select CIFS_XATTR if CIFS
103192 + select EXT2_FS_XATTR if EXT2_FS
103193 + select EXT3_FS_XATTR if EXT3_FS
103194 + select JFFS2_FS_XATTR if JFFS2_FS
103195 + select REISERFS_FS_XATTR if REISERFS_FS
103196 + select SQUASHFS_XATTR if SQUASHFS
103197 + select TMPFS_XATTR if TMPFS
103198 + select UBIFS_FS_XATTR if UBIFS_FS
103199 + help
103200 + Enabling this option will allow you to control PaX features on
103201 + a per executable basis via the 'setfattr' utility. The control
103202 + flags will be read from the user.pax.flags extended attribute of
103203 + the file. This marking has the benefit of supporting binary-only
103204 + applications that self-check themselves (e.g., skype) and would
103205 + not tolerate chpax/paxctl changes. The main drawback is that
103206 + extended attributes are not supported by some filesystems (e.g.,
103207 + isofs, udf, vfat) so copying files through such filesystems will
103208 + lose the extended attributes and these PaX markings.
103209 +
103210 + Note that if you enable the legacy EI_PAX marking support as well,
103211 + the EI_PAX marks will be overridden by the XATTR_PAX_FLAGS marks.
103212 +
103213 + If you enable both PT_PAX_FLAGS and XATTR_PAX_FLAGS support then you
103214 + must make sure that the marks are the same if a binary has both marks.
103215 +
103216 + If you enable none of the marking options then all applications
103217 + will run with PaX enabled on them by default.
103218 +
103219 +choice
103220 + prompt 'MAC system integration'
103221 + default PAX_HAVE_ACL_FLAGS
103222 + help
103223 + Mandatory Access Control systems have the option of controlling
103224 + PaX flags on a per executable basis, choose the method supported
103225 + by your particular system.
103226 +
103227 + - "none": if your MAC system does not interact with PaX,
103228 + - "direct": if your MAC system defines pax_set_initial_flags() itself,
103229 + - "hook": if your MAC system uses the pax_set_initial_flags_func callback.
103230 +
103231 + NOTE: this option is for developers/integrators only.
103232 +
103233 + config PAX_NO_ACL_FLAGS
103234 + bool 'none'
103235 +
103236 + config PAX_HAVE_ACL_FLAGS
103237 + bool 'direct'
103238 +
103239 + config PAX_HOOK_ACL_FLAGS
103240 + bool 'hook'
103241 +endchoice
103242 +
103243 +endmenu
103244 +
103245 +menu "Non-executable pages"
103246 + depends on PAX
103247 +
103248 +config PAX_NOEXEC
103249 + bool "Enforce non-executable pages"
103250 + default y if GRKERNSEC_CONFIG_AUTO
103251 + depends on ALPHA || (ARM && (CPU_V6 || CPU_V6K || CPU_V7)) || IA64 || MIPS || PARISC || PPC || S390 || SPARC || X86
103252 + help
103253 + By design some architectures do not allow for protecting memory
103254 + pages against execution or even if they do, Linux does not make
103255 + use of this feature. In practice this means that if a page is
103256 + readable (such as the stack or heap) it is also executable.
103257 +
103258 + There is a well known exploit technique that makes use of this
103259 + fact and a common programming mistake where an attacker can
103260 + introduce code of his choice somewhere in the attacked program's
103261 + memory (typically the stack or the heap) and then execute it.
103262 +
103263 + If the attacked program was running with different (typically
103264 + higher) privileges than that of the attacker, then he can elevate
103265 + his own privilege level (e.g. get a root shell, write to files for
103266 + which he does not have write access to, etc).
103267 +
103268 + Enabling this option will let you choose from various features
103269 + that prevent the injection and execution of 'foreign' code in
103270 + a program.
103271 +
103272 + This will also break programs that rely on the old behaviour and
103273 + expect that dynamically allocated memory via the malloc() family
103274 + of functions is executable (which it is not). Notable examples
103275 + are the XFree86 4.x server, the java runtime and wine.
103276 +
103277 +config PAX_PAGEEXEC
103278 + bool "Paging based non-executable pages"
103279 + default y if GRKERNSEC_CONFIG_AUTO
103280 + 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)
103281 + select ARCH_TRACK_EXEC_LIMIT if X86_32
103282 + help
103283 + This implementation is based on the paging feature of the CPU.
103284 + On i386 without hardware non-executable bit support there is a
103285 + variable but usually low performance impact, however on Intel's
103286 + P4 core based CPUs it is very high so you should not enable this
103287 + for kernels meant to be used on such CPUs.
103288 +
103289 + On alpha, avr32, ia64, parisc, sparc, sparc64, x86_64 and i386
103290 + with hardware non-executable bit support there is no performance
103291 + impact, on ppc the impact is negligible.
103292 +
103293 + Note that several architectures require various emulations due to
103294 + badly designed userland ABIs, this will cause a performance impact
103295 + but will disappear as soon as userland is fixed. For example, ppc
103296 + userland MUST have been built with secure-plt by a recent toolchain.
103297 +
103298 +config PAX_SEGMEXEC
103299 + bool "Segmentation based non-executable pages"
103300 + default y if GRKERNSEC_CONFIG_AUTO
103301 + depends on PAX_NOEXEC && X86_32
103302 + help
103303 + This implementation is based on the segmentation feature of the
103304 + CPU and has a very small performance impact, however applications
103305 + will be limited to a 1.5 GB address space instead of the normal
103306 + 3 GB.
103307 +
103308 +config PAX_EMUTRAMP
103309 + bool "Emulate trampolines"
103310 + default y if PARISC || GRKERNSEC_CONFIG_AUTO
103311 + depends on (PAX_PAGEEXEC || PAX_SEGMEXEC) && (PARISC || X86)
103312 + help
103313 + There are some programs and libraries that for one reason or
103314 + another attempt to execute special small code snippets from
103315 + non-executable memory pages. Most notable examples are the
103316 + signal handler return code generated by the kernel itself and
103317 + the GCC trampolines.
103318 +
103319 + If you enabled CONFIG_PAX_PAGEEXEC or CONFIG_PAX_SEGMEXEC then
103320 + such programs will no longer work under your kernel.
103321 +
103322 + As a remedy you can say Y here and use the 'chpax' or 'paxctl'
103323 + utilities to enable trampoline emulation for the affected programs
103324 + yet still have the protection provided by the non-executable pages.
103325 +
103326 + On parisc you MUST enable this option and EMUSIGRT as well, otherwise
103327 + your system will not even boot.
103328 +
103329 + Alternatively you can say N here and use the 'chpax' or 'paxctl'
103330 + utilities to disable CONFIG_PAX_PAGEEXEC and CONFIG_PAX_SEGMEXEC
103331 + for the affected files.
103332 +
103333 + NOTE: enabling this feature *may* open up a loophole in the
103334 + protection provided by non-executable pages that an attacker
103335 + could abuse. Therefore the best solution is to not have any
103336 + files on your system that would require this option. This can
103337 + be achieved by not using libc5 (which relies on the kernel
103338 + signal handler return code) and not using or rewriting programs
103339 + that make use of the nested function implementation of GCC.
103340 + Skilled users can just fix GCC itself so that it implements
103341 + nested function calls in a way that does not interfere with PaX.
103342 +
103343 +config PAX_EMUSIGRT
103344 + bool "Automatically emulate sigreturn trampolines"
103345 + depends on PAX_EMUTRAMP && PARISC
103346 + default y
103347 + help
103348 + Enabling this option will have the kernel automatically detect
103349 + and emulate signal return trampolines executing on the stack
103350 + that would otherwise lead to task termination.
103351 +
103352 + This solution is intended as a temporary one for users with
103353 + legacy versions of libc (libc5, glibc 2.0, uClibc before 0.9.17,
103354 + Modula-3 runtime, etc) or executables linked to such, basically
103355 + everything that does not specify its own SA_RESTORER function in
103356 + normal executable memory like glibc 2.1+ does.
103357 +
103358 + On parisc you MUST enable this option, otherwise your system will
103359 + not even boot.
103360 +
103361 + NOTE: this feature cannot be disabled on a per executable basis
103362 + and since it *does* open up a loophole in the protection provided
103363 + by non-executable pages, the best solution is to not have any
103364 + files on your system that would require this option.
103365 +
103366 +config PAX_MPROTECT
103367 + bool "Restrict mprotect()"
103368 + default y if GRKERNSEC_CONFIG_AUTO
103369 + depends on (PAX_PAGEEXEC || PAX_SEGMEXEC)
103370 + help
103371 + Enabling this option will prevent programs from
103372 + - changing the executable status of memory pages that were
103373 + not originally created as executable,
103374 + - making read-only executable pages writable again,
103375 + - creating executable pages from anonymous memory,
103376 + - making read-only-after-relocations (RELRO) data pages writable again.
103377 +
103378 + You should say Y here to complete the protection provided by
103379 + the enforcement of non-executable pages.
103380 +
103381 + NOTE: you can use the 'chpax' or 'paxctl' utilities to control
103382 + this feature on a per file basis.
103383 +
103384 +config PAX_MPROTECT_COMPAT
103385 + bool "Use legacy/compat protection demoting (read help)"
103386 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_DESKTOP)
103387 + depends on PAX_MPROTECT
103388 + help
103389 + The current implementation of PAX_MPROTECT denies RWX allocations/mprotects
103390 + by sending the proper error code to the application. For some broken
103391 + userland, this can cause problems with Python or other applications. The
103392 + current implementation however allows for applications like clamav to
103393 + detect if JIT compilation/execution is allowed and to fall back gracefully
103394 + to an interpreter-based mode if it does not. While we encourage everyone
103395 + to use the current implementation as-is and push upstream to fix broken
103396 + userland (note that the RWX logging option can assist with this), in some
103397 + environments this may not be possible. Having to disable MPROTECT
103398 + completely on certain binaries reduces the security benefit of PaX,
103399 + so this option is provided for those environments to revert to the old
103400 + behavior.
103401 +
103402 +config PAX_ELFRELOCS
103403 + bool "Allow ELF text relocations (read help)"
103404 + depends on PAX_MPROTECT
103405 + default n
103406 + help
103407 + Non-executable pages and mprotect() restrictions are effective
103408 + in preventing the introduction of new executable code into an
103409 + attacked task's address space. There remain only two venues
103410 + for this kind of attack: if the attacker can execute already
103411 + existing code in the attacked task then he can either have it
103412 + create and mmap() a file containing his code or have it mmap()
103413 + an already existing ELF library that does not have position
103414 + independent code in it and use mprotect() on it to make it
103415 + writable and copy his code there. While protecting against
103416 + the former approach is beyond PaX, the latter can be prevented
103417 + by having only PIC ELF libraries on one's system (which do not
103418 + need to relocate their code). If you are sure this is your case,
103419 + as is the case with all modern Linux distributions, then leave
103420 + this option disabled. You should say 'n' here.
103421 +
103422 +config PAX_ETEXECRELOCS
103423 + bool "Allow ELF ET_EXEC text relocations"
103424 + depends on PAX_MPROTECT && (ALPHA || IA64 || PARISC)
103425 + select PAX_ELFRELOCS
103426 + default y
103427 + help
103428 + On some architectures there are incorrectly created applications
103429 + that require text relocations and would not work without enabling
103430 + this option. If you are an alpha, ia64 or parisc user, you should
103431 + enable this option and disable it once you have made sure that
103432 + none of your applications need it.
103433 +
103434 +config PAX_EMUPLT
103435 + bool "Automatically emulate ELF PLT"
103436 + depends on PAX_MPROTECT && (ALPHA || PARISC || SPARC)
103437 + default y
103438 + help
103439 + Enabling this option will have the kernel automatically detect
103440 + and emulate the Procedure Linkage Table entries in ELF files.
103441 + On some architectures such entries are in writable memory, and
103442 + become non-executable leading to task termination. Therefore
103443 + it is mandatory that you enable this option on alpha, parisc,
103444 + sparc and sparc64, otherwise your system would not even boot.
103445 +
103446 + NOTE: this feature *does* open up a loophole in the protection
103447 + provided by the non-executable pages, therefore the proper
103448 + solution is to modify the toolchain to produce a PLT that does
103449 + not need to be writable.
103450 +
103451 +config PAX_DLRESOLVE
103452 + bool 'Emulate old glibc resolver stub'
103453 + depends on PAX_EMUPLT && SPARC
103454 + default n
103455 + help
103456 + This option is needed if userland has an old glibc (before 2.4)
103457 + that puts a 'save' instruction into the runtime generated resolver
103458 + stub that needs special emulation.
103459 +
103460 +config PAX_KERNEXEC
103461 + bool "Enforce non-executable kernel pages"
103462 + 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))
103463 + depends on (X86 || (ARM && (CPU_V6 || CPU_V6K || CPU_V7) && !(ARM_LPAE && MODULES))) && !XEN
103464 + select PAX_PER_CPU_PGD if X86_64 || (X86_32 && X86_PAE)
103465 + select PAX_KERNEXEC_PLUGIN if X86_64
103466 + help
103467 + This is the kernel land equivalent of PAGEEXEC and MPROTECT,
103468 + that is, enabling this option will make it harder to inject
103469 + and execute 'foreign' code in kernel memory itself.
103470 +
103471 +choice
103472 + prompt "Return Address Instrumentation Method"
103473 + default PAX_KERNEXEC_PLUGIN_METHOD_BTS
103474 + depends on PAX_KERNEXEC_PLUGIN
103475 + help
103476 + Select the method used to instrument function pointer dereferences.
103477 + Note that binary modules cannot be instrumented by this approach.
103478 +
103479 + Note that the implementation requires a gcc with plugin support,
103480 + i.e., gcc 4.5 or newer. You may need to install the supporting
103481 + headers explicitly in addition to the normal gcc package.
103482 +
103483 + config PAX_KERNEXEC_PLUGIN_METHOD_BTS
103484 + bool "bts"
103485 + help
103486 + This method is compatible with binary only modules but has
103487 + a higher runtime overhead.
103488 +
103489 + config PAX_KERNEXEC_PLUGIN_METHOD_OR
103490 + bool "or"
103491 + depends on !PARAVIRT
103492 + help
103493 + This method is incompatible with binary only modules but has
103494 + a lower runtime overhead.
103495 +endchoice
103496 +
103497 +config PAX_KERNEXEC_PLUGIN_METHOD
103498 + string
103499 + default "bts" if PAX_KERNEXEC_PLUGIN_METHOD_BTS
103500 + default "or" if PAX_KERNEXEC_PLUGIN_METHOD_OR
103501 + default ""
103502 +
103503 +config PAX_KERNEXEC_MODULE_TEXT
103504 + int "Minimum amount of memory reserved for module code"
103505 + default "4" if (!GRKERNSEC_CONFIG_AUTO || GRKERNSEC_CONFIG_SERVER)
103506 + default "12" if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_DESKTOP)
103507 + depends on PAX_KERNEXEC && X86_32
103508 + help
103509 + Due to implementation details the kernel must reserve a fixed
103510 + amount of memory for runtime allocated code (such as modules)
103511 + at compile time that cannot be changed at runtime. Here you
103512 + can specify the minimum amount in MB that will be reserved.
103513 + Due to the same implementation details this size will always
103514 + be rounded up to the next 2/4 MB boundary (depends on PAE) so
103515 + the actually available memory for runtime allocated code will
103516 + usually be more than this minimum.
103517 +
103518 + The default 4 MB should be enough for most users but if you have
103519 + an excessive number of modules (e.g., most distribution configs
103520 + compile many drivers as modules) or use huge modules such as
103521 + nvidia's kernel driver, you will need to adjust this amount.
103522 + A good rule of thumb is to look at your currently loaded kernel
103523 + modules and add up their sizes.
103524 +
103525 +endmenu
103526 +
103527 +menu "Address Space Layout Randomization"
103528 + depends on PAX
103529 +
103530 +config PAX_ASLR
103531 + bool "Address Space Layout Randomization"
103532 + default y if GRKERNSEC_CONFIG_AUTO
103533 + help
103534 + Many if not most exploit techniques rely on the knowledge of
103535 + certain addresses in the attacked program. The following options
103536 + will allow the kernel to apply a certain amount of randomization
103537 + to specific parts of the program thereby forcing an attacker to
103538 + guess them in most cases. Any failed guess will most likely crash
103539 + the attacked program which allows the kernel to detect such attempts
103540 + and react on them. PaX itself provides no reaction mechanisms,
103541 + instead it is strongly encouraged that you make use of Nergal's
103542 + segvguard (ftp://ftp.pl.openwall.com/misc/segvguard/) or grsecurity's
103543 + (http://www.grsecurity.net/) built-in crash detection features or
103544 + develop one yourself.
103545 +
103546 + By saying Y here you can choose to randomize the following areas:
103547 + - top of the task's kernel stack
103548 + - top of the task's userland stack
103549 + - base address for mmap() requests that do not specify one
103550 + (this includes all libraries)
103551 + - base address of the main executable
103552 +
103553 + It is strongly recommended to say Y here as address space layout
103554 + randomization has negligible impact on performance yet it provides
103555 + a very effective protection.
103556 +
103557 + NOTE: you can use the 'chpax' or 'paxctl' utilities to control
103558 + this feature on a per file basis.
103559 +
103560 +config PAX_RANDKSTACK
103561 + bool "Randomize kernel stack base"
103562 + default y if GRKERNSEC_CONFIG_AUTO && !(GRKERNSEC_CONFIG_VIRT_HOST && GRKERNSEC_CONFIG_VIRT_VIRTUALBOX)
103563 + depends on X86_TSC && X86
103564 + help
103565 + By saying Y here the kernel will randomize every task's kernel
103566 + stack on every system call. This will not only force an attacker
103567 + to guess it but also prevent him from making use of possible
103568 + leaked information about it.
103569 +
103570 + Since the kernel stack is a rather scarce resource, randomization
103571 + may cause unexpected stack overflows, therefore you should very
103572 + carefully test your system. Note that once enabled in the kernel
103573 + configuration, this feature cannot be disabled on a per file basis.
103574 +
103575 +config PAX_RANDUSTACK
103576 + bool "Randomize user stack base"
103577 + default y if GRKERNSEC_CONFIG_AUTO
103578 + depends on PAX_ASLR
103579 + help
103580 + By saying Y here the kernel will randomize every task's userland
103581 + stack. The randomization is done in two steps where the second
103582 + one may apply a big amount of shift to the top of the stack and
103583 + cause problems for programs that want to use lots of memory (more
103584 + than 2.5 GB if SEGMEXEC is not active, or 1.25 GB when it is).
103585 + For this reason the second step can be controlled by 'chpax' or
103586 + 'paxctl' on a per file basis.
103587 +
103588 +config PAX_RANDMMAP
103589 + bool "Randomize mmap() base"
103590 + default y if GRKERNSEC_CONFIG_AUTO
103591 + depends on PAX_ASLR
103592 + help
103593 + By saying Y here the kernel will use a randomized base address for
103594 + mmap() requests that do not specify one themselves. As a result
103595 + all dynamically loaded libraries will appear at random addresses
103596 + and therefore be harder to exploit by a technique where an attacker
103597 + attempts to execute library code for his purposes (e.g. spawn a
103598 + shell from an exploited program that is running at an elevated
103599 + privilege level).
103600 +
103601 + Furthermore, if a program is relinked as a dynamic ELF file, its
103602 + base address will be randomized as well, completing the full
103603 + randomization of the address space layout. Attacking such programs
103604 + becomes a guess game. You can find an example of doing this at
103605 + http://pax.grsecurity.net/et_dyn.tar.gz and practical samples at
103606 + http://www.grsecurity.net/grsec-gcc-specs.tar.gz .
103607 +
103608 + NOTE: you can use the 'chpax' or 'paxctl' utilities to control this
103609 + feature on a per file basis.
103610 +
103611 +endmenu
103612 +
103613 +menu "Miscellaneous hardening features"
103614 +
103615 +config PAX_MEMORY_SANITIZE
103616 + bool "Sanitize all freed memory"
103617 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_PRIORITY_SECURITY)
103618 + help
103619 + By saying Y here the kernel will erase memory pages and slab objects
103620 + as soon as they are freed. This in turn reduces the lifetime of data
103621 + stored in them, making it less likely that sensitive information such
103622 + as passwords, cryptographic secrets, etc stay in memory for too long.
103623 +
103624 + This is especially useful for programs whose runtime is short, long
103625 + lived processes and the kernel itself benefit from this as long as
103626 + they ensure timely freeing of memory that may hold sensitive
103627 + information.
103628 +
103629 + A nice side effect of the sanitization of slab objects is the
103630 + reduction of possible info leaks caused by padding bytes within the
103631 + leaky structures. Use-after-free bugs for structures containing
103632 + pointers can also be detected as dereferencing the sanitized pointer
103633 + will generate an access violation.
103634 +
103635 + The tradeoff is performance impact, on a single CPU system kernel
103636 + compilation sees a 3% slowdown, other systems and workloads may vary
103637 + and you are advised to test this feature on your expected workload
103638 + before deploying it.
103639 +
103640 + To reduce the performance penalty by sanitizing pages only, albeit
103641 + limiting the effectiveness of this feature at the same time, slab
103642 + sanitization can be disabled with the kernel commandline parameter
103643 + "pax_sanitize_slab=0".
103644 +
103645 + Note that this feature does not protect data stored in live pages,
103646 + e.g., process memory swapped to disk may stay there for a long time.
103647 +
103648 +config PAX_MEMORY_STACKLEAK
103649 + bool "Sanitize kernel stack"
103650 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_PRIORITY_SECURITY)
103651 + depends on X86
103652 + help
103653 + By saying Y here the kernel will erase the kernel stack before it
103654 + returns from a system call. This in turn reduces the information
103655 + that a kernel stack leak bug can reveal.
103656 +
103657 + Note that such a bug can still leak information that was put on
103658 + the stack by the current system call (the one eventually triggering
103659 + the bug) but traces of earlier system calls on the kernel stack
103660 + cannot leak anymore.
103661 +
103662 + The tradeoff is performance impact: on a single CPU system kernel
103663 + compilation sees a 1% slowdown, other systems and workloads may vary
103664 + and you are advised to test this feature on your expected workload
103665 + before deploying it.
103666 +
103667 + Note that the full feature requires a gcc with plugin support,
103668 + i.e., gcc 4.5 or newer. You may need to install the supporting
103669 + headers explicitly in addition to the normal gcc package. Using
103670 + older gcc versions means that functions with large enough stack
103671 + frames may leave uninitialized memory behind that may be exposed
103672 + to a later syscall leaking the stack.
103673 +
103674 +config PAX_MEMORY_STRUCTLEAK
103675 + bool "Forcibly initialize local variables copied to userland"
103676 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_PRIORITY_SECURITY)
103677 + help
103678 + By saying Y here the kernel will zero initialize some local
103679 + variables that are going to be copied to userland. This in
103680 + turn prevents unintended information leakage from the kernel
103681 + stack should later code forget to explicitly set all parts of
103682 + the copied variable.
103683 +
103684 + The tradeoff is less performance impact than PAX_MEMORY_STACKLEAK
103685 + at a much smaller coverage.
103686 +
103687 + Note that the implementation requires a gcc with plugin support,
103688 + i.e., gcc 4.5 or newer. You may need to install the supporting
103689 + headers explicitly in addition to the normal gcc package.
103690 +
103691 +config PAX_MEMORY_UDEREF
103692 + bool "Prevent invalid userland pointer dereference"
103693 + default y if GRKERNSEC_CONFIG_AUTO && !(X86_64 && GRKERNSEC_CONFIG_PRIORITY_PERF) && (GRKERNSEC_CONFIG_VIRT_NONE || GRKERNSEC_CONFIG_VIRT_EPT)
103694 + depends on (X86 || (ARM && (CPU_V6 || CPU_V6K || CPU_V7) && !ARM_LPAE)) && !UML_X86 && !XEN
103695 + select PAX_PER_CPU_PGD if X86_64
103696 + help
103697 + By saying Y here the kernel will be prevented from dereferencing
103698 + userland pointers in contexts where the kernel expects only kernel
103699 + pointers. This is both a useful runtime debugging feature and a
103700 + security measure that prevents exploiting a class of kernel bugs.
103701 +
103702 + The tradeoff is that some virtualization solutions may experience
103703 + a huge slowdown and therefore you should not enable this feature
103704 + for kernels meant to run in such environments. Whether a given VM
103705 + solution is affected or not is best determined by simply trying it
103706 + out, the performance impact will be obvious right on boot as this
103707 + mechanism engages from very early on. A good rule of thumb is that
103708 + VMs running on CPUs without hardware virtualization support (i.e.,
103709 + the majority of IA-32 CPUs) will likely experience the slowdown.
103710 +
103711 + On X86_64 the kernel will make use of PCID support when available
103712 + (Intel's Westmere, Sandy Bridge, etc) for better security (default)
103713 + or performance impact. Pass pax_weakuderef on the kernel command
103714 + line to choose the latter.
103715 +
103716 +config PAX_REFCOUNT
103717 + bool "Prevent various kernel object reference counter overflows"
103718 + default y if GRKERNSEC_CONFIG_AUTO
103719 + depends on GRKERNSEC && ((ARM && (CPU_V6 || CPU_V6K || CPU_V7)) || MIPS || SPARC64 || X86)
103720 + help
103721 + By saying Y here the kernel will detect and prevent overflowing
103722 + various (but not all) kinds of object reference counters. Such
103723 + overflows can normally occur due to bugs only and are often, if
103724 + not always, exploitable.
103725 +
103726 + The tradeoff is that data structures protected by an overflowed
103727 + refcount will never be freed and therefore will leak memory. Note
103728 + that this leak also happens even without this protection but in
103729 + that case the overflow can eventually trigger the freeing of the
103730 + data structure while it is still being used elsewhere, resulting
103731 + in the exploitable situation that this feature prevents.
103732 +
103733 + Since this has a negligible performance impact, you should enable
103734 + this feature.
103735 +
103736 +config PAX_CONSTIFY_PLUGIN
103737 + bool "Automatically constify eligible structures"
103738 + default y
103739 + depends on !UML && PAX_KERNEXEC
103740 + help
103741 + By saying Y here the compiler will automatically constify a class
103742 + of types that contain only function pointers. This reduces the
103743 + kernel's attack surface and also produces a better memory layout.
103744 +
103745 + Note that the implementation requires a gcc with plugin support,
103746 + i.e., gcc 4.5 or newer. You may need to install the supporting
103747 + headers explicitly in addition to the normal gcc package.
103748 +
103749 + Note that if some code really has to modify constified variables
103750 + then the source code will have to be patched to allow it. Examples
103751 + can be found in PaX itself (the no_const attribute) and for some
103752 + out-of-tree modules at http://www.grsecurity.net/~paxguy1/ .
103753 +
103754 +config PAX_USERCOPY
103755 + bool "Harden heap object copies between kernel and userland"
103756 + default y if GRKERNSEC_CONFIG_AUTO
103757 + depends on ARM || IA64 || PPC || SPARC || X86
103758 + depends on GRKERNSEC && (SLAB || SLUB || SLOB)
103759 + select PAX_USERCOPY_SLABS
103760 + help
103761 + By saying Y here the kernel will enforce the size of heap objects
103762 + when they are copied in either direction between the kernel and
103763 + userland, even if only a part of the heap object is copied.
103764 +
103765 + Specifically, this checking prevents information leaking from the
103766 + kernel heap during kernel to userland copies (if the kernel heap
103767 + object is otherwise fully initialized) and prevents kernel heap
103768 + overflows during userland to kernel copies.
103769 +
103770 + Note that the current implementation provides the strictest bounds
103771 + checks for the SLUB allocator.
103772 +
103773 + Enabling this option also enables per-slab cache protection against
103774 + data in a given cache being copied into/out of via userland
103775 + accessors. Though the whitelist of regions will be reduced over
103776 + time, it notably protects important data structures like task structs.
103777 +
103778 + If frame pointers are enabled on x86, this option will also restrict
103779 + copies into and out of the kernel stack to local variables within a
103780 + single frame.
103781 +
103782 + Since this has a negligible performance impact, you should enable
103783 + this feature.
103784 +
103785 +config PAX_USERCOPY_DEBUG
103786 + bool
103787 + depends on X86 && PAX_USERCOPY
103788 + default n
103789 +
103790 +config PAX_SIZE_OVERFLOW
103791 + bool "Prevent various integer overflows in function size parameters"
103792 + default y if GRKERNSEC_CONFIG_AUTO
103793 + depends on X86
103794 + help
103795 + By saying Y here the kernel recomputes expressions of function
103796 + arguments marked by a size_overflow attribute with double integer
103797 + precision (DImode/TImode for 32/64 bit integer types).
103798 +
103799 + The recomputed argument is checked against TYPE_MAX and an event
103800 + is logged on overflow and the triggering process is killed.
103801 +
103802 + Homepage: http://www.grsecurity.net/~ephox/overflow_plugin/
103803 +
103804 + Note that the implementation requires a gcc with plugin support,
103805 + i.e., gcc 4.5 or newer. You may need to install the supporting
103806 + headers explicitly in addition to the normal gcc package.
103807 +
103808 +config PAX_LATENT_ENTROPY
103809 + bool "Generate some entropy during boot and runtime"
103810 + default y if GRKERNSEC_CONFIG_AUTO
103811 + help
103812 + By saying Y here the kernel will instrument some kernel code to
103813 + extract some entropy from both original and artificially created
103814 + program state. This will help especially embedded systems where
103815 + there is little 'natural' source of entropy normally. The cost
103816 + is some slowdown of the boot process and fork and irq processing.
103817 +
103818 + When pax_extra_latent_entropy is passed on the kernel command line,
103819 + entropy will be extracted from up to the first 4GB of RAM while the
103820 + runtime memory allocator is being initialized. This costs even more
103821 + slowdown of the boot process.
103822 +
103823 + Note that the implementation requires a gcc with plugin support,
103824 + i.e., gcc 4.5 or newer. You may need to install the supporting
103825 + headers explicitly in addition to the normal gcc package.
103826 +
103827 + Note that entropy extracted this way is not cryptographically
103828 + secure!
103829 +
103830 +endmenu
103831 +
103832 +endmenu
103833 +
103834 +source grsecurity/Kconfig
103835 +
103836 +endmenu
103837 +
103838 +endmenu
103839 +
103840 source security/keys/Kconfig
103841
103842 config SECURITY_DMESG_RESTRICT
103843 @@ -103,7 +1057,7 @@ config INTEL_TXT
103844 config LSM_MMAP_MIN_ADDR
103845 int "Low address space for LSM to protect from user allocation"
103846 depends on SECURITY && SECURITY_SELINUX
103847 - default 32768 if ARM
103848 + default 32768 if ALPHA || ARM || PARISC || SPARC32
103849 default 65536
103850 help
103851 This is the portion of low virtual memory which should be protected
103852 diff --git a/security/apparmor/file.c b/security/apparmor/file.c
103853 index fdaa50c..2761dcb 100644
103854 --- a/security/apparmor/file.c
103855 +++ b/security/apparmor/file.c
103856 @@ -348,8 +348,8 @@ static inline bool xindex_is_subset(u32 link, u32 target)
103857 int aa_path_link(struct aa_profile *profile, struct dentry *old_dentry,
103858 struct path *new_dir, struct dentry *new_dentry)
103859 {
103860 - struct path link = { new_dir->mnt, new_dentry };
103861 - struct path target = { new_dir->mnt, old_dentry };
103862 + struct path link = { .mnt = new_dir->mnt, .dentry = new_dentry };
103863 + struct path target = { .mnt = new_dir->mnt, .dentry = old_dentry };
103864 struct path_cond cond = {
103865 old_dentry->d_inode->i_uid,
103866 old_dentry->d_inode->i_mode
103867 diff --git a/security/apparmor/lsm.c b/security/apparmor/lsm.c
103868 index 4257b7e..2d0732d 100644
103869 --- a/security/apparmor/lsm.c
103870 +++ b/security/apparmor/lsm.c
103871 @@ -186,7 +186,7 @@ static int common_perm_dir_dentry(int op, struct path *dir,
103872 struct dentry *dentry, u32 mask,
103873 struct path_cond *cond)
103874 {
103875 - struct path path = { dir->mnt, dentry };
103876 + struct path path = { .mnt = dir->mnt, .dentry = dentry };
103877
103878 return common_perm(op, &path, mask, cond);
103879 }
103880 @@ -203,7 +203,7 @@ static int common_perm_dir_dentry(int op, struct path *dir,
103881 static int common_perm_mnt_dentry(int op, struct vfsmount *mnt,
103882 struct dentry *dentry, u32 mask)
103883 {
103884 - struct path path = { mnt, dentry };
103885 + struct path path = { .mnt = mnt, .dentry = dentry };
103886 struct path_cond cond = { dentry->d_inode->i_uid,
103887 dentry->d_inode->i_mode
103888 };
103889 @@ -325,8 +325,8 @@ static int apparmor_path_rename(struct path *old_dir, struct dentry *old_dentry,
103890
103891 profile = aa_current_profile();
103892 if (!unconfined(profile)) {
103893 - struct path old_path = { old_dir->mnt, old_dentry };
103894 - struct path new_path = { new_dir->mnt, new_dentry };
103895 + struct path old_path = { .mnt = old_dir->mnt, .dentry = old_dentry };
103896 + struct path new_path = { .mnt = new_dir->mnt, .dentry = new_dentry };
103897 struct path_cond cond = { old_dentry->d_inode->i_uid,
103898 old_dentry->d_inode->i_mode
103899 };
103900 @@ -615,7 +615,7 @@ static int apparmor_task_setrlimit(struct task_struct *task,
103901 return error;
103902 }
103903
103904 -static struct security_operations apparmor_ops = {
103905 +static struct security_operations apparmor_ops __read_only = {
103906 .name = "apparmor",
103907
103908 .ptrace_access_check = apparmor_ptrace_access_check,
103909 diff --git a/security/commoncap.c b/security/commoncap.c
103910 index b9d613e..f68305c 100644
103911 --- a/security/commoncap.c
103912 +++ b/security/commoncap.c
103913 @@ -424,6 +424,32 @@ int get_vfs_caps_from_disk(const struct dentry *dentry, struct cpu_vfs_cap_data
103914 return 0;
103915 }
103916
103917 +/* returns:
103918 + 1 for suid privilege
103919 + 2 for sgid privilege
103920 + 3 for fscap privilege
103921 +*/
103922 +int is_privileged_binary(const struct dentry *dentry)
103923 +{
103924 + struct cpu_vfs_cap_data capdata;
103925 + struct inode *inode = dentry->d_inode;
103926 +
103927 + if (!inode || S_ISDIR(inode->i_mode))
103928 + return 0;
103929 +
103930 + if (inode->i_mode & S_ISUID)
103931 + return 1;
103932 + if ((inode->i_mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))
103933 + return 2;
103934 +
103935 + if (!get_vfs_caps_from_disk(dentry, &capdata)) {
103936 + if (!cap_isclear(capdata.inheritable) || !cap_isclear(capdata.permitted))
103937 + return 3;
103938 + }
103939 +
103940 + return 0;
103941 +}
103942 +
103943 /*
103944 * Attempt to get the on-exec apply capability sets for an executable file from
103945 * its xattrs and, if present, apply them to the proposed credentials being
103946 @@ -592,6 +618,9 @@ int cap_bprm_secureexec(struct linux_binprm *bprm)
103947 const struct cred *cred = current_cred();
103948 kuid_t root_uid = make_kuid(cred->user_ns, 0);
103949
103950 + if (gr_acl_enable_at_secure())
103951 + return 1;
103952 +
103953 if (!uid_eq(cred->uid, root_uid)) {
103954 if (bprm->cap_effective)
103955 return 1;
103956 diff --git a/security/integrity/ima/ima.h b/security/integrity/ima/ima.h
103957 index 0356e1d..72332ab 100644
103958 --- a/security/integrity/ima/ima.h
103959 +++ b/security/integrity/ima/ima.h
103960 @@ -118,8 +118,8 @@ int ima_init_template(void);
103961 extern spinlock_t ima_queue_lock;
103962
103963 struct ima_h_table {
103964 - atomic_long_t len; /* number of stored measurements in the list */
103965 - atomic_long_t violations;
103966 + atomic_long_unchecked_t len; /* number of stored measurements in the list */
103967 + atomic_long_unchecked_t violations;
103968 struct hlist_head queue[IMA_MEASURE_HTABLE_SIZE];
103969 };
103970 extern struct ima_h_table ima_htable;
103971 diff --git a/security/integrity/ima/ima_api.c b/security/integrity/ima/ima_api.c
103972 index c38bbce..f45133d 100644
103973 --- a/security/integrity/ima/ima_api.c
103974 +++ b/security/integrity/ima/ima_api.c
103975 @@ -137,7 +137,7 @@ void ima_add_violation(struct file *file, const unsigned char *filename,
103976 int result;
103977
103978 /* can overflow, only indicator */
103979 - atomic_long_inc(&ima_htable.violations);
103980 + atomic_long_inc_unchecked(&ima_htable.violations);
103981
103982 result = ima_alloc_init_template(NULL, file, filename,
103983 NULL, 0, &entry);
103984 diff --git a/security/integrity/ima/ima_fs.c b/security/integrity/ima/ima_fs.c
103985 index db01125..61f6597 100644
103986 --- a/security/integrity/ima/ima_fs.c
103987 +++ b/security/integrity/ima/ima_fs.c
103988 @@ -28,12 +28,12 @@
103989 static int valid_policy = 1;
103990 #define TMPBUFLEN 12
103991 static ssize_t ima_show_htable_value(char __user *buf, size_t count,
103992 - loff_t *ppos, atomic_long_t *val)
103993 + loff_t *ppos, atomic_long_unchecked_t *val)
103994 {
103995 char tmpbuf[TMPBUFLEN];
103996 ssize_t len;
103997
103998 - len = scnprintf(tmpbuf, TMPBUFLEN, "%li\n", atomic_long_read(val));
103999 + len = scnprintf(tmpbuf, TMPBUFLEN, "%li\n", atomic_long_read_unchecked(val));
104000 return simple_read_from_buffer(buf, count, ppos, tmpbuf, len);
104001 }
104002
104003 diff --git a/security/integrity/ima/ima_queue.c b/security/integrity/ima/ima_queue.c
104004 index d85e997..6992813 100644
104005 --- a/security/integrity/ima/ima_queue.c
104006 +++ b/security/integrity/ima/ima_queue.c
104007 @@ -80,7 +80,7 @@ static int ima_add_digest_entry(struct ima_template_entry *entry)
104008 INIT_LIST_HEAD(&qe->later);
104009 list_add_tail_rcu(&qe->later, &ima_measurements);
104010
104011 - atomic_long_inc(&ima_htable.len);
104012 + atomic_long_inc_unchecked(&ima_htable.len);
104013 key = ima_hash_key(entry->digest);
104014 hlist_add_head_rcu(&qe->hnext, &ima_htable.queue[key]);
104015 return 0;
104016 diff --git a/security/keys/compat.c b/security/keys/compat.c
104017 index bbd32c7..c60c927 100644
104018 --- a/security/keys/compat.c
104019 +++ b/security/keys/compat.c
104020 @@ -44,7 +44,7 @@ static long compat_keyctl_instantiate_key_iov(
104021 if (ret == 0)
104022 goto no_payload_free;
104023
104024 - ret = keyctl_instantiate_key_common(id, iov, ioc, ret, ringid);
104025 + ret = keyctl_instantiate_key_common(id, (const struct iovec __force_user *)iov, ioc, ret, ringid);
104026 err:
104027 if (iov != iovstack)
104028 kfree(iov);
104029 diff --git a/security/keys/internal.h b/security/keys/internal.h
104030 index 80b2aac..bb7ee65 100644
104031 --- a/security/keys/internal.h
104032 +++ b/security/keys/internal.h
104033 @@ -253,7 +253,7 @@ extern long keyctl_instantiate_key_iov(key_serial_t,
104034 extern long keyctl_invalidate_key(key_serial_t);
104035
104036 extern long keyctl_instantiate_key_common(key_serial_t,
104037 - const struct iovec *,
104038 + const struct iovec __user *,
104039 unsigned, size_t, key_serial_t);
104040 #ifdef CONFIG_PERSISTENT_KEYRINGS
104041 extern long keyctl_get_persistent(uid_t, key_serial_t);
104042 diff --git a/security/keys/key.c b/security/keys/key.c
104043 index 6e21c11..9ed67ca 100644
104044 --- a/security/keys/key.c
104045 +++ b/security/keys/key.c
104046 @@ -285,7 +285,7 @@ struct key *key_alloc(struct key_type *type, const char *desc,
104047
104048 atomic_set(&key->usage, 1);
104049 init_rwsem(&key->sem);
104050 - lockdep_set_class(&key->sem, &type->lock_class);
104051 + lockdep_set_class(&key->sem, (struct lock_class_key *)&type->lock_class);
104052 key->index_key.type = type;
104053 key->user = user;
104054 key->quotalen = quotalen;
104055 @@ -1036,7 +1036,9 @@ int register_key_type(struct key_type *ktype)
104056 struct key_type *p;
104057 int ret;
104058
104059 - memset(&ktype->lock_class, 0, sizeof(ktype->lock_class));
104060 + pax_open_kernel();
104061 + memset((void *)&ktype->lock_class, 0, sizeof(ktype->lock_class));
104062 + pax_close_kernel();
104063
104064 ret = -EEXIST;
104065 down_write(&key_types_sem);
104066 @@ -1048,7 +1050,7 @@ int register_key_type(struct key_type *ktype)
104067 }
104068
104069 /* store the type */
104070 - list_add(&ktype->link, &key_types_list);
104071 + pax_list_add((struct list_head *)&ktype->link, &key_types_list);
104072
104073 pr_notice("Key type %s registered\n", ktype->name);
104074 ret = 0;
104075 @@ -1070,7 +1072,7 @@ EXPORT_SYMBOL(register_key_type);
104076 void unregister_key_type(struct key_type *ktype)
104077 {
104078 down_write(&key_types_sem);
104079 - list_del_init(&ktype->link);
104080 + pax_list_del_init((struct list_head *)&ktype->link);
104081 downgrade_write(&key_types_sem);
104082 key_gc_keytype(ktype);
104083 pr_notice("Key type %s unregistered\n", ktype->name);
104084 @@ -1088,10 +1090,10 @@ void __init key_init(void)
104085 0, SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
104086
104087 /* add the special key types */
104088 - list_add_tail(&key_type_keyring.link, &key_types_list);
104089 - list_add_tail(&key_type_dead.link, &key_types_list);
104090 - list_add_tail(&key_type_user.link, &key_types_list);
104091 - list_add_tail(&key_type_logon.link, &key_types_list);
104092 + pax_list_add_tail((struct list_head *)&key_type_keyring.link, &key_types_list);
104093 + pax_list_add_tail((struct list_head *)&key_type_dead.link, &key_types_list);
104094 + pax_list_add_tail((struct list_head *)&key_type_user.link, &key_types_list);
104095 + pax_list_add_tail((struct list_head *)&key_type_logon.link, &key_types_list);
104096
104097 /* record the root user tracking */
104098 rb_link_node(&root_key_user.node,
104099 diff --git a/security/keys/keyctl.c b/security/keys/keyctl.c
104100 index cee72ce..e46074a 100644
104101 --- a/security/keys/keyctl.c
104102 +++ b/security/keys/keyctl.c
104103 @@ -987,7 +987,7 @@ static int keyctl_change_reqkey_auth(struct key *key)
104104 /*
104105 * Copy the iovec data from userspace
104106 */
104107 -static long copy_from_user_iovec(void *buffer, const struct iovec *iov,
104108 +static long copy_from_user_iovec(void *buffer, const struct iovec __user *iov,
104109 unsigned ioc)
104110 {
104111 for (; ioc > 0; ioc--) {
104112 @@ -1009,7 +1009,7 @@ static long copy_from_user_iovec(void *buffer, const struct iovec *iov,
104113 * If successful, 0 will be returned.
104114 */
104115 long keyctl_instantiate_key_common(key_serial_t id,
104116 - const struct iovec *payload_iov,
104117 + const struct iovec __user *payload_iov,
104118 unsigned ioc,
104119 size_t plen,
104120 key_serial_t ringid)
104121 @@ -1104,7 +1104,7 @@ long keyctl_instantiate_key(key_serial_t id,
104122 [0].iov_len = plen
104123 };
104124
104125 - return keyctl_instantiate_key_common(id, iov, 1, plen, ringid);
104126 + return keyctl_instantiate_key_common(id, (const struct iovec __force_user *)iov, 1, plen, ringid);
104127 }
104128
104129 return keyctl_instantiate_key_common(id, NULL, 0, 0, ringid);
104130 @@ -1137,7 +1137,7 @@ long keyctl_instantiate_key_iov(key_serial_t id,
104131 if (ret == 0)
104132 goto no_payload_free;
104133
104134 - ret = keyctl_instantiate_key_common(id, iov, ioc, ret, ringid);
104135 + ret = keyctl_instantiate_key_common(id, (const struct iovec __force_user *)iov, ioc, ret, ringid);
104136 err:
104137 if (iov != iovstack)
104138 kfree(iov);
104139 diff --git a/security/keys/keyring.c b/security/keys/keyring.c
104140 index d46cbc5..2fb2576 100644
104141 --- a/security/keys/keyring.c
104142 +++ b/security/keys/keyring.c
104143 @@ -1000,7 +1000,11 @@ static int keyring_detect_cycle_iterator(const void *object,
104144
104145 kenter("{%d}", key->serial);
104146
104147 - BUG_ON(key != ctx->match_data);
104148 + /* We might get a keyring with matching index-key that is nonetheless a
104149 + * different keyring. */
104150 + if (key != ctx->match_data)
104151 + return 0;
104152 +
104153 ctx->result = ERR_PTR(-EDEADLK);
104154 return 1;
104155 }
104156 diff --git a/security/min_addr.c b/security/min_addr.c
104157 index f728728..6457a0c 100644
104158 --- a/security/min_addr.c
104159 +++ b/security/min_addr.c
104160 @@ -14,6 +14,7 @@ unsigned long dac_mmap_min_addr = CONFIG_DEFAULT_MMAP_MIN_ADDR;
104161 */
104162 static void update_mmap_min_addr(void)
104163 {
104164 +#ifndef SPARC
104165 #ifdef CONFIG_LSM_MMAP_MIN_ADDR
104166 if (dac_mmap_min_addr > CONFIG_LSM_MMAP_MIN_ADDR)
104167 mmap_min_addr = dac_mmap_min_addr;
104168 @@ -22,6 +23,7 @@ static void update_mmap_min_addr(void)
104169 #else
104170 mmap_min_addr = dac_mmap_min_addr;
104171 #endif
104172 +#endif
104173 }
104174
104175 /*
104176 diff --git a/security/security.c b/security/security.c
104177 index 15b6928..60d03ec 100644
104178 --- a/security/security.c
104179 +++ b/security/security.c
104180 @@ -33,8 +33,8 @@
104181 static __initdata char chosen_lsm[SECURITY_NAME_MAX + 1] =
104182 CONFIG_DEFAULT_SECURITY;
104183
104184 -static struct security_operations *security_ops;
104185 -static struct security_operations default_security_ops = {
104186 +struct security_operations *security_ops __read_only;
104187 +struct security_operations default_security_ops __read_only = {
104188 .name = "default",
104189 };
104190
104191 @@ -73,11 +73,6 @@ int __init security_init(void)
104192 return 0;
104193 }
104194
104195 -void reset_security_ops(void)
104196 -{
104197 - security_ops = &default_security_ops;
104198 -}
104199 -
104200 /* Save user chosen LSM */
104201 static int __init choose_lsm(char *str)
104202 {
104203 diff --git a/security/selinux/avc.c b/security/selinux/avc.c
104204 index fc3e662..7844c60 100644
104205 --- a/security/selinux/avc.c
104206 +++ b/security/selinux/avc.c
104207 @@ -59,7 +59,7 @@ struct avc_node {
104208 struct avc_cache {
104209 struct hlist_head slots[AVC_CACHE_SLOTS]; /* head for avc_node->list */
104210 spinlock_t slots_lock[AVC_CACHE_SLOTS]; /* lock for writes */
104211 - atomic_t lru_hint; /* LRU hint for reclaim scan */
104212 + atomic_unchecked_t lru_hint; /* LRU hint for reclaim scan */
104213 atomic_t active_nodes;
104214 u32 latest_notif; /* latest revocation notification */
104215 };
104216 @@ -167,7 +167,7 @@ void __init avc_init(void)
104217 spin_lock_init(&avc_cache.slots_lock[i]);
104218 }
104219 atomic_set(&avc_cache.active_nodes, 0);
104220 - atomic_set(&avc_cache.lru_hint, 0);
104221 + atomic_set_unchecked(&avc_cache.lru_hint, 0);
104222
104223 avc_node_cachep = kmem_cache_create("avc_node", sizeof(struct avc_node),
104224 0, SLAB_PANIC, NULL);
104225 @@ -242,7 +242,7 @@ static inline int avc_reclaim_node(void)
104226 spinlock_t *lock;
104227
104228 for (try = 0, ecx = 0; try < AVC_CACHE_SLOTS; try++) {
104229 - hvalue = atomic_inc_return(&avc_cache.lru_hint) & (AVC_CACHE_SLOTS - 1);
104230 + hvalue = atomic_inc_return_unchecked(&avc_cache.lru_hint) & (AVC_CACHE_SLOTS - 1);
104231 head = &avc_cache.slots[hvalue];
104232 lock = &avc_cache.slots_lock[hvalue];
104233
104234 diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c
104235 index 019749c..0648215 100644
104236 --- a/security/selinux/hooks.c
104237 +++ b/security/selinux/hooks.c
104238 @@ -96,8 +96,6 @@
104239 #include "audit.h"
104240 #include "avc_ss.h"
104241
104242 -extern struct security_operations *security_ops;
104243 -
104244 /* SECMARK reference count */
104245 static atomic_t selinux_secmark_refcount = ATOMIC_INIT(0);
104246
104247 @@ -5763,7 +5761,7 @@ static int selinux_key_getsecurity(struct key *key, char **_buffer)
104248
104249 #endif
104250
104251 -static struct security_operations selinux_ops = {
104252 +static struct security_operations selinux_ops __read_only = {
104253 .name = "selinux",
104254
104255 .ptrace_access_check = selinux_ptrace_access_check,
104256 @@ -6116,6 +6114,9 @@ static void selinux_nf_ip_exit(void)
104257 #ifdef CONFIG_SECURITY_SELINUX_DISABLE
104258 static int selinux_disabled;
104259
104260 +extern struct security_operations *security_ops;
104261 +extern struct security_operations default_security_ops;
104262 +
104263 int selinux_disable(void)
104264 {
104265 if (ss_initialized) {
104266 @@ -6133,7 +6134,9 @@ int selinux_disable(void)
104267 selinux_disabled = 1;
104268 selinux_enabled = 0;
104269
104270 - reset_security_ops();
104271 + pax_open_kernel();
104272 + security_ops = &default_security_ops;
104273 + pax_close_kernel();
104274
104275 /* Try to destroy the avc node cache */
104276 avc_disable();
104277 diff --git a/security/selinux/include/xfrm.h b/security/selinux/include/xfrm.h
104278 index 48c3cc9..8022cf7 100644
104279 --- a/security/selinux/include/xfrm.h
104280 +++ b/security/selinux/include/xfrm.h
104281 @@ -45,7 +45,7 @@ static inline void selinux_xfrm_notify_policyload(void)
104282 {
104283 struct net *net;
104284
104285 - atomic_inc(&flow_cache_genid);
104286 + atomic_inc_unchecked(&flow_cache_genid);
104287 rtnl_lock();
104288 for_each_net(net)
104289 rt_genid_bump_all(net);
104290 diff --git a/security/smack/smack_lsm.c b/security/smack/smack_lsm.c
104291 index b0be893..646bd94 100644
104292 --- a/security/smack/smack_lsm.c
104293 +++ b/security/smack/smack_lsm.c
104294 @@ -3731,7 +3731,7 @@ static int smack_inode_getsecctx(struct inode *inode, void **ctx, u32 *ctxlen)
104295 return 0;
104296 }
104297
104298 -struct security_operations smack_ops = {
104299 +struct security_operations smack_ops __read_only = {
104300 .name = "smack",
104301
104302 .ptrace_access_check = smack_ptrace_access_check,
104303 diff --git a/security/tomoyo/file.c b/security/tomoyo/file.c
104304 index 4003907..13a2b55 100644
104305 --- a/security/tomoyo/file.c
104306 +++ b/security/tomoyo/file.c
104307 @@ -692,7 +692,7 @@ int tomoyo_path_number_perm(const u8 type, struct path *path,
104308 {
104309 struct tomoyo_request_info r;
104310 struct tomoyo_obj_info obj = {
104311 - .path1 = *path,
104312 + .path1 = { .mnt = path->mnt, .dentry = path->dentry },
104313 };
104314 int error = -ENOMEM;
104315 struct tomoyo_path_info buf;
104316 @@ -740,7 +740,7 @@ int tomoyo_check_open_permission(struct tomoyo_domain_info *domain,
104317 struct tomoyo_path_info buf;
104318 struct tomoyo_request_info r;
104319 struct tomoyo_obj_info obj = {
104320 - .path1 = *path,
104321 + .path1 = { .mnt = path->mnt, .dentry = path->dentry },
104322 };
104323 int idx;
104324
104325 @@ -786,7 +786,7 @@ int tomoyo_path_perm(const u8 operation, struct path *path, const char *target)
104326 {
104327 struct tomoyo_request_info r;
104328 struct tomoyo_obj_info obj = {
104329 - .path1 = *path,
104330 + .path1 = { .mnt = path->mnt, .dentry = path->dentry },
104331 };
104332 int error;
104333 struct tomoyo_path_info buf;
104334 @@ -843,7 +843,7 @@ int tomoyo_mkdev_perm(const u8 operation, struct path *path,
104335 {
104336 struct tomoyo_request_info r;
104337 struct tomoyo_obj_info obj = {
104338 - .path1 = *path,
104339 + .path1 = { .mnt = path->mnt, .dentry = path->dentry },
104340 };
104341 int error = -ENOMEM;
104342 struct tomoyo_path_info buf;
104343 @@ -890,8 +890,8 @@ int tomoyo_path2_perm(const u8 operation, struct path *path1,
104344 struct tomoyo_path_info buf2;
104345 struct tomoyo_request_info r;
104346 struct tomoyo_obj_info obj = {
104347 - .path1 = *path1,
104348 - .path2 = *path2,
104349 + .path1 = { .mnt = path1->mnt, .dentry = path1->dentry },
104350 + .path2 = { .mnt = path2->mnt, .dentry = path2->dentry }
104351 };
104352 int idx;
104353
104354 diff --git a/security/tomoyo/mount.c b/security/tomoyo/mount.c
104355 index 390c646..f2f8db3 100644
104356 --- a/security/tomoyo/mount.c
104357 +++ b/security/tomoyo/mount.c
104358 @@ -118,6 +118,10 @@ static int tomoyo_mount_acl(struct tomoyo_request_info *r,
104359 type == tomoyo_mounts[TOMOYO_MOUNT_MOVE]) {
104360 need_dev = -1; /* dev_name is a directory */
104361 } else {
104362 + if (!capable(CAP_SYS_ADMIN)) {
104363 + error = -EPERM;
104364 + goto out;
104365 + }
104366 fstype = get_fs_type(type);
104367 if (!fstype) {
104368 error = -ENODEV;
104369 diff --git a/security/tomoyo/tomoyo.c b/security/tomoyo/tomoyo.c
104370 index f0b756e..8aa497b 100644
104371 --- a/security/tomoyo/tomoyo.c
104372 +++ b/security/tomoyo/tomoyo.c
104373 @@ -146,7 +146,7 @@ static int tomoyo_bprm_check_security(struct linux_binprm *bprm)
104374 */
104375 static int tomoyo_inode_getattr(struct vfsmount *mnt, struct dentry *dentry)
104376 {
104377 - struct path path = { mnt, dentry };
104378 + struct path path = { .mnt = mnt, .dentry = dentry };
104379 return tomoyo_path_perm(TOMOYO_TYPE_GETATTR, &path, NULL);
104380 }
104381
104382 @@ -172,7 +172,7 @@ static int tomoyo_path_truncate(struct path *path)
104383 */
104384 static int tomoyo_path_unlink(struct path *parent, struct dentry *dentry)
104385 {
104386 - struct path path = { parent->mnt, dentry };
104387 + struct path path = { .mnt = parent->mnt, .dentry = dentry };
104388 return tomoyo_path_perm(TOMOYO_TYPE_UNLINK, &path, NULL);
104389 }
104390
104391 @@ -188,7 +188,7 @@ static int tomoyo_path_unlink(struct path *parent, struct dentry *dentry)
104392 static int tomoyo_path_mkdir(struct path *parent, struct dentry *dentry,
104393 umode_t mode)
104394 {
104395 - struct path path = { parent->mnt, dentry };
104396 + struct path path = { .mnt = parent->mnt, .dentry = dentry };
104397 return tomoyo_path_number_perm(TOMOYO_TYPE_MKDIR, &path,
104398 mode & S_IALLUGO);
104399 }
104400 @@ -203,7 +203,7 @@ static int tomoyo_path_mkdir(struct path *parent, struct dentry *dentry,
104401 */
104402 static int tomoyo_path_rmdir(struct path *parent, struct dentry *dentry)
104403 {
104404 - struct path path = { parent->mnt, dentry };
104405 + struct path path = { .mnt = parent->mnt, .dentry = dentry };
104406 return tomoyo_path_perm(TOMOYO_TYPE_RMDIR, &path, NULL);
104407 }
104408
104409 @@ -219,7 +219,7 @@ static int tomoyo_path_rmdir(struct path *parent, struct dentry *dentry)
104410 static int tomoyo_path_symlink(struct path *parent, struct dentry *dentry,
104411 const char *old_name)
104412 {
104413 - struct path path = { parent->mnt, dentry };
104414 + struct path path = { .mnt = parent->mnt, .dentry = dentry };
104415 return tomoyo_path_perm(TOMOYO_TYPE_SYMLINK, &path, old_name);
104416 }
104417
104418 @@ -236,7 +236,7 @@ static int tomoyo_path_symlink(struct path *parent, struct dentry *dentry,
104419 static int tomoyo_path_mknod(struct path *parent, struct dentry *dentry,
104420 umode_t mode, unsigned int dev)
104421 {
104422 - struct path path = { parent->mnt, dentry };
104423 + struct path path = { .mnt = parent->mnt, .dentry = dentry };
104424 int type = TOMOYO_TYPE_CREATE;
104425 const unsigned int perm = mode & S_IALLUGO;
104426
104427 @@ -275,8 +275,8 @@ static int tomoyo_path_mknod(struct path *parent, struct dentry *dentry,
104428 static int tomoyo_path_link(struct dentry *old_dentry, struct path *new_dir,
104429 struct dentry *new_dentry)
104430 {
104431 - struct path path1 = { new_dir->mnt, old_dentry };
104432 - struct path path2 = { new_dir->mnt, new_dentry };
104433 + struct path path1 = { .mnt = new_dir->mnt, .dentry = old_dentry };
104434 + struct path path2 = { .mnt = new_dir->mnt, .dentry = new_dentry };
104435 return tomoyo_path2_perm(TOMOYO_TYPE_LINK, &path1, &path2);
104436 }
104437
104438 @@ -295,8 +295,8 @@ static int tomoyo_path_rename(struct path *old_parent,
104439 struct path *new_parent,
104440 struct dentry *new_dentry)
104441 {
104442 - struct path path1 = { old_parent->mnt, old_dentry };
104443 - struct path path2 = { new_parent->mnt, new_dentry };
104444 + struct path path1 = { .mnt = old_parent->mnt, .dentry = old_dentry };
104445 + struct path path2 = { .mnt = new_parent->mnt, .dentry = new_dentry };
104446 return tomoyo_path2_perm(TOMOYO_TYPE_RENAME, &path1, &path2);
104447 }
104448
104449 @@ -424,7 +424,7 @@ static int tomoyo_sb_mount(const char *dev_name, struct path *path,
104450 */
104451 static int tomoyo_sb_umount(struct vfsmount *mnt, int flags)
104452 {
104453 - struct path path = { mnt, mnt->mnt_root };
104454 + struct path path = { .mnt = mnt, .dentry = mnt->mnt_root };
104455 return tomoyo_path_perm(TOMOYO_TYPE_UMOUNT, &path, NULL);
104456 }
104457
104458 @@ -503,7 +503,7 @@ static int tomoyo_socket_sendmsg(struct socket *sock, struct msghdr *msg,
104459 * tomoyo_security_ops is a "struct security_operations" which is used for
104460 * registering TOMOYO.
104461 */
104462 -static struct security_operations tomoyo_security_ops = {
104463 +static struct security_operations tomoyo_security_ops __read_only = {
104464 .name = "tomoyo",
104465 .cred_alloc_blank = tomoyo_cred_alloc_blank,
104466 .cred_prepare = tomoyo_cred_prepare,
104467 diff --git a/security/yama/Kconfig b/security/yama/Kconfig
104468 index 20ef514..4182bed 100644
104469 --- a/security/yama/Kconfig
104470 +++ b/security/yama/Kconfig
104471 @@ -1,6 +1,6 @@
104472 config SECURITY_YAMA
104473 bool "Yama support"
104474 - depends on SECURITY
104475 + depends on SECURITY && !GRKERNSEC
104476 select SECURITYFS
104477 select SECURITY_PATH
104478 default n
104479 diff --git a/security/yama/yama_lsm.c b/security/yama/yama_lsm.c
104480 index 13c88fbc..f8c115e 100644
104481 --- a/security/yama/yama_lsm.c
104482 +++ b/security/yama/yama_lsm.c
104483 @@ -365,7 +365,7 @@ int yama_ptrace_traceme(struct task_struct *parent)
104484 }
104485
104486 #ifndef CONFIG_SECURITY_YAMA_STACKED
104487 -static struct security_operations yama_ops = {
104488 +static struct security_operations yama_ops __read_only = {
104489 .name = "yama",
104490
104491 .ptrace_access_check = yama_ptrace_access_check,
104492 @@ -376,28 +376,24 @@ static struct security_operations yama_ops = {
104493 #endif
104494
104495 #ifdef CONFIG_SYSCTL
104496 +static int zero __read_only;
104497 +static int max_scope __read_only = YAMA_SCOPE_NO_ATTACH;
104498 +
104499 static int yama_dointvec_minmax(struct ctl_table *table, int write,
104500 void __user *buffer, size_t *lenp, loff_t *ppos)
104501 {
104502 - int rc;
104503 + ctl_table_no_const yama_table;
104504
104505 if (write && !capable(CAP_SYS_PTRACE))
104506 return -EPERM;
104507
104508 - rc = proc_dointvec_minmax(table, write, buffer, lenp, ppos);
104509 - if (rc)
104510 - return rc;
104511 -
104512 + yama_table = *table;
104513 /* Lock the max value if it ever gets set. */
104514 - if (write && *(int *)table->data == *(int *)table->extra2)
104515 - table->extra1 = table->extra2;
104516 -
104517 - return rc;
104518 + if (ptrace_scope == max_scope)
104519 + yama_table.extra1 = &max_scope;
104520 + return proc_dointvec_minmax(&yama_table, write, buffer, lenp, ppos);
104521 }
104522
104523 -static int zero;
104524 -static int max_scope = YAMA_SCOPE_NO_ATTACH;
104525 -
104526 struct ctl_path yama_sysctl_path[] = {
104527 { .procname = "kernel", },
104528 { .procname = "yama", },
104529 diff --git a/sound/aoa/codecs/onyx.c b/sound/aoa/codecs/onyx.c
104530 index 4cedc69..e59d8a3 100644
104531 --- a/sound/aoa/codecs/onyx.c
104532 +++ b/sound/aoa/codecs/onyx.c
104533 @@ -54,7 +54,7 @@ struct onyx {
104534 spdif_locked:1,
104535 analog_locked:1,
104536 original_mute:2;
104537 - int open_count;
104538 + local_t open_count;
104539 struct codec_info *codec_info;
104540
104541 /* mutex serializes concurrent access to the device
104542 @@ -753,7 +753,7 @@ static int onyx_open(struct codec_info_item *cii,
104543 struct onyx *onyx = cii->codec_data;
104544
104545 mutex_lock(&onyx->mutex);
104546 - onyx->open_count++;
104547 + local_inc(&onyx->open_count);
104548 mutex_unlock(&onyx->mutex);
104549
104550 return 0;
104551 @@ -765,8 +765,7 @@ static int onyx_close(struct codec_info_item *cii,
104552 struct onyx *onyx = cii->codec_data;
104553
104554 mutex_lock(&onyx->mutex);
104555 - onyx->open_count--;
104556 - if (!onyx->open_count)
104557 + if (local_dec_and_test(&onyx->open_count))
104558 onyx->spdif_locked = onyx->analog_locked = 0;
104559 mutex_unlock(&onyx->mutex);
104560
104561 diff --git a/sound/aoa/codecs/onyx.h b/sound/aoa/codecs/onyx.h
104562 index ffd2025..df062c9 100644
104563 --- a/sound/aoa/codecs/onyx.h
104564 +++ b/sound/aoa/codecs/onyx.h
104565 @@ -11,6 +11,7 @@
104566 #include <linux/i2c.h>
104567 #include <asm/pmac_low_i2c.h>
104568 #include <asm/prom.h>
104569 +#include <asm/local.h>
104570
104571 /* PCM3052 register definitions */
104572
104573 diff --git a/sound/core/oss/pcm_oss.c b/sound/core/oss/pcm_oss.c
104574 index 4c1cc51..16040040 100644
104575 --- a/sound/core/oss/pcm_oss.c
104576 +++ b/sound/core/oss/pcm_oss.c
104577 @@ -1189,10 +1189,10 @@ snd_pcm_sframes_t snd_pcm_oss_write3(struct snd_pcm_substream *substream, const
104578 if (in_kernel) {
104579 mm_segment_t fs;
104580 fs = snd_enter_user();
104581 - ret = snd_pcm_lib_write(substream, (void __force __user *)ptr, frames);
104582 + ret = snd_pcm_lib_write(substream, (void __force_user *)ptr, frames);
104583 snd_leave_user(fs);
104584 } else {
104585 - ret = snd_pcm_lib_write(substream, (void __force __user *)ptr, frames);
104586 + ret = snd_pcm_lib_write(substream, (void __force_user *)ptr, frames);
104587 }
104588 if (ret != -EPIPE && ret != -ESTRPIPE)
104589 break;
104590 @@ -1234,10 +1234,10 @@ snd_pcm_sframes_t snd_pcm_oss_read3(struct snd_pcm_substream *substream, char *p
104591 if (in_kernel) {
104592 mm_segment_t fs;
104593 fs = snd_enter_user();
104594 - ret = snd_pcm_lib_read(substream, (void __force __user *)ptr, frames);
104595 + ret = snd_pcm_lib_read(substream, (void __force_user *)ptr, frames);
104596 snd_leave_user(fs);
104597 } else {
104598 - ret = snd_pcm_lib_read(substream, (void __force __user *)ptr, frames);
104599 + ret = snd_pcm_lib_read(substream, (void __force_user *)ptr, frames);
104600 }
104601 if (ret == -EPIPE) {
104602 if (runtime->status->state == SNDRV_PCM_STATE_DRAINING) {
104603 @@ -1337,7 +1337,7 @@ static ssize_t snd_pcm_oss_write2(struct snd_pcm_substream *substream, const cha
104604 struct snd_pcm_plugin_channel *channels;
104605 size_t oss_frame_bytes = (runtime->oss.plugin_first->src_width * runtime->oss.plugin_first->src_format.channels) / 8;
104606 if (!in_kernel) {
104607 - if (copy_from_user(runtime->oss.buffer, (const char __force __user *)buf, bytes))
104608 + if (copy_from_user(runtime->oss.buffer, (const char __force_user *)buf, bytes))
104609 return -EFAULT;
104610 buf = runtime->oss.buffer;
104611 }
104612 @@ -1407,7 +1407,7 @@ static ssize_t snd_pcm_oss_write1(struct snd_pcm_substream *substream, const cha
104613 }
104614 } else {
104615 tmp = snd_pcm_oss_write2(substream,
104616 - (const char __force *)buf,
104617 + (const char __force_kernel *)buf,
104618 runtime->oss.period_bytes, 0);
104619 if (tmp <= 0)
104620 goto err;
104621 @@ -1433,7 +1433,7 @@ static ssize_t snd_pcm_oss_read2(struct snd_pcm_substream *substream, char *buf,
104622 struct snd_pcm_runtime *runtime = substream->runtime;
104623 snd_pcm_sframes_t frames, frames1;
104624 #ifdef CONFIG_SND_PCM_OSS_PLUGINS
104625 - char __user *final_dst = (char __force __user *)buf;
104626 + char __user *final_dst = (char __force_user *)buf;
104627 if (runtime->oss.plugin_first) {
104628 struct snd_pcm_plugin_channel *channels;
104629 size_t oss_frame_bytes = (runtime->oss.plugin_last->dst_width * runtime->oss.plugin_last->dst_format.channels) / 8;
104630 @@ -1495,7 +1495,7 @@ static ssize_t snd_pcm_oss_read1(struct snd_pcm_substream *substream, char __use
104631 xfer += tmp;
104632 runtime->oss.buffer_used -= tmp;
104633 } else {
104634 - tmp = snd_pcm_oss_read2(substream, (char __force *)buf,
104635 + tmp = snd_pcm_oss_read2(substream, (char __force_kernel *)buf,
104636 runtime->oss.period_bytes, 0);
104637 if (tmp <= 0)
104638 goto err;
104639 @@ -1663,7 +1663,7 @@ static int snd_pcm_oss_sync(struct snd_pcm_oss_file *pcm_oss_file)
104640 size1);
104641 size1 /= runtime->channels; /* frames */
104642 fs = snd_enter_user();
104643 - snd_pcm_lib_write(substream, (void __force __user *)runtime->oss.buffer, size1);
104644 + snd_pcm_lib_write(substream, (void __force_user *)runtime->oss.buffer, size1);
104645 snd_leave_user(fs);
104646 }
104647 } else if (runtime->access == SNDRV_PCM_ACCESS_RW_NONINTERLEAVED) {
104648 diff --git a/sound/core/pcm_compat.c b/sound/core/pcm_compat.c
104649 index af49721..e85058e 100644
104650 --- a/sound/core/pcm_compat.c
104651 +++ b/sound/core/pcm_compat.c
104652 @@ -31,7 +31,7 @@ static int snd_pcm_ioctl_delay_compat(struct snd_pcm_substream *substream,
104653 int err;
104654
104655 fs = snd_enter_user();
104656 - err = snd_pcm_delay(substream, &delay);
104657 + err = snd_pcm_delay(substream, (snd_pcm_sframes_t __force_user *)&delay);
104658 snd_leave_user(fs);
104659 if (err < 0)
104660 return err;
104661 diff --git a/sound/core/pcm_native.c b/sound/core/pcm_native.c
104662 index 01a5e05..c6bb425 100644
104663 --- a/sound/core/pcm_native.c
104664 +++ b/sound/core/pcm_native.c
104665 @@ -2811,11 +2811,11 @@ int snd_pcm_kernel_ioctl(struct snd_pcm_substream *substream,
104666 switch (substream->stream) {
104667 case SNDRV_PCM_STREAM_PLAYBACK:
104668 result = snd_pcm_playback_ioctl1(NULL, substream, cmd,
104669 - (void __user *)arg);
104670 + (void __force_user *)arg);
104671 break;
104672 case SNDRV_PCM_STREAM_CAPTURE:
104673 result = snd_pcm_capture_ioctl1(NULL, substream, cmd,
104674 - (void __user *)arg);
104675 + (void __force_user *)arg);
104676 break;
104677 default:
104678 result = -EINVAL;
104679 diff --git a/sound/core/seq/oss/seq_oss.c b/sound/core/seq/oss/seq_oss.c
104680 index 8d4d5e8..fdd0826 100644
104681 --- a/sound/core/seq/oss/seq_oss.c
104682 +++ b/sound/core/seq/oss/seq_oss.c
104683 @@ -75,8 +75,8 @@ static int __init alsa_seq_oss_init(void)
104684 {
104685 int rc;
104686 static struct snd_seq_dev_ops ops = {
104687 - snd_seq_oss_synth_register,
104688 - snd_seq_oss_synth_unregister,
104689 + .init_device = snd_seq_oss_synth_register,
104690 + .free_device = snd_seq_oss_synth_unregister,
104691 };
104692
104693 snd_seq_autoload_lock();
104694 diff --git a/sound/core/seq/seq_device.c b/sound/core/seq/seq_device.c
104695 index 040c60e..989a19a 100644
104696 --- a/sound/core/seq/seq_device.c
104697 +++ b/sound/core/seq/seq_device.c
104698 @@ -64,7 +64,7 @@ struct ops_list {
104699 int argsize; /* argument size */
104700
104701 /* operators */
104702 - struct snd_seq_dev_ops ops;
104703 + struct snd_seq_dev_ops *ops;
104704
104705 /* registered devices */
104706 struct list_head dev_list; /* list of devices */
104707 @@ -333,7 +333,7 @@ int snd_seq_device_register_driver(char *id, struct snd_seq_dev_ops *entry,
104708
104709 mutex_lock(&ops->reg_mutex);
104710 /* copy driver operators */
104711 - ops->ops = *entry;
104712 + ops->ops = entry;
104713 ops->driver |= DRIVER_LOADED;
104714 ops->argsize = argsize;
104715
104716 @@ -463,7 +463,7 @@ static int init_device(struct snd_seq_device *dev, struct ops_list *ops)
104717 dev->name, ops->id, ops->argsize, dev->argsize);
104718 return -EINVAL;
104719 }
104720 - if (ops->ops.init_device(dev) >= 0) {
104721 + if (ops->ops->init_device(dev) >= 0) {
104722 dev->status = SNDRV_SEQ_DEVICE_REGISTERED;
104723 ops->num_init_devices++;
104724 } else {
104725 @@ -490,7 +490,7 @@ static int free_device(struct snd_seq_device *dev, struct ops_list *ops)
104726 dev->name, ops->id, ops->argsize, dev->argsize);
104727 return -EINVAL;
104728 }
104729 - if ((result = ops->ops.free_device(dev)) >= 0 || result == -ENXIO) {
104730 + if ((result = ops->ops->free_device(dev)) >= 0 || result == -ENXIO) {
104731 dev->status = SNDRV_SEQ_DEVICE_FREE;
104732 dev->driver_data = NULL;
104733 ops->num_init_devices--;
104734 diff --git a/sound/core/seq/seq_midi.c b/sound/core/seq/seq_midi.c
104735 index 64069db..3c6d392 100644
104736 --- a/sound/core/seq/seq_midi.c
104737 +++ b/sound/core/seq/seq_midi.c
104738 @@ -462,8 +462,8 @@ snd_seq_midisynth_unregister_port(struct snd_seq_device *dev)
104739 static int __init alsa_seq_midi_init(void)
104740 {
104741 static struct snd_seq_dev_ops ops = {
104742 - snd_seq_midisynth_register_port,
104743 - snd_seq_midisynth_unregister_port,
104744 + .init_device = snd_seq_midisynth_register_port,
104745 + .free_device = snd_seq_midisynth_unregister_port,
104746 };
104747 memset(&synths, 0, sizeof(synths));
104748 snd_seq_autoload_lock();
104749 diff --git a/sound/core/sound.c b/sound/core/sound.c
104750 index 437c25e..cd040ab 100644
104751 --- a/sound/core/sound.c
104752 +++ b/sound/core/sound.c
104753 @@ -86,7 +86,7 @@ static void snd_request_other(int minor)
104754 case SNDRV_MINOR_TIMER: str = "snd-timer"; break;
104755 default: return;
104756 }
104757 - request_module(str);
104758 + request_module("%s", str);
104759 }
104760
104761 #endif /* modular kernel */
104762 diff --git a/sound/drivers/mts64.c b/sound/drivers/mts64.c
104763 index 4e0dd22..7a1f32c 100644
104764 --- a/sound/drivers/mts64.c
104765 +++ b/sound/drivers/mts64.c
104766 @@ -29,6 +29,7 @@
104767 #include <sound/initval.h>
104768 #include <sound/rawmidi.h>
104769 #include <sound/control.h>
104770 +#include <asm/local.h>
104771
104772 #define CARD_NAME "Miditerminal 4140"
104773 #define DRIVER_NAME "MTS64"
104774 @@ -67,7 +68,7 @@ struct mts64 {
104775 struct pardevice *pardev;
104776 int pardev_claimed;
104777
104778 - int open_count;
104779 + local_t open_count;
104780 int current_midi_output_port;
104781 int current_midi_input_port;
104782 u8 mode[MTS64_NUM_INPUT_PORTS];
104783 @@ -697,7 +698,7 @@ static int snd_mts64_rawmidi_open(struct snd_rawmidi_substream *substream)
104784 {
104785 struct mts64 *mts = substream->rmidi->private_data;
104786
104787 - if (mts->open_count == 0) {
104788 + if (local_read(&mts->open_count) == 0) {
104789 /* We don't need a spinlock here, because this is just called
104790 if the device has not been opened before.
104791 So there aren't any IRQs from the device */
104792 @@ -705,7 +706,7 @@ static int snd_mts64_rawmidi_open(struct snd_rawmidi_substream *substream)
104793
104794 msleep(50);
104795 }
104796 - ++(mts->open_count);
104797 + local_inc(&mts->open_count);
104798
104799 return 0;
104800 }
104801 @@ -715,8 +716,7 @@ static int snd_mts64_rawmidi_close(struct snd_rawmidi_substream *substream)
104802 struct mts64 *mts = substream->rmidi->private_data;
104803 unsigned long flags;
104804
104805 - --(mts->open_count);
104806 - if (mts->open_count == 0) {
104807 + if (local_dec_return(&mts->open_count) == 0) {
104808 /* We need the spinlock_irqsave here because we can still
104809 have IRQs at this point */
104810 spin_lock_irqsave(&mts->lock, flags);
104811 @@ -725,8 +725,8 @@ static int snd_mts64_rawmidi_close(struct snd_rawmidi_substream *substream)
104812
104813 msleep(500);
104814
104815 - } else if (mts->open_count < 0)
104816 - mts->open_count = 0;
104817 + } else if (local_read(&mts->open_count) < 0)
104818 + local_set(&mts->open_count, 0);
104819
104820 return 0;
104821 }
104822 diff --git a/sound/drivers/opl3/opl3_seq.c b/sound/drivers/opl3/opl3_seq.c
104823 index 6839953..7a0f4b9 100644
104824 --- a/sound/drivers/opl3/opl3_seq.c
104825 +++ b/sound/drivers/opl3/opl3_seq.c
104826 @@ -281,8 +281,8 @@ static int __init alsa_opl3_seq_init(void)
104827 {
104828 static struct snd_seq_dev_ops ops =
104829 {
104830 - snd_opl3_seq_new_device,
104831 - snd_opl3_seq_delete_device
104832 + .init_device = snd_opl3_seq_new_device,
104833 + .free_device = snd_opl3_seq_delete_device
104834 };
104835
104836 return snd_seq_device_register_driver(SNDRV_SEQ_DEV_ID_OPL3, &ops,
104837 diff --git a/sound/drivers/opl4/opl4_lib.c b/sound/drivers/opl4/opl4_lib.c
104838 index b953fb4..1999c01 100644
104839 --- a/sound/drivers/opl4/opl4_lib.c
104840 +++ b/sound/drivers/opl4/opl4_lib.c
104841 @@ -29,7 +29,7 @@ MODULE_AUTHOR("Clemens Ladisch <clemens@ladisch.de>");
104842 MODULE_DESCRIPTION("OPL4 driver");
104843 MODULE_LICENSE("GPL");
104844
104845 -static void inline snd_opl4_wait(struct snd_opl4 *opl4)
104846 +static inline void snd_opl4_wait(struct snd_opl4 *opl4)
104847 {
104848 int timeout = 10;
104849 while ((inb(opl4->fm_port) & OPL4_STATUS_BUSY) && --timeout > 0)
104850 diff --git a/sound/drivers/opl4/opl4_seq.c b/sound/drivers/opl4/opl4_seq.c
104851 index 9919769..d7de36c 100644
104852 --- a/sound/drivers/opl4/opl4_seq.c
104853 +++ b/sound/drivers/opl4/opl4_seq.c
104854 @@ -198,8 +198,8 @@ static int snd_opl4_seq_delete_device(struct snd_seq_device *dev)
104855 static int __init alsa_opl4_synth_init(void)
104856 {
104857 static struct snd_seq_dev_ops ops = {
104858 - snd_opl4_seq_new_device,
104859 - snd_opl4_seq_delete_device
104860 + .init_device = snd_opl4_seq_new_device,
104861 + .free_device = snd_opl4_seq_delete_device
104862 };
104863
104864 return snd_seq_device_register_driver(SNDRV_SEQ_DEV_ID_OPL4, &ops,
104865 diff --git a/sound/drivers/portman2x4.c b/sound/drivers/portman2x4.c
104866 index 991018d..8984740 100644
104867 --- a/sound/drivers/portman2x4.c
104868 +++ b/sound/drivers/portman2x4.c
104869 @@ -48,6 +48,7 @@
104870 #include <sound/initval.h>
104871 #include <sound/rawmidi.h>
104872 #include <sound/control.h>
104873 +#include <asm/local.h>
104874
104875 #define CARD_NAME "Portman 2x4"
104876 #define DRIVER_NAME "portman"
104877 @@ -85,7 +86,7 @@ struct portman {
104878 struct pardevice *pardev;
104879 int pardev_claimed;
104880
104881 - int open_count;
104882 + local_t open_count;
104883 int mode[PORTMAN_NUM_INPUT_PORTS];
104884 struct snd_rawmidi_substream *midi_input[PORTMAN_NUM_INPUT_PORTS];
104885 };
104886 diff --git a/sound/firewire/amdtp.c b/sound/firewire/amdtp.c
104887 index 9048777..2d8b1fc 100644
104888 --- a/sound/firewire/amdtp.c
104889 +++ b/sound/firewire/amdtp.c
104890 @@ -488,7 +488,7 @@ static void queue_out_packet(struct amdtp_out_stream *s, unsigned int cycle)
104891 ptr = s->pcm_buffer_pointer + data_blocks;
104892 if (ptr >= pcm->runtime->buffer_size)
104893 ptr -= pcm->runtime->buffer_size;
104894 - ACCESS_ONCE(s->pcm_buffer_pointer) = ptr;
104895 + ACCESS_ONCE_RW(s->pcm_buffer_pointer) = ptr;
104896
104897 s->pcm_period_pointer += data_blocks;
104898 if (s->pcm_period_pointer >= pcm->runtime->period_size) {
104899 @@ -655,7 +655,7 @@ EXPORT_SYMBOL(amdtp_out_stream_pcm_pointer);
104900 */
104901 void amdtp_out_stream_update(struct amdtp_out_stream *s)
104902 {
104903 - ACCESS_ONCE(s->source_node_id_field) =
104904 + ACCESS_ONCE_RW(s->source_node_id_field) =
104905 (fw_parent_device(s->unit)->card->node_id & 0x3f) << 24;
104906 }
104907 EXPORT_SYMBOL(amdtp_out_stream_update);
104908 diff --git a/sound/firewire/amdtp.h b/sound/firewire/amdtp.h
104909 index 2746ecd..c35dedd 100644
104910 --- a/sound/firewire/amdtp.h
104911 +++ b/sound/firewire/amdtp.h
104912 @@ -135,7 +135,7 @@ static inline bool amdtp_out_streaming_error(struct amdtp_out_stream *s)
104913 static inline void amdtp_out_stream_pcm_trigger(struct amdtp_out_stream *s,
104914 struct snd_pcm_substream *pcm)
104915 {
104916 - ACCESS_ONCE(s->pcm) = pcm;
104917 + ACCESS_ONCE_RW(s->pcm) = pcm;
104918 }
104919
104920 static inline bool cip_sfc_is_base_44100(enum cip_sfc sfc)
104921 diff --git a/sound/firewire/isight.c b/sound/firewire/isight.c
104922 index fd42e6b..c041971 100644
104923 --- a/sound/firewire/isight.c
104924 +++ b/sound/firewire/isight.c
104925 @@ -96,7 +96,7 @@ static void isight_update_pointers(struct isight *isight, unsigned int count)
104926 ptr += count;
104927 if (ptr >= runtime->buffer_size)
104928 ptr -= runtime->buffer_size;
104929 - ACCESS_ONCE(isight->buffer_pointer) = ptr;
104930 + ACCESS_ONCE_RW(isight->buffer_pointer) = ptr;
104931
104932 isight->period_counter += count;
104933 if (isight->period_counter >= runtime->period_size) {
104934 @@ -299,7 +299,7 @@ static int isight_hw_params(struct snd_pcm_substream *substream,
104935 if (err < 0)
104936 return err;
104937
104938 - ACCESS_ONCE(isight->pcm_active) = true;
104939 + ACCESS_ONCE_RW(isight->pcm_active) = true;
104940
104941 return 0;
104942 }
104943 @@ -337,7 +337,7 @@ static int isight_hw_free(struct snd_pcm_substream *substream)
104944 {
104945 struct isight *isight = substream->private_data;
104946
104947 - ACCESS_ONCE(isight->pcm_active) = false;
104948 + ACCESS_ONCE_RW(isight->pcm_active) = false;
104949
104950 mutex_lock(&isight->mutex);
104951 isight_stop_streaming(isight);
104952 @@ -430,10 +430,10 @@ static int isight_trigger(struct snd_pcm_substream *substream, int cmd)
104953
104954 switch (cmd) {
104955 case SNDRV_PCM_TRIGGER_START:
104956 - ACCESS_ONCE(isight->pcm_running) = true;
104957 + ACCESS_ONCE_RW(isight->pcm_running) = true;
104958 break;
104959 case SNDRV_PCM_TRIGGER_STOP:
104960 - ACCESS_ONCE(isight->pcm_running) = false;
104961 + ACCESS_ONCE_RW(isight->pcm_running) = false;
104962 break;
104963 default:
104964 return -EINVAL;
104965 diff --git a/sound/firewire/scs1x.c b/sound/firewire/scs1x.c
104966 index 858023c..83b3d3c 100644
104967 --- a/sound/firewire/scs1x.c
104968 +++ b/sound/firewire/scs1x.c
104969 @@ -74,7 +74,7 @@ static void scs_output_trigger(struct snd_rawmidi_substream *stream, int up)
104970 {
104971 struct scs *scs = stream->rmidi->private_data;
104972
104973 - ACCESS_ONCE(scs->output) = up ? stream : NULL;
104974 + ACCESS_ONCE_RW(scs->output) = up ? stream : NULL;
104975 if (up) {
104976 scs->output_idle = false;
104977 tasklet_schedule(&scs->tasklet);
104978 @@ -257,7 +257,7 @@ static void scs_input_trigger(struct snd_rawmidi_substream *stream, int up)
104979 {
104980 struct scs *scs = stream->rmidi->private_data;
104981
104982 - ACCESS_ONCE(scs->input) = up ? stream : NULL;
104983 + ACCESS_ONCE_RW(scs->input) = up ? stream : NULL;
104984 }
104985
104986 static void scs_input_escaped_byte(struct snd_rawmidi_substream *stream,
104987 @@ -473,8 +473,8 @@ static void scs_remove(struct fw_unit *unit)
104988
104989 snd_card_disconnect(scs->card);
104990
104991 - ACCESS_ONCE(scs->output) = NULL;
104992 - ACCESS_ONCE(scs->input) = NULL;
104993 + ACCESS_ONCE_RW(scs->output) = NULL;
104994 + ACCESS_ONCE_RW(scs->input) = NULL;
104995
104996 wait_event(scs->idle_wait, scs->output_idle);
104997
104998 diff --git a/sound/isa/sb/emu8000_synth.c b/sound/isa/sb/emu8000_synth.c
104999 index 4e3fcfb..ab45a9d 100644
105000 --- a/sound/isa/sb/emu8000_synth.c
105001 +++ b/sound/isa/sb/emu8000_synth.c
105002 @@ -120,8 +120,8 @@ static int __init alsa_emu8000_init(void)
105003 {
105004
105005 static struct snd_seq_dev_ops ops = {
105006 - snd_emu8000_new_device,
105007 - snd_emu8000_delete_device,
105008 + .init_device = snd_emu8000_new_device,
105009 + .free_device = snd_emu8000_delete_device,
105010 };
105011 return snd_seq_device_register_driver(SNDRV_SEQ_DEV_ID_EMU8000, &ops,
105012 sizeof(struct snd_emu8000*));
105013 diff --git a/sound/oss/sb_audio.c b/sound/oss/sb_audio.c
105014 index 048439a..3be9f6f 100644
105015 --- a/sound/oss/sb_audio.c
105016 +++ b/sound/oss/sb_audio.c
105017 @@ -904,7 +904,7 @@ sb16_copy_from_user(int dev,
105018 buf16 = (signed short *)(localbuf + localoffs);
105019 while (c)
105020 {
105021 - locallen = (c >= LBUFCOPYSIZE ? LBUFCOPYSIZE : c);
105022 + locallen = ((unsigned)c >= LBUFCOPYSIZE ? LBUFCOPYSIZE : c);
105023 if (copy_from_user(lbuf8,
105024 userbuf+useroffs + p,
105025 locallen))
105026 diff --git a/sound/oss/swarm_cs4297a.c b/sound/oss/swarm_cs4297a.c
105027 index 7d8803a..559f8d0 100644
105028 --- a/sound/oss/swarm_cs4297a.c
105029 +++ b/sound/oss/swarm_cs4297a.c
105030 @@ -2621,7 +2621,6 @@ static int __init cs4297a_init(void)
105031 {
105032 struct cs4297a_state *s;
105033 u32 pwr, id;
105034 - mm_segment_t fs;
105035 int rval;
105036 #ifndef CONFIG_BCM_CS4297A_CSWARM
105037 u64 cfg;
105038 @@ -2711,22 +2710,23 @@ static int __init cs4297a_init(void)
105039 if (!rval) {
105040 char *sb1250_duart_present;
105041
105042 +#if 0
105043 + mm_segment_t fs;
105044 fs = get_fs();
105045 set_fs(KERNEL_DS);
105046 -#if 0
105047 val = SOUND_MASK_LINE;
105048 mixer_ioctl(s, SOUND_MIXER_WRITE_RECSRC, (unsigned long) &val);
105049 for (i = 0; i < ARRAY_SIZE(initvol); i++) {
105050 val = initvol[i].vol;
105051 mixer_ioctl(s, initvol[i].mixch, (unsigned long) &val);
105052 }
105053 + set_fs(fs);
105054 // cs4297a_write_ac97(s, 0x18, 0x0808);
105055 #else
105056 // cs4297a_write_ac97(s, 0x5e, 0x180);
105057 cs4297a_write_ac97(s, 0x02, 0x0808);
105058 cs4297a_write_ac97(s, 0x18, 0x0808);
105059 #endif
105060 - set_fs(fs);
105061
105062 list_add(&s->list, &cs4297a_devs);
105063
105064 diff --git a/sound/pci/emu10k1/emu10k1_synth.c b/sound/pci/emu10k1/emu10k1_synth.c
105065 index 4c41c90..37f3631 100644
105066 --- a/sound/pci/emu10k1/emu10k1_synth.c
105067 +++ b/sound/pci/emu10k1/emu10k1_synth.c
105068 @@ -108,8 +108,8 @@ static int __init alsa_emu10k1_synth_init(void)
105069 {
105070
105071 static struct snd_seq_dev_ops ops = {
105072 - snd_emu10k1_synth_new_device,
105073 - snd_emu10k1_synth_delete_device,
105074 + .init_device = snd_emu10k1_synth_new_device,
105075 + .free_device = snd_emu10k1_synth_delete_device,
105076 };
105077 return snd_seq_device_register_driver(SNDRV_SEQ_DEV_ID_EMU10K1_SYNTH, &ops,
105078 sizeof(struct snd_emu10k1_synth_arg));
105079 diff --git a/sound/pci/hda/hda_codec.c b/sound/pci/hda/hda_codec.c
105080 index 69178c4..4493d52 100644
105081 --- a/sound/pci/hda/hda_codec.c
105082 +++ b/sound/pci/hda/hda_codec.c
105083 @@ -976,14 +976,10 @@ find_codec_preset(struct hda_codec *codec)
105084 mutex_unlock(&preset_mutex);
105085
105086 if (mod_requested < HDA_MODREQ_MAX_COUNT) {
105087 - char name[32];
105088 if (!mod_requested)
105089 - snprintf(name, sizeof(name), "snd-hda-codec-id:%08x",
105090 - codec->vendor_id);
105091 + request_module("snd-hda-codec-id:%08x", codec->vendor_id);
105092 else
105093 - snprintf(name, sizeof(name), "snd-hda-codec-id:%04x*",
105094 - (codec->vendor_id >> 16) & 0xffff);
105095 - request_module(name);
105096 + request_module("snd-hda-codec-id:%04x*", (codec->vendor_id >> 16) & 0xffff);
105097 mod_requested++;
105098 goto again;
105099 }
105100 @@ -2668,7 +2664,7 @@ static int get_kctl_0dB_offset(struct snd_kcontrol *kctl, int *step_to_check)
105101 /* FIXME: set_fs() hack for obtaining user-space TLV data */
105102 mm_segment_t fs = get_fs();
105103 set_fs(get_ds());
105104 - if (!kctl->tlv.c(kctl, 0, sizeof(_tlv), _tlv))
105105 + if (!kctl->tlv.c(kctl, 0, sizeof(_tlv), (unsigned int __force_user *)_tlv))
105106 tlv = _tlv;
105107 set_fs(fs);
105108 } else if (kctl->vd[0].access & SNDRV_CTL_ELEM_ACCESS_TLV_READ)
105109 diff --git a/sound/pci/ymfpci/ymfpci.h b/sound/pci/ymfpci/ymfpci.h
105110 index 4631a23..001ae57 100644
105111 --- a/sound/pci/ymfpci/ymfpci.h
105112 +++ b/sound/pci/ymfpci/ymfpci.h
105113 @@ -358,7 +358,7 @@ struct snd_ymfpci {
105114 spinlock_t reg_lock;
105115 spinlock_t voice_lock;
105116 wait_queue_head_t interrupt_sleep;
105117 - atomic_t interrupt_sleep_count;
105118 + atomic_unchecked_t interrupt_sleep_count;
105119 struct snd_info_entry *proc_entry;
105120 const struct firmware *dsp_microcode;
105121 const struct firmware *controller_microcode;
105122 diff --git a/sound/pci/ymfpci/ymfpci_main.c b/sound/pci/ymfpci/ymfpci_main.c
105123 index d591c15..8cb8f94 100644
105124 --- a/sound/pci/ymfpci/ymfpci_main.c
105125 +++ b/sound/pci/ymfpci/ymfpci_main.c
105126 @@ -202,8 +202,8 @@ static void snd_ymfpci_hw_stop(struct snd_ymfpci *chip)
105127 if ((snd_ymfpci_readl(chip, YDSXGR_STATUS) & 2) == 0)
105128 break;
105129 }
105130 - if (atomic_read(&chip->interrupt_sleep_count)) {
105131 - atomic_set(&chip->interrupt_sleep_count, 0);
105132 + if (atomic_read_unchecked(&chip->interrupt_sleep_count)) {
105133 + atomic_set_unchecked(&chip->interrupt_sleep_count, 0);
105134 wake_up(&chip->interrupt_sleep);
105135 }
105136 __end:
105137 @@ -787,7 +787,7 @@ static void snd_ymfpci_irq_wait(struct snd_ymfpci *chip)
105138 continue;
105139 init_waitqueue_entry(&wait, current);
105140 add_wait_queue(&chip->interrupt_sleep, &wait);
105141 - atomic_inc(&chip->interrupt_sleep_count);
105142 + atomic_inc_unchecked(&chip->interrupt_sleep_count);
105143 schedule_timeout_uninterruptible(msecs_to_jiffies(50));
105144 remove_wait_queue(&chip->interrupt_sleep, &wait);
105145 }
105146 @@ -825,8 +825,8 @@ static irqreturn_t snd_ymfpci_interrupt(int irq, void *dev_id)
105147 snd_ymfpci_writel(chip, YDSXGR_MODE, mode);
105148 spin_unlock(&chip->reg_lock);
105149
105150 - if (atomic_read(&chip->interrupt_sleep_count)) {
105151 - atomic_set(&chip->interrupt_sleep_count, 0);
105152 + if (atomic_read_unchecked(&chip->interrupt_sleep_count)) {
105153 + atomic_set_unchecked(&chip->interrupt_sleep_count, 0);
105154 wake_up(&chip->interrupt_sleep);
105155 }
105156 }
105157 @@ -2421,7 +2421,7 @@ int snd_ymfpci_create(struct snd_card *card,
105158 spin_lock_init(&chip->reg_lock);
105159 spin_lock_init(&chip->voice_lock);
105160 init_waitqueue_head(&chip->interrupt_sleep);
105161 - atomic_set(&chip->interrupt_sleep_count, 0);
105162 + atomic_set_unchecked(&chip->interrupt_sleep_count, 0);
105163 chip->card = card;
105164 chip->pci = pci;
105165 chip->irq = -1;
105166 diff --git a/sound/soc/fsl/fsl_ssi.c b/sound/soc/fsl/fsl_ssi.c
105167 index 35e2773..6d6ceee 100644
105168 --- a/sound/soc/fsl/fsl_ssi.c
105169 +++ b/sound/soc/fsl/fsl_ssi.c
105170 @@ -857,7 +857,7 @@ static int fsl_ssi_probe(struct platform_device *pdev)
105171 {
105172 struct fsl_ssi_private *ssi_private;
105173 int ret = 0;
105174 - struct device_attribute *dev_attr = NULL;
105175 + device_attribute_no_const *dev_attr = NULL;
105176 struct device_node *np = pdev->dev.of_node;
105177 const char *p, *sprop;
105178 const uint32_t *iprop;
105179 diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c
105180 index a66783e..ed1d791 100644
105181 --- a/sound/soc/soc-core.c
105182 +++ b/sound/soc/soc-core.c
105183 @@ -2253,8 +2253,10 @@ int snd_soc_set_ac97_ops_of_reset(struct snd_ac97_bus_ops *ops,
105184 if (ret)
105185 return ret;
105186
105187 - ops->warm_reset = snd_soc_ac97_warm_reset;
105188 - ops->reset = snd_soc_ac97_reset;
105189 + pax_open_kernel();
105190 + *(void **)&ops->warm_reset = snd_soc_ac97_warm_reset;
105191 + *(void **)&ops->reset = snd_soc_ac97_reset;
105192 + pax_close_kernel();
105193
105194 snd_ac97_rst_cfg = cfg;
105195 return 0;
105196 diff --git a/sound/synth/emux/emux_seq.c b/sound/synth/emux/emux_seq.c
105197 index 7778b8e..3d619fc 100644
105198 --- a/sound/synth/emux/emux_seq.c
105199 +++ b/sound/synth/emux/emux_seq.c
105200 @@ -33,13 +33,13 @@ static int snd_emux_unuse(void *private_data, struct snd_seq_port_subscribe *inf
105201 * MIDI emulation operators
105202 */
105203 static struct snd_midi_op emux_ops = {
105204 - snd_emux_note_on,
105205 - snd_emux_note_off,
105206 - snd_emux_key_press,
105207 - snd_emux_terminate_note,
105208 - snd_emux_control,
105209 - snd_emux_nrpn,
105210 - snd_emux_sysex,
105211 + .note_on = snd_emux_note_on,
105212 + .note_off = snd_emux_note_off,
105213 + .key_press = snd_emux_key_press,
105214 + .note_terminate = snd_emux_terminate_note,
105215 + .control = snd_emux_control,
105216 + .nrpn = snd_emux_nrpn,
105217 + .sysex = snd_emux_sysex,
105218 };
105219
105220
105221 diff --git a/tools/gcc/.gitignore b/tools/gcc/.gitignore
105222 new file mode 100644
105223 index 0000000..4c2c45c
105224 --- /dev/null
105225 +++ b/tools/gcc/.gitignore
105226 @@ -0,0 +1,2 @@
105227 +randomize_layout_seed.h
105228 +size_overflow_hash.h
105229 diff --git a/tools/gcc/Makefile b/tools/gcc/Makefile
105230 new file mode 100644
105231 index 0000000..d25d472
105232 --- /dev/null
105233 +++ b/tools/gcc/Makefile
105234 @@ -0,0 +1,60 @@
105235 +#CC := gcc
105236 +#PLUGIN_SOURCE_FILES := pax_plugin.c
105237 +#PLUGIN_OBJECT_FILES := $(patsubst %.c,%.o,$(PLUGIN_SOURCE_FILES))
105238 +GCCPLUGINS_DIR := $(shell $(CC) -print-file-name=plugin)
105239 +#CFLAGS += -I$(GCCPLUGINS_DIR)/include -fPIC -O2 -Wall -W -std=gnu99
105240 +
105241 +ifeq ($(PLUGINCC),$(HOSTCC))
105242 +HOSTLIBS := hostlibs
105243 +HOST_EXTRACFLAGS += -I$(GCCPLUGINS_DIR)/include -std=gnu99 -ggdb
105244 +else
105245 +HOSTLIBS := hostcxxlibs
105246 +HOST_EXTRACXXFLAGS += -I$(GCCPLUGINS_DIR)/include -std=gnu++98 -fno-rtti -ggdb -Wno-unused-parameter -Wno-narrowing
105247 +endif
105248 +
105249 +$(HOSTLIBS)-$(CONFIG_PAX_CONSTIFY_PLUGIN) := constify_plugin.so
105250 +$(HOSTLIBS)-$(CONFIG_PAX_MEMORY_STACKLEAK) += stackleak_plugin.so
105251 +$(HOSTLIBS)-$(CONFIG_KALLOCSTAT_PLUGIN) += kallocstat_plugin.so
105252 +$(HOSTLIBS)-$(CONFIG_PAX_KERNEXEC_PLUGIN) += kernexec_plugin.so
105253 +$(HOSTLIBS)-$(CONFIG_CHECKER_PLUGIN) += checker_plugin.so
105254 +$(HOSTLIBS)-y += colorize_plugin.so
105255 +$(HOSTLIBS)-$(CONFIG_PAX_SIZE_OVERFLOW) += size_overflow_plugin.so
105256 +$(HOSTLIBS)-$(CONFIG_PAX_LATENT_ENTROPY) += latent_entropy_plugin.so
105257 +$(HOSTLIBS)-$(CONFIG_PAX_MEMORY_STRUCTLEAK) += structleak_plugin.so
105258 +$(HOSTLIBS)-$(CONFIG_GRKERNSEC_RANDSTRUCT) += randomize_layout_plugin.so
105259 +
105260 +always := $($(HOSTLIBS)-y)
105261 +
105262 +constify_plugin-objs := constify_plugin.o
105263 +stackleak_plugin-objs := stackleak_plugin.o
105264 +kallocstat_plugin-objs := kallocstat_plugin.o
105265 +kernexec_plugin-objs := kernexec_plugin.o
105266 +checker_plugin-objs := checker_plugin.o
105267 +colorize_plugin-objs := colorize_plugin.o
105268 +size_overflow_plugin-objs := size_overflow_plugin.o
105269 +latent_entropy_plugin-objs := latent_entropy_plugin.o
105270 +structleak_plugin-objs := structleak_plugin.o
105271 +randomize_layout_plugin-objs := randomize_layout_plugin.o
105272 +
105273 +$(obj)/size_overflow_plugin.o: $(objtree)/$(obj)/size_overflow_hash.h $(objtree)/$(obj)/size_overflow_hash_aux.h
105274 +$(obj)/randomize_layout_plugin.o: $(objtree)/$(obj)/randomize_layout_seed.h
105275 +
105276 +quiet_cmd_build_size_overflow_hash = GENHASH $@
105277 + cmd_build_size_overflow_hash = \
105278 + $(CONFIG_SHELL) $(srctree)/$(src)/generate_size_overflow_hash.sh -s size_overflow_hash -d $< -o $@
105279 +$(objtree)/$(obj)/size_overflow_hash.h: $(src)/size_overflow_hash.data FORCE
105280 + $(call if_changed,build_size_overflow_hash)
105281 +
105282 +quiet_cmd_build_size_overflow_hash_aux = GENHASH $@
105283 + cmd_build_size_overflow_hash_aux = \
105284 + $(CONFIG_SHELL) $(srctree)/$(src)/generate_size_overflow_hash.sh -s size_overflow_hash_aux -d $< -o $@
105285 +$(objtree)/$(obj)/size_overflow_hash_aux.h: $(src)/size_overflow_hash_aux.data FORCE
105286 + $(call if_changed,build_size_overflow_hash_aux)
105287 +
105288 +quiet_cmd_create_randomize_layout_seed = GENSEED $@
105289 + cmd_create_randomize_layout_seed = \
105290 + $(CONFIG_SHELL) $(srctree)/$(src)/gen-random-seed.sh $@ $(objtree)/include/generated/randomize_layout_hash.h
105291 +$(objtree)/$(obj)/randomize_layout_seed.h: FORCE
105292 + $(call if_changed,create_randomize_layout_seed)
105293 +
105294 +targets += size_overflow_hash.h size_overflow_hash_aux.h randomize_layout_seed.h randomize_layout_hash.h
105295 diff --git a/tools/gcc/checker_plugin.c b/tools/gcc/checker_plugin.c
105296 new file mode 100644
105297 index 0000000..5452feea
105298 --- /dev/null
105299 +++ b/tools/gcc/checker_plugin.c
105300 @@ -0,0 +1,150 @@
105301 +/*
105302 + * Copyright 2011-2014 by the PaX Team <pageexec@freemail.hu>
105303 + * Licensed under the GPL v2
105304 + *
105305 + * Note: the choice of the license means that the compilation process is
105306 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
105307 + * but for the kernel it doesn't matter since it doesn't link against
105308 + * any of the gcc libraries
105309 + *
105310 + * gcc plugin to implement various sparse (source code checker) features
105311 + *
105312 + * TODO:
105313 + * - define separate __iomem, __percpu and __rcu address spaces (lots of code to patch)
105314 + *
105315 + * BUGS:
105316 + * - none known
105317 + */
105318 +
105319 +#include "gcc-common.h"
105320 +
105321 +extern void c_register_addr_space (const char *str, addr_space_t as);
105322 +extern enum machine_mode default_addr_space_pointer_mode (addr_space_t);
105323 +extern enum machine_mode default_addr_space_address_mode (addr_space_t);
105324 +extern bool default_addr_space_valid_pointer_mode(enum machine_mode mode, addr_space_t as);
105325 +extern bool default_addr_space_legitimate_address_p(enum machine_mode mode, rtx mem, bool strict, addr_space_t as);
105326 +extern rtx default_addr_space_legitimize_address(rtx x, rtx oldx, enum machine_mode mode, addr_space_t as);
105327 +
105328 +int plugin_is_GPL_compatible;
105329 +
105330 +static struct plugin_info checker_plugin_info = {
105331 + .version = "201304082245",
105332 + .help = NULL,
105333 +};
105334 +
105335 +#define ADDR_SPACE_KERNEL 0
105336 +#define ADDR_SPACE_FORCE_KERNEL 1
105337 +#define ADDR_SPACE_USER 2
105338 +#define ADDR_SPACE_FORCE_USER 3
105339 +#define ADDR_SPACE_IOMEM 0
105340 +#define ADDR_SPACE_FORCE_IOMEM 0
105341 +#define ADDR_SPACE_PERCPU 0
105342 +#define ADDR_SPACE_FORCE_PERCPU 0
105343 +#define ADDR_SPACE_RCU 0
105344 +#define ADDR_SPACE_FORCE_RCU 0
105345 +
105346 +static enum machine_mode checker_addr_space_pointer_mode(addr_space_t addrspace)
105347 +{
105348 + return default_addr_space_pointer_mode(ADDR_SPACE_GENERIC);
105349 +}
105350 +
105351 +static enum machine_mode checker_addr_space_address_mode(addr_space_t addrspace)
105352 +{
105353 + return default_addr_space_address_mode(ADDR_SPACE_GENERIC);
105354 +}
105355 +
105356 +static bool checker_addr_space_valid_pointer_mode(enum machine_mode mode, addr_space_t as)
105357 +{
105358 + return default_addr_space_valid_pointer_mode(mode, as);
105359 +}
105360 +
105361 +static bool checker_addr_space_legitimate_address_p(enum machine_mode mode, rtx mem, bool strict, addr_space_t as)
105362 +{
105363 + return default_addr_space_legitimate_address_p(mode, mem, strict, ADDR_SPACE_GENERIC);
105364 +}
105365 +
105366 +static rtx checker_addr_space_legitimize_address(rtx x, rtx oldx, enum machine_mode mode, addr_space_t as)
105367 +{
105368 + return default_addr_space_legitimize_address(x, oldx, mode, as);
105369 +}
105370 +
105371 +static bool checker_addr_space_subset_p(addr_space_t subset, addr_space_t superset)
105372 +{
105373 + if (subset == ADDR_SPACE_FORCE_KERNEL && superset == ADDR_SPACE_KERNEL)
105374 + return true;
105375 +
105376 + if (subset == ADDR_SPACE_FORCE_USER && superset == ADDR_SPACE_USER)
105377 + return true;
105378 +
105379 + if (subset == ADDR_SPACE_FORCE_IOMEM && superset == ADDR_SPACE_IOMEM)
105380 + return true;
105381 +
105382 + if (subset == ADDR_SPACE_KERNEL && superset == ADDR_SPACE_FORCE_USER)
105383 + return true;
105384 +
105385 + if (subset == ADDR_SPACE_KERNEL && superset == ADDR_SPACE_FORCE_IOMEM)
105386 + return true;
105387 +
105388 + if (subset == ADDR_SPACE_USER && superset == ADDR_SPACE_FORCE_KERNEL)
105389 + return true;
105390 +
105391 + if (subset == ADDR_SPACE_IOMEM && superset == ADDR_SPACE_FORCE_KERNEL)
105392 + return true;
105393 +
105394 + return subset == superset;
105395 +}
105396 +
105397 +static rtx checker_addr_space_convert(rtx op, tree from_type, tree to_type)
105398 +{
105399 +// addr_space_t from_as = TYPE_ADDR_SPACE(TREE_TYPE(from_type));
105400 +// addr_space_t to_as = TYPE_ADDR_SPACE(TREE_TYPE(to_type));
105401 +
105402 + return op;
105403 +}
105404 +
105405 +static void register_checker_address_spaces(void *event_data, void *data)
105406 +{
105407 + c_register_addr_space("__kernel", ADDR_SPACE_KERNEL);
105408 + c_register_addr_space("__force_kernel", ADDR_SPACE_FORCE_KERNEL);
105409 + c_register_addr_space("__user", ADDR_SPACE_USER);
105410 + c_register_addr_space("__force_user", ADDR_SPACE_FORCE_USER);
105411 +// c_register_addr_space("__iomem", ADDR_SPACE_IOMEM);
105412 +// c_register_addr_space("__force_iomem", ADDR_SPACE_FORCE_IOMEM);
105413 +// c_register_addr_space("__percpu", ADDR_SPACE_PERCPU);
105414 +// c_register_addr_space("__force_percpu", ADDR_SPACE_FORCE_PERCPU);
105415 +// c_register_addr_space("__rcu", ADDR_SPACE_RCU);
105416 +// c_register_addr_space("__force_rcu", ADDR_SPACE_FORCE_RCU);
105417 +
105418 + targetm.addr_space.pointer_mode = checker_addr_space_pointer_mode;
105419 + targetm.addr_space.address_mode = checker_addr_space_address_mode;
105420 + targetm.addr_space.valid_pointer_mode = checker_addr_space_valid_pointer_mode;
105421 + targetm.addr_space.legitimate_address_p = checker_addr_space_legitimate_address_p;
105422 +// targetm.addr_space.legitimize_address = checker_addr_space_legitimize_address;
105423 + targetm.addr_space.subset_p = checker_addr_space_subset_p;
105424 + targetm.addr_space.convert = checker_addr_space_convert;
105425 +}
105426 +
105427 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
105428 +{
105429 + const char * const plugin_name = plugin_info->base_name;
105430 + const int argc = plugin_info->argc;
105431 + const struct plugin_argument * const argv = plugin_info->argv;
105432 + int i;
105433 +
105434 + if (!plugin_default_version_check(version, &gcc_version)) {
105435 + error(G_("incompatible gcc/plugin versions"));
105436 + return 1;
105437 + }
105438 +
105439 + register_callback(plugin_name, PLUGIN_INFO, NULL, &checker_plugin_info);
105440 +
105441 + for (i = 0; i < argc; ++i)
105442 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
105443 +
105444 + if (TARGET_64BIT == 0)
105445 + return 0;
105446 +
105447 + register_callback(plugin_name, PLUGIN_PRAGMAS, register_checker_address_spaces, NULL);
105448 +
105449 + return 0;
105450 +}
105451 diff --git a/tools/gcc/colorize_plugin.c b/tools/gcc/colorize_plugin.c
105452 new file mode 100644
105453 index 0000000..06dcfda
105454 --- /dev/null
105455 +++ b/tools/gcc/colorize_plugin.c
105456 @@ -0,0 +1,169 @@
105457 +/*
105458 + * Copyright 2012-2014 by PaX Team <pageexec@freemail.hu>
105459 + * Licensed under the GPL v2
105460 + *
105461 + * Note: the choice of the license means that the compilation process is
105462 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
105463 + * but for the kernel it doesn't matter since it doesn't link against
105464 + * any of the gcc libraries
105465 + *
105466 + * gcc plugin to colorize diagnostic output
105467 + *
105468 + */
105469 +
105470 +#include "gcc-common.h"
105471 +
105472 +int plugin_is_GPL_compatible;
105473 +
105474 +static struct plugin_info colorize_plugin_info = {
105475 + .version = "201401260140",
105476 + .help = NULL,
105477 +};
105478 +
105479 +#define GREEN "\033[32m\033[2m"
105480 +#define LIGHTGREEN "\033[32m\033[1m"
105481 +#define YELLOW "\033[33m\033[2m"
105482 +#define LIGHTYELLOW "\033[33m\033[1m"
105483 +#define RED "\033[31m\033[2m"
105484 +#define LIGHTRED "\033[31m\033[1m"
105485 +#define BLUE "\033[34m\033[2m"
105486 +#define LIGHTBLUE "\033[34m\033[1m"
105487 +#define BRIGHT "\033[m\033[1m"
105488 +#define NORMAL "\033[m"
105489 +
105490 +static diagnostic_starter_fn old_starter;
105491 +static diagnostic_finalizer_fn old_finalizer;
105492 +
105493 +static void start_colorize(diagnostic_context *context, diagnostic_info *diagnostic)
105494 +{
105495 + const char *color;
105496 + char *newprefix;
105497 +
105498 + switch (diagnostic->kind) {
105499 + case DK_NOTE:
105500 + color = LIGHTBLUE;
105501 + break;
105502 +
105503 + case DK_PEDWARN:
105504 + case DK_WARNING:
105505 + color = LIGHTYELLOW;
105506 + break;
105507 +
105508 + case DK_ERROR:
105509 + case DK_FATAL:
105510 + case DK_ICE:
105511 + case DK_PERMERROR:
105512 + case DK_SORRY:
105513 + color = LIGHTRED;
105514 + break;
105515 +
105516 + default:
105517 + color = NORMAL;
105518 + }
105519 +
105520 + old_starter(context, diagnostic);
105521 + if (-1 == asprintf(&newprefix, "%s%s" NORMAL, color, context->printer->prefix))
105522 + return;
105523 + pp_destroy_prefix(context->printer);
105524 + pp_set_prefix(context->printer, newprefix);
105525 +}
105526 +
105527 +static void finalize_colorize(diagnostic_context *context, diagnostic_info *diagnostic)
105528 +{
105529 + old_finalizer(context, diagnostic);
105530 +}
105531 +
105532 +static void colorize_arm(void)
105533 +{
105534 + old_starter = diagnostic_starter(global_dc);
105535 + old_finalizer = diagnostic_finalizer(global_dc);
105536 +
105537 + diagnostic_starter(global_dc) = start_colorize;
105538 + diagnostic_finalizer(global_dc) = finalize_colorize;
105539 +}
105540 +
105541 +static unsigned int execute_colorize_rearm(void)
105542 +{
105543 + if (diagnostic_starter(global_dc) == start_colorize)
105544 + return 0;
105545 +
105546 + colorize_arm();
105547 + return 0;
105548 +}
105549 +
105550 +#if BUILDING_GCC_VERSION >= 4009
105551 +static const struct pass_data colorize_rearm_pass_data = {
105552 +#else
105553 +struct simple_ipa_opt_pass colorize_rearm_pass = {
105554 + .pass = {
105555 +#endif
105556 + .type = SIMPLE_IPA_PASS,
105557 + .name = "colorize_rearm",
105558 +#if BUILDING_GCC_VERSION >= 4008
105559 + .optinfo_flags = OPTGROUP_NONE,
105560 +#endif
105561 +#if BUILDING_GCC_VERSION >= 4009
105562 + .has_gate = false,
105563 + .has_execute = true,
105564 +#else
105565 + .gate = NULL,
105566 + .execute = execute_colorize_rearm,
105567 + .sub = NULL,
105568 + .next = NULL,
105569 + .static_pass_number = 0,
105570 +#endif
105571 + .tv_id = TV_NONE,
105572 + .properties_required = 0,
105573 + .properties_provided = 0,
105574 + .properties_destroyed = 0,
105575 + .todo_flags_start = 0,
105576 + .todo_flags_finish = 0
105577 +#if BUILDING_GCC_VERSION < 4009
105578 + }
105579 +#endif
105580 +};
105581 +
105582 +#if BUILDING_GCC_VERSION >= 4009
105583 +namespace {
105584 +class colorize_rearm_pass : public simple_ipa_opt_pass {
105585 +public:
105586 + colorize_rearm_pass() : simple_ipa_opt_pass(colorize_rearm_pass_data, g) {}
105587 + unsigned int execute() { return execute_colorize_rearm(); }
105588 +};
105589 +}
105590 +#endif
105591 +
105592 +static struct opt_pass *make_colorize_rearm_pass(void)
105593 +{
105594 +#if BUILDING_GCC_VERSION >= 4009
105595 + return new colorize_rearm_pass();
105596 +#else
105597 + return &colorize_rearm_pass.pass;
105598 +#endif
105599 +}
105600 +
105601 +static void colorize_start_unit(void *gcc_data, void *user_data)
105602 +{
105603 + colorize_arm();
105604 +}
105605 +
105606 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
105607 +{
105608 + const char * const plugin_name = plugin_info->base_name;
105609 + struct register_pass_info colorize_rearm_pass_info;
105610 +
105611 + colorize_rearm_pass_info.pass = make_colorize_rearm_pass();
105612 + colorize_rearm_pass_info.reference_pass_name = "*free_lang_data";
105613 + colorize_rearm_pass_info.ref_pass_instance_number = 1;
105614 + colorize_rearm_pass_info.pos_op = PASS_POS_INSERT_AFTER;
105615 +
105616 + if (!plugin_default_version_check(version, &gcc_version)) {
105617 + error(G_("incompatible gcc/plugin versions"));
105618 + return 1;
105619 + }
105620 +
105621 + register_callback(plugin_name, PLUGIN_INFO, NULL, &colorize_plugin_info);
105622 + register_callback(plugin_name, PLUGIN_START_UNIT, &colorize_start_unit, NULL);
105623 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &colorize_rearm_pass_info);
105624 + return 0;
105625 +}
105626 diff --git a/tools/gcc/constify_plugin.c b/tools/gcc/constify_plugin.c
105627 new file mode 100644
105628 index 0000000..4f67ac1
105629 --- /dev/null
105630 +++ b/tools/gcc/constify_plugin.c
105631 @@ -0,0 +1,552 @@
105632 +/*
105633 + * Copyright 2011 by Emese Revfy <re.emese@gmail.com>
105634 + * Copyright 2011-2014 by PaX Team <pageexec@freemail.hu>
105635 + * Licensed under the GPL v2, or (at your option) v3
105636 + *
105637 + * This gcc plugin constifies all structures which contain only function pointers or are explicitly marked for constification.
105638 + *
105639 + * Homepage:
105640 + * http://www.grsecurity.net/~ephox/const_plugin/
105641 + *
105642 + * Usage:
105643 + * $ gcc -I`gcc -print-file-name=plugin`/include -fPIC -shared -O2 -o constify_plugin.so constify_plugin.c
105644 + * $ gcc -fplugin=constify_plugin.so test.c -O2
105645 + */
105646 +
105647 +#include "gcc-common.h"
105648 +
105649 +// unused C type flag in all versions 4.5-4.9
105650 +#define TYPE_CONSTIFY_VISITED(TYPE) TYPE_LANG_FLAG_4(TYPE)
105651 +
105652 +int plugin_is_GPL_compatible;
105653 +
105654 +static struct plugin_info const_plugin_info = {
105655 + .version = "201401270210",
105656 + .help = "no-constify\tturn off constification\n",
105657 +};
105658 +
105659 +typedef struct {
105660 + bool has_fptr_field;
105661 + bool has_writable_field;
105662 + bool has_do_const_field;
105663 + bool has_no_const_field;
105664 +} constify_info;
105665 +
105666 +static const_tree get_field_type(const_tree field)
105667 +{
105668 + return strip_array_types(TREE_TYPE(field));
105669 +}
105670 +
105671 +static bool is_fptr(const_tree field)
105672 +{
105673 + const_tree ptr = get_field_type(field);
105674 +
105675 + if (TREE_CODE(ptr) != POINTER_TYPE)
105676 + return false;
105677 +
105678 + return TREE_CODE(TREE_TYPE(ptr)) == FUNCTION_TYPE;
105679 +}
105680 +
105681 +/*
105682 + * determine whether the given structure type meets the requirements for automatic constification,
105683 + * including the constification attributes on nested structure types
105684 + */
105685 +static void constifiable(const_tree node, constify_info *cinfo)
105686 +{
105687 + const_tree field;
105688 +
105689 + gcc_assert(TREE_CODE(node) == RECORD_TYPE || TREE_CODE(node) == UNION_TYPE);
105690 +
105691 + // e.g., pointer to structure fields while still constructing the structure type
105692 + if (TYPE_FIELDS(node) == NULL_TREE)
105693 + return;
105694 +
105695 + for (field = TYPE_FIELDS(node); field; field = TREE_CHAIN(field)) {
105696 + const_tree type = get_field_type(field);
105697 + enum tree_code code = TREE_CODE(type);
105698 +
105699 + if (node == type)
105700 + continue;
105701 +
105702 + if (is_fptr(field))
105703 + cinfo->has_fptr_field = true;
105704 + else if (!TREE_READONLY(field))
105705 + cinfo->has_writable_field = true;
105706 +
105707 + if (code == RECORD_TYPE || code == UNION_TYPE) {
105708 + if (lookup_attribute("do_const", TYPE_ATTRIBUTES(type)))
105709 + cinfo->has_do_const_field = true;
105710 + else if (lookup_attribute("no_const", TYPE_ATTRIBUTES(type)))
105711 + cinfo->has_no_const_field = true;
105712 + else
105713 + constifiable(type, cinfo);
105714 + }
105715 + }
105716 +}
105717 +
105718 +static bool constified(const_tree node)
105719 +{
105720 + constify_info cinfo = {
105721 + .has_fptr_field = false,
105722 + .has_writable_field = false,
105723 + .has_do_const_field = false,
105724 + .has_no_const_field = false
105725 + };
105726 +
105727 + gcc_assert(TREE_CODE(node) == RECORD_TYPE || TREE_CODE(node) == UNION_TYPE);
105728 +
105729 + if (lookup_attribute("no_const", TYPE_ATTRIBUTES(node))) {
105730 +// gcc_assert(!TYPE_READONLY(node));
105731 + return false;
105732 + }
105733 +
105734 + if (lookup_attribute("do_const", TYPE_ATTRIBUTES(node))) {
105735 + gcc_assert(TYPE_READONLY(node));
105736 + return true;
105737 + }
105738 +
105739 + constifiable(node, &cinfo);
105740 + if ((!cinfo.has_fptr_field || cinfo.has_writable_field) && !cinfo.has_do_const_field)
105741 + return false;
105742 +
105743 + return TYPE_READONLY(node);
105744 +}
105745 +
105746 +static void deconstify_tree(tree node);
105747 +
105748 +static void deconstify_type(tree type)
105749 +{
105750 + tree field;
105751 +
105752 + gcc_assert(TREE_CODE(type) == RECORD_TYPE || TREE_CODE(type) == UNION_TYPE);
105753 +
105754 + for (field = TYPE_FIELDS(type); field; field = TREE_CHAIN(field)) {
105755 + const_tree fieldtype = get_field_type(field);
105756 +
105757 + // special case handling of simple ptr-to-same-array-type members
105758 + if (TREE_CODE(TREE_TYPE(field)) == POINTER_TYPE) {
105759 + tree ptrtype = TREE_TYPE(TREE_TYPE(field));
105760 +
105761 + if (TREE_TYPE(TREE_TYPE(field)) == type)
105762 + continue;
105763 + if (TREE_CODE(ptrtype) != RECORD_TYPE && TREE_CODE(ptrtype) != UNION_TYPE)
105764 + continue;
105765 + if (!constified(ptrtype))
105766 + continue;
105767 + if (TYPE_MAIN_VARIANT(ptrtype) == TYPE_MAIN_VARIANT(type)) {
105768 + TREE_TYPE(field) = copy_node(TREE_TYPE(field));
105769 + TREE_TYPE(TREE_TYPE(field)) = build_qualified_type(type, TYPE_QUALS(ptrtype) & ~TYPE_QUAL_CONST);
105770 + }
105771 + continue;
105772 + }
105773 + if (TREE_CODE(fieldtype) != RECORD_TYPE && TREE_CODE(fieldtype) != UNION_TYPE)
105774 + continue;
105775 + if (!constified(fieldtype))
105776 + continue;
105777 +
105778 + deconstify_tree(field);
105779 + TREE_READONLY(field) = 0;
105780 + }
105781 + TYPE_READONLY(type) = 0;
105782 + C_TYPE_FIELDS_READONLY(type) = 0;
105783 + if (lookup_attribute("do_const", TYPE_ATTRIBUTES(type))) {
105784 + TYPE_ATTRIBUTES(type) = copy_list(TYPE_ATTRIBUTES(type));
105785 + TYPE_ATTRIBUTES(type) = remove_attribute("do_const", TYPE_ATTRIBUTES(type));
105786 + }
105787 +}
105788 +
105789 +static void deconstify_tree(tree node)
105790 +{
105791 + tree old_type, new_type, field;
105792 +
105793 + old_type = TREE_TYPE(node);
105794 + while (TREE_CODE(old_type) == ARRAY_TYPE && TREE_CODE(TREE_TYPE(old_type)) != ARRAY_TYPE) {
105795 + node = TREE_TYPE(node) = copy_node(old_type);
105796 + old_type = TREE_TYPE(old_type);
105797 + }
105798 +
105799 + gcc_assert(TREE_CODE(old_type) == RECORD_TYPE || TREE_CODE(old_type) == UNION_TYPE);
105800 + gcc_assert(TYPE_READONLY(old_type) && (TYPE_QUALS(old_type) & TYPE_QUAL_CONST));
105801 +
105802 + new_type = build_qualified_type(old_type, TYPE_QUALS(old_type) & ~TYPE_QUAL_CONST);
105803 + TYPE_FIELDS(new_type) = copy_list(TYPE_FIELDS(new_type));
105804 + for (field = TYPE_FIELDS(new_type); field; field = TREE_CHAIN(field))
105805 + DECL_FIELD_CONTEXT(field) = new_type;
105806 +
105807 + deconstify_type(new_type);
105808 +
105809 + TREE_TYPE(node) = new_type;
105810 +}
105811 +
105812 +static tree handle_no_const_attribute(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
105813 +{
105814 + tree type;
105815 + constify_info cinfo = {
105816 + .has_fptr_field = false,
105817 + .has_writable_field = false,
105818 + .has_do_const_field = false,
105819 + .has_no_const_field = false
105820 + };
105821 +
105822 + *no_add_attrs = true;
105823 + if (TREE_CODE(*node) == FUNCTION_DECL) {
105824 + error("%qE attribute does not apply to functions (%qF)", name, *node);
105825 + return NULL_TREE;
105826 + }
105827 +
105828 + if (TREE_CODE(*node) == PARM_DECL) {
105829 + error("%qE attribute does not apply to function parameters (%qD)", name, *node);
105830 + return NULL_TREE;
105831 + }
105832 +
105833 + if (TREE_CODE(*node) == VAR_DECL) {
105834 + error("%qE attribute does not apply to variables (%qD)", name, *node);
105835 + return NULL_TREE;
105836 + }
105837 +
105838 + if (TYPE_P(*node)) {
105839 + type = *node;
105840 + } else {
105841 + gcc_assert(TREE_CODE(*node) == TYPE_DECL);
105842 + type = TREE_TYPE(*node);
105843 + }
105844 +
105845 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE) {
105846 + error("%qE attribute used on %qT applies to struct and union types only", name, type);
105847 + return NULL_TREE;
105848 + }
105849 +
105850 + if (lookup_attribute(IDENTIFIER_POINTER(name), TYPE_ATTRIBUTES(type))) {
105851 + error("%qE attribute is already applied to the type %qT", name, type);
105852 + return NULL_TREE;
105853 + }
105854 +
105855 + if (TYPE_P(*node)) {
105856 + if (lookup_attribute("do_const", TYPE_ATTRIBUTES(type)))
105857 + error("%qE attribute used on type %qT is incompatible with 'do_const'", name, type);
105858 + else
105859 + *no_add_attrs = false;
105860 + return NULL_TREE;
105861 + }
105862 +
105863 + constifiable(type, &cinfo);
105864 + if ((cinfo.has_fptr_field && !cinfo.has_writable_field) || lookup_attribute("do_const", TYPE_ATTRIBUTES(type))) {
105865 + deconstify_tree(*node);
105866 + TYPE_CONSTIFY_VISITED(TREE_TYPE(*node)) = 1;
105867 + return NULL_TREE;
105868 + }
105869 +
105870 + error("%qE attribute used on type %qT that is not constified", name, type);
105871 + return NULL_TREE;
105872 +}
105873 +
105874 +static void constify_type(tree type)
105875 +{
105876 + TYPE_READONLY(type) = 1;
105877 + C_TYPE_FIELDS_READONLY(type) = 1;
105878 + TYPE_CONSTIFY_VISITED(type) = 1;
105879 +// TYPE_ATTRIBUTES(type) = copy_list(TYPE_ATTRIBUTES(type));
105880 +// TYPE_ATTRIBUTES(type) = tree_cons(get_identifier("do_const"), NULL_TREE, TYPE_ATTRIBUTES(type));
105881 +}
105882 +
105883 +static tree handle_do_const_attribute(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
105884 +{
105885 + *no_add_attrs = true;
105886 + if (!TYPE_P(*node)) {
105887 + error("%qE attribute applies to types only (%qD)", name, *node);
105888 + return NULL_TREE;
105889 + }
105890 +
105891 + if (TREE_CODE(*node) != RECORD_TYPE && TREE_CODE(*node) != UNION_TYPE) {
105892 + error("%qE attribute used on %qT applies to struct and union types only", name, *node);
105893 + return NULL_TREE;
105894 + }
105895 +
105896 + if (lookup_attribute(IDENTIFIER_POINTER(name), TYPE_ATTRIBUTES(*node))) {
105897 + error("%qE attribute used on %qT is already applied to the type", name, *node);
105898 + return NULL_TREE;
105899 + }
105900 +
105901 + if (lookup_attribute("no_const", TYPE_ATTRIBUTES(*node))) {
105902 + error("%qE attribute used on %qT is incompatible with 'no_const'", name, *node);
105903 + return NULL_TREE;
105904 + }
105905 +
105906 + *no_add_attrs = false;
105907 + return NULL_TREE;
105908 +}
105909 +
105910 +static struct attribute_spec no_const_attr = {
105911 + .name = "no_const",
105912 + .min_length = 0,
105913 + .max_length = 0,
105914 + .decl_required = false,
105915 + .type_required = false,
105916 + .function_type_required = false,
105917 + .handler = handle_no_const_attribute,
105918 +#if BUILDING_GCC_VERSION >= 4007
105919 + .affects_type_identity = true
105920 +#endif
105921 +};
105922 +
105923 +static struct attribute_spec do_const_attr = {
105924 + .name = "do_const",
105925 + .min_length = 0,
105926 + .max_length = 0,
105927 + .decl_required = false,
105928 + .type_required = false,
105929 + .function_type_required = false,
105930 + .handler = handle_do_const_attribute,
105931 +#if BUILDING_GCC_VERSION >= 4007
105932 + .affects_type_identity = true
105933 +#endif
105934 +};
105935 +
105936 +static void register_attributes(void *event_data, void *data)
105937 +{
105938 + register_attribute(&no_const_attr);
105939 + register_attribute(&do_const_attr);
105940 +}
105941 +
105942 +static void finish_type(void *event_data, void *data)
105943 +{
105944 + tree type = (tree)event_data;
105945 + constify_info cinfo = {
105946 + .has_fptr_field = false,
105947 + .has_writable_field = false,
105948 + .has_do_const_field = false,
105949 + .has_no_const_field = false
105950 + };
105951 +
105952 + if (type == NULL_TREE || type == error_mark_node)
105953 + return;
105954 +
105955 + if (TYPE_FIELDS(type) == NULL_TREE || TYPE_CONSTIFY_VISITED(type))
105956 + return;
105957 +
105958 + constifiable(type, &cinfo);
105959 +
105960 + if (lookup_attribute("no_const", TYPE_ATTRIBUTES(type))) {
105961 + if ((cinfo.has_fptr_field && !cinfo.has_writable_field) || cinfo.has_do_const_field) {
105962 + deconstify_type(type);
105963 + TYPE_CONSTIFY_VISITED(type) = 1;
105964 + } else
105965 + error("'no_const' attribute used on type %qT that is not constified", type);
105966 + return;
105967 + }
105968 +
105969 + if (lookup_attribute("do_const", TYPE_ATTRIBUTES(type))) {
105970 + if (!cinfo.has_writable_field) {
105971 + error("'do_const' attribute used on type %qT that is%sconstified", type, cinfo.has_fptr_field ? " " : " not ");
105972 + return;
105973 + }
105974 + constify_type(type);
105975 + return;
105976 + }
105977 +
105978 + if (cinfo.has_fptr_field && !cinfo.has_writable_field) {
105979 + if (lookup_attribute("do_const", TYPE_ATTRIBUTES(type))) {
105980 + error("'do_const' attribute used on type %qT that is constified", type);
105981 + return;
105982 + }
105983 + constify_type(type);
105984 + return;
105985 + }
105986 +
105987 + deconstify_type(type);
105988 + TYPE_CONSTIFY_VISITED(type) = 1;
105989 +}
105990 +
105991 +static void check_global_variables(void *event_data, void *data)
105992 +{
105993 + struct varpool_node *node;
105994 +
105995 + FOR_EACH_VARIABLE(node) {
105996 + tree var = NODE_DECL(node);
105997 + tree type = TREE_TYPE(var);
105998 +
105999 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE)
106000 + continue;
106001 +
106002 + if (!TYPE_READONLY(type) || !C_TYPE_FIELDS_READONLY(type))
106003 + continue;
106004 +
106005 + if (!TYPE_CONSTIFY_VISITED(type))
106006 + continue;
106007 +
106008 + if (DECL_EXTERNAL(var))
106009 + continue;
106010 +
106011 + if (DECL_INITIAL(var))
106012 + continue;
106013 +
106014 + // this works around a gcc bug/feature where uninitialized globals
106015 + // are moved into the .bss section regardless of any constification
106016 + DECL_INITIAL(var) = build_constructor(type, NULL);
106017 +// inform(DECL_SOURCE_LOCATION(var), "constified variable %qE moved into .rodata", var);
106018 + }
106019 +}
106020 +
106021 +static unsigned int check_local_variables(void)
106022 +{
106023 + unsigned int ret = 0;
106024 + tree var;
106025 +
106026 + unsigned int i;
106027 +
106028 + FOR_EACH_LOCAL_DECL(cfun, i, var) {
106029 + tree type = TREE_TYPE(var);
106030 +
106031 + gcc_assert(DECL_P(var));
106032 + if (is_global_var(var))
106033 + continue;
106034 +
106035 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE)
106036 + continue;
106037 +
106038 + if (!TYPE_READONLY(type) || !C_TYPE_FIELDS_READONLY(type))
106039 + continue;
106040 +
106041 + if (!TYPE_CONSTIFY_VISITED(type))
106042 + continue;
106043 +
106044 + error_at(DECL_SOURCE_LOCATION(var), "constified variable %qE cannot be local", var);
106045 + ret = 1;
106046 + }
106047 + return ret;
106048 +}
106049 +
106050 +#if BUILDING_GCC_VERSION >= 4009
106051 +static const struct pass_data check_local_variables_pass_data = {
106052 +#else
106053 +static struct gimple_opt_pass check_local_variables_pass = {
106054 + .pass = {
106055 +#endif
106056 + .type = GIMPLE_PASS,
106057 + .name = "check_local_variables",
106058 +#if BUILDING_GCC_VERSION >= 4008
106059 + .optinfo_flags = OPTGROUP_NONE,
106060 +#endif
106061 +#if BUILDING_GCC_VERSION >= 4009
106062 + .has_gate = false,
106063 + .has_execute = true,
106064 +#else
106065 + .gate = NULL,
106066 + .execute = check_local_variables,
106067 + .sub = NULL,
106068 + .next = NULL,
106069 + .static_pass_number = 0,
106070 +#endif
106071 + .tv_id = TV_NONE,
106072 + .properties_required = 0,
106073 + .properties_provided = 0,
106074 + .properties_destroyed = 0,
106075 + .todo_flags_start = 0,
106076 + .todo_flags_finish = 0
106077 +#if BUILDING_GCC_VERSION < 4009
106078 + }
106079 +#endif
106080 +};
106081 +
106082 +#if BUILDING_GCC_VERSION >= 4009
106083 +namespace {
106084 +class check_local_variables_pass : public gimple_opt_pass {
106085 +public:
106086 + check_local_variables_pass() : gimple_opt_pass(check_local_variables_pass_data, g) {}
106087 + unsigned int execute() { return check_local_variables(); }
106088 +};
106089 +}
106090 +#endif
106091 +
106092 +static struct opt_pass *make_check_local_variables_pass(void)
106093 +{
106094 +#if BUILDING_GCC_VERSION >= 4009
106095 + return new check_local_variables_pass();
106096 +#else
106097 + return &check_local_variables_pass.pass;
106098 +#endif
106099 +}
106100 +
106101 +static struct {
106102 + const char *name;
106103 + const char *asm_op;
106104 +} sections[] = {
106105 + {".init.rodata", "\t.section\t.init.rodata,\"a\""},
106106 + {".ref.rodata", "\t.section\t.ref.rodata,\"a\""},
106107 + {".devinit.rodata", "\t.section\t.devinit.rodata,\"a\""},
106108 + {".devexit.rodata", "\t.section\t.devexit.rodata,\"a\""},
106109 + {".cpuinit.rodata", "\t.section\t.cpuinit.rodata,\"a\""},
106110 + {".cpuexit.rodata", "\t.section\t.cpuexit.rodata,\"a\""},
106111 + {".meminit.rodata", "\t.section\t.meminit.rodata,\"a\""},
106112 + {".memexit.rodata", "\t.section\t.memexit.rodata,\"a\""},
106113 + {".data..read_only", "\t.section\t.data..read_only,\"a\""},
106114 +};
106115 +
106116 +static unsigned int (*old_section_type_flags)(tree decl, const char *name, int reloc);
106117 +
106118 +static unsigned int constify_section_type_flags(tree decl, const char *name, int reloc)
106119 +{
106120 + size_t i;
106121 +
106122 + for (i = 0; i < ARRAY_SIZE(sections); i++)
106123 + if (!strcmp(sections[i].name, name))
106124 + return 0;
106125 + return old_section_type_flags(decl, name, reloc);
106126 +}
106127 +
106128 +static void constify_start_unit(void *gcc_data, void *user_data)
106129 +{
106130 +// size_t i;
106131 +
106132 +// for (i = 0; i < ARRAY_SIZE(sections); i++)
106133 +// sections[i].section = get_unnamed_section(0, output_section_asm_op, sections[i].asm_op);
106134 +// sections[i].section = get_section(sections[i].name, 0, NULL);
106135 +
106136 + old_section_type_flags = targetm.section_type_flags;
106137 + targetm.section_type_flags = constify_section_type_flags;
106138 +}
106139 +
106140 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
106141 +{
106142 + const char * const plugin_name = plugin_info->base_name;
106143 + const int argc = plugin_info->argc;
106144 + const struct plugin_argument * const argv = plugin_info->argv;
106145 + int i;
106146 + bool constify = true;
106147 +
106148 + struct register_pass_info check_local_variables_pass_info;
106149 +
106150 + check_local_variables_pass_info.pass = make_check_local_variables_pass();
106151 + check_local_variables_pass_info.reference_pass_name = "ssa";
106152 + check_local_variables_pass_info.ref_pass_instance_number = 1;
106153 + check_local_variables_pass_info.pos_op = PASS_POS_INSERT_BEFORE;
106154 +
106155 + if (!plugin_default_version_check(version, &gcc_version)) {
106156 + error(G_("incompatible gcc/plugin versions"));
106157 + return 1;
106158 + }
106159 +
106160 + for (i = 0; i < argc; ++i) {
106161 + if (!(strcmp(argv[i].key, "no-constify"))) {
106162 + constify = false;
106163 + continue;
106164 + }
106165 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
106166 + }
106167 +
106168 + if (strcmp(lang_hooks.name, "GNU C")) {
106169 + inform(UNKNOWN_LOCATION, G_("%s supports C only"), plugin_name);
106170 + constify = false;
106171 + }
106172 +
106173 + register_callback(plugin_name, PLUGIN_INFO, NULL, &const_plugin_info);
106174 + if (constify) {
106175 + register_callback(plugin_name, PLUGIN_ALL_IPA_PASSES_START, check_global_variables, NULL);
106176 + register_callback(plugin_name, PLUGIN_FINISH_TYPE, finish_type, NULL);
106177 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &check_local_variables_pass_info);
106178 + register_callback(plugin_name, PLUGIN_START_UNIT, constify_start_unit, NULL);
106179 + }
106180 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
106181 +
106182 + return 0;
106183 +}
106184 diff --git a/tools/gcc/gcc-common.h b/tools/gcc/gcc-common.h
106185 new file mode 100644
106186 index 0000000..8af3693
106187 --- /dev/null
106188 +++ b/tools/gcc/gcc-common.h
106189 @@ -0,0 +1,287 @@
106190 +#ifndef GCC_COMMON_H_INCLUDED
106191 +#define GCC_COMMON_H_INCLUDED
106192 +
106193 +#include "plugin.h"
106194 +#include "bversion.h"
106195 +#include "plugin-version.h"
106196 +#include "config.h"
106197 +#include "system.h"
106198 +#include "coretypes.h"
106199 +#include "tm.h"
106200 +#include "line-map.h"
106201 +#include "input.h"
106202 +#include "tree.h"
106203 +
106204 +#include "tree-inline.h"
106205 +#include "version.h"
106206 +#include "rtl.h"
106207 +#include "tm_p.h"
106208 +#include "flags.h"
106209 +//#include "insn-attr.h"
106210 +//#include "insn-config.h"
106211 +//#include "insn-flags.h"
106212 +#include "hard-reg-set.h"
106213 +//#include "recog.h"
106214 +#include "output.h"
106215 +#include "except.h"
106216 +#include "function.h"
106217 +#include "toplev.h"
106218 +//#include "expr.h"
106219 +#include "basic-block.h"
106220 +#include "intl.h"
106221 +#include "ggc.h"
106222 +//#include "regs.h"
106223 +#include "timevar.h"
106224 +
106225 +#include "params.h"
106226 +#include "pointer-set.h"
106227 +#include "emit-rtl.h"
106228 +//#include "reload.h"
106229 +//#include "ira.h"
106230 +//#include "dwarf2asm.h"
106231 +#include "debug.h"
106232 +#include "target.h"
106233 +#include "langhooks.h"
106234 +#include "cfgloop.h"
106235 +//#include "hosthooks.h"
106236 +#include "cgraph.h"
106237 +#include "opts.h"
106238 +//#include "coverage.h"
106239 +//#include "value-prof.h"
106240 +
106241 +#if BUILDING_GCC_VERSION >= 4007
106242 +#include "tree-pretty-print.h"
106243 +#include "gimple-pretty-print.h"
106244 +#include "c-tree.h"
106245 +//#include "alloc-pool.h"
106246 +#endif
106247 +
106248 +#if BUILDING_GCC_VERSION <= 4008
106249 +#include "tree-flow.h"
106250 +#else
106251 +#include "tree-cfgcleanup.h"
106252 +#endif
106253 +
106254 +#include "diagnostic.h"
106255 +//#include "tree-diagnostic.h"
106256 +#include "tree-dump.h"
106257 +#include "tree-pass.h"
106258 +//#include "df.h"
106259 +#include "predict.h"
106260 +//#include "lto-streamer.h"
106261 +#include "ipa-utils.h"
106262 +
106263 +#if BUILDING_GCC_VERSION >= 4009
106264 +#include "varasm.h"
106265 +#include "stor-layout.h"
106266 +#include "internal-fn.h"
106267 +#include "gimple-expr.h"
106268 +//#include "diagnostic-color.h"
106269 +#include "context.h"
106270 +#include "tree-ssa-alias.h"
106271 +#include "stringpool.h"
106272 +#include "tree-ssanames.h"
106273 +#include "print-tree.h"
106274 +#include "tree-eh.h"
106275 +#endif
106276 +
106277 +#include "gimple.h"
106278 +
106279 +#if BUILDING_GCC_VERSION >= 4009
106280 +#include "tree-ssa-operands.h"
106281 +#include "tree-phinodes.h"
106282 +#include "tree-cfg.h"
106283 +#include "gimple-iterator.h"
106284 +#include "gimple-ssa.h"
106285 +#include "ssa-iterators.h"
106286 +#endif
106287 +
106288 +//#include "expr.h" where are you...
106289 +extern rtx emit_move_insn(rtx x, rtx y);
106290 +
106291 +// missing from basic_block.h...
106292 +extern void debug_dominance_info(enum cdi_direction dir);
106293 +extern void debug_dominance_tree(enum cdi_direction dir, basic_block root);
106294 +
106295 +#define __unused __attribute__((__unused__))
106296 +
106297 +#define DECL_NAME_POINTER(node) IDENTIFIER_POINTER(DECL_NAME(node))
106298 +#define DECL_NAME_LENGTH(node) IDENTIFIER_LENGTH(DECL_NAME(node))
106299 +
106300 +#if BUILDING_GCC_VERSION == 4005
106301 +#define FOR_EACH_LOCAL_DECL(FUN, I, D) for (tree vars = (FUN)->local_decls; vars && (D = TREE_VALUE(vars)); vars = TREE_CHAIN(vars), I)
106302 +#define DECL_CHAIN(NODE) (TREE_CHAIN(DECL_MINIMAL_CHECK(NODE)))
106303 +#define FOR_EACH_VEC_ELT(T, V, I, P) for (I = 0; VEC_iterate(T, (V), (I), (P)); ++(I))
106304 +#define TODO_rebuild_cgraph_edges 0
106305 +
106306 +static inline bool gimple_call_builtin_p(gimple stmt, enum built_in_function code)
106307 +{
106308 + tree fndecl;
106309 +
106310 + if (!is_gimple_call(stmt))
106311 + return false;
106312 + fndecl = gimple_call_fndecl(stmt);
106313 + if (!fndecl || DECL_BUILT_IN_CLASS(fndecl) != BUILT_IN_NORMAL)
106314 + return false;
106315 +// print_node(stderr, "pax", fndecl, 4);
106316 + return DECL_FUNCTION_CODE(fndecl) == code;
106317 +}
106318 +
106319 +static inline bool is_simple_builtin(tree decl)
106320 +{
106321 + if (decl && DECL_BUILT_IN_CLASS(decl) != BUILT_IN_NORMAL)
106322 + return false;
106323 +
106324 + switch (DECL_FUNCTION_CODE(decl)) {
106325 + /* Builtins that expand to constants. */
106326 + case BUILT_IN_CONSTANT_P:
106327 + case BUILT_IN_EXPECT:
106328 + case BUILT_IN_OBJECT_SIZE:
106329 + case BUILT_IN_UNREACHABLE:
106330 + /* Simple register moves or loads from stack. */
106331 + case BUILT_IN_RETURN_ADDRESS:
106332 + case BUILT_IN_EXTRACT_RETURN_ADDR:
106333 + case BUILT_IN_FROB_RETURN_ADDR:
106334 + case BUILT_IN_RETURN:
106335 + case BUILT_IN_AGGREGATE_INCOMING_ADDRESS:
106336 + case BUILT_IN_FRAME_ADDRESS:
106337 + case BUILT_IN_VA_END:
106338 + case BUILT_IN_STACK_SAVE:
106339 + case BUILT_IN_STACK_RESTORE:
106340 + /* Exception state returns or moves registers around. */
106341 + case BUILT_IN_EH_FILTER:
106342 + case BUILT_IN_EH_POINTER:
106343 + case BUILT_IN_EH_COPY_VALUES:
106344 + return true;
106345 +
106346 + default:
106347 + return false;
106348 + }
106349 +}
106350 +#endif
106351 +
106352 +#if BUILDING_GCC_VERSION <= 4006
106353 +#define ANY_RETURN_P(rtx) (GET_CODE(rtx) == RETURN)
106354 +#define C_DECL_REGISTER(EXP) DECL_LANG_FLAG_4(EXP)
106355 +
106356 +// should come from c-tree.h if only it were installed for gcc 4.5...
106357 +#define C_TYPE_FIELDS_READONLY(TYPE) TREE_LANG_FLAG_1(TYPE)
106358 +
106359 +#define get_random_seed(noinit) ({ \
106360 + unsigned HOST_WIDE_INT seed; \
106361 + sscanf(get_random_seed(noinit), "%" HOST_WIDE_INT_PRINT "x", &seed); \
106362 + seed * seed; })
106363 +
106364 +static inline bool gimple_clobber_p(gimple s)
106365 +{
106366 + return false;
106367 +}
106368 +
106369 +static inline tree builtin_decl_implicit(enum built_in_function fncode)
106370 +{
106371 + return implicit_built_in_decls[fncode];
106372 +}
106373 +
106374 +static inline struct cgraph_node *cgraph_get_create_node(tree decl)
106375 +{
106376 + struct cgraph_node *node = cgraph_get_node(decl);
106377 +
106378 + return node ? node : cgraph_node(decl);
106379 +}
106380 +
106381 +static inline bool cgraph_function_with_gimple_body_p(struct cgraph_node *node)
106382 +{
106383 + return node->analyzed && !node->thunk.thunk_p && !node->alias;
106384 +}
106385 +
106386 +static inline struct cgraph_node *cgraph_first_function_with_gimple_body(void)
106387 +{
106388 + struct cgraph_node *node;
106389 +
106390 + for (node = cgraph_nodes; node; node = node->next)
106391 + if (cgraph_function_with_gimple_body_p(node))
106392 + return node;
106393 + return NULL;
106394 +}
106395 +
106396 +static inline struct cgraph_node *cgraph_next_function_with_gimple_body(struct cgraph_node *node)
106397 +{
106398 + for (node = node->next; node; node = node->next)
106399 + if (cgraph_function_with_gimple_body_p(node))
106400 + return node;
106401 + return NULL;
106402 +}
106403 +
106404 +#define FOR_EACH_FUNCTION_WITH_GIMPLE_BODY(node) \
106405 + for ((node) = cgraph_first_function_with_gimple_body(); (node); \
106406 + (node) = cgraph_next_function_with_gimple_body(node))
106407 +#endif
106408 +
106409 +#if BUILDING_GCC_VERSION == 4006
106410 +extern void debug_gimple_stmt(gimple);
106411 +extern void debug_gimple_seq(gimple_seq);
106412 +extern void print_gimple_seq(FILE *, gimple_seq, int, int);
106413 +extern void print_gimple_stmt(FILE *, gimple, int, int);
106414 +extern void print_gimple_expr(FILE *, gimple, int, int);
106415 +extern void dump_gimple_stmt(pretty_printer *, gimple, int, int);
106416 +#endif
106417 +
106418 +#if BUILDING_GCC_VERSION <= 4007
106419 +#define FOR_EACH_VARIABLE(node) for (node = varpool_nodes; node; node = node->next)
106420 +#define PROP_loops 0
106421 +
106422 +static inline int bb_loop_depth(const_basic_block bb)
106423 +{
106424 + return bb->loop_father ? loop_depth(bb->loop_father) : 0;
106425 +}
106426 +
106427 +static inline bool gimple_store_p(gimple gs)
106428 +{
106429 + tree lhs = gimple_get_lhs(gs);
106430 + return lhs && !is_gimple_reg(lhs);
106431 +}
106432 +#endif
106433 +
106434 +#if BUILDING_GCC_VERSION >= 4007
106435 +#define cgraph_create_edge(caller, callee, call_stmt, count, freq, nest) \
106436 + cgraph_create_edge((caller), (callee), (call_stmt), (count), (freq))
106437 +#endif
106438 +
106439 +#if BUILDING_GCC_VERSION <= 4008
106440 +#define ENTRY_BLOCK_PTR_FOR_FN(FN) ENTRY_BLOCK_PTR_FOR_FUNCTION(FN)
106441 +#define EXIT_BLOCK_PTR_FOR_FN(FN) EXIT_BLOCK_PTR_FOR_FUNCTION(FN)
106442 +#define basic_block_info_for_fn(FN) ((FN)->cfg->x_basic_block_info)
106443 +#define n_basic_blocks_for_fn(FN) ((FN)->cfg->x_n_basic_blocks)
106444 +#define n_edges_for_fn(FN) ((FN)->cfg->x_n_edges)
106445 +#define last_basic_block_for_fn(FN) ((FN)->cfg->x_last_basic_block)
106446 +#define label_to_block_map_for_fn(FN) ((FN)->cfg->x_label_to_block_map)
106447 +#define profile_status_for_fn(FN) ((FN)->cfg->x_profile_status)
106448 +
106449 +static inline const char *get_tree_code_name(enum tree_code code)
106450 +{
106451 + gcc_assert(code < MAX_TREE_CODES);
106452 + return tree_code_name[code];
106453 +}
106454 +
106455 +#define ipa_remove_stmt_references(cnode, stmt)
106456 +#endif
106457 +
106458 +#if BUILDING_GCC_VERSION == 4008
106459 +#define NODE_DECL(node) node->symbol.decl
106460 +#else
106461 +#define NODE_DECL(node) node->decl
106462 +#endif
106463 +
106464 +#if BUILDING_GCC_VERSION >= 4008
106465 +#define add_referenced_var(var)
106466 +#define mark_sym_for_renaming(var)
106467 +#define varpool_mark_needed_node(node)
106468 +#define TODO_dump_func 0
106469 +#define TODO_dump_cgraph 0
106470 +#endif
106471 +
106472 +#if BUILDING_GCC_VERSION >= 4009
106473 +#define TODO_ggc_collect 0
106474 +#endif
106475 +
106476 +#endif
106477 diff --git a/tools/gcc/gen-random-seed.sh b/tools/gcc/gen-random-seed.sh
106478 new file mode 100644
106479 index 0000000..7514850
106480 --- /dev/null
106481 +++ b/tools/gcc/gen-random-seed.sh
106482 @@ -0,0 +1,8 @@
106483 +#!/bin/sh
106484 +
106485 +if [ ! -f "$1" ]; then
106486 + SEED=`od -A n -t x8 -N 32 /dev/urandom | tr -d ' \n'`
106487 + echo "const char *randstruct_seed = \"$SEED\";" > "$1"
106488 + HASH=`echo -n "$SEED" | sha256sum | cut -d" " -f1 | tr -d ' \n'`
106489 + echo "#define RANDSTRUCT_HASHED_SEED \"$HASH\"" > "$2"
106490 +fi
106491 diff --git a/tools/gcc/generate_size_overflow_hash.sh b/tools/gcc/generate_size_overflow_hash.sh
106492 new file mode 100644
106493 index 0000000..791ca76
106494 --- /dev/null
106495 +++ b/tools/gcc/generate_size_overflow_hash.sh
106496 @@ -0,0 +1,97 @@
106497 +#!/bin/bash
106498 +
106499 +# This script generates the hash table (size_overflow_hash.h) for the size_overflow gcc plugin (size_overflow_plugin.c).
106500 +
106501 +header1="size_overflow_hash.h"
106502 +database="size_overflow_hash.data"
106503 +n=65536
106504 +hashtable_name="size_overflow_hash"
106505 +
106506 +usage() {
106507 +cat <<EOF
106508 +usage: $0 options
106509 +OPTIONS:
106510 + -h|--help help
106511 + -o header file
106512 + -d database file
106513 + -n hash array size
106514 + -s name of the hash table
106515 +EOF
106516 + return 0
106517 +}
106518 +
106519 +while true
106520 +do
106521 + case "$1" in
106522 + -h|--help) usage && exit 0;;
106523 + -n) n=$2; shift 2;;
106524 + -o) header1="$2"; shift 2;;
106525 + -d) database="$2"; shift 2;;
106526 + -s) hashtable_name="$2"; shift 2;;
106527 + --) shift 1; break ;;
106528 + *) break ;;
106529 + esac
106530 +done
106531 +
106532 +create_defines() {
106533 + for i in `seq 0 31`
106534 + do
106535 + echo -e "#define PARAM"$i" (1U << "$i")" >> "$header1"
106536 + done
106537 + echo >> "$header1"
106538 +}
106539 +
106540 +create_structs() {
106541 + rm -f "$header1"
106542 +
106543 + create_defines
106544 +
106545 + cat "$database" | while read data
106546 + do
106547 + data_array=($data)
106548 + struct_hash_name="${data_array[0]}"
106549 + funcn="${data_array[1]}"
106550 + params="${data_array[2]}"
106551 + next="${data_array[4]}"
106552 +
106553 + echo "const struct size_overflow_hash $struct_hash_name = {" >> "$header1"
106554 +
106555 + echo -e "\t.next\t= $next,\n\t.name\t= \"$funcn\"," >> "$header1"
106556 + echo -en "\t.param\t= " >> "$header1"
106557 + line=
106558 + for param_num in ${params//-/ };
106559 + do
106560 + line="${line}PARAM"$param_num"|"
106561 + done
106562 +
106563 + echo -e "${line%?},\n};\n" >> "$header1"
106564 + done
106565 +}
106566 +
106567 +create_headers() {
106568 + echo "const struct size_overflow_hash * const $hashtable_name[$n] = {" >> "$header1"
106569 +}
106570 +
106571 +create_array_elements() {
106572 + index=0
106573 + grep -v "nohasharray" $database | sort -n -k 4 | while read data
106574 + do
106575 + data_array=($data)
106576 + i="${data_array[3]}"
106577 + hash="${data_array[0]}"
106578 + while [[ $index -lt $i ]]
106579 + do
106580 + echo -e "\t["$index"]\t= NULL," >> "$header1"
106581 + index=$(($index + 1))
106582 + done
106583 + index=$(($index + 1))
106584 + echo -e "\t["$i"]\t= &"$hash"," >> "$header1"
106585 + done
106586 + echo '};' >> $header1
106587 +}
106588 +
106589 +create_structs
106590 +create_headers
106591 +create_array_elements
106592 +
106593 +exit 0
106594 diff --git a/tools/gcc/kallocstat_plugin.c b/tools/gcc/kallocstat_plugin.c
106595 new file mode 100644
106596 index 0000000..b559327
106597 --- /dev/null
106598 +++ b/tools/gcc/kallocstat_plugin.c
106599 @@ -0,0 +1,182 @@
106600 +/*
106601 + * Copyright 2011-2014 by the PaX Team <pageexec@freemail.hu>
106602 + * Licensed under the GPL v2
106603 + *
106604 + * Note: the choice of the license means that the compilation process is
106605 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
106606 + * but for the kernel it doesn't matter since it doesn't link against
106607 + * any of the gcc libraries
106608 + *
106609 + * gcc plugin to find the distribution of k*alloc sizes
106610 + *
106611 + * TODO:
106612 + *
106613 + * BUGS:
106614 + * - none known
106615 + */
106616 +
106617 +#include "gcc-common.h"
106618 +
106619 +int plugin_is_GPL_compatible;
106620 +
106621 +static struct plugin_info kallocstat_plugin_info = {
106622 + .version = "201401260140",
106623 + .help = NULL
106624 +};
106625 +
106626 +static const char * const kalloc_functions[] = {
106627 + "__kmalloc",
106628 + "kmalloc",
106629 + "kmalloc_large",
106630 + "kmalloc_node",
106631 + "kmalloc_order",
106632 + "kmalloc_order_trace",
106633 + "kmalloc_slab",
106634 + "kzalloc",
106635 + "kzalloc_node",
106636 +};
106637 +
106638 +static bool is_kalloc(const char *fnname)
106639 +{
106640 + size_t i;
106641 +
106642 + for (i = 0; i < ARRAY_SIZE(kalloc_functions); i++)
106643 + if (!strcmp(fnname, kalloc_functions[i]))
106644 + return true;
106645 + return false;
106646 +}
106647 +
106648 +static unsigned int execute_kallocstat(void)
106649 +{
106650 + basic_block bb;
106651 +
106652 + // 1. loop through BBs and GIMPLE statements
106653 + FOR_EACH_BB_FN(bb, cfun) {
106654 + gimple_stmt_iterator gsi;
106655 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
106656 + // gimple match:
106657 + tree fndecl, size;
106658 + gimple stmt;
106659 + const char *fnname;
106660 +
106661 + // is it a call
106662 + stmt = gsi_stmt(gsi);
106663 + if (!is_gimple_call(stmt))
106664 + continue;
106665 + fndecl = gimple_call_fndecl(stmt);
106666 + if (fndecl == NULL_TREE)
106667 + continue;
106668 + if (TREE_CODE(fndecl) != FUNCTION_DECL)
106669 + continue;
106670 +
106671 + // is it a call to k*alloc
106672 + fnname = DECL_NAME_POINTER(fndecl);
106673 + if (!is_kalloc(fnname))
106674 + continue;
106675 +
106676 + // is the size arg const or the result of a simple const assignment
106677 + size = gimple_call_arg(stmt, 0);
106678 + while (true) {
106679 + expanded_location xloc;
106680 + size_t size_val;
106681 +
106682 + if (TREE_CONSTANT(size)) {
106683 + xloc = expand_location(gimple_location(stmt));
106684 + if (!xloc.file)
106685 + xloc = expand_location(DECL_SOURCE_LOCATION(current_function_decl));
106686 + size_val = TREE_INT_CST_LOW(size);
106687 + fprintf(stderr, "kallocsize: %8zu %8zx %s %s:%u\n", size_val, size_val, fnname, xloc.file, xloc.line);
106688 + break;
106689 + }
106690 +
106691 + if (TREE_CODE(size) != SSA_NAME)
106692 + break;
106693 + stmt = SSA_NAME_DEF_STMT(size);
106694 +//debug_gimple_stmt(stmt);
106695 +//debug_tree(size);
106696 + if (!stmt || !is_gimple_assign(stmt))
106697 + break;
106698 + if (gimple_num_ops(stmt) != 2)
106699 + break;
106700 + size = gimple_assign_rhs1(stmt);
106701 + }
106702 +//print_gimple_stmt(stderr, call_stmt, 0, TDF_LINENO);
106703 +//debug_tree(gimple_call_fn(call_stmt));
106704 +//print_node(stderr, "pax", fndecl, 4);
106705 + }
106706 + }
106707 +
106708 + return 0;
106709 +}
106710 +
106711 +#if BUILDING_GCC_VERSION >= 4009
106712 +static const struct pass_data kallocstat_pass_data = {
106713 +#else
106714 +static struct gimple_opt_pass kallocstat_pass = {
106715 + .pass = {
106716 +#endif
106717 + .type = GIMPLE_PASS,
106718 + .name = "kallocstat",
106719 +#if BUILDING_GCC_VERSION >= 4008
106720 + .optinfo_flags = OPTGROUP_NONE,
106721 +#endif
106722 +#if BUILDING_GCC_VERSION >= 4009
106723 + .has_gate = false,
106724 + .has_execute = true,
106725 +#else
106726 + .gate = NULL,
106727 + .execute = execute_kallocstat,
106728 + .sub = NULL,
106729 + .next = NULL,
106730 + .static_pass_number = 0,
106731 +#endif
106732 + .tv_id = TV_NONE,
106733 + .properties_required = 0,
106734 + .properties_provided = 0,
106735 + .properties_destroyed = 0,
106736 + .todo_flags_start = 0,
106737 + .todo_flags_finish = 0
106738 +#if BUILDING_GCC_VERSION < 4009
106739 + }
106740 +#endif
106741 +};
106742 +
106743 +#if BUILDING_GCC_VERSION >= 4009
106744 +namespace {
106745 +class kallocstat_pass : public gimple_opt_pass {
106746 +public:
106747 + kallocstat_pass() : gimple_opt_pass(kallocstat_pass_data, g) {}
106748 + unsigned int execute() { return execute_kallocstat(); }
106749 +};
106750 +}
106751 +#endif
106752 +
106753 +static struct opt_pass *make_kallocstat_pass(void)
106754 +{
106755 +#if BUILDING_GCC_VERSION >= 4009
106756 + return new kallocstat_pass();
106757 +#else
106758 + return &kallocstat_pass.pass;
106759 +#endif
106760 +}
106761 +
106762 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
106763 +{
106764 + const char * const plugin_name = plugin_info->base_name;
106765 + struct register_pass_info kallocstat_pass_info;
106766 +
106767 + kallocstat_pass_info.pass = make_kallocstat_pass();
106768 + kallocstat_pass_info.reference_pass_name = "ssa";
106769 + kallocstat_pass_info.ref_pass_instance_number = 1;
106770 + kallocstat_pass_info.pos_op = PASS_POS_INSERT_AFTER;
106771 +
106772 + if (!plugin_default_version_check(version, &gcc_version)) {
106773 + error(G_("incompatible gcc/plugin versions"));
106774 + return 1;
106775 + }
106776 +
106777 + register_callback(plugin_name, PLUGIN_INFO, NULL, &kallocstat_plugin_info);
106778 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kallocstat_pass_info);
106779 +
106780 + return 0;
106781 +}
106782 diff --git a/tools/gcc/kernexec_plugin.c b/tools/gcc/kernexec_plugin.c
106783 new file mode 100644
106784 index 0000000..dd73713
106785 --- /dev/null
106786 +++ b/tools/gcc/kernexec_plugin.c
106787 @@ -0,0 +1,519 @@
106788 +/*
106789 + * Copyright 2011-2014 by the PaX Team <pageexec@freemail.hu>
106790 + * Licensed under the GPL v2
106791 + *
106792 + * Note: the choice of the license means that the compilation process is
106793 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
106794 + * but for the kernel it doesn't matter since it doesn't link against
106795 + * any of the gcc libraries
106796 + *
106797 + * gcc plugin to make KERNEXEC/amd64 almost as good as it is on i386
106798 + *
106799 + * TODO:
106800 + *
106801 + * BUGS:
106802 + * - none known
106803 + */
106804 +
106805 +#include "gcc-common.h"
106806 +
106807 +int plugin_is_GPL_compatible;
106808 +
106809 +static struct plugin_info kernexec_plugin_info = {
106810 + .version = "201401260140",
106811 + .help = "method=[bts|or]\tinstrumentation method\n"
106812 +};
106813 +
106814 +static void (*kernexec_instrument_fptr)(gimple_stmt_iterator *);
106815 +static void (*kernexec_instrument_retaddr)(rtx);
106816 +
106817 +/*
106818 + * add special KERNEXEC instrumentation: reload %r12 after it has been clobbered
106819 + */
106820 +static void kernexec_reload_fptr_mask(gimple_stmt_iterator *gsi)
106821 +{
106822 + gimple asm_movabs_stmt;
106823 +
106824 + // build asm volatile("movabs $0x8000000000000000, %%r12\n\t" : : : );
106825 + asm_movabs_stmt = gimple_build_asm_vec("movabs $0x8000000000000000, %%r12\n\t", NULL, NULL, NULL, NULL);
106826 + gimple_asm_set_volatile(asm_movabs_stmt, true);
106827 + gsi_insert_after(gsi, asm_movabs_stmt, GSI_CONTINUE_LINKING);
106828 + update_stmt(asm_movabs_stmt);
106829 +}
106830 +
106831 +/*
106832 + * find all asm() stmts that clobber r12 and add a reload of r12
106833 + */
106834 +static unsigned int execute_kernexec_reload(void)
106835 +{
106836 + basic_block bb;
106837 +
106838 + // 1. loop through BBs and GIMPLE statements
106839 + FOR_EACH_BB_FN(bb, cfun) {
106840 + gimple_stmt_iterator gsi;
106841 +
106842 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
106843 + // gimple match: __asm__ ("" : : : "r12");
106844 + gimple asm_stmt;
106845 + size_t nclobbers;
106846 +
106847 + // is it an asm ...
106848 + asm_stmt = gsi_stmt(gsi);
106849 + if (gimple_code(asm_stmt) != GIMPLE_ASM)
106850 + continue;
106851 +
106852 + // ... clobbering r12
106853 + nclobbers = gimple_asm_nclobbers(asm_stmt);
106854 + while (nclobbers--) {
106855 + tree op = gimple_asm_clobber_op(asm_stmt, nclobbers);
106856 + if (strcmp(TREE_STRING_POINTER(TREE_VALUE(op)), "r12"))
106857 + continue;
106858 + kernexec_reload_fptr_mask(&gsi);
106859 +//print_gimple_stmt(stderr, asm_stmt, 0, TDF_LINENO);
106860 + break;
106861 + }
106862 + }
106863 + }
106864 +
106865 + return 0;
106866 +}
106867 +
106868 +/*
106869 + * add special KERNEXEC instrumentation: force MSB of fptr to 1, which will produce
106870 + * a non-canonical address from a userland ptr and will just trigger a GPF on dereference
106871 + */
106872 +static void kernexec_instrument_fptr_bts(gimple_stmt_iterator *gsi)
106873 +{
106874 + gimple assign_intptr, assign_new_fptr, call_stmt;
106875 + tree intptr, orptr, old_fptr, new_fptr, kernexec_mask;
106876 +
106877 + call_stmt = gsi_stmt(*gsi);
106878 + old_fptr = gimple_call_fn(call_stmt);
106879 +
106880 + // create temporary unsigned long variable used for bitops and cast fptr to it
106881 + intptr = create_tmp_var(long_unsigned_type_node, "kernexec_bts");
106882 + add_referenced_var(intptr);
106883 + intptr = make_ssa_name(intptr, NULL);
106884 + assign_intptr = gimple_build_assign(intptr, fold_convert(long_unsigned_type_node, old_fptr));
106885 + SSA_NAME_DEF_STMT(intptr) = assign_intptr;
106886 + gsi_insert_before(gsi, assign_intptr, GSI_SAME_STMT);
106887 + update_stmt(assign_intptr);
106888 +
106889 + // apply logical or to temporary unsigned long and bitmask
106890 + kernexec_mask = build_int_cstu(long_long_unsigned_type_node, 0x8000000000000000LL);
106891 +// kernexec_mask = build_int_cstu(long_long_unsigned_type_node, 0xffffffff80000000LL);
106892 + orptr = fold_build2(BIT_IOR_EXPR, long_long_unsigned_type_node, intptr, kernexec_mask);
106893 + intptr = make_ssa_name(SSA_NAME_VAR(intptr), NULL);
106894 + assign_intptr = gimple_build_assign(intptr, orptr);
106895 + SSA_NAME_DEF_STMT(intptr) = assign_intptr;
106896 + gsi_insert_before(gsi, assign_intptr, GSI_SAME_STMT);
106897 + update_stmt(assign_intptr);
106898 +
106899 + // cast temporary unsigned long back to a temporary fptr variable
106900 + new_fptr = create_tmp_var(TREE_TYPE(old_fptr), "kernexec_fptr");
106901 + add_referenced_var(new_fptr);
106902 + new_fptr = make_ssa_name(new_fptr, NULL);
106903 + assign_new_fptr = gimple_build_assign(new_fptr, fold_convert(TREE_TYPE(old_fptr), intptr));
106904 + SSA_NAME_DEF_STMT(new_fptr) = assign_new_fptr;
106905 + gsi_insert_before(gsi, assign_new_fptr, GSI_SAME_STMT);
106906 + update_stmt(assign_new_fptr);
106907 +
106908 + // replace call stmt fn with the new fptr
106909 + gimple_call_set_fn(call_stmt, new_fptr);
106910 + update_stmt(call_stmt);
106911 +}
106912 +
106913 +static void kernexec_instrument_fptr_or(gimple_stmt_iterator *gsi)
106914 +{
106915 + gimple asm_or_stmt, call_stmt;
106916 + tree old_fptr, new_fptr, input, output;
106917 +#if BUILDING_GCC_VERSION <= 4007
106918 + VEC(tree, gc) *inputs = NULL;
106919 + VEC(tree, gc) *outputs = NULL;
106920 +#else
106921 + vec<tree, va_gc> *inputs = NULL;
106922 + vec<tree, va_gc> *outputs = NULL;
106923 +#endif
106924 +
106925 + call_stmt = gsi_stmt(*gsi);
106926 + old_fptr = gimple_call_fn(call_stmt);
106927 +
106928 + // create temporary fptr variable
106929 + new_fptr = create_tmp_var(TREE_TYPE(old_fptr), "kernexec_or");
106930 + add_referenced_var(new_fptr);
106931 + new_fptr = make_ssa_name(new_fptr, NULL);
106932 +
106933 + // build asm volatile("orq %%r12, %0\n\t" : "=r"(new_fptr) : "0"(old_fptr));
106934 + input = build_tree_list(NULL_TREE, build_string(1, "0"));
106935 + input = chainon(NULL_TREE, build_tree_list(input, old_fptr));
106936 + output = build_tree_list(NULL_TREE, build_string(2, "=r"));
106937 + output = chainon(NULL_TREE, build_tree_list(output, new_fptr));
106938 +#if BUILDING_GCC_VERSION <= 4007
106939 + VEC_safe_push(tree, gc, inputs, input);
106940 + VEC_safe_push(tree, gc, outputs, output);
106941 +#else
106942 + vec_safe_push(inputs, input);
106943 + vec_safe_push(outputs, output);
106944 +#endif
106945 + asm_or_stmt = gimple_build_asm_vec("orq %%r12, %0\n\t", inputs, outputs, NULL, NULL);
106946 + SSA_NAME_DEF_STMT(new_fptr) = asm_or_stmt;
106947 + gimple_asm_set_volatile(asm_or_stmt, true);
106948 + gsi_insert_before(gsi, asm_or_stmt, GSI_SAME_STMT);
106949 + update_stmt(asm_or_stmt);
106950 +
106951 + // replace call stmt fn with the new fptr
106952 + gimple_call_set_fn(call_stmt, new_fptr);
106953 + update_stmt(call_stmt);
106954 +}
106955 +
106956 +/*
106957 + * find all C level function pointer dereferences and forcibly set the highest bit of the pointer
106958 + */
106959 +static unsigned int execute_kernexec_fptr(void)
106960 +{
106961 + basic_block bb;
106962 +
106963 + // 1. loop through BBs and GIMPLE statements
106964 + FOR_EACH_BB_FN(bb, cfun) {
106965 + gimple_stmt_iterator gsi;
106966 +
106967 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
106968 + // gimple match: h_1 = get_fptr (); D.2709_3 = h_1 (x_2(D));
106969 + tree fn;
106970 + gimple call_stmt;
106971 +
106972 + // is it a call ...
106973 + call_stmt = gsi_stmt(gsi);
106974 + if (!is_gimple_call(call_stmt))
106975 + continue;
106976 + fn = gimple_call_fn(call_stmt);
106977 + if (TREE_CODE(fn) == ADDR_EXPR)
106978 + continue;
106979 + if (TREE_CODE(fn) != SSA_NAME)
106980 + gcc_unreachable();
106981 +
106982 + // ... through a function pointer
106983 + if (SSA_NAME_VAR(fn) != NULL_TREE) {
106984 + fn = SSA_NAME_VAR(fn);
106985 + if (TREE_CODE(fn) != VAR_DECL && TREE_CODE(fn) != PARM_DECL) {
106986 + debug_tree(fn);
106987 + gcc_unreachable();
106988 + }
106989 + }
106990 + fn = TREE_TYPE(fn);
106991 + if (TREE_CODE(fn) != POINTER_TYPE)
106992 + continue;
106993 + fn = TREE_TYPE(fn);
106994 + if (TREE_CODE(fn) != FUNCTION_TYPE)
106995 + continue;
106996 +
106997 + kernexec_instrument_fptr(&gsi);
106998 +
106999 +//debug_tree(gimple_call_fn(call_stmt));
107000 +//print_gimple_stmt(stderr, call_stmt, 0, TDF_LINENO);
107001 + }
107002 + }
107003 +
107004 + return 0;
107005 +}
107006 +
107007 +// add special KERNEXEC instrumentation: btsq $63,(%rsp) just before retn
107008 +static void kernexec_instrument_retaddr_bts(rtx insn)
107009 +{
107010 + rtx btsq;
107011 + rtvec argvec, constraintvec, labelvec;
107012 + int line;
107013 +
107014 + // create asm volatile("btsq $63,(%%rsp)":::)
107015 + argvec = rtvec_alloc(0);
107016 + constraintvec = rtvec_alloc(0);
107017 + labelvec = rtvec_alloc(0);
107018 + line = expand_location(RTL_LOCATION(insn)).line;
107019 + btsq = gen_rtx_ASM_OPERANDS(VOIDmode, "btsq $63,(%%rsp)", empty_string, 0, argvec, constraintvec, labelvec, line);
107020 + MEM_VOLATILE_P(btsq) = 1;
107021 +// RTX_FRAME_RELATED_P(btsq) = 1; // not for ASM_OPERANDS
107022 + emit_insn_before(btsq, insn);
107023 +}
107024 +
107025 +// add special KERNEXEC instrumentation: orq %r12,(%rsp) just before retn
107026 +static void kernexec_instrument_retaddr_or(rtx insn)
107027 +{
107028 + rtx orq;
107029 + rtvec argvec, constraintvec, labelvec;
107030 + int line;
107031 +
107032 + // create asm volatile("orq %%r12,(%%rsp)":::)
107033 + argvec = rtvec_alloc(0);
107034 + constraintvec = rtvec_alloc(0);
107035 + labelvec = rtvec_alloc(0);
107036 + line = expand_location(RTL_LOCATION(insn)).line;
107037 + orq = gen_rtx_ASM_OPERANDS(VOIDmode, "orq %%r12,(%%rsp)", empty_string, 0, argvec, constraintvec, labelvec, line);
107038 + MEM_VOLATILE_P(orq) = 1;
107039 +// RTX_FRAME_RELATED_P(orq) = 1; // not for ASM_OPERANDS
107040 + emit_insn_before(orq, insn);
107041 +}
107042 +
107043 +/*
107044 + * find all asm level function returns and forcibly set the highest bit of the return address
107045 + */
107046 +static unsigned int execute_kernexec_retaddr(void)
107047 +{
107048 + rtx insn;
107049 +
107050 +// if (stack_realign_drap)
107051 +// inform(DECL_SOURCE_LOCATION(current_function_decl), "drap detected in %s\n", IDENTIFIER_POINTER(DECL_NAME(current_function_decl)));
107052 +
107053 + // 1. find function returns
107054 + for (insn = get_insns(); insn; insn = NEXT_INSN(insn)) {
107055 + // rtl match: (jump_insn 41 40 42 2 (return) fptr.c:42 634 {return_internal} (nil))
107056 + // (jump_insn 12 9 11 2 (parallel [ (return) (unspec [ (0) ] UNSPEC_REP) ]) fptr.c:46 635 {return_internal_long} (nil))
107057 + // (jump_insn 97 96 98 6 (simple_return) fptr.c:50 -1 (nil) -> simple_return)
107058 + rtx body;
107059 +
107060 + // is it a retn
107061 + if (!JUMP_P(insn))
107062 + continue;
107063 + body = PATTERN(insn);
107064 + if (GET_CODE(body) == PARALLEL)
107065 + body = XVECEXP(body, 0, 0);
107066 + if (!ANY_RETURN_P(body))
107067 + continue;
107068 + kernexec_instrument_retaddr(insn);
107069 + }
107070 +
107071 +// print_simple_rtl(stderr, get_insns());
107072 +// print_rtl(stderr, get_insns());
107073 +
107074 + return 0;
107075 +}
107076 +
107077 +static bool kernexec_cmodel_check(void)
107078 +{
107079 + tree section;
107080 +
107081 + if (ix86_cmodel != CM_KERNEL)
107082 + return false;
107083 +
107084 + section = lookup_attribute("section", DECL_ATTRIBUTES(current_function_decl));
107085 + if (!section || !TREE_VALUE(section))
107086 + return true;
107087 +
107088 + section = TREE_VALUE(TREE_VALUE(section));
107089 + if (strncmp(TREE_STRING_POINTER(section), ".vsyscall_", 10))
107090 + return true;
107091 +
107092 + return false;
107093 +}
107094 +
107095 +#if BUILDING_GCC_VERSION >= 4009
107096 +static const struct pass_data kernexec_reload_pass_data = {
107097 +#else
107098 +static struct gimple_opt_pass kernexec_reload_pass = {
107099 + .pass = {
107100 +#endif
107101 + .type = GIMPLE_PASS,
107102 + .name = "kernexec_reload",
107103 +#if BUILDING_GCC_VERSION >= 4008
107104 + .optinfo_flags = OPTGROUP_NONE,
107105 +#endif
107106 +#if BUILDING_GCC_VERSION >= 4009
107107 + .has_gate = true,
107108 + .has_execute = true,
107109 +#else
107110 + .gate = kernexec_cmodel_check,
107111 + .execute = execute_kernexec_reload,
107112 + .sub = NULL,
107113 + .next = NULL,
107114 + .static_pass_number = 0,
107115 +#endif
107116 + .tv_id = TV_NONE,
107117 + .properties_required = 0,
107118 + .properties_provided = 0,
107119 + .properties_destroyed = 0,
107120 + .todo_flags_start = 0,
107121 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_remove_unused_locals | TODO_update_ssa_no_phi
107122 +#if BUILDING_GCC_VERSION < 4009
107123 + }
107124 +#endif
107125 +};
107126 +
107127 +#if BUILDING_GCC_VERSION >= 4009
107128 +static const struct pass_data kernexec_fptr_pass_data = {
107129 +#else
107130 +static struct gimple_opt_pass kernexec_fptr_pass = {
107131 + .pass = {
107132 +#endif
107133 + .type = GIMPLE_PASS,
107134 + .name = "kernexec_fptr",
107135 +#if BUILDING_GCC_VERSION >= 4008
107136 + .optinfo_flags = OPTGROUP_NONE,
107137 +#endif
107138 +#if BUILDING_GCC_VERSION >= 4009
107139 + .has_gate = true,
107140 + .has_execute = true,
107141 +#else
107142 + .gate = kernexec_cmodel_check,
107143 + .execute = execute_kernexec_fptr,
107144 + .sub = NULL,
107145 + .next = NULL,
107146 + .static_pass_number = 0,
107147 +#endif
107148 + .tv_id = TV_NONE,
107149 + .properties_required = 0,
107150 + .properties_provided = 0,
107151 + .properties_destroyed = 0,
107152 + .todo_flags_start = 0,
107153 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_remove_unused_locals | TODO_update_ssa_no_phi
107154 +#if BUILDING_GCC_VERSION < 4009
107155 + }
107156 +#endif
107157 +};
107158 +
107159 +#if BUILDING_GCC_VERSION >= 4009
107160 +static const struct pass_data kernexec_retaddr_pass_data = {
107161 +#else
107162 +static struct rtl_opt_pass kernexec_retaddr_pass = {
107163 + .pass = {
107164 +#endif
107165 + .type = RTL_PASS,
107166 + .name = "kernexec_retaddr",
107167 +#if BUILDING_GCC_VERSION >= 4008
107168 + .optinfo_flags = OPTGROUP_NONE,
107169 +#endif
107170 +#if BUILDING_GCC_VERSION >= 4009
107171 + .has_gate = true,
107172 + .has_execute = true,
107173 +#else
107174 + .gate = kernexec_cmodel_check,
107175 + .execute = execute_kernexec_retaddr,
107176 + .sub = NULL,
107177 + .next = NULL,
107178 + .static_pass_number = 0,
107179 +#endif
107180 + .tv_id = TV_NONE,
107181 + .properties_required = 0,
107182 + .properties_provided = 0,
107183 + .properties_destroyed = 0,
107184 + .todo_flags_start = 0,
107185 + .todo_flags_finish = TODO_dump_func | TODO_ggc_collect
107186 +#if BUILDING_GCC_VERSION < 4009
107187 + }
107188 +#endif
107189 +};
107190 +
107191 +#if BUILDING_GCC_VERSION >= 4009
107192 +namespace {
107193 +class kernexec_reload_pass : public gimple_opt_pass {
107194 +public:
107195 + kernexec_reload_pass() : gimple_opt_pass(kernexec_reload_pass_data, g) {}
107196 + bool gate() { return kernexec_cmodel_check(); }
107197 + unsigned int execute() { return execute_kernexec_reload(); }
107198 +};
107199 +
107200 +class kernexec_fptr_pass : public gimple_opt_pass {
107201 +public:
107202 + kernexec_fptr_pass() : gimple_opt_pass(kernexec_fptr_pass_data, g) {}
107203 + bool gate() { return kernexec_cmodel_check(); }
107204 + unsigned int execute() { return execute_kernexec_fptr(); }
107205 +};
107206 +
107207 +class kernexec_retaddr_pass : public rtl_opt_pass {
107208 +public:
107209 + kernexec_retaddr_pass() : rtl_opt_pass(kernexec_retaddr_pass_data, g) {}
107210 + bool gate() { return kernexec_cmodel_check(); }
107211 + unsigned int execute() { return execute_kernexec_retaddr(); }
107212 +};
107213 +}
107214 +#endif
107215 +
107216 +static struct opt_pass *make_kernexec_reload_pass(void)
107217 +{
107218 +#if BUILDING_GCC_VERSION >= 4009
107219 + return new kernexec_reload_pass();
107220 +#else
107221 + return &kernexec_reload_pass.pass;
107222 +#endif
107223 +}
107224 +
107225 +static struct opt_pass *make_kernexec_fptr_pass(void)
107226 +{
107227 +#if BUILDING_GCC_VERSION >= 4009
107228 + return new kernexec_fptr_pass();
107229 +#else
107230 + return &kernexec_fptr_pass.pass;
107231 +#endif
107232 +}
107233 +
107234 +static struct opt_pass *make_kernexec_retaddr_pass(void)
107235 +{
107236 +#if BUILDING_GCC_VERSION >= 4009
107237 + return new kernexec_retaddr_pass();
107238 +#else
107239 + return &kernexec_retaddr_pass.pass;
107240 +#endif
107241 +}
107242 +
107243 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
107244 +{
107245 + const char * const plugin_name = plugin_info->base_name;
107246 + const int argc = plugin_info->argc;
107247 + const struct plugin_argument * const argv = plugin_info->argv;
107248 + int i;
107249 + struct register_pass_info kernexec_reload_pass_info;
107250 + struct register_pass_info kernexec_fptr_pass_info;
107251 + struct register_pass_info kernexec_retaddr_pass_info;
107252 +
107253 + kernexec_reload_pass_info.pass = make_kernexec_reload_pass();
107254 + kernexec_reload_pass_info.reference_pass_name = "ssa";
107255 + kernexec_reload_pass_info.ref_pass_instance_number = 1;
107256 + kernexec_reload_pass_info.pos_op = PASS_POS_INSERT_AFTER;
107257 +
107258 + kernexec_fptr_pass_info.pass = make_kernexec_fptr_pass();
107259 + kernexec_fptr_pass_info.reference_pass_name = "ssa";
107260 + kernexec_fptr_pass_info.ref_pass_instance_number = 1;
107261 + kernexec_fptr_pass_info.pos_op = PASS_POS_INSERT_AFTER;
107262 +
107263 + kernexec_retaddr_pass_info.pass = make_kernexec_retaddr_pass();
107264 + kernexec_retaddr_pass_info.reference_pass_name = "pro_and_epilogue";
107265 + kernexec_retaddr_pass_info.ref_pass_instance_number = 1;
107266 + kernexec_retaddr_pass_info.pos_op = PASS_POS_INSERT_AFTER;
107267 +
107268 + if (!plugin_default_version_check(version, &gcc_version)) {
107269 + error(G_("incompatible gcc/plugin versions"));
107270 + return 1;
107271 + }
107272 +
107273 + register_callback(plugin_name, PLUGIN_INFO, NULL, &kernexec_plugin_info);
107274 +
107275 + if (TARGET_64BIT == 0)
107276 + return 0;
107277 +
107278 + for (i = 0; i < argc; ++i) {
107279 + if (!strcmp(argv[i].key, "method")) {
107280 + if (!argv[i].value) {
107281 + error(G_("no value supplied for option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
107282 + continue;
107283 + }
107284 + if (!strcmp(argv[i].value, "bts")) {
107285 + kernexec_instrument_fptr = kernexec_instrument_fptr_bts;
107286 + kernexec_instrument_retaddr = kernexec_instrument_retaddr_bts;
107287 + } else if (!strcmp(argv[i].value, "or")) {
107288 + kernexec_instrument_fptr = kernexec_instrument_fptr_or;
107289 + kernexec_instrument_retaddr = kernexec_instrument_retaddr_or;
107290 + fix_register("r12", 1, 1);
107291 + } else
107292 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
107293 + continue;
107294 + }
107295 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
107296 + }
107297 + if (!kernexec_instrument_fptr || !kernexec_instrument_retaddr)
107298 + error(G_("no instrumentation method was selected via '-fplugin-arg-%s-method'"), plugin_name);
107299 +
107300 + if (kernexec_instrument_fptr == kernexec_instrument_fptr_or)
107301 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kernexec_reload_pass_info);
107302 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kernexec_fptr_pass_info);
107303 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kernexec_retaddr_pass_info);
107304 +
107305 + return 0;
107306 +}
107307 diff --git a/tools/gcc/latent_entropy_plugin.c b/tools/gcc/latent_entropy_plugin.c
107308 new file mode 100644
107309 index 0000000..319229d
107310 --- /dev/null
107311 +++ b/tools/gcc/latent_entropy_plugin.c
107312 @@ -0,0 +1,457 @@
107313 +/*
107314 + * Copyright 2012-2014 by the PaX Team <pageexec@freemail.hu>
107315 + * Licensed under the GPL v2
107316 + *
107317 + * Note: the choice of the license means that the compilation process is
107318 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
107319 + * but for the kernel it doesn't matter since it doesn't link against
107320 + * any of the gcc libraries
107321 + *
107322 + * gcc plugin to help generate a little bit of entropy from program state,
107323 + * used throughout the uptime of the kernel
107324 + *
107325 + * TODO:
107326 + * - add ipa pass to identify not explicitly marked candidate functions
107327 + * - mix in more program state (function arguments/return values, loop variables, etc)
107328 + * - more instrumentation control via attribute parameters
107329 + *
107330 + * BUGS:
107331 + * - LTO needs -flto-partition=none for now
107332 + */
107333 +
107334 +#include "gcc-common.h"
107335 +
107336 +int plugin_is_GPL_compatible;
107337 +
107338 +static tree latent_entropy_decl;
107339 +
107340 +static struct plugin_info latent_entropy_plugin_info = {
107341 + .version = "201403280150",
107342 + .help = NULL
107343 +};
107344 +
107345 +static unsigned HOST_WIDE_INT seed;
107346 +static unsigned HOST_WIDE_INT get_random_const(void)
107347 +{
107348 + unsigned int i;
107349 + unsigned HOST_WIDE_INT ret = 0;
107350 +
107351 + for (i = 0; i < 8 * sizeof ret; i++) {
107352 + ret = (ret << 1) | (seed & 1);
107353 + seed >>= 1;
107354 + if (ret & 1)
107355 + seed ^= 0xD800000000000000ULL;
107356 + }
107357 +
107358 + return ret;
107359 +}
107360 +
107361 +static tree handle_latent_entropy_attribute(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
107362 +{
107363 + tree type;
107364 + unsigned long long mask;
107365 +#if BUILDING_GCC_VERSION <= 4007
107366 + VEC(constructor_elt, gc) *vals;
107367 +#else
107368 + vec<constructor_elt, va_gc> *vals;
107369 +#endif
107370 +
107371 + switch (TREE_CODE(*node)) {
107372 + default:
107373 + *no_add_attrs = true;
107374 + error("%qE attribute only applies to functions and variables", name);
107375 + break;
107376 +
107377 + case VAR_DECL:
107378 + if (DECL_INITIAL(*node)) {
107379 + *no_add_attrs = true;
107380 + error("variable %qD with %qE attribute must not be initialized", *node, name);
107381 + break;
107382 + }
107383 +
107384 + if (!TREE_STATIC(*node)) {
107385 + *no_add_attrs = true;
107386 + error("variable %qD with %qE attribute must not be local", *node, name);
107387 + break;
107388 + }
107389 +
107390 + type = TREE_TYPE(*node);
107391 + switch (TREE_CODE(type)) {
107392 + default:
107393 + *no_add_attrs = true;
107394 + 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);
107395 + break;
107396 +
107397 + case RECORD_TYPE: {
107398 + tree field;
107399 + unsigned int nelt = 0;
107400 +
107401 + for (field = TYPE_FIELDS(type); field; nelt++, field = TREE_CHAIN(field)) {
107402 + tree fieldtype;
107403 +
107404 + fieldtype = TREE_TYPE(field);
107405 + if (TREE_CODE(fieldtype) != INTEGER_TYPE) {
107406 + *no_add_attrs = true;
107407 + error("structure variable %qD with %qE attribute has a non-integer field %qE", *node, name, field);
107408 + break;
107409 + }
107410 + }
107411 +
107412 + if (field)
107413 + break;
107414 +
107415 +#if BUILDING_GCC_VERSION <= 4007
107416 + vals = VEC_alloc(constructor_elt, gc, nelt);
107417 +#else
107418 + vec_alloc(vals, nelt);
107419 +#endif
107420 +
107421 + for (field = TYPE_FIELDS(type); field; field = TREE_CHAIN(field)) {
107422 + tree fieldtype;
107423 +
107424 + fieldtype = TREE_TYPE(field);
107425 + mask = 1ULL << (TREE_INT_CST_LOW(TYPE_SIZE(fieldtype)) - 1);
107426 + mask = 2 * (mask - 1) + 1;
107427 +
107428 + if (TYPE_UNSIGNED(fieldtype))
107429 + CONSTRUCTOR_APPEND_ELT(vals, field, build_int_cstu(fieldtype, mask & get_random_const()));
107430 + else
107431 + CONSTRUCTOR_APPEND_ELT(vals, field, build_int_cst(fieldtype, mask & get_random_const()));
107432 + }
107433 +
107434 + DECL_INITIAL(*node) = build_constructor(type, vals);
107435 +//debug_tree(DECL_INITIAL(*node));
107436 + break;
107437 + }
107438 +
107439 + case INTEGER_TYPE:
107440 + mask = 1ULL << (TREE_INT_CST_LOW(TYPE_SIZE(type)) - 1);
107441 + mask = 2 * (mask - 1) + 1;
107442 +
107443 + if (TYPE_UNSIGNED(type))
107444 + DECL_INITIAL(*node) = build_int_cstu(type, mask & get_random_const());
107445 + else
107446 + DECL_INITIAL(*node) = build_int_cst(type, mask & get_random_const());
107447 + break;
107448 +
107449 + case ARRAY_TYPE: {
107450 + tree elt_type, array_size, elt_size;
107451 + unsigned int i, nelt;
107452 +
107453 + elt_type = TREE_TYPE(type);
107454 + elt_size = TYPE_SIZE_UNIT(TREE_TYPE(type));
107455 + array_size = TYPE_SIZE_UNIT(type);
107456 +
107457 + if (TREE_CODE(elt_type) != INTEGER_TYPE || !array_size || TREE_CODE(array_size) != INTEGER_CST) {
107458 + *no_add_attrs = true;
107459 + error("array variable %qD with %qE attribute must be a fixed length integer array type", *node, name);
107460 + break;
107461 + }
107462 +
107463 + nelt = TREE_INT_CST_LOW(array_size) / TREE_INT_CST_LOW(elt_size);
107464 +#if BUILDING_GCC_VERSION <= 4007
107465 + vals = VEC_alloc(constructor_elt, gc, nelt);
107466 +#else
107467 + vec_alloc(vals, nelt);
107468 +#endif
107469 +
107470 + mask = 1ULL << (TREE_INT_CST_LOW(TYPE_SIZE(elt_type)) - 1);
107471 + mask = 2 * (mask - 1) + 1;
107472 +
107473 + for (i = 0; i < nelt; i++)
107474 + if (TYPE_UNSIGNED(elt_type))
107475 + CONSTRUCTOR_APPEND_ELT(vals, size_int(i), build_int_cstu(elt_type, mask & get_random_const()));
107476 + else
107477 + CONSTRUCTOR_APPEND_ELT(vals, size_int(i), build_int_cst(elt_type, mask & get_random_const()));
107478 +
107479 + DECL_INITIAL(*node) = build_constructor(type, vals);
107480 +//debug_tree(DECL_INITIAL(*node));
107481 + break;
107482 + }
107483 + }
107484 + break;
107485 +
107486 + case FUNCTION_DECL:
107487 + break;
107488 + }
107489 +
107490 + return NULL_TREE;
107491 +}
107492 +
107493 +static struct attribute_spec latent_entropy_attr = {
107494 + .name = "latent_entropy",
107495 + .min_length = 0,
107496 + .max_length = 0,
107497 + .decl_required = true,
107498 + .type_required = false,
107499 + .function_type_required = false,
107500 + .handler = handle_latent_entropy_attribute,
107501 +#if BUILDING_GCC_VERSION >= 4007
107502 + .affects_type_identity = false
107503 +#endif
107504 +};
107505 +
107506 +static void register_attributes(void *event_data, void *data)
107507 +{
107508 + register_attribute(&latent_entropy_attr);
107509 +}
107510 +
107511 +static bool gate_latent_entropy(void)
107512 +{
107513 + // don't bother with noreturn functions for now
107514 + if (TREE_THIS_VOLATILE(current_function_decl))
107515 + return false;
107516 +
107517 + return lookup_attribute("latent_entropy", DECL_ATTRIBUTES(current_function_decl)) != NULL_TREE;
107518 +}
107519 +
107520 +static enum tree_code get_op(tree *rhs)
107521 +{
107522 + static enum tree_code op;
107523 + unsigned HOST_WIDE_INT random_const;
107524 +
107525 + random_const = get_random_const();
107526 +
107527 + switch (op) {
107528 + case BIT_XOR_EXPR:
107529 + op = PLUS_EXPR;
107530 + break;
107531 +
107532 + case PLUS_EXPR:
107533 + if (rhs) {
107534 + op = LROTATE_EXPR;
107535 + random_const &= HOST_BITS_PER_WIDE_INT - 1;
107536 + break;
107537 + }
107538 +
107539 + case LROTATE_EXPR:
107540 + default:
107541 + op = BIT_XOR_EXPR;
107542 + break;
107543 + }
107544 + if (rhs)
107545 + *rhs = build_int_cstu(unsigned_intDI_type_node, random_const);
107546 + return op;
107547 +}
107548 +
107549 +static void perturb_local_entropy(basic_block bb, tree local_entropy)
107550 +{
107551 + gimple_stmt_iterator gsi;
107552 + gimple assign;
107553 + tree addxorrol, rhs;
107554 + enum tree_code op;
107555 +
107556 + op = get_op(&rhs);
107557 + addxorrol = fold_build2_loc(UNKNOWN_LOCATION, op, unsigned_intDI_type_node, local_entropy, rhs);
107558 + assign = gimple_build_assign(local_entropy, addxorrol);
107559 + gsi = gsi_after_labels(bb);
107560 + gsi_insert_before(&gsi, assign, GSI_NEW_STMT);
107561 + update_stmt(assign);
107562 +//debug_bb(bb);
107563 +}
107564 +
107565 +static void perturb_latent_entropy(basic_block bb, tree rhs)
107566 +{
107567 + gimple_stmt_iterator gsi;
107568 + gimple assign;
107569 + tree addxorrol, temp;
107570 +
107571 + // 1. create temporary copy of latent_entropy
107572 + temp = create_tmp_var(unsigned_intDI_type_node, "temp_latent_entropy");
107573 + add_referenced_var(temp);
107574 +
107575 + // 2. read...
107576 + temp = make_ssa_name(temp, NULL);
107577 + assign = gimple_build_assign(temp, latent_entropy_decl);
107578 + SSA_NAME_DEF_STMT(temp) = assign;
107579 + add_referenced_var(latent_entropy_decl);
107580 + gsi = gsi_after_labels(bb);
107581 + gsi_insert_after(&gsi, assign, GSI_NEW_STMT);
107582 + update_stmt(assign);
107583 +
107584 + // 3. ...modify...
107585 + addxorrol = fold_build2_loc(UNKNOWN_LOCATION, get_op(NULL), unsigned_intDI_type_node, temp, rhs);
107586 + temp = make_ssa_name(SSA_NAME_VAR(temp), NULL);
107587 + assign = gimple_build_assign(temp, addxorrol);
107588 + SSA_NAME_DEF_STMT(temp) = assign;
107589 + gsi_insert_after(&gsi, assign, GSI_NEW_STMT);
107590 + update_stmt(assign);
107591 +
107592 + // 4. ...write latent_entropy
107593 + assign = gimple_build_assign(latent_entropy_decl, temp);
107594 + gsi_insert_after(&gsi, assign, GSI_NEW_STMT);
107595 + update_stmt(assign);
107596 +}
107597 +
107598 +static unsigned int execute_latent_entropy(void)
107599 +{
107600 + basic_block bb;
107601 + gimple assign;
107602 + gimple_stmt_iterator gsi;
107603 + tree local_entropy;
107604 +
107605 + if (!latent_entropy_decl) {
107606 + struct varpool_node *node;
107607 +
107608 + FOR_EACH_VARIABLE(node) {
107609 + tree var = NODE_DECL(node);
107610 +
107611 + if (strcmp(IDENTIFIER_POINTER(DECL_NAME(var)), "latent_entropy"))
107612 + continue;
107613 + latent_entropy_decl = var;
107614 +// debug_tree(var);
107615 + break;
107616 + }
107617 + if (!latent_entropy_decl) {
107618 +// debug_tree(current_function_decl);
107619 + return 0;
107620 + }
107621 + }
107622 +
107623 +//fprintf(stderr, "latent_entropy: %s\n", IDENTIFIER_POINTER(DECL_NAME(current_function_decl)));
107624 +
107625 + // 1. create local entropy variable
107626 + local_entropy = create_tmp_var(unsigned_intDI_type_node, "local_entropy");
107627 + add_referenced_var(local_entropy);
107628 + mark_sym_for_renaming(local_entropy);
107629 +
107630 + // 2. initialize local entropy variable
107631 + bb = split_block_after_labels(ENTRY_BLOCK_PTR_FOR_FN(cfun))->dest;
107632 + if (dom_info_available_p(CDI_DOMINATORS))
107633 + set_immediate_dominator(CDI_DOMINATORS, bb, ENTRY_BLOCK_PTR_FOR_FN(cfun));
107634 + gsi = gsi_start_bb(bb);
107635 +
107636 + assign = gimple_build_assign(local_entropy, build_int_cstu(unsigned_intDI_type_node, get_random_const()));
107637 +// gimple_set_location(assign, loc);
107638 + gsi_insert_after(&gsi, assign, GSI_NEW_STMT);
107639 + update_stmt(assign);
107640 +//debug_bb(bb);
107641 + gcc_assert(single_succ_p(bb));
107642 + bb = single_succ(bb);
107643 +
107644 + // 3. instrument each BB with an operation on the local entropy variable
107645 + while (bb != EXIT_BLOCK_PTR_FOR_FN(cfun)) {
107646 + perturb_local_entropy(bb, local_entropy);
107647 +//debug_bb(bb);
107648 + bb = bb->next_bb;
107649 + };
107650 +
107651 + // 4. mix local entropy into the global entropy variable
107652 + gcc_assert(single_pred_p(EXIT_BLOCK_PTR_FOR_FN(cfun)));
107653 + perturb_latent_entropy(single_pred(EXIT_BLOCK_PTR_FOR_FN(cfun)), local_entropy);
107654 +//debug_bb(single_pred(EXIT_BLOCK_PTR_FOR_FN(cfun)));
107655 + return 0;
107656 +}
107657 +
107658 +static void latent_entropy_start_unit(void *gcc_data, void *user_data)
107659 +{
107660 + tree latent_entropy_type;
107661 +
107662 + seed = get_random_seed(false);
107663 +
107664 + if (in_lto_p)
107665 + return;
107666 +
107667 + // extern volatile u64 latent_entropy
107668 + gcc_assert(TYPE_PRECISION(long_long_unsigned_type_node) == 64);
107669 + latent_entropy_type = build_qualified_type(long_long_unsigned_type_node, TYPE_QUALS(long_long_unsigned_type_node) | TYPE_QUAL_VOLATILE);
107670 + latent_entropy_decl = build_decl(UNKNOWN_LOCATION, VAR_DECL, get_identifier("latent_entropy"), latent_entropy_type);
107671 +
107672 + TREE_STATIC(latent_entropy_decl) = 1;
107673 + TREE_PUBLIC(latent_entropy_decl) = 1;
107674 + TREE_USED(latent_entropy_decl) = 1;
107675 + TREE_THIS_VOLATILE(latent_entropy_decl) = 1;
107676 + DECL_EXTERNAL(latent_entropy_decl) = 1;
107677 + DECL_ARTIFICIAL(latent_entropy_decl) = 1;
107678 + lang_hooks.decls.pushdecl(latent_entropy_decl);
107679 +// DECL_ASSEMBLER_NAME(latent_entropy_decl);
107680 +// varpool_finalize_decl(latent_entropy_decl);
107681 +// varpool_mark_needed_node(latent_entropy_decl);
107682 +}
107683 +
107684 +#if BUILDING_GCC_VERSION >= 4009
107685 +static const struct pass_data latent_entropy_pass_data = {
107686 +#else
107687 +static struct gimple_opt_pass latent_entropy_pass = {
107688 + .pass = {
107689 +#endif
107690 + .type = GIMPLE_PASS,
107691 + .name = "latent_entropy",
107692 +#if BUILDING_GCC_VERSION >= 4008
107693 + .optinfo_flags = OPTGROUP_NONE,
107694 +#endif
107695 +#if BUILDING_GCC_VERSION >= 4009
107696 + .has_gate = true,
107697 + .has_execute = true,
107698 +#else
107699 + .gate = gate_latent_entropy,
107700 + .execute = execute_latent_entropy,
107701 + .sub = NULL,
107702 + .next = NULL,
107703 + .static_pass_number = 0,
107704 +#endif
107705 + .tv_id = TV_NONE,
107706 + .properties_required = PROP_gimple_leh | PROP_cfg,
107707 + .properties_provided = 0,
107708 + .properties_destroyed = 0,
107709 + .todo_flags_start = 0, //TODO_verify_ssa | TODO_verify_flow | TODO_verify_stmts,
107710 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_update_ssa
107711 +#if BUILDING_GCC_VERSION < 4009
107712 + }
107713 +#endif
107714 +};
107715 +
107716 +#if BUILDING_GCC_VERSION >= 4009
107717 +namespace {
107718 +class latent_entropy_pass : public gimple_opt_pass {
107719 +public:
107720 + latent_entropy_pass() : gimple_opt_pass(latent_entropy_pass_data, g) {}
107721 + bool gate() { return gate_latent_entropy(); }
107722 + unsigned int execute() { return execute_latent_entropy(); }
107723 +};
107724 +}
107725 +#endif
107726 +
107727 +static struct opt_pass *make_latent_entropy_pass(void)
107728 +{
107729 +#if BUILDING_GCC_VERSION >= 4009
107730 + return new latent_entropy_pass();
107731 +#else
107732 + return &latent_entropy_pass.pass;
107733 +#endif
107734 +}
107735 +
107736 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
107737 +{
107738 + const char * const plugin_name = plugin_info->base_name;
107739 + struct register_pass_info latent_entropy_pass_info;
107740 +
107741 + latent_entropy_pass_info.pass = make_latent_entropy_pass();
107742 + latent_entropy_pass_info.reference_pass_name = "optimized";
107743 + latent_entropy_pass_info.ref_pass_instance_number = 1;
107744 + latent_entropy_pass_info.pos_op = PASS_POS_INSERT_BEFORE;
107745 + static const struct ggc_root_tab gt_ggc_r_gt_latent_entropy[] = {
107746 + {
107747 + .base = &latent_entropy_decl,
107748 + .nelt = 1,
107749 + .stride = sizeof(latent_entropy_decl),
107750 + .cb = &gt_ggc_mx_tree_node,
107751 + .pchw = &gt_pch_nx_tree_node
107752 + },
107753 + LAST_GGC_ROOT_TAB
107754 + };
107755 +
107756 + if (!plugin_default_version_check(version, &gcc_version)) {
107757 + error(G_("incompatible gcc/plugin versions"));
107758 + return 1;
107759 + }
107760 +
107761 + register_callback(plugin_name, PLUGIN_INFO, NULL, &latent_entropy_plugin_info);
107762 + register_callback(plugin_name, PLUGIN_START_UNIT, &latent_entropy_start_unit, NULL);
107763 + if (!in_lto_p)
107764 + register_callback(plugin_name, PLUGIN_REGISTER_GGC_ROOTS, NULL, (void *)&gt_ggc_r_gt_latent_entropy);
107765 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &latent_entropy_pass_info);
107766 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
107767 +
107768 + return 0;
107769 +}
107770 diff --git a/tools/gcc/randomize_layout_plugin.c b/tools/gcc/randomize_layout_plugin.c
107771 new file mode 100644
107772 index 0000000..8dafb22
107773 --- /dev/null
107774 +++ b/tools/gcc/randomize_layout_plugin.c
107775 @@ -0,0 +1,910 @@
107776 +/*
107777 + * Copyright 2014 by Open Source Security, Inc., Brad Spengler <spender@grsecurity.net>
107778 + * and PaX Team <pageexec@freemail.hu>
107779 + * Licensed under the GPL v2
107780 + *
107781 + * Usage:
107782 + * $ # for 4.5/4.6/C based 4.7
107783 + * $ 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
107784 + * $ # for C++ based 4.7/4.8+
107785 + * $ 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
107786 + * $ gcc -fplugin=./randomize_layout_plugin.so test.c -O2
107787 + */
107788 +
107789 +#include "gcc-common.h"
107790 +#include "randomize_layout_seed.h"
107791 +
107792 +#if BUILDING_GCC_MAJOR < 4 || BUILDING_GCC_MINOR < 6 || (BUILDING_GCC_MINOR == 6 && BUILDING_GCC_PATCHLEVEL < 4)
107793 +#error "The RANDSTRUCT plugin requires GCC 4.6.4 or newer."
107794 +#endif
107795 +
107796 +#define ORIG_TYPE_NAME(node) \
107797 + (TYPE_NAME(TYPE_MAIN_VARIANT(node)) != NULL_TREE ? ((const unsigned char *)IDENTIFIER_POINTER(TYPE_NAME(TYPE_MAIN_VARIANT(node)))) : (const unsigned char *)"anonymous")
107798 +
107799 +int plugin_is_GPL_compatible;
107800 +
107801 +static int performance_mode;
107802 +
107803 +static struct plugin_info randomize_layout_plugin_info = {
107804 + .version = "201402201816",
107805 + .help = "disable\t\t\tdo not activate plugin\n"
107806 + "performance-mode\tenable cacheline-aware layout randomization\n"
107807 +};
107808 +
107809 +/* from old Linux dcache.h */
107810 +static inline unsigned long
107811 +partial_name_hash(unsigned long c, unsigned long prevhash)
107812 +{
107813 + return (prevhash + (c << 4) + (c >> 4)) * 11;
107814 +}
107815 +static inline unsigned int
107816 +name_hash(const unsigned char *name)
107817 +{
107818 + unsigned long hash = 0;
107819 + unsigned int len = strlen((const char *)name);
107820 + while (len--)
107821 + hash = partial_name_hash(*name++, hash);
107822 + return (unsigned int)hash;
107823 +}
107824 +
107825 +static tree handle_randomize_layout_attr(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
107826 +{
107827 + tree type;
107828 +
107829 + *no_add_attrs = true;
107830 + if (TREE_CODE(*node) == FUNCTION_DECL) {
107831 + error("%qE attribute does not apply to functions (%qF)", name, *node);
107832 + return NULL_TREE;
107833 + }
107834 +
107835 + if (TREE_CODE(*node) == PARM_DECL) {
107836 + error("%qE attribute does not apply to function parameters (%qD)", name, *node);
107837 + return NULL_TREE;
107838 + }
107839 +
107840 + if (TREE_CODE(*node) == VAR_DECL) {
107841 + error("%qE attribute does not apply to variables (%qD)", name, *node);
107842 + return NULL_TREE;
107843 + }
107844 +
107845 + if (TYPE_P(*node)) {
107846 + type = *node;
107847 + } else {
107848 + gcc_assert(TREE_CODE(*node) == TYPE_DECL);
107849 + type = TREE_TYPE(*node);
107850 + }
107851 +
107852 + if (TREE_CODE(type) != RECORD_TYPE) {
107853 + error("%qE attribute used on %qT applies to struct types only", name, type);
107854 + return NULL_TREE;
107855 + }
107856 +
107857 + if (lookup_attribute(IDENTIFIER_POINTER(name), TYPE_ATTRIBUTES(type))) {
107858 + error("%qE attribute is already applied to the type %qT", name, type);
107859 + return NULL_TREE;
107860 + }
107861 +
107862 + *no_add_attrs = false;
107863 +
107864 + return NULL_TREE;
107865 +}
107866 +
107867 +/* set on complete types that we don't need to inspect further at all */
107868 +static tree handle_randomize_considered_attr(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
107869 +{
107870 + *no_add_attrs = false;
107871 + return NULL_TREE;
107872 +}
107873 +
107874 +/*
107875 + * set on types that we've performed a shuffle on, to prevent re-shuffling
107876 + * this does not preclude us from inspecting its fields for potential shuffles
107877 + */
107878 +static tree handle_randomize_performed_attr(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
107879 +{
107880 + *no_add_attrs = false;
107881 + return NULL_TREE;
107882 +}
107883 +
107884 +/*
107885 + * 64bit variant of Bob Jenkins' public domain PRNG
107886 + * 256 bits of internal state
107887 + */
107888 +
107889 +typedef unsigned long long u64;
107890 +
107891 +typedef struct ranctx { u64 a; u64 b; u64 c; u64 d; } ranctx;
107892 +
107893 +#define rot(x,k) (((x)<<(k))|((x)>>(64-(k))))
107894 +static u64 ranval(ranctx *x) {
107895 + u64 e = x->a - rot(x->b, 7);
107896 + x->a = x->b ^ rot(x->c, 13);
107897 + x->b = x->c + rot(x->d, 37);
107898 + x->c = x->d + e;
107899 + x->d = e + x->a;
107900 + return x->d;
107901 +}
107902 +
107903 +static void raninit(ranctx *x, u64 *seed) {
107904 + int i;
107905 +
107906 + x->a = seed[0];
107907 + x->b = seed[1];
107908 + x->c = seed[2];
107909 + x->d = seed[3];
107910 +
107911 + for (i=0; i < 30; ++i)
107912 + (void)ranval(x);
107913 +}
107914 +
107915 +static u64 shuffle_seed[4];
107916 +
107917 +struct partition_group {
107918 + tree tree_start;
107919 + unsigned long start;
107920 + unsigned long length;
107921 +};
107922 +
107923 +static void partition_struct(tree *fields, unsigned long length, struct partition_group *size_groups, unsigned long *num_groups)
107924 +{
107925 + unsigned long i;
107926 + unsigned long accum_size = 0;
107927 + unsigned long accum_length = 0;
107928 + unsigned long group_idx = 0;
107929 +
107930 + gcc_assert(length < INT_MAX);
107931 +
107932 + memset(size_groups, 0, sizeof(struct partition_group) * length);
107933 +
107934 + for (i = 0; i < length; i++) {
107935 + if (size_groups[group_idx].tree_start == NULL_TREE) {
107936 + size_groups[group_idx].tree_start = fields[i];
107937 + size_groups[group_idx].start = i;
107938 + accum_length = 0;
107939 + accum_size = 0;
107940 + }
107941 + accum_size += (unsigned long)int_size_in_bytes(TREE_TYPE(fields[i]));
107942 + accum_length++;
107943 + if (accum_size >= 64) {
107944 + size_groups[group_idx].length = accum_length;
107945 + accum_length = 0;
107946 + group_idx++;
107947 + }
107948 + }
107949 +
107950 + if (size_groups[group_idx].tree_start != NULL_TREE &&
107951 + !size_groups[group_idx].length) {
107952 + size_groups[group_idx].length = accum_length;
107953 + group_idx++;
107954 + }
107955 +
107956 + *num_groups = group_idx;
107957 +}
107958 +
107959 +static void performance_shuffle(tree *newtree, unsigned long length, ranctx *prng_state)
107960 +{
107961 + unsigned long i, x;
107962 + struct partition_group size_group[length];
107963 + unsigned long num_groups = 0;
107964 + unsigned long randnum;
107965 +
107966 + partition_struct(newtree, length, (struct partition_group *)&size_group, &num_groups);
107967 + for (i = num_groups - 1; i > 0; i--) {
107968 + struct partition_group tmp;
107969 + randnum = ranval(prng_state) % (i + 1);
107970 + tmp = size_group[i];
107971 + size_group[i] = size_group[randnum];
107972 + size_group[randnum] = tmp;
107973 + }
107974 +
107975 + for (x = 0; x < num_groups; x++) {
107976 + for (i = size_group[x].start + size_group[x].length - 1; i > size_group[x].start; i--) {
107977 + tree tmp;
107978 + if (DECL_BIT_FIELD_TYPE(newtree[i]))
107979 + continue;
107980 + randnum = ranval(prng_state) % (i + 1);
107981 + // we could handle this case differently if desired
107982 + if (DECL_BIT_FIELD_TYPE(newtree[randnum]))
107983 + continue;
107984 + tmp = newtree[i];
107985 + newtree[i] = newtree[randnum];
107986 + newtree[randnum] = tmp;
107987 + }
107988 + }
107989 +}
107990 +
107991 +static void full_shuffle(tree *newtree, unsigned long length, ranctx *prng_state)
107992 +{
107993 + unsigned long i, randnum;
107994 +
107995 + for (i = length - 1; i > 0; i--) {
107996 + tree tmp;
107997 + randnum = ranval(prng_state) % (i + 1);
107998 + tmp = newtree[i];
107999 + newtree[i] = newtree[randnum];
108000 + newtree[randnum] = tmp;
108001 + }
108002 +}
108003 +
108004 +/* modern in-place Fisher-Yates shuffle */
108005 +static void shuffle(const_tree type, tree *newtree, unsigned long length)
108006 +{
108007 + unsigned long i;
108008 + u64 seed[4];
108009 + ranctx prng_state;
108010 + const unsigned char *structname;
108011 +
108012 + if (length == 0)
108013 + return;
108014 +
108015 + gcc_assert(TREE_CODE(type) == RECORD_TYPE);
108016 +
108017 + structname = ORIG_TYPE_NAME(type);
108018 +
108019 +#ifdef __DEBUG_PLUGIN
108020 + fprintf(stderr, "Shuffling struct %s %p\n", (const char *)structname, type);
108021 +#ifdef __DEBUG_VERBOSE
108022 + debug_tree((tree)type);
108023 +#endif
108024 +#endif
108025 +
108026 + for (i = 0; i < 4; i++) {
108027 + seed[i] = shuffle_seed[i];
108028 + seed[i] ^= name_hash(structname);
108029 + }
108030 +
108031 + raninit(&prng_state, (u64 *)&seed);
108032 +
108033 + if (performance_mode)
108034 + performance_shuffle(newtree, length, &prng_state);
108035 + else
108036 + full_shuffle(newtree, length, &prng_state);
108037 +}
108038 +
108039 +static bool is_flexible_array(const_tree field)
108040 +{
108041 + const_tree fieldtype;
108042 + const_tree typesize;
108043 + const_tree elemtype;
108044 + const_tree elemsize;
108045 +
108046 + fieldtype = TREE_TYPE(field);
108047 + typesize = TYPE_SIZE(fieldtype);
108048 +
108049 + if (TREE_CODE(fieldtype) != ARRAY_TYPE)
108050 + return false;
108051 +
108052 + elemtype = TREE_TYPE(fieldtype);
108053 + elemsize = TYPE_SIZE(elemtype);
108054 +
108055 + /* size of type is represented in bits */
108056 +
108057 + if (typesize == NULL_TREE && TYPE_DOMAIN(fieldtype) != NULL_TREE &&
108058 + TYPE_MAX_VALUE(TYPE_DOMAIN(fieldtype)) == NULL_TREE)
108059 + return true;
108060 +
108061 + if (typesize != NULL_TREE &&
108062 + (TREE_CONSTANT(typesize) && (!TREE_INT_CST_LOW(typesize) ||
108063 + TREE_INT_CST_LOW(typesize) == TREE_INT_CST_LOW(elemsize))))
108064 + return true;
108065 +
108066 + return false;
108067 +}
108068 +
108069 +static int relayout_struct(tree type)
108070 +{
108071 + unsigned long num_fields = (unsigned long)list_length(TYPE_FIELDS(type));
108072 + unsigned long shuffle_length = num_fields;
108073 + tree field;
108074 + tree newtree[num_fields];
108075 + unsigned long i;
108076 + tree list;
108077 + tree variant;
108078 + expanded_location xloc;
108079 +
108080 + if (TYPE_FIELDS(type) == NULL_TREE)
108081 + return 0;
108082 +
108083 + if (num_fields < 2)
108084 + return 0;
108085 +
108086 + gcc_assert(TREE_CODE(type) == RECORD_TYPE);
108087 +
108088 + gcc_assert(num_fields < INT_MAX);
108089 +
108090 + if (lookup_attribute("randomize_performed", TYPE_ATTRIBUTES(type)) ||
108091 + lookup_attribute("no_randomize_layout", TYPE_ATTRIBUTES(TYPE_MAIN_VARIANT(type))))
108092 + return 0;
108093 +
108094 + /* throw out any structs in uapi */
108095 + xloc = expand_location(DECL_SOURCE_LOCATION(TYPE_FIELDS(type)));
108096 +
108097 + if (strstr(xloc.file, "/uapi/"))
108098 + error(G_("attempted to randomize userland API struct %s"), ORIG_TYPE_NAME(type));
108099 +
108100 + for (field = TYPE_FIELDS(type), i = 0; field; field = TREE_CHAIN(field), i++) {
108101 + gcc_assert(TREE_CODE(field) == FIELD_DECL);
108102 + newtree[i] = field;
108103 + }
108104 +
108105 + /*
108106 + * enforce that we don't randomize the layout of the last
108107 + * element of a struct if it's a 0 or 1-length array
108108 + * or a proper flexible array
108109 + */
108110 + if (is_flexible_array(newtree[num_fields - 1]))
108111 + shuffle_length--;
108112 +
108113 + shuffle(type, (tree *)newtree, shuffle_length);
108114 +
108115 + /*
108116 + * set up a bogus anonymous struct field designed to error out on unnamed struct initializers
108117 + * as gcc provides no other way to detect such code
108118 + */
108119 + list = make_node(FIELD_DECL);
108120 + TREE_CHAIN(list) = newtree[0];
108121 + TREE_TYPE(list) = void_type_node;
108122 + DECL_SIZE(list) = bitsize_zero_node;
108123 + DECL_NONADDRESSABLE_P(list) = 1;
108124 + DECL_FIELD_BIT_OFFSET(list) = bitsize_zero_node;
108125 + DECL_SIZE_UNIT(list) = size_zero_node;
108126 + DECL_FIELD_OFFSET(list) = size_zero_node;
108127 + // to satisfy the constify plugin
108128 + TREE_READONLY(list) = 1;
108129 +
108130 + for (i = 0; i < num_fields - 1; i++)
108131 + TREE_CHAIN(newtree[i]) = newtree[i+1];
108132 + TREE_CHAIN(newtree[num_fields - 1]) = NULL_TREE;
108133 +
108134 + for (variant = TYPE_MAIN_VARIANT(type); variant; variant = TYPE_NEXT_VARIANT(variant)) {
108135 + TYPE_FIELDS(variant) = list;
108136 + TYPE_ATTRIBUTES(variant) = copy_list(TYPE_ATTRIBUTES(variant));
108137 + TYPE_ATTRIBUTES(variant) = tree_cons(get_identifier("randomize_performed"), NULL_TREE, TYPE_ATTRIBUTES(variant));
108138 + // force a re-layout
108139 + TYPE_SIZE(variant) = NULL_TREE;
108140 + layout_type(variant);
108141 + }
108142 +
108143 + return 1;
108144 +}
108145 +
108146 +/* from constify plugin */
108147 +static const_tree get_field_type(const_tree field)
108148 +{
108149 + return strip_array_types(TREE_TYPE(field));
108150 +}
108151 +
108152 +/* from constify plugin */
108153 +static bool is_fptr(const_tree fieldtype)
108154 +{
108155 + if (TREE_CODE(fieldtype) != POINTER_TYPE)
108156 + return false;
108157 +
108158 + return TREE_CODE(TREE_TYPE(fieldtype)) == FUNCTION_TYPE;
108159 +}
108160 +
108161 +/* derived from constify plugin */
108162 +static int is_pure_ops_struct(const_tree node)
108163 +{
108164 + const_tree field;
108165 +
108166 + gcc_assert(TREE_CODE(node) == RECORD_TYPE || TREE_CODE(node) == UNION_TYPE);
108167 +
108168 + for (field = TYPE_FIELDS(node); field; field = TREE_CHAIN(field)) {
108169 + const_tree fieldtype = get_field_type(field);
108170 + enum tree_code code = TREE_CODE(fieldtype);
108171 +
108172 + if (node == fieldtype)
108173 + continue;
108174 +
108175 + if (!is_fptr(fieldtype))
108176 + return 0;
108177 +
108178 + if (code != RECORD_TYPE && code != UNION_TYPE)
108179 + continue;
108180 +
108181 + if (!is_pure_ops_struct(fieldtype))
108182 + return 0;
108183 + }
108184 +
108185 + return 1;
108186 +}
108187 +
108188 +static void randomize_type(tree type)
108189 +{
108190 + tree variant;
108191 +
108192 + gcc_assert(TREE_CODE(type) == RECORD_TYPE);
108193 +
108194 + if (lookup_attribute("randomize_considered", TYPE_ATTRIBUTES(type)))
108195 + return;
108196 +
108197 + if (lookup_attribute("randomize_layout", TYPE_ATTRIBUTES(TYPE_MAIN_VARIANT(type))) || is_pure_ops_struct(type))
108198 + relayout_struct(type);
108199 +
108200 + for (variant = TYPE_MAIN_VARIANT(type); variant; variant = TYPE_NEXT_VARIANT(variant)) {
108201 + TYPE_ATTRIBUTES(type) = copy_list(TYPE_ATTRIBUTES(type));
108202 + TYPE_ATTRIBUTES(type) = tree_cons(get_identifier("randomize_considered"), NULL_TREE, TYPE_ATTRIBUTES(type));
108203 + }
108204 +#ifdef __DEBUG_PLUGIN
108205 + fprintf(stderr, "Marking randomize_considered on struct %s\n", ORIG_TYPE_NAME(type));
108206 +#ifdef __DEBUG_VERBOSE
108207 + debug_tree(type);
108208 +#endif
108209 +#endif
108210 +}
108211 +
108212 +static void randomize_layout_finish_decl(void *event_data, void *data)
108213 +{
108214 + tree decl = (tree)event_data;
108215 + tree type;
108216 +
108217 + if (decl == NULL_TREE || decl == error_mark_node)
108218 + return;
108219 +
108220 + type = TREE_TYPE(decl);
108221 +
108222 + if (TREE_CODE(decl) != VAR_DECL)
108223 + return;
108224 +
108225 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE)
108226 + return;
108227 +
108228 + if (!lookup_attribute("randomize_performed", TYPE_ATTRIBUTES(type)))
108229 + return;
108230 +
108231 + relayout_decl(decl);
108232 +}
108233 +
108234 +static void finish_type(void *event_data, void *data)
108235 +{
108236 + tree type = (tree)event_data;
108237 +
108238 + if (type == NULL_TREE || type == error_mark_node)
108239 + return;
108240 +
108241 + if (TREE_CODE(type) != RECORD_TYPE)
108242 + return;
108243 +
108244 + if (TYPE_FIELDS(type) == NULL_TREE)
108245 + return;
108246 +
108247 + if (lookup_attribute("randomize_considered", TYPE_ATTRIBUTES(type)))
108248 + return;
108249 +
108250 +#ifdef __DEBUG_PLUGIN
108251 + fprintf(stderr, "Calling randomize_type on %s\n", ORIG_TYPE_NAME(type));
108252 +#endif
108253 +#ifdef __DEBUG_VERBOSE
108254 + debug_tree(type);
108255 +#endif
108256 + randomize_type(type);
108257 +
108258 + return;
108259 +}
108260 +
108261 +static struct attribute_spec randomize_layout_attr = {
108262 + .name = "randomize_layout",
108263 + // related to args
108264 + .min_length = 0,
108265 + .max_length = 0,
108266 + .decl_required = false,
108267 + // need type declaration
108268 + .type_required = true,
108269 + .function_type_required = false,
108270 + .handler = handle_randomize_layout_attr,
108271 +#if BUILDING_GCC_VERSION >= 4007
108272 + .affects_type_identity = true
108273 +#endif
108274 +};
108275 +
108276 +static struct attribute_spec no_randomize_layout_attr = {
108277 + .name = "no_randomize_layout",
108278 + // related to args
108279 + .min_length = 0,
108280 + .max_length = 0,
108281 + .decl_required = false,
108282 + // need type declaration
108283 + .type_required = true,
108284 + .function_type_required = false,
108285 + .handler = handle_randomize_layout_attr,
108286 +#if BUILDING_GCC_VERSION >= 4007
108287 + .affects_type_identity = true
108288 +#endif
108289 +};
108290 +
108291 +static struct attribute_spec randomize_considered_attr = {
108292 + .name = "randomize_considered",
108293 + // related to args
108294 + .min_length = 0,
108295 + .max_length = 0,
108296 + .decl_required = false,
108297 + // need type declaration
108298 + .type_required = true,
108299 + .function_type_required = false,
108300 + .handler = handle_randomize_considered_attr,
108301 +#if BUILDING_GCC_VERSION >= 4007
108302 + .affects_type_identity = false
108303 +#endif
108304 +};
108305 +
108306 +static struct attribute_spec randomize_performed_attr = {
108307 + .name = "randomize_performed",
108308 + // related to args
108309 + .min_length = 0,
108310 + .max_length = 0,
108311 + .decl_required = false,
108312 + // need type declaration
108313 + .type_required = true,
108314 + .function_type_required = false,
108315 + .handler = handle_randomize_performed_attr,
108316 +#if BUILDING_GCC_VERSION >= 4007
108317 + .affects_type_identity = false
108318 +#endif
108319 +};
108320 +
108321 +static void register_attributes(void *event_data, void *data)
108322 +{
108323 + register_attribute(&randomize_layout_attr);
108324 + register_attribute(&no_randomize_layout_attr);
108325 + register_attribute(&randomize_considered_attr);
108326 + register_attribute(&randomize_performed_attr);
108327 +}
108328 +
108329 +static void check_bad_casts_in_constructor(tree var, tree init)
108330 +{
108331 + unsigned HOST_WIDE_INT idx;
108332 + tree field, val;
108333 + tree field_type, val_type;
108334 +
108335 + FOR_EACH_CONSTRUCTOR_ELT(CONSTRUCTOR_ELTS(init), idx, field, val) {
108336 + if (TREE_CODE(val) == CONSTRUCTOR) {
108337 + check_bad_casts_in_constructor(var, val);
108338 + continue;
108339 + }
108340 +
108341 + /* pipacs' plugin creates franken-arrays that differ from those produced by
108342 + normal code which all have valid 'field' trees. work around this */
108343 + if (field == NULL_TREE)
108344 + continue;
108345 + field_type = TREE_TYPE(field);
108346 + val_type = TREE_TYPE(val);
108347 +
108348 + if (TREE_CODE(field_type) != POINTER_TYPE || TREE_CODE(val_type) != POINTER_TYPE)
108349 + continue;
108350 +
108351 + if (field_type == val_type)
108352 + continue;
108353 +
108354 + field_type = TYPE_MAIN_VARIANT(strip_array_types(TYPE_MAIN_VARIANT(TREE_TYPE(field_type))));
108355 + val_type = TYPE_MAIN_VARIANT(strip_array_types(TYPE_MAIN_VARIANT(TREE_TYPE(val_type))));
108356 +
108357 + if (field_type == void_type_node)
108358 + continue;
108359 + if (field_type == val_type)
108360 + continue;
108361 + if (TREE_CODE(val_type) != RECORD_TYPE)
108362 + continue;
108363 +
108364 + if (!lookup_attribute("randomize_performed", TYPE_ATTRIBUTES(val_type)))
108365 + continue;
108366 + inform(DECL_SOURCE_LOCATION(var), "found mismatched struct pointer types: %qT and %qT\n", TYPE_MAIN_VARIANT(field_type), TYPE_MAIN_VARIANT(val_type));
108367 + }
108368 +}
108369 +
108370 +/* derived from the constify plugin */
108371 +static void check_global_variables(void *event_data, void *data)
108372 +{
108373 + struct varpool_node *node;
108374 + tree init;
108375 +
108376 + FOR_EACH_VARIABLE(node) {
108377 + tree var = NODE_DECL(node);
108378 + init = DECL_INITIAL(var);
108379 + if (init == NULL_TREE)
108380 + continue;
108381 +
108382 + if (TREE_CODE(init) != CONSTRUCTOR)
108383 + continue;
108384 +
108385 + check_bad_casts_in_constructor(var, init);
108386 + }
108387 +}
108388 +
108389 +static bool dominated_by_is_err(const_tree rhs, basic_block bb)
108390 +{
108391 + basic_block dom;
108392 + gimple dom_stmt;
108393 + gimple call_stmt;
108394 + const_tree dom_lhs;
108395 + const_tree poss_is_err_cond;
108396 + const_tree poss_is_err_func;
108397 + const_tree is_err_arg;
108398 +
108399 + dom = get_immediate_dominator(CDI_DOMINATORS, bb);
108400 + if (!dom)
108401 + return false;
108402 +
108403 + dom_stmt = last_stmt(dom);
108404 + if (!dom_stmt)
108405 + return false;
108406 +
108407 + if (gimple_code(dom_stmt) != GIMPLE_COND)
108408 + return false;
108409 +
108410 + if (gimple_cond_code(dom_stmt) != NE_EXPR)
108411 + return false;
108412 +
108413 + if (!integer_zerop(gimple_cond_rhs(dom_stmt)))
108414 + return false;
108415 +
108416 + poss_is_err_cond = gimple_cond_lhs(dom_stmt);
108417 +
108418 + if (TREE_CODE(poss_is_err_cond) != SSA_NAME)
108419 + return false;
108420 +
108421 + call_stmt = SSA_NAME_DEF_STMT(poss_is_err_cond);
108422 +
108423 + if (gimple_code(call_stmt) != GIMPLE_CALL)
108424 + return false;
108425 +
108426 + dom_lhs = gimple_get_lhs(call_stmt);
108427 + poss_is_err_func = gimple_call_fndecl(call_stmt);
108428 + if (!poss_is_err_func)
108429 + return false;
108430 + if (dom_lhs != poss_is_err_cond)
108431 + return false;
108432 + if (strcmp(DECL_NAME_POINTER(poss_is_err_func), "IS_ERR"))
108433 + return false;
108434 +
108435 + is_err_arg = gimple_call_arg(call_stmt, 0);
108436 + if (!is_err_arg)
108437 + return false;
108438 +
108439 + if (is_err_arg != rhs)
108440 + return false;
108441 +
108442 + return true;
108443 +}
108444 +
108445 +static void handle_local_var_initializers(void)
108446 +{
108447 + tree var;
108448 + unsigned int i;
108449 +
108450 + FOR_EACH_LOCAL_DECL(cfun, i, var) {
108451 + tree init = DECL_INITIAL(var);
108452 + if (!init)
108453 + continue;
108454 + if (TREE_CODE(init) != CONSTRUCTOR)
108455 + continue;
108456 + check_bad_casts_in_constructor(var, init);
108457 + }
108458 +}
108459 +
108460 +/*
108461 + * iterate over all statements to find "bad" casts:
108462 + * those where the address of the start of a structure is cast
108463 + * to a pointer of a structure of a different type, or a
108464 + * structure pointer type is cast to a different structure pointer type
108465 + */
108466 +static unsigned int find_bad_casts(void)
108467 +{
108468 + basic_block bb;
108469 +
108470 + handle_local_var_initializers();
108471 +
108472 + FOR_ALL_BB_FN(bb, cfun) {
108473 + gimple_stmt_iterator gsi;
108474 +
108475 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
108476 + gimple stmt;
108477 + const_tree lhs;
108478 + const_tree lhs_type;
108479 + const_tree rhs1;
108480 + const_tree rhs_type;
108481 + const_tree ptr_lhs_type;
108482 + const_tree ptr_rhs_type;
108483 + const_tree op0;
108484 + const_tree op0_type;
108485 + enum tree_code rhs_code;
108486 +
108487 + stmt = gsi_stmt(gsi);
108488 +
108489 +#ifdef __DEBUG_PLUGIN
108490 +#ifdef __DEBUG_VERBOSE
108491 + debug_gimple_stmt(stmt);
108492 + debug_tree(gimple_get_lhs(stmt));
108493 +#endif
108494 +#endif
108495 +
108496 + if (gimple_code(stmt) != GIMPLE_ASSIGN)
108497 + continue;
108498 +
108499 +#ifdef __DEBUG_PLUGIN
108500 +#ifdef __DEBUG_VERBOSE
108501 + debug_tree(gimple_assign_rhs1(stmt));
108502 +#endif
108503 +#endif
108504 +
108505 + rhs_code = gimple_assign_rhs_code(stmt);
108506 +
108507 + if (rhs_code != ADDR_EXPR && rhs_code != SSA_NAME)
108508 + continue;
108509 +
108510 + lhs = gimple_get_lhs(stmt);
108511 + lhs_type = TREE_TYPE(lhs);
108512 + rhs1 = gimple_assign_rhs1(stmt);
108513 + rhs_type = TREE_TYPE(rhs1);
108514 +
108515 + if (TREE_CODE(rhs_type) != POINTER_TYPE ||
108516 + TREE_CODE(lhs_type) != POINTER_TYPE)
108517 + continue;
108518 +
108519 + ptr_lhs_type = TYPE_MAIN_VARIANT(strip_array_types(TYPE_MAIN_VARIANT(TREE_TYPE(lhs_type))));
108520 + ptr_rhs_type = TYPE_MAIN_VARIANT(strip_array_types(TYPE_MAIN_VARIANT(TREE_TYPE(rhs_type))));
108521 +
108522 + if (ptr_rhs_type == void_type_node)
108523 + continue;
108524 +
108525 + if (ptr_lhs_type == void_type_node)
108526 + continue;
108527 +
108528 + if (dominated_by_is_err(rhs1, bb))
108529 + continue;
108530 +
108531 + if (TREE_CODE(ptr_rhs_type) != RECORD_TYPE) {
108532 +#ifndef __DEBUG_PLUGIN
108533 + if (lookup_attribute("randomize_performed", TYPE_ATTRIBUTES(ptr_lhs_type)))
108534 +#endif
108535 + inform(gimple_location(stmt), "found mismatched struct pointer types: %qT and %qT\n", ptr_lhs_type, ptr_rhs_type);
108536 + continue;
108537 + }
108538 +
108539 + if (rhs_code == SSA_NAME && ptr_lhs_type == ptr_rhs_type)
108540 + continue;
108541 +
108542 + if (rhs_code == ADDR_EXPR) {
108543 + op0 = TREE_OPERAND(rhs1, 0);
108544 +
108545 + if (op0 == NULL_TREE)
108546 + continue;
108547 +
108548 + if (TREE_CODE(op0) != VAR_DECL)
108549 + continue;
108550 +
108551 + op0_type = TYPE_MAIN_VARIANT(strip_array_types(TYPE_MAIN_VARIANT(TREE_TYPE(op0))));
108552 + if (op0_type == ptr_lhs_type)
108553 + continue;
108554 +
108555 +#ifndef __DEBUG_PLUGIN
108556 + if (lookup_attribute("randomize_performed", TYPE_ATTRIBUTES(op0_type)))
108557 +#endif
108558 + inform(gimple_location(stmt), "found mismatched struct pointer types: %qT and %qT\n", ptr_lhs_type, op0_type);
108559 + } else {
108560 + const_tree ssa_name_var = SSA_NAME_VAR(rhs1);
108561 + /* skip bogus type casts introduced by container_of */
108562 + if (ssa_name_var != NULL_TREE && DECL_NAME(ssa_name_var) &&
108563 + !strcmp((const char *)DECL_NAME_POINTER(ssa_name_var), "__mptr"))
108564 + continue;
108565 +#ifndef __DEBUG_PLUGIN
108566 + if (lookup_attribute("randomize_performed", TYPE_ATTRIBUTES(ptr_rhs_type)))
108567 +#endif
108568 + inform(gimple_location(stmt), "found mismatched struct pointer types: %qT and %qT\n", ptr_lhs_type, ptr_rhs_type);
108569 + }
108570 +
108571 + }
108572 + }
108573 + return 0;
108574 +}
108575 +
108576 +#if BUILDING_GCC_VERSION >= 4009
108577 +static const struct pass_data randomize_layout_bad_cast_data = {
108578 +#else
108579 +static struct gimple_opt_pass randomize_layout_bad_cast = {
108580 + .pass = {
108581 +#endif
108582 + .type = GIMPLE_PASS,
108583 + .name = "randomize_layout_bad_cast",
108584 +#if BUILDING_GCC_VERSION >= 4008
108585 + .optinfo_flags = OPTGROUP_NONE,
108586 +#endif
108587 +#if BUILDING_GCC_VERSION >= 4009
108588 + .has_gate = false,
108589 + .has_execute = true,
108590 +#else
108591 + .gate = NULL,
108592 + .execute = find_bad_casts,
108593 + .sub = NULL,
108594 + .next = NULL,
108595 + .static_pass_number = 0,
108596 +#endif
108597 + .tv_id = TV_NONE,
108598 + .properties_required = PROP_cfg,
108599 + .properties_provided = 0,
108600 + .properties_destroyed = 0,
108601 + .todo_flags_start = 0,
108602 + .todo_flags_finish = TODO_dump_func
108603 +#if BUILDING_GCC_VERSION < 4009
108604 + }
108605 +#endif
108606 +};
108607 +
108608 +#if BUILDING_GCC_VERSION >= 4009
108609 +namespace {
108610 +class randomize_layout_bad_cast : public gimple_opt_pass {
108611 +public:
108612 + randomize_layout_bad_cast() : gimple_opt_pass(randomize_layout_bad_cast_data, g) {}
108613 + unsigned int execute() { return find_bad_casts(); }
108614 +};
108615 +}
108616 +#endif
108617 +
108618 +static struct opt_pass *make_randomize_layout_bad_cast(void)
108619 +{
108620 +#if BUILDING_GCC_VERSION >= 4009
108621 + return new randomize_layout_bad_cast();
108622 +#else
108623 + return &randomize_layout_bad_cast.pass;
108624 +#endif
108625 +}
108626 +
108627 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
108628 +{
108629 + int i;
108630 + const char * const plugin_name = plugin_info->base_name;
108631 + const int argc = plugin_info->argc;
108632 + const struct plugin_argument * const argv = plugin_info->argv;
108633 + bool enable = true;
108634 + int obtained_seed = 0;
108635 + struct register_pass_info randomize_layout_bad_cast_info;
108636 +
108637 + randomize_layout_bad_cast_info.pass = make_randomize_layout_bad_cast();
108638 + randomize_layout_bad_cast_info.reference_pass_name = "ssa";
108639 + randomize_layout_bad_cast_info.ref_pass_instance_number = 1;
108640 + randomize_layout_bad_cast_info.pos_op = PASS_POS_INSERT_AFTER;
108641 +
108642 + if (!plugin_default_version_check(version, &gcc_version)) {
108643 + error(G_("incompatible gcc/plugin versions"));
108644 + return 1;
108645 + }
108646 +
108647 + if (strcmp(lang_hooks.name, "GNU C")) {
108648 + inform(UNKNOWN_LOCATION, G_("%s supports C only"), plugin_name);
108649 + enable = false;
108650 + }
108651 +
108652 + for (i = 0; i < argc; ++i) {
108653 + if (!strcmp(argv[i].key, "disable")) {
108654 + enable = false;
108655 + continue;
108656 + }
108657 + if (!strcmp(argv[i].key, "performance-mode")) {
108658 + performance_mode = 1;
108659 + continue;
108660 + }
108661 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
108662 + }
108663 +
108664 + if (strlen(randstruct_seed) != 64) {
108665 + error(G_("invalid seed value supplied for %s plugin"), plugin_name);
108666 + return 1;
108667 + }
108668 + obtained_seed = sscanf(randstruct_seed, "%016llx%016llx%016llx%016llx",
108669 + &shuffle_seed[0], &shuffle_seed[1], &shuffle_seed[2], &shuffle_seed[3]);
108670 + if (obtained_seed != 4) {
108671 + error(G_("Invalid seed supplied for %s plugin"), plugin_name);
108672 + return 1;
108673 + }
108674 +
108675 + register_callback(plugin_name, PLUGIN_INFO, NULL, &randomize_layout_plugin_info);
108676 + if (enable) {
108677 + register_callback(plugin_name, PLUGIN_ALL_IPA_PASSES_START, check_global_variables, NULL);
108678 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &randomize_layout_bad_cast_info);
108679 + register_callback(plugin_name, PLUGIN_FINISH_TYPE, finish_type, NULL);
108680 + register_callback(plugin_name, PLUGIN_FINISH_DECL, randomize_layout_finish_decl, NULL);
108681 + }
108682 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
108683 +
108684 + return 0;
108685 +}
108686 diff --git a/tools/gcc/size_overflow_hash.data b/tools/gcc/size_overflow_hash.data
108687 new file mode 100644
108688 index 0000000..9529806
108689 --- /dev/null
108690 +++ b/tools/gcc/size_overflow_hash.data
108691 @@ -0,0 +1,5709 @@
108692 +intel_fake_agp_alloc_by_type_1 intel_fake_agp_alloc_by_type 1 1 NULL
108693 +ocfs2_get_refcount_tree_3 ocfs2_get_refcount_tree 0 3 NULL
108694 +storvsc_connect_to_vsp_22 storvsc_connect_to_vsp 2 22 NULL
108695 +compat_sock_setsockopt_23 compat_sock_setsockopt 5 23 NULL
108696 +carl9170_alloc_27 carl9170_alloc 1 27 NULL
108697 +sel_read_policyvers_55 sel_read_policyvers 3 55 NULL nohasharray
108698 +padzero_55 padzero 1 55 &sel_read_policyvers_55
108699 +cfg80211_disconnected_57 cfg80211_disconnected 4 57 NULL
108700 +__skb_to_sgvec_72 __skb_to_sgvec 0 72 NULL
108701 +snd_korg1212_copy_to_92 snd_korg1212_copy_to 6 92 NULL
108702 +load_msg_95 load_msg 2 95 NULL
108703 +ipath_verbs_send_117 ipath_verbs_send 5-3 117 NULL
108704 +init_q_132 init_q 4 132 NULL
108705 +memstick_alloc_host_142 memstick_alloc_host 1 142 NULL
108706 +hva_to_gfn_memslot_149 hva_to_gfn_memslot 0-1 149 NULL
108707 +ping_v6_sendmsg_152 ping_v6_sendmsg 4 152 NULL
108708 +ext4_ext_get_actual_len_153 ext4_ext_get_actual_len 0 153 NULL nohasharray
108709 +tracing_trace_options_write_153 tracing_trace_options_write 3 153 &ext4_ext_get_actual_len_153
108710 +pci_request_selected_regions_169 pci_request_selected_regions 0 169 NULL
108711 +xfs_buf_item_get_format_189 xfs_buf_item_get_format 2 189 NULL
108712 +iscsi_session_setup_196 iscsi_session_setup 4-5 196 NULL
108713 +br_port_info_size_268 br_port_info_size 0 268 NULL
108714 +generic_file_direct_write_291 generic_file_direct_write 0 291 NULL
108715 +read_file_war_stats_292 read_file_war_stats 3 292 NULL
108716 +SYSC_connect_304 SYSC_connect 3 304 NULL
108717 +syslog_print_307 syslog_print 2 307 NULL
108718 +dn_setsockopt_314 dn_setsockopt 5 314 NULL
108719 +mlx5_core_access_reg_361 mlx5_core_access_reg 3-5 361 NULL
108720 +hw_device_state_409 hw_device_state 0 409 NULL
108721 +aio_read_events_ring_410 aio_read_events_ring 3-0 410 NULL
108722 +lbs_rdmac_read_418 lbs_rdmac_read 3 418 NULL
108723 +snd_ca0106_ptr_read_467 snd_ca0106_ptr_read 0 467 NULL
108724 +cfs_trace_set_debug_mb_usrstr_486 cfs_trace_set_debug_mb_usrstr 2 486 NULL
108725 +nvme_trans_modesel_data_488 nvme_trans_modesel_data 4 488 NULL
108726 +iwl_dbgfs_protection_mode_write_502 iwl_dbgfs_protection_mode_write 3 502 NULL
108727 +rx_rx_defrag_end_read_505 rx_rx_defrag_end_read 3 505 NULL
108728 +ocfs2_validate_meta_ecc_bhs_527 ocfs2_validate_meta_ecc_bhs 0 527 NULL
108729 +zlib_deflate_workspacesize_537 zlib_deflate_workspacesize 0-1-2 537 NULL
108730 +iwl_dbgfs_wowlan_sram_read_540 iwl_dbgfs_wowlan_sram_read 3 540 NULL
108731 +sco_sock_setsockopt_552 sco_sock_setsockopt 5 552 NULL
108732 +lpfc_nlp_state_name_556 lpfc_nlp_state_name 2 556 NULL
108733 +snd_aw2_saa7146_get_hw_ptr_playback_558 snd_aw2_saa7146_get_hw_ptr_playback 0 558 NULL
108734 +start_isoc_chain_565 start_isoc_chain 2 565 NULL nohasharray
108735 +dev_hard_header_565 dev_hard_header 0 565 &start_isoc_chain_565
108736 +ocfs2_refcounted_xattr_delete_need_584 ocfs2_refcounted_xattr_delete_need 0 584 NULL
108737 +osl_pktget_590 osl_pktget 2 590 NULL
108738 +smk_write_load_self2_591 smk_write_load_self2 3 591 NULL
108739 +btrfs_stack_file_extent_offset_607 btrfs_stack_file_extent_offset 0 607 NULL
108740 +ni_gpct_device_construct_610 ni_gpct_device_construct 5 610 NULL
108741 +fuse_request_alloc_nofs_617 fuse_request_alloc_nofs 1 617 NULL
108742 +ptlrpc_lprocfs_nrs_seq_write_621 ptlrpc_lprocfs_nrs_seq_write 3 621 NULL
108743 +viafb_dfpl_proc_write_627 viafb_dfpl_proc_write 3 627 NULL
108744 +clone_split_bio_633 clone_split_bio 6 633 NULL
108745 +ceph_osdc_new_request_635 ceph_osdc_new_request 6 635 NULL
108746 +cfs_hash_bkt_size_643 cfs_hash_bkt_size 0 643 NULL
108747 +unlink_queued_645 unlink_queued 4 645 NULL
108748 +dtim_interval_read_654 dtim_interval_read 3 654 NULL
108749 +mem_rx_free_mem_blks_read_675 mem_rx_free_mem_blks_read 3 675 NULL
108750 +persistent_ram_vmap_709 persistent_ram_vmap 1-2 709 NULL
108751 +sctp_setsockopt_peer_addr_params_734 sctp_setsockopt_peer_addr_params 3 734 NULL
108752 +dvb_video_write_754 dvb_video_write 3 754 NULL
108753 +cfs_trace_allocate_string_buffer_781 cfs_trace_allocate_string_buffer 2 781 NULL
108754 +ath6kl_disconnect_timeout_write_794 ath6kl_disconnect_timeout_write 3 794 NULL
108755 +if_writecmd_815 if_writecmd 2 815 NULL
108756 +aac_change_queue_depth_825 aac_change_queue_depth 2 825 NULL
108757 +error_state_read_859 error_state_read 6 859 NULL
108758 +o2net_send_message_vec_879 o2net_send_message_vec 4 879 NULL nohasharray
108759 +iwl_dbgfs_fh_reg_read_879 iwl_dbgfs_fh_reg_read 3 879 &o2net_send_message_vec_879
108760 +snd_pcm_action_single_905 snd_pcm_action_single 0 905 NULL
108761 +carl9170_cmd_buf_950 carl9170_cmd_buf 3 950 NULL
108762 +__nodes_weight_956 __nodes_weight 2-0 956 NULL
108763 +bnx2x_fill_fw_str_968 bnx2x_fill_fw_str 3 968 NULL
108764 +memcmp_990 memcmp 0 990 NULL
108765 +readreg_1017 readreg 0-1 1017 NULL
108766 +smk_write_cipso2_1021 smk_write_cipso2 3 1021 NULL
108767 +gigaset_initdriver_1060 gigaset_initdriver 2 1060 NULL
108768 +mce_request_packet_1073 mce_request_packet 3 1073 NULL
108769 +agp_create_memory_1075 agp_create_memory 1 1075 NULL
108770 +_scsih_adjust_queue_depth_1083 _scsih_adjust_queue_depth 2 1083 NULL
108771 +llcp_sock_sendmsg_1092 llcp_sock_sendmsg 4 1092 NULL
108772 +llc_mac_hdr_init_1094 llc_mac_hdr_init 0 1094 NULL
108773 +nfs4_init_nonuniform_client_string_1097 nfs4_init_nonuniform_client_string 3 1097 NULL
108774 +utf8s_to_utf16s_1115 utf8s_to_utf16s 0 1115 NULL
108775 +cfg80211_report_obss_beacon_1133 cfg80211_report_obss_beacon 3 1133 NULL
108776 +i2400m_rx_ctl_1157 i2400m_rx_ctl 4 1157 NULL
108777 +ipc_alloc_1192 ipc_alloc 1 1192 NULL
108778 +ib_create_send_mad_1196 ib_create_send_mad 5 1196 NULL
108779 +pstore_ftrace_knob_write_1198 pstore_ftrace_knob_write 3 1198 NULL
108780 +i2400m_rx_ctl_ack_1199 i2400m_rx_ctl_ack 3 1199 NULL
108781 +dgrp_dpa_read_1204 dgrp_dpa_read 3 1204 NULL
108782 +i2cdev_read_1206 i2cdev_read 3 1206 NULL
108783 +lov_ost_pool_init_1215 lov_ost_pool_init 2 1215 NULL
108784 +ocfs2_extend_file_1266 ocfs2_extend_file 3 1266 NULL
108785 +qla4xxx_change_queue_depth_1268 qla4xxx_change_queue_depth 2 1268 NULL
108786 +ioctl_private_iw_point_1273 ioctl_private_iw_point 7 1273 NULL
108787 +SyS_flistxattr_1287 SyS_flistxattr 3 1287 NULL
108788 +tx_frag_in_process_called_read_1290 tx_frag_in_process_called_read 3 1290 NULL
108789 +ffs_1322 ffs 0 1322 NULL
108790 +qlcnic_pci_sriov_configure_1327 qlcnic_pci_sriov_configure 2 1327 NULL
108791 +btrfs_submit_compressed_write_1347 btrfs_submit_compressed_write 5 1347 NULL
108792 +snd_pcm_lib_write1_1358 snd_pcm_lib_write1 0-3 1358 NULL
108793 +ipx_sendmsg_1362 ipx_sendmsg 4 1362 NULL
108794 +fw_stats_raw_read_1369 fw_stats_raw_read 3 1369 NULL
108795 +ocfs2_prepare_inode_for_write_1372 ocfs2_prepare_inode_for_write 3 1372 NULL
108796 +sctp_setsockopt_initmsg_1383 sctp_setsockopt_initmsg 3 1383 NULL
108797 +do_msgsnd_1387 do_msgsnd 4 1387 NULL
108798 +SYSC_io_getevents_1392 SYSC_io_getevents 3 1392 NULL
108799 +file_read_actor_1401 file_read_actor 4-0 1401 NULL
108800 +cfs_trace_copyout_string_1416 cfs_trace_copyout_string 2 1416 NULL
108801 +init_rs_internal_1436 init_rs_internal 1 1436 NULL
108802 +stack_max_size_read_1445 stack_max_size_read 3 1445 NULL
108803 +tx_queue_len_read_1463 tx_queue_len_read 3 1463 NULL
108804 +xprt_alloc_1475 xprt_alloc 2 1475 NULL
108805 +SYSC_syslog_1477 SYSC_syslog 3 1477 NULL
108806 +sta_num_ps_buf_frames_read_1488 sta_num_ps_buf_frames_read 3 1488 NULL
108807 +fpregs_set_1497 fpregs_set 4 1497 NULL
108808 +tomoyo_round2_1518 tomoyo_round2 0 1518 NULL
108809 +alloc_perm_bits_1532 alloc_perm_bits 2 1532 NULL
108810 +ath6kl_init_get_fwcaps_1557 ath6kl_init_get_fwcaps 3 1557 NULL
108811 +ieee80211_if_read_dot11MeshHWMPnetDiameterTraversalTime_1589 ieee80211_if_read_dot11MeshHWMPnetDiameterTraversalTime 3 1589 NULL
108812 +ipath_ht_handle_hwerrors_1592 ipath_ht_handle_hwerrors 3 1592 NULL
108813 +packet_buffer_init_1607 packet_buffer_init 2 1607 NULL
108814 +btmrvl_hscmd_read_1614 btmrvl_hscmd_read 3 1614 NULL
108815 +v9fs_fid_xattr_get_1618 v9fs_fid_xattr_get 0 1618 NULL
108816 +ikconfig_read_current_1658 ikconfig_read_current 3 1658 NULL
108817 +mei_cl_recv_1665 mei_cl_recv 3 1665 NULL
108818 +rmap_add_1677 rmap_add 3 1677 NULL
108819 +configfs_read_file_1683 configfs_read_file 3 1683 NULL
108820 +pdu_write_u_1710 pdu_write_u 3 1710 NULL
108821 +coda_psdev_write_1711 coda_psdev_write 3 1711 NULL
108822 +internal_create_group_1733 internal_create_group 0 1733 NULL
108823 +dev_irnet_read_1741 dev_irnet_read 3 1741 NULL
108824 +tx_frag_called_read_1748 tx_frag_called_read 3 1748 NULL
108825 +cosa_write_1774 cosa_write 3 1774 NULL
108826 +fcoe_ctlr_device_add_1793 fcoe_ctlr_device_add 3 1793 NULL
108827 +__nodelist_scnprintf_1815 __nodelist_scnprintf 2-0 1815 NULL
108828 +sb_issue_zeroout_1884 sb_issue_zeroout 3 1884 NULL
108829 +rx_defrag_called_read_1897 rx_defrag_called_read 3 1897 NULL
108830 +nfs_parse_server_name_1899 nfs_parse_server_name 2 1899 NULL
108831 +SyS_add_key_1900 SyS_add_key 4 1900 NULL
108832 +uhid_char_read_1920 uhid_char_read 3 1920 NULL
108833 +tx_tx_retry_data_read_1926 tx_tx_retry_data_read 3 1926 NULL
108834 +bdev_erase_1933 bdev_erase 3 1933 NULL
108835 +ext3_fiemap_1936 ext3_fiemap 4 1936 NULL
108836 +cyttsp_probe_1940 cyttsp_probe 4 1940 NULL
108837 +ieee80211_if_fmt_dot11MeshConfirmTimeout_1945 ieee80211_if_fmt_dot11MeshConfirmTimeout 3 1945 NULL
108838 +ivtv_v4l2_read_1964 ivtv_v4l2_read 3 1964 NULL
108839 +sel_read_avc_hash_stats_1984 sel_read_avc_hash_stats 3 1984 NULL
108840 +gpio_power_write_1991 gpio_power_write 3 1991 NULL
108841 +__alloc_bootmem_node_1992 __alloc_bootmem_node 2 1992 NULL
108842 +rx_rx_defrag_read_2010 rx_rx_defrag_read 3 2010 NULL
108843 +ocfs2_global_qinit_alloc_2018 ocfs2_global_qinit_alloc 0 2018 NULL
108844 +write_flush_pipefs_2021 write_flush_pipefs 3 2021 NULL
108845 +BcmCopySection_2035 BcmCopySection 5 2035 NULL
108846 +ath6kl_fwlog_mask_read_2050 ath6kl_fwlog_mask_read 3 2050 NULL
108847 +ocfs2_expand_inline_dir_2063 ocfs2_expand_inline_dir 3 2063 NULL
108848 +__generic_copy_from_user_intel_2073 __generic_copy_from_user_intel 0-3 2073 NULL
108849 +diva_set_driver_dbg_mask_2077 diva_set_driver_dbg_mask 0 2077 NULL
108850 +iwl_dbgfs_current_sleep_command_read_2081 iwl_dbgfs_current_sleep_command_read 3 2081 NULL
108851 +idetape_chrdev_read_2097 idetape_chrdev_read 3 2097 NULL
108852 +audit_expand_2098 audit_expand 0 2098 NULL
108853 +iwl_dbgfs_log_event_read_2107 iwl_dbgfs_log_event_read 3 2107 NULL
108854 +ecryptfs_encrypt_and_encode_filename_2109 ecryptfs_encrypt_and_encode_filename 6 2109 NULL
108855 +enable_read_2117 enable_read 3 2117 NULL
108856 +pcf50633_write_block_2124 pcf50633_write_block 2-3 2124 NULL
108857 +check_load_and_stores_2143 check_load_and_stores 2 2143 NULL
108858 +iov_iter_count_2152 iov_iter_count 0 2152 NULL
108859 +__copy_to_user_ll_2157 __copy_to_user_ll 0-3 2157 NULL
108860 +_ore_get_io_state_2166 _ore_get_io_state 3-4-5 2166 NULL
108861 +bio_integrity_alloc_2194 bio_integrity_alloc 3 2194 NULL
108862 +picolcd_debug_reset_write_2195 picolcd_debug_reset_write 3 2195 NULL
108863 +u32_array_read_2219 u32_array_read 3 2219 NULL nohasharray
108864 +mei_dbgfs_read_meclients_2219 mei_dbgfs_read_meclients 3 2219 &u32_array_read_2219
108865 +vhci_write_2224 vhci_write 3 2224 NULL
108866 +__ocfs2_journal_access_2241 __ocfs2_journal_access 0 2241 NULL
108867 +ieee80211_if_read_dot11MeshHWMPRannInterval_2249 ieee80211_if_read_dot11MeshHWMPRannInterval 3 2249 NULL
108868 +netlbl_secattr_catmap_walk_2255 netlbl_secattr_catmap_walk 0-2 2255 NULL
108869 +sel_write_avc_cache_threshold_2256 sel_write_avc_cache_threshold 3 2256 NULL
108870 +do_update_counters_2259 do_update_counters 4 2259 NULL
108871 +ath6kl_wmi_bssinfo_event_rx_2275 ath6kl_wmi_bssinfo_event_rx 3 2275 NULL
108872 +debug_debug5_read_2291 debug_debug5_read 3 2291 NULL
108873 +kvm_clear_guest_page_2308 kvm_clear_guest_page 4 2308 NULL
108874 +intel_sdvo_set_value_2311 intel_sdvo_set_value 4 2311 NULL
108875 +hfsplus_find_init_2318 hfsplus_find_init 0 2318 NULL nohasharray
108876 +picolcd_fb_write_2318 picolcd_fb_write 3 2318 &hfsplus_find_init_2318
108877 +dice_hwdep_read_2326 dice_hwdep_read 3 2326 NULL
108878 +__erst_read_to_erange_2341 __erst_read_to_erange 0 2341 NULL
108879 +zr364xx_read_2354 zr364xx_read 3 2354 NULL
108880 +sysfs_add_file_mode_ns_2362 sysfs_add_file_mode_ns 0 2362 NULL
108881 +viafb_iga2_odev_proc_write_2363 viafb_iga2_odev_proc_write 3 2363 NULL
108882 +xfs_buf_map_from_irec_2368 xfs_buf_map_from_irec 5 2368 NULL nohasharray
108883 +rose_recvmsg_2368 rose_recvmsg 4 2368 &xfs_buf_map_from_irec_2368
108884 +il_dbgfs_sensitivity_read_2370 il_dbgfs_sensitivity_read 3 2370 NULL
108885 +rxpipe_rx_prep_beacon_drop_read_2403 rxpipe_rx_prep_beacon_drop_read 3 2403 NULL
108886 +isdn_v110_open_2418 isdn_v110_open 3 2418 NULL
108887 +raid1_size_2419 raid1_size 0-2 2419 NULL
108888 +b43legacy_debugfs_read_2473 b43legacy_debugfs_read 3 2473 NULL
108889 +wiphy_new_2482 wiphy_new 2 2482 NULL
108890 +bio_alloc_bioset_2484 bio_alloc_bioset 2 2484 NULL
108891 +hfsplus_user_setxattr_2485 hfsplus_user_setxattr 4 2485 NULL
108892 +squashfs_read_fragment_index_table_2506 squashfs_read_fragment_index_table 4 2506 NULL
108893 +v9fs_cached_file_read_2514 v9fs_cached_file_read 3 2514 NULL
108894 +ext4_get_inode_loc_2516 ext4_get_inode_loc 0 2516 NULL
108895 +batadv_tvlv_container_list_size_2524 batadv_tvlv_container_list_size 0 2524 NULL
108896 +gspca_dev_probe_2570 gspca_dev_probe 4 2570 NULL
108897 +pcm_sanity_check_2574 pcm_sanity_check 0 2574 NULL
108898 +mdc_max_rpcs_in_flight_seq_write_2594 mdc_max_rpcs_in_flight_seq_write 3 2594 NULL
108899 +slot_bytes_2609 slot_bytes 0 2609 NULL
108900 +smk_write_logging_2618 smk_write_logging 3 2618 NULL
108901 +switch_status_2629 switch_status 5 2629 NULL
108902 +tcp_xmit_size_goal_2661 tcp_xmit_size_goal 2 2661 NULL
108903 +osc_build_ppga_2670 osc_build_ppga 2 2670 NULL
108904 +ffs_ep0_read_2672 ffs_ep0_read 3 2672 NULL
108905 +oti6858_write_2692 oti6858_write 4 2692 NULL
108906 +nfc_llcp_send_ui_frame_2702 nfc_llcp_send_ui_frame 5 2702 NULL
108907 +memcpy_fromiovecend_2707 memcpy_fromiovecend 3-4 2707 NULL
108908 +lprocfs_stats_counter_size_2708 lprocfs_stats_counter_size 0 2708 NULL
108909 +xfs_readdir_2767 xfs_readdir 3 2767 NULL
108910 +mon_bin_ioctl_2771 mon_bin_ioctl 3 2771 NULL
108911 +device_add_attrs_2789 device_add_attrs 0 2789 NULL
108912 +iwl_dbgfs_clear_ucode_statistics_write_2804 iwl_dbgfs_clear_ucode_statistics_write 3 2804 NULL
108913 +sel_read_enforce_2828 sel_read_enforce 3 2828 NULL
108914 +vb2_dc_get_userptr_2829 vb2_dc_get_userptr 2-3 2829 NULL
108915 +wait_for_avail_2847 wait_for_avail 0 2847 NULL
108916 +sfq_alloc_2861 sfq_alloc 1 2861 NULL
108917 +irnet_ctrl_read_2863 irnet_ctrl_read 4 2863 NULL
108918 +move_addr_to_user_2868 move_addr_to_user 2 2868 NULL
108919 +nla_padlen_2883 nla_padlen 1 2883 NULL
108920 +cmm_write_2896 cmm_write 3 2896 NULL
108921 +osc_import_seq_write_2923 osc_import_seq_write 3 2923 NULL
108922 +xfs_trans_get_buf_map_2927 xfs_trans_get_buf_map 4 2927 NULL
108923 +nes_read_indexed_2946 nes_read_indexed 0 2946 NULL
108924 +tm6000_i2c_recv_regs16_2949 tm6000_i2c_recv_regs16 5 2949 NULL
108925 +i40e_dbg_prep_dump_buf_2951 i40e_dbg_prep_dump_buf 2 2951 NULL
108926 +set_fast_connectable_2952 set_fast_connectable 4 2952 NULL
108927 +free_area_init_core_2962 free_area_init_core 2-3 2962 NULL
108928 +do_strnlen_user_2976 do_strnlen_user 0-2 2976 NULL
108929 +p9_nr_pages_2992 p9_nr_pages 0-2 2992 NULL
108930 +lov_stripetype_seq_write_3013 lov_stripetype_seq_write 3 3013 NULL
108931 +do_dmabuf_dirty_sou_3017 do_dmabuf_dirty_sou 7 3017 NULL
108932 +depth_write_3021 depth_write 3 3021 NULL
108933 +snd_azf3328_codec_inl_3022 snd_azf3328_codec_inl 0 3022 NULL
108934 +kvm_unmap_hva_3028 kvm_unmap_hva 2 3028 NULL
108935 +xfrm_dst_alloc_copy_3034 xfrm_dst_alloc_copy 3 3034 NULL
108936 +lpfc_idiag_mbxacc_write_3038 lpfc_idiag_mbxacc_write 3 3038 NULL nohasharray
108937 +iwl_dbgfs_sleep_level_override_read_3038 iwl_dbgfs_sleep_level_override_read 3 3038 &lpfc_idiag_mbxacc_write_3038
108938 +nr_free_buffer_pages_3044 nr_free_buffer_pages 0 3044 NULL
108939 +il3945_ucode_rx_stats_read_3048 il3945_ucode_rx_stats_read 3 3048 NULL
108940 +qp_alloc_ppn_set_3068 qp_alloc_ppn_set 2-4 3068 NULL
108941 +__blk_end_bidi_request_3070 __blk_end_bidi_request 3-4 3070 NULL
108942 +dac960_user_command_proc_write_3071 dac960_user_command_proc_write 3 3071 NULL
108943 +read_file_antenna_diversity_3077 read_file_antenna_diversity 3 3077 NULL
108944 +clone_bio_3100 clone_bio 6 3100 NULL nohasharray
108945 +ttusb2_msg_3100 ttusb2_msg 4 3100 &clone_bio_3100
108946 +rb_alloc_3102 rb_alloc 1 3102 NULL
108947 +simple_write_to_buffer_3122 simple_write_to_buffer 5-2 3122 NULL
108948 +print_time_3132 print_time 0 3132 NULL
108949 +fill_write_buffer_3142 fill_write_buffer 3 3142 NULL
108950 +CIFSSMBSetPosixACL_3154 CIFSSMBSetPosixACL 5 3154 NULL
108951 +compat_sys_migrate_pages_3157 compat_sys_migrate_pages 2 3157 NULL
108952 +uv_num_possible_blades_3177 uv_num_possible_blades 0 3177 NULL
108953 +uvc_video_stats_dump_3181 uvc_video_stats_dump 3 3181 NULL
108954 +compat_do_ip6t_set_ctl_3184 compat_do_ip6t_set_ctl 4 3184 NULL
108955 +mempool_create_node_3191 mempool_create_node 1 3191 NULL
108956 +alloc_context_3194 alloc_context 1 3194 NULL
108957 +shmem_pread_slow_3198 shmem_pread_slow 3-2 3198 NULL
108958 +codec_reg_write_file_3204 codec_reg_write_file 3 3204 NULL
108959 +SyS_sendto_3219 SyS_sendto 6 3219 NULL
108960 +btrfs_prealloc_file_range_3227 btrfs_prealloc_file_range 3 3227 NULL
108961 +kimage_crash_alloc_3233 kimage_crash_alloc 3 3233 NULL
108962 +write_adapter_mem_3234 write_adapter_mem 3 3234 NULL
108963 +do_read_log_to_user_3236 do_read_log_to_user 4 3236 NULL
108964 +ext3_xattr_find_entry_3237 ext3_xattr_find_entry 0 3237 NULL
108965 +key_key_read_3241 key_key_read 3 3241 NULL
108966 +__ilog2_u64_3284 __ilog2_u64 0 3284 NULL
108967 +__iovec_copy_from_user_inatomic_3314 __iovec_copy_from_user_inatomic 0-4-3 3314 NULL
108968 +dbDiscardAG_3322 dbDiscardAG 3 3322 NULL
108969 +compat_sys_setsockopt_3326 compat_sys_setsockopt 5 3326 NULL
108970 +ocfs2_extend_xattr_bucket_3328 ocfs2_extend_xattr_bucket 4 3328 NULL
108971 +read_from_oldmem_3337 read_from_oldmem 2 3337 NULL
108972 +sysfs_create_group_3339 sysfs_create_group 0 3339 NULL
108973 +tty_port_register_device_attr_3341 tty_port_register_device_attr 3 3341 NULL
108974 +il_dbgfs_interrupt_read_3351 il_dbgfs_interrupt_read 3 3351 NULL
108975 +gsm_control_rls_3353 gsm_control_rls 3 3353 NULL
108976 +scnprintf_3360 scnprintf 0-2 3360 NULL
108977 +ReadByteAmd7930_3365 ReadByteAmd7930 0 3365 NULL
108978 +sr_read_3366 sr_read 3 3366 NULL
108979 +mtdchar_writeoob_3393 mtdchar_writeoob 4 3393 NULL
108980 +send_stream_3397 send_stream 4 3397 NULL
108981 +isdn_readbchan_3401 isdn_readbchan 0-5 3401 NULL
108982 +mei_io_cb_alloc_resp_buf_3414 mei_io_cb_alloc_resp_buf 2 3414 NULL
108983 +pci_add_cap_save_buffer_3426 pci_add_cap_save_buffer 3 3426 NULL
108984 +crystalhd_create_dio_pool_3427 crystalhd_create_dio_pool 2 3427 NULL
108985 +SyS_msgsnd_3436 SyS_msgsnd 3 3436 NULL
108986 +pipe_iov_copy_to_user_3447 pipe_iov_copy_to_user 3 3447 NULL
108987 +s3fb_ddc_read_3451 s3fb_ddc_read 0 3451 NULL
108988 +softsynth_write_3455 softsynth_write 3 3455 NULL
108989 +snd_pcm_lib_readv_transfer_3464 snd_pcm_lib_readv_transfer 5-4-2 3464 NULL nohasharray
108990 +jffs2_acl_setxattr_3464 jffs2_acl_setxattr 4 3464 &snd_pcm_lib_readv_transfer_3464
108991 +security_context_to_sid_default_3492 security_context_to_sid_default 2 3492 NULL
108992 +xfrm_migrate_msgsize_3496 xfrm_migrate_msgsize 1 3496 NULL
108993 +mem_tx_free_mem_blks_read_3521 mem_tx_free_mem_blks_read 3 3521 NULL
108994 +SyS_semtimedop_3532 SyS_semtimedop 3 3532 NULL
108995 +SyS_readv_3539 SyS_readv 3 3539 NULL
108996 +btrfs_dir_name_len_3549 btrfs_dir_name_len 0 3549 NULL
108997 +alloc_smp_resp_3566 alloc_smp_resp 1 3566 NULL
108998 +evtchn_read_3569 evtchn_read 3 3569 NULL
108999 +ll_track_ppid_seq_write_3582 ll_track_ppid_seq_write 3 3582 NULL
109000 +vc_resize_3585 vc_resize 3-2 3585 NULL
109001 +kvm_mmu_notifier_change_pte_3596 kvm_mmu_notifier_change_pte 3 3596 NULL
109002 +sctp_getsockopt_events_3607 sctp_getsockopt_events 2 3607 NULL
109003 +edac_mc_alloc_3611 edac_mc_alloc 4 3611 NULL
109004 +tx_tx_starts_read_3617 tx_tx_starts_read 3 3617 NULL
109005 +aligned_kmalloc_3628 aligned_kmalloc 1 3628 NULL
109006 +ath6kl_disconnect_timeout_read_3650 ath6kl_disconnect_timeout_read 3 3650 NULL
109007 +i915_compat_ioctl_3656 i915_compat_ioctl 2 3656 NULL
109008 +snd_m3_assp_read_3703 snd_m3_assp_read 0 3703 NULL
109009 +ci_ll_write_3740 ci_ll_write 4 3740 NULL nohasharray
109010 +ath6kl_mgmt_tx_3740 ath6kl_mgmt_tx 7 3740 &ci_ll_write_3740
109011 +sctp_setsockopt_auth_key_3793 sctp_setsockopt_auth_key 3 3793 NULL
109012 +ncp_file_write_3813 ncp_file_write 3 3813 NULL
109013 +llc_ui_recvmsg_3826 llc_ui_recvmsg 4 3826 NULL
109014 +hfsplus_direct_IO_3835 hfsplus_direct_IO 4 3835 NULL
109015 +create_one_cdev_3852 create_one_cdev 2 3852 NULL
109016 +smk_read_onlycap_3855 smk_read_onlycap 3 3855 NULL
109017 +get_fd_set_3866 get_fd_set 1 3866 NULL
109018 +apei_res_sub_3873 apei_res_sub 0 3873 NULL
109019 +garp_attr_create_3883 garp_attr_create 3 3883 NULL
109020 +efivarfs_file_read_3893 efivarfs_file_read 3 3893 NULL
109021 +nvram_write_3894 nvram_write 3 3894 NULL
109022 +pipeline_pre_proc_swi_read_3898 pipeline_pre_proc_swi_read 3 3898 NULL
109023 +comedi_buf_read_n_available_3899 comedi_buf_read_n_available 0 3899 NULL
109024 +vcs_write_3910 vcs_write 3 3910 NULL
109025 +SyS_move_pages_3920 SyS_move_pages 2 3920 NULL
109026 +hdlc_irq_one_3944 hdlc_irq_one 2 3944 NULL
109027 +brcmf_debugfs_fws_stats_read_3947 brcmf_debugfs_fws_stats_read 3 3947 NULL
109028 +ll_get_max_mdsize_3962 ll_get_max_mdsize 0 3962 NULL
109029 +mite_bytes_written_to_memory_lb_3987 mite_bytes_written_to_memory_lb 0 3987 NULL
109030 +do_add_counters_3992 do_add_counters 3 3992 NULL
109031 +obd_alloc_memmd_4002 obd_alloc_memmd 0 4002 NULL
109032 +userspace_status_4004 userspace_status 4 4004 NULL
109033 +xfs_check_block_4005 xfs_check_block 4 4005 NULL nohasharray
109034 +mei_write_4005 mei_write 3 4005 &xfs_check_block_4005
109035 +snd_hdsp_capture_copy_4011 snd_hdsp_capture_copy 5 4011 NULL
109036 +blk_end_request_4024 blk_end_request 3 4024 NULL
109037 +ext4_xattr_find_entry_4025 ext4_xattr_find_entry 0 4025 NULL
109038 +mtip_hw_read_registers_4037 mtip_hw_read_registers 3 4037 NULL
109039 +read_file_queues_4078 read_file_queues 3 4078 NULL
109040 +fbcon_do_set_font_4079 fbcon_do_set_font 2-3 4079 NULL
109041 +C_SYSC_rt_sigpending_4114 C_SYSC_rt_sigpending 2 4114 NULL
109042 +tm6000_read_4151 tm6000_read 3 4151 NULL
109043 +mpt_raid_phys_disk_get_num_paths_4155 mpt_raid_phys_disk_get_num_paths 0 4155 NULL
109044 +msg_bits_4158 msg_bits 0-3-4 4158 NULL
109045 +get_alua_req_4166 get_alua_req 3 4166 NULL
109046 +blk_dropped_read_4168 blk_dropped_read 3 4168 NULL
109047 +read_file_bool_4180 read_file_bool 3 4180 NULL
109048 +ocfs2_find_cpos_for_right_leaf_4194 ocfs2_find_cpos_for_right_leaf 0 4194 NULL
109049 +vring_new_virtqueue_4199 vring_new_virtqueue 2 4199 NULL
109050 +f1x_determine_channel_4202 f1x_determine_channel 2 4202 NULL
109051 +_osd_req_list_objects_4204 _osd_req_list_objects 6 4204 NULL
109052 +__snd_gf1_read_addr_4210 __snd_gf1_read_addr 0 4210 NULL
109053 +ath6kl_force_roam_write_4282 ath6kl_force_roam_write 3 4282 NULL
109054 +goldfish_audio_write_4284 goldfish_audio_write 3 4284 NULL
109055 +__usbnet_read_cmd_4299 __usbnet_read_cmd 7 4299 NULL
109056 +dvb_ringbuffer_pkt_read_user_4303 dvb_ringbuffer_pkt_read_user 3-2-5 4303 NULL
109057 +count_strings_4315 count_strings 0 4315 NULL
109058 +__sysfs_add_one_4326 __sysfs_add_one 0 4326 NULL
109059 +nouveau_fifo_create__4327 nouveau_fifo_create_ 5-6 4327 NULL
109060 +snd_rawmidi_kernel_read_4328 snd_rawmidi_kernel_read 3 4328 NULL
109061 +__copy_from_user_inatomic_4365 __copy_from_user_inatomic 0-3 4365 NULL nohasharray
109062 +lookup_string_4365 lookup_string 0 4365 &__copy_from_user_inatomic_4365
109063 +irda_sendmsg_4388 irda_sendmsg 4 4388 NULL
109064 +access_process_vm_4412 access_process_vm 0 4412 NULL nohasharray
109065 +cxacru_cm_get_array_4412 cxacru_cm_get_array 4 4412 &access_process_vm_4412
109066 +libfc_vport_create_4415 libfc_vport_create 2 4415 NULL
109067 +rtw_android_get_rssi_4421 rtw_android_get_rssi 0 4421 NULL
109068 +do_pages_stat_4437 do_pages_stat 2 4437 NULL
109069 +at76_set_card_command_4471 at76_set_card_command 4 4471 NULL
109070 +snd_seq_expand_var_event_4481 snd_seq_expand_var_event 5-0 4481 NULL
109071 +vmbus_establish_gpadl_4495 vmbus_establish_gpadl 3 4495 NULL
109072 +set_link_security_4502 set_link_security 4 4502 NULL
109073 +ll_max_readahead_per_file_mb_seq_write_4531 ll_max_readahead_per_file_mb_seq_write 3 4531 NULL
109074 +tty_register_device_4544 tty_register_device 2 4544 NULL
109075 +btrfs_file_extent_inline_item_len_4575 btrfs_file_extent_inline_item_len 0 4575 NULL
109076 +xfs_buf_get_maps_4581 xfs_buf_get_maps 2 4581 NULL
109077 +bch_alloc_4593 bch_alloc 1 4593 NULL
109078 +ocfs2_refcount_lock_4595 ocfs2_refcount_lock 0 4595 NULL
109079 +ll_rw_extents_stats_seq_write_4633 ll_rw_extents_stats_seq_write 3 4633 NULL
109080 +iwl_dbgfs_tx_queue_read_4635 iwl_dbgfs_tx_queue_read 3 4635 NULL
109081 +skb_add_data_nocache_4682 skb_add_data_nocache 4 4682 NULL
109082 +cx18_read_pos_4683 cx18_read_pos 3 4683 NULL
109083 +short_retry_limit_read_4687 short_retry_limit_read 3 4687 NULL
109084 +kone_receive_4690 kone_receive 4 4690 NULL
109085 +hash_netportnet6_expire_4702 hash_netportnet6_expire 4 4702 NULL
109086 +cxgbi_alloc_big_mem_4707 cxgbi_alloc_big_mem 1 4707 NULL
109087 +ati_create_gatt_pages_4722 ati_create_gatt_pages 1 4722 NULL nohasharray
109088 +show_header_4722 show_header 3 4722 &ati_create_gatt_pages_4722
109089 +bitmap_startwrite_4736 bitmap_startwrite 2 4736 NULL nohasharray
109090 +ll_rw_offset_stats_seq_write_4736 ll_rw_offset_stats_seq_write 3 4736 &bitmap_startwrite_4736
109091 +lu_buf_alloc_4753 lu_buf_alloc 2 4753 NULL
109092 +pwr_rcvd_bcns_cnt_read_4774 pwr_rcvd_bcns_cnt_read 3 4774 NULL
109093 +create_subvol_4791 create_subvol 4 4791 NULL
109094 +ncp__vol2io_4804 ncp__vol2io 5 4804 NULL
109095 +repair_io_failure_4815 repair_io_failure 4-3 4815 NULL
109096 +comedi_buf_write_free_4847 comedi_buf_write_free 2 4847 NULL
109097 +gigaset_if_receive_4861 gigaset_if_receive 3 4861 NULL
109098 +key_tx_spec_read_4862 key_tx_spec_read 3 4862 NULL
109099 +ocfs2_defrag_extent_4873 ocfs2_defrag_extent 2 4873 NULL
109100 +hid_register_field_4874 hid_register_field 2-3 4874 NULL
109101 +vga_arb_read_4886 vga_arb_read 3 4886 NULL
109102 +ieee80211_if_fmt_ave_beacon_4941 ieee80211_if_fmt_ave_beacon 3 4941 NULL
109103 +ocfs2_should_refresh_lock_res_4958 ocfs2_should_refresh_lock_res 0 4958 NULL
109104 +compat_rawv6_setsockopt_4967 compat_rawv6_setsockopt 5 4967 NULL
109105 +ath10k_read_chip_id_4969 ath10k_read_chip_id 3 4969 NULL
109106 +skb_network_header_len_4971 skb_network_header_len 0 4971 NULL
109107 +ieee80211_if_fmt_dot11MeshHWMPconfirmationInterval_4976 ieee80211_if_fmt_dot11MeshHWMPconfirmationInterval 3 4976 NULL
109108 +compat_SyS_ipc_5000 compat_SyS_ipc 3 5000 NULL
109109 +do_mincore_5018 do_mincore 0-2-1 5018 NULL
109110 +btrfs_punch_hole_5041 btrfs_punch_hole 2 5041 NULL
109111 +cfg80211_rx_mgmt_5056 cfg80211_rx_mgmt 5 5056 NULL
109112 +ocfs2_check_range_for_holes_5066 ocfs2_check_range_for_holes 3-2 5066 NULL
109113 +snd_mixart_BA1_read_5082 snd_mixart_BA1_read 5 5082 NULL
109114 +snd_emu10k1_ptr20_read_5087 snd_emu10k1_ptr20_read 0 5087 NULL
109115 +kfifo_copy_from_user_5091 kfifo_copy_from_user 3-4-0 5091 NULL nohasharray
109116 +get_random_bytes_5091 get_random_bytes 2 5091 &kfifo_copy_from_user_5091 nohasharray
109117 +blk_rq_sectors_5091 blk_rq_sectors 0 5091 &get_random_bytes_5091
109118 +sound_write_5102 sound_write 3 5102 NULL
109119 +i40e_dbg_netdev_ops_write_5117 i40e_dbg_netdev_ops_write 3 5117 NULL
109120 +qib_7220_handle_hwerrors_5142 qib_7220_handle_hwerrors 3 5142 NULL
109121 +__uwb_addr_print_5161 __uwb_addr_print 2 5161 NULL
109122 +iwl_dbgfs_status_read_5171 iwl_dbgfs_status_read 3 5171 NULL
109123 +acpi_pcc_get_sqty_5176 acpi_pcc_get_sqty 0 5176 NULL
109124 +ppp_cp_parse_cr_5214 ppp_cp_parse_cr 4 5214 NULL
109125 +dwc2_hcd_urb_alloc_5217 dwc2_hcd_urb_alloc 2 5217 NULL
109126 +ath6kl_debug_roam_tbl_event_5224 ath6kl_debug_roam_tbl_event 3 5224 NULL
109127 +usb_descriptor_fillbuf_5302 usb_descriptor_fillbuf 0 5302 NULL
109128 +r592_write_fifo_pio_5315 r592_write_fifo_pio 3 5315 NULL
109129 +sbc_get_write_same_sectors_5317 sbc_get_write_same_sectors 0 5317 NULL
109130 +pwr_elp_enter_read_5324 pwr_elp_enter_read 3 5324 NULL
109131 +cq_free_res_5355 cq_free_res 5 5355 NULL
109132 +ps_pspoll_utilization_read_5361 ps_pspoll_utilization_read 3 5361 NULL
109133 +cciss_allocate_sg_chain_blocks_5368 cciss_allocate_sg_chain_blocks 3-2 5368 NULL
109134 +__split_bvec_across_targets_5454 __split_bvec_across_targets 3 5454 NULL
109135 +xfs_efd_init_5463 xfs_efd_init 3 5463 NULL
109136 +xfs_efi_init_5476 xfs_efi_init 2 5476 NULL
109137 +cifs_security_flags_proc_write_5484 cifs_security_flags_proc_write 3 5484 NULL
109138 +tty_write_5494 tty_write 3 5494 NULL
109139 +tomoyo_update_domain_5498 tomoyo_update_domain 2 5498 NULL nohasharray
109140 +ieee80211_if_fmt_last_beacon_5498 ieee80211_if_fmt_last_beacon 3 5498 &tomoyo_update_domain_5498
109141 +__max_nr_grant_frames_5505 __max_nr_grant_frames 0 5505 NULL
109142 +ieee80211_if_fmt_auto_open_plinks_5534 ieee80211_if_fmt_auto_open_plinks 3 5534 NULL
109143 +get_entry_msg_len_5552 get_entry_msg_len 0 5552 NULL
109144 +le_readq_5557 le_readq 0 5557 NULL
109145 +inw_5558 inw 0 5558 NULL
109146 +bioset_create_5580 bioset_create 1 5580 NULL
109147 +oz_ep_alloc_5587 oz_ep_alloc 1 5587 NULL
109148 +SYSC_fsetxattr_5639 SYSC_fsetxattr 4 5639 NULL
109149 +ext4_xattr_get_5661 ext4_xattr_get 0 5661 NULL
109150 +posix_clock_register_5662 posix_clock_register 2 5662 NULL
109151 +get_arg_5694 get_arg 3 5694 NULL
109152 +subbuf_read_actor_5708 subbuf_read_actor 3 5708 NULL
109153 +vmw_kms_readback_5727 vmw_kms_readback 6 5727 NULL
109154 +rts51x_transfer_data_partial_5735 rts51x_transfer_data_partial 6 5735 NULL
109155 +sctp_setsockopt_autoclose_5775 sctp_setsockopt_autoclose 3 5775 NULL
109156 +__vxge_hw_blockpool_malloc_5786 __vxge_hw_blockpool_malloc 2 5786 NULL
109157 +nvme_trans_bdev_char_page_5797 nvme_trans_bdev_char_page 3 5797 NULL
109158 +skb_copy_datagram_iovec_5806 skb_copy_datagram_iovec 2-4 5806 NULL
109159 +nv50_disp_pioc_create__5812 nv50_disp_pioc_create_ 5 5812 NULL
109160 +ceph_x_encrypt_buflen_5829 ceph_x_encrypt_buflen 0-1 5829 NULL
109161 +ceph_msg_new_5846 ceph_msg_new 2 5846 NULL
109162 +setup_req_5848 setup_req 3-0 5848 NULL
109163 +ria_page_count_5849 ria_page_count 0 5849 NULL
109164 +rx_filter_max_arp_queue_dep_read_5851 rx_filter_max_arp_queue_dep_read 3 5851 NULL
109165 +config_buf_5862 config_buf 0 5862 NULL
109166 +iwl_dbgfs_scan_ant_rxchain_write_5877 iwl_dbgfs_scan_ant_rxchain_write 3 5877 NULL
109167 +lprocfs_fid_width_seq_write_5889 lprocfs_fid_width_seq_write 3 5889 NULL
109168 +port_show_regs_5904 port_show_regs 3 5904 NULL
109169 +rbd_segment_length_5907 rbd_segment_length 0-3-2 5907 NULL
109170 +uhci_debug_read_5911 uhci_debug_read 3 5911 NULL
109171 +lbs_highsnr_read_5931 lbs_highsnr_read 3 5931 NULL
109172 +ps_poll_ps_poll_timeouts_read_5934 ps_poll_ps_poll_timeouts_read 3 5934 NULL
109173 +edac_device_alloc_ctl_info_5941 edac_device_alloc_ctl_info 1 5941 NULL
109174 +ll_statahead_one_5962 ll_statahead_one 3 5962 NULL
109175 +__apu_get_register_5967 __apu_get_register 0 5967 NULL
109176 +ieee80211_if_fmt_rc_rateidx_mask_5ghz_5971 ieee80211_if_fmt_rc_rateidx_mask_5ghz 3 5971 NULL
109177 +SyS_semop_5980 SyS_semop 3 5980 NULL
109178 +alloc_msg_6072 alloc_msg 1 6072 NULL
109179 +sctp_setsockopt_connectx_6073 sctp_setsockopt_connectx 3 6073 NULL
109180 +rts51x_ms_rw_multi_sector_6076 rts51x_ms_rw_multi_sector 3-4 6076 NULL
109181 +ipmi_addr_length_6110 ipmi_addr_length 0 6110 NULL
109182 +dfs_global_file_write_6112 dfs_global_file_write 3 6112 NULL
109183 +nouveau_parent_create__6131 nouveau_parent_create_ 7 6131 NULL
109184 +ieee80211_if_fmt_beacon_timeout_6153 ieee80211_if_fmt_beacon_timeout 3 6153 NULL
109185 +ivtv_copy_buf_to_user_6159 ivtv_copy_buf_to_user 4 6159 NULL
109186 +wl1251_cmd_template_set_6172 wl1251_cmd_template_set 4 6172 NULL
109187 +SyS_setgroups_6182 SyS_setgroups 1 6182 NULL
109188 +mxt_show_instance_6207 mxt_show_instance 2-0 6207 NULL
109189 +v4l2_ctrl_new_std_menu_6221 v4l2_ctrl_new_std_menu 4 6221 NULL
109190 +mqueue_read_file_6228 mqueue_read_file 3 6228 NULL
109191 +f_hidg_read_6238 f_hidg_read 3 6238 NULL
109192 +fbcon_prepare_logo_6246 fbcon_prepare_logo 5 6246 NULL
109193 +tx_tx_start_null_frame_read_6281 tx_tx_start_null_frame_read 3 6281 NULL
109194 +snd_hda_override_conn_list_6282 snd_hda_override_conn_list 3-0 6282 NULL nohasharray
109195 +xenbus_file_write_6282 xenbus_file_write 3 6282 &snd_hda_override_conn_list_6282
109196 +posix_acl_fix_xattr_to_user_6283 posix_acl_fix_xattr_to_user 2 6283 NULL
109197 +serial_port_in_6291 serial_port_in 0 6291 NULL
109198 +qlcnic_sriov_alloc_bc_msg_6309 qlcnic_sriov_alloc_bc_msg 2 6309 NULL
109199 +hfa384x_inw_6329 hfa384x_inw 0 6329 NULL nohasharray
109200 +SyS_mincore_6329 SyS_mincore 2-1 6329 &hfa384x_inw_6329
109201 +fuse_get_req_for_background_6337 fuse_get_req_for_background 2 6337 NULL
109202 +ucs2_strnlen_6342 ucs2_strnlen 0 6342 NULL
109203 +regcache_sync_block_raw_6350 regcache_sync_block_raw 5-4 6350 NULL
109204 +mei_dbgfs_read_devstate_6352 mei_dbgfs_read_devstate 3 6352 NULL
109205 +_proc_do_string_6376 _proc_do_string 2 6376 NULL
109206 +osd_req_read_sg_kern_6378 osd_req_read_sg_kern 5 6378 NULL
109207 +posix_acl_fix_xattr_userns_6420 posix_acl_fix_xattr_userns 4 6420 NULL
109208 +add_transaction_credits_6422 add_transaction_credits 2-3 6422 NULL
109209 +ipr_change_queue_depth_6431 ipr_change_queue_depth 2 6431 NULL
109210 +__alloc_bootmem_node_nopanic_6432 __alloc_bootmem_node_nopanic 2 6432 NULL
109211 +ieee80211_if_fmt_dot11MeshMaxRetries_6476 ieee80211_if_fmt_dot11MeshMaxRetries 3 6476 NULL
109212 +qp_memcpy_from_queue_6479 qp_memcpy_from_queue 5-4 6479 NULL
109213 +cipso_v4_map_lvl_hton_6490 cipso_v4_map_lvl_hton 0 6490 NULL
109214 +dbg_intr_buf_6501 dbg_intr_buf 2 6501 NULL
109215 +mei_read_6507 mei_read 3 6507 NULL
109216 +rndis_set_oid_6547 rndis_set_oid 4 6547 NULL
109217 +wdm_read_6549 wdm_read 3 6549 NULL
109218 +dm_stats_create_6551 dm_stats_create 4-2-3 6551 NULL
109219 +fb_alloc_cmap_6554 fb_alloc_cmap 2 6554 NULL
109220 +SyS_semtimedop_6563 SyS_semtimedop 3 6563 NULL
109221 +ecryptfs_filldir_6622 ecryptfs_filldir 3 6622 NULL
109222 +xfs_do_div_6649 xfs_do_div 0-2 6649 NULL
109223 +process_rcvd_data_6679 process_rcvd_data 3 6679 NULL
109224 +btrfs_lookup_csums_range_6696 btrfs_lookup_csums_range 2-3 6696 NULL
109225 +ps_pspoll_max_apturn_read_6699 ps_pspoll_max_apturn_read 3 6699 NULL
109226 +bnad_debugfs_write_regrd_6706 bnad_debugfs_write_regrd 3 6706 NULL
109227 +mpeg_read_6708 mpeg_read 3 6708 NULL
109228 +ibmpex_query_sensor_count_6709 ibmpex_query_sensor_count 0 6709 NULL
109229 +video_proc_write_6724 video_proc_write 3 6724 NULL
109230 +posix_acl_xattr_count_6725 posix_acl_xattr_count 0-1 6725 NULL
109231 +kobject_add_varg_6781 kobject_add_varg 0 6781 NULL
109232 +iwl_dbgfs_channels_read_6784 iwl_dbgfs_channels_read 3 6784 NULL
109233 +ieee80211_if_read_6785 ieee80211_if_read 3 6785 NULL
109234 +zone_spanned_pages_in_node_6787 zone_spanned_pages_in_node 0-3-4 6787 NULL
109235 +hdlcdrv_register_6792 hdlcdrv_register 2 6792 NULL
109236 +tx_tx_done_data_read_6799 tx_tx_done_data_read 3 6799 NULL
109237 +lbs_rdrf_write_6826 lbs_rdrf_write 3 6826 NULL
109238 +calc_pages_for_6838 calc_pages_for 0-1-2 6838 NULL
109239 +mon_bin_read_6841 mon_bin_read 3 6841 NULL
109240 +snd_cs4281_BA0_read_6847 snd_cs4281_BA0_read 5 6847 NULL
109241 +perf_output_sample_ustack_6868 perf_output_sample_ustack 2 6868 NULL
109242 +dio_complete_6879 dio_complete 0-2-3 6879 NULL
109243 +raw_seticmpfilter_6888 raw_seticmpfilter 3 6888 NULL nohasharray
109244 +ieee80211_if_fmt_path_refresh_time_6888 ieee80211_if_fmt_path_refresh_time 3 6888 &raw_seticmpfilter_6888
109245 +dlmfs_file_write_6892 dlmfs_file_write 3 6892 NULL
109246 +proc_sessionid_read_6911 proc_sessionid_read 3 6911 NULL nohasharray
109247 +spi_show_regs_6911 spi_show_regs 3 6911 &proc_sessionid_read_6911 nohasharray
109248 +acm_alloc_minor_6911 acm_alloc_minor 0 6911 &spi_show_regs_6911
109249 +__kfifo_dma_in_finish_r_6913 __kfifo_dma_in_finish_r 2-3 6913 NULL
109250 +do_msgrcv_6921 do_msgrcv 3 6921 NULL
109251 +cache_do_downcall_6926 cache_do_downcall 3 6926 NULL
109252 +ipath_verbs_send_dma_6929 ipath_verbs_send_dma 6 6929 NULL
109253 +qsfp_cks_6945 qsfp_cks 2-0 6945 NULL
109254 +tg3_nvram_write_block_unbuffered_6955 tg3_nvram_write_block_unbuffered 3 6955 NULL
109255 +pch_uart_hal_read_6961 pch_uart_hal_read 0 6961 NULL
109256 +rsa_extract_mpi_6973 rsa_extract_mpi 5 6973 NULL nohasharray
109257 +i40e_dbg_dump_write_6973 i40e_dbg_dump_write 3 6973 &rsa_extract_mpi_6973
109258 +request_key_async_6990 request_key_async 4 6990 NULL
109259 +tpl_write_6998 tpl_write 3 6998 NULL
109260 +r871x_set_wpa_ie_7000 r871x_set_wpa_ie 3 7000 NULL
109261 +cipso_v4_gentag_enum_7006 cipso_v4_gentag_enum 0 7006 NULL
109262 +tracing_cpumask_read_7010 tracing_cpumask_read 3 7010 NULL
109263 +ld_usb_write_7022 ld_usb_write 3 7022 NULL
109264 +wimax_msg_7030 wimax_msg 4 7030 NULL
109265 +ipath_get_base_info_7043 ipath_get_base_info 3 7043 NULL
109266 +snd_pcm_oss_bytes_7051 snd_pcm_oss_bytes 2 7051 NULL
109267 +hci_sock_recvmsg_7072 hci_sock_recvmsg 4 7072 NULL
109268 +event_enable_read_7074 event_enable_read 3 7074 NULL
109269 +beacon_interval_read_7091 beacon_interval_read 3 7091 NULL
109270 +pipeline_enc_rx_stat_fifo_int_read_7107 pipeline_enc_rx_stat_fifo_int_read 3 7107 NULL
109271 +osc_resend_count_seq_write_7120 osc_resend_count_seq_write 3 7120 NULL
109272 +qib_format_hwerrors_7133 qib_format_hwerrors 5 7133 NULL
109273 +kvm_mmu_notifier_test_young_7139 kvm_mmu_notifier_test_young 3 7139 NULL
109274 +__alloc_objio_seg_7203 __alloc_objio_seg 1 7203 NULL
109275 +hdlc_loop_7255 hdlc_loop 0 7255 NULL
109276 +f_midi_start_ep_7270 f_midi_start_ep 0 7270 NULL
109277 +rx_rate_rx_frames_per_rates_read_7282 rx_rate_rx_frames_per_rates_read 3 7282 NULL
109278 +get_string_7302 get_string 0 7302 NULL
109279 +mgmt_control_7349 mgmt_control 3 7349 NULL
109280 +at_est2timeout_7365 at_est2timeout 0-1 7365 NULL
109281 +ieee80211_if_read_dot11MeshHWMPactivePathTimeout_7368 ieee80211_if_read_dot11MeshHWMPactivePathTimeout 3 7368 NULL
109282 +ath10k_read_fw_stats_7387 ath10k_read_fw_stats 3 7387 NULL
109283 +hweight_long_7388 hweight_long 1-0 7388 NULL
109284 +sl_change_mtu_7396 sl_change_mtu 2 7396 NULL
109285 +_ore_add_stripe_unit_7399 _ore_add_stripe_unit 6-3 7399 NULL
109286 +readb_7401 readb 0 7401 NULL
109287 +drm_property_create_blob_7414 drm_property_create_blob 2 7414 NULL
109288 +__copy_to_user_nocheck_7443 __copy_to_user_nocheck 0-3 7443 NULL
109289 +ip_options_get_alloc_7448 ip_options_get_alloc 1 7448 NULL
109290 +SYSC_setgroups_7454 SYSC_setgroups 1 7454 NULL
109291 +rt2x00debug_read_queue_stats_7455 rt2x00debug_read_queue_stats 3 7455 NULL
109292 +l2tp_ip6_sendmsg_7461 l2tp_ip6_sendmsg 4 7461 NULL
109293 +garp_request_join_7471 garp_request_join 4 7471 NULL nohasharray
109294 +ReadHSCX_7471 ReadHSCX 0 7471 &garp_request_join_7471
109295 +snd_pcm_lib_read1_7491 snd_pcm_lib_read1 0-3 7491 NULL
109296 +iwl_mvm_power_dbgfs_read_7502 iwl_mvm_power_dbgfs_read 0 7502 NULL
109297 +ahash_instance_headroom_7509 ahash_instance_headroom 0 7509 NULL nohasharray
109298 +sdhci_alloc_host_7509 sdhci_alloc_host 2 7509 &ahash_instance_headroom_7509
109299 +array_zalloc_7519 array_zalloc 1-2 7519 NULL
109300 +ath10k_read_htt_stats_mask_7557 ath10k_read_htt_stats_mask 3 7557 NULL
109301 +smk_read_mapped_7562 smk_read_mapped 3 7562 NULL
109302 +cfs_cpt_num_estimate_7571 cfs_cpt_num_estimate 0 7571 NULL
109303 +ocfs2_lock_create_7612 ocfs2_lock_create 0 7612 NULL
109304 +groups_alloc_7614 groups_alloc 1 7614 NULL nohasharray
109305 +create_dir_7614 create_dir 0 7614 &groups_alloc_7614
109306 +_rtw_zmalloc_7636 _rtw_zmalloc 1 7636 NULL
109307 +fault_inject_write_7662 fault_inject_write 3 7662 NULL
109308 +acpi_ex_allocate_name_string_7685 acpi_ex_allocate_name_string 2-1 7685 NULL
109309 +acpi_ns_get_pathname_length_7699 acpi_ns_get_pathname_length 0 7699 NULL
109310 +dev_write_7708 dev_write 3 7708 NULL
109311 +pci_raw_set_power_state_7729 pci_raw_set_power_state 0 7729 NULL
109312 +vxge_device_register_7752 vxge_device_register 4 7752 NULL
109313 +iwl_dbgfs_bt_cmd_read_7770 iwl_dbgfs_bt_cmd_read 3 7770 NULL
109314 +alloc_candev_7776 alloc_candev 1-2 7776 NULL
109315 +dfs_global_file_read_7787 dfs_global_file_read 3 7787 NULL
109316 +bnx2_nvram_write_7790 bnx2_nvram_write 4-2 7790 NULL
109317 +diva_os_copy_from_user_7792 diva_os_copy_from_user 4 7792 NULL nohasharray
109318 +lustre_packed_msg_size_7792 lustre_packed_msg_size 0 7792 &diva_os_copy_from_user_7792
109319 +cfs_trace_dump_debug_buffer_usrstr_7861 cfs_trace_dump_debug_buffer_usrstr 2 7861 NULL
109320 +tipc_alloc_entry_7875 tipc_alloc_entry 2 7875 NULL
109321 +config_desc_7878 config_desc 0 7878 NULL
109322 +dvb_dmxdev_read_sec_7892 dvb_dmxdev_read_sec 4 7892 NULL
109323 +xfs_trans_get_efi_7898 xfs_trans_get_efi 2 7898 NULL
109324 +libfc_host_alloc_7917 libfc_host_alloc 2 7917 NULL
109325 +f_hidg_write_7932 f_hidg_write 3 7932 NULL
109326 +integrity_digsig_verify_7956 integrity_digsig_verify 3-0 7956 NULL
109327 +smk_write_load_self_7958 smk_write_load_self 3 7958 NULL
109328 +tt3650_ci_msg_locked_8013 tt3650_ci_msg_locked 4 8013 NULL
109329 +vcs_read_8017 vcs_read 3 8017 NULL
109330 +vhost_add_used_and_signal_n_8038 vhost_add_used_and_signal_n 4 8038 NULL
109331 +ms_read_multiple_pages_8052 ms_read_multiple_pages 5-4 8052 NULL
109332 +dgrp_mon_read_8065 dgrp_mon_read 3 8065 NULL
109333 +spi_write_then_read_8073 spi_write_then_read 5-3 8073 NULL
109334 +qla4xxx_post_ping_evt_work_8074 qla4xxx_post_ping_evt_work 4 8074 NULL
109335 +venus_lookup_8121 venus_lookup 4 8121 NULL
109336 +ieee80211_if_fmt_num_buffered_multicast_8127 ieee80211_if_fmt_num_buffered_multicast 3 8127 NULL
109337 +xfs_file_fallocate_8150 xfs_file_fallocate 3-4 8150 NULL
109338 +__sk_mem_schedule_8185 __sk_mem_schedule 2 8185 NULL
109339 +ieee80211_if_fmt_dot11MeshHoldingTimeout_8187 ieee80211_if_fmt_dot11MeshHoldingTimeout 3 8187 NULL
109340 +recent_mt_proc_write_8206 recent_mt_proc_write 3 8206 NULL
109341 +__ocfs2_lock_refcount_tree_8207 __ocfs2_lock_refcount_tree 0 8207 NULL
109342 +rt2x00debug_write_bbp_8212 rt2x00debug_write_bbp 3 8212 NULL
109343 +ad7879_spi_multi_read_8218 ad7879_spi_multi_read 3 8218 NULL
109344 +play_iframe_8219 play_iframe 3 8219 NULL
109345 +kvm_mmu_page_set_gfn_8225 kvm_mmu_page_set_gfn 2 8225 NULL
109346 +sctp_ssnmap_size_8228 sctp_ssnmap_size 0-1-2 8228 NULL
109347 +ceph_sync_write_8233 ceph_sync_write 4 8233 NULL
109348 +check_xattr_ref_inode_8244 check_xattr_ref_inode 0 8244 NULL
109349 +t3_init_l2t_8261 t3_init_l2t 1 8261 NULL
109350 +init_cdev_8274 init_cdev 1 8274 NULL
109351 +rproc_recovery_write_8281 rproc_recovery_write 3 8281 NULL
109352 +qib_decode_7220_err_8315 qib_decode_7220_err 3 8315 NULL
109353 +ipwireless_send_packet_8328 ipwireless_send_packet 4 8328 NULL
109354 +tracing_entries_read_8345 tracing_entries_read 3 8345 NULL
109355 +ieee80211_if_fmt_ht_opmode_8347 ieee80211_if_fmt_ht_opmode 3 8347 NULL
109356 +generic_write_sync_8358 generic_write_sync 0 8358 NULL
109357 +ping_getfrag_8360 ping_getfrag 4-3 8360 NULL
109358 +ath6kl_lrssi_roam_write_8362 ath6kl_lrssi_roam_write 3 8362 NULL
109359 +xdi_copy_from_user_8395 xdi_copy_from_user 4 8395 NULL
109360 +zd_rf_scnprint_id_8406 zd_rf_scnprint_id 0-3 8406 NULL
109361 +smk_write_change_rule_8411 smk_write_change_rule 3 8411 NULL nohasharray
109362 +uvc_v4l2_ioctl_8411 uvc_v4l2_ioctl 2 8411 &smk_write_change_rule_8411
109363 +roccat_common2_sysfs_read_8431 roccat_common2_sysfs_read 6 8431 NULL
109364 +afs_cell_lookup_8482 afs_cell_lookup 2 8482 NULL
109365 +fore200e_chunk_alloc_8501 fore200e_chunk_alloc 4-3 8501 NULL
109366 +batadv_tt_len_8502 batadv_tt_len 0-1 8502 NULL
109367 +dev_config_8506 dev_config 3 8506 NULL
109368 +ACL_to_cifs_posix_8509 ACL_to_cifs_posix 3 8509 NULL
109369 +opticon_process_data_packet_8524 opticon_process_data_packet 3 8524 NULL
109370 +user_on_off_8552 user_on_off 2 8552 NULL
109371 +profile_remove_8556 profile_remove 3 8556 NULL
109372 +cache_slow_downcall_8570 cache_slow_downcall 2 8570 NULL
109373 +isr_dma0_done_read_8574 isr_dma0_done_read 3 8574 NULL
109374 +tower_write_8580 tower_write 3 8580 NULL
109375 +cfs_cpt_number_8618 cfs_cpt_number 0 8618 NULL
109376 +shash_setkey_unaligned_8620 shash_setkey_unaligned 3 8620 NULL
109377 +it821x_firmware_command_8628 it821x_firmware_command 3 8628 NULL
109378 +scsi_dma_map_8632 scsi_dma_map 0 8632 NULL
109379 +fuse_send_write_pages_8636 fuse_send_write_pages 0-5 8636 NULL
109380 +generic_acl_set_8658 generic_acl_set 4 8658 NULL
109381 +mlx5_vzalloc_8663 mlx5_vzalloc 1 8663 NULL
109382 +dio_bio_alloc_8677 dio_bio_alloc 5 8677 NULL
109383 +lbs_bcnmiss_read_8678 lbs_bcnmiss_read 3 8678 NULL
109384 +rproc_trace_read_8686 rproc_trace_read 3 8686 NULL
109385 +skb_frag_size_8695 skb_frag_size 0 8695 NULL
109386 +arcfb_write_8702 arcfb_write 3 8702 NULL
109387 +i_size_read_8703 i_size_read 0 8703 NULL nohasharray
109388 +init_header_8703 init_header 0 8703 &i_size_read_8703
109389 +HDLC_irq_8709 HDLC_irq 2 8709 NULL
109390 +ctrl_out_8712 ctrl_out 3-5 8712 NULL
109391 +tracing_max_lat_write_8728 tracing_max_lat_write 3 8728 NULL
109392 +jffs2_acl_count_8729 jffs2_acl_count 0-1 8729 NULL
109393 +__create_irqs_8733 __create_irqs 2 8733 NULL
109394 +tx_tx_exch_expiry_read_8749 tx_tx_exch_expiry_read 3 8749 NULL
109395 +compound_order_8750 compound_order 0 8750 NULL
109396 +ocfs2_find_path_8754 ocfs2_find_path 0 8754 NULL
109397 +yurex_write_8761 yurex_write 3 8761 NULL
109398 +joydev_compat_ioctl_8765 joydev_compat_ioctl 2 8765 NULL
109399 +kstrtoint_from_user_8778 kstrtoint_from_user 2 8778 NULL
109400 +paging32_prefetch_gpte_8783 paging32_prefetch_gpte 4 8783 NULL
109401 +ext4_try_to_write_inline_data_8785 ext4_try_to_write_inline_data 3-4 8785 NULL
109402 +__bitmap_weight_8796 __bitmap_weight 0-2 8796 NULL
109403 +cpuset_common_file_read_8800 cpuset_common_file_read 5 8800 NULL
109404 +metronomefb_write_8823 metronomefb_write 3 8823 NULL
109405 +SyS_llistxattr_8824 SyS_llistxattr 3 8824 NULL
109406 +get_queue_depth_8833 get_queue_depth 0 8833 NULL
109407 +dvb_ringbuffer_pkt_next_8834 dvb_ringbuffer_pkt_next 0-2 8834 NULL
109408 +usb_ep_queue_8839 usb_ep_queue 0 8839 NULL
109409 +debug_debug1_read_8856 debug_debug1_read 3 8856 NULL
109410 +wa_nep_queue_8858 wa_nep_queue 2 8858 NULL
109411 +radeon_drm_ioctl_8875 radeon_drm_ioctl 2 8875 NULL
109412 +compressed_bio_size_8887 compressed_bio_size 0-2 8887 NULL
109413 +ab3100_get_set_reg_8890 ab3100_get_set_reg 3 8890 NULL nohasharray
109414 +tracing_max_lat_read_8890 tracing_max_lat_read 3 8890 &ab3100_get_set_reg_8890
109415 +sdio_max_byte_size_8907 sdio_max_byte_size 0 8907 NULL
109416 +sysfs_merge_group_8917 sysfs_merge_group 0 8917 NULL
109417 +write_file_ani_8918 write_file_ani 3 8918 NULL
109418 +layout_commit_8926 layout_commit 3 8926 NULL
109419 +adjust_priv_size_8935 adjust_priv_size 0-1 8935 NULL
109420 +driver_stats_read_8944 driver_stats_read 3 8944 NULL
109421 +read_file_tgt_stats_8959 read_file_tgt_stats 3 8959 NULL
109422 +usb_allocate_stream_buffers_8964 usb_allocate_stream_buffers 3 8964 NULL
109423 +qib_qsfp_dump_8966 qib_qsfp_dump 0-3 8966 NULL
109424 +venus_mkdir_8967 venus_mkdir 4 8967 NULL
109425 +seq_open_net_8968 seq_open_net 4 8968 NULL nohasharray
109426 +vol_cdev_read_8968 vol_cdev_read 3 8968 &seq_open_net_8968
109427 +bio_integrity_get_tag_8974 bio_integrity_get_tag 3 8974 NULL
109428 +jbd2_journal_blocks_per_page_9004 jbd2_journal_blocks_per_page 0 9004 NULL
109429 +il_dbgfs_clear_ucode_stats_write_9016 il_dbgfs_clear_ucode_stats_write 3 9016 NULL
109430 +snd_emu10k1_ptr_read_9026 snd_emu10k1_ptr_read 0-2 9026 NULL
109431 +fd_ioctl_9028 fd_ioctl 3 9028 NULL
109432 +nla_put_9042 nla_put 3 9042 NULL
109433 +snd_emu10k1_synth_copy_from_user_9061 snd_emu10k1_synth_copy_from_user 3-5 9061 NULL
109434 +snd_gus_dram_peek_9062 snd_gus_dram_peek 4 9062 NULL
109435 +fib_info_hash_alloc_9075 fib_info_hash_alloc 1 9075 NULL
109436 +create_queues_9088 create_queues 2-3 9088 NULL
109437 +ftdi_prepare_write_buffer_9093 ftdi_prepare_write_buffer 3 9093 NULL
109438 +adxl34x_spi_read_block_9108 adxl34x_spi_read_block 3 9108 NULL
109439 +caif_stream_sendmsg_9110 caif_stream_sendmsg 4 9110 NULL nohasharray
109440 +gfn_to_rmap_9110 gfn_to_rmap 3-2 9110 &caif_stream_sendmsg_9110
109441 +udf_direct_IO_9111 udf_direct_IO 4 9111 NULL
109442 +pmcraid_change_queue_depth_9116 pmcraid_change_queue_depth 2 9116 NULL
109443 +apei_resources_merge_9149 apei_resources_merge 0 9149 NULL
109444 +vb2_dma_sg_alloc_9157 vb2_dma_sg_alloc 2 9157 NULL
109445 +dbg_command_buf_9165 dbg_command_buf 2 9165 NULL
109446 +isr_irqs_read_9181 isr_irqs_read 3 9181 NULL
109447 +count_leading_zeros_9183 count_leading_zeros 0 9183 NULL
109448 +altera_swap_ir_9194 altera_swap_ir 2 9194 NULL
109449 +snd_m3_get_pointer_9206 snd_m3_get_pointer 0 9206 NULL
109450 +virtqueue_add_9217 virtqueue_add 4-5 9217 NULL
109451 +tx_tx_prepared_descs_read_9221 tx_tx_prepared_descs_read 3 9221 NULL
109452 +sctp_getsockopt_delayed_ack_9232 sctp_getsockopt_delayed_ack 2 9232 NULL
109453 +hfsplus_bnode_read_u16_9262 hfsplus_bnode_read_u16 0 9262 NULL
109454 +hdpvr_read_9273 hdpvr_read 3 9273 NULL
109455 +flakey_status_9274 flakey_status 5 9274 NULL
109456 +iwl_dbgfs_stations_read_9309 iwl_dbgfs_stations_read 3 9309 NULL
109457 +ceph_sync_setxattr_9310 ceph_sync_setxattr 4 9310 NULL
109458 +ieee80211_if_fmt_txpower_9334 ieee80211_if_fmt_txpower 3 9334 NULL
109459 +nvme_trans_fmt_get_parm_header_9340 nvme_trans_fmt_get_parm_header 2 9340 NULL
109460 +ocfs2_orphan_for_truncate_9342 ocfs2_orphan_for_truncate 4 9342 NULL
109461 +ll_direct_rw_pages_9361 ll_direct_rw_pages 0 9361 NULL
109462 +sta_beacon_loss_count_read_9370 sta_beacon_loss_count_read 3 9370 NULL
109463 +get_request_type_9393 get_request_type 0 9393 NULL nohasharray
109464 +mlx4_bitmap_init_9393 mlx4_bitmap_init 5-2 9393 &get_request_type_9393
109465 +virtqueue_add_outbuf_9395 virtqueue_add_outbuf 3 9395 NULL
109466 +read_9397 read 3 9397 NULL
109467 +hash_ipportip4_expire_9415 hash_ipportip4_expire 4 9415 NULL
109468 +btrfs_drop_extents_9423 btrfs_drop_extents 4 9423 NULL
109469 +bm_realloc_pages_9431 bm_realloc_pages 2 9431 NULL
109470 +ffs_ep0_write_9438 ffs_ep0_write 3 9438 NULL
109471 +ieee80211_if_fmt_fwded_unicast_9454 ieee80211_if_fmt_fwded_unicast 3 9454 NULL
109472 +ext3_xattr_set_acl_9467 ext3_xattr_set_acl 4 9467 NULL
109473 +agp_generic_alloc_user_9470 agp_generic_alloc_user 1 9470 NULL nohasharray
109474 +get_registers_9470 get_registers 4 9470 &agp_generic_alloc_user_9470
109475 +crypt_status_9492 crypt_status 5 9492 NULL
109476 +lbs_threshold_write_9502 lbs_threshold_write 5 9502 NULL
109477 +lp_write_9511 lp_write 3 9511 NULL
109478 +mext_calc_swap_extents_9517 mext_calc_swap_extents 4 9517 NULL
109479 +scsi_tgt_kspace_exec_9522 scsi_tgt_kspace_exec 8 9522 NULL
109480 +ll_max_read_ahead_whole_mb_seq_write_9528 ll_max_read_ahead_whole_mb_seq_write 3 9528 NULL
109481 +read_file_dma_9530 read_file_dma 3 9530 NULL
109482 +iwl_dbgfs_bf_params_read_9542 iwl_dbgfs_bf_params_read 3 9542 NULL
109483 +il_dbgfs_missed_beacon_write_9546 il_dbgfs_missed_beacon_write 3 9546 NULL
109484 +compat_SyS_pwritev64_9548 compat_SyS_pwritev64 3 9548 NULL
109485 +fw_node_create_9559 fw_node_create 2 9559 NULL
109486 +kobj_map_9566 kobj_map 2-3 9566 NULL
109487 +f2fs_read_data_pages_9574 f2fs_read_data_pages 4 9574 NULL
109488 +snd_emu10k1_fx8010_read_9605 snd_emu10k1_fx8010_read 5-6 9605 NULL
109489 +lov_ost_pool_add_9626 lov_ost_pool_add 3 9626 NULL
109490 +saa7164_buffer_alloc_user_9627 saa7164_buffer_alloc_user 2 9627 NULL
109491 +ceph_copy_user_to_page_vector_9635 ceph_copy_user_to_page_vector 4-3 9635 NULL
109492 +acpi_ex_insert_into_field_9638 acpi_ex_insert_into_field 3 9638 NULL
109493 +compat_sys_keyctl_9639 compat_sys_keyctl 4 9639 NULL
109494 +ll_checksum_seq_write_9648 ll_checksum_seq_write 3 9648 NULL
109495 +ocfs2_xattr_get_rec_9652 ocfs2_xattr_get_rec 0 9652 NULL
109496 +queue_received_packet_9657 queue_received_packet 5 9657 NULL
109497 +snd_opl4_mem_proc_write_9670 snd_opl4_mem_proc_write 5 9670 NULL
109498 +dns_query_9676 dns_query 3 9676 NULL
109499 +qib_7322_handle_hwerrors_9678 qib_7322_handle_hwerrors 3 9678 NULL
109500 +__erst_read_from_storage_9690 __erst_read_from_storage 0 9690 NULL
109501 +vx_transfer_end_9701 vx_transfer_end 0 9701 NULL
109502 +fuse_iter_npages_9705 fuse_iter_npages 0 9705 NULL nohasharray
109503 +ieee80211_if_read_aid_9705 ieee80211_if_read_aid 3 9705 &fuse_iter_npages_9705
109504 +cfg80211_tx_mlme_mgmt_9715 cfg80211_tx_mlme_mgmt 3 9715 NULL
109505 +btrfs_stack_file_extent_num_bytes_9720 btrfs_stack_file_extent_num_bytes 0 9720 NULL
109506 +SYSC_ppoll_9721 SYSC_ppoll 2 9721 NULL
109507 +nla_get_u8_9736 nla_get_u8 0 9736 NULL
109508 +ieee80211_if_fmt_num_mcast_sta_9738 ieee80211_if_fmt_num_mcast_sta 3 9738 NULL
109509 +ddb_input_read_9743 ddb_input_read 3-0 9743 NULL
109510 +sta_last_ack_signal_read_9751 sta_last_ack_signal_read 3 9751 NULL
109511 +btrfs_super_root_9763 btrfs_super_root 0 9763 NULL
109512 +__blk_queue_init_tags_9778 __blk_queue_init_tags 2 9778 NULL
109513 +snd_mem_proc_write_9786 snd_mem_proc_write 3 9786 NULL
109514 +kvm_age_hva_9795 kvm_age_hva 2 9795 NULL
109515 +parse_uac2_sample_rate_range_9801 parse_uac2_sample_rate_range 0 9801 NULL
109516 +tpm_data_in_9802 tpm_data_in 0 9802 NULL
109517 +udpv6_recvmsg_9813 udpv6_recvmsg 4 9813 NULL nohasharray
109518 +ieee80211_if_read_state_9813 ieee80211_if_read_state 3 9813 &udpv6_recvmsg_9813
109519 +pmcraid_alloc_sglist_9864 pmcraid_alloc_sglist 1 9864 NULL
109520 +btrfs_free_reserved_extent_9867 btrfs_free_reserved_extent 2 9867 NULL
109521 +f1x_translate_sysaddr_to_cs_9868 f1x_translate_sysaddr_to_cs 2 9868 NULL
109522 +wil_read_file_ioblob_9878 wil_read_file_ioblob 3 9878 NULL
109523 +snd_midi_event_new_9893 snd_midi_event_new 1 9893 NULL nohasharray
109524 +bm_register_write_9893 bm_register_write 3 9893 &snd_midi_event_new_9893
109525 +snd_gf1_pcm_playback_copy_9895 snd_gf1_pcm_playback_copy 5-3 9895 NULL
109526 +nonpaging_page_fault_9908 nonpaging_page_fault 2 9908 NULL
109527 +root_nfs_parse_options_9937 root_nfs_parse_options 3 9937 NULL
109528 +pstore_ftrace_knob_read_9947 pstore_ftrace_knob_read 3 9947 NULL
109529 +read_file_misc_9948 read_file_misc 3 9948 NULL
109530 +csum_partial_copy_fromiovecend_9957 csum_partial_copy_fromiovecend 3-4 9957 NULL
109531 +SyS_gethostname_9964 SyS_gethostname 2 9964 NULL
109532 +get_free_serial_index_9969 get_free_serial_index 0 9969 NULL
109533 +btrfs_add_link_9973 btrfs_add_link 5 9973 NULL
109534 +gameport_read_9983 gameport_read 0 9983 NULL
109535 +SYSC_move_pages_9986 SYSC_move_pages 2 9986 NULL
109536 +aat2870_dump_reg_10019 aat2870_dump_reg 0 10019 NULL
109537 +ieee80211_set_probe_resp_10077 ieee80211_set_probe_resp 3 10077 NULL
109538 +get_elem_size_10110 get_elem_size 0-2 10110 NULL nohasharray
109539 +dynamic_ps_timeout_read_10110 dynamic_ps_timeout_read 3 10110 &get_elem_size_10110
109540 +gfs2_meta_read_10112 gfs2_meta_read 0 10112 NULL
109541 +SyS_migrate_pages_10134 SyS_migrate_pages 2 10134 NULL
109542 +aes_decrypt_packets_read_10155 aes_decrypt_packets_read 3 10155 NULL
109543 +rx_out_of_mem_read_10157 rx_out_of_mem_read 3 10157 NULL
109544 +hidg_alloc_ep_req_10159 hidg_alloc_ep_req 2 10159 NULL
109545 +asd_store_update_bios_10165 asd_store_update_bios 4 10165 NULL
109546 +kstrtol_from_user_10168 kstrtol_from_user 2 10168 NULL
109547 +proc_pid_attr_read_10173 proc_pid_attr_read 3 10173 NULL
109548 +jffs2_user_setxattr_10182 jffs2_user_setxattr 4 10182 NULL
109549 +hdlc_rpr_irq_10240 hdlc_rpr_irq 2 10240 NULL
109550 +cciss_proc_write_10259 cciss_proc_write 3 10259 NULL
109551 +__qlcnic_pci_sriov_enable_10281 __qlcnic_pci_sriov_enable 2 10281 NULL
109552 +snd_rme9652_capture_copy_10287 snd_rme9652_capture_copy 5 10287 NULL
109553 +read_emulate_10310 read_emulate 2-4 10310 NULL
109554 +read_file_spectral_count_10320 read_file_spectral_count 3 10320 NULL
109555 +compat_SyS_writev_10327 compat_SyS_writev 3 10327 NULL
109556 +tun_sendmsg_10337 tun_sendmsg 4 10337 NULL
109557 +ufx_alloc_urb_list_10349 ufx_alloc_urb_list 3 10349 NULL
109558 +whci_add_cap_10350 whci_add_cap 0 10350 NULL
109559 +dbAllocAny_10354 dbAllocAny 0 10354 NULL
109560 +ath6kl_listen_int_read_10355 ath6kl_listen_int_read 3 10355 NULL
109561 +ms_write_multiple_pages_10362 ms_write_multiple_pages 6-5 10362 NULL
109562 +sta_ht_capa_read_10366 sta_ht_capa_read 3 10366 NULL
109563 +ecryptfs_decode_and_decrypt_filename_10379 ecryptfs_decode_and_decrypt_filename 5 10379 NULL
109564 +do_compat_pselect_10398 do_compat_pselect 1 10398 NULL
109565 +fwtty_rx_10434 fwtty_rx 3 10434 NULL
109566 +event_phy_transmit_error_read_10471 event_phy_transmit_error_read 3 10471 NULL
109567 +hash_ipportip6_expire_10478 hash_ipportip6_expire 4 10478 NULL
109568 +nouveau_pwr_create__10483 nouveau_pwr_create_ 4 10483 NULL
109569 +ext4_itable_unused_count_10501 ext4_itable_unused_count 0 10501 NULL
109570 +qib_alloc_fast_reg_page_list_10507 qib_alloc_fast_reg_page_list 2 10507 NULL
109571 +sel_write_disable_10511 sel_write_disable 3 10511 NULL
109572 +osd_req_write_sg_kern_10514 osd_req_write_sg_kern 5 10514 NULL
109573 +rds_message_alloc_10517 rds_message_alloc 1 10517 NULL
109574 +qlcnic_pci_sriov_enable_10519 qlcnic_pci_sriov_enable 2 10519 NULL
109575 +kstrtouint_from_user_10536 kstrtouint_from_user 2 10536 NULL nohasharray
109576 +snd_pcm_lib_read_10536 snd_pcm_lib_read 0-3 10536 &kstrtouint_from_user_10536
109577 +ext4_write_begin_10576 ext4_write_begin 3-4 10576 NULL
109578 +scrub_remap_extent_10588 scrub_remap_extent 2 10588 NULL
109579 +otp_read_10594 otp_read 2-4-5 10594 NULL
109580 +supply_map_read_file_10608 supply_map_read_file 3 10608 NULL
109581 +ima_show_htable_violations_10619 ima_show_htable_violations 3 10619 NULL
109582 +nfs_idmap_lookup_id_10660 nfs_idmap_lookup_id 2 10660 NULL
109583 +efx_max_tx_len_10662 efx_max_tx_len 0-2 10662 NULL
109584 +parport_write_10669 parport_write 0 10669 NULL
109585 +edge_write_10692 edge_write 4 10692 NULL
109586 +selinux_inode_setxattr_10708 selinux_inode_setxattr 4 10708 NULL nohasharray
109587 +inl_10708 inl 0 10708 &selinux_inode_setxattr_10708
109588 +shash_async_setkey_10720 shash_async_setkey 3 10720 NULL nohasharray
109589 +pvr2_ioread_read_10720 pvr2_ioread_read 3 10720 &shash_async_setkey_10720
109590 +spi_sync_10731 spi_sync 0 10731 NULL
109591 +apu_get_register_10737 apu_get_register 0 10737 NULL nohasharray
109592 +sctp_getsockopt_maxseg_10737 sctp_getsockopt_maxseg 2 10737 &apu_get_register_10737
109593 +SyS_io_getevents_10756 SyS_io_getevents 3 10756 NULL
109594 +vhost_add_used_n_10760 vhost_add_used_n 3 10760 NULL
109595 +kvm_read_guest_atomic_10765 kvm_read_guest_atomic 4 10765 NULL
109596 +__qp_memcpy_to_queue_10779 __qp_memcpy_to_queue 2-4 10779 NULL
109597 +diva_set_trace_filter_10820 diva_set_trace_filter 0-1 10820 NULL
109598 +lbs_sleepparams_read_10840 lbs_sleepparams_read 3 10840 NULL
109599 +ida_get_new_above_10853 ida_get_new_above 0 10853 NULL
109600 +fuse_conn_max_background_read_10855 fuse_conn_max_background_read 3 10855 NULL
109601 +snd_pcm_oss_write1_10872 snd_pcm_oss_write1 3 10872 NULL
109602 +wiidebug_drm_write_10879 wiidebug_drm_write 3 10879 NULL
109603 +get_scq_10897 get_scq 2 10897 NULL
109604 +cgroup_write_string_10900 cgroup_write_string 5 10900 NULL
109605 +tifm_alloc_adapter_10903 tifm_alloc_adapter 1 10903 NULL
109606 +lprocfs_wr_atomic_10912 lprocfs_wr_atomic 3 10912 NULL
109607 +__copy_from_user_10918 __copy_from_user 0-3 10918 NULL
109608 +kobject_add_10919 kobject_add 0 10919 NULL
109609 +ar9003_dump_modal_eeprom_10959 ar9003_dump_modal_eeprom 3-2-0 10959 NULL
109610 +ci_port_test_write_10962 ci_port_test_write 3 10962 NULL
109611 +bm_entry_read_10976 bm_entry_read 3 10976 NULL
109612 +sched_autogroup_write_10984 sched_autogroup_write 3 10984 NULL
109613 +xfrm_hash_alloc_10997 xfrm_hash_alloc 1 10997 NULL
109614 +rx_filter_accum_arp_pend_requests_read_11003 rx_filter_accum_arp_pend_requests_read 3 11003 NULL
109615 +SetLineNumber_11023 SetLineNumber 0 11023 NULL
109616 +tda10048_writeregbulk_11050 tda10048_writeregbulk 4 11050 NULL
109617 +insert_inline_extent_backref_11063 insert_inline_extent_backref 8 11063 NULL
109618 +tcp_send_mss_11079 tcp_send_mss 0 11079 NULL
109619 +count_argc_11083 count_argc 0 11083 NULL
109620 +ocfs2_blocks_per_xattr_bucket_11099 ocfs2_blocks_per_xattr_bucket 0 11099 NULL
109621 +kvm_write_guest_cached_11106 kvm_write_guest_cached 4 11106 NULL
109622 +tw_change_queue_depth_11116 tw_change_queue_depth 2 11116 NULL
109623 +page_offset_11120 page_offset 0 11120 NULL
109624 +cea_db_payload_len_11124 cea_db_payload_len 0 11124 NULL nohasharray
109625 +tracing_buffers_read_11124 tracing_buffers_read 3 11124 &cea_db_payload_len_11124
109626 +alloc_alien_cache_11127 alloc_alien_cache 2 11127 NULL
109627 +snd_gf1_pcm_playback_silence_11172 snd_gf1_pcm_playback_silence 4-3 11172 NULL
109628 +il_dbgfs_rx_queue_read_11221 il_dbgfs_rx_queue_read 3 11221 NULL
109629 +comedi_alloc_spriv_11234 comedi_alloc_spriv 2 11234 NULL
109630 +hugetlbfs_read_11268 hugetlbfs_read 3 11268 NULL
109631 +ath6kl_power_params_write_11274 ath6kl_power_params_write 3 11274 NULL
109632 +__proc_daemon_file_11305 __proc_daemon_file 5 11305 NULL
109633 +ext4_xattr_check_names_11314 ext4_xattr_check_names 0 11314 NULL
109634 +bcache_dev_sectors_dirty_add_11315 bcache_dev_sectors_dirty_add 3-4 11315 NULL
109635 +sk_filter_size_11316 sk_filter_size 0 11316 NULL nohasharray
109636 +tcp_send_rcvq_11316 tcp_send_rcvq 3 11316 &sk_filter_size_11316
109637 +construct_key_11329 construct_key 3 11329 NULL nohasharray
109638 +__kfifo_out_peek_11329 __kfifo_out_peek 0-3 11329 &construct_key_11329
109639 +next_segment_11330 next_segment 0-2-1 11330 NULL
109640 +persistent_ram_buffer_map_11332 persistent_ram_buffer_map 2-1 11332 NULL
109641 +ext4_get_inline_size_11349 ext4_get_inline_size 0 11349 NULL
109642 +sel_write_create_11353 sel_write_create 3 11353 NULL nohasharray
109643 +nl80211_send_mgmt_11353 nl80211_send_mgmt 7 11353 &sel_write_create_11353
109644 +qib_get_base_info_11369 qib_get_base_info 3 11369 NULL
109645 +nft_value_dump_11381 nft_value_dump 3 11381 NULL
109646 +isku_sysfs_read_keys_capslock_11392 isku_sysfs_read_keys_capslock 6 11392 NULL
109647 +dev_irnet_write_11398 dev_irnet_write 3 11398 NULL
109648 +lprocfs_wr_evict_client_11402 lprocfs_wr_evict_client 3 11402 NULL
109649 +___alloc_bootmem_11410 ___alloc_bootmem 1 11410 NULL
109650 +str_to_user_11411 str_to_user 2 11411 NULL
109651 +mem_fw_gen_free_mem_blks_read_11413 mem_fw_gen_free_mem_blks_read 3 11413 NULL
109652 +ath6kl_wmi_test_rx_11414 ath6kl_wmi_test_rx 3 11414 NULL
109653 +adis16480_show_firmware_revision_11417 adis16480_show_firmware_revision 3 11417 NULL nohasharray
109654 +import_sec_validate_get_11417 import_sec_validate_get 0 11417 &adis16480_show_firmware_revision_11417
109655 +trace_options_read_11419 trace_options_read 3 11419 NULL
109656 +i40e_dbg_command_write_11421 i40e_dbg_command_write 3 11421 NULL
109657 +xd_read_multiple_pages_11422 xd_read_multiple_pages 5-4 11422 NULL
109658 +bttv_read_11432 bttv_read 3 11432 NULL
109659 +create_zero_mask_11453 create_zero_mask 0-1 11453 NULL
109660 +do_blockdev_direct_IO_11455 do_blockdev_direct_IO 0-6 11455 NULL
109661 +pci_set_power_state_11479 pci_set_power_state 0 11479 NULL nohasharray
109662 +sca3000_read_first_n_hw_rb_11479 sca3000_read_first_n_hw_rb 2 11479 &pci_set_power_state_11479
109663 +xfs_file_buffered_aio_write_11492 xfs_file_buffered_aio_write 4 11492 NULL
109664 +sd_do_mode_sense_11507 sd_do_mode_sense 5 11507 NULL
109665 +kmem_zalloc_11510 kmem_zalloc 1 11510 NULL
109666 +ll_direct_IO_26_seg_11518 ll_direct_IO_26_seg 0 11518 NULL
109667 +twl_direction_in_11527 twl_direction_in 2 11527 NULL
109668 +skb_cow_data_11565 skb_cow_data 0 11565 NULL
109669 +lpfc_idiag_ctlacc_write_11576 lpfc_idiag_ctlacc_write 3 11576 NULL
109670 +oprofilefs_ulong_to_user_11582 oprofilefs_ulong_to_user 3 11582 NULL
109671 +batadv_iv_ogm_orig_add_if_11586 batadv_iv_ogm_orig_add_if 2 11586 NULL
109672 +snd_pcm_action_11589 snd_pcm_action 0 11589 NULL
109673 +fw_device_op_ioctl_11595 fw_device_op_ioctl 2 11595 NULL
109674 +batadv_iv_ogm_orig_del_if_11604 batadv_iv_ogm_orig_del_if 2 11604 NULL
109675 +SYSC_mq_timedsend_11607 SYSC_mq_timedsend 3 11607 NULL
109676 +sisusb_send_bridge_packet_11649 sisusb_send_bridge_packet 2 11649 NULL
109677 +nla_total_size_11658 nla_total_size 1-0 11658 NULL
109678 +slab_ksize_11664 slab_ksize 0 11664 NULL
109679 +ide_queue_pc_tail_11673 ide_queue_pc_tail 5 11673 NULL
109680 +compat_SyS_msgsnd_11675 compat_SyS_msgsnd 3 11675 NULL
109681 +btrfs_alloc_delayed_item_11678 btrfs_alloc_delayed_item 1 11678 NULL
109682 +sctp_setsockopt_hmac_ident_11687 sctp_setsockopt_hmac_ident 3 11687 NULL
109683 +split_11691 split 2 11691 NULL
109684 +snd_ctl_elem_user_tlv_11695 snd_ctl_elem_user_tlv 3 11695 NULL
109685 +blk_rq_cur_bytes_11723 blk_rq_cur_bytes 0 11723 NULL
109686 +dm_bio_prison_create_11749 dm_bio_prison_create 1 11749 NULL
109687 +iwl_dbgfs_qos_read_11753 iwl_dbgfs_qos_read 3 11753 NULL
109688 +ps_pspoll_timeouts_read_11776 ps_pspoll_timeouts_read 3 11776 NULL
109689 +btrfs_key_blockptr_11786 btrfs_key_blockptr 0 11786 NULL
109690 +pcpu_fc_alloc_11818 pcpu_fc_alloc 2 11818 NULL
109691 +umc_device_register_11824 umc_device_register 0 11824 NULL
109692 +zerocopy_sg_from_iovec_11828 zerocopy_sg_from_iovec 3 11828 NULL
109693 +sctp_setsockopt_maxseg_11829 sctp_setsockopt_maxseg 3 11829 NULL
109694 +rts51x_read_status_11830 rts51x_read_status 4 11830 NULL
109695 +unix_stream_connect_11844 unix_stream_connect 3 11844 NULL
109696 +ecryptfs_copy_filename_11868 ecryptfs_copy_filename 4 11868 NULL
109697 +ieee80211_rx_bss_info_11887 ieee80211_rx_bss_info 3 11887 NULL
109698 +mdc_rename_11899 mdc_rename 4-6 11899 NULL
109699 +xstateregs_get_11906 xstateregs_get 4 11906 NULL
109700 +ti_write_11916 ti_write 4 11916 NULL
109701 +fs_devrw_entry_11924 fs_devrw_entry 3 11924 NULL
109702 +bitmap_remap_11929 bitmap_remap 5 11929 NULL
109703 +atomic_sub_return_11939 atomic_sub_return 0-1 11939 NULL
109704 +r1_sync_page_io_11963 r1_sync_page_io 3 11963 NULL
109705 +f1x_swap_interleaved_region_11970 f1x_swap_interleaved_region 0-2 11970 NULL
109706 +read_and_add_raw_conns_11987 read_and_add_raw_conns 0 11987 NULL
109707 +i40e_pci_sriov_configure_12011 i40e_pci_sriov_configure 2 12011 NULL
109708 +ftdi_elan_total_command_size_12045 ftdi_elan_total_command_size 0 12045 NULL
109709 +ieee80211_if_read_user_power_level_12050 ieee80211_if_read_user_power_level 3 12050 NULL
109710 +il4965_ucode_tx_stats_read_12064 il4965_ucode_tx_stats_read 3 12064 NULL
109711 +ptc_proc_write_12076 ptc_proc_write 3 12076 NULL
109712 +batadv_tt_global_size_mod_12085 batadv_tt_global_size_mod 3 12085 NULL
109713 +rtw_malloc2d_12102 rtw_malloc2d 1-2-3 12102 NULL
109714 +alloc_bulk_urbs_generic_12127 alloc_bulk_urbs_generic 5 12127 NULL
109715 +set_powered_12129 set_powered 4 12129 NULL
109716 +ramoops_init_prz_12134 ramoops_init_prz 5 12134 NULL
109717 +xfs_handle_to_dentry_12135 xfs_handle_to_dentry 3 12135 NULL
109718 +rawv6_seticmpfilter_12137 rawv6_seticmpfilter 5 12137 NULL
109719 +rawsock_recvmsg_12144 rawsock_recvmsg 4 12144 NULL
109720 +btmrvl_sdio_host_to_card_12152 btmrvl_sdio_host_to_card 3 12152 NULL
109721 +vmbus_open_12154 vmbus_open 2-3 12154 NULL
109722 +fnic_reset_stats_write_12177 fnic_reset_stats_write 3 12177 NULL
109723 +LNetEQAlloc_12178 LNetEQAlloc 1 12178 NULL
109724 +ddp_make_gl_12179 ddp_make_gl 1 12179 NULL
109725 +compat_do_arpt_set_ctl_12184 compat_do_arpt_set_ctl 4 12184 NULL
109726 +ip_generic_getfrag_12187 ip_generic_getfrag 3-4 12187 NULL
109727 +snd_pcm_kernel_ioctl_12219 snd_pcm_kernel_ioctl 0 12219 NULL
109728 +fuse_get_req_12221 fuse_get_req 2 12221 NULL nohasharray
109729 +aat2870_reg_read_file_12221 aat2870_reg_read_file 3 12221 &fuse_get_req_12221
109730 +__alloc_bootmem_low_nopanic_12235 __alloc_bootmem_low_nopanic 1 12235 NULL
109731 +ib_uverbs_unmarshall_recv_12251 ib_uverbs_unmarshall_recv 5 12251 NULL
109732 +shash_compat_setkey_12267 shash_compat_setkey 3 12267 NULL
109733 +add_sctp_bind_addr_12269 add_sctp_bind_addr 3 12269 NULL
109734 +note_last_dentry_12285 note_last_dentry 3 12285 NULL
109735 +roundup_to_multiple_of_64_12288 roundup_to_multiple_of_64 0-1 12288 NULL nohasharray
109736 +il_dbgfs_nvm_read_12288 il_dbgfs_nvm_read 3 12288 &roundup_to_multiple_of_64_12288
109737 +bt_sock_recvmsg_12316 bt_sock_recvmsg 4 12316 NULL
109738 +pcbit_writecmd_12332 pcbit_writecmd 2 12332 NULL
109739 +mptctl_ioctl_12355 mptctl_ioctl 2 12355 NULL
109740 +__nf_ct_ext_add_length_12364 __nf_ct_ext_add_length 3 12364 NULL
109741 +xfs_iext_inline_to_direct_12384 xfs_iext_inline_to_direct 2 12384 NULL
109742 +btrfs_file_extent_ram_bytes_12391 btrfs_file_extent_ram_bytes 0 12391 NULL nohasharray
109743 +populate_dir_12391 populate_dir 0 12391 &btrfs_file_extent_ram_bytes_12391 nohasharray
109744 +write_file_dump_12391 write_file_dump 3 12391 &populate_dir_12391
109745 +hbucket_elem_add_12416 hbucket_elem_add 3 12416 NULL
109746 +ieee80211_if_read_num_mcast_sta_12419 ieee80211_if_read_num_mcast_sta 3 12419 NULL
109747 +ptlrpc_set_wait_12426 ptlrpc_set_wait 0 12426 NULL
109748 +cfs_array_alloc_12441 cfs_array_alloc 2 12441 NULL
109749 +skb_do_copy_data_nocache_12465 skb_do_copy_data_nocache 5 12465 NULL
109750 +x25_sendmsg_12487 x25_sendmsg 4 12487 NULL
109751 +fnic_trace_ctrl_read_12497 fnic_trace_ctrl_read 3 12497 NULL
109752 +qib_alloc_fast_reg_mr_12526 qib_alloc_fast_reg_mr 2 12526 NULL
109753 +xfs_get_extsz_hint_12531 xfs_get_extsz_hint 0 12531 NULL
109754 +hvc_alloc_12579 hvc_alloc 4 12579 NULL
109755 +pcpu_extend_area_map_12589 pcpu_extend_area_map 2 12589 NULL
109756 +tlbflush_write_file_12598 tlbflush_write_file 3 12598 NULL
109757 +vhci_put_user_12604 vhci_put_user 4 12604 NULL
109758 +sdhci_pltfm_init_12627 sdhci_pltfm_init 3 12627 NULL
109759 +pwr_rcvd_awake_bcns_cnt_read_12632 pwr_rcvd_awake_bcns_cnt_read 3 12632 NULL
109760 +pn_sendmsg_12640 pn_sendmsg 4 12640 NULL
109761 +dwc3_link_state_write_12641 dwc3_link_state_write 3 12641 NULL
109762 +nr_recvmsg_12649 nr_recvmsg 4 12649 NULL
109763 +rtw_android_get_link_speed_12655 rtw_android_get_link_speed 0 12655 NULL
109764 +ocfs2_read_block_12659 ocfs2_read_block 0 12659 NULL
109765 +lustre_pack_request_v2_12665 lustre_pack_request_v2 0 12665 NULL
109766 +sel_read_class_12669 sel_read_class 3 12669 NULL nohasharray
109767 +sparse_mem_maps_populate_node_12669 sparse_mem_maps_populate_node 4 12669 &sel_read_class_12669
109768 +ext4_writepage_trans_blocks_12674 ext4_writepage_trans_blocks 0 12674 NULL
109769 +iwl_dbgfs_calib_disabled_write_12707 iwl_dbgfs_calib_disabled_write 3 12707 NULL
109770 +ieee80211_if_read_num_buffered_multicast_12716 ieee80211_if_read_num_buffered_multicast 3 12716 NULL
109771 +ivtv_write_12721 ivtv_write 3 12721 NULL
109772 +key_rx_spec_read_12736 key_rx_spec_read 3 12736 NULL
109773 +__mei_cl_async_send_12737 __mei_cl_async_send 3 12737 NULL
109774 +ieee80211_if_read_dot11MeshMaxRetries_12756 ieee80211_if_read_dot11MeshMaxRetries 3 12756 NULL
109775 +listxattr_12769 listxattr 3 12769 NULL
109776 +sctp_ssnmap_init_12772 sctp_ssnmap_init 2-3 12772 NULL
109777 +scsi_adjust_queue_depth_12802 scsi_adjust_queue_depth 3 12802 NULL
109778 +xfs_inumbers_fmt_12817 xfs_inumbers_fmt 3 12817 NULL
109779 +readq_12825 readq 0 12825 NULL
109780 +SyS_add_key_12834 SyS_add_key 4 12834 NULL
109781 +TSS_authhmac_12839 TSS_authhmac 3 12839 NULL
109782 +spidev_sync_12842 spidev_sync 0 12842 NULL
109783 +spidev_ioctl_12846 spidev_ioctl 2 12846 NULL
109784 +ath9k_dump_4k_modal_eeprom_12883 ath9k_dump_4k_modal_eeprom 3-2 12883 NULL
109785 +get_leb_cnt_12892 get_leb_cnt 0-2 12892 NULL
109786 +get_virtual_node_size_12908 get_virtual_node_size 0 12908 NULL
109787 +rds_pages_in_vec_12922 rds_pages_in_vec 0 12922 NULL
109788 +do_inode_permission_12946 do_inode_permission 0 12946 NULL
109789 +bm_status_write_12964 bm_status_write 3 12964 NULL
109790 +raid56_parity_recover_12987 raid56_parity_recover 5 12987 NULL
109791 +TransmitTcb_12989 TransmitTcb 4 12989 NULL
109792 +sk_peek_offset_12991 sk_peek_offset 0 12991 NULL
109793 +subsystem_filter_write_13022 subsystem_filter_write 3 13022 NULL
109794 +generic_segment_checks_13041 generic_segment_checks 0 13041 NULL
109795 +ocfs2_write_begin_13045 ocfs2_write_begin 3-4 13045 NULL
109796 +__dn_setsockopt_13060 __dn_setsockopt 5 13060 NULL nohasharray
109797 +ptlrpc_lprocfs_threads_min_seq_write_13060 ptlrpc_lprocfs_threads_min_seq_write 3 13060 &__dn_setsockopt_13060
109798 +biovec_create_pool_13079 biovec_create_pool 2 13079 NULL
109799 +xattr_getsecurity_13090 xattr_getsecurity 0 13090 NULL
109800 +ttm_dma_pool_alloc_new_pages_13105 ttm_dma_pool_alloc_new_pages 3 13105 NULL
109801 +SyS_msgrcv_13109 SyS_msgrcv 3 13109 NULL
109802 +snd_rme96_playback_copy_13111 snd_rme96_playback_copy 5 13111 NULL
109803 +bfad_debugfs_read_13119 bfad_debugfs_read 3 13119 NULL
109804 +blk_update_request_13146 blk_update_request 3 13146 NULL
109805 +ocfs2_quota_trans_credits_13150 ocfs2_quota_trans_credits 0 13150 NULL
109806 +caif_stream_recvmsg_13173 caif_stream_recvmsg 4 13173 NULL
109807 +pwr_disable_ps_read_13176 pwr_disable_ps_read 3 13176 NULL
109808 +ucs2_strlen_13178 ucs2_strlen 0 13178 NULL
109809 +dgrp_net_ioctl_13183 dgrp_net_ioctl 2 13183 NULL
109810 +create_trace_uprobe_13184 create_trace_uprobe 1 13184 NULL
109811 +comedi_read_13199 comedi_read 3 13199 NULL
109812 +hash_ipport4_expire_13201 hash_ipport4_expire 4 13201 NULL
109813 +mmc_ext_csd_read_13205 mmc_ext_csd_read 3 13205 NULL
109814 +svm_msrpm_offset_13220 svm_msrpm_offset 0-1 13220 NULL
109815 +fnic_trace_ctrl_write_13229 fnic_trace_ctrl_write 3 13229 NULL
109816 +asix_read_cmd_13245 asix_read_cmd 5 13245 NULL
109817 +init_tid_tabs_13252 init_tid_tabs 2-3-4 13252 NULL
109818 +bio_integrity_trim_13259 bio_integrity_trim 3 13259 NULL
109819 +simple_attr_write_13260 simple_attr_write 3 13260 NULL
109820 +pmcraid_notify_aen_13274 pmcraid_notify_aen 3 13274 NULL
109821 +il4965_stats_flag_13281 il4965_stats_flag 3-0 13281 NULL
109822 +lpfc_idiag_mbxacc_get_setup_13282 lpfc_idiag_mbxacc_get_setup 0 13282 NULL
109823 +sd_major_13294 sd_major 0-1 13294 NULL
109824 +module_param_sysfs_setup_13296 module_param_sysfs_setup 0 13296 NULL
109825 +__clone_and_map_data_bio_13334 __clone_and_map_data_bio 4-8 13334 NULL
109826 +kvm_read_nested_guest_page_13337 kvm_read_nested_guest_page 5 13337 NULL
109827 +hscx_empty_fifo_13360 hscx_empty_fifo 2 13360 NULL
109828 +iso_sched_alloc_13377 iso_sched_alloc 1 13377 NULL nohasharray
109829 +wep_key_not_found_read_13377 wep_key_not_found_read 3 13377 &iso_sched_alloc_13377
109830 +ext4_meta_trans_blocks_13380 ext4_meta_trans_blocks 0-3-2 13380 NULL
109831 +lov_mds_md_size_13388 lov_mds_md_size 0-1 13388 NULL nohasharray
109832 +dis_bypass_write_13388 dis_bypass_write 3 13388 &lov_mds_md_size_13388
109833 +netxen_alloc_sds_rings_13417 netxen_alloc_sds_rings 2 13417 NULL
109834 +sctp_setsockopt_peer_primary_addr_13440 sctp_setsockopt_peer_primary_addr 3 13440 NULL
109835 +ath6kl_cfg80211_connect_event_13443 ath6kl_cfg80211_connect_event 8-9-7 13443 NULL
109836 +sb_init_dio_done_wq_13482 sb_init_dio_done_wq 0 13482 NULL
109837 +data_read_13494 data_read 3 13494 NULL
109838 +ioat_chansts_32_13506 ioat_chansts_32 0 13506 NULL
109839 +ocfs2_align_bytes_to_blocks_13512 ocfs2_align_bytes_to_blocks 0-2 13512 NULL
109840 +core_status_13515 core_status 4 13515 NULL
109841 +smk_write_mapped_13519 smk_write_mapped 3 13519 NULL
109842 +bm_init_13529 bm_init 2 13529 NULL
109843 +llcp_sock_recvmsg_13556 llcp_sock_recvmsg 4 13556 NULL
109844 +ieee80211_if_read_ap_power_level_13558 ieee80211_if_read_ap_power_level 3 13558 NULL
109845 +hash_net4_expire_13559 hash_net4_expire 4 13559 NULL
109846 +read_file_antenna_13574 read_file_antenna 3 13574 NULL
109847 +cache_write_13589 cache_write 3 13589 NULL
109848 +Rd_Indx_13602 Rd_Indx 3-2 13602 NULL
109849 +wm8994_bulk_write_13615 wm8994_bulk_write 2-3 13615 NULL
109850 +pmcraid_get_minor_13619 pmcraid_get_minor 0 13619 NULL
109851 +packet_snd_13634 packet_snd 3 13634 NULL
109852 +blk_msg_write_13655 blk_msg_write 3 13655 NULL
109853 +cache_downcall_13666 cache_downcall 3 13666 NULL
109854 +ext3_xattr_list_entries_13682 ext3_xattr_list_entries 0 13682 NULL
109855 +nv94_aux_13689 nv94_aux 2-5 13689 NULL
109856 +usb_get_string_13693 usb_get_string 0 13693 NULL
109857 +fw_iso_buffer_alloc_13704 fw_iso_buffer_alloc 2 13704 NULL
109858 +audit_unpack_string_13748 audit_unpack_string 3 13748 NULL
109859 +ieee802154_alloc_device_13767 ieee802154_alloc_device 1 13767 NULL
109860 +fb_sys_read_13778 fb_sys_read 3 13778 NULL
109861 +ath6kl_mgmt_powersave_ap_13791 ath6kl_mgmt_powersave_ap 6 13791 NULL
109862 +random_read_13815 random_read 3 13815 NULL
109863 +mutex_lock_interruptible_nested_13817 mutex_lock_interruptible_nested 0 13817 NULL
109864 +hsi_register_board_info_13820 hsi_register_board_info 2 13820 NULL
109865 +___mei_cl_send_13821 ___mei_cl_send 3 13821 NULL
109866 +enc_pools_insert_13849 enc_pools_insert 3 13849 NULL
109867 +evdev_ioctl_compat_13851 evdev_ioctl_compat 2 13851 NULL
109868 +compat_ip_setsockopt_13870 compat_ip_setsockopt 5 13870 NULL
109869 +qp_memcpy_to_queue_13886 qp_memcpy_to_queue 5-2 13886 NULL
109870 +snd_pcm_aio_read_13900 snd_pcm_aio_read 3 13900 NULL
109871 +cfg80211_inform_bss_width_13933 cfg80211_inform_bss_width 9 13933 NULL
109872 +ext3_xattr_block_get_13936 ext3_xattr_block_get 0 13936 NULL
109873 +ieee80211_if_read_dot11MeshForwarding_13940 ieee80211_if_read_dot11MeshForwarding 3 13940 NULL nohasharray
109874 +ocfs2_xa_value_truncate_13940 ocfs2_xa_value_truncate 2 13940 &ieee80211_if_read_dot11MeshForwarding_13940
109875 +iwl_dbgfs_protection_mode_read_13943 iwl_dbgfs_protection_mode_read 3 13943 NULL
109876 +ieee80211_if_read_min_discovery_timeout_13946 ieee80211_if_read_min_discovery_timeout 3 13946 NULL
109877 +lpfc_idiag_queacc_read_13950 lpfc_idiag_queacc_read 3 13950 NULL
109878 +osc_grant_shrink_interval_seq_write_13952 osc_grant_shrink_interval_seq_write 3 13952 NULL
109879 +ocfs2_refresh_slot_info_13957 ocfs2_refresh_slot_info 0 13957 NULL
109880 +snd_pcm_plug_slave_size_13967 snd_pcm_plug_slave_size 0-2 13967 NULL
109881 +qcam_read_13977 qcam_read 3 13977 NULL
109882 +dsp_read_13980 dsp_read 2 13980 NULL
109883 +dvb_demux_read_13981 dvb_demux_read 3 13981 NULL
109884 +create_files_14003 create_files 0 14003 NULL
109885 +sddr09_write_data_14014 sddr09_write_data 3 14014 NULL
109886 +btrfs_get_blocks_direct_14016 btrfs_get_blocks_direct 2 14016 NULL
109887 +dmi_format_ids_14018 dmi_format_ids 2 14018 NULL
109888 +iscsi_create_flashnode_conn_14022 iscsi_create_flashnode_conn 4 14022 NULL
109889 +dvb_usercopy_14036 dvb_usercopy 2 14036 NULL
109890 +read_def_modal_eeprom_14041 read_def_modal_eeprom 3 14041 NULL
109891 +ieee80211_if_fmt_aid_14055 ieee80211_if_fmt_aid 3 14055 NULL
109892 +ovs_nla_alloc_flow_actions_14056 ovs_nla_alloc_flow_actions 1 14056 NULL
109893 +sta_agg_status_read_14058 sta_agg_status_read 3 14058 NULL
109894 +lov_stripeoffset_seq_write_14078 lov_stripeoffset_seq_write 3 14078 NULL
109895 +do_proc_readlink_14096 do_proc_readlink 3 14096 NULL
109896 +compat_sys_pselect6_14105 compat_sys_pselect6 1 14105 NULL
109897 +ext4_journal_blocks_per_page_14127 ext4_journal_blocks_per_page 0 14127 NULL
109898 +isku_sysfs_read_light_14140 isku_sysfs_read_light 6 14140 NULL
109899 +em_canid_change_14150 em_canid_change 3 14150 NULL
109900 +gsm_dlci_data_14155 gsm_dlci_data 3 14155 NULL
109901 +print_input_mask_14168 print_input_mask 3-0 14168 NULL
109902 +ocfs2_xattr_value_truncate_14183 ocfs2_xattr_value_truncate 3 14183 NULL
109903 +datafab_read_data_14186 datafab_read_data 4 14186 NULL
109904 +hfsplus_brec_find_14200 hfsplus_brec_find 0 14200 NULL
109905 +alloc_async_14208 alloc_async 1 14208 NULL
109906 +ath6kl_regread_write_14220 ath6kl_regread_write 3 14220 NULL
109907 +ieee80211_if_write_uapsd_max_sp_len_14233 ieee80211_if_write_uapsd_max_sp_len 3 14233 NULL
109908 +dma_declare_coherent_memory_14244 dma_declare_coherent_memory 4 14244 NULL
109909 +ath6kl_connect_event_14267 ath6kl_connect_event 7-8-9 14267 NULL
109910 +rr_status_14293 rr_status 5 14293 NULL
109911 +read_default_ldt_14302 read_default_ldt 2 14302 NULL
109912 +oo_objects_14319 oo_objects 0 14319 NULL
109913 +ll_get_user_pages_14328 ll_get_user_pages 3-2-0 14328 NULL
109914 +p9_client_zc_rpc_14345 p9_client_zc_rpc 7 14345 NULL
109915 +alloc_tx_struct_14349 alloc_tx_struct 1 14349 NULL
109916 +hash_ipportnet4_expire_14354 hash_ipportnet4_expire 4 14354 NULL
109917 +snd_pcm_lib_readv_14363 snd_pcm_lib_readv 0-3 14363 NULL
109918 +ath6kl_regdump_read_14393 ath6kl_regdump_read 3 14393 NULL
109919 +smk_write_onlycap_14400 smk_write_onlycap 3 14400 NULL
109920 +mtd_concat_create_14416 mtd_concat_create 2 14416 NULL
109921 +get_kcore_size_14425 get_kcore_size 0 14425 NULL
109922 +block_size_14443 block_size 0 14443 NULL
109923 +lmv_user_md_size_14456 lmv_user_md_size 0-1 14456 NULL
109924 +snd_emu10k1_proc_spdif_status_14457 snd_emu10k1_proc_spdif_status 4-5 14457 NULL
109925 +ath10k_write_htt_stats_mask_14458 ath10k_write_htt_stats_mask 3 14458 NULL
109926 +lustre_msg_size_v2_14470 lustre_msg_size_v2 0 14470 NULL
109927 +dma_transfer_size_14473 dma_transfer_size 0 14473 NULL
109928 +udplite_getfrag_14479 udplite_getfrag 3-4 14479 NULL
109929 +ieee80211_if_read_dot11MeshGateAnnouncementProtocol_14486 ieee80211_if_read_dot11MeshGateAnnouncementProtocol 3 14486 NULL
109930 +ocfs2_debug_read_14507 ocfs2_debug_read 3 14507 NULL
109931 +ep0_write_14536 ep0_write 3 14536 NULL nohasharray
109932 +dataflash_read_user_otp_14536 dataflash_read_user_otp 3-2 14536 &ep0_write_14536
109933 +picolcd_debug_eeprom_read_14549 picolcd_debug_eeprom_read 3 14549 NULL
109934 +qp_host_alloc_queue_14566 qp_host_alloc_queue 1 14566 NULL
109935 +SyS_setdomainname_14569 SyS_setdomainname 2 14569 NULL
109936 +idmap_pipe_downcall_14591 idmap_pipe_downcall 3 14591 NULL
109937 +ceph_osdc_alloc_request_14597 ceph_osdc_alloc_request 3 14597 NULL
109938 +dbJoin_14644 dbJoin 0 14644 NULL
109939 +profile_replace_14652 profile_replace 3 14652 NULL
109940 +min_bytes_needed_14675 min_bytes_needed 0 14675 NULL
109941 +nvme_trans_log_info_exceptions_14677 nvme_trans_log_info_exceptions 3 14677 NULL
109942 +pipeline_enc_tx_stat_fifo_int_read_14680 pipeline_enc_tx_stat_fifo_int_read 3 14680 NULL
109943 +ieee80211_if_fmt_rc_rateidx_mask_2ghz_14683 ieee80211_if_fmt_rc_rateidx_mask_2ghz 3 14683 NULL
109944 +SyS_fsetxattr_14702 SyS_fsetxattr 4 14702 NULL
109945 +persistent_ram_ecc_string_14704 persistent_ram_ecc_string 0 14704 NULL
109946 +u_audio_playback_14709 u_audio_playback 3 14709 NULL
109947 +rtw_cbuf_alloc_14710 rtw_cbuf_alloc 1 14710 NULL
109948 +cgroup_path_14713 cgroup_path 3 14713 NULL
109949 +vfd_write_14717 vfd_write 3 14717 NULL
109950 +__blk_end_request_14729 __blk_end_request 3 14729 NULL
109951 +raid1_resize_14740 raid1_resize 2 14740 NULL
109952 +i915_error_state_buf_init_14742 i915_error_state_buf_init 2 14742 NULL
109953 +btrfs_inode_extref_name_len_14752 btrfs_inode_extref_name_len 0 14752 NULL
109954 +rx_rx_cmplt_read_14753 rx_rx_cmplt_read 3 14753 NULL
109955 +regmap_range_read_file_14775 regmap_range_read_file 3 14775 NULL
109956 +sta_dev_read_14782 sta_dev_read 3 14782 NULL
109957 +keys_proc_write_14792 keys_proc_write 3 14792 NULL
109958 +ext4_kvmalloc_14796 ext4_kvmalloc 1 14796 NULL
109959 +__kfifo_in_14797 __kfifo_in 3-0 14797 NULL
109960 +hpet_readl_14801 hpet_readl 0 14801 NULL nohasharray
109961 +snd_als300_gcr_read_14801 snd_als300_gcr_read 0 14801 &hpet_readl_14801
109962 +do_tune_cpucache_14828 do_tune_cpucache 2 14828 NULL
109963 +mrp_attr_create_14853 mrp_attr_create 3 14853 NULL
109964 +lcd_write_14857 lcd_write 3 14857 NULL
109965 +get_user_cpu_mask_14861 get_user_cpu_mask 2 14861 NULL
109966 +gmux_index_read8_14890 gmux_index_read8 0 14890 NULL
109967 +acpi_os_allocate_14892 acpi_os_allocate 1 14892 NULL
109968 +SYSC_readv_14901 SYSC_readv 3 14901 NULL
109969 +__arch_hweight64_14923 __arch_hweight64 0 14923 NULL nohasharray
109970 +qp_memcpy_to_queue_iov_14923 qp_memcpy_to_queue_iov 5-2 14923 &__arch_hweight64_14923
109971 +ocfs2_expand_nonsparse_inode_14936 ocfs2_expand_nonsparse_inode 3-4 14936 NULL
109972 +queue_cnt_14951 queue_cnt 0 14951 NULL
109973 +unix_dgram_recvmsg_14952 unix_dgram_recvmsg 4 14952 NULL
109974 +videobuf_read_stream_14956 videobuf_read_stream 3 14956 NULL
109975 +mce_flush_rx_buffer_14976 mce_flush_rx_buffer 2 14976 NULL
109976 +setkey_14987 setkey 3 14987 NULL nohasharray
109977 +gpio_twl4030_write_14987 gpio_twl4030_write 1 14987 &setkey_14987
109978 +xfs_dinode_size_14996 xfs_dinode_size 0 14996 NULL
109979 +blk_integrity_tuple_size_15027 blk_integrity_tuple_size 0 15027 NULL
109980 +cld_pipe_downcall_15058 cld_pipe_downcall 3 15058 NULL
109981 +ieee80211_if_read_uapsd_max_sp_len_15067 ieee80211_if_read_uapsd_max_sp_len 3 15067 NULL
109982 +nfs4_write_cached_acl_15070 nfs4_write_cached_acl 4 15070 NULL
109983 +ntfs_copy_from_user_15072 ntfs_copy_from_user 3-5-0 15072 NULL
109984 +pppoe_recvmsg_15073 pppoe_recvmsg 4 15073 NULL
109985 +ceph_calc_ceph_pg_15075 ceph_calc_ceph_pg 0 15075 NULL
109986 +smscore_load_firmware_family2_15086 smscore_load_firmware_family2 3 15086 NULL
109987 +compat_SyS_pwritev_15118 compat_SyS_pwritev 3 15118 NULL
109988 +hex_dump_to_buffer_15121 hex_dump_to_buffer 6 15121 NULL
109989 +start_port_15124 start_port 0 15124 NULL
109990 +ipwireless_ppp_mru_15153 ipwireless_ppp_mru 0 15153 NULL
109991 +iwl_dbgfs_sta_drain_write_15167 iwl_dbgfs_sta_drain_write 3 15167 NULL
109992 +SYSC_setdomainname_15180 SYSC_setdomainname 2 15180 NULL
109993 +iscsi_create_endpoint_15193 iscsi_create_endpoint 1 15193 NULL
109994 +mtt_alloc_res_15211 mtt_alloc_res 5 15211 NULL
109995 +bfad_debugfs_write_regrd_15218 bfad_debugfs_write_regrd 3 15218 NULL
109996 +iwl_dbgfs_sram_write_15239 iwl_dbgfs_sram_write 3 15239 NULL
109997 +il_dbgfs_rx_stats_read_15243 il_dbgfs_rx_stats_read 3 15243 NULL
109998 +simple_strtol_15273 simple_strtol 0 15273 NULL
109999 +fw_realloc_buffer_15280 fw_realloc_buffer 2 15280 NULL
110000 +ocfs2_read_refcount_block_15305 ocfs2_read_refcount_block 0 15305 NULL
110001 +xlog_ticket_alloc_15335 xlog_ticket_alloc 2 15335 NULL
110002 +kovaplus_sysfs_read_15337 kovaplus_sysfs_read 6 15337 NULL
110003 +ioread16_15342 ioread16 0 15342 NULL
110004 +ept_prefetch_gpte_15348 ept_prefetch_gpte 4 15348 NULL
110005 +acpi_ut_create_string_object_15360 acpi_ut_create_string_object 1 15360 NULL
110006 +ext4_direct_IO_15369 ext4_direct_IO 4 15369 NULL
110007 +graph_depth_read_15371 graph_depth_read 3 15371 NULL
110008 +compat_sys_process_vm_readv_15374 compat_sys_process_vm_readv 3-5 15374 NULL
110009 +fq_codel_zalloc_15378 fq_codel_zalloc 1 15378 NULL
110010 +alloc_fddidev_15382 alloc_fddidev 1 15382 NULL
110011 +pipeline_csum_to_rx_xfer_swi_read_15403 pipeline_csum_to_rx_xfer_swi_read 3 15403 NULL
110012 +get_modalias_15406 get_modalias 2 15406 NULL
110013 +blockdev_direct_IO_15408 blockdev_direct_IO 5 15408 NULL
110014 +__videobuf_copy_to_user_15423 __videobuf_copy_to_user 4-0 15423 NULL
110015 +tcp_mtu_to_mss_15438 tcp_mtu_to_mss 2-0 15438 NULL
110016 +hpsa_change_queue_depth_15449 hpsa_change_queue_depth 2 15449 NULL
110017 +memweight_15450 memweight 2 15450 NULL
110018 +zd_chip_is_zd1211b_15518 zd_chip_is_zd1211b 0 15518 NULL
110019 +ifx_spi_write_15531 ifx_spi_write 3 15531 NULL
110020 +p9_check_zc_errors_15534 p9_check_zc_errors 4 15534 NULL
110021 +xfrm_state_mtu_15548 xfrm_state_mtu 0-2 15548 NULL
110022 +persistent_status_15574 persistent_status 4 15574 NULL
110023 +bnx2fc_process_unsol_compl_15576 bnx2fc_process_unsol_compl 2 15576 NULL
110024 +vme_user_write_15587 vme_user_write 3 15587 NULL
110025 +compat_fillonedir_15620 compat_fillonedir 3 15620 NULL
110026 +proc_loginuid_read_15631 proc_loginuid_read 3 15631 NULL
110027 +tomoyo_scan_bprm_15642 tomoyo_scan_bprm 2-4 15642 NULL nohasharray
110028 +sk_memory_allocated_add_15642 sk_memory_allocated_add 2 15642 &tomoyo_scan_bprm_15642 nohasharray
110029 +pipeline_hs_tx_stat_fifo_int_read_15642 pipeline_hs_tx_stat_fifo_int_read 3 15642 &sk_memory_allocated_add_15642
110030 +joydev_handle_JSIOCSBTNMAP_15643 joydev_handle_JSIOCSBTNMAP 3 15643 NULL
110031 +fs_path_add_15648 fs_path_add 3 15648 NULL
110032 +xsd_read_15653 xsd_read 3 15653 NULL
110033 +unix_bind_15668 unix_bind 3 15668 NULL
110034 +dm_read_15674 dm_read 3 15674 NULL nohasharray
110035 +SyS_connect_15674 SyS_connect 3 15674 &dm_read_15674
110036 +tracing_snapshot_write_15719 tracing_snapshot_write 3 15719 NULL
110037 +HiSax_readstatus_15752 HiSax_readstatus 2 15752 NULL
110038 +bio_map_15794 bio_map 3-0 15794 NULL
110039 +smk_read_direct_15803 smk_read_direct 3 15803 NULL
110040 +nameseq_list_15817 nameseq_list 3-0 15817 NULL nohasharray
110041 +gnttab_expand_15817 gnttab_expand 1 15817 &nameseq_list_15817
110042 +afs_proc_rootcell_write_15822 afs_proc_rootcell_write 3 15822 NULL
110043 +brcmf_sdbrcm_died_dump_15841 brcmf_sdbrcm_died_dump 3 15841 NULL
110044 +table_size_15851 table_size 0-1-2 15851 NULL
110045 +write_file_tx99_15856 write_file_tx99 3 15856 NULL
110046 +media_entity_init_15870 media_entity_init 2-4 15870 NULL
110047 +__mptctl_ioctl_15875 __mptctl_ioctl 2 15875 NULL
110048 +nfs_map_group_to_gid_15892 nfs_map_group_to_gid 3 15892 NULL
110049 +native_read_msr_15905 native_read_msr 0 15905 NULL
110050 +parse_audio_stream_data_15937 parse_audio_stream_data 3 15937 NULL
110051 +power_read_15939 power_read 3 15939 NULL
110052 +lpfc_idiag_drbacc_read_15948 lpfc_idiag_drbacc_read 3 15948 NULL
110053 +snd_pcm_lib_read_transfer_15952 snd_pcm_lib_read_transfer 5-2-4 15952 NULL
110054 +viafb_vt1636_proc_write_16018 viafb_vt1636_proc_write 3 16018 NULL
110055 +dccp_recvmsg_16056 dccp_recvmsg 4 16056 NULL
110056 +read_file_spectral_period_16057 read_file_spectral_period 3 16057 NULL
110057 +si5351_msynth_params_address_16062 si5351_msynth_params_address 0-1 16062 NULL
110058 +isr_tx_exch_complete_read_16103 isr_tx_exch_complete_read 3 16103 NULL
110059 +isr_hw_pm_mode_changes_read_16110 isr_hw_pm_mode_changes_read 3 16110 NULL nohasharray
110060 +dma_tx_requested_read_16110 dma_tx_requested_read 3 16110 &isr_hw_pm_mode_changes_read_16110
110061 +snd_dma_pointer_16126 snd_dma_pointer 0-2 16126 NULL
110062 +compat_sys_select_16131 compat_sys_select 1 16131 NULL
110063 +fsm_init_16134 fsm_init 2 16134 NULL
110064 +ext4_xattr_block_get_16148 ext4_xattr_block_get 0 16148 NULL
110065 +optimal_reclaimed_pages_16172 optimal_reclaimed_pages 0 16172 NULL
110066 +mapping_level_16188 mapping_level 2-0 16188 NULL
110067 +i40e_allocate_virt_mem_d_16191 i40e_allocate_virt_mem_d 3 16191 NULL
110068 +ath10k_htt_rx_ring_size_16201 ath10k_htt_rx_ring_size 0 16201 NULL
110069 +cipso_v4_map_cat_rng_hton_16203 cipso_v4_map_cat_rng_hton 0 16203 NULL
110070 +SyS_pselect6_16210 SyS_pselect6 1 16210 NULL
110071 +create_table_16213 create_table 2 16213 NULL
110072 +ath9k_hw_ar9287_dump_eeprom_16224 ath9k_hw_ar9287_dump_eeprom 5-4 16224 NULL
110073 +atomic_read_file_16227 atomic_read_file 3 16227 NULL
110074 +BcmGetSectionValStartOffset_16235 BcmGetSectionValStartOffset 0 16235 NULL
110075 +lov_prep_brw_set_16246 lov_prep_brw_set 3 16246 NULL
110076 +btrfs_dev_extent_chunk_offset_16247 btrfs_dev_extent_chunk_offset 0 16247 NULL nohasharray
110077 +i40e_dbg_dump_read_16247 i40e_dbg_dump_read 3 16247 &btrfs_dev_extent_chunk_offset_16247
110078 +il_dbgfs_disable_ht40_write_16249 il_dbgfs_disable_ht40_write 3 16249 NULL
110079 +SyS_fgetxattr_16254 SyS_fgetxattr 4 16254 NULL
110080 +reiserfs_acl_count_16265 reiserfs_acl_count 0-1 16265 NULL
110081 +ocfs2_xattr_bucket_value_truncate_16279 ocfs2_xattr_bucket_value_truncate 4 16279 NULL
110082 +nand_bch_init_16280 nand_bch_init 3-2 16280 NULL nohasharray
110083 +drbd_setsockopt_16280 drbd_setsockopt 5 16280 &nand_bch_init_16280
110084 +account_16283 account 0-4-2 16283 NULL nohasharray
110085 +mirror_status_16283 mirror_status 5 16283 &account_16283
110086 +jumpshot_read_data_16287 jumpshot_read_data 4 16287 NULL
110087 +mo_xattr_get_16288 mo_xattr_get 0 16288 NULL
110088 +stk_allocate_buffers_16291 stk_allocate_buffers 2 16291 NULL
110089 +rbd_segment_offset_16293 rbd_segment_offset 0-2 16293 NULL
110090 +rsc_mgr_init_16299 rsc_mgr_init 3 16299 NULL
110091 +kvm_handle_hva_range_16312 kvm_handle_hva_range 3-2 16312 NULL
110092 +sysfs_create_groups_16360 sysfs_create_groups 0 16360 NULL
110093 +total_ps_buffered_read_16365 total_ps_buffered_read 3 16365 NULL
110094 +iscsi_tcp_conn_setup_16376 iscsi_tcp_conn_setup 2 16376 NULL
110095 +ieee80211_if_read_tsf_16420 ieee80211_if_read_tsf 3 16420 NULL
110096 +rxrpc_server_keyring_16431 rxrpc_server_keyring 3 16431 NULL
110097 +__bio_add_page_16435 __bio_add_page 0-4 16435 NULL
110098 +cmdline_store_16442 cmdline_store 4 16442 NULL
110099 +btrfs_truncate_inode_items_16452 btrfs_truncate_inode_items 4 16452 NULL
110100 +netlink_change_ngroups_16457 netlink_change_ngroups 2 16457 NULL
110101 +req_capsule_get_size_16467 req_capsule_get_size 0 16467 NULL
110102 +tracing_readme_read_16493 tracing_readme_read 3 16493 NULL
110103 +KEY_OFFSET_16504 KEY_OFFSET 0 16504 NULL
110104 +snd_interval_max_16529 snd_interval_max 0 16529 NULL
110105 +raid10_resize_16537 raid10_resize 2 16537 NULL
110106 +lpfc_debugfs_read_16566 lpfc_debugfs_read 3 16566 NULL
110107 +agp_allocate_memory_wrap_16576 agp_allocate_memory_wrap 1 16576 NULL
110108 +lustre_msg_hdr_size_v2_16589 lustre_msg_hdr_size_v2 0 16589 NULL
110109 +gmux_index_read32_16604 gmux_index_read32 0 16604 NULL
110110 +rtw_set_wpa_ie_16633 rtw_set_wpa_ie 3 16633 NULL
110111 +btrfs_get_token_32_16651 btrfs_get_token_32 0 16651 NULL
110112 +__wa_populate_dto_urb_16699 __wa_populate_dto_urb 3-4 16699 NULL
110113 +__proc_lnet_buffers_16717 __proc_lnet_buffers 5 16717 NULL
110114 +__copy_to_user_swizzled_16748 __copy_to_user_swizzled 3-4 16748 NULL
110115 +arcmsr_adjust_disk_queue_depth_16756 arcmsr_adjust_disk_queue_depth 2 16756 NULL
110116 +blk_rq_map_user_iov_16772 blk_rq_map_user_iov 5 16772 NULL
110117 +i2o_parm_issue_16790 i2o_parm_issue 0 16790 NULL
110118 +get_server_iovec_16804 get_server_iovec 2 16804 NULL
110119 +drm_malloc_ab_16831 drm_malloc_ab 1-2 16831 NULL
110120 +scsi_mode_sense_16835 scsi_mode_sense 5 16835 NULL
110121 +hfsplus_min_io_size_16859 hfsplus_min_io_size 0 16859 NULL
110122 +alloc_idx_lebs_16872 alloc_idx_lebs 2 16872 NULL
110123 +carl9170_debugfs_ampdu_state_read_16873 carl9170_debugfs_ampdu_state_read 3 16873 NULL
110124 +st_write_16874 st_write 3 16874 NULL
110125 +__kfifo_peek_n_16877 __kfifo_peek_n 0 16877 NULL
110126 +transport_init_session_tags_16878 transport_init_session_tags 1-2 16878 NULL
110127 +snd_gf1_mem_proc_dump_16926 snd_gf1_mem_proc_dump 5 16926 NULL nohasharray
110128 +psb_unlocked_ioctl_16926 psb_unlocked_ioctl 2 16926 &snd_gf1_mem_proc_dump_16926
110129 +_sp2d_alloc_16944 _sp2d_alloc 1-2-3 16944 NULL
110130 +squashfs_read_table_16945 squashfs_read_table 3 16945 NULL
110131 +keyctl_instantiate_key_iov_16969 keyctl_instantiate_key_iov 3 16969 NULL
110132 +ocfs2_read_quota_phys_block_16990 ocfs2_read_quota_phys_block 0 16990 NULL
110133 +ceph_read_dir_17005 ceph_read_dir 3 17005 NULL
110134 +copy_counters_to_user_17027 copy_counters_to_user 5 17027 NULL
110135 +jffs2_trusted_setxattr_17048 jffs2_trusted_setxattr 4 17048 NULL
110136 +__arch_hweight32_17060 __arch_hweight32 0 17060 NULL
110137 +sddr55_read_data_17072 sddr55_read_data 4 17072 NULL
110138 +dvb_dvr_read_17073 dvb_dvr_read 3 17073 NULL
110139 +simple_transaction_read_17076 simple_transaction_read 3 17076 NULL
110140 +carl9170_debugfs_mem_usage_read_17084 carl9170_debugfs_mem_usage_read 3 17084 NULL
110141 +entry_length_17093 entry_length 0 17093 NULL
110142 +ocfs2_get_refcount_cpos_end_17113 ocfs2_get_refcount_cpos_end 0 17113 NULL
110143 +write_mem_17114 write_mem 3 17114 NULL
110144 +pvr2_hdw_state_report_17121 pvr2_hdw_state_report 3 17121 NULL
110145 +nouveau_instobj_create__17144 nouveau_instobj_create_ 4 17144 NULL
110146 +jumpshot_write_data_17151 jumpshot_write_data 4 17151 NULL
110147 +sep_read_17161 sep_read 3 17161 NULL
110148 +befs_nls2utf_17163 befs_nls2utf 3 17163 NULL
110149 +tx_tx_start_templates_read_17164 tx_tx_start_templates_read 3 17164 NULL
110150 +UniStrnlen_17169 UniStrnlen 0 17169 NULL
110151 +access_remote_vm_17189 access_remote_vm 0 17189 NULL nohasharray
110152 +iwl_dbgfs_txfifo_flush_write_17189 iwl_dbgfs_txfifo_flush_write 3 17189 &access_remote_vm_17189 nohasharray
110153 +ocfs2_flock_handle_signal_17189 ocfs2_flock_handle_signal 0 17189 &iwl_dbgfs_txfifo_flush_write_17189
110154 +iscsit_find_cmd_from_itt_or_dump_17194 iscsit_find_cmd_from_itt_or_dump 3 17194 NULL nohasharray
110155 +driver_state_read_17194 driver_state_read 3 17194 &iscsit_find_cmd_from_itt_or_dump_17194
110156 +sync_request_17208 sync_request 2 17208 NULL
110157 +dn_recvmsg_17213 dn_recvmsg 4 17213 NULL
110158 +lprocfs_read_frac_helper_17261 lprocfs_read_frac_helper 0 17261 NULL
110159 +error_error_frame_cts_nul_flid_read_17262 error_error_frame_cts_nul_flid_read 3 17262 NULL
110160 +alloc_ep_17269 alloc_ep 1 17269 NULL
110161 +pg_read_17276 pg_read 3 17276 NULL
110162 +raw_recvmsg_17277 raw_recvmsg 4 17277 NULL
110163 +hmac_sha256_17278 hmac_sha256 2 17278 NULL
110164 +neigh_hash_grow_17283 neigh_hash_grow 2 17283 NULL
110165 +minstrel_stats_read_17290 minstrel_stats_read 3 17290 NULL
110166 +__ptlrpc_request_bufs_pack_17298 __ptlrpc_request_bufs_pack 0 17298 NULL
110167 +ieee80211_if_fmt_dot11MeshForwarding_17301 ieee80211_if_fmt_dot11MeshForwarding 3 17301 NULL
110168 +mb_cache_create_17307 mb_cache_create 2 17307 NULL
110169 +gnttab_map_frames_v2_17314 gnttab_map_frames_v2 2 17314 NULL
110170 +ieee80211_if_read_dot11MeshHWMPperrMinInterval_17346 ieee80211_if_read_dot11MeshHWMPperrMinInterval 3 17346 NULL
110171 +ath6kl_wmi_send_mgmt_cmd_17347 ath6kl_wmi_send_mgmt_cmd 7 17347 NULL
110172 +mdc_import_seq_write_17409 mdc_import_seq_write 3 17409 NULL
110173 +lpfc_debugfs_dif_err_write_17424 lpfc_debugfs_dif_err_write 3 17424 NULL
110174 +compat_sys_ppoll_17430 compat_sys_ppoll 2 17430 NULL
110175 +sta_connected_time_read_17435 sta_connected_time_read 3 17435 NULL
110176 +libcfs_ipif_enumerate_17445 libcfs_ipif_enumerate 0 17445 NULL
110177 +nla_get_u32_17455 nla_get_u32 0 17455 NULL
110178 +__ref_totlen_17461 __ref_totlen 0 17461 NULL
110179 +probe_kernel_write_17481 probe_kernel_write 3 17481 NULL
110180 +TSS_rawhmac_17486 TSS_rawhmac 3 17486 NULL
110181 +lbs_highrssi_write_17515 lbs_highrssi_write 3 17515 NULL
110182 +qp_free_res_17541 qp_free_res 5 17541 NULL
110183 +__copy_to_user_17551 __copy_to_user 3-0 17551 NULL
110184 +copy_from_user_17559 copy_from_user 0-3 17559 NULL
110185 +hash_netport4_expire_17573 hash_netport4_expire 4 17573 NULL
110186 +acpi_ut_create_package_object_17594 acpi_ut_create_package_object 1 17594 NULL
110187 +neigh_hash_alloc_17595 neigh_hash_alloc 1 17595 NULL
110188 +osst_execute_17607 osst_execute 7-6 17607 NULL
110189 +ieee80211_if_read_dot11MeshHWMPactivePathToRootTimeout_17618 ieee80211_if_read_dot11MeshHWMPactivePathToRootTimeout 3 17618 NULL
110190 +dma_map_page_17628 dma_map_page 0 17628 NULL
110191 +ocfs2_rotate_subtree_left_17634 ocfs2_rotate_subtree_left 5 17634 NULL
110192 +twl4030_set_gpio_direction_17645 twl4030_set_gpio_direction 1 17645 NULL
110193 +SYSC_migrate_pages_17657 SYSC_migrate_pages 2 17657 NULL
110194 +packet_setsockopt_17662 packet_setsockopt 5 17662 NULL
110195 +pwr_enable_ps_read_17686 pwr_enable_ps_read 3 17686 NULL
110196 +venus_rename_17707 venus_rename 4-5 17707 NULL nohasharray
110197 +__einj_error_trigger_17707 __einj_error_trigger 0 17707 &venus_rename_17707
110198 +exofs_read_lookup_dev_table_17733 exofs_read_lookup_dev_table 3 17733 NULL
110199 +sctpprobe_read_17741 sctpprobe_read 3 17741 NULL
110200 +dgap_do_fep_load_17765 dgap_do_fep_load 3 17765 NULL
110201 +brcmf_sdio_chip_verifynvram_17776 brcmf_sdio_chip_verifynvram 4 17776 NULL
110202 +shrink_slab_node_17794 shrink_slab_node 3 17794 NULL
110203 +gnet_stats_copy_app_17821 gnet_stats_copy_app 3 17821 NULL
110204 +cipso_v4_gentag_rbm_17836 cipso_v4_gentag_rbm 0 17836 NULL
110205 +dm_stats_message_17863 dm_stats_message 5 17863 NULL
110206 +sisusb_send_bulk_msg_17864 sisusb_send_bulk_msg 3 17864 NULL
110207 +alloc_sja1000dev_17868 alloc_sja1000dev 1 17868 NULL
110208 +virtio_cread32_17873 virtio_cread32 0 17873 NULL
110209 +ray_cs_essid_proc_write_17875 ray_cs_essid_proc_write 3 17875 NULL
110210 +orinoco_set_key_17878 orinoco_set_key 5-7 17878 NULL nohasharray
110211 +i40e_align_l2obj_base_17878 i40e_align_l2obj_base 0-1 17878 &orinoco_set_key_17878
110212 +init_per_cpu_17880 init_per_cpu 1 17880 NULL
110213 +ieee80211_if_fmt_dot11MeshMaxPeerLinks_17883 ieee80211_if_fmt_dot11MeshMaxPeerLinks 3 17883 NULL
110214 +ieee80211_if_fmt_dot11MeshHWMPRootMode_17890 ieee80211_if_fmt_dot11MeshHWMPRootMode 3 17890 NULL
110215 +xfs_buf_associate_memory_17915 xfs_buf_associate_memory 3 17915 NULL
110216 +scsi_bufflen_17933 scsi_bufflen 0 17933 NULL
110217 +__mutex_lock_check_stamp_17947 __mutex_lock_check_stamp 0 17947 NULL
110218 +beacon_interval_write_17952 beacon_interval_write 3 17952 NULL
110219 +calc_nr_buckets_17976 calc_nr_buckets 0 17976 NULL
110220 +ext4_ext_calc_credits_for_single_extent_17983 ext4_ext_calc_credits_for_single_extent 0-2 17983 NULL
110221 +smk_write_cipso_17989 smk_write_cipso 3 17989 NULL
110222 +gnttab_max_grant_frames_17993 gnttab_max_grant_frames 0 17993 NULL
110223 +pvr2_v4l2_read_18006 pvr2_v4l2_read 3 18006 NULL
110224 +alloc_rx_desc_ring_18016 alloc_rx_desc_ring 2 18016 NULL
110225 +cpufreq_add_dev_symlink_18028 cpufreq_add_dev_symlink 0 18028 NULL
110226 +o2hb_highest_node_18034 o2hb_highest_node 0 18034 NULL
110227 +cryptd_alloc_instance_18048 cryptd_alloc_instance 2-3 18048 NULL
110228 +ddebug_proc_write_18055 ddebug_proc_write 3 18055 NULL
110229 +lua_sysfs_read_18062 lua_sysfs_read 6 18062 NULL
110230 +fpregs_get_18066 fpregs_get 4 18066 NULL
110231 +kvm_read_guest_page_18074 kvm_read_guest_page 5 18074 NULL
110232 +SYSC_pselect6_18076 SYSC_pselect6 1 18076 NULL
110233 +SYSC_semtimedop_18091 SYSC_semtimedop 3 18091 NULL
110234 +mpi_alloc_18094 mpi_alloc 1 18094 NULL
110235 +hfs_direct_IO_18104 hfs_direct_IO 4 18104 NULL
110236 +dfs_file_read_18116 dfs_file_read 3 18116 NULL
110237 +svc_getnl_18120 svc_getnl 0 18120 NULL
110238 +paging32_gpte_to_gfn_lvl_18131 paging32_gpte_to_gfn_lvl 0-2-1 18131 NULL
110239 +selinux_inode_setsecurity_18148 selinux_inode_setsecurity 4 18148 NULL
110240 +pccard_store_cis_18176 pccard_store_cis 6 18176 NULL
110241 +orinoco_add_extscan_result_18207 orinoco_add_extscan_result 3 18207 NULL
110242 +gsm_control_message_18209 gsm_control_message 4 18209 NULL
110243 +do_ipv6_setsockopt_18215 do_ipv6_setsockopt 5 18215 NULL
110244 +gnttab_alloc_grant_references_18240 gnttab_alloc_grant_references 1 18240 NULL
110245 +alloc_trace_uprobe_18247 alloc_trace_uprobe 3 18247 NULL
110246 +rfcomm_sock_setsockopt_18254 rfcomm_sock_setsockopt 5 18254 NULL
110247 +qdisc_class_hash_alloc_18262 qdisc_class_hash_alloc 1 18262 NULL
110248 +gfs2_alloc_sort_buffer_18275 gfs2_alloc_sort_buffer 1 18275 NULL
110249 +alloc_ring_18278 alloc_ring 2-4 18278 NULL
110250 +bio_phys_segments_18281 bio_phys_segments 0 18281 NULL nohasharray
110251 +nouveau_subdev_create__18281 nouveau_subdev_create_ 7 18281 &bio_phys_segments_18281
110252 +ext4_readpages_18283 ext4_readpages 4 18283 NULL
110253 +mmc_send_bus_test_18285 mmc_send_bus_test 4 18285 NULL
110254 +um_idi_write_18293 um_idi_write 3 18293 NULL
110255 +nouveau_disp_create__18305 nouveau_disp_create_ 4-7 18305 NULL
110256 +vga_r_18310 vga_r 0 18310 NULL
110257 +class_add_profile_18315 class_add_profile 1-3-5 18315 NULL
110258 +csio_mem_read_18319 csio_mem_read 3 18319 NULL
110259 +alloc_and_copy_string_18321 alloc_and_copy_string 2 18321 NULL
110260 +ecryptfs_send_message_18322 ecryptfs_send_message 2 18322 NULL
110261 +bio_integrity_advance_18324 bio_integrity_advance 2 18324 NULL
110262 +lcd_proc_write_18351 lcd_proc_write 3 18351 NULL
110263 +pwr_power_save_off_read_18355 pwr_power_save_off_read 3 18355 NULL
110264 +SyS_process_vm_readv_18366 SyS_process_vm_readv 3-5 18366 NULL
110265 +ep_io_18367 ep_io 0 18367 NULL
110266 +qib_user_sdma_num_pages_18371 qib_user_sdma_num_pages 0 18371 NULL
110267 +ci_role_write_18388 ci_role_write 3 18388 NULL
110268 +hdlc_empty_fifo_18397 hdlc_empty_fifo 2 18397 NULL
110269 +adis16136_show_serial_18402 adis16136_show_serial 3 18402 NULL
110270 +crystalhd_user_data_18407 crystalhd_user_data 3 18407 NULL
110271 +iscsi_create_flashnode_sess_18433 iscsi_create_flashnode_sess 4 18433 NULL
110272 +snd_hda_get_connections_18437 snd_hda_get_connections 0 18437 NULL
110273 +flash_dev_cache_miss_18454 flash_dev_cache_miss 4 18454 NULL
110274 +fuse_perform_write_18457 fuse_perform_write 4 18457 NULL
110275 +regset_tls_set_18459 regset_tls_set 4 18459 NULL
110276 +pci_vpd_lrdt_size_18479 pci_vpd_lrdt_size 0 18479 NULL nohasharray
110277 +mite_bytes_in_transit_18479 mite_bytes_in_transit 0 18479 &pci_vpd_lrdt_size_18479
110278 +udpv6_setsockopt_18487 udpv6_setsockopt 5 18487 NULL
110279 +btrfs_fiemap_18501 btrfs_fiemap 3 18501 NULL
110280 +__copy_user_zeroing_intel_18510 __copy_user_zeroing_intel 0-3 18510 NULL
110281 +snd_vx_inb_18514 snd_vx_inb 0 18514 NULL
110282 +snd_gus_dram_poke_18525 snd_gus_dram_poke 4 18525 NULL
110283 +nouveau_fifo_channel_create__18530 nouveau_fifo_channel_create_ 9 18530 NULL
110284 +seq_copy_in_user_18543 seq_copy_in_user 3 18543 NULL
110285 +sas_change_queue_depth_18555 sas_change_queue_depth 2 18555 NULL
110286 +smk_write_rules_list_18565 smk_write_rules_list 3 18565 NULL
110287 +debug_output_18575 debug_output 3 18575 NULL
110288 +filemap_fdatawait_range_18600 filemap_fdatawait_range 0 18600 NULL nohasharray
110289 +slabinfo_write_18600 slabinfo_write 3 18600 &filemap_fdatawait_range_18600
110290 +iowarrior_write_18604 iowarrior_write 3 18604 NULL
110291 +nvc0_ram_create__18624 nvc0_ram_create_ 4 18624 NULL nohasharray
110292 +audio_get_endpoint_req_18624 audio_get_endpoint_req 0 18624 &nvc0_ram_create__18624
110293 +from_buffer_18625 from_buffer 3 18625 NULL
110294 +snd_pcm_oss_write3_18657 snd_pcm_oss_write3 0-3 18657 NULL
110295 +ieee80211_if_fmt_rssi_threshold_18664 ieee80211_if_fmt_rssi_threshold 3 18664 NULL
110296 +xfs_iext_insert_18667 xfs_iext_insert 3 18667 NULL
110297 +fnic_stats_debugfs_read_18688 fnic_stats_debugfs_read 3 18688 NULL
110298 +echo_client_prep_commit_18693 echo_client_prep_commit 8 18693 NULL
110299 +iwl_dbgfs_rx_handlers_read_18708 iwl_dbgfs_rx_handlers_read 3 18708 NULL
110300 +ceph_alloc_page_vector_18710 ceph_alloc_page_vector 1 18710 NULL
110301 +blk_rq_bytes_18715 blk_rq_bytes 0 18715 NULL
110302 +snd_als4k_gcr_read_addr_18741 snd_als4k_gcr_read_addr 0 18741 NULL
110303 +o2hb_debug_create_18744 o2hb_debug_create 4 18744 NULL
110304 +__erst_read_to_erange_from_nvram_18748 __erst_read_to_erange_from_nvram 0 18748 NULL
110305 +wep_packets_read_18751 wep_packets_read 3 18751 NULL
110306 +read_file_dump_nfcal_18766 read_file_dump_nfcal 3 18766 NULL
110307 +ffs_epfile_read_18775 ffs_epfile_read 3 18775 NULL
110308 +SyS_lsetxattr_18776 SyS_lsetxattr 4 18776 NULL
110309 +alloc_fcdev_18780 alloc_fcdev 1 18780 NULL
110310 +prealloc_18800 prealloc 0 18800 NULL
110311 +dm_stats_print_18815 dm_stats_print 7 18815 NULL
110312 +sys_modify_ldt_18824 sys_modify_ldt 3 18824 NULL
110313 +mtf_test_write_18844 mtf_test_write 3 18844 NULL
110314 +sctp_setsockopt_events_18862 sctp_setsockopt_events 3 18862 NULL
110315 +ieee80211_if_read_element_ttl_18869 ieee80211_if_read_element_ttl 3 18869 NULL
110316 +xlog_find_verify_log_record_18870 xlog_find_verify_log_record 2 18870 NULL
110317 +ceph_setxattr_18913 ceph_setxattr 4 18913 NULL
110318 +ieee80211_rx_mgmt_disassoc_18927 ieee80211_rx_mgmt_disassoc 3 18927 NULL
110319 +snapshot_write_next_18937 snapshot_write_next 0 18937 NULL
110320 +__nla_reserve_18974 __nla_reserve 3 18974 NULL
110321 +__blockdev_direct_IO_18977 __blockdev_direct_IO 0-6 18977 NULL
110322 +layout_in_gaps_19006 layout_in_gaps 2 19006 NULL
110323 +huge_page_size_19008 huge_page_size 0 19008 NULL
110324 +hash_netport6_expire_19013 hash_netport6_expire 4 19013 NULL
110325 +sysfs_create_dir_ns_19033 sysfs_create_dir_ns 0 19033 NULL
110326 +revalidate_19043 revalidate 2 19043 NULL
110327 +afs_vnode_store_data_19048 afs_vnode_store_data 2-3-4-5 19048 NULL
110328 +osc_pinger_recov_seq_write_19056 osc_pinger_recov_seq_write 3 19056 NULL
110329 +create_gpadl_header_19064 create_gpadl_header 2 19064 NULL
110330 +ieee80211_key_alloc_19065 ieee80211_key_alloc 3 19065 NULL
110331 +ceph_create_snap_context_19082 ceph_create_snap_context 1 19082 NULL
110332 +sta_last_seq_ctrl_read_19106 sta_last_seq_ctrl_read 3 19106 NULL
110333 +cifs_readv_from_socket_19109 cifs_readv_from_socket 3 19109 NULL
110334 +ATOMIC_SUB_RETURN_19115 ATOMIC_SUB_RETURN 2 19115 NULL
110335 +snd_als4k_iobase_readl_19136 snd_als4k_iobase_readl 0 19136 NULL
110336 +alloc_irdadev_19140 alloc_irdadev 1 19140 NULL
110337 +sleep_auth_read_19159 sleep_auth_read 3 19159 NULL
110338 +smk_write_access2_19170 smk_write_access2 3 19170 NULL
110339 +iwl_dbgfs_reply_tx_error_read_19205 iwl_dbgfs_reply_tx_error_read 3 19205 NULL
110340 +vmw_unlocked_ioctl_19212 vmw_unlocked_ioctl 2 19212 NULL
110341 +__copy_to_user_inatomic_19214 __copy_to_user_inatomic 3-0 19214 NULL
110342 +dev_counters_read_19216 dev_counters_read 3 19216 NULL
110343 +wbcir_tx_19219 wbcir_tx 3 19219 NULL
110344 +snd_mask_max_19224 snd_mask_max 0 19224 NULL
110345 +bio_alloc_mddev_19238 bio_alloc_mddev 2 19238 NULL
110346 +ucma_query_19260 ucma_query 4 19260 NULL
110347 +il_dbgfs_rxon_filter_flags_read_19281 il_dbgfs_rxon_filter_flags_read 3 19281 NULL
110348 +batadv_tt_save_orig_buffer_19288 batadv_tt_save_orig_buffer 4 19288 NULL nohasharray
110349 +cfg80211_rx_unprot_mlme_mgmt_19288 cfg80211_rx_unprot_mlme_mgmt 3 19288 &batadv_tt_save_orig_buffer_19288
110350 +qc_capture_19298 qc_capture 3 19298 NULL
110351 +ocfs2_prepare_inode_for_refcount_19303 ocfs2_prepare_inode_for_refcount 4-3 19303 NULL
110352 +event_tx_stuck_read_19305 event_tx_stuck_read 3 19305 NULL
110353 +debug_read_19322 debug_read 3 19322 NULL
110354 +lbs_host_sleep_write_19332 lbs_host_sleep_write 3 19332 NULL nohasharray
110355 +cfg80211_inform_bss_19332 cfg80211_inform_bss 8 19332 &lbs_host_sleep_write_19332
110356 +closure_sub_19359 closure_sub 2 19359 NULL
110357 +firmware_data_write_19360 firmware_data_write 6-5 19360 NULL
110358 +read_zero_19366 read_zero 3 19366 NULL
110359 +interpret_user_input_19393 interpret_user_input 2 19393 NULL
110360 +sync_fill_pt_info_19397 sync_fill_pt_info 0 19397 NULL
110361 +pep_recvmsg_19402 pep_recvmsg 4 19402 NULL
110362 +dvbdmx_write_19423 dvbdmx_write 3 19423 NULL
110363 +SyS_sched_getaffinity_19444 SyS_sched_getaffinity 2 19444 NULL
110364 +xfrm_alg_auth_len_19454 xfrm_alg_auth_len 0 19454 NULL
110365 +gnet_stats_copy_19458 gnet_stats_copy 4 19458 NULL
110366 +gp2ap020a00f_get_thresh_reg_19468 gp2ap020a00f_get_thresh_reg 0 19468 NULL
110367 +sky2_read16_19475 sky2_read16 0 19475 NULL
110368 +__read_status_pciv2_19492 __read_status_pciv2 0 19492 NULL
110369 +kstrtoll_from_user_19500 kstrtoll_from_user 2 19500 NULL
110370 +ext4_add_new_descs_19509 ext4_add_new_descs 3 19509 NULL
110371 +batadv_tvlv_container_register_19520 batadv_tvlv_container_register 5 19520 NULL
110372 +apei_exec_pre_map_gars_19529 apei_exec_pre_map_gars 0 19529 NULL nohasharray
110373 +cfc_write_array_to_buffer_19529 cfc_write_array_to_buffer 3 19529 &apei_exec_pre_map_gars_19529
110374 +nfc_llcp_build_tlv_19536 nfc_llcp_build_tlv 3 19536 NULL
110375 +howmany_64_19548 howmany_64 2 19548 NULL
110376 +gfn_to_index_19558 gfn_to_index 0-1-3-2 19558 NULL
110377 +ocfs2_control_message_19564 ocfs2_control_message 3 19564 NULL
110378 +ieee80211_if_read_tkip_mic_test_19565 ieee80211_if_read_tkip_mic_test 3 19565 NULL
110379 +nfsd_read_19568 nfsd_read 5 19568 NULL
110380 +cgroup_read_s64_19570 cgroup_read_s64 5 19570 NULL
110381 +bm_status_read_19583 bm_status_read 3 19583 NULL
110382 +load_xattr_datum_19594 load_xattr_datum 0 19594 NULL
110383 +__mei_cl_recv_19636 __mei_cl_recv 3 19636 NULL
110384 +LoadBitmap_19658 LoadBitmap 2 19658 NULL
110385 +iwl_dbgfs_pm_params_write_19660 iwl_dbgfs_pm_params_write 3 19660 NULL
110386 +read_reg_19723 read_reg 0 19723 NULL
110387 +wm8350_block_write_19727 wm8350_block_write 2-3 19727 NULL
110388 +memcpy_toiovecend_19736 memcpy_toiovecend 4-3 19736 NULL
110389 +snd_es1968_get_dma_ptr_19747 snd_es1968_get_dma_ptr 0 19747 NULL
110390 +p9_client_read_19750 p9_client_read 5-0 19750 NULL
110391 +pnpbios_proc_write_19758 pnpbios_proc_write 3 19758 NULL
110392 +ocfs2_readpages_19759 ocfs2_readpages 4 19759 NULL
110393 +jffs2_acl_from_medium_19762 jffs2_acl_from_medium 2 19762 NULL
110394 +readhscx_19769 readhscx 0 19769 NULL
110395 +__set_print_fmt_19776 __set_print_fmt 0 19776 NULL
110396 +iwl_dbgfs_disable_power_off_write_19823 iwl_dbgfs_disable_power_off_write 3 19823 NULL
110397 +irda_setsockopt_19824 irda_setsockopt 5 19824 NULL
110398 +vfs_getxattr_19832 vfs_getxattr 0 19832 NULL
110399 +security_context_to_sid_19839 security_context_to_sid 2 19839 NULL
110400 +crypt_alloc_buffer_19846 crypt_alloc_buffer 2 19846 NULL
110401 +cfg80211_mlme_register_mgmt_19852 cfg80211_mlme_register_mgmt 5 19852 NULL
110402 +__nla_put_19857 __nla_put 3 19857 NULL
110403 +mrp_request_join_19882 mrp_request_join 4 19882 NULL
110404 +aes_decrypt_interrupt_read_19910 aes_decrypt_interrupt_read 3 19910 NULL
110405 +ps_upsd_max_apturn_read_19918 ps_upsd_max_apturn_read 3 19918 NULL
110406 +mangle_name_19923 mangle_name 0 19923 NULL
110407 +cgroup_task_count_19930 cgroup_task_count 0 19930 NULL
110408 +guest_read_tsc_19931 guest_read_tsc 0 19931 NULL
110409 +iwl_dbgfs_rx_queue_read_19943 iwl_dbgfs_rx_queue_read 3 19943 NULL
110410 +cfg80211_rx_assoc_resp_19944 cfg80211_rx_assoc_resp 4 19944 NULL
110411 +get_jack_mode_name_19976 get_jack_mode_name 4 19976 NULL
110412 +attach_hdlc_protocol_19986 attach_hdlc_protocol 3 19986 NULL
110413 +rtw_set_wps_probe_resp_19989 rtw_set_wps_probe_resp 3 19989 NULL
110414 +lustre_pack_request_19992 lustre_pack_request 0 19992 NULL
110415 +diva_um_idi_read_20003 diva_um_idi_read 0 20003 NULL
110416 +lov_stripe_md_size_20009 lov_stripe_md_size 0-1 20009 NULL
110417 +tree_mod_log_eb_move_20011 tree_mod_log_eb_move 5 20011 NULL
110418 +SYSC_fgetxattr_20027 SYSC_fgetxattr 4 20027 NULL
110419 +split_scan_timeout_read_20029 split_scan_timeout_read 3 20029 NULL
110420 +alloc_ieee80211_20063 alloc_ieee80211 1 20063 NULL
110421 +iwl_mvm_power_mac_dbgfs_read_20067 iwl_mvm_power_mac_dbgfs_read 4 20067 NULL
110422 +target_message_20072 target_message 2 20072 NULL
110423 +rawv6_sendmsg_20080 rawv6_sendmsg 4 20080 NULL
110424 +fuse_conn_limit_read_20084 fuse_conn_limit_read 3 20084 NULL
110425 +aat2870_reg_write_file_20086 aat2870_reg_write_file 3 20086 NULL
110426 +team_options_register_20091 team_options_register 3 20091 NULL
110427 +qla2x00_adjust_sdev_qdepth_up_20097 qla2x00_adjust_sdev_qdepth_up 2 20097 NULL
110428 +root_nfs_copy_20111 root_nfs_copy 3 20111 NULL
110429 +hptiop_adjust_disk_queue_depth_20122 hptiop_adjust_disk_queue_depth 2 20122 NULL
110430 +tomoyo_commit_ok_20167 tomoyo_commit_ok 2 20167 NULL
110431 +read_flush_pipefs_20171 read_flush_pipefs 3 20171 NULL
110432 +wep_addr_key_count_read_20174 wep_addr_key_count_read 3 20174 NULL
110433 +create_trace_probe_20175 create_trace_probe 1 20175 NULL
110434 +crystalhd_map_dio_20181 crystalhd_map_dio 3 20181 NULL
110435 +pvr2_ctrl_value_to_sym_20229 pvr2_ctrl_value_to_sym 5 20229 NULL
110436 +rose_sendmsg_20249 rose_sendmsg 4 20249 NULL
110437 +tm6000_i2c_send_regs_20250 tm6000_i2c_send_regs 5 20250 NULL
110438 +btrfs_header_nritems_20296 btrfs_header_nritems 0 20296 NULL
110439 +r10_sync_page_io_20307 r10_sync_page_io 3 20307 NULL
110440 +dm_get_reserved_bio_based_ios_20315 dm_get_reserved_bio_based_ios 0 20315 NULL
110441 +tx_tx_burst_programmed_read_20320 tx_tx_burst_programmed_read 3 20320 NULL
110442 +vx_send_msg_nolock_20322 vx_send_msg_nolock 0 20322 NULL
110443 +snd_cs4281_BA1_read_20323 snd_cs4281_BA1_read 5 20323 NULL
110444 +gfs2_glock_nq_m_20347 gfs2_glock_nq_m 1 20347 NULL
110445 +handle_arr_calc_size_20355 handle_arr_calc_size 0-1 20355 NULL
110446 +smk_set_cipso_20379 smk_set_cipso 3 20379 NULL
110447 +snd_nm256_readl_20394 snd_nm256_readl 0 20394 NULL nohasharray
110448 +read_7220_creg32_20394 read_7220_creg32 0 20394 &snd_nm256_readl_20394
110449 +__kfifo_from_user_20399 __kfifo_from_user 3 20399 NULL nohasharray
110450 +SyS_get_mempolicy_20399 SyS_get_mempolicy 3 20399 &__kfifo_from_user_20399
110451 +nfs3_setxattr_20458 nfs3_setxattr 4 20458 NULL
110452 +compat_ipv6_setsockopt_20468 compat_ipv6_setsockopt 5 20468 NULL
110453 +read_buf_20469 read_buf 2 20469 NULL
110454 +bio_trim_20472 bio_trim 2 20472 NULL
110455 +btrfs_get_32_20476 btrfs_get_32 0 20476 NULL
110456 +xfs_iext_realloc_direct_20521 xfs_iext_realloc_direct 2 20521 NULL
110457 +drbd_bm_resize_20522 drbd_bm_resize 2 20522 NULL
110458 +amd_create_gatt_pages_20537 amd_create_gatt_pages 1 20537 NULL
110459 +scsi_report_opcode_20551 scsi_report_opcode 3 20551 NULL
110460 +venus_create_20555 venus_create 4 20555 NULL
110461 +btrfs_super_log_root_20565 btrfs_super_log_root 0 20565 NULL
110462 +crypto_ahash_reqsize_20569 crypto_ahash_reqsize 0 20569 NULL
110463 +ocfs2_cluster_lock_20588 ocfs2_cluster_lock 0 20588 NULL
110464 +kvm_test_age_hva_20593 kvm_test_age_hva 2 20593 NULL
110465 +sync_timeline_create_20601 sync_timeline_create 2 20601 NULL
110466 +lirc_write_20604 lirc_write 3 20604 NULL
110467 +qib_qsfp_write_20614 qib_qsfp_write 0-2-4 20614 NULL
110468 +snd_pcm_oss_prepare_20641 snd_pcm_oss_prepare 0 20641 NULL
110469 +get_extent_skip_holes_20642 get_extent_skip_holes 2 20642 NULL
110470 +kfifo_copy_to_user_20646 kfifo_copy_to_user 3-4 20646 NULL
110471 +cpulist_scnprintf_20648 cpulist_scnprintf 2-0 20648 NULL
110472 +oz_add_farewell_20652 oz_add_farewell 5 20652 NULL
110473 +oz_cdev_read_20659 oz_cdev_read 3 20659 NULL
110474 +snd_hdsp_playback_copy_20676 snd_hdsp_playback_copy 5 20676 NULL
110475 +dvb_dmxdev_buffer_read_20682 dvb_dmxdev_buffer_read 0-4 20682 NULL
110476 +cpumask_size_20683 cpumask_size 0 20683 NULL
110477 +btrfs_node_blockptr_20685 btrfs_node_blockptr 0 20685 NULL
110478 +read_file_tgt_int_stats_20697 read_file_tgt_int_stats 3 20697 NULL
110479 +__maestro_read_20700 __maestro_read 0 20700 NULL
110480 +cipso_v4_gentag_rng_20703 cipso_v4_gentag_rng 0 20703 NULL
110481 +pcpu_page_first_chunk_20712 pcpu_page_first_chunk 1 20712 NULL
110482 +ocfs2_read_xattr_bucket_20722 ocfs2_read_xattr_bucket 0 20722 NULL
110483 +security_context_to_sid_force_20724 security_context_to_sid_force 2 20724 NULL
110484 +fb_prepare_logo_20743 fb_prepare_logo 0 20743 NULL
110485 +vol_cdev_direct_write_20751 vol_cdev_direct_write 3 20751 NULL
110486 +ocfs2_align_bytes_to_clusters_20754 ocfs2_align_bytes_to_clusters 2 20754 NULL
110487 +brcmf_p2p_escan_20763 brcmf_p2p_escan 2 20763 NULL
110488 +fb_alloc_cmap_gfp_20792 fb_alloc_cmap_gfp 2 20792 NULL
110489 +iwl_dbgfs_rxon_flags_read_20795 iwl_dbgfs_rxon_flags_read 3 20795 NULL
110490 +strndup_user_20819 strndup_user 2 20819 NULL
110491 +tipc_msg_build_20825 tipc_msg_build 3 20825 NULL
110492 +wl1271_format_buffer_20834 wl1271_format_buffer 2 20834 NULL
110493 +uvc_alloc_entity_20836 uvc_alloc_entity 3-4 20836 NULL
110494 +p9_tag_alloc_20845 p9_tag_alloc 3 20845 NULL
110495 +nvme_trans_supported_vpd_pages_20847 nvme_trans_supported_vpd_pages 4 20847 NULL
110496 +get_name_20855 get_name 4 20855 NULL
110497 +iwl_dbgfs_pm_params_read_20866 iwl_dbgfs_pm_params_read 3 20866 NULL
110498 +snd_pcm_capture_avail_20867 snd_pcm_capture_avail 0 20867 NULL
110499 +srq_free_res_20868 srq_free_res 5 20868 NULL
110500 +cfs_cpt_table_create_20884 cfs_cpt_table_create 1 20884 NULL
110501 +rb_simple_write_20890 rb_simple_write 3 20890 NULL
110502 +sisusb_send_packet_20891 sisusb_send_packet 2 20891 NULL
110503 +key_icverrors_read_20895 key_icverrors_read 3 20895 NULL
110504 +vfio_msi_enable_20906 vfio_msi_enable 2 20906 NULL
110505 +lbs_rdbbp_write_20918 lbs_rdbbp_write 3 20918 NULL
110506 +htable_bits_20933 htable_bits 0 20933 NULL
110507 +altera_set_ir_post_20948 altera_set_ir_post 2 20948 NULL
110508 +rx_rx_phy_hdr_read_20950 rx_rx_phy_hdr_read 3 20950 NULL
110509 +rsxx_cram_read_20957 rsxx_cram_read 3 20957 NULL
110510 +nfs_map_name_to_uid_20962 nfs_map_name_to_uid 3 20962 NULL
110511 +snd_rme9652_playback_copy_20970 snd_rme9652_playback_copy 5 20970 NULL
110512 +alg_setsockopt_20985 alg_setsockopt 5 20985 NULL
110513 +qib_verbs_send_20999 qib_verbs_send 5-3 20999 NULL
110514 +btrfs_inode_ref_name_len_21024 btrfs_inode_ref_name_len 0 21024 NULL
110515 +rx_defrag_tkip_called_read_21031 rx_defrag_tkip_called_read 3 21031 NULL
110516 +srp_change_queue_depth_21038 srp_change_queue_depth 2 21038 NULL
110517 +lbs_threshold_read_21046 lbs_threshold_read 5 21046 NULL
110518 +reiserfs_direct_IO_21051 reiserfs_direct_IO 4 21051 NULL
110519 +proc_fault_inject_write_21058 proc_fault_inject_write 3 21058 NULL
110520 +qdisc_get_default_21072 qdisc_get_default 2 21072 NULL
110521 +event_calibration_read_21083 event_calibration_read 3 21083 NULL
110522 +bl_add_page_to_bio_21094 bl_add_page_to_bio 2 21094 NULL nohasharray
110523 +multipath_status_21094 multipath_status 5 21094 &bl_add_page_to_bio_21094
110524 +rate_control_pid_events_read_21099 rate_control_pid_events_read 3 21099 NULL
110525 +ocfs2_extend_meta_needed_21104 ocfs2_extend_meta_needed 0 21104 NULL
110526 +ath6kl_send_go_probe_resp_21113 ath6kl_send_go_probe_resp 3 21113 NULL
110527 +i2400m_rx_trace_21127 i2400m_rx_trace 3 21127 NULL
110528 +cx18_v4l2_read_21196 cx18_v4l2_read 3 21196 NULL
110529 +ipc_rcu_alloc_21208 ipc_rcu_alloc 1 21208 NULL
110530 +scsi_execute_req_flags_21215 scsi_execute_req_flags 5 21215 NULL
110531 +get_numpages_21227 get_numpages 0-1-2 21227 NULL
110532 +input_ff_create_21240 input_ff_create 2 21240 NULL
110533 +cfg80211_notify_new_peer_candidate_21242 cfg80211_notify_new_peer_candidate 4 21242 NULL
110534 +use_debug_keys_read_21251 use_debug_keys_read 3 21251 NULL
110535 +fru_length_21257 fru_length 0 21257 NULL
110536 +rtw_set_wps_beacon_21262 rtw_set_wps_beacon 3 21262 NULL
110537 +ocfs2_blocks_for_bytes_21268 ocfs2_blocks_for_bytes 0-2 21268 NULL
110538 +do_msg_fill_21307 do_msg_fill 3 21307 NULL
110539 +add_res_range_21310 add_res_range 4 21310 NULL
110540 +get_zeroed_page_21322 get_zeroed_page 0 21322 NULL
110541 +ftrace_profile_read_21327 ftrace_profile_read 3 21327 NULL
110542 +read_file_bool_bmps_21344 read_file_bool_bmps 3 21344 NULL
110543 +ocfs2_find_subtree_root_21351 ocfs2_find_subtree_root 0 21351 NULL
110544 +gfs2_ea_get_copy_21353 gfs2_ea_get_copy 0 21353 NULL
110545 +alloc_orinocodev_21371 alloc_orinocodev 1 21371 NULL
110546 +SYSC_rt_sigpending_21379 SYSC_rt_sigpending 2 21379 NULL
110547 +video_ioctl2_21380 video_ioctl2 2 21380 NULL
110548 +insert_ptr_21386 insert_ptr 6 21386 NULL
110549 +diva_get_driver_dbg_mask_21399 diva_get_driver_dbg_mask 0 21399 NULL
110550 +snd_m3_inw_21406 snd_m3_inw 0 21406 NULL
110551 +snapshot_read_next_21426 snapshot_read_next 0 21426 NULL
110552 +tcp_bound_to_half_wnd_21429 tcp_bound_to_half_wnd 0-2 21429 NULL
110553 +tracing_saved_cmdlines_read_21434 tracing_saved_cmdlines_read 3 21434 NULL
110554 +aggr_size_tx_agg_vs_rate_read_21438 aggr_size_tx_agg_vs_rate_read 3 21438 NULL
110555 +__ertm_hdr_size_21450 __ertm_hdr_size 0 21450 NULL
110556 +ReadISAR_21453 ReadISAR 0 21453 NULL
110557 +mei_nfc_send_21477 mei_nfc_send 3 21477 NULL
110558 +read_file_xmit_21487 read_file_xmit 3 21487 NULL
110559 +mmc_alloc_sg_21504 mmc_alloc_sg 1 21504 NULL
110560 +btrfs_file_aio_write_21520 btrfs_file_aio_write 4 21520 NULL
110561 +il_dbgfs_stations_read_21532 il_dbgfs_stations_read 3 21532 NULL
110562 +cipso_v4_map_cat_enum_hton_21540 cipso_v4_map_cat_enum_hton 0 21540 NULL
110563 +rxrpc_send_data_21553 rxrpc_send_data 5 21553 NULL
110564 +rx_rx_beacon_early_term_read_21559 rx_rx_beacon_early_term_read 3 21559 NULL
110565 +xfs_buf_read_uncached_21585 xfs_buf_read_uncached 3 21585 NULL
110566 +snd_es18xx_mixer_read_21586 snd_es18xx_mixer_read 0 21586 NULL
110567 +ocfs2_acl_from_xattr_21604 ocfs2_acl_from_xattr 2 21604 NULL
110568 +filemap_get_page_21606 filemap_get_page 2 21606 NULL
110569 +ocfs2_refcount_cow_hunk_21630 ocfs2_refcount_cow_hunk 3-4 21630 NULL
110570 +__jfs_getxattr_21631 __jfs_getxattr 0 21631 NULL
110571 +atalk_sendmsg_21677 atalk_sendmsg 4 21677 NULL
110572 +ocfs2_xattr_get_nolock_21678 ocfs2_xattr_get_nolock 0 21678 NULL
110573 +rtllib_alloc_txb_21687 rtllib_alloc_txb 1 21687 NULL
110574 +evdev_ioctl_handler_21705 evdev_ioctl_handler 2 21705 NULL
110575 +unix_skb_len_21722 unix_skb_len 0 21722 NULL
110576 +lprocfs_wr_import_21728 lprocfs_wr_import 3 21728 NULL
110577 +mthca_alloc_init_21754 mthca_alloc_init 2 21754 NULL
110578 +usbat_flash_read_data_21762 usbat_flash_read_data 4 21762 NULL
110579 +gen_pool_add_21776 gen_pool_add 3 21776 NULL
110580 +xfs_da_grow_inode_int_21785 xfs_da_grow_inode_int 3 21785 NULL
110581 +dvb_generic_ioctl_21810 dvb_generic_ioctl 2 21810 NULL
110582 +__ocfs2_cluster_lock_21812 __ocfs2_cluster_lock 0 21812 NULL
110583 +oom_adj_read_21847 oom_adj_read 3 21847 NULL
110584 +lpfc_idiag_extacc_avail_get_21865 lpfc_idiag_extacc_avail_get 0-3 21865 NULL
110585 +brcms_debugfs_hardware_read_21867 brcms_debugfs_hardware_read 3 21867 NULL
110586 +sisusbcon_bmove_21873 sisusbcon_bmove 6-5-7 21873 NULL
110587 +ldlm_lock_create_21888 ldlm_lock_create 7 21888 NULL
110588 +dbAllocCtl_21911 dbAllocCtl 0 21911 NULL
110589 +qsfp_1_read_21915 qsfp_1_read 3 21915 NULL
110590 +SYSC_prctl_21980 SYSC_prctl 4 21980 NULL
110591 +compat_rw_copy_check_uvector_22001 compat_rw_copy_check_uvector 0-3 22001 NULL nohasharray
110592 +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
110593 +regcache_sync_block_raw_flush_22021 regcache_sync_block_raw_flush 3-4 22021 NULL
110594 +btrfs_get_16_22023 btrfs_get_16 0 22023 NULL
110595 +_sp2d_min_pg_22032 _sp2d_min_pg 0 22032 NULL
110596 +zd_usb_read_fw_22049 zd_usb_read_fw 4 22049 NULL
110597 +ieee80211_if_fmt_dropped_frames_ttl_22054 ieee80211_if_fmt_dropped_frames_ttl 3 22054 NULL
110598 +btrfs_reloc_clone_csums_22077 btrfs_reloc_clone_csums 2-3 22077 NULL
110599 +mem_rw_22085 mem_rw 3 22085 NULL
110600 +kstrtos32_from_user_22087 kstrtos32_from_user 2 22087 NULL
110601 +rt2x00debug_read_crypto_stats_22109 rt2x00debug_read_crypto_stats 3 22109 NULL
110602 +snd_hda_codec_read_22130 snd_hda_codec_read 0 22130 NULL
110603 +SyS_sched_setaffinity_22148 SyS_sched_setaffinity 2 22148 NULL
110604 +do_tcp_sendpages_22155 do_tcp_sendpages 4 22155 NULL
110605 +__kfifo_alloc_22173 __kfifo_alloc 3 22173 NULL
110606 +rfcomm_sock_recvmsg_22227 rfcomm_sock_recvmsg 4 22227 NULL
110607 +mem_write_22232 mem_write 3 22232 NULL
110608 +p9_virtio_zc_request_22240 p9_virtio_zc_request 6-5 22240 NULL
110609 +prepare_to_wait_event_22247 prepare_to_wait_event 0 22247 NULL
110610 +compat_process_vm_rw_22254 compat_process_vm_rw 3-5 22254 NULL
110611 +ping_common_sendmsg_22261 ping_common_sendmsg 5 22261 NULL
110612 +add_res_tree_22263 add_res_tree 7 22263 NULL
110613 +__btrfs_direct_write_22273 __btrfs_direct_write 4 22273 NULL
110614 +queue_max_sectors_22280 queue_max_sectors 0 22280 NULL
110615 +__tun_chr_ioctl_22300 __tun_chr_ioctl 4 22300 NULL nohasharray
110616 +pci_vpd_srdt_size_22300 pci_vpd_srdt_size 0 22300 &__tun_chr_ioctl_22300
110617 +mesh_table_alloc_22305 mesh_table_alloc 1 22305 NULL
110618 +lov_setstripe_22307 lov_setstripe 2 22307 NULL
110619 +udpv6_sendmsg_22316 udpv6_sendmsg 4 22316 NULL
110620 +C_SYSC_msgrcv_22320 C_SYSC_msgrcv 3 22320 NULL
110621 +atomic_read_22342 atomic_read 0 22342 NULL
110622 +ll_lazystatfs_seq_write_22353 ll_lazystatfs_seq_write 3 22353 NULL
110623 +memcg_size_22360 memcg_size 0 22360 NULL
110624 +snd_pcm_alsa_frames_22363 snd_pcm_alsa_frames 2 22363 NULL
110625 +evdev_ioctl_22371 evdev_ioctl 2 22371 NULL
110626 +alloc_large_system_hash_22391 alloc_large_system_hash 2 22391 NULL
110627 +zoran_write_22404 zoran_write 3 22404 NULL
110628 +ATOMIC_ADD_RETURN_22413 ATOMIC_ADD_RETURN 2 22413 NULL
110629 +queue_reply_22416 queue_reply 3 22416 NULL
110630 +__set_enter_print_fmt_22431 __set_enter_print_fmt 0 22431 NULL
110631 +queue_max_segments_22441 queue_max_segments 0 22441 NULL
110632 +handle_received_packet_22457 handle_received_packet 3 22457 NULL
110633 +mem_cgroup_read_22461 mem_cgroup_read 5 22461 NULL
110634 +source_sink_start_ep_22472 source_sink_start_ep 0 22472 NULL
110635 +ecryptfs_write_22488 ecryptfs_write 4-3 22488 NULL
110636 +qib_user_sdma_alloc_header_22490 qib_user_sdma_alloc_header 2 22490 NULL
110637 +cache_write_procfs_22491 cache_write_procfs 3 22491 NULL
110638 +mutex_lock_interruptible_22505 mutex_lock_interruptible 0 22505 NULL
110639 +trim_no_bitmap_22524 trim_no_bitmap 4-3 22524 NULL
110640 +ocfs2_read_extent_block_22550 ocfs2_read_extent_block 0 22550 NULL
110641 +agp_alloc_page_array_22554 agp_alloc_page_array 1 22554 NULL
110642 +dbFindCtl_22587 dbFindCtl 0 22587 NULL
110643 +snapshot_read_22601 snapshot_read 3 22601 NULL
110644 +sctp_setsockopt_connectx_old_22631 sctp_setsockopt_connectx_old 3 22631 NULL
110645 +ide_core_cp_entry_22636 ide_core_cp_entry 3 22636 NULL
110646 +wl1271_rx_filter_get_fields_size_22638 wl1271_rx_filter_get_fields_size 0 22638 NULL
110647 +pwr_wake_on_timer_exp_read_22640 pwr_wake_on_timer_exp_read 3 22640 NULL
110648 +iwl_dbgfs_calib_disabled_read_22649 iwl_dbgfs_calib_disabled_read 3 22649 NULL
110649 +compat_SyS_msgrcv_22661 compat_SyS_msgrcv 3 22661 NULL
110650 +ext4_ext_direct_IO_22679 ext4_ext_direct_IO 4 22679 NULL
110651 +l2tp_ip_recvmsg_22681 l2tp_ip_recvmsg 4 22681 NULL
110652 +bch_dump_read_22685 bch_dump_read 3 22685 NULL
110653 +reg_umr_22686 reg_umr 5 22686 NULL
110654 +alloc_libipw_22708 alloc_libipw 1 22708 NULL
110655 +cx18_copy_buf_to_user_22735 cx18_copy_buf_to_user 4-0 22735 NULL
110656 +ceph_decode_32_22738 ceph_decode_32 0 22738 NULL nohasharray
110657 +__mei_cl_send_22738 __mei_cl_send 3 22738 &ceph_decode_32_22738
110658 +iio_debugfs_write_reg_22742 iio_debugfs_write_reg 3 22742 NULL
110659 +qlcnic_sriov_init_22762 qlcnic_sriov_init 2 22762 NULL
110660 +print_frame_22769 print_frame 0 22769 NULL
110661 +ftrace_arch_read_dyn_info_22773 ftrace_arch_read_dyn_info 0 22773 NULL
110662 +pla_ocp_write_22802 pla_ocp_write 4 22802 NULL
110663 +__generic_copy_to_user_intel_22806 __generic_copy_to_user_intel 0-3 22806 NULL
110664 +clone_bio_integrity_22842 clone_bio_integrity 4 22842 NULL
110665 +read_file_rcstat_22854 read_file_rcstat 3 22854 NULL
110666 +create_attr_set_22861 create_attr_set 1 22861 NULL
110667 +hash_ip6_expire_22867 hash_ip6_expire 4 22867 NULL
110668 +vmw_execbuf_process_22885 vmw_execbuf_process 5 22885 NULL
110669 +usblp_new_writeurb_22894 usblp_new_writeurb 2 22894 NULL
110670 +mdc800_device_read_22896 mdc800_device_read 3 22896 NULL
110671 +policy_emit_config_values_22900 policy_emit_config_values 3 22900 NULL
110672 +xstateregs_set_22932 xstateregs_set 4 22932 NULL
110673 +pcpu_mem_zalloc_22948 pcpu_mem_zalloc 1 22948 NULL
110674 +alloc_sglist_22960 alloc_sglist 2-3 22960 NULL
110675 +caif_seqpkt_sendmsg_22961 caif_seqpkt_sendmsg 4 22961 NULL
110676 +vme_get_size_22964 vme_get_size 0 22964 NULL
110677 +tx_frag_key_not_found_read_22971 tx_frag_key_not_found_read 3 22971 NULL
110678 +usb_get_langid_22983 usb_get_langid 0 22983 NULL
110679 +remote_settings_file_write_22987 remote_settings_file_write 3 22987 NULL
110680 +brcmf_sdio_chip_exit_download_23001 brcmf_sdio_chip_exit_download 4 23001 NULL
110681 +viafb_dvp0_proc_write_23023 viafb_dvp0_proc_write 3 23023 NULL
110682 +cifs_local_to_utf16_bytes_23025 cifs_local_to_utf16_bytes 0 23025 NULL
110683 +ocfs2_refcount_cow_xattr_23029 ocfs2_refcount_cow_xattr 0-6-7 23029 NULL
110684 +st_status_23032 st_status 5 23032 NULL
110685 +nv50_disp_chan_create__23056 nv50_disp_chan_create_ 5 23056 NULL
110686 +comedi_buf_write_n_available_23057 comedi_buf_write_n_available 0 23057 NULL
110687 +reiserfs_add_entry_23062 reiserfs_add_entry 4 23062 NULL nohasharray
110688 +unix_seqpacket_recvmsg_23062 unix_seqpacket_recvmsg 4 23062 &reiserfs_add_entry_23062
110689 +mei_cl_send_23068 mei_cl_send 3 23068 NULL
110690 +kvm_mmu_gva_to_gpa_write_23075 kvm_mmu_gva_to_gpa_write 0 23075 NULL
110691 +raw_sendmsg_23078 raw_sendmsg 4 23078 NULL
110692 +get_user_hdr_len_23079 get_user_hdr_len 0 23079 NULL
110693 +isr_tx_procs_read_23084 isr_tx_procs_read 3 23084 NULL
110694 +rt2x00debug_write_eeprom_23091 rt2x00debug_write_eeprom 3 23091 NULL
110695 +ntfs_ucstonls_23097 ntfs_ucstonls 3-5 23097 NULL
110696 +pipe_iov_copy_from_user_23102 pipe_iov_copy_from_user 3 23102 NULL
110697 +dgram_recvmsg_23104 dgram_recvmsg 4 23104 NULL
110698 +mwl8k_cmd_set_beacon_23110 mwl8k_cmd_set_beacon 4 23110 NULL
110699 +nl80211_send_rx_auth_23111 nl80211_send_rx_auth 4 23111 NULL
110700 +__clear_user_23118 __clear_user 0-2 23118 NULL
110701 +drm_mode_create_tv_properties_23122 drm_mode_create_tv_properties 2 23122 NULL
110702 +ata_scsi_change_queue_depth_23126 ata_scsi_change_queue_depth 2 23126 NULL
110703 +read_file_ani_23161 read_file_ani 3 23161 NULL
110704 +usblp_write_23178 usblp_write 3 23178 NULL
110705 +gss_pipe_downcall_23182 gss_pipe_downcall 3 23182 NULL
110706 +mpi_alloc_limb_space_23190 mpi_alloc_limb_space 1 23190 NULL
110707 +tty_buffer_request_room_23228 tty_buffer_request_room 2-0 23228 NULL
110708 +xlog_get_bp_23229 xlog_get_bp 2 23229 NULL nohasharray
110709 +__read_status_pci_23229 __read_status_pci 0 23229 &xlog_get_bp_23229
110710 +ft1000_read_dpram_mag_32_23232 ft1000_read_dpram_mag_32 0 23232 NULL
110711 +rxrpc_client_sendmsg_23236 rxrpc_client_sendmsg 5 23236 NULL
110712 +__gfn_to_rmap_23240 __gfn_to_rmap 2-1 23240 NULL
110713 +nv50_ram_create__23241 nv50_ram_create_ 4 23241 NULL
110714 +sctp_recvmsg_23265 sctp_recvmsg 4 23265 NULL
110715 +uwb_dev_addr_print_23282 uwb_dev_addr_print 2 23282 NULL
110716 +diva_get_trace_filter_23286 diva_get_trace_filter 0 23286 NULL
110717 +i2cdev_write_23310 i2cdev_write 3 23310 NULL
110718 +__aa_kvmalloc_23320 __aa_kvmalloc 1 23320 NULL
110719 +page_readlink_23346 page_readlink 3 23346 NULL
110720 +kmem_zalloc_large_23351 kmem_zalloc_large 1 23351 NULL
110721 +get_dst_timing_23358 get_dst_timing 0 23358 NULL
110722 +fd_setup_write_same_buf_23369 fd_setup_write_same_buf 3 23369 NULL
110723 +iscsi_change_queue_depth_23416 iscsi_change_queue_depth 2 23416 NULL
110724 +vga_mm_r_23419 vga_mm_r 0 23419 NULL
110725 +ocfs2_zero_tail_23447 ocfs2_zero_tail 3 23447 NULL
110726 +hidraw_send_report_23449 hidraw_send_report 3 23449 NULL
110727 +__ata_change_queue_depth_23484 __ata_change_queue_depth 3 23484 NULL
110728 +linear_conf_23485 linear_conf 2 23485 NULL
110729 +event_filter_read_23494 event_filter_read 3 23494 NULL
110730 +lustre_acl_xattr_merge2ext_23502 lustre_acl_xattr_merge2ext 2 23502 NULL
110731 +devm_iio_device_alloc_23511 devm_iio_device_alloc 2 23511 NULL
110732 +__proc_cpt_table_23516 __proc_cpt_table 5 23516 NULL
110733 +ima_show_measurements_count_23536 ima_show_measurements_count 3 23536 NULL
110734 +tcp_current_mss_23552 tcp_current_mss 0 23552 NULL
110735 +btrfs_super_bytenr_23561 btrfs_super_bytenr 0 23561 NULL
110736 +venus_symlink_23570 venus_symlink 6-4 23570 NULL
110737 +iwl_dbgfs_interrupt_read_23574 iwl_dbgfs_interrupt_read 3 23574 NULL
110738 +xfpregs_get_23586 xfpregs_get 4 23586 NULL
110739 +snd_interval_min_23590 snd_interval_min 0 23590 NULL
110740 +islpci_mgt_transaction_23610 islpci_mgt_transaction 5 23610 NULL
110741 +ocfs2_journal_access_23616 ocfs2_journal_access 0 23616 NULL
110742 +__i2400mu_send_barker_23652 __i2400mu_send_barker 3 23652 NULL
110743 +sInW_23663 sInW 0 23663 NULL
110744 +SyS_connect_23669 SyS_connect 3 23669 NULL
110745 +cx18_read_23699 cx18_read 3 23699 NULL
110746 +at_get_23708 at_get 0 23708 NULL
110747 +rx_rx_dropped_frame_read_23748 rx_rx_dropped_frame_read 3 23748 NULL
110748 +__kfifo_max_r_23768 __kfifo_max_r 0-2-1 23768 NULL
110749 +__build_packet_message_23778 __build_packet_message 4-10 23778 NULL
110750 +security_inode_getxattr_23781 security_inode_getxattr 0 23781 NULL
110751 +cfg80211_inform_bss_width_frame_23782 cfg80211_inform_bss_width_frame 5 23782 NULL
110752 +mpt_free_res_23793 mpt_free_res 5 23793 NULL
110753 +map_write_23795 map_write 3 23795 NULL
110754 +rx_path_reset_read_23801 rx_path_reset_read 3 23801 NULL
110755 +ocfs2_replace_cow_23803 ocfs2_replace_cow 0 23803 NULL
110756 +__earlyonly_bootmem_alloc_23824 __earlyonly_bootmem_alloc 2 23824 NULL
110757 +lustre_msg_buflen_23827 lustre_msg_buflen 0 23827 NULL
110758 +ceph_copy_page_vector_to_user_23829 ceph_copy_page_vector_to_user 3-4 23829 NULL
110759 +pgdat_end_pfn_23842 pgdat_end_pfn 0 23842 NULL
110760 +iwl_dbgfs_nvm_read_23845 iwl_dbgfs_nvm_read 3 23845 NULL
110761 +p54_init_common_23850 p54_init_common 1 23850 NULL
110762 +bin_to_hex_dup_23853 bin_to_hex_dup 2 23853 NULL
110763 +ocfs2_xattr_get_clusters_23857 ocfs2_xattr_get_clusters 0 23857 NULL
110764 +ieee80211_if_read_dot11MeshMaxPeerLinks_23878 ieee80211_if_read_dot11MeshMaxPeerLinks 3 23878 NULL
110765 +nouveau_clock_create__23881 nouveau_clock_create_ 5 23881 NULL
110766 +tipc_snprintf_23893 tipc_snprintf 2-0 23893 NULL
110767 +usbg_prepare_w_request_23895 usbg_prepare_w_request 0 23895 NULL
110768 +add_new_gdb_meta_bg_23911 add_new_gdb_meta_bg 3 23911 NULL nohasharray
110769 +ieee80211_if_read_hw_queues_23911 ieee80211_if_read_hw_queues 3 23911 &add_new_gdb_meta_bg_23911
110770 +f2fs_getxattr_23917 f2fs_getxattr 0 23917 NULL
110771 +mpihelp_mul_karatsuba_case_23918 mpihelp_mul_karatsuba_case 5-3 23918 NULL nohasharray
110772 +ipath_reg_phys_mr_23918 ipath_reg_phys_mr 3 23918 &mpihelp_mul_karatsuba_case_23918
110773 +kvm_read_guest_23928 kvm_read_guest 4-2 23928 NULL
110774 +uvc_endpoint_max_bpi_23944 uvc_endpoint_max_bpi 0 23944 NULL
110775 +cifs_setxattr_23957 cifs_setxattr 4 23957 NULL
110776 +size_roundup_power2_23958 size_roundup_power2 0-1 23958 NULL
110777 +sddr55_write_data_23983 sddr55_write_data 4 23983 NULL
110778 +zd_usb_iowrite16v_async_23984 zd_usb_iowrite16v_async 3 23984 NULL
110779 +cxgb_alloc_mem_24007 cxgb_alloc_mem 1 24007 NULL
110780 +give_pages_24021 give_pages 3 24021 NULL
110781 +adis16400_show_serial_number_24037 adis16400_show_serial_number 3 24037 NULL
110782 +hmac_setkey_24043 hmac_setkey 3 24043 NULL
110783 +afs_cell_alloc_24052 afs_cell_alloc 2 24052 NULL
110784 +blkcipher_copy_iv_24075 blkcipher_copy_iv 3 24075 NULL
110785 +vb2_fop_read_24080 vb2_fop_read 3 24080 NULL
110786 +pipeline_post_proc_swi_read_24108 pipeline_post_proc_swi_read 3 24108 NULL
110787 +request_key_auth_read_24109 request_key_auth_read 3 24109 NULL
110788 +lov_brw_24122 lov_brw 4 24122 NULL
110789 +mpu401_read_24126 mpu401_read 3-0 24126 NULL
110790 +_picolcd_flash_write_24134 _picolcd_flash_write 4 24134 NULL
110791 +irnet_ctrl_write_24139 irnet_ctrl_write 3 24139 NULL
110792 +SyS_sethostname_24150 SyS_sethostname 2 24150 NULL
110793 +trim_bitmaps_24158 trim_bitmaps 3 24158 NULL
110794 +adu_read_24177 adu_read 3 24177 NULL
110795 +safe_prepare_write_buffer_24187 safe_prepare_write_buffer 3 24187 NULL
110796 +irq_remapping_setup_msi_irqs_24194 irq_remapping_setup_msi_irqs 2 24194 NULL
110797 +ieee80211_if_read_dot11MeshHWMPpreqMinInterval_24208 ieee80211_if_read_dot11MeshHWMPpreqMinInterval 3 24208 NULL
110798 +tcpprobe_sprint_24222 tcpprobe_sprint 0-2 24222 NULL
110799 +pcpu_embed_first_chunk_24224 pcpu_embed_first_chunk 3-2-1 24224 NULL nohasharray
110800 +mei_amthif_read_24224 mei_amthif_read 4 24224 &pcpu_embed_first_chunk_24224
110801 +pci_num_vf_24235 pci_num_vf 0 24235 NULL
110802 +sel_read_bool_24236 sel_read_bool 3 24236 NULL
110803 +em28xx_alloc_urbs_24260 em28xx_alloc_urbs 4-6 24260 NULL
110804 +calculate_sizes_24273 calculate_sizes 2 24273 NULL
110805 +thin_status_24278 thin_status 5 24278 NULL
110806 +msg_size_24288 msg_size 0 24288 NULL
110807 +gserial_connect_24302 gserial_connect 0 24302 NULL
110808 +btmrvl_pscmd_read_24308 btmrvl_pscmd_read 3 24308 NULL
110809 +ath6kl_add_bss_if_needed_24317 ath6kl_add_bss_if_needed 6 24317 NULL
110810 +si476x_radio_read_acf_blob_24336 si476x_radio_read_acf_blob 3 24336 NULL
110811 +C_SYSC_pwritev_24345 C_SYSC_pwritev 3 24345 NULL
110812 +kzalloc_node_24352 kzalloc_node 1 24352 NULL
110813 +qla2x00_handle_queue_full_24365 qla2x00_handle_queue_full 2 24365 NULL
110814 +cfi_read_pri_24366 cfi_read_pri 3 24366 NULL
110815 +btrfs_item_size_nr_24367 btrfs_item_size_nr 0 24367 NULL
110816 +igetword_24373 igetword 0 24373 NULL
110817 +max_io_len_24384 max_io_len 0-1 24384 NULL
110818 +mpt_alloc_res_24387 mpt_alloc_res 5 24387 NULL
110819 +osc_cur_grant_bytes_seq_write_24396 osc_cur_grant_bytes_seq_write 3 24396 NULL
110820 +getxattr_24398 getxattr 4 24398 NULL nohasharray
110821 +pvr2_v4l2_ioctl_24398 pvr2_v4l2_ioctl 2 24398 &getxattr_24398
110822 +blk_update_bidi_request_24415 blk_update_bidi_request 3-4 24415 NULL
110823 +nvme_trans_log_supp_pages_24418 nvme_trans_log_supp_pages 3 24418 NULL
110824 +b43_debugfs_read_24425 b43_debugfs_read 3 24425 NULL
110825 +xenbus_file_read_24427 xenbus_file_read 3 24427 NULL
110826 +ieee80211_rx_mgmt_beacon_24430 ieee80211_rx_mgmt_beacon 3 24430 NULL
110827 +copy_and_ioctl_24434 copy_and_ioctl 4 24434 NULL
110828 +ixgbe_alloc_q_vector_24439 ixgbe_alloc_q_vector 4-6 24439 NULL
110829 +smk_user_access_24440 smk_user_access 3 24440 NULL nohasharray
110830 +rtw_set_wps_assoc_resp_24440 rtw_set_wps_assoc_resp 3 24440 &smk_user_access_24440
110831 +evdev_do_ioctl_24459 evdev_do_ioctl 2 24459 NULL
110832 +lbs_highsnr_write_24460 lbs_highsnr_write 3 24460 NULL
110833 +skb_copy_and_csum_datagram_iovec_24466 skb_copy_and_csum_datagram_iovec 2 24466 NULL
110834 +dut_mode_read_24489 dut_mode_read 3 24489 NULL
110835 +read_file_spec_scan_ctl_24491 read_file_spec_scan_ctl 3 24491 NULL
110836 +pd_video_read_24510 pd_video_read 3 24510 NULL
110837 +request_key_with_auxdata_24515 request_key_with_auxdata 4 24515 NULL
110838 +xfs_buf_get_map_24522 xfs_buf_get_map 3 24522 NULL
110839 +do_mpage_readpage_24536 do_mpage_readpage 3 24536 NULL
110840 +write_cache_pages_24562 write_cache_pages 0 24562 NULL
110841 +SyS_pselect6_24582 SyS_pselect6 1 24582 NULL
110842 +udf_compute_nr_groups_24594 udf_compute_nr_groups 0 24594 NULL
110843 +sensor_hub_get_physical_device_count_24605 sensor_hub_get_physical_device_count 0 24605 NULL nohasharray
110844 +lov_alloc_memmd_24605 lov_alloc_memmd 2 24605 &sensor_hub_get_physical_device_count_24605
110845 +SyS_poll_24620 SyS_poll 2 24620 NULL
110846 +context_alloc_24645 context_alloc 3 24645 NULL
110847 +blk_rq_err_bytes_24650 blk_rq_err_bytes 0 24650 NULL
110848 +datafab_write_data_24696 datafab_write_data 4 24696 NULL
110849 +intelfbhw_get_p1p2_24703 intelfbhw_get_p1p2 2 24703 NULL
110850 +simple_attr_read_24738 simple_attr_read 3 24738 NULL
110851 +qla2x00_change_queue_depth_24742 qla2x00_change_queue_depth 2 24742 NULL
110852 +get_dma_residue_24749 get_dma_residue 0 24749 NULL
110853 +ocfs2_cow_file_pos_24751 ocfs2_cow_file_pos 3 24751 NULL
110854 +kgdb_hex2mem_24755 kgdb_hex2mem 3 24755 NULL
110855 +ocfs2_read_blocks_24777 ocfs2_read_blocks 0 24777 NULL
110856 +datablob_hmac_verify_24786 datablob_hmac_verify 4 24786 NULL
110857 +cache_read_24790 cache_read 3 24790 NULL
110858 +user_regset_copyout_24796 user_regset_copyout 7 24796 NULL
110859 +kvm_read_guest_virt_helper_24804 kvm_read_guest_virt_helper 3-1 24804 NULL
110860 +ath6kl_fwlog_mask_write_24810 ath6kl_fwlog_mask_write 3 24810 NULL
110861 +net2272_read_24825 net2272_read 0 24825 NULL
110862 +snd_als4k_gcr_read_24840 snd_als4k_gcr_read 0 24840 NULL
110863 +snd_pcm_lib_buffer_bytes_24865 snd_pcm_lib_buffer_bytes 0 24865 NULL
110864 +pnp_alloc_24869 pnp_alloc 1 24869 NULL nohasharray
110865 +l2cap_create_basic_pdu_24869 l2cap_create_basic_pdu 3 24869 &pnp_alloc_24869
110866 +queues_read_24877 queues_read 3 24877 NULL
110867 +__vxge_hw_vp_initialize_24885 __vxge_hw_vp_initialize 2 24885 NULL
110868 +codec_list_read_file_24910 codec_list_read_file 3 24910 NULL
110869 +v4l2_ctrl_new_24927 v4l2_ctrl_new 7 24927 NULL nohasharray
110870 +__btrfs_free_extent_24927 __btrfs_free_extent 7 24927 &v4l2_ctrl_new_24927
110871 +ocfs2_fiemap_24949 ocfs2_fiemap 4-3 24949 NULL
110872 +packet_sendmsg_24954 packet_sendmsg 4 24954 NULL
110873 +ll_layout_fetch_24961 ll_layout_fetch 0 24961 NULL
110874 +twl_i2c_write_u8_24976 twl_i2c_write_u8 3 24976 NULL
110875 +llc_ui_sendmsg_24987 llc_ui_sendmsg 4 24987 NULL
110876 +key_conf_hw_key_idx_read_25003 key_conf_hw_key_idx_read 3 25003 NULL
110877 +il_dbgfs_channels_read_25005 il_dbgfs_channels_read 3 25005 NULL
110878 +ni_660x_num_counters_25031 ni_660x_num_counters 0 25031 NULL
110879 +nfs_dns_resolve_name_25036 nfs_dns_resolve_name 3 25036 NULL
110880 +load_unaligned_zeropad_25050 load_unaligned_zeropad 0 25050 NULL
110881 +btrfs_stack_key_blockptr_25058 btrfs_stack_key_blockptr 0 25058 NULL
110882 +gs_buf_alloc_25067 gs_buf_alloc 2 25067 NULL
110883 +ll_track_pid_seq_write_25068 ll_track_pid_seq_write 3 25068 NULL
110884 +SYSC_listxattr_25072 SYSC_listxattr 3 25072 NULL
110885 +iwl_dbgfs_tx_flush_write_25091 iwl_dbgfs_tx_flush_write 3 25091 NULL
110886 +ima_appraise_measurement_25093 ima_appraise_measurement 6 25093 NULL
110887 +blkg_path_25099 blkg_path 3 25099 NULL
110888 +snd_rawmidi_kernel_write_25106 snd_rawmidi_kernel_write 3 25106 NULL
110889 +ipath_init_qp_table_25167 ipath_init_qp_table 2 25167 NULL
110890 +kvm_mmu_notifier_change_pte_25169 kvm_mmu_notifier_change_pte 3 25169 NULL
110891 +sctp_getsockopt_local_addrs_25178 sctp_getsockopt_local_addrs 2 25178 NULL
110892 +mon_stat_read_25238 mon_stat_read 3 25238 NULL
110893 +stripe_status_25259 stripe_status 5 25259 NULL
110894 +snd_pcm_start_25273 snd_pcm_start 0 25273 NULL
110895 +crypto_alloc_instance2_25277 crypto_alloc_instance2 3 25277 NULL
110896 +vfs_writev_25278 vfs_writev 3 25278 NULL
110897 +l2tp_session_create_25286 l2tp_session_create 1 25286 NULL
110898 +ath9k_debugfs_read_buf_25316 ath9k_debugfs_read_buf 3 25316 NULL
110899 +rng_buffer_size_25348 rng_buffer_size 0 25348 NULL
110900 +SYSC_kexec_load_25361 SYSC_kexec_load 2 25361 NULL
110901 +unix_mkname_25368 unix_mkname 0-2 25368 NULL
110902 +sel_read_mls_25369 sel_read_mls 3 25369 NULL
110903 +vsp1_entity_init_25407 vsp1_entity_init 3 25407 NULL
110904 +dai_list_read_file_25421 dai_list_read_file 3 25421 NULL
110905 +generic_file_buffered_write_25464 generic_file_buffered_write 4 25464 NULL
110906 +ipath_decode_err_25468 ipath_decode_err 3 25468 NULL
110907 +crypto_hash_digestsize_25469 crypto_hash_digestsize 0 25469 NULL
110908 +ivtv_buf_copy_from_user_25502 ivtv_buf_copy_from_user 4-0 25502 NULL
110909 +snd_pcm_plugin_build_25505 snd_pcm_plugin_build 5 25505 NULL
110910 +sb_permission_25523 sb_permission 0 25523 NULL
110911 +ext3_get_inode_loc_25542 ext3_get_inode_loc 0 25542 NULL
110912 +ieee80211_if_read_path_refresh_time_25545 ieee80211_if_read_path_refresh_time 3 25545 NULL
110913 +wimax_addr_scnprint_25548 wimax_addr_scnprint 2 25548 NULL
110914 +ht_print_chan_25556 ht_print_chan 3-4-0 25556 NULL
110915 +skb_tailroom_25567 skb_tailroom 0 25567 NULL
110916 +ping_recvmsg_25597 ping_recvmsg 4 25597 NULL
110917 +copy_user_generic_25611 copy_user_generic 0 25611 NULL
110918 +proc_coredump_filter_write_25625 proc_coredump_filter_write 3 25625 NULL
110919 +befs_utf2nls_25628 befs_utf2nls 3 25628 NULL nohasharray
110920 +__get_user_pages_25628 __get_user_pages 0 25628 &befs_utf2nls_25628
110921 +__direct_map_25647 __direct_map 6-5 25647 NULL
110922 +aircable_prepare_write_buffer_25669 aircable_prepare_write_buffer 3 25669 NULL
110923 +lpfc_idiag_cmd_get_25672 lpfc_idiag_cmd_get 2 25672 NULL
110924 +sta_inactive_ms_read_25690 sta_inactive_ms_read 3 25690 NULL
110925 +rx_filter_mc_filter_read_25712 rx_filter_mc_filter_read 3 25712 NULL
110926 +ibmasm_new_command_25714 ibmasm_new_command 2 25714 NULL
110927 +__alloc_bootmem_low_node_25726 __alloc_bootmem_low_node 2 25726 NULL nohasharray
110928 +sel_write_context_25726 sel_write_context 3 25726 &__alloc_bootmem_low_node_25726
110929 +cxgbi_device_portmap_create_25747 cxgbi_device_portmap_create 3 25747 NULL
110930 +event_rx_pool_read_25792 event_rx_pool_read 3 25792 NULL
110931 +sg_read_25799 sg_read 3 25799 NULL
110932 +system_enable_read_25815 system_enable_read 3 25815 NULL
110933 +realloc_buffer_25816 realloc_buffer 2 25816 NULL
110934 +pwr_missing_bcns_read_25824 pwr_missing_bcns_read 3 25824 NULL
110935 +parport_read_25855 parport_read 0 25855 NULL
110936 +xfs_dir2_sf_hdr_size_25858 xfs_dir2_sf_hdr_size 0 25858 NULL
110937 +key_attr_size_25865 key_attr_size 0 25865 NULL
110938 +ath6kl_regread_read_25884 ath6kl_regread_read 3 25884 NULL
110939 +run_delalloc_nocow_25896 run_delalloc_nocow 3-4 25896 NULL
110940 +sisusbcon_scroll_area_25899 sisusbcon_scroll_area 4-3 25899 NULL
110941 +lpfc_change_queue_depth_25905 lpfc_change_queue_depth 2 25905 NULL
110942 +nvme_trans_mode_page_create_25908 nvme_trans_mode_page_create 7-4 25908 NULL
110943 +do_jffs2_setxattr_25910 do_jffs2_setxattr 5 25910 NULL
110944 +rcname_read_25919 rcname_read 3 25919 NULL
110945 +snd_es1938_capture_copy_25930 snd_es1938_capture_copy 5 25930 NULL
110946 +key_flags_read_25931 key_flags_read 3 25931 NULL
110947 +copy_play_buf_25932 copy_play_buf 3 25932 NULL
110948 +flush_25957 flush 2 25957 NULL
110949 +udp_setsockopt_25985 udp_setsockopt 5 25985 NULL
110950 +lustre_msg_buflen_v2_25997 lustre_msg_buflen_v2 0 25997 NULL
110951 +SyS_process_vm_readv_26019 SyS_process_vm_readv 3-5 26019 NULL
110952 +xfs_xattr_acl_set_26028 xfs_xattr_acl_set 4 26028 NULL
110953 +mptscsih_change_queue_depth_26036 mptscsih_change_queue_depth 2 26036 NULL
110954 +selinux_inode_post_setxattr_26037 selinux_inode_post_setxattr 4 26037 NULL
110955 +tun_do_read_26047 tun_do_read 5 26047 NULL
110956 +keyctl_update_key_26061 keyctl_update_key 3 26061 NULL
110957 +rx_rx_wa_density_dropped_frame_read_26095 rx_rx_wa_density_dropped_frame_read 3 26095 NULL
110958 +read_sb_page_26119 read_sb_page 5 26119 NULL
110959 +ath9k_hw_name_26146 ath9k_hw_name 3 26146 NULL
110960 +copy_oldmem_page_26164 copy_oldmem_page 3 26164 NULL
110961 +gfs2_xattr_acl_get_26166 gfs2_xattr_acl_get 0 26166 NULL nohasharray
110962 +ath6kl_roam_table_read_26166 ath6kl_roam_table_read 3 26166 &gfs2_xattr_acl_get_26166
110963 +disk_devt_26180 disk_devt 0 26180 NULL
110964 +cgroup_setxattr_26188 cgroup_setxattr 4 26188 NULL
110965 +ieee80211_if_fmt_dot11MeshTTL_26198 ieee80211_if_fmt_dot11MeshTTL 3 26198 NULL
110966 +xfs_idata_realloc_26199 xfs_idata_realloc 2 26199 NULL
110967 +mce_write_26201 mce_write 3 26201 NULL
110968 +mwifiex_regrdwr_write_26225 mwifiex_regrdwr_write 3 26225 NULL
110969 +_scsih_change_queue_depth_26230 _scsih_change_queue_depth 2 26230 NULL
110970 +rxrpc_recvmsg_26233 rxrpc_recvmsg 4 26233 NULL
110971 +bio_split_26235 bio_split 2 26235 NULL
110972 +crypto_ctxsize_26278 crypto_ctxsize 0 26278 NULL
110973 +apei_resources_request_26279 apei_resources_request 0 26279 NULL
110974 +wacom_set_device_mode_26280 wacom_set_device_mode 3 26280 NULL
110975 +snd_pcm_plug_client_channels_buf_26309 snd_pcm_plug_client_channels_buf 0-3 26309 NULL nohasharray
110976 +pax_get_random_long_26309 pax_get_random_long 0 26309 &snd_pcm_plug_client_channels_buf_26309
110977 +pwr_wake_on_host_read_26321 pwr_wake_on_host_read 3 26321 NULL
110978 +check_can_nocow_26336 check_can_nocow 2 26336 NULL
110979 +snd_vx_check_reg_bit_26344 snd_vx_check_reg_bit 0 26344 NULL
110980 +ocfs2_duplicate_clusters_by_page_26357 ocfs2_duplicate_clusters_by_page 6-3 26357 NULL
110981 +cifs_readdata_alloc_26360 cifs_readdata_alloc 1 26360 NULL
110982 +invalidate_inode_pages2_range_26403 invalidate_inode_pages2_range 0 26403 NULL
110983 +ntty_write_26404 ntty_write 3 26404 NULL
110984 +firmware_store_26408 firmware_store 4 26408 NULL
110985 +pagemap_read_26441 pagemap_read 3 26441 NULL
110986 +tower_read_26461 tower_read 3 26461 NULL nohasharray
110987 +enc_pools_add_pages_26461 enc_pools_add_pages 1 26461 &tower_read_26461
110988 +ib_alloc_device_26483 ib_alloc_device 1 26483 NULL
110989 +ulong_write_file_26485 ulong_write_file 3 26485 NULL
110990 +dvb_ca_en50221_io_ioctl_26490 dvb_ca_en50221_io_ioctl 2 26490 NULL
110991 +read_vmcore_26501 read_vmcore 3 26501 NULL
110992 +uhid_char_write_26502 uhid_char_write 3 26502 NULL
110993 +vfio_pci_set_msi_trigger_26507 vfio_pci_set_msi_trigger 4-3 26507 NULL
110994 +iwl_dbgfs_rf_reset_read_26512 iwl_dbgfs_rf_reset_read 3 26512 NULL
110995 +SyS_rt_sigpending_26538 SyS_rt_sigpending 2 26538 NULL
110996 +__vhost_add_used_n_26554 __vhost_add_used_n 3 26554 NULL
110997 +dio_new_bio_26562 dio_new_bio 0 26562 NULL
110998 +rts51x_read_mem_26577 rts51x_read_mem 4 26577 NULL
110999 +pwr_fix_tsf_ps_read_26627 pwr_fix_tsf_ps_read 3 26627 NULL
111000 +irq_alloc_generic_chip_26650 irq_alloc_generic_chip 2 26650 NULL nohasharray
111001 +inb_p_26650 inb_p 0 26650 &irq_alloc_generic_chip_26650
111002 +nouveau_volt_create__26654 nouveau_volt_create_ 4 26654 NULL
111003 +cipso_v4_map_cat_rbm_hton_26680 cipso_v4_map_cat_rbm_hton 0 26680 NULL
111004 +nouveau_namedb_create__26732 nouveau_namedb_create_ 7 26732 NULL
111005 +pipeline_tcp_rx_stat_fifo_int_read_26745 pipeline_tcp_rx_stat_fifo_int_read 3 26745 NULL
111006 +bos_desc_26752 bos_desc 0 26752 NULL
111007 +snd_hda_get_raw_connections_26762 snd_hda_get_raw_connections 0 26762 NULL
111008 +dma_map_single_attrs_26779 dma_map_single_attrs 0 26779 NULL
111009 +qlcnic_alloc_sds_rings_26795 qlcnic_alloc_sds_rings 2 26795 NULL
111010 +cipso_v4_genopt_26812 cipso_v4_genopt 0 26812 NULL
111011 +iwl_trans_read_mem32_26825 iwl_trans_read_mem32 0 26825 NULL
111012 +smk_write_load_26829 smk_write_load 3 26829 NULL
111013 +scnprint_id_26842 scnprint_id 3-0 26842 NULL
111014 +ecryptfs_miscdev_write_26847 ecryptfs_miscdev_write 3 26847 NULL
111015 +tipc_conn_sendmsg_26867 tipc_conn_sendmsg 5 26867 NULL
111016 +ath6kl_create_qos_write_26879 ath6kl_create_qos_write 3 26879 NULL
111017 +svc_print_xprts_26881 svc_print_xprts 0 26881 NULL
111018 +cfg80211_process_auth_26916 cfg80211_process_auth 3 26916 NULL
111019 +x25_asy_change_mtu_26928 x25_asy_change_mtu 2 26928 NULL
111020 +scsi_tgt_copy_sense_26933 scsi_tgt_copy_sense 3 26933 NULL
111021 +sctp_setsockopt_adaptation_layer_26935 sctp_setsockopt_adaptation_layer 3 26935 NULL nohasharray
111022 +pwr_ps_enter_read_26935 pwr_ps_enter_read 3 26935 &sctp_setsockopt_adaptation_layer_26935
111023 +hecubafb_write_26942 hecubafb_write 3 26942 NULL
111024 +do_trimming_26952 do_trimming 3 26952 NULL nohasharray
111025 +extract_entropy_user_26952 extract_entropy_user 3 26952 &do_trimming_26952
111026 +do_direct_IO_26979 do_direct_IO 0 26979 NULL
111027 +__videobuf_alloc_vb_27062 __videobuf_alloc_vb 1 27062 NULL
111028 +ext4_convert_unwritten_extents_27064 ext4_convert_unwritten_extents 4-3-0 27064 NULL
111029 +snd_pcm_lib_period_bytes_27071 snd_pcm_lib_period_bytes 0 27071 NULL
111030 +paravirt_read_msr_27077 paravirt_read_msr 0 27077 NULL
111031 +alloc_fdmem_27083 alloc_fdmem 1 27083 NULL
111032 +btmrvl_hscmd_write_27089 btmrvl_hscmd_write 3 27089 NULL nohasharray
111033 +ath9k_hw_4k_dump_eeprom_27089 ath9k_hw_4k_dump_eeprom 5-4 27089 &btmrvl_hscmd_write_27089
111034 +__devcgroup_inode_permission_27108 __devcgroup_inode_permission 0 27108 NULL
111035 +get_kernel_page_27133 get_kernel_page 0 27133 NULL
111036 +drbd_get_capacity_27141 drbd_get_capacity 0 27141 NULL
111037 +pms_capture_27142 pms_capture 4 27142 NULL
111038 +btmrvl_hscfgcmd_write_27143 btmrvl_hscfgcmd_write 3 27143 NULL
111039 +snd_compr_calc_avail_27165 snd_compr_calc_avail 0 27165 NULL
111040 +ieee80211_if_read_rc_rateidx_mask_5ghz_27183 ieee80211_if_read_rc_rateidx_mask_5ghz 3 27183 NULL
111041 +__sg_alloc_table_27198 __sg_alloc_table 0 27198 NULL
111042 +write_kmem_27225 write_kmem 3 27225 NULL
111043 +dbAllocAG_27228 dbAllocAG 0 27228 NULL
111044 +rxrpc_request_key_27235 rxrpc_request_key 3 27235 NULL
111045 +ll_track_gid_seq_write_27267 ll_track_gid_seq_write 3 27267 NULL
111046 +comedi_alloc_devpriv_27272 comedi_alloc_devpriv 2 27272 NULL
111047 +copy_from_buf_27308 copy_from_buf 4-2 27308 NULL
111048 +virtqueue_add_inbuf_27312 virtqueue_add_inbuf 3 27312 NULL
111049 +snd_pcm_oss_write2_27332 snd_pcm_oss_write2 3-0 27332 NULL
111050 +afs_cell_create_27346 afs_cell_create 2 27346 NULL
111051 +iwl_dbgfs_csr_write_27363 iwl_dbgfs_csr_write 3 27363 NULL
111052 +pcbit_stat_27364 pcbit_stat 2 27364 NULL
111053 +seq_read_27411 seq_read 3 27411 NULL
111054 +ib_dma_map_sg_27413 ib_dma_map_sg 0 27413 NULL
111055 +ieee80211_if_read_smps_27416 ieee80211_if_read_smps 3 27416 NULL
111056 +ocfs2_refcount_cal_cow_clusters_27422 ocfs2_refcount_cal_cow_clusters 0-3-4 27422 NULL
111057 +cypress_write_27423 cypress_write 4 27423 NULL
111058 +sddr09_read_data_27447 sddr09_read_data 3 27447 NULL
111059 +v4l2_ctrl_new_std_menu_items_27487 v4l2_ctrl_new_std_menu_items 4 27487 NULL
111060 +hcd_buffer_alloc_27495 hcd_buffer_alloc 2 27495 NULL
111061 +ip_set_get_h32_27498 ip_set_get_h32 0 27498 NULL
111062 +btrfs_get_64_27499 btrfs_get_64 0 27499 NULL
111063 +garmin_read_process_27509 garmin_read_process 3 27509 NULL
111064 +oti_alloc_cookies_27510 oti_alloc_cookies 2 27510 NULL
111065 +ib_copy_to_udata_27525 ib_copy_to_udata 3 27525 NULL
111066 +snd_sonicvibes_getdmaa_27552 snd_sonicvibes_getdmaa 0 27552 NULL
111067 +SyS_fgetxattr_27571 SyS_fgetxattr 4 27571 NULL
111068 +sco_sock_recvmsg_27572 sco_sock_recvmsg 4 27572 NULL
111069 +libipw_alloc_txb_27579 libipw_alloc_txb 1 27579 NULL
111070 +ocfs2_xattr_ibody_get_27642 ocfs2_xattr_ibody_get 0 27642 NULL nohasharray
111071 +nl80211_send_connect_result_27642 nl80211_send_connect_result 5-7 27642 &ocfs2_xattr_ibody_get_27642 nohasharray
111072 +read_flush_procfs_27642 read_flush_procfs 3 27642 &nl80211_send_connect_result_27642 nohasharray
111073 +ocfs2_direct_IO_27642 ocfs2_direct_IO 4 27642 &read_flush_procfs_27642
111074 +add_new_gdb_27643 add_new_gdb 3 27643 NULL
111075 +btrfs_fallocate_27647 btrfs_fallocate 3-4 27647 NULL
111076 +qnx6_readpages_27657 qnx6_readpages 4 27657 NULL
111077 +cdrom_read_cdda_old_27664 cdrom_read_cdda_old 4 27664 NULL
111078 +ocfs2_extend_dir_27695 ocfs2_extend_dir 4 27695 NULL
111079 +fs_path_add_from_extent_buffer_27702 fs_path_add_from_extent_buffer 4 27702 NULL
111080 +evm_write_key_27715 evm_write_key 3 27715 NULL
111081 +ieee80211_if_fmt_dot11MeshGateAnnouncementProtocol_27722 ieee80211_if_fmt_dot11MeshGateAnnouncementProtocol 3 27722 NULL
111082 +xfs_dir2_block_sfsize_27727 xfs_dir2_block_sfsize 0 27727 NULL
111083 +SyS_setsockopt_27759 SyS_setsockopt 5 27759 NULL
111084 +__lov_setstripe_27782 __lov_setstripe 2 27782 NULL
111085 +twl4030_set_gpio_dataout_27792 twl4030_set_gpio_dataout 1 27792 NULL
111086 +SyS_readv_27804 SyS_readv 3 27804 NULL
111087 +mpihelp_mul_27805 mpihelp_mul 5-3 27805 NULL
111088 +fwtty_buffer_rx_27821 fwtty_buffer_rx 3 27821 NULL
111089 +hpt374_read_freq_27828 hpt374_read_freq 0 27828 NULL
111090 +init_header_complete_27833 init_header_complete 0 27833 NULL
111091 +read_profile_27859 read_profile 3 27859 NULL
111092 +sky2_pci_read16_27863 sky2_pci_read16 0 27863 NULL
111093 +ieee80211_if_read_dot11MeshHWMProotInterval_27873 ieee80211_if_read_dot11MeshHWMProotInterval 3 27873 NULL
111094 +unix_seqpacket_sendmsg_27893 unix_seqpacket_sendmsg 4 27893 NULL
111095 +check_mapped_name_27943 check_mapped_name 3 27943 NULL
111096 +tracing_clock_write_27961 tracing_clock_write 3 27961 NULL
111097 +tipc_media_addr_printf_27971 tipc_media_addr_printf 2 27971 NULL
111098 +device_register_27972 device_register 0 27972 NULL nohasharray
111099 +mic_rx_pkts_read_27972 mic_rx_pkts_read 3 27972 &device_register_27972
111100 +pci_enable_device_flags_27977 pci_enable_device_flags 0 27977 NULL
111101 +f2fs_bio_alloc_27983 f2fs_bio_alloc 2 27983 NULL
111102 +edt_ft5x06_debugfs_raw_data_read_28002 edt_ft5x06_debugfs_raw_data_read 3 28002 NULL
111103 +snd_rawmidi_write_28008 snd_rawmidi_write 3 28008 NULL
111104 +powercap_register_zone_28028 powercap_register_zone 6 28028 NULL
111105 +sctp_setsockopt_maxburst_28041 sctp_setsockopt_maxburst 3 28041 NULL
111106 +rts51x_xd_rw_28046 rts51x_xd_rw 3-4 28046 NULL
111107 +cx231xx_init_vbi_isoc_28053 cx231xx_init_vbi_isoc 3-2-4 28053 NULL
111108 +pool_status_28055 pool_status 5 28055 NULL
111109 +init_rs_non_canonical_28059 init_rs_non_canonical 1 28059 NULL
111110 +lpfc_idiag_mbxacc_read_28061 lpfc_idiag_mbxacc_read 3 28061 NULL
111111 +tx_frag_bad_mblk_num_read_28064 tx_frag_bad_mblk_num_read 3 28064 NULL
111112 +mmc_test_alloc_mem_28102 mmc_test_alloc_mem 3-2 28102 NULL
111113 +rx_defrag_need_defrag_read_28117 rx_defrag_need_defrag_read 3 28117 NULL
111114 +vgacon_adjust_height_28124 vgacon_adjust_height 2 28124 NULL
111115 +video_read_28148 video_read 3 28148 NULL
111116 +snd_midi_channel_alloc_set_28153 snd_midi_channel_alloc_set 1 28153 NULL
111117 +stats_dot11FCSErrorCount_read_28154 stats_dot11FCSErrorCount_read 3 28154 NULL
111118 +vread_28173 vread 0-3 28173 NULL
111119 +macvtap_get_user_28185 macvtap_get_user 4 28185 NULL
111120 +counter_free_res_28187 counter_free_res 5 28187 NULL
111121 +read_disk_sb_28188 read_disk_sb 2 28188 NULL
111122 +nouveau_mxm_create__28200 nouveau_mxm_create_ 4 28200 NULL
111123 +__qp_memcpy_from_queue_28220 __qp_memcpy_from_queue 3-4 28220 NULL
111124 +line6_alloc_sysex_buffer_28225 line6_alloc_sysex_buffer 4 28225 NULL
111125 +amd_nb_num_28228 amd_nb_num 0 28228 NULL
111126 +fuse_direct_IO_28275 fuse_direct_IO 4 28275 NULL
111127 +usemap_size_28281 usemap_size 0 28281 NULL
111128 +inline_xattr_size_28285 inline_xattr_size 0 28285 NULL
111129 +dma_map_sg_attrs_28289 dma_map_sg_attrs 0 28289 NULL
111130 +SyS_ppoll_28290 SyS_ppoll 2 28290 NULL
111131 +kstrtos16_from_user_28300 kstrtos16_from_user 2 28300 NULL
111132 +nouveau_compat_ioctl_28305 nouveau_compat_ioctl 2 28305 NULL
111133 +snd_pcm_oss_read_28317 snd_pcm_oss_read 3 28317 NULL
111134 +bm_entry_write_28338 bm_entry_write 3 28338 NULL
111135 +tcp_copy_to_iovec_28344 tcp_copy_to_iovec 3 28344 NULL
111136 +snapshot_write_28351 snapshot_write 3 28351 NULL
111137 +xfs_iomap_write_unwritten_28365 xfs_iomap_write_unwritten 3-2 28365 NULL
111138 +batadv_handle_tt_response_28370 batadv_handle_tt_response 4 28370 NULL
111139 +dlmfs_file_read_28385 dlmfs_file_read 3 28385 NULL
111140 +tx_frag_cache_miss_read_28394 tx_frag_cache_miss_read 3 28394 NULL
111141 +bypass_pwup_write_28416 bypass_pwup_write 3 28416 NULL
111142 +subdev_ioctl_28417 subdev_ioctl 2 28417 NULL
111143 +ksocknal_alloc_tx_28426 ksocknal_alloc_tx 2 28426 NULL
111144 +mpage_readpages_28436 mpage_readpages 3 28436 NULL
111145 +snd_emu10k1_efx_read_28452 snd_emu10k1_efx_read 2 28452 NULL
111146 +key_mic_failures_read_28457 key_mic_failures_read 3 28457 NULL
111147 +alloc_irq_cpu_rmap_28459 alloc_irq_cpu_rmap 1 28459 NULL
111148 +ps_poll_upsd_utilization_read_28519 ps_poll_upsd_utilization_read 3 28519 NULL
111149 +i2400m_tx_stats_read_28527 i2400m_tx_stats_read 3 28527 NULL
111150 +sel_read_policycap_28544 sel_read_policycap 3 28544 NULL
111151 +mptctl_getiocinfo_28545 mptctl_getiocinfo 2 28545 NULL nohasharray
111152 +run_delalloc_range_28545 run_delalloc_range 3-4 28545 &mptctl_getiocinfo_28545 nohasharray
111153 +aio_read_events_28545 aio_read_events 3 28545 &run_delalloc_range_28545
111154 +sysfs_create_bin_file_28551 sysfs_create_bin_file 0 28551 NULL
111155 +b43legacy_debugfs_write_28556 b43legacy_debugfs_write 3 28556 NULL
111156 +asymmetric_verify_28567 asymmetric_verify 3 28567 NULL
111157 +oxygen_read32_28582 oxygen_read32 0 28582 NULL
111158 +extract_entropy_28604 extract_entropy 5-3 28604 NULL
111159 +kfifo_unused_28612 kfifo_unused 0 28612 NULL
111160 +snd_nm256_capture_copy_28622 snd_nm256_capture_copy 5-3 28622 NULL
111161 +setup_usemap_28636 setup_usemap 3-4 28636 NULL
111162 +qib_handle_6120_hwerrors_28642 qib_handle_6120_hwerrors 3 28642 NULL
111163 +p9_fcall_alloc_28652 p9_fcall_alloc 1 28652 NULL
111164 +read_nic_io_byte_28654 read_nic_io_byte 0 28654 NULL
111165 +blk_queue_resize_tags_28670 blk_queue_resize_tags 2 28670 NULL
111166 +SyS_setgroups16_28686 SyS_setgroups16 1 28686 NULL
111167 +kvm_mmu_get_page_28692 kvm_mmu_get_page 2 28692 NULL
111168 +drm_plane_init_28731 drm_plane_init 6 28731 NULL
111169 +spi_execute_28736 spi_execute 5 28736 NULL
111170 +snd_pcm_aio_write_28738 snd_pcm_aio_write 3 28738 NULL
111171 +read_file_btcoex_28743 read_file_btcoex 3 28743 NULL
111172 +max_hw_blocks_28748 max_hw_blocks 0 28748 NULL
111173 +rpc_pipe_generic_upcall_28766 rpc_pipe_generic_upcall 4 28766 NULL
111174 +ath6kl_get_num_reg_28780 ath6kl_get_num_reg 0 28780 NULL
111175 +sel_write_member_28800 sel_write_member 3 28800 NULL
111176 +cgroup_file_read_28804 cgroup_file_read 3 28804 NULL
111177 +iwl_dbgfs_rxon_filter_flags_read_28832 iwl_dbgfs_rxon_filter_flags_read 3 28832 NULL
111178 +vp_request_msix_vectors_28849 vp_request_msix_vectors 2 28849 NULL
111179 +ipv6_renew_options_28867 ipv6_renew_options 5 28867 NULL
111180 +max_io_len_target_boundary_28879 max_io_len_target_boundary 0-1 28879 NULL
111181 +packet_sendmsg_spkt_28885 packet_sendmsg_spkt 4 28885 NULL
111182 +da9055_group_write_28904 da9055_group_write 2-3 28904 NULL
111183 +ps_upsd_timeouts_read_28924 ps_upsd_timeouts_read 3 28924 NULL
111184 +iwl_dbgfs_sleep_level_override_write_28925 iwl_dbgfs_sleep_level_override_write 3 28925 NULL
111185 +push_rx_28939 push_rx 3 28939 NULL
111186 +btrfs_trim_block_group_28963 btrfs_trim_block_group 3-4 28963 NULL
111187 +alloc_sched_domains_28972 alloc_sched_domains 1 28972 NULL
111188 +hash_net6_expire_28979 hash_net6_expire 4 28979 NULL
111189 +hci_sock_setsockopt_28993 hci_sock_setsockopt 5 28993 NULL
111190 +bin_uuid_28999 bin_uuid 3 28999 NULL
111191 +fd_execute_rw_29004 fd_execute_rw 3 29004 NULL
111192 +ieee80211_if_read_ht_opmode_29044 ieee80211_if_read_ht_opmode 3 29044 NULL
111193 +rxrpc_sendmsg_29049 rxrpc_sendmsg 4 29049 NULL
111194 +btrfs_root_bytenr_29058 btrfs_root_bytenr 0 29058 NULL
111195 +iso_packets_buffer_init_29061 iso_packets_buffer_init 3-4 29061 NULL
111196 +roundup_64_29066 roundup_64 2-0-1 29066 NULL
111197 +lpfc_idiag_extacc_drivr_get_29067 lpfc_idiag_extacc_drivr_get 0-3 29067 NULL
111198 +sctp_getsockopt_assoc_stats_29074 sctp_getsockopt_assoc_stats 2 29074 NULL
111199 +iwl_dbgfs_log_event_write_29088 iwl_dbgfs_log_event_write 3 29088 NULL
111200 +i915_error_object_create_sized_29091 i915_error_object_create_sized 3 29091 NULL
111201 +isdn_ppp_write_29109 isdn_ppp_write 4 29109 NULL
111202 +snprintf_29125 snprintf 0 29125 NULL
111203 +iov_shorten_29130 iov_shorten 0 29130 NULL
111204 +proc_scsi_write_29142 proc_scsi_write 3 29142 NULL
111205 +kvm_mmu_notifier_clear_flush_young_29154 kvm_mmu_notifier_clear_flush_young 3 29154 NULL
111206 +drm_property_create_enum_29201 drm_property_create_enum 5 29201 NULL
111207 +wusb_prf_256_29203 wusb_prf_256 7 29203 NULL
111208 +iwl_dbgfs_temperature_read_29224 iwl_dbgfs_temperature_read 3 29224 NULL
111209 +nvme_trans_copy_from_user_29227 nvme_trans_copy_from_user 3 29227 NULL
111210 +irq_domain_add_linear_29236 irq_domain_add_linear 2 29236 NULL
111211 +evdev_handle_get_val_29242 evdev_handle_get_val 5-6 29242 NULL
111212 +security_context_to_sid_core_29248 security_context_to_sid_core 2 29248 NULL
111213 +prism2_set_genericelement_29277 prism2_set_genericelement 3 29277 NULL
111214 +ext4_fiemap_29296 ext4_fiemap 4 29296 NULL
111215 +sn9c102_read_29305 sn9c102_read 3 29305 NULL
111216 +__fuse_get_req_29315 __fuse_get_req 2 29315 NULL
111217 +lprocfs_write_helper_29323 lprocfs_write_helper 2 29323 NULL
111218 +kvm_handle_hva_29326 kvm_handle_hva 2 29326 NULL
111219 +tun_put_user_29337 tun_put_user 5 29337 NULL
111220 +__alloc_ei_netdev_29338 __alloc_ei_netdev 1 29338 NULL
111221 +l2cap_sock_setsockopt_old_29346 l2cap_sock_setsockopt_old 4 29346 NULL
111222 +mwifiex_cfg80211_mgmt_tx_29387 mwifiex_cfg80211_mgmt_tx 7 29387 NULL
111223 +read_file_tx99_power_29405 read_file_tx99_power 3 29405 NULL
111224 +mempool_create_29437 mempool_create 1 29437 NULL
111225 +crypto_ahash_alignmask_29445 crypto_ahash_alignmask 0 29445 NULL
111226 +p9_client_prepare_req_29448 p9_client_prepare_req 3 29448 NULL
111227 +validate_scan_freqs_29462 validate_scan_freqs 0 29462 NULL
111228 +SyS_flistxattr_29474 SyS_flistxattr 3 29474 NULL
111229 +do_register_entry_29478 do_register_entry 4 29478 NULL
111230 +simple_strtoul_29480 simple_strtoul 0 29480 NULL
111231 +btmrvl_pscmd_write_29504 btmrvl_pscmd_write 3 29504 NULL
111232 +btrfs_file_extent_disk_bytenr_29505 btrfs_file_extent_disk_bytenr 0 29505 NULL
111233 +write_file_regidx_29517 write_file_regidx 3 29517 NULL
111234 +atk_debugfs_ggrp_read_29522 atk_debugfs_ggrp_read 3 29522 NULL
111235 +ftrace_write_29551 ftrace_write 3 29551 NULL
111236 +idetape_queue_rw_tail_29562 idetape_queue_rw_tail 3 29562 NULL
111237 +leaf_dealloc_29566 leaf_dealloc 3 29566 NULL
111238 +kvm_read_guest_virt_system_29569 kvm_read_guest_virt_system 4-2 29569 NULL
111239 +lbs_lowsnr_read_29571 lbs_lowsnr_read 3 29571 NULL
111240 +iwl_dbgfs_missed_beacon_write_29586 iwl_dbgfs_missed_beacon_write 3 29586 NULL
111241 +pvr2_hdw_report_unlocked_29589 pvr2_hdw_report_unlocked 4-0 29589 NULL
111242 +dio_set_defer_completion_29599 dio_set_defer_completion 0 29599 NULL
111243 +slots_per_page_29601 slots_per_page 0 29601 NULL
111244 +osc_cached_mb_seq_write_29610 osc_cached_mb_seq_write 3 29610 NULL
111245 +nla_get_u16_29624 nla_get_u16 0 29624 NULL
111246 +tx_frag_cache_hit_read_29639 tx_frag_cache_hit_read 3 29639 NULL
111247 +sctp_make_abort_user_29654 sctp_make_abort_user 3 29654 NULL
111248 +sisusb_write_mem_bulk_29678 sisusb_write_mem_bulk 4 29678 NULL
111249 +lustre_posix_acl_xattr_2ext_29693 lustre_posix_acl_xattr_2ext 2 29693 NULL
111250 +posix_acl_from_xattr_29708 posix_acl_from_xattr 3 29708 NULL
111251 +probes_write_29711 probes_write 3 29711 NULL
111252 +read_cis_cache_29735 read_cis_cache 4 29735 NULL
111253 +xfs_new_eof_29737 xfs_new_eof 2 29737 NULL
111254 +std_nic_write_29752 std_nic_write 3 29752 NULL
111255 +dbAlloc_29794 dbAlloc 0 29794 NULL
111256 +tcp_sendpage_29829 tcp_sendpage 4 29829 NULL
111257 +__probe_kernel_write_29842 __probe_kernel_write 3 29842 NULL
111258 +kvm_read_hva_atomic_29848 kvm_read_hva_atomic 3 29848 NULL
111259 +count_partial_29850 count_partial 0 29850 NULL
111260 +write_file_bool_bmps_29870 write_file_bool_bmps 3 29870 NULL
111261 +ipv6_setsockopt_29871 ipv6_setsockopt 5 29871 NULL
111262 +scsi_end_request_29876 scsi_end_request 3 29876 NULL
111263 +crypto_aead_alignmask_29885 crypto_aead_alignmask 0 29885 NULL
111264 +lov_ost_pool_extend_29914 lov_ost_pool_extend 2 29914 NULL
111265 +write_file_queue_29922 write_file_queue 3 29922 NULL
111266 +ext4_xattr_set_acl_29930 ext4_xattr_set_acl 4 29930 NULL
111267 +__btrfs_getxattr_29947 __btrfs_getxattr 0 29947 NULL nohasharray
111268 +ipv6_recv_error_29947 ipv6_recv_error 3 29947 &__btrfs_getxattr_29947
111269 +dev_mem_write_30028 dev_mem_write 3 30028 NULL
111270 +alloc_netdev_mqs_30030 alloc_netdev_mqs 1 30030 NULL
111271 +scsi_vpd_inquiry_30040 scsi_vpd_inquiry 4 30040 NULL
111272 +drp_wmove_30043 drp_wmove 4 30043 NULL
111273 +__pci_request_selected_regions_30058 __pci_request_selected_regions 0 30058 NULL
111274 +cxgbi_ddp_reserve_30091 cxgbi_ddp_reserve 4 30091 NULL
111275 +snd_midi_channel_init_set_30092 snd_midi_channel_init_set 1 30092 NULL
111276 +rx_filter_data_filter_read_30098 rx_filter_data_filter_read 3 30098 NULL
111277 +defragment_dma_buffer_30113 defragment_dma_buffer 0 30113 NULL
111278 +spi_async_locked_30117 spi_async_locked 0 30117 NULL
111279 +recv_stream_30138 recv_stream 4 30138 NULL
111280 +u_memcpya_30139 u_memcpya 3-2 30139 NULL
111281 +elfcorehdr_read_30159 elfcorehdr_read 2 30159 NULL
111282 +alloc_switch_ctx_30165 alloc_switch_ctx 2 30165 NULL
111283 +expand_inode_data_30169 expand_inode_data 2-3 30169 NULL
111284 +mempool_create_page_pool_30189 mempool_create_page_pool 1 30189 NULL
111285 +drm_property_create_bitmask_30195 drm_property_create_bitmask 5 30195 NULL
111286 +usblp_ioctl_30203 usblp_ioctl 2 30203 NULL
111287 +read_4k_modal_eeprom_30212 read_4k_modal_eeprom 3 30212 NULL
111288 +SyS_semop_30227 SyS_semop 3 30227 NULL
111289 +bitmap_file_set_bit_30228 bitmap_file_set_bit 2 30228 NULL
111290 +ocfs2_calc_bg_discontig_credits_30230 ocfs2_calc_bg_discontig_credits 0 30230 NULL
111291 +rawv6_recvmsg_30265 rawv6_recvmsg 4 30265 NULL
111292 +hfsplus_trusted_setxattr_30270 hfsplus_trusted_setxattr 4 30270 NULL
111293 +isr_pci_pm_read_30271 isr_pci_pm_read 3 30271 NULL
111294 +compat_readv_30273 compat_readv 3 30273 NULL
111295 +skcipher_sendmsg_30290 skcipher_sendmsg 4 30290 NULL
111296 +pipeline_sec_frag_swi_read_30294 pipeline_sec_frag_swi_read 3 30294 NULL
111297 +tcp_sendmsg_30296 tcp_sendmsg 4 30296 NULL
111298 +osc_contention_seconds_seq_write_30305 osc_contention_seconds_seq_write 3 30305 NULL
111299 +ext4_acl_from_disk_30320 ext4_acl_from_disk 2 30320 NULL
111300 +i8254_read_30330 i8254_read 0 30330 NULL
111301 +resource_from_user_30341 resource_from_user 3 30341 NULL
111302 +o2nm_this_node_30342 o2nm_this_node 0 30342 NULL
111303 +kstrtou32_from_user_30361 kstrtou32_from_user 2 30361 NULL
111304 +C_SYSC_readv_30369 C_SYSC_readv 3 30369 NULL
111305 +blkdev_issue_zeroout_30392 blkdev_issue_zeroout 3 30392 NULL
111306 +c4iw_init_resource_30393 c4iw_init_resource 2-3 30393 NULL
111307 +get_kernel_pages_30397 get_kernel_pages 0 30397 NULL
111308 +vb2_fop_write_30420 vb2_fop_write 3 30420 NULL
111309 +tx_tx_template_prepared_read_30424 tx_tx_template_prepared_read 3 30424 NULL
111310 +lstcon_session_info_30425 lstcon_session_info 6 30425 NULL
111311 +enable_write_30456 enable_write 3 30456 NULL
111312 +tx_tx_template_programmed_read_30461 tx_tx_template_programmed_read 3 30461 NULL
111313 +urandom_read_30462 urandom_read 3 30462 NULL
111314 +zoran_ioctl_30465 zoran_ioctl 2 30465 NULL
111315 +i2c_ctrl_read_30467 i2c_ctrl_read 0 30467 NULL
111316 +adu_write_30487 adu_write 3 30487 NULL
111317 +dtim_interval_write_30489 dtim_interval_write 3 30489 NULL
111318 +batadv_send_tt_request_30493 batadv_send_tt_request 5 30493 NULL
111319 +dwc3_testmode_write_30516 dwc3_testmode_write 3 30516 NULL
111320 +set_config_30526 set_config 0 30526 NULL nohasharray
111321 +debug_debug2_read_30526 debug_debug2_read 3 30526 &set_config_30526
111322 +xfs_sb_version_hasftype_30559 xfs_sb_version_hasftype 0 30559 NULL
111323 +disk_expand_part_tbl_30561 disk_expand_part_tbl 2 30561 NULL
111324 +set_le_30581 set_le 4 30581 NULL
111325 +blk_init_tags_30592 blk_init_tags 1 30592 NULL
111326 +i2c_hid_get_report_length_30598 i2c_hid_get_report_length 0 30598 NULL
111327 +sgl_map_user_pages_30610 sgl_map_user_pages 2 30610 NULL nohasharray
111328 +cpufreq_get_global_kobject_30610 cpufreq_get_global_kobject 0 30610 &sgl_map_user_pages_30610
111329 +SyS_msgrcv_30611 SyS_msgrcv 3 30611 NULL
111330 +macvtap_sendmsg_30629 macvtap_sendmsg 4 30629 NULL
111331 +ieee80211_if_read_dot11MeshAwakeWindowDuration_30631 ieee80211_if_read_dot11MeshAwakeWindowDuration 3 30631 NULL
111332 +compat_raw_setsockopt_30634 compat_raw_setsockopt 5 30634 NULL
111333 +mlx5_ib_alloc_fast_reg_page_list_30638 mlx5_ib_alloc_fast_reg_page_list 2 30638 NULL
111334 +SyS_listxattr_30647 SyS_listxattr 3 30647 NULL
111335 +jffs2_flash_read_30667 jffs2_flash_read 0 30667 NULL
111336 +ni_ai_fifo_read_30681 ni_ai_fifo_read 3 30681 NULL
111337 +dccp_setsockopt_ccid_30701 dccp_setsockopt_ccid 4 30701 NULL
111338 +lbs_wrbbp_write_30712 lbs_wrbbp_write 3 30712 NULL
111339 +lbs_debugfs_read_30721 lbs_debugfs_read 3 30721 NULL
111340 +snd_nm256_playback_silence_30727 snd_nm256_playback_silence 4-3 30727 NULL
111341 +snapshot_status_30744 snapshot_status 5 30744 NULL
111342 +fuse_conn_limit_write_30777 fuse_conn_limit_write 3 30777 NULL
111343 +smk_read_doi_30813 smk_read_doi 3 30813 NULL
111344 +get_kobj_path_length_30831 get_kobj_path_length 0 30831 NULL
111345 +sctp_setsockopt_auth_chunk_30843 sctp_setsockopt_auth_chunk 3 30843 NULL
111346 +wd_autoreset_write_30862 wd_autoreset_write 3 30862 NULL
111347 +ieee80211_if_fmt_dropped_frames_no_route_30884 ieee80211_if_fmt_dropped_frames_no_route 3 30884 NULL
111348 +pn_recvmsg_30887 pn_recvmsg 4 30887 NULL
111349 +sctp_setsockopt_rtoinfo_30941 sctp_setsockopt_rtoinfo 3 30941 NULL
111350 +tty_insert_flip_string_flags_30969 tty_insert_flip_string_flags 4 30969 NULL
111351 +huge_page_mask_30981 huge_page_mask 0 30981 NULL
111352 +read_file_bt_ant_diversity_30983 read_file_bt_ant_diversity 3 30983 NULL
111353 +lbs_host_sleep_read_31013 lbs_host_sleep_read 3 31013 NULL
111354 +ima_eventsig_init_31022 ima_eventsig_init 5 31022 NULL
111355 +template_fmt_size_31033 template_fmt_size 0 31033 NULL
111356 +do_setup_msi_irqs_31043 do_setup_msi_irqs 2 31043 NULL
111357 +stride_pg_count_31053 stride_pg_count 0-2-1-4-3-5 31053 NULL
111358 +lbs_failcount_read_31063 lbs_failcount_read 3 31063 NULL
111359 +sctp_setsockopt_context_31091 sctp_setsockopt_context 3 31091 NULL
111360 +proc_gid_map_write_31093 proc_gid_map_write 3 31093 NULL
111361 +compat_sys_get_mempolicy_31109 compat_sys_get_mempolicy 3 31109 NULL
111362 +depth_read_31112 depth_read 3 31112 NULL
111363 +hash_ipportnet6_expire_31118 hash_ipportnet6_expire 4 31118 NULL
111364 +kimage_normal_alloc_31140 kimage_normal_alloc 3 31140 NULL
111365 +size_inside_page_31141 size_inside_page 0 31141 NULL
111366 +w9966_v4l_read_31148 w9966_v4l_read 3 31148 NULL
111367 +ch_do_scsi_31171 ch_do_scsi 4 31171 NULL
111368 +r592_read_fifo_pio_31198 r592_read_fifo_pio 3 31198 NULL
111369 +mtdchar_readoob_31200 mtdchar_readoob 4 31200 NULL
111370 +__btrfs_free_reserved_extent_31207 __btrfs_free_reserved_extent 2 31207 NULL
111371 +cpumask_weight_31215 cpumask_weight 0 31215 NULL
111372 +__read_reg_31216 __read_reg 0 31216 NULL
111373 +atm_get_addr_31221 atm_get_addr 3 31221 NULL
111374 +tcp_recvmsg_31238 tcp_recvmsg 4 31238 NULL
111375 +cyy_readb_31240 cyy_readb 0 31240 NULL
111376 +_create_sg_bios_31244 _create_sg_bios 4 31244 NULL
111377 +ieee80211_if_read_last_beacon_31257 ieee80211_if_read_last_beacon 3 31257 NULL
111378 +hash_netportnet4_expire_31290 hash_netportnet4_expire 4 31290 NULL
111379 +uvc_simplify_fraction_31303 uvc_simplify_fraction 3 31303 NULL
111380 +sisusbcon_scroll_31315 sisusbcon_scroll 5-2-3 31315 NULL
111381 +command_file_write_31318 command_file_write 3 31318 NULL
111382 +hwerr_crcbits_31334 hwerr_crcbits 4 31334 NULL
111383 +em28xx_init_usb_xfer_31337 em28xx_init_usb_xfer 4-6 31337 NULL
111384 +outlen_write_31358 outlen_write 3 31358 NULL
111385 +ieee80211_rx_mgmt_auth_31366 ieee80211_rx_mgmt_auth 3 31366 NULL
111386 +xprt_rdma_allocate_31372 xprt_rdma_allocate 2 31372 NULL
111387 +vb2_vmalloc_get_userptr_31374 vb2_vmalloc_get_userptr 3-2 31374 NULL
111388 +trace_parser_get_init_31379 trace_parser_get_init 2 31379 NULL
111389 +inb_31388 inb 0 31388 NULL
111390 +key_ifindex_read_31411 key_ifindex_read 3 31411 NULL
111391 +_sp2d_max_pg_31422 _sp2d_max_pg 0 31422 NULL
111392 +TSS_checkhmac1_31429 TSS_checkhmac1 5 31429 NULL
111393 +snd_aw2_saa7146_get_hw_ptr_capture_31431 snd_aw2_saa7146_get_hw_ptr_capture 0 31431 NULL
111394 +transport_alloc_session_tags_31449 transport_alloc_session_tags 2-3 31449 NULL
111395 +opera1_xilinx_rw_31453 opera1_xilinx_rw 5 31453 NULL
111396 +xfs_btree_get_numrecs_31477 xfs_btree_get_numrecs 0 31477 NULL
111397 +alg_setkey_31485 alg_setkey 3 31485 NULL
111398 +rds_message_map_pages_31487 rds_message_map_pages 2 31487 NULL
111399 +qsfp_2_read_31491 qsfp_2_read 3 31491 NULL
111400 +__alloc_bootmem_31498 __alloc_bootmem 1 31498 NULL
111401 +hidraw_write_31536 hidraw_write 3 31536 NULL
111402 +usbvision_read_31555 usbvision_read 3 31555 NULL
111403 +tx_frag_tkip_called_read_31575 tx_frag_tkip_called_read 3 31575 NULL
111404 +get_max_inline_xattr_value_size_31578 get_max_inline_xattr_value_size 0 31578 NULL
111405 +osst_write_31581 osst_write 3 31581 NULL
111406 +snd_compr_get_avail_31584 snd_compr_get_avail 0 31584 NULL
111407 +iwl_dbgfs_ucode_tx_stats_read_31611 iwl_dbgfs_ucode_tx_stats_read 3 31611 NULL
111408 +mtd_get_user_prot_info_31616 mtd_get_user_prot_info 0 31616 NULL
111409 +arvo_sysfs_read_31617 arvo_sysfs_read 6 31617 NULL
111410 +videobuf_read_one_31637 videobuf_read_one 3 31637 NULL
111411 +pod_alloc_sysex_buffer_31651 pod_alloc_sysex_buffer 3 31651 NULL
111412 +xfer_secondary_pool_31661 xfer_secondary_pool 2 31661 NULL
111413 +__lgread_31668 __lgread 4 31668 NULL
111414 +copy_from_user_nmi_31672 copy_from_user_nmi 3-0 31672 NULL
111415 +forced_ps_read_31685 forced_ps_read 3 31685 NULL
111416 +fst_recover_rx_error_31687 fst_recover_rx_error 3 31687 NULL
111417 +utf16s_to_utf8s_31735 utf16s_to_utf8s 0 31735 NULL nohasharray
111418 +lu_buf_check_and_grow_31735 lu_buf_check_and_grow 2 31735 &utf16s_to_utf8s_31735
111419 +shmem_pwrite_slow_31741 shmem_pwrite_slow 3-2 31741 NULL
111420 +input_abs_get_max_31742 input_abs_get_max 0 31742 NULL nohasharray
111421 +NCR_700_change_queue_depth_31742 NCR_700_change_queue_depth 2 31742 &input_abs_get_max_31742
111422 +bcm_char_read_31750 bcm_char_read 3 31750 NULL
111423 +snd_seq_device_new_31753 snd_seq_device_new 4 31753 NULL
111424 +SyS_lsetxattr_31766 SyS_lsetxattr 4 31766 NULL
111425 +usblp_cache_device_id_string_31790 usblp_cache_device_id_string 0 31790 NULL
111426 +ecryptfs_send_message_locked_31801 ecryptfs_send_message_locked 2 31801 NULL
111427 +isr_rx_procs_read_31804 isr_rx_procs_read 3 31804 NULL
111428 +data_write_31805 data_write 3 31805 NULL
111429 +SyS_msgsnd_31814 SyS_msgsnd 3 31814 NULL
111430 +strnlen_user_31815 strnlen_user 0-2 31815 NULL
111431 +sta_last_signal_read_31818 sta_last_signal_read 3 31818 NULL
111432 +SyS_ppoll_31855 SyS_ppoll 2 31855 NULL
111433 +iwl_dbgfs_disable_ht40_write_31876 iwl_dbgfs_disable_ht40_write 3 31876 NULL
111434 +drm_mode_crtc_set_gamma_size_31881 drm_mode_crtc_set_gamma_size 2 31881 NULL
111435 +ddb_output_write_31902 ddb_output_write 3-0 31902 NULL
111436 +xattr_permission_31907 xattr_permission 0 31907 NULL
111437 +lu_buf_realloc_31915 lu_buf_realloc 2 31915 NULL
111438 +new_dir_31919 new_dir 3 31919 NULL
111439 +kmem_alloc_31920 kmem_alloc 1 31920 NULL
111440 +SYSC_sethostname_31940 SYSC_sethostname 2 31940 NULL
111441 +read_mem_31942 read_mem 3 31942 NULL nohasharray
111442 +iov_iter_copy_from_user_31942 iov_iter_copy_from_user 4-0 31942 &read_mem_31942
111443 +vb2_write_31948 vb2_write 3 31948 NULL
111444 +pvr2_ctrl_get_valname_31951 pvr2_ctrl_get_valname 4 31951 NULL
111445 +regcache_rbtree_sync_31964 regcache_rbtree_sync 2 31964 NULL
111446 +copy_from_user_toio_31966 copy_from_user_toio 3 31966 NULL
111447 +iblock_execute_rw_31982 iblock_execute_rw 3 31982 NULL nohasharray
111448 +vx_read_status_31982 vx_read_status 0 31982 &iblock_execute_rw_31982
111449 +find_next_zero_bit_31990 find_next_zero_bit 0 31990 NULL
111450 +lustre_acl_xattr_merge2posix_31992 lustre_acl_xattr_merge2posix 2 31992 NULL
111451 +sysfs_create_file_31996 sysfs_create_file 0 31996 NULL
111452 +calc_hmac_32010 calc_hmac 3 32010 NULL
111453 +aead_len_32021 aead_len 0 32021 NULL
111454 +posix_acl_set_32037 posix_acl_set 4 32037 NULL
111455 +stk_read_32038 stk_read 3 32038 NULL
111456 +ocfs2_update_edge_lengths_32046 ocfs2_update_edge_lengths 3 32046 NULL
111457 +SYSC_llistxattr_32061 SYSC_llistxattr 3 32061 NULL
111458 +proc_scsi_devinfo_write_32064 proc_scsi_devinfo_write 3 32064 NULL
111459 +cow_file_range_inline_32091 cow_file_range_inline 3 32091 NULL
111460 +bio_alloc_32095 bio_alloc 2 32095 NULL
111461 +ath6kl_fwlog_read_32101 ath6kl_fwlog_read 3 32101 NULL
111462 +disk_status_32120 disk_status 4 32120 NULL
111463 +kobject_add_internal_32133 kobject_add_internal 0 32133 NULL
111464 +venus_link_32165 venus_link 5 32165 NULL
111465 +do_writepages_32173 do_writepages 0 32173 NULL
111466 +del_ptr_32197 del_ptr 4 32197 NULL
111467 +wusb_ccm_mac_32199 wusb_ccm_mac 7 32199 NULL
111468 +riva_get_cmap_len_32218 riva_get_cmap_len 0 32218 NULL
111469 +caif_seqpkt_recvmsg_32241 caif_seqpkt_recvmsg 4 32241 NULL
111470 +lbs_lowrssi_read_32242 lbs_lowrssi_read 3 32242 NULL
111471 +ocfs2_xattr_find_entry_32260 ocfs2_xattr_find_entry 0 32260 NULL
111472 +kvm_set_spte_hva_32312 kvm_set_spte_hva 2 32312 NULL
111473 +cas_calc_tabort_32316 cas_calc_tabort 0 32316 NULL
111474 +SyS_select_32319 SyS_select 1 32319 NULL
111475 +nouveau_bar_create__32332 nouveau_bar_create_ 4 32332 NULL
111476 +nl80211_send_mlme_event_32337 nl80211_send_mlme_event 4 32337 NULL
111477 +t4_alloc_mem_32342 t4_alloc_mem 1 32342 NULL
111478 +dispatch_ioctl_32357 dispatch_ioctl 2 32357 NULL nohasharray
111479 +rx_streaming_always_write_32357 rx_streaming_always_write 3 32357 &dispatch_ioctl_32357
111480 +ReadHDLCPCI_32362 ReadHDLCPCI 0 32362 NULL nohasharray
111481 +sel_read_initcon_32362 sel_read_initcon 3 32362 &ReadHDLCPCI_32362
111482 +ocfs2_cancel_convert_32392 ocfs2_cancel_convert 0 32392 NULL
111483 +ll_setxattr_common_32398 ll_setxattr_common 4 32398 NULL
111484 +xfs_iext_add_indirect_multi_32400 xfs_iext_add_indirect_multi 3 32400 NULL
111485 +vmci_qp_alloc_32405 vmci_qp_alloc 5-3 32405 NULL
111486 +cache_status_32462 cache_status 5 32462 NULL
111487 +fill_readbuf_32464 fill_readbuf 3 32464 NULL
111488 +dgap_usertoboard_32490 dgap_usertoboard 4 32490 NULL
111489 +ide_driver_proc_write_32493 ide_driver_proc_write 3 32493 NULL
111490 +bypass_pwoff_write_32499 bypass_pwoff_write 3 32499 NULL
111491 +mdc_pinger_recov_seq_write_32510 mdc_pinger_recov_seq_write 3 32510 NULL
111492 +ctrl_std_val_to_sym_32516 ctrl_std_val_to_sym 5 32516 NULL
111493 +disconnect_32521 disconnect 4 32521 NULL
111494 +qsfp_read_32522 qsfp_read 0-2-4 32522 NULL
111495 +ocfs2_refresh_qinfo_32524 ocfs2_refresh_qinfo 0 32524 NULL nohasharray
111496 +audio_get_intf_req_32524 audio_get_intf_req 0 32524 &ocfs2_refresh_qinfo_32524
111497 +ilo_read_32531 ilo_read 3 32531 NULL
111498 +ieee80211_if_read_estab_plinks_32533 ieee80211_if_read_estab_plinks 3 32533 NULL
111499 +format_devstat_counter_32550 format_devstat_counter 3 32550 NULL
111500 +aes_encrypt_fail_read_32562 aes_encrypt_fail_read 3 32562 NULL
111501 +osc_iocontrol_32565 osc_iocontrol 3 32565 NULL
111502 +mem_swapout_entry_32586 mem_swapout_entry 3 32586 NULL
111503 +pipeline_tcp_tx_stat_fifo_int_read_32589 pipeline_tcp_tx_stat_fifo_int_read 3 32589 NULL
111504 +read_file_beacon_32595 read_file_beacon 3 32595 NULL
111505 +ieee80211_if_read_dropped_frames_congestion_32603 ieee80211_if_read_dropped_frames_congestion 3 32603 NULL
111506 +irda_recvmsg_dgram_32631 irda_recvmsg_dgram 4 32631 NULL
111507 +cfg80211_roamed_32632 cfg80211_roamed 5-7 32632 NULL
111508 +kvmalloc_32646 kvmalloc 1 32646 NULL
111509 +ib_sg_dma_len_32649 ib_sg_dma_len 0 32649 NULL
111510 +generic_readlink_32654 generic_readlink 3 32654 NULL
111511 +move_addr_to_kernel_32673 move_addr_to_kernel 2 32673 NULL
111512 +apei_res_add_32674 apei_res_add 0 32674 NULL
111513 +compat_SyS_preadv_32679 compat_SyS_preadv 3 32679 NULL
111514 +jfs_readpages_32702 jfs_readpages 4 32702 NULL
111515 +rt2x00debug_read_queue_dump_32712 rt2x00debug_read_queue_dump 3 32712 NULL
111516 +i40e_pci_sriov_enable_32742 i40e_pci_sriov_enable 2 32742 NULL
111517 +megasas_change_queue_depth_32747 megasas_change_queue_depth 2 32747 NULL
111518 +stats_read_ul_32751 stats_read_ul 3 32751 NULL
111519 +vmci_transport_dgram_dequeue_32775 vmci_transport_dgram_dequeue 4 32775 NULL
111520 +sctp_tsnmap_grow_32784 sctp_tsnmap_grow 2 32784 NULL
111521 +rproc_name_read_32805 rproc_name_read 3 32805 NULL
111522 +new_tape_buffer_32866 new_tape_buffer 2 32866 NULL
111523 +cifs_writedata_alloc_32880 cifs_writedata_alloc 1 32880 NULL nohasharray
111524 +ath6kl_usb_submit_ctrl_in_32880 ath6kl_usb_submit_ctrl_in 6 32880 &cifs_writedata_alloc_32880
111525 +vp702x_usb_inout_cmd_32884 vp702x_usb_inout_cmd 6-4 32884 NULL
111526 +il_dbgfs_tx_stats_read_32913 il_dbgfs_tx_stats_read 3 32913 NULL
111527 +zlib_inflate_workspacesize_32927 zlib_inflate_workspacesize 0 32927 NULL
111528 +rmap_recycle_32938 rmap_recycle 3 32938 NULL
111529 +xfs_log_reserve_32959 xfs_log_reserve 2 32959 NULL
111530 +ocfs2_check_dir_trailer_32968 ocfs2_check_dir_trailer 0 32968 NULL
111531 +compat_filldir_32999 compat_filldir 3 32999 NULL
111532 +SyS_syslog_33007 SyS_syslog 3 33007 NULL
111533 +br_multicast_set_hash_max_33012 br_multicast_set_hash_max 2 33012 NULL
111534 +write_file_bt_ant_diversity_33019 write_file_bt_ant_diversity 3 33019 NULL
111535 +mic_virtio_copy_to_user_33048 mic_virtio_copy_to_user 3 33048 NULL
111536 +SYSC_lgetxattr_33049 SYSC_lgetxattr 4 33049 NULL
111537 +pipeline_dec_packet_in_fifo_full_read_33052 pipeline_dec_packet_in_fifo_full_read 3 33052 NULL
111538 +ebt_compat_match_offset_33053 ebt_compat_match_offset 0-2 33053 NULL
111539 +bitmap_resize_33054 bitmap_resize 2 33054 NULL
111540 +stats_dot11RTSSuccessCount_read_33065 stats_dot11RTSSuccessCount_read 3 33065 NULL
111541 +sel_read_checkreqprot_33068 sel_read_checkreqprot 3 33068 NULL
111542 +alloc_tio_33077 alloc_tio 3 33077 NULL
111543 +acl_permission_check_33083 acl_permission_check 0 33083 NULL
111544 +fb_sys_write_33130 fb_sys_write 3 33130 NULL
111545 +__len_within_target_33132 __len_within_target 0 33132 NULL
111546 +SyS_poll_33152 SyS_poll 2 33152 NULL
111547 +debug_debug6_read_33168 debug_debug6_read 3 33168 NULL
111548 +dataflash_read_fact_otp_33204 dataflash_read_fact_otp 3-2 33204 NULL
111549 +pp_read_33210 pp_read 3 33210 NULL
111550 +xfs_file_aio_write_33234 xfs_file_aio_write 4 33234 NULL
111551 +snd_pcm_plug_client_size_33267 snd_pcm_plug_client_size 0-2 33267 NULL
111552 +cachefiles_cook_key_33274 cachefiles_cook_key 2 33274 NULL
111553 +sync_pt_create_33282 sync_pt_create 2 33282 NULL
111554 +mcs7830_get_reg_33308 mcs7830_get_reg 3 33308 NULL
111555 +isku_sysfs_read_keys_easyzone_33318 isku_sysfs_read_keys_easyzone 6 33318 NULL
111556 +vx_send_irq_dsp_33329 vx_send_irq_dsp 0 33329 NULL
111557 +joydev_ioctl_33343 joydev_ioctl 2 33343 NULL
111558 +lov_stripesize_seq_write_33353 lov_stripesize_seq_write 3 33353 NULL
111559 +create_xattr_datum_33356 create_xattr_datum 5 33356 NULL nohasharray
111560 +irq_pkt_threshold_read_33356 irq_pkt_threshold_read 3 33356 &create_xattr_datum_33356
111561 +read_file_regidx_33370 read_file_regidx 3 33370 NULL
111562 +ieee80211_if_read_dropped_frames_no_route_33383 ieee80211_if_read_dropped_frames_no_route 3 33383 NULL
111563 +scsi_varlen_cdb_length_33385 scsi_varlen_cdb_length 0 33385 NULL
111564 +ocfs2_allocate_unwritten_extents_33394 ocfs2_allocate_unwritten_extents 3-2 33394 NULL
111565 +cfs_trace_copyin_string_33396 cfs_trace_copyin_string 4 33396 NULL
111566 +snd_pcm_capture_ioctl1_33408 snd_pcm_capture_ioctl1 0 33408 NULL
111567 +hash_netiface6_expire_33421 hash_netiface6_expire 4 33421 NULL
111568 +dis_tap_write_33426 dis_tap_write 3 33426 NULL
111569 +message_stats_list_33440 message_stats_list 5 33440 NULL
111570 +ovs_vport_alloc_33475 ovs_vport_alloc 1 33475 NULL
111571 +create_entry_33479 create_entry 2 33479 NULL
111572 +ip_setsockopt_33487 ip_setsockopt 5 33487 NULL nohasharray
111573 +elf_map_33487 elf_map 0-2 33487 &ip_setsockopt_33487
111574 +res_counter_read_33499 res_counter_read 4 33499 NULL
111575 +hash_netnet4_expire_33500 hash_netnet4_expire 4 33500 NULL
111576 +fb_read_33506 fb_read 3 33506 NULL
111577 +musb_test_mode_write_33518 musb_test_mode_write 3 33518 NULL
111578 +ahash_setkey_unaligned_33521 ahash_setkey_unaligned 3 33521 NULL
111579 +nes_alloc_fast_reg_page_list_33523 nes_alloc_fast_reg_page_list 2 33523 NULL
111580 +aggr_size_rx_size_read_33526 aggr_size_rx_size_read 3 33526 NULL
111581 +tomoyo_read_self_33539 tomoyo_read_self 3 33539 NULL nohasharray
111582 +osc_max_rpcs_in_flight_seq_write_33539 osc_max_rpcs_in_flight_seq_write 3 33539 &tomoyo_read_self_33539
111583 +count_subheaders_33591 count_subheaders 0 33591 NULL
111584 +scsi_execute_33596 scsi_execute 5 33596 NULL
111585 +comedi_buf_write_n_allocated_33604 comedi_buf_write_n_allocated 0 33604 NULL
111586 +xt_compat_target_offset_33608 xt_compat_target_offset 0 33608 NULL
111587 +usb_gstrings_attach_33615 usb_gstrings_attach 3 33615 NULL nohasharray
111588 +il_dbgfs_qos_read_33615 il_dbgfs_qos_read 3 33615 &usb_gstrings_attach_33615
111589 +stride_page_count_33641 stride_page_count 2 33641 NULL
111590 +irq_blk_threshold_read_33666 irq_blk_threshold_read 3 33666 NULL
111591 +inw_p_33668 inw_p 0 33668 NULL
111592 +arp_hdr_len_33671 arp_hdr_len 0 33671 NULL
111593 +i2c_hid_alloc_buffers_33673 i2c_hid_alloc_buffers 2 33673 NULL
111594 +nv50_disp_dmac_create__33696 nv50_disp_dmac_create_ 6 33696 NULL
111595 +netlink_sendmsg_33708 netlink_sendmsg 4 33708 NULL
111596 +tipc_link_stats_33716 tipc_link_stats 3 33716 NULL
111597 +ext4_wb_update_i_disksize_33717 ext4_wb_update_i_disksize 2 33717 NULL
111598 +pvr2_stream_buffer_count_33719 pvr2_stream_buffer_count 2 33719 NULL
111599 +write_file_spectral_count_33723 write_file_spectral_count 3 33723 NULL
111600 +__mutex_lock_interruptible_slowpath_33735 __mutex_lock_interruptible_slowpath 0 33735 NULL
111601 +vifs_state_read_33762 vifs_state_read 3 33762 NULL
111602 +hashtab_create_33769 hashtab_create 3 33769 NULL
111603 +if_sdio_read_rx_len_33800 if_sdio_read_rx_len 0 33800 NULL
111604 +filter_write_33819 filter_write 3 33819 NULL
111605 +sep_create_msgarea_context_33829 sep_create_msgarea_context 4 33829 NULL
111606 +scrub_setup_recheck_block_33831 scrub_setup_recheck_block 5-4 33831 NULL
111607 +ext4_journal_extend_33835 ext4_journal_extend 2 33835 NULL
111608 +oz_cdev_write_33852 oz_cdev_write 3 33852 NULL
111609 +get_user_pages_33908 get_user_pages 0 33908 NULL
111610 +ath6kl_roam_mode_write_33912 ath6kl_roam_mode_write 3 33912 NULL
111611 +queue_logical_block_size_33918 queue_logical_block_size 0 33918 NULL
111612 +sel_read_avc_cache_threshold_33942 sel_read_avc_cache_threshold 3 33942 NULL
111613 +lpfc_idiag_ctlacc_read_33943 lpfc_idiag_ctlacc_read 3 33943 NULL
111614 +read_file_tgt_rx_stats_33944 read_file_tgt_rx_stats 3 33944 NULL
111615 +hfsplus_osx_setxattr_33952 hfsplus_osx_setxattr 4 33952 NULL
111616 +__proc_dump_kernel_33954 __proc_dump_kernel 5 33954 NULL
111617 +vga_switcheroo_debugfs_write_33984 vga_switcheroo_debugfs_write 3 33984 NULL
111618 +lbs_lowrssi_write_34025 lbs_lowrssi_write 3 34025 NULL
111619 +ppp_write_34034 ppp_write 3 34034 NULL
111620 +tty_insert_flip_string_34042 tty_insert_flip_string 3-0 34042 NULL
111621 +memcg_update_all_caches_34068 memcg_update_all_caches 1 34068 NULL
111622 +pipeline_pipeline_fifo_full_read_34095 pipeline_pipeline_fifo_full_read 3 34095 NULL
111623 +__irq_domain_add_34101 __irq_domain_add 2 34101 NULL
111624 +proc_scsi_host_write_34107 proc_scsi_host_write 3 34107 NULL
111625 +islpci_mgt_transmit_34133 islpci_mgt_transmit 5 34133 NULL
111626 +ttm_dma_page_pool_free_34135 ttm_dma_page_pool_free 2-0 34135 NULL
111627 +ixgbe_dbg_netdev_ops_write_34141 ixgbe_dbg_netdev_ops_write 3 34141 NULL
111628 +shmem_pread_fast_34147 shmem_pread_fast 3 34147 NULL
111629 +ocfs2_xattr_list_entry_34165 ocfs2_xattr_list_entry 0 34165 NULL
111630 +skb_to_sgvec_34171 skb_to_sgvec 0 34171 NULL
111631 +ext4_da_write_begin_34215 ext4_da_write_begin 3-4 34215 NULL
111632 +sysfs_bin_read_34228 sysfs_bin_read 3 34228 NULL
111633 +bl_pipe_downcall_34264 bl_pipe_downcall 3 34264 NULL
111634 +ocfs2_dlm_lock_34265 ocfs2_dlm_lock 0 34265 NULL
111635 +device_private_init_34279 device_private_init 0 34279 NULL
111636 +ext4_get_groups_count_34324 ext4_get_groups_count 0 34324 NULL
111637 +pcpu_need_to_extend_34326 pcpu_need_to_extend 0 34326 NULL nohasharray
111638 +iov_iter_single_seg_count_34326 iov_iter_single_seg_count 0 34326 &pcpu_need_to_extend_34326
111639 +crypto_ablkcipher_ivsize_34363 crypto_ablkcipher_ivsize 0 34363 NULL nohasharray
111640 +sync_page_io_34363 sync_page_io 3 34363 &crypto_ablkcipher_ivsize_34363
111641 +rngapi_reset_34366 rngapi_reset 3 34366 NULL
111642 +ea_read_34378 ea_read 0 34378 NULL
111643 +fuse_send_read_34379 fuse_send_read 4 34379 NULL
111644 +av7110_vbi_write_34384 av7110_vbi_write 3 34384 NULL
111645 +usbvision_v4l2_read_34386 usbvision_v4l2_read 3 34386 NULL
111646 +read_rbu_image_type_34387 read_rbu_image_type 6 34387 NULL
111647 +iwl_calib_set_34400 iwl_calib_set 3 34400 NULL nohasharray
111648 +ivtv_read_pos_34400 ivtv_read_pos 3 34400 &iwl_calib_set_34400
111649 +wd_exp_mode_write_34407 wd_exp_mode_write 3 34407 NULL
111650 +nl80211_send_disassoc_34424 nl80211_send_disassoc 4 34424 NULL
111651 +usbtest_alloc_urb_34446 usbtest_alloc_urb 3-5 34446 NULL
111652 +mwifiex_regrdwr_read_34472 mwifiex_regrdwr_read 3 34472 NULL
111653 +skcipher_sndbuf_34476 skcipher_sndbuf 0 34476 NULL
111654 +i2o_parm_field_get_34477 i2o_parm_field_get 5 34477 NULL
111655 +ocfs2_mv_xattr_buckets_34484 ocfs2_mv_xattr_buckets 6 34484 NULL
111656 +security_inode_permission_34488 security_inode_permission 0 34488 NULL
111657 +SyS_pwritev_34494 SyS_pwritev 3 34494 NULL
111658 +qp_alloc_res_34496 qp_alloc_res 5 34496 NULL
111659 +lu_buf_check_and_alloc_34505 lu_buf_check_and_alloc 2 34505 NULL
111660 +ext4_fallocate_34537 ext4_fallocate 4-3 34537 NULL nohasharray
111661 +tracing_stats_read_34537 tracing_stats_read 3 34537 &ext4_fallocate_34537
111662 +hugetlbfs_read_actor_34547 hugetlbfs_read_actor 2-5-4-0 34547 NULL
111663 +dbBackSplit_34561 dbBackSplit 0 34561 NULL
111664 +alloc_ieee80211_rsl_34564 alloc_ieee80211_rsl 1 34564 NULL
111665 +lov_stripecount_seq_write_34582 lov_stripecount_seq_write 3 34582 NULL
111666 +init_send_hfcd_34586 init_send_hfcd 1 34586 NULL
111667 +inet6_ifla6_size_34591 inet6_ifla6_size 0 34591 NULL
111668 +ceph_msgpool_init_34599 ceph_msgpool_init 4 34599 NULL nohasharray
111669 +cw1200_queue_init_34599 cw1200_queue_init 4 34599 &ceph_msgpool_init_34599
111670 +brcmf_cfg80211_mgmt_tx_34608 brcmf_cfg80211_mgmt_tx 7 34608 NULL
111671 +__jffs2_ref_totlen_34609 __jffs2_ref_totlen 0 34609 NULL
111672 +apei_get_nvs_resources_34616 apei_get_nvs_resources 0 34616 NULL
111673 +__cfg80211_disconnected_34622 __cfg80211_disconnected 3 34622 NULL
111674 +cnic_alloc_dma_34641 cnic_alloc_dma 3 34641 NULL
111675 +kvm_set_spte_hva_34671 kvm_set_spte_hva 2 34671 NULL
111676 +sleep_auth_write_34676 sleep_auth_write 3 34676 NULL
111677 +isr_fiqs_read_34687 isr_fiqs_read 3 34687 NULL
111678 +batadv_tvlv_realloc_packet_buff_34688 batadv_tvlv_realloc_packet_buff 3-4 34688 NULL
111679 +port_print_34704 port_print 3 34704 NULL
111680 +ieee80211_if_read_num_sta_ps_34722 ieee80211_if_read_num_sta_ps 3 34722 NULL
111681 +platform_list_read_file_34734 platform_list_read_file 3 34734 NULL
111682 +reg_w_ixbuf_34736 reg_w_ixbuf 4 34736 NULL
111683 +lsm_alloc_plain_34755 lsm_alloc_plain 1 34755 NULL
111684 +bootmode_store_34762 bootmode_store 4 34762 NULL
111685 +device_add_34766 device_add 0 34766 NULL
111686 +qib_cdev_init_34778 qib_cdev_init 1 34778 NULL
111687 +SYSC_keyctl_34800 SYSC_keyctl 4 34800 NULL
111688 +can_nocow_extent_34801 can_nocow_extent 2 34801 NULL
111689 +drbd_get_max_capacity_34804 drbd_get_max_capacity 0 34804 NULL
111690 +ll_setxattr_34806 ll_setxattr 4 34806 NULL
111691 +file_page_index_34820 file_page_index 0-2 34820 NULL
111692 +b43_debugfs_write_34838 b43_debugfs_write 3 34838 NULL
111693 +nl_portid_hash_zalloc_34843 nl_portid_hash_zalloc 1 34843 NULL
111694 +acpi_system_write_wakeup_device_34853 acpi_system_write_wakeup_device 3 34853 NULL
111695 +usb_serial_generic_prepare_write_buffer_34857 usb_serial_generic_prepare_write_buffer 3 34857 NULL
111696 +ieee80211_if_read_txpower_34871 ieee80211_if_read_txpower 3 34871 NULL
111697 +msg_print_text_34889 msg_print_text 0 34889 NULL
111698 +ieee80211_if_write_34894 ieee80211_if_write 3 34894 NULL
111699 +si476x_radio_read_rsq_primary_blob_34916 si476x_radio_read_rsq_primary_blob 3 34916 NULL
111700 +__inode_permission_34925 __inode_permission 0 34925 NULL nohasharray
111701 +btrfs_super_chunk_root_34925 btrfs_super_chunk_root 0 34925 &__inode_permission_34925
111702 +ceph_aio_write_34930 ceph_aio_write 4 34930 NULL
111703 +sec_flags2str_34933 sec_flags2str 3 34933 NULL
111704 +snd_info_entry_read_34938 snd_info_entry_read 3 34938 NULL
111705 +i2c_transfer_34958 i2c_transfer 0 34958 NULL
111706 +do_add_page_to_bio_34974 do_add_page_to_bio 2-10 34974 NULL
111707 +rx_rx_hdr_overflow_read_35002 rx_rx_hdr_overflow_read 3 35002 NULL
111708 +l2cap_skbuff_fromiovec_35003 l2cap_skbuff_fromiovec 4-3 35003 NULL
111709 +sisusb_copy_memory_35016 sisusb_copy_memory 4 35016 NULL
111710 +coda_psdev_read_35029 coda_psdev_read 3 35029 NULL
111711 +brcmf_sdio_chip_writenvram_35042 brcmf_sdio_chip_writenvram 4 35042 NULL
111712 +pwr_connection_out_of_sync_read_35061 pwr_connection_out_of_sync_read 3 35061 NULL
111713 +__kfifo_uint_must_check_helper_35097 __kfifo_uint_must_check_helper 0-1 35097 NULL
111714 +capi_write_35104 capi_write 3 35104 NULL nohasharray
111715 +tx_tx_done_template_read_35104 tx_tx_done_template_read 3 35104 &capi_write_35104
111716 +ide_settings_proc_write_35110 ide_settings_proc_write 3 35110 NULL
111717 +ceph_osdc_start_request_35122 ceph_osdc_start_request 0 35122 NULL
111718 +message_stats_print_35158 message_stats_print 6 35158 NULL
111719 +iscsi_conn_setup_35159 iscsi_conn_setup 2 35159 NULL
111720 +ieee80211_if_read_bssid_35161 ieee80211_if_read_bssid 3 35161 NULL
111721 +unix_stream_recvmsg_35210 unix_stream_recvmsg 4 35210 NULL
111722 +security_key_getsecurity_35218 security_key_getsecurity 0 35218 NULL nohasharray
111723 +striped_read_35218 striped_read 0-2 35218 &security_key_getsecurity_35218
111724 +rx_rx_cmplt_task_read_35226 rx_rx_cmplt_task_read 3 35226 NULL
111725 +set_fd_set_35249 set_fd_set 1 35249 NULL
111726 +ioapic_setup_resources_35255 ioapic_setup_resources 1 35255 NULL
111727 +jbd2_journal_get_write_access_35263 jbd2_journal_get_write_access 0 35263 NULL
111728 +dis_disc_write_35265 dis_disc_write 3 35265 NULL
111729 +dma_show_regs_35266 dma_show_regs 3 35266 NULL
111730 +irda_recvmsg_stream_35280 irda_recvmsg_stream 4 35280 NULL
111731 +i2o_block_end_request_35282 i2o_block_end_request 3 35282 NULL
111732 +isr_rx_rdys_read_35283 isr_rx_rdys_read 3 35283 NULL
111733 +__btrfs_buffered_write_35311 __btrfs_buffered_write 3 35311 NULL nohasharray
111734 +brcmf_sdio_forensic_read_35311 brcmf_sdio_forensic_read 3 35311 &__btrfs_buffered_write_35311
111735 +tracing_read_pipe_35312 tracing_read_pipe 3 35312 NULL
111736 +ieee80211_if_fmt_ap_power_level_35347 ieee80211_if_fmt_ap_power_level 3 35347 NULL
111737 +nouveau_devinit_create__35348 nouveau_devinit_create_ 4 35348 NULL
111738 +ieee80211_rx_mgmt_deauth_35351 ieee80211_rx_mgmt_deauth 3 35351 NULL
111739 +compat_filldir64_35354 compat_filldir64 3 35354 NULL
111740 +read_kmem_35372 read_kmem 3 35372 NULL
111741 +SyS_getxattr_35408 SyS_getxattr 4 35408 NULL
111742 +rawv6_send_hdrinc_35425 rawv6_send_hdrinc 3 35425 NULL
111743 +buffer_to_user_35439 buffer_to_user 3 35439 NULL
111744 +fiemap_prepare_and_copy_exts_35494 fiemap_prepare_and_copy_exts 5 35494 NULL
111745 +btrfs_prealloc_file_range_trans_35500 btrfs_prealloc_file_range_trans 4 35500 NULL
111746 +async_setkey_35521 async_setkey 3 35521 NULL
111747 +__filemap_fdatawrite_range_35528 __filemap_fdatawrite_range 0 35528 NULL
111748 +iwl_dbgfs_bt_traffic_read_35534 iwl_dbgfs_bt_traffic_read 3 35534 NULL
111749 +pstore_mkfile_35536 pstore_mkfile 7 35536 NULL
111750 +rxpipe_tx_xfr_host_int_trig_rx_data_read_35538 rxpipe_tx_xfr_host_int_trig_rx_data_read 3 35538 NULL
111751 +ibnl_put_attr_35541 ibnl_put_attr 3 35541 NULL
111752 +ieee80211_if_write_smps_35550 ieee80211_if_write_smps 3 35550 NULL
111753 +sysfs_create_subdir_35567 sysfs_create_subdir 0 35567 NULL
111754 +ext4_blocks_for_truncate_35579 ext4_blocks_for_truncate 0 35579 NULL
111755 +ext2_acl_from_disk_35580 ext2_acl_from_disk 2 35580 NULL
111756 +spk_msg_set_35586 spk_msg_set 3 35586 NULL
111757 +kernel_readv_35617 kernel_readv 3 35617 NULL
111758 +reiserfs_readpages_35629 reiserfs_readpages 4 35629 NULL
111759 +pci_request_regions_35635 pci_request_regions 0 35635 NULL
111760 +ptlrpcd_steal_rqset_35637 ptlrpcd_steal_rqset 0 35637 NULL
111761 +spi_register_board_info_35651 spi_register_board_info 2 35651 NULL
111762 +rdmaltWithLock_35669 rdmaltWithLock 0 35669 NULL
111763 +compat_sys_kexec_load_35674 compat_sys_kexec_load 2 35674 NULL
111764 +SYSC_pwritev_35690 SYSC_pwritev 3 35690 NULL
111765 +rds_page_copy_user_35691 rds_page_copy_user 4 35691 NULL
111766 +md_super_write_35703 md_super_write 4 35703 NULL
111767 +ocfs2_extent_recs_per_gd_35710 ocfs2_extent_recs_per_gd 0 35710 NULL
111768 +iwl_dbgfs_disable_ht40_read_35761 iwl_dbgfs_disable_ht40_read 3 35761 NULL
111769 +udf_alloc_i_data_35786 udf_alloc_i_data 2 35786 NULL
111770 +pvr2_hdw_cpufw_get_35824 pvr2_hdw_cpufw_get 0-4-2 35824 NULL
111771 +tx_tx_cmplt_read_35854 tx_tx_cmplt_read 3 35854 NULL
111772 +vx_query_hbuffer_size_35859 vx_query_hbuffer_size 0 35859 NULL
111773 +mthca_buf_alloc_35861 mthca_buf_alloc 2 35861 NULL
111774 +fls64_35862 fls64 0 35862 NULL
111775 +kvm_dirty_bitmap_bytes_35886 kvm_dirty_bitmap_bytes 0 35886 NULL
111776 +ieee80211_if_fmt_dot11MeshRetryTimeout_35890 ieee80211_if_fmt_dot11MeshRetryTimeout 3 35890 NULL
111777 +uwb_rc_cmd_done_35892 uwb_rc_cmd_done 4 35892 NULL
111778 +SyS_set_mempolicy_35909 SyS_set_mempolicy 3 35909 NULL
111779 +kernel_setsockopt_35913 kernel_setsockopt 5 35913 NULL
111780 +rbio_nr_pages_35916 rbio_nr_pages 0-1-2 35916 NULL
111781 +sctp_tsnmap_mark_35929 sctp_tsnmap_mark 2 35929 NULL
111782 +rx_defrag_init_called_read_35935 rx_defrag_init_called_read 3 35935 NULL
111783 +put_cmsg_compat_35937 put_cmsg_compat 4 35937 NULL
111784 +ext_rts51x_sd_execute_write_data_35971 ext_rts51x_sd_execute_write_data 9 35971 NULL
111785 +ceph_buffer_new_35974 ceph_buffer_new 1 35974 NULL nohasharray
111786 +generic_ocp_read_35974 generic_ocp_read 3 35974 &ceph_buffer_new_35974
111787 +acl_alloc_35979 acl_alloc 1 35979 NULL
111788 +device_add_class_symlinks_35985 device_add_class_symlinks 0 35985 NULL
111789 +generic_file_aio_read_35987 generic_file_aio_read 0 35987 NULL
111790 +write_file_antenna_35998 write_file_antenna 3 35998 NULL nohasharray
111791 +kuc_alloc_35998 kuc_alloc 1 35998 &write_file_antenna_35998
111792 +il3945_ucode_tx_stats_read_36016 il3945_ucode_tx_stats_read 3 36016 NULL
111793 +__videobuf_alloc_36031 __videobuf_alloc 1 36031 NULL
111794 +account_shadowed_36048 account_shadowed 2 36048 NULL
111795 +gpio_power_read_36059 gpio_power_read 3 36059 NULL
111796 +write_emulate_36065 write_emulate 2-4 36065 NULL
111797 +stack_max_size_write_36068 stack_max_size_write 3 36068 NULL
111798 +radeon_vm_num_pdes_36070 radeon_vm_num_pdes 0 36070 NULL
111799 +ieee80211_if_fmt_peer_36071 ieee80211_if_fmt_peer 3 36071 NULL
111800 +ieee80211_if_write_tsf_36077 ieee80211_if_write_tsf 3 36077 NULL
111801 +snd_pcm_plug_read_transfer_36080 snd_pcm_plug_read_transfer 0-3 36080 NULL
111802 +mtip_hw_read_device_status_36082 mtip_hw_read_device_status 3 36082 NULL
111803 +vga_arb_write_36112 vga_arb_write 3 36112 NULL
111804 +simple_xattr_alloc_36118 simple_xattr_alloc 2 36118 NULL
111805 +ext3_readpages_36144 ext3_readpages 4 36144 NULL
111806 +twl_set_36154 twl_set 2 36154 NULL
111807 +b1_alloc_card_36155 b1_alloc_card 1 36155 NULL
111808 +btrfs_file_extent_inline_len_36158 btrfs_file_extent_inline_len 0 36158 NULL
111809 +snd_korg1212_copy_from_36169 snd_korg1212_copy_from 6 36169 NULL
111810 +SyS_kexec_load_36176 SyS_kexec_load 2 36176 NULL
111811 +ramoops_init_przs_36199 ramoops_init_przs 4 36199 NULL
111812 +SYSC_sched_getaffinity_36208 SYSC_sched_getaffinity 2 36208 NULL
111813 +SYSC_process_vm_readv_36216 SYSC_process_vm_readv 3-5 36216 NULL
111814 +atomic_stats_read_36228 atomic_stats_read 3 36228 NULL
111815 +viafb_iga1_odev_proc_write_36241 viafb_iga1_odev_proc_write 3 36241 NULL
111816 +SYSC_getxattr_36242 SYSC_getxattr 4 36242 NULL
111817 +rproc_recovery_read_36245 rproc_recovery_read 3 36245 NULL
111818 +scrub_stripe_36248 scrub_stripe 5-4 36248 NULL
111819 +compat_sys_mbind_36256 compat_sys_mbind 5 36256 NULL
111820 +usb_buffer_alloc_36276 usb_buffer_alloc 2 36276 NULL nohasharray
111821 +cfs_hash_buckets_realloc_36276 cfs_hash_buckets_realloc 4 36276 &usb_buffer_alloc_36276
111822 +codec_reg_read_file_36280 codec_reg_read_file 3 36280 NULL
111823 +crypto_shash_digestsize_36284 crypto_shash_digestsize 0 36284 NULL
111824 +nouveau_cli_create_36293 nouveau_cli_create 3 36293 NULL
111825 +lpfc_debugfs_dif_err_read_36303 lpfc_debugfs_dif_err_read 3 36303 NULL
111826 +cfg80211_rx_mlme_mgmt_36306 cfg80211_rx_mlme_mgmt 3 36306 NULL
111827 +ad7879_spi_xfer_36311 ad7879_spi_xfer 3 36311 NULL
111828 +fat_compat_ioctl_filldir_36328 fat_compat_ioctl_filldir 3 36328 NULL
111829 +lc_create_36332 lc_create 4 36332 NULL
111830 +jbd2_journal_init_revoke_table_36336 jbd2_journal_init_revoke_table 1 36336 NULL
111831 +isku_sysfs_read_key_mask_36343 isku_sysfs_read_key_mask 6 36343 NULL
111832 +ath6kl_regwrite_write_36351 ath6kl_regwrite_write 3 36351 NULL
111833 +v9fs_file_readn_36353 v9fs_file_readn 4 36353 NULL
111834 +to_sector_36361 to_sector 0-1 36361 NULL
111835 +tunables_read_36385 tunables_read 3 36385 NULL
111836 +afs_alloc_flat_call_36399 afs_alloc_flat_call 2-3 36399 NULL
111837 +sierra_write_36402 sierra_write 4 36402 NULL
111838 +iwl_dbgfs_d3_sram_write_36403 iwl_dbgfs_d3_sram_write 3 36403 NULL
111839 +SyS_sethostname_36417 SyS_sethostname 2 36417 NULL
111840 +ReadW6692B_36445 ReadW6692B 0 36445 NULL
111841 +sctp_tsnmap_init_36446 sctp_tsnmap_init 2 36446 NULL
111842 +alloc_etherdev_mqs_36450 alloc_etherdev_mqs 1 36450 NULL
111843 +SyS_process_vm_writev_36476 SyS_process_vm_writev 3-5 36476 NULL
111844 +b43_nphy_load_samples_36481 b43_nphy_load_samples 3 36481 NULL
111845 +tx_tx_checksum_result_read_36490 tx_tx_checksum_result_read 3 36490 NULL nohasharray
111846 +ip6_append_data_36490 ip6_append_data 4 36490 &tx_tx_checksum_result_read_36490
111847 +cmd_loop_36491 cmd_loop 0 36491 NULL
111848 +__hwahc_op_set_ptk_36510 __hwahc_op_set_ptk 5 36510 NULL
111849 +mcam_v4l_read_36513 mcam_v4l_read 3 36513 NULL
111850 +get_param_l_36518 get_param_l 0 36518 NULL
111851 +ieee80211_if_read_fwded_frames_36520 ieee80211_if_read_fwded_frames 3 36520 NULL
111852 +crypto_aead_authsize_36537 crypto_aead_authsize 0 36537 NULL
111853 +cpu_type_read_36540 cpu_type_read 3 36540 NULL
111854 +__kfifo_to_user_36555 __kfifo_to_user 3-0 36555 NULL nohasharray
111855 +macvtap_do_read_36555 macvtap_do_read 4 36555 &__kfifo_to_user_36555
111856 +btrfs_get_token_64_36572 btrfs_get_token_64 0 36572 NULL
111857 +__erst_read_36579 __erst_read 0 36579 NULL
111858 +put_cmsg_36589 put_cmsg 4 36589 NULL
111859 +fat_ioctl_filldir_36621 fat_ioctl_filldir 3 36621 NULL
111860 +vxge_config_vpaths_36636 vxge_config_vpaths 0 36636 NULL
111861 +convert_extent_item_v0_36645 convert_extent_item_v0 4 36645 NULL
111862 +ced_ioctl_36647 ced_ioctl 2 36647 NULL
111863 +lpfc_idiag_extacc_alloc_get_36648 lpfc_idiag_extacc_alloc_get 0-3 36648 NULL
111864 +osd_req_list_collection_objects_36664 osd_req_list_collection_objects 5 36664 NULL
111865 +iscsi_host_alloc_36671 iscsi_host_alloc 2 36671 NULL
111866 +xillybus_read_36678 xillybus_read 3 36678 NULL
111867 +gsmtty_write_36702 gsmtty_write 3 36702 NULL
111868 +snd_rawmidi_kernel_read1_36740 snd_rawmidi_kernel_read1 4-0 36740 NULL
111869 +cxgbi_device_register_36746 cxgbi_device_register 1-2 36746 NULL
111870 +ps_poll_upsd_timeouts_read_36755 ps_poll_upsd_timeouts_read 3 36755 NULL
111871 +ptp_filter_init_36780 ptp_filter_init 2 36780 NULL
111872 +i40e_init_lan_hmc_36796 i40e_init_lan_hmc 2-3-4-5 36796 NULL
111873 +proc_fault_inject_read_36802 proc_fault_inject_read 3 36802 NULL
111874 +hiddev_ioctl_36816 hiddev_ioctl 2 36816 NULL
111875 +int_hardware_entry_36833 int_hardware_entry 3 36833 NULL
111876 +fc_change_queue_depth_36841 fc_change_queue_depth 2 36841 NULL
111877 +keyctl_describe_key_36853 keyctl_describe_key 3 36853 NULL
111878 +cm_write_36858 cm_write 3 36858 NULL
111879 +tx_tx_data_programmed_read_36871 tx_tx_data_programmed_read 3 36871 NULL
111880 +svc_setsockopt_36876 svc_setsockopt 5 36876 NULL
111881 +raid56_parity_write_36877 raid56_parity_write 5 36877 NULL
111882 +__btrfs_map_block_36883 __btrfs_map_block 3 36883 NULL
111883 +ib_ucm_alloc_data_36885 ib_ucm_alloc_data 3 36885 NULL
111884 +selinux_inode_notifysecctx_36896 selinux_inode_notifysecctx 3 36896 NULL
111885 +OS_kmalloc_36909 OS_kmalloc 1 36909 NULL
111886 +audio_set_endpoint_req_36918 audio_set_endpoint_req 0 36918 NULL
111887 +crypto_blkcipher_ivsize_36944 crypto_blkcipher_ivsize 0 36944 NULL
111888 +il4965_rs_sta_dbgfs_scale_table_write_36979 il4965_rs_sta_dbgfs_scale_table_write 3 36979 NULL
111889 +drbd_new_dev_size_36998 drbd_new_dev_size 0-3 36998 NULL
111890 +auok190xfb_write_37001 auok190xfb_write 3 37001 NULL
111891 +setxattr_37006 setxattr 4 37006 NULL
111892 +ocfs2_dlm_unlock_37037 ocfs2_dlm_unlock 0 37037 NULL
111893 +command_file_read_37038 command_file_read 3 37038 NULL
111894 +figure_loop_size_37051 figure_loop_size 2-3 37051 NULL
111895 +ieee80211_if_read_drop_unencrypted_37053 ieee80211_if_read_drop_unencrypted 3 37053 NULL nohasharray
111896 +qp_broker_create_37053 qp_broker_create 6-5 37053 &ieee80211_if_read_drop_unencrypted_37053
111897 +SYSC_setxattr_37078 SYSC_setxattr 4 37078 NULL
111898 +parse_command_37079 parse_command 2 37079 NULL
111899 +pipeline_cs_rx_packet_in_read_37089 pipeline_cs_rx_packet_in_read 3 37089 NULL
111900 +tun_get_user_37094 tun_get_user 5 37094 NULL
111901 +has_wrprotected_page_37123 has_wrprotected_page 3-2 37123 NULL
111902 +snd_hda_get_conn_list_37132 snd_hda_get_conn_list 0 37132 NULL
111903 +mtt_free_res_37144 mtt_free_res 5 37144 NULL
111904 +msg_word_37164 msg_word 0 37164 NULL
111905 +f2fs_direct_IO_37167 f2fs_direct_IO 4 37167 NULL
111906 +can_set_xattr_37182 can_set_xattr 4 37182 NULL
111907 +vcc_recvmsg_37198 vcc_recvmsg 4 37198 NULL
111908 +sysfs_add_file_37200 sysfs_add_file 0 37200 NULL
111909 +forced_ps_write_37209 forced_ps_write 3 37209 NULL
111910 +crypto_shash_descsize_37212 crypto_shash_descsize 0 37212 NULL nohasharray
111911 +ext4_ind_direct_IO_37212 ext4_ind_direct_IO 0-4 37212 &crypto_shash_descsize_37212
111912 +bchannel_get_rxbuf_37213 bchannel_get_rxbuf 2-0 37213 NULL
111913 +regmap_access_read_file_37223 regmap_access_read_file 3 37223 NULL
111914 +__do_replace_37227 __do_replace 5 37227 NULL
111915 +iwl_dbgfs_d3_sram_read_37237 iwl_dbgfs_d3_sram_read 3 37237 NULL
111916 +rx_filter_dup_filter_read_37238 rx_filter_dup_filter_read 3 37238 NULL
111917 +exofs_max_io_pages_37263 exofs_max_io_pages 0-2 37263 NULL
111918 +ieee80211_if_read_power_mode_37305 ieee80211_if_read_power_mode 3 37305 NULL
111919 +ext3_direct_IO_37308 ext3_direct_IO 4 37308 NULL
111920 +ocfs2_calc_extend_credits_37310 ocfs2_calc_extend_credits 0 37310 NULL
111921 +jffs2_write_dirent_37311 jffs2_write_dirent 5 37311 NULL
111922 +send_msg_37323 send_msg 4 37323 NULL
111923 +l2cap_create_connless_pdu_37327 l2cap_create_connless_pdu 3 37327 NULL nohasharray
111924 +bnx2x_vf_fill_fw_str_37327 bnx2x_vf_fill_fw_str 3 37327 &l2cap_create_connless_pdu_37327
111925 +scsi_mode_select_37330 scsi_mode_select 6 37330 NULL
111926 +rxrpc_server_sendmsg_37331 rxrpc_server_sendmsg 4 37331 NULL
111927 +security_inode_getsecurity_37354 security_inode_getsecurity 0 37354 NULL
111928 +hci_sock_sendmsg_37420 hci_sock_sendmsg 4 37420 NULL
111929 +acpi_os_allocate_zeroed_37422 acpi_os_allocate_zeroed 1 37422 NULL
111930 +tty_insert_flip_string_fixed_flag_37428 tty_insert_flip_string_fixed_flag 4-0 37428 NULL
111931 +iwl_print_last_event_logs_37433 iwl_print_last_event_logs 7-9-0 37433 NULL
111932 +fru_alloc_37442 fru_alloc 1 37442 NULL
111933 +tcp_established_options_37450 tcp_established_options 0 37450 NULL nohasharray
111934 +tipc_send2port_37450 tipc_send2port 4 37450 &tcp_established_options_37450
111935 +brcmf_sdio_dump_console_37455 brcmf_sdio_dump_console 4 37455 NULL
111936 +get_est_timing_37484 get_est_timing 0 37484 NULL
111937 +kmem_realloc_37489 kmem_realloc 2 37489 NULL
111938 +__hfsplus_setxattr_37499 __hfsplus_setxattr 4 37499 NULL
111939 +bitmap_dirty_bits_37503 bitmap_dirty_bits 2 37503 NULL
111940 +osc_active_seq_write_37514 osc_active_seq_write 3 37514 NULL
111941 +bdev_writeseg_37519 bdev_writeseg 2-3 37519 NULL
111942 +xz_dec_test_write_37527 xz_dec_test_write 3 37527 NULL
111943 +fault_inject_read_37534 fault_inject_read 3 37534 NULL
111944 +hdr_size_37536 hdr_size 0 37536 NULL
111945 +extent_map_end_37550 extent_map_end 0 37550 NULL
111946 +sep_create_dcb_dmatables_context_37551 sep_create_dcb_dmatables_context 6 37551 NULL
111947 +ioat_chansts_37558 ioat_chansts 0 37558 NULL
111948 +xhci_alloc_streams_37586 xhci_alloc_streams 5 37586 NULL
111949 +qla2x00_debounce_register_37597 qla2x00_debounce_register 0 37597 NULL
111950 +kvm_read_guest_page_mmu_37611 kvm_read_guest_page_mmu 6 37611 NULL
111951 +SYSC_mbind_37622 SYSC_mbind 5 37622 NULL
111952 +SyS_mbind_37638 SyS_mbind 5 37638 NULL
111953 +bio_copy_user_iov_37660 bio_copy_user_iov 4 37660 NULL
111954 +rfcomm_sock_sendmsg_37661 rfcomm_sock_sendmsg 4 37661 NULL nohasharray
111955 +vmw_framebuffer_dmabuf_dirty_37661 vmw_framebuffer_dmabuf_dirty 6 37661 &rfcomm_sock_sendmsg_37661
111956 +SYSC_get_mempolicy_37664 SYSC_get_mempolicy 3 37664 NULL
111957 +__wa_seg_calculate_isoc_frame_count_37672 __wa_seg_calculate_isoc_frame_count 0 37672 NULL
111958 +ieee80211_if_read_rc_rateidx_mcs_mask_2ghz_37675 ieee80211_if_read_rc_rateidx_mcs_mask_2ghz 3 37675 NULL
111959 +regmap_map_read_file_37685 regmap_map_read_file 3 37685 NULL
111960 +page_chain_free_37697 page_chain_free 0 37697 NULL
111961 +nametbl_header_37698 nametbl_header 2-0 37698 NULL
111962 +__le32_to_cpup_37702 __le32_to_cpup 0 37702 NULL
111963 +dynamic_ps_timeout_write_37713 dynamic_ps_timeout_write 3 37713 NULL
111964 +read_enabled_file_bool_37744 read_enabled_file_bool 3 37744 NULL
111965 +ocfs2_control_cfu_37750 ocfs2_control_cfu 2 37750 NULL
111966 +ipath_cdev_init_37752 ipath_cdev_init 1 37752 NULL
111967 +dccp_setsockopt_cscov_37766 dccp_setsockopt_cscov 2 37766 NULL
111968 +il4965_rs_sta_dbgfs_rate_scale_data_read_37792 il4965_rs_sta_dbgfs_rate_scale_data_read 3 37792 NULL
111969 +smk_read_logging_37804 smk_read_logging 3 37804 NULL
111970 +ocrdma_alloc_frmr_page_list_37815 ocrdma_alloc_frmr_page_list 2 37815 NULL
111971 +rx_decrypt_key_not_found_read_37820 rx_decrypt_key_not_found_read 3 37820 NULL
111972 +android_get_p2p_addr_37832 android_get_p2p_addr 0 37832 NULL
111973 +jbd2_journal_get_undo_access_37837 jbd2_journal_get_undo_access 0 37837 NULL
111974 +o2hb_debug_read_37851 o2hb_debug_read 3 37851 NULL
111975 +xfs_dir2_block_to_sf_37868 xfs_dir2_block_to_sf 3 37868 NULL
111976 +set_registers_37883 set_registers 4 37883 NULL
111977 +btrfs_stack_file_extent_disk_bytenr_37888 btrfs_stack_file_extent_disk_bytenr 0 37888 NULL
111978 +pkt_alloc_packet_data_37928 pkt_alloc_packet_data 1 37928 NULL nohasharray
111979 +_rtw_malloc_37928 _rtw_malloc 1 37928 &pkt_alloc_packet_data_37928
111980 +read_rbu_packet_size_37939 read_rbu_packet_size 6 37939 NULL
111981 +write_file_bool_37957 write_file_bool 3 37957 NULL
111982 +fifo_alloc_37961 fifo_alloc 1 37961 NULL
111983 +rds_rdma_extra_size_37990 rds_rdma_extra_size 0 37990 NULL
111984 +persistent_ram_old_size_37997 persistent_ram_old_size 0 37997 NULL
111985 +vfs_readv_38011 vfs_readv 3 38011 NULL
111986 +aggr_recv_addba_req_evt_38037 aggr_recv_addba_req_evt 4 38037 NULL
111987 +il_dbgfs_chain_noise_read_38044 il_dbgfs_chain_noise_read 3 38044 NULL nohasharray
111988 +klsi_105_prepare_write_buffer_38044 klsi_105_prepare_write_buffer 3 38044 &il_dbgfs_chain_noise_read_38044
111989 +SyS_llistxattr_38048 SyS_llistxattr 3 38048 NULL
111990 +sysfs_do_create_link_38051 sysfs_do_create_link 0 38051 NULL
111991 +_xfs_buf_alloc_38058 _xfs_buf_alloc 3 38058 NULL
111992 +nsm_create_handle_38060 nsm_create_handle 4 38060 NULL
111993 +alloc_ltalkdev_38071 alloc_ltalkdev 1 38071 NULL
111994 +xfs_buf_readahead_map_38081 xfs_buf_readahead_map 3 38081 NULL nohasharray
111995 +wcn36xx_smd_rsp_process_38081 wcn36xx_smd_rsp_process 3 38081 &xfs_buf_readahead_map_38081
111996 +uwb_mac_addr_print_38085 uwb_mac_addr_print 2 38085 NULL
111997 +request_key_auth_new_38092 request_key_auth_new 3 38092 NULL
111998 +proc_self_readlink_38094 proc_self_readlink 3 38094 NULL
111999 +ep0_read_38095 ep0_read 3 38095 NULL
112000 +sk_wmem_schedule_38096 sk_wmem_schedule 2 38096 NULL nohasharray
112001 +osc_checksum_seq_write_38096 osc_checksum_seq_write 3 38096 &sk_wmem_schedule_38096
112002 +o2hb_read_slots_38105 o2hb_read_slots 2 38105 NULL
112003 +snd_pcm_oss_write_38108 snd_pcm_oss_write 3 38108 NULL
112004 +vmw_kms_present_38130 vmw_kms_present 9 38130 NULL
112005 +__ntfs_copy_from_user_iovec_inatomic_38153 __ntfs_copy_from_user_iovec_inatomic 0-4-3 38153 NULL
112006 +btrfs_extent_same_38163 btrfs_extent_same 3-2 38163 NULL
112007 +kvm_clear_guest_38164 kvm_clear_guest 3-2 38164 NULL
112008 +cdev_add_38176 cdev_add 2-3 38176 NULL
112009 +rt2x00debug_write_rf_38195 rt2x00debug_write_rf 3 38195 NULL
112010 +get_ucode_user_38202 get_ucode_user 3 38202 NULL
112011 +osd_req_list_partition_collections_38223 osd_req_list_partition_collections 5 38223 NULL
112012 +ceph_decode_16_38239 ceph_decode_16 0 38239 NULL
112013 +_ipw_read_reg32_38245 _ipw_read_reg32 0 38245 NULL
112014 +mthca_alloc_icm_table_38268 mthca_alloc_icm_table 4-3 38268 NULL nohasharray
112015 +ieee80211_if_read_auto_open_plinks_38268 ieee80211_if_read_auto_open_plinks 3 38268 &mthca_alloc_icm_table_38268 nohasharray
112016 +SYSC_msgrcv_38268 SYSC_msgrcv 3 38268 &ieee80211_if_read_auto_open_plinks_38268
112017 +xfs_bmbt_to_bmdr_38275 xfs_bmbt_to_bmdr 3 38275 NULL nohasharray
112018 +xfs_bmdr_to_bmbt_38275 xfs_bmdr_to_bmbt 5 38275 &xfs_bmbt_to_bmdr_38275
112019 +ftdi_process_packet_38281 ftdi_process_packet 4 38281 NULL
112020 +ucma_query_path_38305 ucma_query_path 3 38305 NULL
112021 +isr_rx_headers_read_38325 isr_rx_headers_read 3 38325 NULL
112022 +ida_simple_get_38326 ida_simple_get 0 38326 NULL
112023 +__snd_gf1_look8_38333 __snd_gf1_look8 0 38333 NULL
112024 +btrfs_file_extent_disk_num_bytes_38363 btrfs_file_extent_disk_num_bytes 0 38363 NULL
112025 +xfs_free_file_space_38383 xfs_free_file_space 2-3 38383 NULL
112026 +dn_sendmsg_38390 dn_sendmsg 4 38390 NULL
112027 +ieee80211_if_read_dtim_count_38419 ieee80211_if_read_dtim_count 3 38419 NULL
112028 +pmcraid_copy_sglist_38431 pmcraid_copy_sglist 3 38431 NULL
112029 +kvm_write_guest_38454 kvm_write_guest 4-2 38454 NULL
112030 +blk_end_bidi_request_38482 blk_end_bidi_request 3-4 38482 NULL
112031 +dev_names_read_38509 dev_names_read 3 38509 NULL
112032 +iscsi_create_iface_38510 iscsi_create_iface 5 38510 NULL
112033 +event_rx_mismatch_read_38518 event_rx_mismatch_read 3 38518 NULL
112034 +ubifs_idx_node_sz_38546 ubifs_idx_node_sz 0-2 38546 NULL
112035 +btrfs_discard_extent_38547 btrfs_discard_extent 2 38547 NULL
112036 +kuc_len_38557 kuc_len 0-1 38557 NULL
112037 +irda_sendmsg_dgram_38563 irda_sendmsg_dgram 4 38563 NULL
112038 +il4965_rs_sta_dbgfs_scale_table_read_38564 il4965_rs_sta_dbgfs_scale_table_read 3 38564 NULL
112039 +_ipw_read32_38565 _ipw_read32 0 38565 NULL
112040 +snd_nm256_playback_copy_38567 snd_nm256_playback_copy 5-3 38567 NULL
112041 +copy_ctl_value_to_user_38587 copy_ctl_value_to_user 4 38587 NULL
112042 +icn_writecmd_38629 icn_writecmd 2 38629 NULL
112043 +write_enabled_file_bool_38630 write_enabled_file_bool 3 38630 NULL
112044 +ext2_readpages_38640 ext2_readpages 4 38640 NULL
112045 +audit_init_entry_38644 audit_init_entry 1 38644 NULL
112046 +qp_broker_alloc_38646 qp_broker_alloc 6-5 38646 NULL
112047 +mmc_send_cxd_data_38655 mmc_send_cxd_data 5 38655 NULL
112048 +nouveau_instmem_create__38664 nouveau_instmem_create_ 4 38664 NULL
112049 +snd_es1371_wait_src_ready_38673 snd_es1371_wait_src_ready 0 38673 NULL
112050 +iscsit_dump_data_payload_38683 iscsit_dump_data_payload 2 38683 NULL
112051 +rbio_add_io_page_38700 rbio_add_io_page 6 38700 NULL
112052 +alloc_trace_probe_38720 alloc_trace_probe 6 38720 NULL
112053 +w83977af_sir_interrupt_38738 w83977af_sir_interrupt 0 38738 NULL
112054 +udf_readpages_38761 udf_readpages 4 38761 NULL
112055 +iwl_dbgfs_thermal_throttling_read_38779 iwl_dbgfs_thermal_throttling_read 3 38779 NULL
112056 +bcache_device_init_38781 bcache_device_init 3 38781 NULL
112057 +snd_gus_dram_write_38784 snd_gus_dram_write 4 38784 NULL
112058 +slab_order_38794 slab_order 0 38794 NULL
112059 +do_pci_enable_device_38802 do_pci_enable_device 0 38802 NULL
112060 +err_decode_38804 err_decode 2 38804 NULL
112061 +ipv6_renew_option_38813 ipv6_renew_option 3 38813 NULL
112062 +direct_entry_38836 direct_entry 3 38836 NULL
112063 +compat_udp_setsockopt_38840 compat_udp_setsockopt 5 38840 NULL
112064 +read_nic_io_word_38853 read_nic_io_word 0 38853 NULL
112065 +interfaces_38859 interfaces 2 38859 NULL
112066 +pci_msix_table_size_38867 pci_msix_table_size 0 38867 NULL
112067 +dbgfs_state_38894 dbgfs_state 3 38894 NULL
112068 +f2fs_xattr_set_acl_38895 f2fs_xattr_set_acl 4 38895 NULL
112069 +il_dbgfs_sram_write_38942 il_dbgfs_sram_write 3 38942 NULL
112070 +__ath6kl_wmi_send_mgmt_cmd_38971 __ath6kl_wmi_send_mgmt_cmd 7 38971 NULL
112071 +usb_maxpacket_38977 usb_maxpacket 0 38977 NULL nohasharray
112072 +C_SYSC_preadv64_38977 C_SYSC_preadv64 3 38977 &usb_maxpacket_38977
112073 +OSDSetBlock_38986 OSDSetBlock 2-4 38986 NULL
112074 +lpfc_idiag_extacc_write_38998 lpfc_idiag_extacc_write 3 38998 NULL
112075 +get_nodes_39012 get_nodes 3 39012 NULL
112076 +twl6030_interrupt_unmask_39013 twl6030_interrupt_unmask 2 39013 NULL
112077 +__blkdev_issue_zeroout_39020 __blkdev_issue_zeroout 3 39020 NULL
112078 +_zd_iowrite32v_async_locked_39034 _zd_iowrite32v_async_locked 3 39034 NULL
112079 +do_write_kmem_39051 do_write_kmem 0-1-3 39051 NULL
112080 +ReadHFC_39104 ReadHFC 0 39104 NULL
112081 +tomoyo_truncate_39105 tomoyo_truncate 0 39105 NULL
112082 +__kfifo_to_user_r_39123 __kfifo_to_user_r 5-3 39123 NULL
112083 +ea_foreach_39133 ea_foreach 0 39133 NULL
112084 +generic_permission_39150 generic_permission 0 39150 NULL
112085 +proc_coredump_filter_read_39153 proc_coredump_filter_read 3 39153 NULL
112086 +ath9k_hw_ar9003_dump_eeprom_39156 ath9k_hw_ar9003_dump_eeprom 5-4 39156 NULL
112087 +echo_client_kbrw_39170 echo_client_kbrw 6 39170 NULL
112088 +ext3_xattr_check_names_39174 ext3_xattr_check_names 0 39174 NULL
112089 +ubi_more_update_data_39189 ubi_more_update_data 4 39189 NULL
112090 +qcam_read_bytes_39205 qcam_read_bytes 0 39205 NULL
112091 +ivtv_v4l2_write_39226 ivtv_v4l2_write 3 39226 NULL
112092 +posix_acl_to_xattr_39237 posix_acl_to_xattr 0 39237 NULL
112093 +snd_pcm_capture_forward_39248 snd_pcm_capture_forward 2 39248 NULL
112094 +r128_compat_ioctl_39250 r128_compat_ioctl 2 39250 NULL nohasharray
112095 +pwr_cont_miss_bcns_spread_read_39250 pwr_cont_miss_bcns_spread_read 3 39250 &r128_compat_ioctl_39250
112096 +i915_error_state_read_39254 i915_error_state_read 3 39254 NULL
112097 +rx_filter_protection_filter_read_39282 rx_filter_protection_filter_read 3 39282 NULL
112098 +__cfg80211_connect_result_39326 __cfg80211_connect_result 4-6 39326 NULL
112099 +insert_reserved_file_extent_39327 insert_reserved_file_extent 3 39327 NULL
112100 +wimax_msg_alloc_39343 wimax_msg_alloc 4 39343 NULL
112101 +ide_complete_rq_39354 ide_complete_rq 3 39354 NULL
112102 +do_write_log_from_user_39362 do_write_log_from_user 3-0 39362 NULL
112103 +vortex_wtdma_getlinearpos_39371 vortex_wtdma_getlinearpos 0 39371 NULL
112104 +regmap_name_read_file_39379 regmap_name_read_file 3 39379 NULL
112105 +fnic_trace_debugfs_read_39380 fnic_trace_debugfs_read 3 39380 NULL
112106 +ps_poll_ps_poll_utilization_read_39383 ps_poll_ps_poll_utilization_read 3 39383 NULL
112107 +__send_to_port_39386 __send_to_port 3 39386 NULL
112108 +user_power_read_39414 user_power_read 3 39414 NULL
112109 +alloc_agpphysmem_i8xx_39427 alloc_agpphysmem_i8xx 1 39427 NULL
112110 +mic_desc_size_39464 mic_desc_size 0 39464 NULL
112111 +apei_resources_add_39470 apei_resources_add 0 39470 NULL
112112 +setkey_unaligned_39474 setkey_unaligned 3 39474 NULL
112113 +ieee80211_if_fmt_dot11MeshHWMPmaxPREQretries_39499 ieee80211_if_fmt_dot11MeshHWMPmaxPREQretries 3 39499 NULL
112114 +cl_req_alloc_39523 cl_req_alloc 4 39523 NULL
112115 +int_proc_write_39542 int_proc_write 3 39542 NULL
112116 +mdc_unpack_capa_39553 mdc_unpack_capa 0 39553 NULL
112117 +pp_write_39554 pp_write 3 39554 NULL
112118 +datablob_format_39571 datablob_format 2 39571 NULL nohasharray
112119 +ieee80211_if_read_fwded_mcast_39571 ieee80211_if_read_fwded_mcast 3 39571 &datablob_format_39571
112120 +ext_depth_39607 ext_depth 0 39607 NULL
112121 +batadv_tt_tvlv_generate_39615 batadv_tt_tvlv_generate 4 39615 NULL
112122 +nfs_idmap_get_key_39616 nfs_idmap_get_key 2 39616 NULL
112123 +sdio_readb_39618 sdio_readb 0 39618 NULL
112124 +set_dev_class_39645 set_dev_class 4 39645 NULL
112125 +snd_rme32_capture_copy_39653 snd_rme32_capture_copy 5 39653 NULL
112126 +tcp_try_rmem_schedule_39657 tcp_try_rmem_schedule 3 39657 NULL
112127 +kvm_read_guest_cached_39666 kvm_read_guest_cached 4 39666 NULL
112128 +v4l_stk_read_39672 v4l_stk_read 3 39672 NULL
112129 +hsc_msg_len_get_39673 hsc_msg_len_get 0 39673 NULL
112130 +do_surface_dirty_sou_39678 do_surface_dirty_sou 7 39678 NULL
112131 +sd_completed_bytes_39705 sd_completed_bytes 0 39705 NULL
112132 +ftrace_pid_write_39710 ftrace_pid_write 3 39710 NULL
112133 +adt7316_spi_multi_read_39765 adt7316_spi_multi_read 3 39765 NULL
112134 +security_inode_listsecurity_39812 security_inode_listsecurity 0 39812 NULL
112135 +snd_pcm_oss_writev3_39818 snd_pcm_oss_writev3 3 39818 NULL
112136 +get_priv_size_39828 get_priv_size 0-1 39828 NULL
112137 +pkt_add_39897 pkt_add 3 39897 NULL
112138 +read_file_modal_eeprom_39909 read_file_modal_eeprom 3 39909 NULL
112139 +gen_pool_add_virt_39913 gen_pool_add_virt 4 39913 NULL
112140 +dw210x_op_rw_39915 dw210x_op_rw 6 39915 NULL
112141 +aes_encrypt_interrupt_read_39919 aes_encrypt_interrupt_read 3 39919 NULL
112142 +exofs_read_kern_39921 exofs_read_kern 6 39921 NULL nohasharray
112143 +oom_score_adj_read_39921 oom_score_adj_read 3 39921 &exofs_read_kern_39921
112144 +__spi_async_39932 __spi_async 0 39932 NULL
112145 +__get_order_39935 __get_order 0 39935 NULL
112146 +error_error_frame_read_39947 error_error_frame_read 3 39947 NULL
112147 +tty_prepare_flip_string_39955 tty_prepare_flip_string 3-0 39955 NULL
112148 +lstcon_group_list_39958 lstcon_group_list 2 39958 NULL
112149 +dma_push_rx_39973 dma_push_rx 2 39973 NULL
112150 +broadsheetfb_write_39976 broadsheetfb_write 3 39976 NULL
112151 +mthca_array_init_39987 mthca_array_init 2 39987 NULL
112152 +fw_device_op_read_39990 fw_device_op_read 3 39990 NULL
112153 +server_name2svname_39998 server_name2svname 4 39998 NULL
112154 +xen_hvm_config_40018 xen_hvm_config 2 40018 NULL
112155 +ivtvfb_write_40023 ivtvfb_write 3 40023 NULL
112156 +disc_pwup_write_40027 disc_pwup_write 3 40027 NULL
112157 +ea_foreach_i_40028 ea_foreach_i 0 40028 NULL
112158 +datablob_hmac_append_40038 datablob_hmac_append 3 40038 NULL
112159 +l2cap_create_iframe_pdu_40055 l2cap_create_iframe_pdu 3 40055 NULL nohasharray
112160 +add_tty_40055 add_tty 1 40055 &l2cap_create_iframe_pdu_40055
112161 +atomic_xchg_40070 atomic_xchg 0 40070 NULL
112162 +sctp_setsockopt_delayed_ack_40129 sctp_setsockopt_delayed_ack 3 40129 NULL
112163 +dwc2_max_desc_num_40132 dwc2_max_desc_num 0 40132 NULL
112164 +rx_rx_frame_checksum_read_40140 rx_rx_frame_checksum_read 3 40140 NULL
112165 +ath10k_write_simulate_fw_crash_40143 ath10k_write_simulate_fw_crash 3 40143 NULL
112166 +iwch_alloc_fastreg_pbl_40153 iwch_alloc_fastreg_pbl 2 40153 NULL
112167 +pt_write_40159 pt_write 3 40159 NULL
112168 +scsi_sg_count_40182 scsi_sg_count 0 40182 NULL
112169 +ipr_alloc_ucode_buffer_40199 ipr_alloc_ucode_buffer 1 40199 NULL
112170 +allocate_probes_40204 allocate_probes 1 40204 NULL
112171 +au0828_v4l2_read_40220 au0828_v4l2_read 3 40220 NULL
112172 +compress_file_range_40225 compress_file_range 3-4 40225 NULL
112173 +osst_read_40237 osst_read 3 40237 NULL
112174 +lpage_info_slot_40243 lpage_info_slot 3-1 40243 NULL
112175 +ocfs2_zero_extend_get_range_40248 ocfs2_zero_extend_get_range 4-3 40248 NULL
112176 +ptlrpc_queue_wait_40252 ptlrpc_queue_wait 0 40252 NULL
112177 +rs_sta_dbgfs_scale_table_read_40262 rs_sta_dbgfs_scale_table_read 3 40262 NULL
112178 +ext2_fiemap_40271 ext2_fiemap 4 40271 NULL
112179 +usbnet_read_cmd_40275 usbnet_read_cmd 7 40275 NULL
112180 +rx_xfr_hint_trig_read_40283 rx_xfr_hint_trig_read 3 40283 NULL
112181 +SyS_bind_40303 SyS_bind 3 40303 NULL
112182 +ib_get_mad_data_offset_40336 ib_get_mad_data_offset 0 40336 NULL
112183 +mmio_read_40348 mmio_read 4 40348 NULL
112184 +event_rx_mem_empty_read_40363 event_rx_mem_empty_read 3 40363 NULL
112185 +ocfs2_check_range_for_refcount_40365 ocfs2_check_range_for_refcount 3-2 40365 NULL
112186 +get_chars_40373 get_chars 3 40373 NULL
112187 +fb_prepare_extra_logos_40429 fb_prepare_extra_logos 0-2 40429 NULL
112188 +tomoyo_update_policy_40458 tomoyo_update_policy 2 40458 NULL
112189 +zd_usb_scnprint_id_40459 zd_usb_scnprint_id 0-3 40459 NULL
112190 +gp2ap020a00f_write_event_threshold_40461 gp2ap020a00f_write_event_threshold 2 40461 NULL
112191 +SyS_writev_40467 SyS_writev 3 40467 NULL
112192 +SyS_select_40473 SyS_select 1 40473 NULL
112193 +afs_fs_store_data_40484 afs_fs_store_data 3-4-5-6 40484 NULL
112194 +batadv_hash_new_40491 batadv_hash_new 1 40491 NULL
112195 +devcgroup_inode_permission_40492 devcgroup_inode_permission 0 40492 NULL
112196 +__ethtool_get_sset_count_40511 __ethtool_get_sset_count 0 40511 NULL
112197 +TSS_checkhmac2_40520 TSS_checkhmac2 5-7 40520 NULL
112198 +ixgbe_dbg_reg_ops_read_40540 ixgbe_dbg_reg_ops_read 3 40540 NULL
112199 +ima_write_policy_40548 ima_write_policy 3 40548 NULL
112200 +esp_alloc_tmp_40558 esp_alloc_tmp 3-2 40558 NULL
112201 +b1_get_byte_40597 b1_get_byte 0 40597 NULL
112202 +get_priv_descr_and_size_40612 get_priv_descr_and_size 0 40612 NULL
112203 +twl4030_kpwrite_u8_40665 twl4030_kpwrite_u8 3 40665 NULL
112204 +__cfg80211_roamed_40668 __cfg80211_roamed 4-6 40668 NULL
112205 +pipeline_rx_complete_stat_fifo_int_read_40671 pipeline_rx_complete_stat_fifo_int_read 3 40671 NULL
112206 +fops_read_40672 fops_read 3 40672 NULL
112207 +idr_get_empty_slot_40674 idr_get_empty_slot 0 40674 NULL
112208 +alloc_rbio_40676 alloc_rbio 4 40676 NULL
112209 +videobuf_dma_init_user_locked_40678 videobuf_dma_init_user_locked 4-3 40678 NULL
112210 +pci_enable_resources_40680 pci_enable_resources 0 40680 NULL
112211 +nfc_hci_set_param_40697 nfc_hci_set_param 5 40697 NULL
112212 +__seq_open_private_40715 __seq_open_private 3 40715 NULL
112213 +fuse_readpages_40737 fuse_readpages 4 40737 NULL
112214 +xfs_iext_remove_direct_40744 xfs_iext_remove_direct 3 40744 NULL
112215 +security_inode_listxattr_40752 security_inode_listxattr 0 40752 NULL
112216 +card_send_command_40757 card_send_command 3 40757 NULL
112217 +ad1889_readl_40765 ad1889_readl 0 40765 NULL
112218 +pg_write_40766 pg_write 3 40766 NULL
112219 +show_list_40775 show_list 3-0 40775 NULL
112220 +kfifo_out_copy_r_40784 kfifo_out_copy_r 3-0 40784 NULL
112221 +bitmap_weight_40791 bitmap_weight 0-2 40791 NULL
112222 +pyra_sysfs_read_40795 pyra_sysfs_read 6 40795 NULL
112223 +add_action_40811 add_action 4 40811 NULL
112224 +nl80211_send_roamed_40825 nl80211_send_roamed 5-7 40825 NULL
112225 +SyS_mbind_40828 SyS_mbind 5 40828 NULL
112226 +nilfs_mdt_init_40849 nilfs_mdt_init 3 40849 NULL
112227 +v9fs_file_read_40858 v9fs_file_read 3 40858 NULL
112228 +read_file_queue_40895 read_file_queue 3 40895 NULL
112229 +waiters_read_40902 waiters_read 3 40902 NULL
112230 +isdn_add_channels_40905 isdn_add_channels 3 40905 NULL
112231 +gfs2_ea_find_40913 gfs2_ea_find 0 40913 NULL
112232 +vol_cdev_write_40915 vol_cdev_write 3 40915 NULL
112233 +snd_vx_create_40948 snd_vx_create 4 40948 NULL nohasharray
112234 +sg_alloc_table_40948 sg_alloc_table 0 40948 &snd_vx_create_40948
112235 +rds_sendmsg_40976 rds_sendmsg 4 40976 NULL
112236 +il_dbgfs_fh_reg_read_40993 il_dbgfs_fh_reg_read 3 40993 NULL
112237 +iwl_dbgfs_scan_ant_rxchain_read_40999 iwl_dbgfs_scan_ant_rxchain_read 3 40999 NULL
112238 +mac80211_format_buffer_41010 mac80211_format_buffer 2 41010 NULL
112239 +__proc_dobitmasks_41029 __proc_dobitmasks 5 41029 NULL
112240 +_req_append_segment_41031 _req_append_segment 2 41031 NULL
112241 +mISDN_sock_sendmsg_41035 mISDN_sock_sendmsg 4 41035 NULL
112242 +ocfs2_xattr_index_block_find_41040 ocfs2_xattr_index_block_find 0 41040 NULL
112243 +lprocfs_write_frac_helper_41050 lprocfs_write_frac_helper 2 41050 NULL
112244 +calculate_order_41061 calculate_order 0 41061 NULL
112245 +vfs_listxattr_41062 vfs_listxattr 0 41062 NULL nohasharray
112246 +beacon_filtering_write_41062 beacon_filtering_write 3 41062 &vfs_listxattr_41062
112247 +cfg80211_inform_bss_frame_41078 cfg80211_inform_bss_frame 4 41078 NULL
112248 +nvme_map_user_pages_41093 nvme_map_user_pages 4-3 41093 NULL nohasharray
112249 +roccat_read_41093 roccat_read 3 41093 &nvme_map_user_pages_41093
112250 +dma_attach_41094 dma_attach 5-6 41094 NULL
112251 +provide_user_output_41105 provide_user_output 3 41105 NULL
112252 +f_audio_buffer_alloc_41110 f_audio_buffer_alloc 1 41110 NULL
112253 +ath10k_read_wmi_services_41112 ath10k_read_wmi_services 3 41112 NULL
112254 +ocfs2_extend_trans_41116 ocfs2_extend_trans 2 41116 NULL
112255 +v4l2_ctrl_new_int_menu_41151 v4l2_ctrl_new_int_menu 4 41151 NULL
112256 +tx_frag_mpdu_alloc_failed_read_41167 tx_frag_mpdu_alloc_failed_read 3 41167 NULL
112257 +dvb_ca_write_41171 dvb_ca_write 3 41171 NULL
112258 +dgap_driver_kzmalloc_41189 dgap_driver_kzmalloc 1 41189 NULL
112259 +compat_sys_process_vm_writev_41194 compat_sys_process_vm_writev 3-5 41194 NULL
112260 +dfs_file_write_41196 dfs_file_write 3 41196 NULL
112261 +nfs_page_array_len_41219 nfs_page_array_len 0-2-1 41219 NULL
112262 +cfg80211_process_disassoc_41231 cfg80211_process_disassoc 3 41231 NULL
112263 +hiddev_compat_ioctl_41255 hiddev_compat_ioctl 2 41255 NULL
112264 +erst_read_41260 erst_read 0 41260 NULL
112265 +alloc_context_41283 alloc_context 1 41283 NULL
112266 +o2hb_setup_one_bio_41341 o2hb_setup_one_bio 4 41341 NULL
112267 +twl_change_queue_depth_41342 twl_change_queue_depth 2 41342 NULL
112268 +rtw_android_set_block_41347 rtw_android_set_block 0 41347 NULL
112269 +cnic_init_id_tbl_41354 cnic_init_id_tbl 2 41354 NULL
112270 +kmp_init_41373 kmp_init 2 41373 NULL
112271 +isr_commands_read_41398 isr_commands_read 3 41398 NULL
112272 +rx_defrag_decrypt_failed_read_41411 rx_defrag_decrypt_failed_read 3 41411 NULL
112273 +xfs_iext_add_41422 xfs_iext_add 3 41422 NULL
112274 +isdn_ppp_fill_rq_41428 isdn_ppp_fill_rq 2 41428 NULL
112275 +lbs_rdrf_read_41431 lbs_rdrf_read 3 41431 NULL
112276 +iio_device_alloc_41440 iio_device_alloc 1 41440 NULL
112277 +ntfs_file_buffered_write_41442 ntfs_file_buffered_write 6-4 41442 NULL
112278 +pcpu_build_alloc_info_41443 pcpu_build_alloc_info 1-2-3 41443 NULL
112279 +se_io_cb_41461 se_io_cb 3 41461 NULL
112280 +layout_leb_in_gaps_41470 layout_leb_in_gaps 0 41470 NULL
112281 +rt2x00debug_write_rfcsr_41473 rt2x00debug_write_rfcsr 3 41473 NULL
112282 +bl_alloc_init_bio_41478 bl_alloc_init_bio 1 41478 NULL
112283 +kvm_unmap_hva_range_41484 kvm_unmap_hva_range 3-2 41484 NULL
112284 +wep_interrupt_read_41492 wep_interrupt_read 3 41492 NULL
112285 +SyS_get_mempolicy_41495 SyS_get_mempolicy 3 41495 NULL
112286 +hpfs_translate_name_41497 hpfs_translate_name 3 41497 NULL
112287 +xfrm_hash_new_size_41505 xfrm_hash_new_size 0-1 41505 NULL
112288 +SyS_preadv_41523 SyS_preadv 3 41523 NULL
112289 +dm_get_reserved_rq_based_ios_41529 dm_get_reserved_rq_based_ios 0 41529 NULL
112290 +tx_tx_frame_checksum_read_41553 tx_tx_frame_checksum_read 3 41553 NULL
112291 +ath6kl_endpoint_stats_read_41554 ath6kl_endpoint_stats_read 3 41554 NULL
112292 +nr_status_frames_41559 nr_status_frames 0-1 41559 NULL nohasharray
112293 +si476x_radio_fops_read_41559 si476x_radio_fops_read 3 41559 &nr_status_frames_41559
112294 +rng_dev_read_41581 rng_dev_read 3 41581 NULL
112295 +batadv_tvlv_container_ogm_append_41588 batadv_tvlv_container_ogm_append 4 41588 NULL
112296 +vga_io_r_41609 vga_io_r 0 41609 NULL
112297 +tcp_hdrlen_41610 tcp_hdrlen 0 41610 NULL
112298 +lbs_bcnmiss_write_41613 lbs_bcnmiss_write 3 41613 NULL nohasharray
112299 +usb_endpoint_maxp_41613 usb_endpoint_maxp 0 41613 &lbs_bcnmiss_write_41613
112300 +a2mp_send_41615 a2mp_send 4 41615 NULL
112301 +lstcon_batch_list_41627 lstcon_batch_list 2 41627 NULL
112302 +mempool_create_kmalloc_pool_41650 mempool_create_kmalloc_pool 1 41650 NULL
112303 +rx_rx_pre_complt_read_41653 rx_rx_pre_complt_read 3 41653 NULL
112304 +get_std_timing_41654 get_std_timing 0 41654 NULL
112305 +ieee80211_if_fmt_bssid_41677 ieee80211_if_fmt_bssid 3 41677 NULL
112306 +fill_pcm_stream_name_41685 fill_pcm_stream_name 2 41685 NULL
112307 +lov_unpackmd_41701 lov_unpackmd 4 41701 NULL
112308 +apei_exec_for_each_entry_41717 apei_exec_for_each_entry 0 41717 NULL
112309 +fillonedir_41746 fillonedir 3 41746 NULL
112310 +iwl_dbgfs_bt_notif_read_41794 iwl_dbgfs_bt_notif_read 3 41794 NULL
112311 +hsi_alloc_controller_41802 hsi_alloc_controller 1 41802 NULL
112312 +rtw_android_get_macaddr_41812 rtw_android_get_macaddr 0 41812 NULL
112313 +sco_send_frame_41815 sco_send_frame 3 41815 NULL
112314 +ixgbe_dbg_netdev_ops_read_41839 ixgbe_dbg_netdev_ops_read 3 41839 NULL
112315 +do_ip_setsockopt_41852 do_ip_setsockopt 5 41852 NULL
112316 +keyctl_instantiate_key_41855 keyctl_instantiate_key 3 41855 NULL
112317 +pci_map_single_41869 pci_map_single 0 41869 NULL
112318 +usb_gadget_get_string_41871 usb_gadget_get_string 0 41871 NULL
112319 +v_APCI3120_InterruptDmaMoveBlock16bit_41914 v_APCI3120_InterruptDmaMoveBlock16bit 4 41914 NULL
112320 +get_fdb_entries_41916 get_fdb_entries 3 41916 NULL
112321 +nfsd_getxattr_41934 nfsd_getxattr 0 41934 NULL
112322 +ext4_da_write_inline_data_begin_41935 ext4_da_write_inline_data_begin 3-4 41935 NULL
112323 +sci_rxfill_41945 sci_rxfill 0 41945 NULL
112324 +read_gssp_41947 read_gssp 3 41947 NULL
112325 +ocfs2_xattr_bucket_get_name_value_41949 ocfs2_xattr_bucket_get_name_value 0 41949 NULL
112326 +portnames_read_41958 portnames_read 3 41958 NULL
112327 +dst_mtu_41969 dst_mtu 0 41969 NULL
112328 +cx24116_writeregN_41975 cx24116_writeregN 4 41975 NULL
112329 +pool_allocate_42012 pool_allocate 3 42012 NULL
112330 +spidev_sync_read_42014 spidev_sync_read 0 42014 NULL
112331 +rs_sta_dbgfs_scale_table_write_42017 rs_sta_dbgfs_scale_table_write 3 42017 NULL
112332 +create_dir_42025 create_dir 0 42025 NULL
112333 +acpi_ut_create_buffer_object_42030 acpi_ut_create_buffer_object 1 42030 NULL
112334 +__btrfs_drop_extents_42032 __btrfs_drop_extents 5 42032 NULL
112335 +__hwahc_op_set_gtk_42038 __hwahc_op_set_gtk 4 42038 NULL
112336 +irda_sendmsg_ultra_42047 irda_sendmsg_ultra 4 42047 NULL
112337 +jffs2_do_link_42048 jffs2_do_link 6 42048 NULL
112338 +ps_poll_upsd_max_ap_turn_read_42050 ps_poll_upsd_max_ap_turn_read 3 42050 NULL
112339 +InterfaceTransmitPacket_42058 InterfaceTransmitPacket 3 42058 NULL
112340 +scsi_execute_req_42088 scsi_execute_req 5 42088 NULL
112341 +sk_chk_filter_42095 sk_chk_filter 2 42095 NULL
112342 +submit_inquiry_42108 submit_inquiry 3 42108 NULL
112343 +dw_dma_cyclic_prep_42113 dw_dma_cyclic_prep 3-4 42113 NULL
112344 +obd_get_info_42156 obd_get_info 0 42156 NULL
112345 +blk_ioctl_zeroout_42160 blk_ioctl_zeroout 3 42160 NULL
112346 +mmc_align_data_size_42161 mmc_align_data_size 0-2 42161 NULL
112347 +read_file_base_eeprom_42168 read_file_base_eeprom 3 42168 NULL
112348 +oprofilefs_str_to_user_42182 oprofilefs_str_to_user 3 42182 NULL
112349 +write_file_beacon_42185 write_file_beacon 3 42185 NULL
112350 +get_znodes_to_commit_42201 get_znodes_to_commit 0 42201 NULL
112351 +pla_ocp_read_42235 pla_ocp_read 3 42235 NULL
112352 +rx_defrag_need_decrypt_read_42253 rx_defrag_need_decrypt_read 3 42253 NULL
112353 +find_last_bit_42260 find_last_bit 0 42260 NULL
112354 +__pcpu_size_to_slot_42271 __pcpu_size_to_slot 0 42271 NULL
112355 +snd_pcm_hw_param_value_max_42280 snd_pcm_hw_param_value_max 0 42280 NULL
112356 +__cpus_weight_42299 __cpus_weight 2-0 42299 NULL
112357 +sel_read_perm_42302 sel_read_perm 3 42302 NULL
112358 +sctp_setsockopt_del_key_42304 sctp_setsockopt_del_key 3 42304 NULL nohasharray
112359 +ulong_read_file_42304 ulong_read_file 3 42304 &sctp_setsockopt_del_key_42304
112360 +xfs_vm_readpages_42308 xfs_vm_readpages 4 42308 NULL
112361 +hysdn_conf_read_42324 hysdn_conf_read 3 42324 NULL
112362 +tcp_sync_mss_42330 tcp_sync_mss 2-0 42330 NULL
112363 +ide_raw_taskfile_42355 ide_raw_taskfile 4 42355 NULL
112364 +tipc_send_42374 tipc_send 3 42374 NULL
112365 +drbd_md_last_sector_42378 drbd_md_last_sector 0 42378 NULL
112366 +il_dbgfs_disable_ht40_read_42386 il_dbgfs_disable_ht40_read 3 42386 NULL
112367 +msnd_fifo_read_42406 msnd_fifo_read 0-3 42406 NULL
112368 +krng_get_random_42420 krng_get_random 3 42420 NULL
112369 +gsm_data_alloc_42437 gsm_data_alloc 3 42437 NULL
112370 +key_conf_keyidx_read_42443 key_conf_keyidx_read 3 42443 NULL
112371 +alloc_request_42448 alloc_request 0 42448 NULL
112372 +snd_pcm_action_group_42452 snd_pcm_action_group 0 42452 NULL
112373 +tcm_loop_change_queue_depth_42454 tcm_loop_change_queue_depth 2 42454 NULL
112374 +kuc_free_42455 kuc_free 2 42455 NULL
112375 +__simple_xattr_set_42474 __simple_xattr_set 4 42474 NULL
112376 +omfs_readpages_42490 omfs_readpages 4 42490 NULL
112377 +bypass_write_42498 bypass_write 3 42498 NULL
112378 +SyS_mincore_42511 SyS_mincore 1-2 42511 NULL
112379 +kvm_write_wall_clock_42520 kvm_write_wall_clock 2 42520 NULL
112380 +dio_bio_complete_42524 dio_bio_complete 0 42524 NULL
112381 +smk_write_netlbladdr_42525 smk_write_netlbladdr 3 42525 NULL
112382 +dbAllocNear_42546 dbAllocNear 0 42546 NULL
112383 +ath6kl_wmi_proc_events_vif_42549 ath6kl_wmi_proc_events_vif 5 42549 NULL
112384 +udp_recvmsg_42558 udp_recvmsg 4 42558 NULL
112385 +iwl_print_event_log_42566 iwl_print_event_log 7-5-0 42566 NULL
112386 +xfrm_new_hash_mask_42579 xfrm_new_hash_mask 0-1 42579 NULL
112387 +oom_score_adj_write_42594 oom_score_adj_write 3 42594 NULL
112388 +ieee80211_if_fmt_dot11MeshHWMPactivePathTimeout_42635 ieee80211_if_fmt_dot11MeshHWMPactivePathTimeout 3 42635 NULL
112389 +scsi_activate_tcq_42640 scsi_activate_tcq 2 42640 NULL
112390 +br_mdb_rehash_42643 br_mdb_rehash 2 42643 NULL
112391 +parport_pc_compat_write_block_pio_42644 parport_pc_compat_write_block_pio 3 42644 NULL
112392 +_regmap_raw_write_42652 _regmap_raw_write 4-2 42652 NULL
112393 +request_key_and_link_42693 request_key_and_link 4 42693 NULL
112394 +vb2_read_42703 vb2_read 3 42703 NULL
112395 +read_status_42722 read_status 0 42722 NULL
112396 +dvb_demux_ioctl_42733 dvb_demux_ioctl 2 42733 NULL
112397 +set_aoe_iflist_42737 set_aoe_iflist 2 42737 NULL
112398 +ax25_setsockopt_42740 ax25_setsockopt 5 42740 NULL
112399 +dpm_sysfs_add_42756 dpm_sysfs_add 0 42756 NULL
112400 +x25_recvmsg_42777 x25_recvmsg 4 42777 NULL
112401 +snd_midi_event_decode_42780 snd_midi_event_decode 0 42780 NULL
112402 +cryptd_hash_setkey_42781 cryptd_hash_setkey 3 42781 NULL nohasharray
112403 +isku_sysfs_read_info_42781 isku_sysfs_read_info 6 42781 &cryptd_hash_setkey_42781
112404 +elfcorehdr_read_notes_42786 elfcorehdr_read_notes 2 42786 NULL
112405 +koneplus_sysfs_read_42792 koneplus_sysfs_read 6 42792 NULL
112406 +ptlrpc_request_bufs_pack_42793 ptlrpc_request_bufs_pack 0 42793 NULL
112407 +ntfs_attr_extend_allocation_42796 ntfs_attr_extend_allocation 0 42796 NULL
112408 +fw_device_op_compat_ioctl_42804 fw_device_op_compat_ioctl 2 42804 NULL
112409 +drm_ioctl_42813 drm_ioctl 2 42813 NULL
112410 +iwl_dbgfs_ucode_bt_stats_read_42820 iwl_dbgfs_ucode_bt_stats_read 3 42820 NULL
112411 +set_arg_42824 set_arg 3 42824 NULL
112412 +si476x_radio_read_rsq_blob_42827 si476x_radio_read_rsq_blob 3 42827 NULL
112413 +ocfs2_clusters_for_bytes_42872 ocfs2_clusters_for_bytes 0-2 42872 NULL
112414 +nvme_trans_unit_serial_page_42879 nvme_trans_unit_serial_page 4 42879 NULL
112415 +xpc_kmalloc_cacheline_aligned_42895 xpc_kmalloc_cacheline_aligned 1 42895 NULL
112416 +hd_end_request_42904 hd_end_request 2 42904 NULL
112417 +sta_last_rx_rate_read_42909 sta_last_rx_rate_read 3 42909 NULL
112418 +sctp_getsockopt_maxburst_42941 sctp_getsockopt_maxburst 2 42941 NULL nohasharray
112419 +mdc_unpack_acl_42941 mdc_unpack_acl 0 42941 &sctp_getsockopt_maxburst_42941
112420 +vx_reset_chk_42946 vx_reset_chk 0 42946 NULL
112421 +blkdev_direct_IO_42962 blkdev_direct_IO 4 42962 NULL
112422 +read_file_node_stat_42964 read_file_node_stat 3 42964 NULL
112423 +compat_udpv6_setsockopt_42981 compat_udpv6_setsockopt 5 42981 NULL
112424 +nfs_idmap_get_desc_42990 nfs_idmap_get_desc 4-2 42990 NULL nohasharray
112425 +rtw_os_xmit_resource_alloc_42990 rtw_os_xmit_resource_alloc 3 42990 &nfs_idmap_get_desc_42990
112426 +isr_rx_mem_overflow_read_43025 isr_rx_mem_overflow_read 3 43025 NULL
112427 +wep_default_key_count_read_43035 wep_default_key_count_read 3 43035 NULL
112428 +nouveau_gpuobj_create__43072 nouveau_gpuobj_create_ 9 43072 NULL
112429 +nfs_map_group_to_gid_43082 nfs_map_group_to_gid 3 43082 NULL
112430 +_xfer_secondary_pool_43089 _xfer_secondary_pool 2 43089 NULL
112431 +sysfs_create_file_ns_43103 sysfs_create_file_ns 0 43103 NULL
112432 +ieee80211_if_fmt_drop_unencrypted_43107 ieee80211_if_fmt_drop_unencrypted 3 43107 NULL
112433 +calculate_node_totalpages_43118 calculate_node_totalpages 2-3 43118 NULL
112434 +read_file_dfs_43145 read_file_dfs 3 43145 NULL
112435 +cfs_cpt_table_alloc_43159 cfs_cpt_table_alloc 1 43159 NULL
112436 +usb_string_sub_43164 usb_string_sub 0 43164 NULL
112437 +il_dbgfs_power_save_status_read_43165 il_dbgfs_power_save_status_read 3 43165 NULL
112438 +ath6kl_set_assoc_req_ies_43185 ath6kl_set_assoc_req_ies 3 43185 NULL
112439 +ext4_xattr_ibody_get_43200 ext4_xattr_ibody_get 0 43200 NULL
112440 +uio_write_43202 uio_write 3 43202 NULL
112441 +iso_callback_43208 iso_callback 3 43208 NULL
112442 +ath10k_p2p_calc_noa_ie_len_43209 ath10k_p2p_calc_noa_ie_len 0 43209 NULL
112443 +f2fs_acl_from_disk_43210 f2fs_acl_from_disk 2 43210 NULL
112444 +atomic_long_add_return_43217 atomic_long_add_return 1-0 43217 NULL
112445 +batadv_tt_tvlv_unicast_handler_v1_43239 batadv_tt_tvlv_unicast_handler_v1 5 43239 NULL
112446 +vmemmap_alloc_block_43245 vmemmap_alloc_block 1 43245 NULL
112447 +ide_end_rq_43269 ide_end_rq 4 43269 NULL
112448 +nilfs_direct_IO_43271 nilfs_direct_IO 4 43271 NULL
112449 +parport_pc_ecp_write_block_pio_43278 parport_pc_ecp_write_block_pio 3 43278 NULL nohasharray
112450 +evtchn_write_43278 evtchn_write 3 43278 &parport_pc_ecp_write_block_pio_43278
112451 +filemap_write_and_wait_range_43279 filemap_write_and_wait_range 0 43279 NULL
112452 +mpage_alloc_43299 mpage_alloc 3 43299 NULL
112453 +mmu_set_spte_43327 mmu_set_spte 7-6 43327 NULL
112454 +__ext4_get_inode_loc_43332 __ext4_get_inode_loc 0 43332 NULL
112455 +xenfb_write_43412 xenfb_write 3 43412 NULL
112456 +__alloc_bootmem_low_43423 __alloc_bootmem_low 1 43423 NULL
112457 +usb_alloc_urb_43436 usb_alloc_urb 1 43436 NULL
112458 +ath6kl_wmi_roam_tbl_event_rx_43440 ath6kl_wmi_roam_tbl_event_rx 3 43440 NULL
112459 +usb_string_43443 usb_string 0 43443 NULL nohasharray
112460 +usemap_size_43443 usemap_size 0-2-1 43443 &usb_string_43443
112461 +get_vm_area_size_43444 get_vm_area_size 0 43444 NULL
112462 +nvme_trans_device_id_page_43466 nvme_trans_device_id_page 4 43466 NULL
112463 +tx_tx_data_prepared_read_43497 tx_tx_data_prepared_read 3 43497 NULL
112464 +ieee80211_if_fmt_dot11MeshHWMPnetDiameterTraversalTime_43505 ieee80211_if_fmt_dot11MeshHWMPnetDiameterTraversalTime 3 43505 NULL
112465 +do_readlink_43518 do_readlink 2 43518 NULL
112466 +dvb_ca_en50221_io_write_43533 dvb_ca_en50221_io_write 3 43533 NULL
112467 +read_events_43534 read_events 3 43534 NULL
112468 +cachefiles_daemon_write_43535 cachefiles_daemon_write 3 43535 NULL
112469 +tx_frag_failed_read_43540 tx_frag_failed_read 3 43540 NULL
112470 +request_resource_43548 request_resource 0 43548 NULL
112471 +rpc_malloc_43573 rpc_malloc 2 43573 NULL
112472 +handle_frequent_errors_43599 handle_frequent_errors 4 43599 NULL
112473 +lpfc_idiag_drbacc_read_reg_43606 lpfc_idiag_drbacc_read_reg 0-3 43606 NULL
112474 +proc_read_43614 proc_read 3 43614 NULL
112475 +disable_dma_on_even_43618 disable_dma_on_even 0 43618 NULL
112476 +alloc_thread_groups_43625 alloc_thread_groups 2 43625 NULL
112477 +random_write_43656 random_write 3 43656 NULL
112478 +bio_integrity_tag_43658 bio_integrity_tag 3 43658 NULL
112479 +ext4_acl_count_43659 ext4_acl_count 0-1 43659 NULL
112480 +write_file_tx99_power_43670 write_file_tx99_power 3 43670 NULL
112481 +dmam_declare_coherent_memory_43679 dmam_declare_coherent_memory 4 43679 NULL
112482 +max77693_bulk_write_43698 max77693_bulk_write 2-3 43698 NULL
112483 +drbd_md_first_sector_43729 drbd_md_first_sector 0 43729 NULL
112484 +snd_rme32_playback_copy_43732 snd_rme32_playback_copy 5 43732 NULL
112485 +fuse_conn_congestion_threshold_write_43736 fuse_conn_congestion_threshold_write 3 43736 NULL
112486 +gigaset_initcs_43753 gigaset_initcs 2 43753 NULL
112487 +sctp_setsockopt_active_key_43755 sctp_setsockopt_active_key 3 43755 NULL
112488 +ocfs2_xattr_get_value_outside_43787 ocfs2_xattr_get_value_outside 0 43787 NULL nohasharray
112489 +byte_pos_43787 byte_pos 0-2 43787 &ocfs2_xattr_get_value_outside_43787
112490 +btrfs_copy_from_user_43806 btrfs_copy_from_user 0-3-1 43806 NULL
112491 +ieee80211_if_fmt_element_ttl_43825 ieee80211_if_fmt_element_ttl 3 43825 NULL
112492 +ieee80211_alloc_hw_43829 ieee80211_alloc_hw 1 43829 NULL
112493 +read_flush_43851 read_flush 3 43851 NULL
112494 +pm860x_bulk_write_43875 pm860x_bulk_write 2-3 43875 NULL
112495 +SendString_43928 SendString 3 43928 NULL
112496 +stats_dot11RTSFailureCount_read_43948 stats_dot11RTSFailureCount_read 3 43948 NULL
112497 +__get_required_blob_size_43980 __get_required_blob_size 0-3-2 43980 NULL
112498 +nla_reserve_43984 nla_reserve 3 43984 NULL
112499 +__clkdev_alloc_43990 __clkdev_alloc 1 43990 NULL
112500 +scsi_command_size_43992 scsi_command_size 0 43992 NULL nohasharray
112501 +kvm_read_guest_virt_43992 kvm_read_guest_virt 4-2 43992 &scsi_command_size_43992 nohasharray
112502 +bcm_recvmsg_43992 bcm_recvmsg 4 43992 &kvm_read_guest_virt_43992
112503 +emit_flags_44006 emit_flags 4-3 44006 NULL
112504 +write_flush_procfs_44011 write_flush_procfs 3 44011 NULL
112505 +fru_strlen_44046 fru_strlen 0 44046 NULL
112506 +ath9k_def_dump_modal_eeprom_44078 ath9k_def_dump_modal_eeprom 3-2-0 44078 NULL
112507 +SYSC_add_key_44079 SYSC_add_key 4 44079 NULL
112508 +__vxge_hw_vpath_tim_configure_44093 __vxge_hw_vpath_tim_configure 2 44093 NULL
112509 +xlog_recover_add_to_cont_trans_44102 xlog_recover_add_to_cont_trans 4 44102 NULL
112510 +skb_frag_dma_map_44112 skb_frag_dma_map 0 44112 NULL
112511 +tracing_set_trace_read_44122 tracing_set_trace_read 3 44122 NULL
112512 +SyS_process_vm_writev_44129 SyS_process_vm_writev 3-5 44129 NULL
112513 +ttm_get_pages_44142 ttm_get_pages 2 44142 NULL
112514 +scsi_get_resid_44147 scsi_get_resid 0 44147 NULL
112515 +ocfs2_xattr_bucket_find_44174 ocfs2_xattr_bucket_find 0 44174 NULL
112516 +SYSC_set_mempolicy_44176 SYSC_set_mempolicy 3 44176 NULL
112517 +readreg_ipac_44186 readreg_ipac 0 44186 NULL
112518 +handle_eviocgbit_44193 handle_eviocgbit 3 44193 NULL
112519 +srp_alloc_iu_44227 srp_alloc_iu 2 44227 NULL
112520 +scsi_track_queue_full_44239 scsi_track_queue_full 2 44239 NULL
112521 +sigma_action_write_regmap_44240 sigma_action_write_regmap 3 44240 NULL
112522 +apei_resources_sub_44252 apei_resources_sub 0 44252 NULL
112523 +device_create_file_44285 device_create_file 0 44285 NULL
112524 +ath6kl_keepalive_read_44303 ath6kl_keepalive_read 3 44303 NULL
112525 +bitmap_scnprintf_44318 bitmap_scnprintf 0-2 44318 NULL
112526 +dispatch_proc_write_44320 dispatch_proc_write 3 44320 NULL
112527 +rs_init_44327 rs_init 1 44327 NULL
112528 +blk_queue_init_tags_44355 blk_queue_init_tags 2 44355 NULL nohasharray
112529 +nfs_fscache_get_super_cookie_44355 nfs_fscache_get_super_cookie 3 44355 &blk_queue_init_tags_44355
112530 +alloc_requests_44372 alloc_requests 0 44372 NULL
112531 +rts_threshold_read_44384 rts_threshold_read 3 44384 NULL
112532 +mtip_hw_read_flags_44396 mtip_hw_read_flags 3 44396 NULL
112533 +aoedev_flush_44398 aoedev_flush 2 44398 NULL
112534 +strlcpy_44400 strlcpy 3 44400 NULL
112535 +drm_buffer_alloc_44405 drm_buffer_alloc 2 44405 NULL
112536 +osst_do_scsi_44410 osst_do_scsi 4 44410 NULL
112537 +ieee80211_if_read_rc_rateidx_mcs_mask_5ghz_44423 ieee80211_if_read_rc_rateidx_mcs_mask_5ghz 3 44423 NULL
112538 +iwl_dbgfs_bf_params_write_44450 iwl_dbgfs_bf_params_write 3 44450 NULL
112539 +write_file_debug_44476 write_file_debug 3 44476 NULL
112540 +btrfs_chunk_item_size_44478 btrfs_chunk_item_size 0-1 44478 NULL
112541 +sdio_align_size_44489 sdio_align_size 0-2 44489 NULL
112542 +bio_advance_44496 bio_advance 2 44496 NULL
112543 +ieee80211_if_read_dropped_frames_ttl_44500 ieee80211_if_read_dropped_frames_ttl 3 44500 NULL
112544 +ac_register_board_44504 ac_register_board 3 44504 NULL
112545 +security_getprocattr_44505 security_getprocattr 0 44505 NULL nohasharray
112546 +iwl_dbgfs_sram_read_44505 iwl_dbgfs_sram_read 3 44505 &security_getprocattr_44505
112547 +spidev_write_44510 spidev_write 3 44510 NULL
112548 +SyS_io_getevents_44519 SyS_io_getevents 3 44519 NULL
112549 +ieee80211_rx_mgmt_assoc_resp_44525 ieee80211_rx_mgmt_assoc_resp 3 44525 NULL
112550 +comm_write_44537 comm_write 3 44537 NULL
112551 +xfs_log_calc_unit_res_44540 xfs_log_calc_unit_res 0-2 44540 NULL
112552 +dgrp_config_proc_write_44571 dgrp_config_proc_write 3 44571 NULL
112553 +nouveau_perfmon_create__44602 nouveau_perfmon_create_ 4 44602 NULL
112554 +alloc_ctrl_packet_44667 alloc_ctrl_packet 1 44667 NULL
112555 +mpi_resize_44674 mpi_resize 2 44674 NULL
112556 +sysfs_create_link_44685 sysfs_create_link 0 44685 NULL
112557 +ts_read_44687 ts_read 3 44687 NULL
112558 +lov_emerg_alloc_44698 lov_emerg_alloc 1 44698 NULL
112559 +__ocfs2_rotate_tree_left_44705 __ocfs2_rotate_tree_left 3 44705 NULL
112560 +xfer_to_user_44713 xfer_to_user 3 44713 NULL nohasharray
112561 +__generic_block_fiemap_44713 __generic_block_fiemap 4 44713 &xfer_to_user_44713
112562 +_zd_iowrite32v_locked_44725 _zd_iowrite32v_locked 3 44725 NULL
112563 +clusterip_proc_write_44729 clusterip_proc_write 3 44729 NULL
112564 +fib_count_nexthops_44730 fib_count_nexthops 0 44730 NULL
112565 +key_tx_rx_count_read_44742 key_tx_rx_count_read 3 44742 NULL
112566 +tnode_new_44757 tnode_new 3 44757 NULL nohasharray
112567 +pty_write_44757 pty_write 3 44757 &tnode_new_44757
112568 +__videobuf_copy_stream_44769 __videobuf_copy_stream 4-0 44769 NULL
112569 +handsfree_ramp_44777 handsfree_ramp 2 44777 NULL
112570 +irq_domain_add_legacy_44781 irq_domain_add_legacy 4-2 44781 NULL
112571 +sctp_setsockopt_44788 sctp_setsockopt 5 44788 NULL
112572 +rx_dropped_read_44799 rx_dropped_read 3 44799 NULL
112573 +qla4xxx_alloc_work_44813 qla4xxx_alloc_work 2 44813 NULL
112574 +mei_cl_read_start_44824 mei_cl_read_start 2 44824 NULL
112575 +rmap_write_protect_44833 rmap_write_protect 2 44833 NULL
112576 +sisusb_write_44834 sisusb_write 3 44834 NULL
112577 +kvm_read_hva_44847 kvm_read_hva 3 44847 NULL
112578 +qib_verbs_send_dma_44850 qib_verbs_send_dma 6 44850 NULL
112579 +copydesc_user_44855 copydesc_user 3 44855 NULL
112580 +set_advertising_44870 set_advertising 4 44870 NULL
112581 +init_rs_44873 init_rs 1 44873 NULL
112582 +skb_availroom_44883 skb_availroom 0 44883 NULL
112583 +ocfs2_wait_for_mask_44893 ocfs2_wait_for_mask 0 44893 NULL
112584 +do_tty_write_44896 do_tty_write 5 44896 NULL
112585 +regmap_spi_read_44921 regmap_spi_read 3-5 44921 NULL
112586 +tx_queue_status_read_44978 tx_queue_status_read 3 44978 NULL
112587 +bytepos_delta_45017 bytepos_delta 0-2 45017 NULL
112588 +ptrace_writedata_45021 ptrace_writedata 4 45021 NULL
112589 +dm_kvzalloc_45025 dm_kvzalloc 1 45025 NULL
112590 +vhci_get_user_45039 vhci_get_user 3 45039 NULL
112591 +sysfs_do_create_link_sd_45057 sysfs_do_create_link_sd 0 45057 NULL
112592 +sel_write_user_45060 sel_write_user 3 45060 NULL
112593 +snd_mixart_BA0_read_45069 snd_mixart_BA0_read 5 45069 NULL
112594 +kvm_mmu_page_get_gfn_45110 kvm_mmu_page_get_gfn 0-2 45110 NULL
112595 +pwr_missing_bcns_cnt_read_45113 pwr_missing_bcns_cnt_read 3 45113 NULL
112596 +usbdev_read_45114 usbdev_read 3 45114 NULL
112597 +send_to_tty_45141 send_to_tty 3 45141 NULL
112598 +cfs_trace_daemon_command_usrstr_45147 cfs_trace_daemon_command_usrstr 2 45147 NULL
112599 +gen_bitmask_string_45149 gen_bitmask_string 6 45149 NULL
112600 +device_write_45156 device_write 3 45156 NULL nohasharray
112601 +ocfs2_remove_inode_range_45156 ocfs2_remove_inode_range 3-4 45156 &device_write_45156
112602 +tomoyo_write_self_45161 tomoyo_write_self 3 45161 NULL
112603 +sta_agg_status_write_45164 sta_agg_status_write 3 45164 NULL
112604 +snd_sb_csp_load_user_45190 snd_sb_csp_load_user 3 45190 NULL nohasharray
112605 +sctp_pack_cookie_45190 sctp_pack_cookie 6 45190 &snd_sb_csp_load_user_45190
112606 +iso_alloc_urb_45206 iso_alloc_urb 4-5 45206 NULL
112607 +spi_alloc_master_45223 spi_alloc_master 2 45223 NULL
112608 +ieee80211_if_read_peer_45233 ieee80211_if_read_peer 3 45233 NULL
112609 +event_enable_write_45238 event_enable_write 3 45238 NULL
112610 +prism2_pda_proc_read_45246 prism2_pda_proc_read 3 45246 NULL
112611 +input_mt_init_slots_45279 input_mt_init_slots 2 45279 NULL
112612 +gfs2_fiemap_45282 gfs2_fiemap 4 45282 NULL
112613 +snd_pcm_oss_sync1_45298 snd_pcm_oss_sync1 2 45298 NULL
112614 +e1000_tx_map_45309 e1000_tx_map 5 45309 NULL
112615 +copy_vm86_regs_from_user_45340 copy_vm86_regs_from_user 3 45340 NULL
112616 +null_alloc_repbuf_45375 null_alloc_repbuf 3 45375 NULL
112617 +sock_recv_errqueue_45412 sock_recv_errqueue 3 45412 NULL
112618 +ieee80211_if_fmt_dot11MeshHWMProotInterval_45421 ieee80211_if_fmt_dot11MeshHWMProotInterval 3 45421 NULL
112619 +ll_iocontrol_register_45430 ll_iocontrol_register 2 45430 NULL
112620 +tty_buffer_alloc_45437 tty_buffer_alloc 2 45437 NULL
112621 +__node_remap_45458 __node_remap 4 45458 NULL
112622 +rds_ib_set_wr_signal_state_45463 rds_ib_set_wr_signal_state 0 45463 NULL
112623 +tracing_read_dyn_info_45468 tracing_read_dyn_info 3 45468 NULL
112624 +rds_message_copy_from_user_45510 rds_message_copy_from_user 3 45510 NULL
112625 +i40e_alloc_vfs_45511 i40e_alloc_vfs 2 45511 NULL
112626 +cgroup_read_u64_45532 cgroup_read_u64 5 45532 NULL
112627 +copy_macs_45534 copy_macs 4 45534 NULL
112628 +nla_attr_size_45545 nla_attr_size 0-1 45545 NULL
112629 +v9fs_direct_read_45546 v9fs_direct_read 3 45546 NULL
112630 +cx18_copy_mdl_to_user_45549 cx18_copy_mdl_to_user 4 45549 NULL
112631 +stats_dot11ACKFailureCount_read_45558 stats_dot11ACKFailureCount_read 3 45558 NULL
112632 +_regmap_bus_raw_write_45559 _regmap_bus_raw_write 2 45559 NULL
112633 +posix_acl_xattr_size_45561 posix_acl_xattr_size 0-1 45561 NULL
112634 +venus_rmdir_45564 venus_rmdir 4 45564 NULL
112635 +ath6kl_keepalive_write_45600 ath6kl_keepalive_write 3 45600 NULL
112636 +hidraw_get_report_45609 hidraw_get_report 3 45609 NULL
112637 +compat_mpctl_ioctl_45671 compat_mpctl_ioctl 2 45671 NULL
112638 +dgram_sendmsg_45679 dgram_sendmsg 4 45679 NULL
112639 +smk_write_ambient_45691 smk_write_ambient 3 45691 NULL
112640 +unix_dgram_sendmsg_45699 unix_dgram_sendmsg 4 45699 NULL nohasharray
112641 +bscnl_emit_45699 bscnl_emit 2-5-0 45699 &unix_dgram_sendmsg_45699
112642 +sg_proc_write_adio_45704 sg_proc_write_adio 3 45704 NULL
112643 +snd_cs46xx_io_read_45734 snd_cs46xx_io_read 5 45734 NULL nohasharray
112644 +task_cgroup_path_45734 task_cgroup_path 3 45734 &snd_cs46xx_io_read_45734
112645 +rw_copy_check_uvector_45748 rw_copy_check_uvector 3-0 45748 NULL nohasharray
112646 +v4l2_ctrl_new_std_45748 v4l2_ctrl_new_std 5 45748 &rw_copy_check_uvector_45748
112647 +lkdtm_debugfs_read_45752 lkdtm_debugfs_read 3 45752 NULL
112648 +alloc_ts_config_45775 alloc_ts_config 1 45775 NULL
112649 +osc_checksum_type_seq_write_45785 osc_checksum_type_seq_write 3 45785 NULL
112650 +raw_setsockopt_45800 raw_setsockopt 5 45800 NULL
112651 +rds_tcp_inc_copy_to_user_45804 rds_tcp_inc_copy_to_user 3 45804 NULL
112652 +lbs_rdbbp_read_45805 lbs_rdbbp_read 3 45805 NULL
112653 +pcpu_alloc_alloc_info_45813 pcpu_alloc_alloc_info 1-2 45813 NULL
112654 +ll_max_readahead_mb_seq_write_45815 ll_max_readahead_mb_seq_write 3 45815 NULL
112655 +memcg_update_cache_size_45828 memcg_update_cache_size 2 45828 NULL
112656 +ipv6_recv_rxpmtu_45830 ipv6_recv_rxpmtu 3 45830 NULL
112657 +x509_process_extension_45854 x509_process_extension 5 45854 NULL
112658 +efx_tx_queue_insert_45859 efx_tx_queue_insert 2 45859 NULL
112659 +isdn_write_45863 isdn_write 3 45863 NULL
112660 +tpm_config_in_45880 tpm_config_in 0 45880 NULL
112661 +get_rdac_req_45882 get_rdac_req 3 45882 NULL
112662 +ima_eventdigest_init_common_45889 ima_eventdigest_init_common 2 45889 NULL
112663 +ocfs2_xattr_block_find_45891 ocfs2_xattr_block_find 0 45891 NULL
112664 +cfs_cpt_weight_45903 cfs_cpt_weight 0 45903 NULL
112665 +wm_adsp_region_to_reg_45915 wm_adsp_region_to_reg 0-2 45915 NULL
112666 +dbgfs_frame_45917 dbgfs_frame 3 45917 NULL
112667 +alloc_mr_45935 alloc_mr 1 45935 NULL
112668 +copy_to_45969 copy_to 3 45969 NULL
112669 +rb_simple_read_45972 rb_simple_read 3 45972 NULL
112670 +ioat2_dca_count_dca_slots_45984 ioat2_dca_count_dca_slots 0 45984 NULL
112671 +kobject_init_and_add_46003 kobject_init_and_add 0 46003 NULL
112672 +sierra_setup_urb_46029 sierra_setup_urb 5 46029 NULL
112673 +fnic_reset_stats_read_46030 fnic_reset_stats_read 3 46030 NULL nohasharray
112674 +get_free_entries_46030 get_free_entries 1 46030 &fnic_reset_stats_read_46030
112675 +__access_remote_vm_46031 __access_remote_vm 0 46031 NULL
112676 +snd_emu10k1x_ptr_read_46049 snd_emu10k1x_ptr_read 0 46049 NULL
112677 +__ocfs2_move_extent_46060 __ocfs2_move_extent 3-4 46060 NULL nohasharray
112678 +dma_tx_errors_read_46060 dma_tx_errors_read 3 46060 &__ocfs2_move_extent_46060
112679 +sel_commit_bools_write_46077 sel_commit_bools_write 3 46077 NULL
112680 +il3945_ucode_general_stats_read_46111 il3945_ucode_general_stats_read 3 46111 NULL nohasharray
112681 +memcg_update_array_size_46111 memcg_update_array_size 1 46111 &il3945_ucode_general_stats_read_46111
112682 +C_SYSC_writev_46113 C_SYSC_writev 3 46113 NULL
112683 +mlx4_ib_alloc_fast_reg_page_list_46119 mlx4_ib_alloc_fast_reg_page_list 2 46119 NULL
112684 +rtw_buf_update_46138 rtw_buf_update 4 46138 NULL
112685 +vb2_dma_sg_get_userptr_46146 vb2_dma_sg_get_userptr 3-2 46146 NULL
112686 +__netlink_change_ngroups_46156 __netlink_change_ngroups 2 46156 NULL
112687 +twl_direction_out_46182 twl_direction_out 2 46182 NULL
112688 +vxge_os_dma_malloc_46184 vxge_os_dma_malloc 2 46184 NULL
112689 +fq_resize_46195 fq_resize 2 46195 NULL
112690 +add_conn_list_46197 add_conn_list 3-0 46197 NULL
112691 +i2400m_op_msg_from_user_46213 i2400m_op_msg_from_user 4 46213 NULL
112692 +tm6000_i2c_recv_regs_46215 tm6000_i2c_recv_regs 5 46215 NULL
112693 +dsp_write_46218 dsp_write 2 46218 NULL
112694 +hash_netiface4_expire_46226 hash_netiface4_expire 4 46226 NULL
112695 +xen_setup_msi_irqs_46245 xen_setup_msi_irqs 2 46245 NULL
112696 +mpi_read_raw_data_46248 mpi_read_raw_data 2 46248 NULL
112697 +ReadReg_46277 ReadReg 0 46277 NULL
112698 +sptlrpc_req_get_ctx_46303 sptlrpc_req_get_ctx 0 46303 NULL
112699 +sg_proc_write_dressz_46316 sg_proc_write_dressz 3 46316 NULL
112700 +__hwahc_dev_set_key_46328 __hwahc_dev_set_key 5 46328 NULL nohasharray
112701 +compat_SyS_readv_46328 compat_SyS_readv 3 46328 &__hwahc_dev_set_key_46328
112702 +iwl_dbgfs_chain_noise_read_46355 iwl_dbgfs_chain_noise_read 3 46355 NULL
112703 +smk_write_direct_46363 smk_write_direct 3 46363 NULL
112704 +fuse_file_aio_write_46399 fuse_file_aio_write 4 46399 NULL
112705 +crypto_ablkcipher_reqsize_46411 crypto_ablkcipher_reqsize 0 46411 NULL
112706 +ttm_page_pool_get_pages_46431 ttm_page_pool_get_pages 0-5 46431 NULL
112707 +cfs_power2_roundup_46433 cfs_power2_roundup 0-1 46433 NULL
112708 +cp210x_set_config_46447 cp210x_set_config 4 46447 NULL
112709 +parport_pc_fifo_write_block_46455 parport_pc_fifo_write_block 3 46455 NULL
112710 +il_dbgfs_clear_traffic_stats_write_46458 il_dbgfs_clear_traffic_stats_write 3 46458 NULL
112711 +filldir64_46469 filldir64 3 46469 NULL
112712 +fill_in_write_vector_46498 fill_in_write_vector 0 46498 NULL
112713 +pin_code_reply_46510 pin_code_reply 4 46510 NULL
112714 +mthca_alloc_cq_buf_46512 mthca_alloc_cq_buf 3 46512 NULL
112715 +kmsg_read_46514 kmsg_read 3 46514 NULL nohasharray
112716 +nouveau_drm_ioctl_46514 nouveau_drm_ioctl 2 46514 &kmsg_read_46514
112717 +nl80211_send_rx_assoc_46538 nl80211_send_rx_assoc 4 46538 NULL
112718 +dn_current_mss_46574 dn_current_mss 0 46574 NULL
112719 +serverworks_create_gatt_pages_46582 serverworks_create_gatt_pages 1 46582 NULL
112720 +snd_compr_write_data_46592 snd_compr_write_data 3 46592 NULL
112721 +il3945_stats_flag_46606 il3945_stats_flag 3-0 46606 NULL
112722 +vscnprintf_46617 vscnprintf 0-2 46617 NULL
112723 +__kfifo_out_r_46623 __kfifo_out_r 3-0 46623 NULL
112724 +request_key_async_with_auxdata_46624 request_key_async_with_auxdata 4 46624 NULL
112725 +pci_enable_device_46642 pci_enable_device 0 46642 NULL
112726 +vfs_getxattr_alloc_46649 vfs_getxattr_alloc 0 46649 NULL
112727 +e1000_tx_map_46672 e1000_tx_map 4 46672 NULL
112728 +alloc_data_packet_46698 alloc_data_packet 1 46698 NULL
112729 +__ilog2_u32_46706 __ilog2_u32 0 46706 NULL
112730 +erst_dbg_write_46715 erst_dbg_write 3 46715 NULL
112731 +wl1271_rx_filter_alloc_field_46721 wl1271_rx_filter_alloc_field 5 46721 NULL
112732 +irq_domain_add_simple_46734 irq_domain_add_simple 2 46734 NULL
112733 +read_file_tx99_46741 read_file_tx99 3 46741 NULL
112734 +ext4_count_free_46754 ext4_count_free 2 46754 NULL
112735 +hest_ghes_dev_register_46766 hest_ghes_dev_register 1 46766 NULL
112736 +int_hw_irq_en_46776 int_hw_irq_en 3 46776 NULL
112737 +_xfs_buf_get_pages_46811 _xfs_buf_get_pages 2 46811 NULL
112738 +xfs_iroot_realloc_46826 xfs_iroot_realloc 2 46826 NULL
112739 +readreg_46845 readreg 0 46845 NULL
112740 +spi_async_46857 spi_async 0 46857 NULL
112741 +SyS_move_pages_46863 SyS_move_pages 2 46863 NULL nohasharray
112742 +vsnprintf_46863 vsnprintf 0 46863 &SyS_move_pages_46863
112743 +nvme_alloc_queue_46865 nvme_alloc_queue 3 46865 NULL
112744 +qp_memcpy_from_queue_iov_46874 qp_memcpy_from_queue_iov 5-4 46874 NULL
112745 +lov_iocontrol_46876 lov_iocontrol 3 46876 NULL
112746 +ixgbe_dbg_reg_ops_write_46895 ixgbe_dbg_reg_ops_write 3 46895 NULL
112747 +sk_mem_pages_46896 sk_mem_pages 0-1 46896 NULL
112748 +ieee80211_if_fmt_power_mode_46906 ieee80211_if_fmt_power_mode 3 46906 NULL
112749 +wlcore_alloc_hw_46917 wlcore_alloc_hw 1-3 46917 NULL
112750 +fb_write_46924 fb_write 3 46924 NULL
112751 +__sctp_setsockopt_connectx_46949 __sctp_setsockopt_connectx 3 46949 NULL
112752 +qla4xxx_post_aen_work_46953 qla4xxx_post_aen_work 3 46953 NULL
112753 +SYSC_poll_46965 SYSC_poll 2 46965 NULL
112754 +crypto_tfm_alg_alignmask_46971 crypto_tfm_alg_alignmask 0 46971 NULL
112755 +mgmt_pending_add_46976 mgmt_pending_add 5 46976 NULL
112756 +strlcat_46985 strlcat 3 46985 NULL
112757 +bitmap_file_clear_bit_46990 bitmap_file_clear_bit 2 46990 NULL
112758 +sel_write_bool_46996 sel_write_bool 3 46996 NULL nohasharray
112759 +gfs2_xattr_system_set_46996 gfs2_xattr_system_set 4 46996 &sel_write_bool_46996
112760 +blk_rq_map_kern_47004 blk_rq_map_kern 4 47004 NULL
112761 +cx231xx_init_bulk_47024 cx231xx_init_bulk 3-2-4 47024 NULL
112762 +fs_path_len_47060 fs_path_len 0 47060 NULL
112763 +ext4_xattr_list_entries_47070 ext4_xattr_list_entries 0 47070 NULL
112764 +pipeline_dec_packet_in_read_47076 pipeline_dec_packet_in_read 3 47076 NULL
112765 +scsi_deactivate_tcq_47086 scsi_deactivate_tcq 2 47086 NULL
112766 +iwl_dump_nic_event_log_47089 iwl_dump_nic_event_log 0 47089 NULL
112767 +ptlrpc_lprocfs_threads_max_seq_write_47104 ptlrpc_lprocfs_threads_max_seq_write 3 47104 NULL
112768 +mousedev_read_47123 mousedev_read 3 47123 NULL
112769 +acpi_ut_initialize_buffer_47143 acpi_ut_initialize_buffer 2 47143 NULL nohasharray
112770 +ses_recv_diag_47143 ses_recv_diag 4 47143 &acpi_ut_initialize_buffer_47143
112771 +mxms_headerlen_47161 mxms_headerlen 0 47161 NULL
112772 +rs_sta_dbgfs_rate_scale_data_read_47165 rs_sta_dbgfs_rate_scale_data_read 3 47165 NULL
112773 +rts51x_ms_rw_47171 rts51x_ms_rw 3-4 47171 NULL
112774 +can_set_system_xattr_47182 can_set_system_xattr 4 47182 NULL
112775 +options_write_47243 options_write 3 47243 NULL
112776 +portcntrs_1_read_47253 portcntrs_1_read 3 47253 NULL
112777 +ablkcipher_next_slow_47274 ablkcipher_next_slow 4-3 47274 NULL
112778 +gfs2_readpages_47285 gfs2_readpages 4 47285 NULL
112779 +vsnprintf_47291 vsnprintf 0 47291 NULL
112780 +SYSC_semop_47292 SYSC_semop 3 47292 NULL
112781 +tx_internal_desc_overflow_read_47300 tx_internal_desc_overflow_read 3 47300 NULL
112782 +nouveau_fb_create__47316 nouveau_fb_create_ 4 47316 NULL
112783 +ieee80211_if_read_dot11MeshHoldingTimeout_47356 ieee80211_if_read_dot11MeshHoldingTimeout 3 47356 NULL
112784 +avc_get_hash_stats_47359 avc_get_hash_stats 0 47359 NULL
112785 +kvm_arch_create_memslot_47364 kvm_arch_create_memslot 3 47364 NULL nohasharray
112786 +__output_copy_user_47364 __output_copy_user 3 47364 &kvm_arch_create_memslot_47364
112787 +__bio_map_kern_47379 __bio_map_kern 3 47379 NULL
112788 +trace_options_core_read_47390 trace_options_core_read 3 47390 NULL nohasharray
112789 +nv_rd32_47390 nv_rd32 0 47390 &trace_options_core_read_47390
112790 +nametbl_list_47391 nametbl_list 2 47391 NULL
112791 +dgrp_net_write_47392 dgrp_net_write 3 47392 NULL
112792 +pfkey_sendmsg_47394 pfkey_sendmsg 4 47394 NULL
112793 +lbs_wrmac_write_47400 lbs_wrmac_write 3 47400 NULL
112794 +sta_vht_capa_read_47409 sta_vht_capa_read 3 47409 NULL
112795 +crypto_ablkcipher_alignmask_47410 crypto_ablkcipher_alignmask 0 47410 NULL
112796 +lbs_wrrf_write_47418 lbs_wrrf_write 3 47418 NULL
112797 +posix_acl_from_disk_47445 posix_acl_from_disk 2 47445 NULL
112798 +nvme_trans_send_fw_cmd_47479 nvme_trans_send_fw_cmd 4 47479 NULL
112799 +newpart_47485 newpart 6-4 47485 NULL
112800 +mcp23s17_read_regs_47491 mcp23s17_read_regs 4 47491 NULL
112801 +core_sys_select_47494 core_sys_select 1 47494 NULL
112802 +alloc_arraycache_47505 alloc_arraycache 2 47505 NULL
112803 +unlink_simple_47506 unlink_simple 3 47506 NULL
112804 +pstore_decompress_47510 pstore_decompress 0 47510 NULL
112805 +__proc_lnet_portal_rotor_47529 __proc_lnet_portal_rotor 5 47529 NULL
112806 +process_vm_rw_47533 process_vm_rw 3-5 47533 NULL nohasharray
112807 +vscnprintf_47533 vscnprintf 0-2 47533 &process_vm_rw_47533
112808 +einj_check_trigger_header_47534 einj_check_trigger_header 0 47534 NULL
112809 +ieee80211_if_fmt_min_discovery_timeout_47539 ieee80211_if_fmt_min_discovery_timeout 3 47539 NULL
112810 +read_ldt_47570 read_ldt 2 47570 NULL
112811 +isku_sysfs_read_last_set_47572 isku_sysfs_read_last_set 6 47572 NULL
112812 +btrfs_stack_header_bytenr_47589 btrfs_stack_header_bytenr 0 47589 NULL
112813 +ext4_kvzalloc_47605 ext4_kvzalloc 1 47605 NULL
112814 +sctp_ssnmap_new_47608 sctp_ssnmap_new 2-1 47608 NULL
112815 +cache_read_pipefs_47615 cache_read_pipefs 3 47615 NULL
112816 +twl4030_clear_set_47624 twl4030_clear_set 4 47624 NULL
112817 +get_size_47644 get_size 1-2 47644 NULL
112818 +packet_recvmsg_47700 packet_recvmsg 4 47700 NULL nohasharray
112819 +ipath_format_hwmsg_47700 ipath_format_hwmsg 2 47700 &packet_recvmsg_47700
112820 +save_microcode_47717 save_microcode 3 47717 NULL
112821 +bits_to_user_47733 bits_to_user 2-3 47733 NULL
112822 +carl9170_debugfs_read_47738 carl9170_debugfs_read 3 47738 NULL
112823 +ir_prepare_write_buffer_47747 ir_prepare_write_buffer 3 47747 NULL
112824 +mvumi_alloc_mem_resource_47750 mvumi_alloc_mem_resource 3 47750 NULL
112825 +alloc_sched_domains_47756 alloc_sched_domains 1 47756 NULL
112826 +uwb_ie_dump_hex_47774 uwb_ie_dump_hex 4 47774 NULL
112827 +SyS_setgroups16_47780 SyS_setgroups16 1 47780 NULL
112828 +error_error_numll_frame_cts_start_read_47781 error_error_numll_frame_cts_start_read 3 47781 NULL
112829 +posix_acl_fix_xattr_from_user_47793 posix_acl_fix_xattr_from_user 2 47793 NULL
112830 +W6692_empty_Bfifo_47804 W6692_empty_Bfifo 2 47804 NULL
112831 +lov_packmd_47810 lov_packmd 0 47810 NULL
112832 +tree_mod_log_insert_move_47823 tree_mod_log_insert_move 5 47823 NULL
112833 +pinconf_dbg_config_write_47835 pinconf_dbg_config_write 3 47835 NULL
112834 +KEY_SIZE_47855 KEY_SIZE 0 47855 NULL
112835 +vhci_read_47878 vhci_read 3 47878 NULL
112836 +keyctl_instantiate_key_common_47889 keyctl_instantiate_key_common 4 47889 NULL
112837 +cfs_percpt_alloc_47918 cfs_percpt_alloc 2 47918 NULL
112838 +comedi_write_47926 comedi_write 3 47926 NULL
112839 +nvme_trans_get_blk_desc_len_47946 nvme_trans_get_blk_desc_len 0-2 47946 NULL
112840 +gether_get_ifname_47972 gether_get_ifname 3 47972 NULL
112841 +mempool_resize_47983 mempool_resize 2 47983 NULL nohasharray
112842 +iwl_dbgfs_ucode_tracing_read_47983 iwl_dbgfs_ucode_tracing_read 3 47983 &mempool_resize_47983
112843 +dbg_port_buf_47990 dbg_port_buf 2 47990 NULL
112844 +ib_umad_write_47993 ib_umad_write 3 47993 NULL
112845 +lustre_cfg_len_48002 lustre_cfg_len 0 48002 NULL
112846 +gdm_tty_recv_complete_48011 gdm_tty_recv_complete 2 48011 NULL
112847 +ffs_epfile_write_48014 ffs_epfile_write 3 48014 NULL
112848 +bio_integrity_set_tag_48035 bio_integrity_set_tag 3 48035 NULL
112849 +pppoe_sendmsg_48039 pppoe_sendmsg 4 48039 NULL
112850 +SYSC_writev_48040 SYSC_writev 3 48040 NULL
112851 +wpan_phy_alloc_48056 wpan_phy_alloc 1 48056 NULL
112852 +posix_acl_alloc_48063 posix_acl_alloc 1 48063 NULL
112853 +palmas_bulk_write_48068 palmas_bulk_write 2-3-5 48068 NULL
112854 +disc_write_48070 disc_write 3 48070 NULL
112855 +mmc_alloc_host_48097 mmc_alloc_host 1 48097 NULL
112856 +skb_copy_datagram_const_iovec_48102 skb_copy_datagram_const_iovec 4-2-5 48102 NULL
112857 +vmw_framebuffer_surface_dirty_48132 vmw_framebuffer_surface_dirty 6 48132 NULL
112858 +set_discoverable_48141 set_discoverable 4 48141 NULL
112859 +dn_fib_count_nhs_48145 dn_fib_count_nhs 0 48145 NULL
112860 +_add_to_r4w_48152 _add_to_r4w 4 48152 NULL
112861 +isr_dma1_done_read_48159 isr_dma1_done_read 3 48159 NULL
112862 +c4iw_id_table_alloc_48163 c4iw_id_table_alloc 3 48163 NULL
112863 +rbd_obj_method_sync_48170 rbd_obj_method_sync 8 48170 NULL
112864 +alloc_cc770dev_48186 alloc_cc770dev 1 48186 NULL
112865 +brcmf_sdio_chip_cm3_exitdl_48192 brcmf_sdio_chip_cm3_exitdl 4 48192 NULL
112866 +cfg80211_process_deauth_48200 cfg80211_process_deauth 3 48200 NULL
112867 +ext4_index_trans_blocks_48205 ext4_index_trans_blocks 0-2 48205 NULL
112868 +snd_seq_dump_var_event_48209 snd_seq_dump_var_event 0 48209 NULL
112869 +ll_direct_IO_26_48216 ll_direct_IO_26 4 48216 NULL
112870 +uv_blade_nr_possible_cpus_48226 uv_blade_nr_possible_cpus 0 48226 NULL
112871 +nilfs_readpages_48229 nilfs_readpages 4 48229 NULL
112872 +read_file_recv_48232 read_file_recv 3 48232 NULL
112873 +unaccount_shadowed_48233 unaccount_shadowed 2 48233 NULL
112874 +nouveau_i2c_port_create__48240 nouveau_i2c_port_create_ 7 48240 NULL
112875 +nfsctl_transaction_read_48250 nfsctl_transaction_read 3 48250 NULL
112876 +batadv_socket_read_48257 batadv_socket_read 3 48257 NULL
112877 +cache_write_pipefs_48270 cache_write_pipefs 3 48270 NULL
112878 +trace_options_write_48275 trace_options_write 3 48275 NULL
112879 +send_set_info_48288 send_set_info 7 48288 NULL
112880 +lpfc_idiag_extacc_read_48301 lpfc_idiag_extacc_read 3 48301 NULL
112881 +timblogiw_read_48305 timblogiw_read 3 48305 NULL
112882 +hash_setkey_48310 hash_setkey 3 48310 NULL
112883 +audio_set_intf_req_48319 audio_set_intf_req 0 48319 NULL
112884 +kvm_mmu_pte_write_48340 kvm_mmu_pte_write 2 48340 NULL
112885 +skb_add_data_48363 skb_add_data 3 48363 NULL
112886 +tx_frag_init_called_read_48377 tx_frag_init_called_read 3 48377 NULL
112887 +lbs_debugfs_write_48413 lbs_debugfs_write 3 48413 NULL
112888 +uhid_event_from_user_48417 uhid_event_from_user 2 48417 NULL
112889 +div64_u64_rem_48418 div64_u64_rem 0-1-2 48418 NULL
112890 +pwr_tx_without_ps_read_48423 pwr_tx_without_ps_read 3 48423 NULL
112891 +print_filtered_48442 print_filtered 2-0 48442 NULL
112892 +tun_recvmsg_48463 tun_recvmsg 4 48463 NULL
112893 +compat_SyS_preadv64_48469 compat_SyS_preadv64 3 48469 NULL
112894 +ipath_format_hwerrors_48487 ipath_format_hwerrors 5 48487 NULL
112895 +r8712_usbctrl_vendorreq_48489 r8712_usbctrl_vendorreq 6 48489 NULL
112896 +ocfs2_refcount_cow_48495 ocfs2_refcount_cow 3 48495 NULL
112897 +send_control_msg_48498 send_control_msg 6 48498 NULL
112898 +count_masked_bytes_48507 count_masked_bytes 0-1 48507 NULL
112899 +diva_os_copy_to_user_48508 diva_os_copy_to_user 4 48508 NULL
112900 +brcmf_sdio_trap_info_48510 brcmf_sdio_trap_info 4 48510 NULL
112901 +phantom_get_free_48514 phantom_get_free 0 48514 NULL
112902 +drbd_bm_capacity_48530 drbd_bm_capacity 0 48530 NULL
112903 +raid10_size_48571 raid10_size 0-2-3 48571 NULL
112904 +llog_data_len_48607 llog_data_len 1 48607 NULL
112905 +do_ip_vs_set_ctl_48641 do_ip_vs_set_ctl 4 48641 NULL
112906 +ll_rw_extents_stats_pp_seq_write_48651 ll_rw_extents_stats_pp_seq_write 3 48651 NULL
112907 +mtd_read_48655 mtd_read 0 48655 NULL
112908 +aes_encrypt_packets_read_48666 aes_encrypt_packets_read 3 48666 NULL
112909 +sm501_create_subdev_48668 sm501_create_subdev 3-4 48668 NULL
112910 +hysdn_log_write_48694 hysdn_log_write 3 48694 NULL
112911 +altera_drscan_48698 altera_drscan 2 48698 NULL
112912 +kvm_set_irq_routing_48704 kvm_set_irq_routing 3 48704 NULL
112913 +recv_msg_48709 recv_msg 4 48709 NULL
112914 +lpfc_idiag_drbacc_write_48712 lpfc_idiag_drbacc_write 3 48712 NULL
112915 +SyS_lgetxattr_48719 SyS_lgetxattr 4 48719 NULL
112916 +ath6kl_usb_bmi_read_48745 ath6kl_usb_bmi_read 3 48745 NULL
112917 +ath6kl_regwrite_read_48747 ath6kl_regwrite_read 3 48747 NULL
112918 +l2cap_segment_sdu_48772 l2cap_segment_sdu 4 48772 NULL
112919 +gfs2_direct_IO_48774 gfs2_direct_IO 4 48774 NULL
112920 +il3945_sta_dbgfs_stats_table_read_48802 il3945_sta_dbgfs_stats_table_read 3 48802 NULL
112921 +twa_change_queue_depth_48808 twa_change_queue_depth 2 48808 NULL
112922 +atomic_counters_read_48827 atomic_counters_read 3 48827 NULL
112923 +azx_get_position_48841 azx_get_position 0 48841 NULL
112924 +vc_do_resize_48842 vc_do_resize 3-4 48842 NULL
112925 +comedi_buf_write_alloc_48846 comedi_buf_write_alloc 0-2 48846 NULL
112926 +suspend_dtim_interval_write_48854 suspend_dtim_interval_write 3 48854 NULL
112927 +sptlrpc_cli_alloc_reqbuf_48855 sptlrpc_cli_alloc_reqbuf 0 48855 NULL
112928 +C_SYSC_pwritev64_48864 C_SYSC_pwritev64 3 48864 NULL nohasharray
112929 +viafb_dvp1_proc_write_48864 viafb_dvp1_proc_write 3 48864 &C_SYSC_pwritev64_48864
112930 +__ffs_ep0_read_events_48868 __ffs_ep0_read_events 3 48868 NULL
112931 +crypto_cipher_ctxsize_48890 crypto_cipher_ctxsize 0 48890 NULL
112932 +joydev_handle_JSIOCSAXMAP_48898 joydev_handle_JSIOCSAXMAP 3 48898 NULL
112933 +xdi_copy_to_user_48900 xdi_copy_to_user 4 48900 NULL
112934 +msg_hdr_sz_48908 msg_hdr_sz 0 48908 NULL
112935 +sep_crypto_dma_48937 sep_crypto_dma 0 48937 NULL
112936 +si5351_write_parameters_48940 si5351_write_parameters 2 48940 NULL
112937 +event_heart_beat_read_48961 event_heart_beat_read 3 48961 NULL
112938 +nand_ecc_test_run_48966 nand_ecc_test_run 1 48966 NULL
112939 +vmci_handle_arr_create_48971 vmci_handle_arr_create 1 48971 NULL
112940 +rds_rm_size_48996 rds_rm_size 0-2 48996 NULL
112941 +sel_write_enforce_48998 sel_write_enforce 3 48998 NULL
112942 +null_alloc_rs_49019 null_alloc_rs 2 49019 NULL
112943 +filemap_check_errors_49022 filemap_check_errors 0 49022 NULL
112944 +aic_inb_49023 aic_inb 0 49023 NULL
112945 +transient_status_49027 transient_status 4 49027 NULL
112946 +iwl_mvm_power_legacy_dbgfs_read_49038 iwl_mvm_power_legacy_dbgfs_read 4 49038 NULL
112947 +aic7xxx_rem_scb_from_disc_list_49041 aic7xxx_rem_scb_from_disc_list 0 49041 NULL
112948 +scsi_register_49094 scsi_register 2 49094 NULL
112949 +compat_do_readv_writev_49102 compat_do_readv_writev 4 49102 NULL
112950 +xfrm_replay_state_esn_len_49119 xfrm_replay_state_esn_len 0 49119 NULL
112951 +ll_max_cached_mb_seq_write_49122 ll_max_cached_mb_seq_write 3 49122 NULL
112952 +pt_read_49136 pt_read 3 49136 NULL
112953 +ipwireless_tty_received_49154 ipwireless_tty_received 3 49154 NULL
112954 +f2fs_acl_count_49155 f2fs_acl_count 0-1 49155 NULL
112955 +ipw_queue_tx_init_49161 ipw_queue_tx_init 3 49161 NULL
112956 +__jfs_setxattr_49175 __jfs_setxattr 5 49175 NULL
112957 +ath6kl_bgscan_int_write_49178 ath6kl_bgscan_int_write 3 49178 NULL
112958 +dvb_dvr_ioctl_49182 dvb_dvr_ioctl 2 49182 NULL
112959 +print_queue_49191 print_queue 4-0 49191 NULL
112960 +root_nfs_cat_49192 root_nfs_cat 3 49192 NULL
112961 +iwl_dbgfs_ucode_general_stats_read_49199 iwl_dbgfs_ucode_general_stats_read 3 49199 NULL
112962 +il4965_rs_sta_dbgfs_stats_table_read_49206 il4965_rs_sta_dbgfs_stats_table_read 3 49206 NULL
112963 +do_jffs2_getxattr_49210 do_jffs2_getxattr 0 49210 NULL
112964 +nouveau_therm_create__49228 nouveau_therm_create_ 4 49228 NULL
112965 +hugetlb_cgroup_read_49259 hugetlb_cgroup_read 5 49259 NULL
112966 +ieee80211_if_read_rssi_threshold_49260 ieee80211_if_read_rssi_threshold 3 49260 NULL
112967 +isku_sysfs_read_keys_media_49268 isku_sysfs_read_keys_media 6 49268 NULL
112968 +ptlrpc_check_set_49277 ptlrpc_check_set 0 49277 NULL
112969 +rx_filter_beacon_filter_read_49279 rx_filter_beacon_filter_read 3 49279 NULL
112970 +viafb_dfph_proc_write_49288 viafb_dfph_proc_write 3 49288 NULL
112971 +uio_read_49300 uio_read 3 49300 NULL
112972 +isku_sysfs_read_keys_macro_49312 isku_sysfs_read_keys_macro 6 49312 NULL
112973 +SYSC_mincore_49319 SYSC_mincore 2-1 49319 NULL
112974 +fwtty_port_handler_49327 fwtty_port_handler 9 49327 NULL
112975 +srpt_alloc_ioctx_ring_49330 srpt_alloc_ioctx_ring 2-4-3 49330 NULL
112976 +joydev_ioctl_common_49359 joydev_ioctl_common 2 49359 NULL
112977 +iscsi_alloc_session_49390 iscsi_alloc_session 3 49390 NULL
112978 +ext4_ext_index_trans_blocks_49396 ext4_ext_index_trans_blocks 0 49396 NULL
112979 +rx_streaming_always_read_49401 rx_streaming_always_read 3 49401 NULL
112980 +tnode_alloc_49407 tnode_alloc 1 49407 NULL
112981 +samples_to_bytes_49426 samples_to_bytes 0-2 49426 NULL
112982 +compat_do_msg_fill_49440 compat_do_msg_fill 3 49440 NULL
112983 +__hfsplus_getxattr_49460 __hfsplus_getxattr 0 49460 NULL
112984 +agp_3_5_isochronous_node_enable_49465 agp_3_5_isochronous_node_enable 3 49465 NULL
112985 +xfs_iformat_local_49472 xfs_iformat_local 4 49472 NULL
112986 +isr_decrypt_done_read_49490 isr_decrypt_done_read 3 49490 NULL
112987 +iwl_dbgfs_disable_power_off_read_49517 iwl_dbgfs_disable_power_off_read 3 49517 NULL
112988 +SyS_listxattr_49519 SyS_listxattr 3 49519 NULL
112989 +emulator_write_phys_49520 emulator_write_phys 2-4 49520 NULL
112990 +smk_write_access_49561 smk_write_access 3 49561 NULL
112991 +alloc_chunk_49575 alloc_chunk 1 49575 NULL
112992 +sctp_setsockopt_default_send_param_49578 sctp_setsockopt_default_send_param 3 49578 NULL
112993 +ptlrpc_request_pack_49581 ptlrpc_request_pack 0 49581 NULL
112994 +readfifo_49583 readfifo 1 49583 NULL
112995 +tap_write_49595 tap_write 3 49595 NULL
112996 +isr_wakeups_read_49607 isr_wakeups_read 3 49607 NULL
112997 +btrfs_mksubvol_49616 btrfs_mksubvol 3 49616 NULL
112998 +heap_init_49617 heap_init 2 49617 NULL
112999 +smk_write_doi_49621 smk_write_doi 3 49621 NULL
113000 +port_fops_read_49626 port_fops_read 3 49626 NULL
113001 +btrfsic_cmp_log_and_dev_bytenr_49628 btrfsic_cmp_log_and_dev_bytenr 2 49628 NULL
113002 +aa_simple_write_to_buffer_49683 aa_simple_write_to_buffer 4-3 49683 NULL
113003 +SyS_pwritev_49688 SyS_pwritev 3 49688 NULL
113004 +__copy_from_user_nocheck_49699 __copy_from_user_nocheck 0-3 49699 NULL
113005 +cx2341x_ctrl_new_menu_49700 cx2341x_ctrl_new_menu 3 49700 NULL
113006 +write_pool_49718 write_pool 3 49718 NULL
113007 +kvm_mmu_notifier_invalidate_page_49723 kvm_mmu_notifier_invalidate_page 3 49723 NULL
113008 +sep_create_dcb_dmatables_context_kernel_49728 sep_create_dcb_dmatables_context_kernel 6 49728 NULL
113009 +zd_usb_iowrite16v_49744 zd_usb_iowrite16v 3 49744 NULL
113010 +btrfs_chunk_num_stripes_49751 btrfs_chunk_num_stripes 0 49751 NULL
113011 +fuse_wr_pages_49753 fuse_wr_pages 0-1-2 49753 NULL
113012 +key_conf_keylen_read_49758 key_conf_keylen_read 3 49758 NULL
113013 +fuse_conn_waiting_read_49762 fuse_conn_waiting_read 3 49762 NULL
113014 +w83977af_fir_interrupt_49775 w83977af_fir_interrupt 0 49775 NULL
113015 +ceph_osdc_readpages_49789 ceph_osdc_readpages 0 49789 NULL
113016 +nfs4_acl_new_49806 nfs4_acl_new 1 49806 NULL
113017 +ntfs_copy_from_user_iovec_49829 ntfs_copy_from_user_iovec 3-6-0 49829 NULL
113018 +add_uuid_49831 add_uuid 4 49831 NULL
113019 +iraw_loop_49842 iraw_loop 0-1 49842 NULL
113020 +twl4030_write_49846 twl4030_write 2 49846 NULL
113021 +scsi_dispatch_cmd_entry_49848 scsi_dispatch_cmd_entry 3 49848 NULL
113022 +timeradd_entry_49850 timeradd_entry 3 49850 NULL
113023 +fiemap_count_to_size_49869 fiemap_count_to_size 0-1 49869 NULL
113024 +sctp_setsockopt_bindx_49870 sctp_setsockopt_bindx 3 49870 NULL
113025 +ceph_get_caps_49890 ceph_get_caps 0 49890 NULL
113026 +osc_brw_49896 osc_brw 4 49896 NULL
113027 +config_ep_by_speed_49939 config_ep_by_speed 0 49939 NULL
113028 +ieee80211_if_fmt_dtim_count_49987 ieee80211_if_fmt_dtim_count 3 49987 NULL
113029 +drm_buffer_copy_from_user_49990 drm_buffer_copy_from_user 3 49990 NULL
113030 +l2cap_chan_send_49995 l2cap_chan_send 3 49995 NULL
113031 +dn_mss_from_pmtu_50011 dn_mss_from_pmtu 0-2 50011 NULL
113032 +isdn_read_50021 isdn_read 3 50021 NULL
113033 +mdc_rename_pack_50023 mdc_rename_pack 4-6 50023 NULL
113034 +ioread8_50049 ioread8 0 50049 NULL
113035 +fuse_conn_max_background_write_50061 fuse_conn_max_background_write 3 50061 NULL
113036 +__kfifo_dma_in_prepare_50081 __kfifo_dma_in_prepare 4 50081 NULL
113037 +dev_set_alias_50084 dev_set_alias 3 50084 NULL
113038 +libcfs_ioctl_popdata_50087 libcfs_ioctl_popdata 3 50087 NULL
113039 +sock_setsockopt_50088 sock_setsockopt 5 50088 NULL
113040 +altera_swap_dr_50090 altera_swap_dr 2 50090 NULL
113041 +android_set_cntry_50100 android_set_cntry 0 50100 NULL
113042 +read_file_slot_50111 read_file_slot 3 50111 NULL
113043 +rx_streaming_interval_write_50120 rx_streaming_interval_write 3 50120 NULL
113044 +jfs_direct_IO_50125 jfs_direct_IO 4 50125 NULL
113045 +SYSC_preadv_50134 SYSC_preadv 3 50134 NULL
113046 +copy_items_50140 copy_items 6 50140 NULL
113047 +tx_frag_need_fragmentation_read_50153 tx_frag_need_fragmentation_read 3 50153 NULL
113048 +kmalloc_node_50163 kmalloc_node 1 50163 NULL
113049 +rx_filter_ibss_filter_read_50167 rx_filter_ibss_filter_read 3 50167 NULL
113050 +ahd_probe_stack_size_50168 ahd_probe_stack_size 0 50168 NULL
113051 +odev_update_50169 odev_update 2 50169 NULL
113052 +ubi_resize_volume_50172 ubi_resize_volume 2 50172 NULL nohasharray
113053 +ieee80211_if_fmt_dot11MeshHWMPRannInterval_50172 ieee80211_if_fmt_dot11MeshHWMPRannInterval 3 50172 &ubi_resize_volume_50172
113054 +cfg80211_roamed_bss_50198 cfg80211_roamed_bss 4-6 50198 NULL
113055 +cyttsp4_probe_50201 cyttsp4_probe 4 50201 NULL
113056 +rx_rx_timeout_wa_read_50204 rx_rx_timeout_wa_read 3 50204 NULL
113057 +mthca_buddy_init_50206 mthca_buddy_init 2 50206 NULL
113058 +l2cap_sock_setsockopt_50207 l2cap_sock_setsockopt 5 50207 NULL
113059 +mon_bin_compat_ioctl_50234 mon_bin_compat_ioctl 3 50234 NULL
113060 +sg_kmalloc_50240 sg_kmalloc 1 50240 NULL
113061 +rxrpc_setsockopt_50286 rxrpc_setsockopt 5 50286 NULL
113062 +soc_codec_reg_show_50302 soc_codec_reg_show 0-3 50302 NULL
113063 +SYSC_flistxattr_50307 SYSC_flistxattr 3 50307 NULL
113064 +SYSC_sched_setaffinity_50310 SYSC_sched_setaffinity 2 50310 NULL
113065 +soc_camera_read_50319 soc_camera_read 3 50319 NULL
113066 +do_launder_page_50329 do_launder_page 0 50329 NULL
113067 +nouveau_engine_create__50331 nouveau_engine_create_ 7 50331 NULL
113068 +lpfc_idiag_pcicfg_read_50334 lpfc_idiag_pcicfg_read 3 50334 NULL
113069 +snd_pcm_lib_writev_50337 snd_pcm_lib_writev 0-3 50337 NULL
113070 +tpm_read_50344 tpm_read 3 50344 NULL
113071 +isdn_ppp_read_50356 isdn_ppp_read 4 50356 NULL
113072 +iwl_dbgfs_echo_test_write_50362 iwl_dbgfs_echo_test_write 3 50362 NULL
113073 +xfrm_send_migrate_50365 xfrm_send_migrate 5 50365 NULL
113074 +roccat_common2_receive_50369 roccat_common2_receive 4 50369 NULL
113075 +sl_alloc_bufs_50380 sl_alloc_bufs 2 50380 NULL
113076 +l2tp_ip_sendmsg_50411 l2tp_ip_sendmsg 4 50411 NULL
113077 +iscsi_create_conn_50425 iscsi_create_conn 2 50425 NULL
113078 +validate_acl_mac_addrs_50429 validate_acl_mac_addrs 0 50429 NULL
113079 +btrfs_error_discard_extent_50444 btrfs_error_discard_extent 2 50444 NULL
113080 +pgctrl_write_50453 pgctrl_write 3 50453 NULL
113081 +device_create_sys_dev_entry_50458 device_create_sys_dev_entry 0 50458 NULL
113082 +cfs_size_round_50472 cfs_size_round 0-1 50472 NULL
113083 +cdrom_read_cdda_50478 cdrom_read_cdda 4 50478 NULL
113084 +mei_io_cb_alloc_req_buf_50493 mei_io_cb_alloc_req_buf 2 50493 NULL
113085 +pwr_rcvd_awake_beacons_read_50505 pwr_rcvd_awake_beacons_read 3 50505 NULL
113086 +ath6kl_set_ap_probe_resp_ies_50539 ath6kl_set_ap_probe_resp_ies 3 50539 NULL
113087 +usbat_flash_write_data_50553 usbat_flash_write_data 4 50553 NULL
113088 +fat_readpages_50582 fat_readpages 4 50582 NULL
113089 +iwl_dbgfs_missed_beacon_read_50584 iwl_dbgfs_missed_beacon_read 3 50584 NULL
113090 +xillybus_write_50605 xillybus_write 3 50605 NULL
113091 +rx_rx_checksum_result_read_50617 rx_rx_checksum_result_read 3 50617 NULL
113092 +sparse_early_usemaps_alloc_node_50623 sparse_early_usemaps_alloc_node 4 50623 NULL
113093 +simple_transaction_get_50633 simple_transaction_get 3 50633 NULL
113094 +ath6kl_tm_rx_event_50664 ath6kl_tm_rx_event 3 50664 NULL
113095 +bnad_debugfs_read_50665 bnad_debugfs_read 3 50665 NULL
113096 +prism2_read_fid_reg_50689 prism2_read_fid_reg 0 50689 NULL
113097 +xfs_growfs_get_hdr_buf_50697 xfs_growfs_get_hdr_buf 3 50697 NULL
113098 +dev_mem_read_50706 dev_mem_read 3 50706 NULL
113099 +blk_check_plugged_50736 blk_check_plugged 3 50736 NULL
113100 +__ext3_get_inode_loc_50744 __ext3_get_inode_loc 0 50744 NULL
113101 +ocfs2_xattr_block_get_50773 ocfs2_xattr_block_get 0 50773 NULL
113102 +tm6000_read_write_usb_50774 tm6000_read_write_usb 7 50774 NULL
113103 +bio_alloc_map_data_50782 bio_alloc_map_data 1-2 50782 NULL
113104 +tpm_write_50798 tpm_write 3 50798 NULL
113105 +write_flush_50803 write_flush 3 50803 NULL
113106 +dvb_play_50814 dvb_play 3 50814 NULL
113107 +dpcm_show_state_50827 dpcm_show_state 0 50827 NULL
113108 +SetArea_50835 SetArea 4 50835 NULL
113109 +videobuf_dma_init_user_50839 videobuf_dma_init_user 4-3 50839 NULL
113110 +carl9170_debugfs_write_50857 carl9170_debugfs_write 3 50857 NULL
113111 +SyS_lgetxattr_50889 SyS_lgetxattr 4 50889 NULL
113112 +netlbl_secattr_catmap_walk_rng_50894 netlbl_secattr_catmap_walk_rng 0-2 50894 NULL
113113 +__bdev_writeseg_50903 __bdev_writeseg 4 50903 NULL
113114 +xfs_iext_remove_50909 xfs_iext_remove 3 50909 NULL
113115 +blk_rq_cur_sectors_50910 blk_rq_cur_sectors 0 50910 NULL
113116 +hash_recvmsg_50924 hash_recvmsg 4 50924 NULL
113117 +chd_dec_fetch_cdata_50926 chd_dec_fetch_cdata 3 50926 NULL
113118 +show_device_status_50947 show_device_status 0 50947 NULL
113119 +irq_timeout_write_50950 irq_timeout_write 3 50950 NULL
113120 +virtio_cread16_50951 virtio_cread16 0 50951 NULL
113121 +sdio_uart_write_50954 sdio_uart_write 3 50954 NULL
113122 +SyS_setxattr_50957 SyS_setxattr 4 50957 NULL
113123 +iwl_statistics_flag_50981 iwl_statistics_flag 3-0 50981 NULL
113124 +timeout_write_50991 timeout_write 3 50991 NULL
113125 +proc_write_51003 proc_write 3 51003 NULL
113126 +jbd2_journal_extend_51012 jbd2_journal_extend 2 51012 NULL
113127 +lbs_dev_info_51023 lbs_dev_info 3 51023 NULL
113128 +fuse_conn_congestion_threshold_read_51028 fuse_conn_congestion_threshold_read 3 51028 NULL
113129 +BcmGetSectionValEndOffset_51039 BcmGetSectionValEndOffset 0 51039 NULL
113130 +dump_midi_51040 dump_midi 3 51040 NULL
113131 +usb_get_descriptor_51041 usb_get_descriptor 0 51041 NULL
113132 +srpt_alloc_ioctx_51042 srpt_alloc_ioctx 2-3 51042 NULL
113133 +do_arpt_set_ctl_51053 do_arpt_set_ctl 4 51053 NULL
113134 +wusb_prf_64_51065 wusb_prf_64 7 51065 NULL
113135 +jbd2_journal_init_revoke_51088 jbd2_journal_init_revoke 2 51088 NULL
113136 +__ocfs2_find_path_51096 __ocfs2_find_path 0 51096 NULL
113137 +ti_recv_51110 ti_recv 3 51110 NULL
113138 +uasp_prepare_r_request_51124 uasp_prepare_r_request 0 51124 NULL
113139 +nfs_map_name_to_uid_51132 nfs_map_name_to_uid 3 51132 NULL
113140 +alloc_rtllib_51136 alloc_rtllib 1 51136 NULL
113141 +simple_xattr_set_51140 simple_xattr_set 4 51140 NULL
113142 +xfs_trans_get_efd_51148 xfs_trans_get_efd 3 51148 NULL
113143 +nf_ct_ext_create_51232 nf_ct_ext_create 3 51232 NULL
113144 +snd_pcm_write_51235 snd_pcm_write 3 51235 NULL
113145 +drm_property_create_51239 drm_property_create 4 51239 NULL
113146 +__mxt_read_reg_51249 __mxt_read_reg 0 51249 NULL
113147 +st_read_51251 st_read 3 51251 NULL
113148 +compat_dccp_setsockopt_51263 compat_dccp_setsockopt 5 51263 NULL
113149 +target_alloc_sgl_51264 target_alloc_sgl 3 51264 NULL
113150 +dvb_audio_write_51275 dvb_audio_write 3 51275 NULL
113151 +ipwireless_network_packet_received_51277 ipwireless_network_packet_received 4 51277 NULL
113152 +pvr2_std_id_to_str_51288 pvr2_std_id_to_str 2 51288 NULL
113153 +bnad_debugfs_read_regrd_51308 bnad_debugfs_read_regrd 3 51308 NULL
113154 +init_map_ipmac_51317 init_map_ipmac 5 51317 NULL
113155 +alloc_hippi_dev_51320 alloc_hippi_dev 1 51320 NULL
113156 +ext2_xattr_get_51327 ext2_xattr_get 0 51327 NULL
113157 +alloc_smp_req_51337 alloc_smp_req 1 51337 NULL
113158 +ipw_get_event_log_len_51341 ipw_get_event_log_len 0 51341 NULL
113159 +ieee80211_if_fmt_estab_plinks_51370 ieee80211_if_fmt_estab_plinks 3 51370 NULL
113160 +radeon_kms_compat_ioctl_51371 radeon_kms_compat_ioctl 2 51371 NULL
113161 +ceph_sync_read_51410 ceph_sync_read 3-0 51410 NULL
113162 +blk_register_region_51424 blk_register_region 1-2 51424 NULL
113163 +mwifiex_rdeeprom_read_51429 mwifiex_rdeeprom_read 3 51429 NULL
113164 +hfsplus_brec_read_51436 hfsplus_brec_read 0 51436 NULL
113165 +ieee80211_if_read_dot11MeshHWMPRootMode_51441 ieee80211_if_read_dot11MeshHWMPRootMode 3 51441 NULL
113166 +print_devstats_dot11ACKFailureCount_51443 print_devstats_dot11ACKFailureCount 3 51443 NULL
113167 +____alloc_ei_netdev_51475 ____alloc_ei_netdev 1 51475 NULL
113168 +xfs_buf_get_uncached_51477 xfs_buf_get_uncached 2 51477 NULL
113169 +kvm_fetch_guest_virt_51493 kvm_fetch_guest_virt 4-2 51493 NULL
113170 +ieee80211_if_write_uapsd_queues_51526 ieee80211_if_write_uapsd_queues 3 51526 NULL
113171 +__alloc_eip_netdev_51549 __alloc_eip_netdev 1 51549 NULL
113172 +batadv_tt_prepare_tvlv_local_data_51568 batadv_tt_prepare_tvlv_local_data 0 51568 NULL
113173 +ixgb_get_eeprom_len_51586 ixgb_get_eeprom_len 0 51586 NULL
113174 +aac_convert_sgraw2_51598 aac_convert_sgraw2 4 51598 NULL
113175 +table_size_to_number_of_entries_51613 table_size_to_number_of_entries 0-1 51613 NULL
113176 +extent_fiemap_51621 extent_fiemap 3 51621 NULL
113177 +sctp_auth_create_key_51641 sctp_auth_create_key 1 51641 NULL
113178 +iscsi_create_session_51647 iscsi_create_session 3 51647 NULL
113179 +ps_upsd_utilization_read_51669 ps_upsd_utilization_read 3 51669 NULL
113180 +sctp_setsockopt_associnfo_51684 sctp_setsockopt_associnfo 3 51684 NULL
113181 +host_mapping_level_51696 host_mapping_level 0 51696 NULL
113182 +sel_write_access_51704 sel_write_access 3 51704 NULL
113183 +tty_cdev_add_51714 tty_cdev_add 2-4 51714 NULL
113184 +v9fs_alloc_rdir_buf_51716 v9fs_alloc_rdir_buf 2 51716 NULL
113185 +drm_compat_ioctl_51717 drm_compat_ioctl 2 51717 NULL
113186 +sg_read_oxfer_51724 sg_read_oxfer 3 51724 NULL
113187 +cm4040_read_51732 cm4040_read 3 51732 NULL
113188 +get_user_pages_fast_51751 get_user_pages_fast 0 51751 NULL
113189 +ifx_spi_insert_flip_string_51752 ifx_spi_insert_flip_string 3 51752 NULL
113190 +if_write_51756 if_write 3 51756 NULL
113191 +qib_alloc_devdata_51819 qib_alloc_devdata 2 51819 NULL
113192 +buffer_from_user_51826 buffer_from_user 3 51826 NULL
113193 +ioread32_51847 ioread32 0 51847 NULL nohasharray
113194 +read_file_tgt_tx_stats_51847 read_file_tgt_tx_stats 3 51847 &ioread32_51847
113195 +do_readv_writev_51849 do_readv_writev 4 51849 NULL
113196 +SYSC_sendto_51852 SYSC_sendto 6 51852 NULL
113197 +bm_page_io_async_51858 bm_page_io_async 2 51858 NULL
113198 +pointer_size_read_51863 pointer_size_read 3 51863 NULL
113199 +get_indirect_ea_51869 get_indirect_ea 4 51869 NULL
113200 +user_read_51881 user_read 3 51881 NULL
113201 +dbAdjCtl_51888 dbAdjCtl 0 51888 NULL
113202 +SyS_mq_timedsend_51896 SyS_mq_timedsend 3 51896 NULL
113203 +wmi_set_ie_51919 wmi_set_ie 3 51919 NULL
113204 +dbg_status_buf_51930 dbg_status_buf 2 51930 NULL
113205 +__tcp_mtu_to_mss_51938 __tcp_mtu_to_mss 0-2 51938 NULL
113206 +xfrm_alg_len_51940 xfrm_alg_len 0 51940 NULL
113207 +scsi_get_vpd_page_51951 scsi_get_vpd_page 4 51951 NULL
113208 +snd_mask_min_51969 snd_mask_min 0 51969 NULL
113209 +__blkdev_get_51972 __blkdev_get 0 51972 NULL
113210 +get_zone_51981 get_zone 0-1 51981 NULL
113211 +ath6kl_sdio_alloc_prep_scat_req_51986 ath6kl_sdio_alloc_prep_scat_req 2 51986 NULL
113212 +_c4iw_write_mem_dma_51991 _c4iw_write_mem_dma 3 51991 NULL
113213 +dwc3_mode_write_51997 dwc3_mode_write 3 51997 NULL
113214 +skb_copy_datagram_from_iovec_52014 skb_copy_datagram_from_iovec 4-2-5 52014 NULL
113215 +rdmalt_52022 rdmalt 0 52022 NULL
113216 +override_release_52032 override_release 2 52032 NULL
113217 +end_port_52042 end_port 0 52042 NULL
113218 +dma_rx_errors_read_52045 dma_rx_errors_read 3 52045 NULL
113219 +msnd_fifo_write_52052 msnd_fifo_write 0-3 52052 NULL
113220 +dvb_ringbuffer_avail_52057 dvb_ringbuffer_avail 0 52057 NULL
113221 +__fuse_request_alloc_52060 __fuse_request_alloc 1 52060 NULL
113222 +isofs_readpages_52067 isofs_readpages 4 52067 NULL
113223 +nsm_get_handle_52089 nsm_get_handle 4 52089 NULL
113224 +o2net_debug_read_52105 o2net_debug_read 3 52105 NULL
113225 +split_scan_timeout_write_52128 split_scan_timeout_write 3 52128 NULL
113226 +retry_count_read_52129 retry_count_read 3 52129 NULL
113227 +gdm_usb_hci_send_52138 gdm_usb_hci_send 3 52138 NULL
113228 +sub_alloc_52140 sub_alloc 0 52140 NULL
113229 +hysdn_conf_write_52145 hysdn_conf_write 3 52145 NULL
113230 +htable_size_52148 htable_size 0-1 52148 NULL
113231 +smk_write_load2_52155 smk_write_load2 3 52155 NULL
113232 +ieee80211_if_read_dot11MeshRetryTimeout_52168 ieee80211_if_read_dot11MeshRetryTimeout 3 52168 NULL
113233 +mga_compat_ioctl_52170 mga_compat_ioctl 2 52170 NULL
113234 +print_prefix_52176 print_prefix 0 52176 NULL
113235 +proc_pid_readlink_52186 proc_pid_readlink 3 52186 NULL
113236 +vmci_qp_broker_alloc_52216 vmci_qp_broker_alloc 6-5 52216 NULL
113237 +fuse_request_alloc_52243 fuse_request_alloc 1 52243 NULL nohasharray
113238 +xfs_iomap_eof_align_last_fsb_52243 xfs_iomap_eof_align_last_fsb 3 52243 &fuse_request_alloc_52243
113239 +mdiobus_alloc_size_52259 mdiobus_alloc_size 1 52259 NULL
113240 +shrink_slab_52261 shrink_slab 2 52261 NULL
113241 +sisusbcon_do_font_op_52271 sisusbcon_do_font_op 9 52271 NULL
113242 +handle_supp_msgs_52284 handle_supp_msgs 4 52284 NULL
113243 +kobject_set_name_vargs_52309 kobject_set_name_vargs 0 52309 NULL
113244 +read_file_reset_52310 read_file_reset 3 52310 NULL
113245 +request_asymmetric_key_52317 request_asymmetric_key 2-4 52317 NULL
113246 +hwflags_read_52318 hwflags_read 3 52318 NULL
113247 +test_unaligned_bulk_52333 test_unaligned_bulk 3 52333 NULL
113248 +hur_len_52339 hur_len 0 52339 NULL
113249 +bytes_to_frames_52362 bytes_to_frames 0-2 52362 NULL
113250 +copy_entries_to_user_52367 copy_entries_to_user 1 52367 NULL
113251 +iwl_dump_fh_52371 iwl_dump_fh 0 52371 NULL
113252 +hfsplus_find_attr_52374 hfsplus_find_attr 0 52374 NULL
113253 +mq_emit_config_values_52378 mq_emit_config_values 3 52378 NULL
113254 +isdn_writebuf_stub_52383 isdn_writebuf_stub 4 52383 NULL
113255 +jfs_setxattr_52389 jfs_setxattr 4 52389 NULL
113256 +aer_inject_write_52399 aer_inject_write 3 52399 NULL
113257 +cgroup_file_write_52417 cgroup_file_write 3 52417 NULL
113258 +line6_midibuf_init_52425 line6_midibuf_init 2 52425 NULL
113259 +hso_serial_common_create_52428 hso_serial_common_create 4 52428 NULL
113260 +delay_status_52431 delay_status 5 52431 NULL
113261 +ath6kl_delete_qos_write_52435 ath6kl_delete_qos_write 3 52435 NULL
113262 +ieee80211_if_fmt_num_sta_ps_52438 ieee80211_if_fmt_num_sta_ps 3 52438 NULL
113263 +acpi_nvs_for_each_region_52448 acpi_nvs_for_each_region 0 52448 NULL
113264 +alauda_read_data_52452 alauda_read_data 3 52452 NULL
113265 +ieee80211_alloc_txb_52477 ieee80211_alloc_txb 1 52477 NULL
113266 +usb_tranzport_write_52479 usb_tranzport_write 3 52479 NULL
113267 +ocfs2_extend_no_holes_52483 ocfs2_extend_no_holes 3-4 52483 NULL
113268 +fd_do_rw_52495 fd_do_rw 3 52495 NULL
113269 +int_tasklet_entry_52500 int_tasklet_entry 3 52500 NULL
113270 +lmv_get_easize_52504 lmv_get_easize 0 52504 NULL
113271 +pm_qos_power_write_52513 pm_qos_power_write 3 52513 NULL
113272 +bt_sock_stream_recvmsg_52518 bt_sock_stream_recvmsg 4 52518 NULL
113273 +dup_variable_bug_52525 dup_variable_bug 3 52525 NULL
113274 +raw_recvmsg_52529 raw_recvmsg 4 52529 NULL
113275 +dccpprobe_read_52549 dccpprobe_read 3 52549 NULL
113276 +debug_level_proc_write_52572 debug_level_proc_write 3 52572 NULL
113277 +isku_sysfs_read_macro_52587 isku_sysfs_read_macro 6 52587 NULL
113278 +SyS_setsockopt_52610 SyS_setsockopt 5 52610 NULL
113279 +ll_sa_entry_alloc_52611 ll_sa_entry_alloc 4 52611 NULL
113280 +tps80031_writes_52638 tps80031_writes 3-4 52638 NULL
113281 +brcmf_sdio_assert_info_52653 brcmf_sdio_assert_info 4 52653 NULL
113282 +nvme_queue_extra_52661 nvme_queue_extra 0-1 52661 NULL
113283 +SYSC_gethostname_52677 SYSC_gethostname 2 52677 NULL
113284 +nvd0_disp_pioc_create__52693 nvd0_disp_pioc_create_ 5 52693 NULL
113285 +nouveau_client_create__52715 nouveau_client_create_ 5 52715 NULL
113286 +__dm_stat_bio_52722 __dm_stat_bio 3 52722 NULL
113287 +cx25840_ir_rx_read_52724 cx25840_ir_rx_read 3 52724 NULL
113288 +blkcipher_next_slow_52733 blkcipher_next_slow 3-4 52733 NULL
113289 +relay_alloc_page_array_52735 relay_alloc_page_array 1 52735 NULL
113290 +hfcsusb_rx_frame_52745 hfcsusb_rx_frame 3 52745 NULL
113291 +carl9170_debugfs_vif_dump_read_52755 carl9170_debugfs_vif_dump_read 3 52755 NULL
113292 +ieee80211_if_read_beacon_timeout_52756 ieee80211_if_read_beacon_timeout 3 52756 NULL
113293 +nvme_trans_ext_inq_page_52776 nvme_trans_ext_inq_page 3 52776 NULL
113294 +pwr_rcvd_beacons_read_52836 pwr_rcvd_beacons_read 3 52836 NULL
113295 +ext2_xattr_set_acl_52857 ext2_xattr_set_acl 4 52857 NULL
113296 +mon_bin_get_event_52863 mon_bin_get_event 4-6 52863 NULL
113297 +twl6030_gpadc_write_52867 twl6030_gpadc_write 1 52867 NULL
113298 +qib_decode_6120_err_52876 qib_decode_6120_err 3 52876 NULL
113299 +twlreg_write_52880 twlreg_write 3 52880 NULL
113300 +pvr2_ctrl_value_to_sym_internal_52881 pvr2_ctrl_value_to_sym_internal 5 52881 NULL
113301 +cache_read_procfs_52882 cache_read_procfs 3 52882 NULL
113302 +kvm_kvzalloc_52894 kvm_kvzalloc 1 52894 NULL
113303 +dio_bio_reap_52913 dio_bio_reap 0 52913 NULL
113304 +__kfifo_out_peek_r_52919 __kfifo_out_peek_r 3 52919 NULL
113305 +iblock_get_bio_52936 iblock_get_bio 3 52936 NULL
113306 +__nodes_remap_52951 __nodes_remap 5 52951 NULL
113307 +send_packet_52960 send_packet 4 52960 NULL
113308 +ieee80211_if_fmt_fwded_mcast_52961 ieee80211_if_fmt_fwded_mcast 3 52961 NULL
113309 +tx_tx_exch_read_52986 tx_tx_exch_read 3 52986 NULL
113310 +num_node_state_52989 num_node_state 0 52989 NULL
113311 +efivarfs_file_write_53000 efivarfs_file_write 3 53000 NULL
113312 +uasp_alloc_stream_res_53015 uasp_alloc_stream_res 0 53015 NULL
113313 +btrfs_free_and_pin_reserved_extent_53016 btrfs_free_and_pin_reserved_extent 2 53016 NULL
113314 +tx_tx_exch_pending_read_53018 tx_tx_exch_pending_read 3 53018 NULL
113315 +bio_cur_bytes_53037 bio_cur_bytes 0 53037 NULL
113316 +regcache_lzo_block_count_53056 regcache_lzo_block_count 0 53056 NULL
113317 +cfi_read_query_53066 cfi_read_query 0 53066 NULL
113318 +iwl_dbgfs_interrupt_write_53069 iwl_dbgfs_interrupt_write 3 53069 NULL
113319 +mwifiex_debug_read_53074 mwifiex_debug_read 3 53074 NULL
113320 +mic_virtio_copy_from_user_53107 mic_virtio_copy_from_user 3 53107 NULL
113321 +verity_status_53120 verity_status 5 53120 NULL
113322 +brcmf_usb_dl_cmd_53130 brcmf_usb_dl_cmd 4 53130 NULL
113323 +ps_poll_ps_poll_max_ap_turn_read_53140 ps_poll_ps_poll_max_ap_turn_read 3 53140 NULL
113324 +ieee80211_bss_info_update_53170 ieee80211_bss_info_update 4 53170 NULL
113325 +btrfs_io_bio_alloc_53179 btrfs_io_bio_alloc 2 53179 NULL
113326 +clear_capture_buf_53192 clear_capture_buf 2 53192 NULL
113327 +tx_tx_start_data_read_53219 tx_tx_start_data_read 3 53219 NULL
113328 +ptlrpc_lprocfs_req_history_max_seq_write_53243 ptlrpc_lprocfs_req_history_max_seq_write 3 53243 NULL
113329 +hfsplus_xattr_set_posix_acl_53249 hfsplus_xattr_set_posix_acl 4 53249 NULL
113330 +xfs_trans_read_buf_map_53258 xfs_trans_read_buf_map 5 53258 NULL
113331 +wil_write_file_ssid_53266 wil_write_file_ssid 3 53266 NULL
113332 +btrfs_file_extent_num_bytes_53269 btrfs_file_extent_num_bytes 0 53269 NULL
113333 +ftrace_profile_write_53327 ftrace_profile_write 3 53327 NULL
113334 +find_nr_power_limit_53330 find_nr_power_limit 0 53330 NULL
113335 +gsm_control_reply_53333 gsm_control_reply 4 53333 NULL
113336 +vm_mmap_53339 vm_mmap 0 53339 NULL
113337 +read_6120_creg32_53363 read_6120_creg32 0 53363 NULL
113338 +sock_setbindtodevice_53369 sock_setbindtodevice 3 53369 NULL
113339 +get_random_bytes_arch_53370 get_random_bytes_arch 2 53370 NULL
113340 +isr_cmd_cmplt_read_53439 isr_cmd_cmplt_read 3 53439 NULL
113341 +mwifiex_info_read_53447 mwifiex_info_read 3 53447 NULL
113342 +apei_exec_run_optional_53452 apei_exec_run_optional 0 53452 NULL
113343 +paging64_prefetch_gpte_53468 paging64_prefetch_gpte 4 53468 NULL
113344 +ima_write_template_field_data_53475 ima_write_template_field_data 2 53475 NULL
113345 +iowarrior_read_53483 iowarrior_read 3 53483 NULL
113346 +osd_req_write_kern_53486 osd_req_write_kern 5 53486 NULL
113347 +do_verify_xattr_datum_53499 do_verify_xattr_datum 0 53499 NULL
113348 +snd_pcm_format_physical_width_53505 snd_pcm_format_physical_width 0 53505 NULL
113349 +dbAllocNext_53506 dbAllocNext 0 53506 NULL
113350 +ocfs2_xattr_set_acl_53508 ocfs2_xattr_set_acl 4 53508 NULL
113351 +check_acl_53512 check_acl 0 53512 NULL
113352 +nft_data_dump_53549 nft_data_dump 5 53549 NULL
113353 +SYSC_bind_53582 SYSC_bind 3 53582 NULL
113354 +cifs_utf16_bytes_53593 cifs_utf16_bytes 0 53593 NULL
113355 +proc_uid_map_write_53596 proc_uid_map_write 3 53596 NULL
113356 +pfkey_recvmsg_53604 pfkey_recvmsg 4 53604 NULL
113357 +___alloc_bootmem_nopanic_53626 ___alloc_bootmem_nopanic 1 53626 NULL
113358 +xd_write_multiple_pages_53633 xd_write_multiple_pages 6-5 53633 NULL
113359 +ccid_getsockopt_builtin_ccids_53634 ccid_getsockopt_builtin_ccids 2 53634 NULL
113360 +nr_sendmsg_53656 nr_sendmsg 4 53656 NULL
113361 +fuse_fill_write_pages_53682 fuse_fill_write_pages 0-4 53682 NULL
113362 +v4l2_event_subscribe_53687 v4l2_event_subscribe 3 53687 NULL
113363 +bdev_logical_block_size_53690 bdev_logical_block_size 0 53690 NULL nohasharray
113364 +igb_alloc_q_vector_53690 igb_alloc_q_vector 4-6 53690 &bdev_logical_block_size_53690
113365 +find_overflow_devnum_53711 find_overflow_devnum 0 53711 NULL
113366 +bio_integrity_split_53714 bio_integrity_split 3 53714 NULL
113367 +__proc_debug_mb_53732 __proc_debug_mb 5 53732 NULL
113368 +wdm_write_53735 wdm_write 3 53735 NULL
113369 +amdtp_out_stream_get_max_payload_53755 amdtp_out_stream_get_max_payload 0 53755 NULL nohasharray
113370 +lpfc_idiag_queacc_read_qe_53755 lpfc_idiag_queacc_read_qe 0-2 53755 &amdtp_out_stream_get_max_payload_53755
113371 +ext2_acl_count_53773 ext2_acl_count 0-1 53773 NULL
113372 +__kfifo_dma_in_prepare_r_53792 __kfifo_dma_in_prepare_r 4-5 53792 NULL
113373 +qp_alloc_host_work_53798 qp_alloc_host_work 5-3 53798 NULL
113374 +regmap_raw_write_53803 regmap_raw_write 2-4 53803 NULL
113375 +lpfc_idiag_ctlacc_read_reg_53809 lpfc_idiag_ctlacc_read_reg 0-3 53809 NULL
113376 +nls_nullsize_53815 nls_nullsize 0 53815 NULL
113377 +setup_data_read_53822 setup_data_read 3 53822 NULL
113378 +pms_read_53873 pms_read 3 53873 NULL
113379 +ieee80211_if_fmt_dropped_frames_congestion_53883 ieee80211_if_fmt_dropped_frames_congestion 3 53883 NULL
113380 +SyS_setgroups_53900 SyS_setgroups 1 53900 NULL
113381 +batadv_tt_tvlv_ogm_handler_v1_53909 batadv_tt_tvlv_ogm_handler_v1 5 53909 NULL
113382 +usb_serial_generic_write_53927 usb_serial_generic_write 4 53927 NULL
113383 +ocfs2_make_clusters_writable_53938 ocfs2_make_clusters_writable 0 53938 NULL
113384 +idetape_chrdev_write_53976 idetape_chrdev_write 3 53976 NULL
113385 +__ocfs2_xattr_set_value_outside_53981 __ocfs2_xattr_set_value_outside 5 53981 NULL
113386 +ieee80211_if_fmt_dot11MeshHWMPperrMinInterval_53998 ieee80211_if_fmt_dot11MeshHWMPperrMinInterval 3 53998 NULL
113387 +hfsplus_attr_build_key_54013 hfsplus_attr_build_key 0 54013 NULL
113388 +snd_pcm_lib_write_transfer_54018 snd_pcm_lib_write_transfer 5-2-4 54018 NULL
113389 +mdc_kuc_write_54019 mdc_kuc_write 3 54019 NULL
113390 +ipxrtr_route_packet_54036 ipxrtr_route_packet 4 54036 NULL
113391 +batadv_tt_update_orig_54049 batadv_tt_update_orig 6-4 54049 NULL
113392 +pipeline_dec_packet_out_read_54052 pipeline_dec_packet_out_read 3 54052 NULL
113393 +nl80211_send_disconnected_54056 nl80211_send_disconnected 5 54056 NULL
113394 +rproc_state_read_54057 rproc_state_read 3 54057 NULL
113395 +_malloc_54077 _malloc 1 54077 NULL
113396 +bitmap_bitremap_54096 bitmap_bitremap 4 54096 NULL
113397 +altera_set_ir_pre_54103 altera_set_ir_pre 2 54103 NULL nohasharray
113398 +lustre_posix_acl_xattr_filter_54103 lustre_posix_acl_xattr_filter 2 54103 &altera_set_ir_pre_54103
113399 +__comedi_buf_write_alloc_54112 __comedi_buf_write_alloc 0-2 54112 NULL
113400 +strn_len_54122 strn_len 0 54122 NULL
113401 +isku_receive_54130 isku_receive 4 54130 NULL
113402 +isr_host_acknowledges_read_54136 isr_host_acknowledges_read 3 54136 NULL
113403 +irq_blk_threshold_write_54138 irq_blk_threshold_write 3 54138 NULL
113404 +memcpy_toiovec_54166 memcpy_toiovec 3 54166 NULL
113405 +nouveau_falcon_create__54169 nouveau_falcon_create_ 8 54169 NULL
113406 +p9_client_prepare_req_54175 p9_client_prepare_req 3 54175 NULL
113407 +do_sys_poll_54221 do_sys_poll 2 54221 NULL
113408 +__register_chrdev_54223 __register_chrdev 2-3 54223 NULL
113409 +pi_read_regr_54231 pi_read_regr 0 54231 NULL
113410 +mcp23s08_read_regs_54246 mcp23s08_read_regs 4 54246 NULL
113411 +reada_add_block_54247 reada_add_block 2 54247 NULL
113412 +xfs_dir2_sf_addname_hard_54254 xfs_dir2_sf_addname_hard 3 54254 NULL
113413 +ceph_msgpool_get_54258 ceph_msgpool_get 2 54258 NULL
113414 +audio_write_54261 audio_write 4 54261 NULL nohasharray
113415 +wusb_prf_54261 wusb_prf 7 54261 &audio_write_54261
113416 +mwifiex_getlog_read_54269 mwifiex_getlog_read 3 54269 NULL
113417 +kstrtou16_from_user_54274 kstrtou16_from_user 2 54274 NULL
113418 +tipc_multicast_54285 tipc_multicast 4 54285 NULL
113419 +altera_set_dr_post_54291 altera_set_dr_post 2 54291 NULL
113420 +dlm_alloc_pagevec_54296 dlm_alloc_pagevec 1 54296 NULL
113421 +reclaim_pages_54301 reclaim_pages 3 54301 NULL
113422 +sprintf_54306 sprintf 0 54306 NULL
113423 +bio_add_pc_page_54319 bio_add_pc_page 4 54319 NULL
113424 +br_fdb_fillbuf_54339 br_fdb_fillbuf 0 54339 NULL
113425 +__alloc_dev_table_54343 __alloc_dev_table 2 54343 NULL
113426 +__get_free_pages_54352 __get_free_pages 0 54352 NULL
113427 +tcf_hash_create_54360 tcf_hash_create 4 54360 NULL
113428 +read_file_credit_dist_stats_54367 read_file_credit_dist_stats 3 54367 NULL
113429 +vfs_readlink_54368 vfs_readlink 3 54368 NULL
113430 +do_dccp_setsockopt_54377 do_dccp_setsockopt 5 54377 NULL nohasharray
113431 +intel_sdvo_write_cmd_54377 intel_sdvo_write_cmd 4 54377 &do_dccp_setsockopt_54377
113432 +ah_alloc_tmp_54378 ah_alloc_tmp 3-2 54378 NULL
113433 +snd_pcm_oss_read2_54387 snd_pcm_oss_read2 3-0 54387 NULL
113434 +iwl_dbgfs_power_save_status_read_54392 iwl_dbgfs_power_save_status_read 3 54392 NULL
113435 +ll_ra_count_get_54410 ll_ra_count_get 3 54410 NULL
113436 +copy_gadget_strings_54417 copy_gadget_strings 2-3 54417 NULL
113437 +sparse_early_mem_maps_alloc_node_54485 sparse_early_mem_maps_alloc_node 4 54485 NULL
113438 +simple_strtoull_54493 simple_strtoull 0 54493 NULL
113439 +btrfs_ordered_sum_size_54509 btrfs_ordered_sum_size 0-2 54509 NULL
113440 +cgroup_write_X64_54514 cgroup_write_X64 5 54514 NULL
113441 +rfc4106_set_key_54519 rfc4106_set_key 3 54519 NULL
113442 +vmci_transport_dgram_enqueue_54525 vmci_transport_dgram_enqueue 4 54525 NULL
113443 +viacam_read_54526 viacam_read 3 54526 NULL
113444 +unix_dgram_connect_54535 unix_dgram_connect 3 54535 NULL
113445 +setsockopt_54539 setsockopt 5 54539 NULL
113446 +lbs_lowsnr_write_54549 lbs_lowsnr_write 3 54549 NULL
113447 +SYSC_setsockopt_54561 SYSC_setsockopt 5 54561 NULL
113448 +nfsd_vfs_write_54577 nfsd_vfs_write 6 54577 NULL
113449 +fw_iso_buffer_init_54582 fw_iso_buffer_init 3 54582 NULL
113450 +nvme_npages_54601 nvme_npages 0-1 54601 NULL
113451 +irq_pkt_threshold_write_54605 irq_pkt_threshold_write 3 54605 NULL
113452 +port_fops_write_54627 port_fops_write 3 54627 NULL
113453 +irq_timeout_read_54653 irq_timeout_read 3 54653 NULL
113454 +dns_resolver_read_54658 dns_resolver_read 3 54658 NULL
113455 +twl6030_interrupt_mask_54659 twl6030_interrupt_mask 2 54659 NULL
113456 +tdp_page_fault_54663 tdp_page_fault 2 54663 NULL
113457 +bus_add_device_54665 bus_add_device 0 54665 NULL
113458 +cw1200_queue_stats_init_54670 cw1200_queue_stats_init 2 54670 NULL
113459 +bio_kmalloc_54672 bio_kmalloc 2 54672 NULL
113460 +evm_read_key_54674 evm_read_key 3 54674 NULL
113461 +tipc_link_send_sections_fast_54689 tipc_link_send_sections_fast 3 54689 NULL
113462 +__btrfs_inc_extent_ref_54706 __btrfs_inc_extent_ref 7 54706 NULL
113463 +rfkill_fop_read_54711 rfkill_fop_read 3 54711 NULL
113464 +ocfs2_control_write_54737 ocfs2_control_write 3 54737 NULL
113465 +kzalloc_54740 kzalloc 1 54740 NULL
113466 +wep_iv_read_54744 wep_iv_read 3 54744 NULL
113467 +lpfc_idiag_pcicfg_write_54749 lpfc_idiag_pcicfg_write 3 54749 NULL
113468 +iio_event_chrdev_read_54757 iio_event_chrdev_read 3 54757 NULL
113469 +adis16480_show_firmware_date_54762 adis16480_show_firmware_date 3 54762 NULL
113470 +ldsem_atomic_update_54774 ldsem_atomic_update 1 54774 NULL
113471 +flexcop_device_kmalloc_54793 flexcop_device_kmalloc 1 54793 NULL
113472 +nfsd_write_54809 nfsd_write 6 54809 NULL
113473 +ar9287_dump_modal_eeprom_54814 ar9287_dump_modal_eeprom 3-2 54814 NULL
113474 +crypto_tfm_ctx_alignment_54815 crypto_tfm_ctx_alignment 0 54815 NULL nohasharray
113475 +kvzalloc_54815 kvzalloc 1 54815 &crypto_tfm_ctx_alignment_54815 nohasharray
113476 +aes_decrypt_fail_read_54815 aes_decrypt_fail_read 3 54815 &kvzalloc_54815
113477 +generic_perform_write_54832 generic_perform_write 3 54832 NULL
113478 +write_rio_54837 write_rio 3 54837 NULL
113479 +ext3_acl_from_disk_54839 ext3_acl_from_disk 2 54839 NULL nohasharray
113480 +nouveau_engctx_create__54839 nouveau_engctx_create_ 8 54839 &ext3_acl_from_disk_54839
113481 +ll_layout_conf_54841 ll_layout_conf 0 54841 NULL
113482 +ufx_ops_write_54848 ufx_ops_write 3 54848 NULL
113483 +printer_read_54851 printer_read 3 54851 NULL
113484 +alloc_ep_req_54860 alloc_ep_req 2 54860 NULL
113485 +broadsheet_spiflash_rewrite_sector_54864 broadsheet_spiflash_rewrite_sector 2 54864 NULL
113486 +prism_build_supp_rates_54865 prism_build_supp_rates 0 54865 NULL
113487 +iscsi_pool_init_54913 iscsi_pool_init 2-4 54913 NULL nohasharray
113488 +kobject_set_name_vargs_54913 kobject_set_name_vargs 0 54913 &iscsi_pool_init_54913
113489 +btrfs_stack_chunk_num_stripes_54923 btrfs_stack_chunk_num_stripes 0 54923 NULL
113490 +bio_add_page_54933 bio_add_page 0-3 54933 NULL
113491 +mxms_structlen_54939 mxms_structlen 0 54939 NULL
113492 +add_port_54941 add_port 2 54941 NULL
113493 +ath9k_dump_btcoex_54949 ath9k_dump_btcoex 3-0 54949 NULL
113494 +alauda_write_data_54967 alauda_write_data 3 54967 NULL
113495 +c4_add_card_54968 c4_add_card 3 54968 NULL
113496 +ext3_xattr_get_54989 ext3_xattr_get 0 54989 NULL
113497 +cx231xx_v4l2_read_55014 cx231xx_v4l2_read 3 55014 NULL
113498 +error_error_null_Frame_tx_start_read_55024 error_error_null_Frame_tx_start_read 3 55024 NULL
113499 +dgap_do_bios_load_55025 dgap_do_bios_load 3 55025 NULL
113500 +apei_exec_run_55075 apei_exec_run 0 55075 NULL
113501 +bitmap_storage_alloc_55077 bitmap_storage_alloc 2 55077 NULL
113502 +read_dma_55086 read_dma 3 55086 NULL
113503 +rxpipe_beacon_buffer_thres_host_int_trig_rx_data_read_55106 rxpipe_beacon_buffer_thres_host_int_trig_rx_data_read 3 55106 NULL
113504 +crypto_ahash_setkey_55134 crypto_ahash_setkey 3 55134 NULL
113505 +filldir_55137 filldir 3 55137 NULL
113506 +ocfs2_truncate_file_55148 ocfs2_truncate_file 3 55148 NULL
113507 +npages_to_npools_55149 npages_to_npools 0-1 55149 NULL
113508 +ieee80211_if_read_uapsd_queues_55150 ieee80211_if_read_uapsd_queues 3 55150 NULL
113509 +mtd_get_fact_prot_info_55186 mtd_get_fact_prot_info 0 55186 NULL
113510 +sel_write_relabel_55195 sel_write_relabel 3 55195 NULL
113511 +sched_feat_write_55202 sched_feat_write 3 55202 NULL
113512 +ht40allow_map_read_55209 ht40allow_map_read 3 55209 NULL
113513 +__kfifo_dma_out_prepare_r_55211 __kfifo_dma_out_prepare_r 4-5 55211 NULL
113514 +do_raw_setsockopt_55215 do_raw_setsockopt 5 55215 NULL
113515 +qxl_alloc_client_monitors_config_55216 qxl_alloc_client_monitors_config 2 55216 NULL
113516 +nouveau_mc_create__55217 nouveau_mc_create_ 4 55217 NULL
113517 +dbAllocDmap_55227 dbAllocDmap 0 55227 NULL
113518 +memcpy_fromiovec_55247 memcpy_fromiovec 3 55247 NULL
113519 +lbs_failcount_write_55276 lbs_failcount_write 3 55276 NULL
113520 +persistent_ram_new_55286 persistent_ram_new 2-1 55286 NULL
113521 +rx_streaming_interval_read_55291 rx_streaming_interval_read 3 55291 NULL
113522 +lov_get_stripecnt_55297 lov_get_stripecnt 0-3 55297 NULL
113523 +gsm_control_modem_55303 gsm_control_modem 3 55303 NULL
113524 +wimax_msg_len_55304 wimax_msg_len 0 55304 NULL
113525 +qp_alloc_guest_work_55305 qp_alloc_guest_work 5-3 55305 NULL
113526 +__vxge_hw_vpath_initialize_55328 __vxge_hw_vpath_initialize 2 55328 NULL
113527 +vme_user_read_55338 vme_user_read 3 55338 NULL
113528 +__wa_xfer_setup_sizes_55342 __wa_xfer_setup_sizes 0 55342 NULL nohasharray
113529 +sctp_datamsg_from_user_55342 sctp_datamsg_from_user 4 55342 &__wa_xfer_setup_sizes_55342
113530 +tipc_send2name_55373 tipc_send2name 5 55373 NULL
113531 +cw1200_sdio_align_size_55391 cw1200_sdio_align_size 2 55391 NULL
113532 +iwl_dbgfs_plcp_delta_read_55407 iwl_dbgfs_plcp_delta_read 3 55407 NULL
113533 +sysfs_chmod_file_55408 sysfs_chmod_file 0 55408 NULL
113534 +si476x_radio_read_rds_blckcnt_blob_55427 si476x_radio_read_rds_blckcnt_blob 3 55427 NULL
113535 +sysfs_sd_setattr_55437 sysfs_sd_setattr 0 55437 NULL
113536 +__vxge_hw_channel_allocate_55462 __vxge_hw_channel_allocate 3 55462 NULL
113537 +cx23888_ir_rx_read_55473 cx23888_ir_rx_read 3 55473 NULL
113538 +snd_pcm_lib_write_55483 snd_pcm_lib_write 0-3 55483 NULL
113539 +i2o_pool_alloc_55485 i2o_pool_alloc 4 55485 NULL
113540 +batadv_tt_entries_55487 batadv_tt_entries 0-1 55487 NULL
113541 +ras_stride_increase_window_55501 ras_stride_increase_window 3 55501 NULL
113542 +tx_tx_done_int_template_read_55511 tx_tx_done_int_template_read 3 55511 NULL
113543 +ea_get_55522 ea_get 3-0 55522 NULL
113544 +buffer_size_55534 buffer_size 0 55534 NULL
113545 +set_msr_interception_55538 set_msr_interception 2 55538 NULL
113546 +tty_port_register_device_55543 tty_port_register_device 3 55543 NULL
113547 +dgap_do_config_load_55548 dgap_do_config_load 2 55548 NULL
113548 +hash_ipport6_expire_55549 hash_ipport6_expire 4 55549 NULL
113549 +dm_stats_list_55551 dm_stats_list 4 55551 NULL
113550 +__vdev_disk_physio_55568 __vdev_disk_physio 4 55568 NULL
113551 +add_partition_55588 add_partition 2 55588 NULL
113552 +kstrtou8_from_user_55599 kstrtou8_from_user 2 55599 NULL
113553 +SyS_keyctl_55602 SyS_keyctl 4 55602 NULL nohasharray
113554 +config_buf_55602 config_buf 0 55602 &SyS_keyctl_55602
113555 +macvtap_put_user_55609 macvtap_put_user 4 55609 NULL
113556 +selinux_setprocattr_55611 selinux_setprocattr 4 55611 NULL
113557 +edge_tty_recv_55622 edge_tty_recv 3 55622 NULL
113558 +pktgen_if_write_55628 pktgen_if_write 3 55628 NULL nohasharray
113559 +reiserfs_xattr_get_55628 reiserfs_xattr_get 0 55628 &pktgen_if_write_55628
113560 +osc_obd_max_pages_per_rpc_seq_write_55636 osc_obd_max_pages_per_rpc_seq_write 3 55636 NULL
113561 +xfs_bmbt_maxrecs_55649 xfs_bmbt_maxrecs 0-2 55649 NULL
113562 +lpfc_idiag_queinfo_read_55662 lpfc_idiag_queinfo_read 3 55662 NULL
113563 +il_dbgfs_tx_queue_read_55668 il_dbgfs_tx_queue_read 3 55668 NULL
113564 +get_info_55681 get_info 3 55681 NULL
113565 +iwl_dbgfs_plcp_delta_write_55682 iwl_dbgfs_plcp_delta_write 3 55682 NULL
113566 +echo_big_lmm_get_55690 echo_big_lmm_get 0 55690 NULL
113567 +genl_allocate_reserve_groups_55705 genl_allocate_reserve_groups 1 55705 NULL
113568 +pm8001_store_update_fw_55716 pm8001_store_update_fw 4 55716 NULL
113569 +ocfs2_lock_refcount_tree_55719 ocfs2_lock_refcount_tree 0 55719 NULL
113570 +tap_pwup_write_55723 tap_pwup_write 3 55723 NULL
113571 +__iio_allocate_kfifo_55738 __iio_allocate_kfifo 2 55738 NULL
113572 +set_local_name_55757 set_local_name 4 55757 NULL
113573 +strlen_55778 strlen 0 55778 NULL
113574 +set_spte_55783 set_spte 4-5 55783 NULL
113575 +req_bio_endio_55786 req_bio_endio 3 55786 NULL nohasharray
113576 +conf_read_55786 conf_read 3 55786 &req_bio_endio_55786
113577 +uwb_rc_neh_grok_event_55799 uwb_rc_neh_grok_event 3 55799 NULL
113578 +sb16_copy_from_user_55836 sb16_copy_from_user 10-6-7 55836 NULL
113579 +ip_hdrlen_55849 ip_hdrlen 0 55849 NULL
113580 +hcd_alloc_coherent_55862 hcd_alloc_coherent 5 55862 NULL
113581 +shmem_setxattr_55867 shmem_setxattr 4 55867 NULL
113582 +hsc_write_55875 hsc_write 3 55875 NULL
113583 +ramdisk_store_55885 ramdisk_store 4 55885 NULL
113584 +pm_qos_power_read_55891 pm_qos_power_read 3 55891 NULL
113585 +hash_ip4_expire_55911 hash_ip4_expire 4 55911 NULL
113586 +snd_pcm_hw_param_value_min_55917 snd_pcm_hw_param_value_min 0 55917 NULL
113587 +ext2_direct_IO_55932 ext2_direct_IO 4 55932 NULL
113588 +kvm_write_guest_virt_system_55944 kvm_write_guest_virt_system 4-2 55944 NULL
113589 +sel_read_policy_55947 sel_read_policy 3 55947 NULL
113590 +ceph_get_direct_page_vector_55956 ceph_get_direct_page_vector 2 55956 NULL
113591 +simple_read_from_buffer_55957 simple_read_from_buffer 2-5 55957 NULL
113592 +tx_tx_imm_resp_read_55964 tx_tx_imm_resp_read 3 55964 NULL
113593 +btrfs_clone_55977 btrfs_clone 5-3 55977 NULL
113594 +wa_xfer_create_subset_sg_55992 wa_xfer_create_subset_sg 3-2 55992 NULL
113595 +nvme_alloc_iod_56027 nvme_alloc_iod 1-2 56027 NULL
113596 +dccp_sendmsg_56058 dccp_sendmsg 4 56058 NULL
113597 +pscsi_get_bio_56103 pscsi_get_bio 1 56103 NULL
113598 +add_sysfs_param_56108 add_sysfs_param 0 56108 NULL
113599 +usb_alloc_stream_buffers_56123 usb_alloc_stream_buffers 3 56123 NULL
113600 +sel_read_handle_status_56139 sel_read_handle_status 3 56139 NULL
113601 +write_file_frameerrors_56145 write_file_frameerrors 3 56145 NULL
113602 +__i2c_transfer_56162 __i2c_transfer 0 56162 NULL
113603 +rawv6_setsockopt_56165 rawv6_setsockopt 5 56165 NULL
113604 +ath9k_dump_legacy_btcoex_56194 ath9k_dump_legacy_btcoex 3-0 56194 NULL
113605 +vring_add_indirect_56222 vring_add_indirect 4 56222 NULL
113606 +ocfs2_find_xe_in_bucket_56224 ocfs2_find_xe_in_bucket 0 56224 NULL
113607 +do_ipt_set_ctl_56238 do_ipt_set_ctl 4 56238 NULL
113608 +fd_copyin_56247 fd_copyin 3 56247 NULL
113609 +sk_rmem_schedule_56255 sk_rmem_schedule 3 56255 NULL
113610 +il4965_ucode_general_stats_read_56277 il4965_ucode_general_stats_read 3 56277 NULL
113611 +ieee80211_if_fmt_user_power_level_56283 ieee80211_if_fmt_user_power_level 3 56283 NULL
113612 +RESIZE_IF_NEEDED_56286 RESIZE_IF_NEEDED 2 56286 NULL
113613 +dvb_aplay_56296 dvb_aplay 3 56296 NULL
113614 +btmrvl_hscfgcmd_read_56303 btmrvl_hscfgcmd_read 3 56303 NULL
113615 +speakup_file_write_56310 speakup_file_write 3 56310 NULL
113616 +pipeline_pre_to_defrag_swi_read_56321 pipeline_pre_to_defrag_swi_read 3 56321 NULL
113617 +journal_init_revoke_table_56331 journal_init_revoke_table 1 56331 NULL
113618 +snd_rawmidi_read_56337 snd_rawmidi_read 3 56337 NULL
113619 +vxge_os_dma_malloc_async_56348 vxge_os_dma_malloc_async 3 56348 NULL
113620 +mite_device_bytes_transferred_56355 mite_device_bytes_transferred 0 56355 NULL
113621 +iov_iter_copy_from_user_atomic_56368 iov_iter_copy_from_user_atomic 4-0 56368 NULL
113622 +dev_read_56369 dev_read 3 56369 NULL
113623 +ath10k_read_simulate_fw_crash_56371 ath10k_read_simulate_fw_crash 3 56371 NULL
113624 +write_gssp_56404 write_gssp 3 56404 NULL
113625 +ocfs2_control_read_56405 ocfs2_control_read 3 56405 NULL
113626 +do_get_write_access_56410 do_get_write_access 0 56410 NULL
113627 +store_msg_56417 store_msg 3 56417 NULL
113628 +pppol2tp_sendmsg_56420 pppol2tp_sendmsg 4 56420 NULL
113629 +fl_create_56435 fl_create 5 56435 NULL
113630 +gnttab_map_56439 gnttab_map 2 56439 NULL
113631 +cx231xx_init_isoc_56453 cx231xx_init_isoc 3-2-4 56453 NULL
113632 +set_connectable_56458 set_connectable 4 56458 NULL
113633 +osd_req_list_partition_objects_56464 osd_req_list_partition_objects 5 56464 NULL
113634 +putused_user_56467 putused_user 3 56467 NULL
113635 +lbs_rdmac_write_56471 lbs_rdmac_write 3 56471 NULL
113636 +calc_linear_pos_56472 calc_linear_pos 0-3 56472 NULL
113637 +crypto_shash_alignmask_56486 crypto_shash_alignmask 0 56486 NULL
113638 +ieee80211_rx_mgmt_probe_beacon_56491 ieee80211_rx_mgmt_probe_beacon 3 56491 NULL
113639 +init_map_ip_56508 init_map_ip 5 56508 NULL
113640 +lustre_posix_acl_xattr_reduce_space_56512 lustre_posix_acl_xattr_reduce_space 3 56512 NULL
113641 +cfg80211_connect_result_56515 cfg80211_connect_result 4-6 56515 NULL
113642 +ip_options_get_56538 ip_options_get 4 56538 NULL
113643 +ll_wr_track_id_56544 ll_wr_track_id 2 56544 NULL
113644 +alloc_apertures_56561 alloc_apertures 1 56561 NULL
113645 +rs_sta_dbgfs_stats_table_read_56573 rs_sta_dbgfs_stats_table_read 3 56573 NULL
113646 +portcntrs_2_read_56586 portcntrs_2_read 3 56586 NULL
113647 +event_filter_write_56609 event_filter_write 3 56609 NULL
113648 +nvme_trans_log_temperature_56613 nvme_trans_log_temperature 3 56613 NULL
113649 +edac_device_create_block_56619 edac_device_create_block 0 56619 NULL
113650 +gather_array_56641 gather_array 3 56641 NULL
113651 +lookup_extent_backref_56644 lookup_extent_backref 9 56644 NULL
113652 +uvc_debugfs_stats_read_56651 uvc_debugfs_stats_read 3 56651 NULL
113653 +tg3_nvram_write_block_56666 tg3_nvram_write_block 3 56666 NULL
113654 +snd_gus_dram_read_56686 snd_gus_dram_read 4 56686 NULL
113655 +dvb_ringbuffer_read_user_56702 dvb_ringbuffer_read_user 3-0 56702 NULL
113656 +sta_flags_read_56710 sta_flags_read 3 56710 NULL
113657 +ipv6_getsockopt_sticky_56711 ipv6_getsockopt_sticky 5 56711 NULL
113658 +__wa_xfer_setup_segs_56725 __wa_xfer_setup_segs 2 56725 NULL
113659 +__copy_from_user_ll_56738 __copy_from_user_ll 0-3 56738 NULL
113660 +drm_agp_bind_pages_56748 drm_agp_bind_pages 3 56748 NULL
113661 +btrfsic_map_block_56751 btrfsic_map_block 2 56751 NULL
113662 +ttm_alloc_new_pages_56792 ttm_alloc_new_pages 5 56792 NULL
113663 +do_syslog_56807 do_syslog 3 56807 NULL
113664 +mtdchar_write_56831 mtdchar_write 3 56831 NULL
113665 +snd_rawmidi_kernel_write1_56847 snd_rawmidi_kernel_write1 4-0 56847 NULL
113666 +si476x_radio_read_agc_blob_56849 si476x_radio_read_agc_blob 3 56849 NULL
113667 +ext3_xattr_ibody_get_56880 ext3_xattr_ibody_get 0 56880 NULL
113668 +pvr2_debugifc_print_status_56890 pvr2_debugifc_print_status 3 56890 NULL
113669 +debug_debug3_read_56894 debug_debug3_read 3 56894 NULL
113670 +batadv_tt_update_changes_56895 batadv_tt_update_changes 3 56895 NULL
113671 +hfsplus_find_cat_56899 hfsplus_find_cat 0 56899 NULL
113672 +hfsplus_setxattr_56902 hfsplus_setxattr 4 56902 NULL
113673 +strcspn_56913 strcspn 0 56913 NULL
113674 +__kfifo_out_56927 __kfifo_out 0-3 56927 NULL
113675 +journal_init_revoke_56933 journal_init_revoke 2 56933 NULL
113676 +nouveau_xtensa_create__56952 nouveau_xtensa_create_ 8 56952 NULL
113677 +diva_get_driver_info_56967 diva_get_driver_info 0 56967 NULL
113678 +nouveau_device_create__56984 nouveau_device_create_ 6 56984 NULL
113679 +sptlrpc_secflags2str_56995 sptlrpc_secflags2str 3 56995 NULL
113680 +vlsi_alloc_ring_57003 vlsi_alloc_ring 3-4 57003 NULL
113681 +btrfs_super_csum_size_57004 btrfs_super_csum_size 0 57004 NULL
113682 +aircable_process_packet_57027 aircable_process_packet 4 57027 NULL
113683 +ieee80211_if_fmt_state_57043 ieee80211_if_fmt_state 3 57043 NULL nohasharray
113684 +skb_network_offset_57043 skb_network_offset 0 57043 &ieee80211_if_fmt_state_57043
113685 +bytes_to_samples_57049 bytes_to_samples 0-2 57049 NULL
113686 +xfs_buf_read_map_57053 xfs_buf_read_map 3 57053 NULL
113687 +cx2341x_ctrl_new_std_57061 cx2341x_ctrl_new_std 4 57061 NULL
113688 +sca3000_read_data_57064 sca3000_read_data 4 57064 NULL
113689 +pcmcia_replace_cis_57066 pcmcia_replace_cis 3 57066 NULL
113690 +tracing_set_trace_write_57096 tracing_set_trace_write 3 57096 NULL
113691 +altera_get_note_57099 altera_get_note 6 57099 NULL
113692 +hpfs_readpages_57106 hpfs_readpages 4 57106 NULL
113693 +crypto_compress_ctxsize_57109 crypto_compress_ctxsize 0 57109 NULL
113694 +sysfs_write_file_57116 sysfs_write_file 3 57116 NULL
113695 +cipso_v4_gentag_loc_57119 cipso_v4_gentag_loc 0 57119 NULL
113696 +rds_ib_sub_signaled_57136 rds_ib_sub_signaled 2 57136 NULL nohasharray
113697 +nl80211_send_deauth_57136 nl80211_send_deauth 4 57136 &rds_ib_sub_signaled_57136 nohasharray
113698 +ima_show_htable_value_57136 ima_show_htable_value 2 57136 &nl80211_send_deauth_57136
113699 +snd_sonicvibes_getdmac_57140 snd_sonicvibes_getdmac 0 57140 NULL
113700 +udl_prime_create_57159 udl_prime_create 2 57159 NULL
113701 +stk_prepare_sio_buffers_57168 stk_prepare_sio_buffers 2 57168 NULL
113702 +rx_hw_stuck_read_57179 rx_hw_stuck_read 3 57179 NULL
113703 +hash_netnet6_expire_57191 hash_netnet6_expire 4 57191 NULL
113704 +tt3650_ci_msg_57219 tt3650_ci_msg 4 57219 NULL
113705 +dma_fifo_alloc_57236 dma_fifo_alloc 5-3-2 57236 NULL
113706 +rsxx_cram_write_57244 rsxx_cram_write 3 57244 NULL
113707 +ieee80211_if_fmt_tsf_57249 ieee80211_if_fmt_tsf 3 57249 NULL
113708 +oprofilefs_ulong_from_user_57251 oprofilefs_ulong_from_user 3 57251 NULL
113709 +alloc_flex_gd_57259 alloc_flex_gd 1 57259 NULL
113710 +lbs_sleepparams_write_57283 lbs_sleepparams_write 3 57283 NULL
113711 +pstore_file_read_57288 pstore_file_read 3 57288 NULL
113712 +snd_pcm_read_57289 snd_pcm_read 3 57289 NULL
113713 +ftdi_elan_write_57309 ftdi_elan_write 3 57309 NULL
113714 +write_file_regval_57313 write_file_regval 3 57313 NULL
113715 +__mxt_write_reg_57326 __mxt_write_reg 3 57326 NULL
113716 +usblp_read_57342 usblp_read 3 57342 NULL
113717 +print_devstats_dot11RTSFailureCount_57347 print_devstats_dot11RTSFailureCount 3 57347 NULL
113718 +dio_send_cur_page_57348 dio_send_cur_page 0 57348 NULL
113719 +tipc_bclink_stats_57372 tipc_bclink_stats 2 57372 NULL
113720 +tty_register_device_attr_57381 tty_register_device_attr 2 57381 NULL
113721 +read_file_blob_57406 read_file_blob 3 57406 NULL
113722 +enclosure_register_57412 enclosure_register 3 57412 NULL
113723 +compat_keyctl_instantiate_key_iov_57431 compat_keyctl_instantiate_key_iov 3 57431 NULL
113724 +copy_to_user_fromio_57432 copy_to_user_fromio 3 57432 NULL
113725 +__roundup_pow_of_two_57461 __roundup_pow_of_two 0 57461 NULL
113726 +sisusb_clear_vram_57466 sisusb_clear_vram 2-3 57466 NULL
113727 +ieee80211_if_read_flags_57470 ieee80211_if_read_flags 3 57470 NULL
113728 +tipc_port_reject_sections_57478 tipc_port_reject_sections 4 57478 NULL
113729 +bnad_debugfs_write_regwr_57500 bnad_debugfs_write_regwr 3 57500 NULL
113730 +skb_headlen_57501 skb_headlen 0 57501 NULL
113731 +copy_in_user_57502 copy_in_user 3 57502 NULL
113732 +ckhdid_printf_57505 ckhdid_printf 2 57505 NULL
113733 +init_tag_map_57515 init_tag_map 3 57515 NULL
113734 +il_dbgfs_force_reset_read_57517 il_dbgfs_force_reset_read 3 57517 NULL nohasharray
113735 +wil_read_file_ssid_57517 wil_read_file_ssid 3 57517 &il_dbgfs_force_reset_read_57517
113736 +cmm_read_57520 cmm_read 3 57520 NULL
113737 +inode_permission_57531 inode_permission 0 57531 NULL
113738 +acpi_dev_get_resources_57534 acpi_dev_get_resources 0 57534 NULL
113739 +ptlrpc_lprocfs_hp_ratio_seq_write_57537 ptlrpc_lprocfs_hp_ratio_seq_write 3 57537 NULL
113740 +ReadHDLCPnP_57559 ReadHDLCPnP 0 57559 NULL
113741 +obd_unpackmd_57563 obd_unpackmd 0 57563 NULL
113742 +snd_pcm_playback_ioctl1_57569 snd_pcm_playback_ioctl1 0 57569 NULL
113743 +get_bridge_ifindices_57579 get_bridge_ifindices 0 57579 NULL
113744 +ldlm_cli_enqueue_local_57582 ldlm_cli_enqueue_local 11 57582 NULL
113745 +il_dbgfs_interrupt_write_57591 il_dbgfs_interrupt_write 3 57591 NULL
113746 +read_file_spectral_fft_period_57593 read_file_spectral_fft_period 3 57593 NULL
113747 +tx_tx_retry_template_read_57623 tx_tx_retry_template_read 3 57623 NULL
113748 +sisusbcon_putcs_57630 sisusbcon_putcs 3 57630 NULL
113749 +mem_read_57631 mem_read 3 57631 NULL
113750 +r3964_write_57662 r3964_write 4 57662 NULL
113751 +proc_ns_readlink_57664 proc_ns_readlink 3 57664 NULL
113752 +__lgwrite_57669 __lgwrite 4 57669 NULL
113753 +f1x_match_to_this_node_57695 f1x_match_to_this_node 3 57695 NULL
113754 +i2400m_rx_stats_read_57706 i2400m_rx_stats_read 3 57706 NULL
113755 +ieee80211_if_read_dot11MeshHWMPconfirmationInterval_57722 ieee80211_if_read_dot11MeshHWMPconfirmationInterval 3 57722 NULL
113756 +nouveau_gpio_create__57735 nouveau_gpio_create_ 4-5 57735 NULL
113757 +pppol2tp_recvmsg_57742 pppol2tp_recvmsg 4 57742 NULL nohasharray
113758 +compat_sys_set_mempolicy_57742 compat_sys_set_mempolicy 3 57742 &pppol2tp_recvmsg_57742
113759 +ieee80211_if_fmt_dot11MeshHWMPpreqMinInterval_57762 ieee80211_if_fmt_dot11MeshHWMPpreqMinInterval 3 57762 NULL
113760 +SYSC_process_vm_writev_57776 SYSC_process_vm_writev 3-5 57776 NULL
113761 +apei_exec_collect_resources_57788 apei_exec_collect_resources 0 57788 NULL
113762 +ld2_57794 ld2 0 57794 NULL
113763 +ivtv_read_57796 ivtv_read 3 57796 NULL
113764 +bfad_debugfs_read_regrd_57830 bfad_debugfs_read_regrd 3 57830 NULL
113765 +copy_to_user_57835 copy_to_user 3-0 57835 NULL
113766 +flash_read_57843 flash_read 3 57843 NULL
113767 +kiblnd_create_tx_pool_57846 kiblnd_create_tx_pool 2 57846 NULL
113768 +xt_alloc_table_info_57903 xt_alloc_table_info 1 57903 NULL
113769 +iio_read_first_n_kfifo_57910 iio_read_first_n_kfifo 2 57910 NULL
113770 +memcg_caches_array_size_57918 memcg_caches_array_size 0-1 57918 NULL
113771 +twl_i2c_write_57923 twl_i2c_write 3-4 57923 NULL
113772 +__snd_gf1_look16_57925 __snd_gf1_look16 0 57925 NULL
113773 +sel_read_handle_unknown_57933 sel_read_handle_unknown 3 57933 NULL
113774 +xfs_mru_cache_create_57943 xfs_mru_cache_create 3 57943 NULL
113775 +key_algorithm_read_57946 key_algorithm_read 3 57946 NULL
113776 +ip_set_alloc_57953 ip_set_alloc 1 57953 NULL nohasharray
113777 +ioat3_dca_count_dca_slots_57953 ioat3_dca_count_dca_slots 0 57953 &ip_set_alloc_57953
113778 +do_rx_dma_57996 do_rx_dma 5 57996 NULL
113779 +rx_reset_counter_read_58001 rx_reset_counter_read 3 58001 NULL
113780 +iwl_dbgfs_ucode_rx_stats_read_58023 iwl_dbgfs_ucode_rx_stats_read 3 58023 NULL
113781 +io_playback_transfer_58030 io_playback_transfer 4 58030 NULL
113782 +mce_async_out_58056 mce_async_out 3 58056 NULL
113783 +ocfs2_find_leaf_58065 ocfs2_find_leaf 0 58065 NULL
113784 +dt3155_alloc_coherent_58073 dt3155_alloc_coherent 2 58073 NULL
113785 +cm4040_write_58079 cm4040_write 3 58079 NULL
113786 +ipv6_flowlabel_opt_58135 ipv6_flowlabel_opt 3 58135 NULL nohasharray
113787 +slhc_init_58135 slhc_init 1-2 58135 &ipv6_flowlabel_opt_58135
113788 +garmin_write_bulk_58191 garmin_write_bulk 3 58191 NULL
113789 +ieee80211_if_fmt_flags_58205 ieee80211_if_fmt_flags 3 58205 NULL
113790 +btrfsic_create_link_to_next_block_58246 btrfsic_create_link_to_next_block 4 58246 NULL
113791 +read_file_debug_58256 read_file_debug 3 58256 NULL
113792 +osc_max_dirty_mb_seq_write_58263 osc_max_dirty_mb_seq_write 3 58263 NULL
113793 +cfg80211_mgmt_tx_status_58266 cfg80211_mgmt_tx_status 4 58266 NULL
113794 +profile_load_58267 profile_load 3 58267 NULL
113795 +kstrtos8_from_user_58268 kstrtos8_from_user 2 58268 NULL
113796 +acpi_ds_build_internal_package_obj_58271 acpi_ds_build_internal_package_obj 3 58271 NULL
113797 +iscsi_decode_text_input_58292 iscsi_decode_text_input 4 58292 NULL
113798 +ieee80211_if_read_dot11MeshTTL_58307 ieee80211_if_read_dot11MeshTTL 3 58307 NULL
113799 +tx_tx_start_int_templates_read_58324 tx_tx_start_int_templates_read 3 58324 NULL
113800 +ext4_ext_truncate_extend_restart_58331 ext4_ext_truncate_extend_restart 3 58331 NULL
113801 +__copy_from_user_swizzled_58337 __copy_from_user_swizzled 2-4 58337 NULL
113802 +SyS_migrate_pages_58348 SyS_migrate_pages 2 58348 NULL
113803 +brcmf_debugfs_sdio_counter_read_58369 brcmf_debugfs_sdio_counter_read 3 58369 NULL
113804 +il_dbgfs_status_read_58388 il_dbgfs_status_read 3 58388 NULL
113805 +_drbd_md_sync_page_io_58403 _drbd_md_sync_page_io 6 58403 NULL
113806 +kvm_mmu_write_protect_pt_masked_58406 kvm_mmu_write_protect_pt_masked 3 58406 NULL nohasharray
113807 +idetape_pad_zeros_58406 idetape_pad_zeros 2 58406 &kvm_mmu_write_protect_pt_masked_58406
113808 +i2400m_pld_size_58415 i2400m_pld_size 0 58415 NULL
113809 +capabilities_read_58457 capabilities_read 3 58457 NULL
113810 +lpfc_idiag_baracc_read_58466 lpfc_idiag_baracc_read 3 58466 NULL nohasharray
113811 +compat_do_ipt_set_ctl_58466 compat_do_ipt_set_ctl 4 58466 &lpfc_idiag_baracc_read_58466
113812 +nv_rd08_58472 nv_rd08 0 58472 NULL
113813 +acpi_tables_sysfs_init_58477 acpi_tables_sysfs_init 0 58477 NULL
113814 +snd_gf1_read_addr_58483 snd_gf1_read_addr 0 58483 NULL
113815 +snd_rme96_capture_copy_58484 snd_rme96_capture_copy 5 58484 NULL
113816 +btrfs_cont_expand_58498 btrfs_cont_expand 2-3 58498 NULL
113817 +rndis_add_response_58544 rndis_add_response 2 58544 NULL
113818 +ldlm_srv_pool_shrink_58554 ldlm_srv_pool_shrink 0 58554 NULL
113819 +wep_decrypt_fail_read_58567 wep_decrypt_fail_read 3 58567 NULL
113820 +scnprint_mac_oui_58578 scnprint_mac_oui 3-0 58578 NULL
113821 +get_rhf_errstring_58582 get_rhf_errstring 3 58582 NULL
113822 +ea_read_inline_58589 ea_read_inline 0 58589 NULL
113823 +isku_sysfs_read_keys_thumbster_58590 isku_sysfs_read_keys_thumbster 6 58590 NULL
113824 +xip_file_read_58592 xip_file_read 3 58592 NULL
113825 +ecryptfs_write_end_58594 ecryptfs_write_end 5-3 58594 NULL
113826 +radeon_bo_size_58606 radeon_bo_size 0 58606 NULL
113827 +skb_copy_to_page_nocache_58624 skb_copy_to_page_nocache 6 58624 NULL
113828 +tx_tx_start_fw_gen_read_58648 tx_tx_start_fw_gen_read 3 58648 NULL
113829 +iwl_dbgfs_rx_handlers_write_58655 iwl_dbgfs_rx_handlers_write 3 58655 NULL
113830 +find_zero_58685 find_zero 0-1 58685 NULL
113831 +uwb_bce_print_IEs_58686 uwb_bce_print_IEs 4 58686 NULL
113832 +tps6586x_writes_58689 tps6586x_writes 2-3 58689 NULL
113833 +vx_send_msg_58711 vx_send_msg 0 58711 NULL
113834 +csum_exist_in_range_58730 csum_exist_in_range 2-3 58730 NULL
113835 +frames_to_bytes_58741 frames_to_bytes 0-2 58741 NULL
113836 +ieee80211_if_write_tkip_mic_test_58748 ieee80211_if_write_tkip_mic_test 3 58748 NULL
113837 +agp_allocate_memory_58761 agp_allocate_memory 2 58761 NULL
113838 +regmap_calc_reg_len_58795 regmap_calc_reg_len 0 58795 NULL
113839 +raw_send_hdrinc_58803 raw_send_hdrinc 4 58803 NULL
113840 +isku_sysfs_read_58806 isku_sysfs_read 5 58806 NULL
113841 +ep_read_58813 ep_read 3 58813 NULL
113842 +command_write_58841 command_write 3 58841 NULL
113843 +ath6kl_wmi_send_action_cmd_58860 ath6kl_wmi_send_action_cmd 7 58860 NULL
113844 +gs_alloc_req_58883 gs_alloc_req 2 58883 NULL
113845 +esas2r_change_queue_depth_58886 esas2r_change_queue_depth 2 58886 NULL
113846 +lprocfs_wr_pinger_recov_58914 lprocfs_wr_pinger_recov 3 58914 NULL
113847 +print_devstats_dot11FCSErrorCount_58919 print_devstats_dot11FCSErrorCount 3 58919 NULL
113848 +pipeline_cs_rx_packet_out_read_58926 pipeline_cs_rx_packet_out_read 3 58926 NULL
113849 +sptlrpc_import_sec_adapt_58948 sptlrpc_import_sec_adapt 0 58948 NULL
113850 +wait_table_hash_nr_entries_58962 wait_table_hash_nr_entries 0 58962 NULL
113851 +ieee80211_if_fmt_dot11MeshHWMPactivePathToRootTimeout_58965 ieee80211_if_fmt_dot11MeshHWMPactivePathToRootTimeout 3 58965 NULL
113852 +crypto_aead_ivsize_58970 crypto_aead_ivsize 0 58970 NULL
113853 +init_list_set_59005 init_list_set 3 59005 NULL
113854 +ep_write_59008 ep_write 3 59008 NULL
113855 +lpfc_idiag_baracc_write_59014 lpfc_idiag_baracc_write 3 59014 NULL
113856 +SyS_preadv_59029 SyS_preadv 3 59029 NULL
113857 +init_pci_cap_msi_perm_59033 init_pci_cap_msi_perm 2 59033 NULL
113858 +selinux_transaction_write_59038 selinux_transaction_write 3 59038 NULL
113859 +crypto_aead_reqsize_59039 crypto_aead_reqsize 0 59039 NULL
113860 +regmap_bulk_write_59049 regmap_bulk_write 2-4 59049 NULL
113861 +sysfs_link_sibling_59078 sysfs_link_sibling 0 59078 NULL
113862 +mmc_sd_num_wr_blocks_59112 mmc_sd_num_wr_blocks 0 59112 NULL
113863 +scsi_io_completion_59122 scsi_io_completion 2 59122 NULL
113864 +nfc_llcp_send_i_frame_59130 nfc_llcp_send_i_frame 3 59130 NULL
113865 +print_devstats_dot11RTSSuccessCount_59145 print_devstats_dot11RTSSuccessCount 3 59145 NULL nohasharray
113866 +framebuffer_alloc_59145 framebuffer_alloc 1 59145 &print_devstats_dot11RTSSuccessCount_59145
113867 +radeon_compat_ioctl_59150 radeon_compat_ioctl 2 59150 NULL
113868 +pvr2_hdw_report_clients_59152 pvr2_hdw_report_clients 3 59152 NULL
113869 +md_getxattr_59161 md_getxattr 0 59161 NULL
113870 +ksize_59176 ksize 0 59176 NULL
113871 +setup_window_59178 setup_window 4-2-5-7 59178 NULL
113872 +ocfs2_move_extent_59187 ocfs2_move_extent 2-5 59187 NULL
113873 +xfs_iext_realloc_indirect_59211 xfs_iext_realloc_indirect 2 59211 NULL
113874 +check_mapped_selector_name_59216 check_mapped_selector_name 5 59216 NULL
113875 +dt3155_read_59226 dt3155_read 3 59226 NULL
113876 +paging64_gpte_to_gfn_lvl_59229 paging64_gpte_to_gfn_lvl 0-1-2 59229 NULL
113877 +tty_prepare_flip_string_flags_59240 tty_prepare_flip_string_flags 4 59240 NULL
113878 +nla_len_59258 nla_len 0 59258 NULL
113879 +drbd_bm_write_page_59290 drbd_bm_write_page 2 59290 NULL
113880 +btrfs_insert_dir_item_59304 btrfs_insert_dir_item 4 59304 NULL
113881 +fd_copyout_59323 fd_copyout 3 59323 NULL
113882 +read_9287_modal_eeprom_59327 read_9287_modal_eeprom 3 59327 NULL
113883 +rx_defrag_in_process_called_read_59338 rx_defrag_in_process_called_read 3 59338 NULL
113884 +xfs_attrmulti_attr_set_59346 xfs_attrmulti_attr_set 4 59346 NULL
113885 +__map_request_59350 __map_request 0 59350 NULL
113886 +f2fs_fallocate_59377 f2fs_fallocate 3-4 59377 NULL
113887 +pvr2_debugifc_print_info_59380 pvr2_debugifc_print_info 3 59380 NULL
113888 +journal_init_dev_59384 journal_init_dev 5 59384 NULL
113889 +__net_get_random_once_59389 __net_get_random_once 2 59389 NULL
113890 +isku_sysfs_read_keys_function_59412 isku_sysfs_read_keys_function 6 59412 NULL
113891 +pci_ctrl_read_59424 pci_ctrl_read 0 59424 NULL
113892 +vxge_hw_ring_rxds_per_block_get_59425 vxge_hw_ring_rxds_per_block_get 0 59425 NULL
113893 +SyS_sched_setaffinity_59442 SyS_sched_setaffinity 2 59442 NULL
113894 +fs_path_ensure_buf_59445 fs_path_ensure_buf 2 59445 NULL
113895 +ib_copy_from_udata_59502 ib_copy_from_udata 3 59502 NULL
113896 +mic_vringh_copy_59523 mic_vringh_copy 4 59523 NULL
113897 +mpi_get_nbits_59551 mpi_get_nbits 0 59551 NULL
113898 +tunables_write_59563 tunables_write 3 59563 NULL
113899 +__copy_from_user_ll_nozero_59571 __copy_from_user_ll_nozero 0-3 59571 NULL
113900 +write_pbl_59583 write_pbl 4 59583 NULL
113901 +memdup_user_59590 memdup_user 2 59590 NULL
113902 +xrcdn_free_res_59616 xrcdn_free_res 5 59616 NULL nohasharray
113903 +mem_fwlog_free_mem_blks_read_59616 mem_fwlog_free_mem_blks_read 3 59616 &xrcdn_free_res_59616
113904 +ath6kl_endpoint_stats_write_59621 ath6kl_endpoint_stats_write 3 59621 NULL
113905 +mtrr_write_59622 mtrr_write 3 59622 NULL
113906 +find_first_zero_bit_59636 find_first_zero_bit 0 59636 NULL
113907 +SyS_setdomainname_59646 SyS_setdomainname 2 59646 NULL
113908 +hidraw_read_59650 hidraw_read 3 59650 NULL
113909 +v9fs_xattr_set_acl_59651 v9fs_xattr_set_acl 4 59651 NULL
113910 +__devcgroup_check_permission_59665 __devcgroup_check_permission 0 59665 NULL
113911 +iwl_dbgfs_mac_params_read_59666 iwl_dbgfs_mac_params_read 3 59666 NULL
113912 +alloc_dca_provider_59670 alloc_dca_provider 2 59670 NULL
113913 +mic_calc_failure_read_59700 mic_calc_failure_read 3 59700 NULL
113914 +ioperm_get_59701 ioperm_get 4-3 59701 NULL
113915 +prism2_info_scanresults_59729 prism2_info_scanresults 3 59729 NULL
113916 +ieee80211_if_read_fwded_unicast_59740 ieee80211_if_read_fwded_unicast 3 59740 NULL
113917 +fat_direct_IO_59741 fat_direct_IO 4 59741 NULL
113918 +qib_decode_7220_sdma_errs_59745 qib_decode_7220_sdma_errs 4 59745 NULL
113919 +strnlen_59746 strnlen 0 59746 NULL
113920 +ext3_acl_count_59754 ext3_acl_count 0-1 59754 NULL
113921 +long_retry_limit_read_59766 long_retry_limit_read 3 59766 NULL
113922 +venus_remove_59781 venus_remove 4 59781 NULL
113923 +mei_nfc_recv_59784 mei_nfc_recv 3 59784 NULL
113924 +C_SYSC_preadv_59801 C_SYSC_preadv 3 59801 NULL
113925 +ipw_write_59807 ipw_write 3 59807 NULL
113926 +scsi_init_shared_tag_map_59812 scsi_init_shared_tag_map 2 59812 NULL
113927 +ieee80211_if_read_dot11MeshHWMPmaxPREQretries_59829 ieee80211_if_read_dot11MeshHWMPmaxPREQretries 3 59829 NULL
113928 +gspca_dev_probe2_59833 gspca_dev_probe2 4 59833 NULL
113929 +regmap_raw_write_async_59849 regmap_raw_write_async 2-4 59849 NULL
113930 +pvr2_ioread_set_sync_key_59882 pvr2_ioread_set_sync_key 3 59882 NULL
113931 +l2cap_sock_recvmsg_59886 l2cap_sock_recvmsg 4 59886 NULL
113932 +ffs_prepare_buffer_59892 ffs_prepare_buffer 2 59892 NULL
113933 +ocfs2_extend_rotate_transaction_59894 ocfs2_extend_rotate_transaction 2-3 59894 NULL
113934 +aic7xxx_abort_waiting_scb_59932 aic7xxx_abort_waiting_scb 0 59932 NULL
113935 +kvm_mmu_notifier_invalidate_range_start_59944 kvm_mmu_notifier_invalidate_range_start 3-4 59944 NULL
113936 +dapm_widget_power_read_file_59950 dapm_widget_power_read_file 3 59950 NULL nohasharray
113937 +il_dbgfs_rxon_flags_read_59950 il_dbgfs_rxon_flags_read 3 59950 &dapm_widget_power_read_file_59950
113938 +il_dbgfs_missed_beacon_read_59956 il_dbgfs_missed_beacon_read 3 59956 NULL
113939 +__arch_hweight16_59975 __arch_hweight16 0 59975 NULL
113940 +osd_req_read_kern_59990 osd_req_read_kern 5 59990 NULL
113941 +ghash_async_setkey_60001 ghash_async_setkey 3 60001 NULL
113942 +ieee80211_if_fmt_dot11MeshAwakeWindowDuration_60006 ieee80211_if_fmt_dot11MeshAwakeWindowDuration 3 60006 NULL
113943 +rawsock_sendmsg_60010 rawsock_sendmsg 4 60010 NULL
113944 +mthca_init_cq_60011 mthca_init_cq 2 60011 NULL
113945 +osd_req_list_dev_partitions_60027 osd_req_list_dev_partitions 4 60027 NULL
113946 +xlog_bread_offset_60030 xlog_bread_offset 3 60030 NULL
113947 +bio_integrity_hw_sectors_60039 bio_integrity_hw_sectors 0-2 60039 NULL
113948 +do_ip6t_set_ctl_60040 do_ip6t_set_ctl 4 60040 NULL
113949 +vcs_size_60050 vcs_size 0 60050 NULL
113950 +gru_alloc_gts_60056 gru_alloc_gts 3-2 60056 NULL
113951 +compat_writev_60063 compat_writev 3 60063 NULL
113952 +ath6kl_listen_int_write_60066 ath6kl_listen_int_write 3 60066 NULL
113953 +c4iw_num_stags_60073 c4iw_num_stags 0 60073 NULL
113954 +rxrpc_kernel_send_data_60083 rxrpc_kernel_send_data 3 60083 NULL
113955 +ieee80211_if_fmt_fwded_frames_60103 ieee80211_if_fmt_fwded_frames 3 60103 NULL
113956 +SYSC_msgsnd_60113 SYSC_msgsnd 3 60113 NULL
113957 +nfs_idmap_request_key_60124 nfs_idmap_request_key 2 60124 NULL
113958 +__mutex_lock_common_60134 __mutex_lock_common 0 60134 NULL
113959 +ld_usb_read_60156 ld_usb_read 3 60156 NULL
113960 +jmb38x_ms_count_slots_60164 jmb38x_ms_count_slots 0 60164 NULL
113961 +init_state_60165 init_state 2 60165 NULL
113962 +jffs2_alloc_full_dirent_60179 jffs2_alloc_full_dirent 1 60179 NULL nohasharray
113963 +sg_build_sgat_60179 sg_build_sgat 3 60179 &jffs2_alloc_full_dirent_60179
113964 +fuse_async_req_send_60183 fuse_async_req_send 0-3 60183 NULL
113965 +rx_rx_tkip_replays_read_60193 rx_rx_tkip_replays_read 3 60193 NULL
113966 +qib_reg_phys_mr_60202 qib_reg_phys_mr 3 60202 NULL
113967 +btrfs_get_token_16_60220 btrfs_get_token_16 0 60220 NULL
113968 +irq_alloc_domain_generic_chips_60264 irq_alloc_domain_generic_chips 2-3 60264 NULL
113969 +display_crc_ctl_write_60273 display_crc_ctl_write 3 60273 NULL
113970 +printer_write_60276 printer_write 3 60276 NULL
113971 +do_xip_mapping_read_60297 do_xip_mapping_read 5 60297 NULL
113972 +getDataLength_60301 getDataLength 0 60301 NULL
113973 +usb_alphatrack_write_60341 usb_alphatrack_write 3 60341 NULL
113974 +__kfifo_from_user_r_60345 __kfifo_from_user_r 5-3 60345 NULL
113975 +dccp_setsockopt_60367 dccp_setsockopt 5 60367 NULL
113976 +mthca_alloc_resize_buf_60394 mthca_alloc_resize_buf 3 60394 NULL
113977 +ocfs2_zero_extend_60396 ocfs2_zero_extend 3 60396 NULL
113978 +driver_names_read_60399 driver_names_read 3 60399 NULL
113979 +simple_alloc_urb_60420 simple_alloc_urb 3 60420 NULL
113980 +excessive_retries_read_60425 excessive_retries_read 3 60425 NULL
113981 +kmalloc_60432 kmalloc 1 60432 NULL nohasharray
113982 +tstats_write_60432 tstats_write 3 60432 &kmalloc_60432
113983 +snd_hda_get_num_raw_conns_60462 snd_hda_get_num_raw_conns 0 60462 NULL
113984 +crypto_shash_setkey_60483 crypto_shash_setkey 3 60483 NULL
113985 +lustre_msg_early_size_60496 lustre_msg_early_size 0 60496 NULL
113986 +v9fs_fid_readn_60544 v9fs_fid_readn 4 60544 NULL
113987 +nonpaging_map_60551 nonpaging_map 4 60551 NULL
113988 +osc_lockless_truncate_seq_write_60553 osc_lockless_truncate_seq_write 3 60553 NULL
113989 +tracing_entries_write_60563 tracing_entries_write 3 60563 NULL
113990 +skb_transport_offset_60619 skb_transport_offset 0 60619 NULL
113991 +wl1273_fm_fops_write_60621 wl1273_fm_fops_write 3 60621 NULL
113992 +acl_alloc_stack_init_60630 acl_alloc_stack_init 1 60630 NULL
113993 +__proc_lnet_stats_60647 __proc_lnet_stats 5 60647 NULL
113994 +if_sdio_host_to_card_60666 if_sdio_host_to_card 4 60666 NULL
113995 +ieee80211_if_read_dot11MeshConfirmTimeout_60670 ieee80211_if_read_dot11MeshConfirmTimeout 3 60670 NULL
113996 +vga_rcrt_60731 vga_rcrt 0 60731 NULL
113997 +snd_ice1712_ds_read_60754 snd_ice1712_ds_read 0 60754 NULL
113998 +raid_status_60755 raid_status 5 60755 NULL
113999 +sel_write_checkreqprot_60774 sel_write_checkreqprot 3 60774 NULL
114000 +opticon_write_60775 opticon_write 4 60775 NULL
114001 +acl_alloc_num_60778 acl_alloc_num 1-2 60778 NULL
114002 +snd_pcm_oss_readv3_60792 snd_pcm_oss_readv3 3 60792 NULL
114003 +pwr_tx_with_ps_read_60851 pwr_tx_with_ps_read 3 60851 NULL
114004 +alloc_buf_60864 alloc_buf 3-2 60864 NULL
114005 +generic_writepages_60871 generic_writepages 0 60871 NULL
114006 +ext4_update_inline_data_60888 ext4_update_inline_data 3 60888 NULL
114007 +iio_debugfs_read_reg_60908 iio_debugfs_read_reg 3 60908 NULL
114008 +libcfs_sock_ioctl_60915 libcfs_sock_ioctl 0 60915 NULL
114009 +mgt_set_varlen_60916 mgt_set_varlen 4 60916 NULL
114010 +scrub_chunk_60926 scrub_chunk 5 60926 NULL
114011 +submit_extent_page_60928 submit_extent_page 5 60928 NULL
114012 +pti_char_write_60960 pti_char_write 3 60960 NULL
114013 +mwifiex_alloc_sdio_mpa_buffers_60961 mwifiex_alloc_sdio_mpa_buffers 2-3 60961 NULL
114014 +__a2mp_build_60987 __a2mp_build 3 60987 NULL
114015 +hsc_msg_alloc_60990 hsc_msg_alloc 1 60990 NULL
114016 +ath6kl_lrssi_roam_read_61022 ath6kl_lrssi_roam_read 3 61022 NULL
114017 +graph_depth_write_61024 graph_depth_write 3 61024 NULL
114018 +sdhci_pltfm_register_61031 sdhci_pltfm_register 3 61031 NULL
114019 +lpfc_idiag_queacc_write_61043 lpfc_idiag_queacc_write 3 61043 NULL
114020 +symtab_init_61050 symtab_init 2 61050 NULL
114021 +fuse_send_write_61053 fuse_send_write 0-4 61053 NULL
114022 +bitmap_scnlistprintf_61062 bitmap_scnlistprintf 0-2 61062 NULL
114023 +ahash_align_buffer_size_61070 ahash_align_buffer_size 0-1-2 61070 NULL
114024 +get_derived_key_61100 get_derived_key 4 61100 NULL
114025 +i40e_calculate_l2fpm_size_61104 i40e_calculate_l2fpm_size 0-1-2-3-4 61104 NULL
114026 +alloc_chrdev_region_61112 alloc_chrdev_region 0 61112 NULL
114027 +__probe_kernel_read_61119 __probe_kernel_read 3 61119 NULL
114028 +vmemmap_alloc_block_buf_61126 vmemmap_alloc_block_buf 1 61126 NULL
114029 +afs_proc_cells_write_61139 afs_proc_cells_write 3 61139 NULL
114030 +brcmf_sdio_chip_cr4_exitdl_61143 brcmf_sdio_chip_cr4_exitdl 4 61143 NULL
114031 +osl_malloc_61156 osl_malloc 2 61156 NULL
114032 +pair_device_61175 pair_device 4 61175 NULL nohasharray
114033 +event_oom_late_read_61175 event_oom_late_read 3 61175 &pair_device_61175
114034 +dio_bio_add_page_61178 dio_bio_add_page 0 61178 NULL
114035 +SyS_prctl_61202 SyS_prctl 4 61202 NULL
114036 +arch_hibernation_header_save_61212 arch_hibernation_header_save 0 61212 NULL
114037 +smk_read_ambient_61220 smk_read_ambient 3 61220 NULL
114038 +btrfs_bio_alloc_61270 btrfs_bio_alloc 3 61270 NULL nohasharray
114039 +find_get_pages_tag_61270 find_get_pages_tag 0 61270 &btrfs_bio_alloc_61270 nohasharray
114040 +ifalias_store_61270 ifalias_store 4 61270 &find_get_pages_tag_61270
114041 +vortex_adbdma_getlinearpos_61283 vortex_adbdma_getlinearpos 0 61283 NULL nohasharray
114042 +hfsplus_getxattr_finder_info_61283 hfsplus_getxattr_finder_info 0 61283 &vortex_adbdma_getlinearpos_61283
114043 +nvme_trans_copy_to_user_61288 nvme_trans_copy_to_user 3 61288 NULL
114044 +xfer_from_user_61307 xfer_from_user 3 61307 NULL
114045 +xfrm_user_sec_ctx_size_61320 xfrm_user_sec_ctx_size 0 61320 NULL
114046 +C_SYSC_msgsnd_61330 C_SYSC_msgsnd 3 61330 NULL
114047 +write_file_spectral_short_repeat_61335 write_file_spectral_short_repeat 3 61335 NULL
114048 +st5481_setup_isocpipes_61340 st5481_setup_isocpipes 6-4 61340 NULL
114049 +rx_rx_wa_ba_not_expected_read_61341 rx_rx_wa_ba_not_expected_read 3 61341 NULL
114050 +__dm_get_reserved_ios_61342 __dm_get_reserved_ios 0-3-2 61342 NULL
114051 +f1x_map_sysaddr_to_csrow_61344 f1x_map_sysaddr_to_csrow 2 61344 NULL
114052 +debug_debug4_read_61367 debug_debug4_read 3 61367 NULL
114053 +system_enable_write_61396 system_enable_write 3 61396 NULL
114054 +xfs_zero_remaining_bytes_61423 xfs_zero_remaining_bytes 3 61423 NULL
114055 +unix_stream_sendmsg_61455 unix_stream_sendmsg 4 61455 NULL
114056 +snd_pcm_lib_writev_transfer_61483 snd_pcm_lib_writev_transfer 5-4-2 61483 NULL
114057 +btrfs_item_size_61485 btrfs_item_size 0 61485 NULL
114058 +ocfs2_get_refcount_rec_61514 ocfs2_get_refcount_rec 0 61514 NULL
114059 +erst_errno_61526 erst_errno 0 61526 NULL
114060 +trace_options_core_write_61551 trace_options_core_write 3 61551 NULL
114061 +dvb_net_ioctl_61559 dvb_net_ioctl 2 61559 NULL
114062 +parport_pc_fifo_write_block_dma_61568 parport_pc_fifo_write_block_dma 3 61568 NULL
114063 +fan_proc_write_61569 fan_proc_write 3 61569 NULL
114064 +ieee80211_if_read_rc_rateidx_mask_2ghz_61570 ieee80211_if_read_rc_rateidx_mask_2ghz 3 61570 NULL
114065 +ldlm_pool_rw_atomic_seq_write_61572 ldlm_pool_rw_atomic_seq_write 3 61572 NULL
114066 +seq_open_private_61589 seq_open_private 3 61589 NULL
114067 +ept_gpte_to_gfn_lvl_61591 ept_gpte_to_gfn_lvl 0-1-2 61591 NULL
114068 +netlink_recvmsg_61600 netlink_recvmsg 4 61600 NULL
114069 +nfs4_init_uniform_client_string_61601 nfs4_init_uniform_client_string 3 61601 NULL
114070 +configfs_write_file_61621 configfs_write_file 3 61621 NULL
114071 +ieee80211_if_fmt_hw_queues_61629 ieee80211_if_fmt_hw_queues 3 61629 NULL
114072 +i2o_parm_table_get_61635 i2o_parm_table_get 6 61635 NULL
114073 +snd_pcm_oss_read3_61643 snd_pcm_oss_read3 0-3 61643 NULL
114074 +resize_stripes_61650 resize_stripes 2 61650 NULL
114075 +ttm_page_pool_free_61661 ttm_page_pool_free 2-0 61661 NULL
114076 +insert_one_name_61668 insert_one_name 7 61668 NULL
114077 +qib_format_hwmsg_61679 qib_format_hwmsg 2 61679 NULL
114078 +lock_loop_61681 lock_loop 1 61681 NULL
114079 +__do_tune_cpucache_61684 __do_tune_cpucache 2 61684 NULL
114080 +filter_read_61692 filter_read 3 61692 NULL
114081 +iov_length_61716 iov_length 0 61716 NULL
114082 +fragmentation_threshold_read_61718 fragmentation_threshold_read 3 61718 NULL
114083 +null_alloc_reqbuf_61719 null_alloc_reqbuf 3 61719 NULL
114084 +read_file_interrupt_61742 read_file_interrupt 3 61742 NULL nohasharray
114085 +read_file_regval_61742 read_file_regval 3 61742 &read_file_interrupt_61742
114086 +SyS_sendto_61763 SyS_sendto 6 61763 NULL
114087 +mls_compute_context_len_61812 mls_compute_context_len 0 61812 NULL
114088 +bfad_debugfs_write_regwr_61841 bfad_debugfs_write_regwr 3 61841 NULL
114089 +regcache_sync_block_61846 regcache_sync_block 5-4 61846 NULL
114090 +ath9k_hw_def_dump_eeprom_61853 ath9k_hw_def_dump_eeprom 5-4 61853 NULL
114091 +fs_path_prepare_for_add_61854 fs_path_prepare_for_add 2 61854 NULL
114092 +evdev_compute_buffer_size_61863 evdev_compute_buffer_size 0 61863 NULL
114093 +SYSC_lsetxattr_61869 SYSC_lsetxattr 4 61869 NULL
114094 +get_fw_name_61874 get_fw_name 3 61874 NULL
114095 +btrfs_ioctl_clone_61886 btrfs_ioctl_clone 3-4-5 61886 NULL
114096 +lprocfs_write_frac_u64_helper_61897 lprocfs_write_frac_u64_helper 2 61897 NULL
114097 +lov_mds_md_stripecnt_61899 lov_mds_md_stripecnt 0-1 61899 NULL
114098 +clear_refs_write_61904 clear_refs_write 3 61904 NULL nohasharray
114099 +import_sec_check_expire_61904 import_sec_check_expire 0 61904 &clear_refs_write_61904
114100 +rx_filter_arp_filter_read_61914 rx_filter_arp_filter_read 3 61914 NULL
114101 +au0828_init_isoc_61917 au0828_init_isoc 3-2-4 61917 NULL
114102 +sctp_sendmsg_61919 sctp_sendmsg 4 61919 NULL
114103 +edac_device_create_instance_61940 edac_device_create_instance 0 61940 NULL
114104 +SyS_kexec_load_61946 SyS_kexec_load 2 61946 NULL
114105 +il4965_ucode_rx_stats_read_61948 il4965_ucode_rx_stats_read 3 61948 NULL
114106 +squashfs_read_id_index_table_61961 squashfs_read_id_index_table 4 61961 NULL
114107 +fix_read_error_61965 fix_read_error 4 61965 NULL
114108 +ocfs2_quota_write_61972 ocfs2_quota_write 4-5 61972 NULL
114109 +fd_locked_ioctl_61978 fd_locked_ioctl 3 61978 NULL
114110 +cow_file_range_61979 cow_file_range 3 61979 NULL
114111 +dequeue_event_62000 dequeue_event 3 62000 NULL
114112 +xt_compat_match_offset_62011 xt_compat_match_offset 0 62011 NULL
114113 +SyS_setxattr_62019 SyS_setxattr 4 62019 NULL
114114 +jffs2_do_unlink_62020 jffs2_do_unlink 4 62020 NULL
114115 +SYSC_select_62024 SYSC_select 1 62024 NULL
114116 +pmcraid_build_passthrough_ioadls_62034 pmcraid_build_passthrough_ioadls 2 62034 NULL
114117 +sctp_user_addto_chunk_62047 sctp_user_addto_chunk 2-3 62047 NULL
114118 +do_pselect_62061 do_pselect 1 62061 NULL
114119 +pcpu_alloc_bootmem_62074 pcpu_alloc_bootmem 2 62074 NULL
114120 +jffs2_security_setxattr_62107 jffs2_security_setxattr 4 62107 NULL
114121 +btrfs_direct_IO_62114 btrfs_direct_IO 4 62114 NULL
114122 +ip_recv_error_62117 ip_recv_error 3 62117 NULL
114123 +generic_block_fiemap_62122 generic_block_fiemap 4 62122 NULL
114124 +llc_ui_header_len_62131 llc_ui_header_len 0 62131 NULL
114125 +kobject_add_varg_62133 kobject_add_varg 0 62133 NULL nohasharray
114126 +qib_diag_write_62133 qib_diag_write 3 62133 &kobject_add_varg_62133
114127 +device_add_attrs_62135 device_add_attrs 0 62135 NULL nohasharray
114128 +ql_status_62135 ql_status 5 62135 &device_add_attrs_62135
114129 +video_usercopy_62151 video_usercopy 2 62151 NULL
114130 +SyS_getxattr_62166 SyS_getxattr 4 62166 NULL
114131 +prism54_wpa_bss_ie_get_62173 prism54_wpa_bss_ie_get 0 62173 NULL
114132 +write_file_dfs_62180 write_file_dfs 3 62180 NULL
114133 +alloc_upcall_62186 alloc_upcall 2 62186 NULL
114134 +btrfs_xattr_acl_set_62203 btrfs_xattr_acl_set 4 62203 NULL
114135 +sock_kmalloc_62205 sock_kmalloc 2 62205 NULL
114136 +SYSC_setgroups16_62232 SYSC_setgroups16 1 62232 NULL
114137 +nfsd_read_file_62241 nfsd_read_file 6 62241 NULL
114138 +subtract_dirty_62242 subtract_dirty 2-3 62242 NULL
114139 +get_random_int_62279 get_random_int 0 62279 NULL
114140 +il_dbgfs_sram_read_62296 il_dbgfs_sram_read 3 62296 NULL
114141 +sparse_early_usemaps_alloc_pgdat_section_62304 sparse_early_usemaps_alloc_pgdat_section 2 62304 NULL
114142 +subsystem_filter_read_62310 subsystem_filter_read 3 62310 NULL
114143 +Wb35Reg_BurstWrite_62327 Wb35Reg_BurstWrite 4 62327 NULL
114144 +ocfs2_xattr_buckets_per_cluster_62330 ocfs2_xattr_buckets_per_cluster 0 62330 NULL
114145 +subseq_list_62332 subseq_list 3-0 62332 NULL
114146 +ll_statahead_max_seq_write_62333 ll_statahead_max_seq_write 3 62333 NULL
114147 +flash_write_62354 flash_write 3 62354 NULL
114148 +xfpregs_set_62363 xfpregs_set 4 62363 NULL
114149 +rx_rx_timeout_read_62389 rx_rx_timeout_read 3 62389 NULL
114150 +altera_irscan_62396 altera_irscan 2 62396 NULL
114151 +set_ssp_62411 set_ssp 4 62411 NULL
114152 +ext_rts51x_sd_execute_read_data_62501 ext_rts51x_sd_execute_read_data 9 62501 NULL
114153 +pep_sendmsg_62524 pep_sendmsg 4 62524 NULL
114154 +test_iso_queue_62534 test_iso_queue 5 62534 NULL
114155 +debugfs_read_62535 debugfs_read 3 62535 NULL
114156 +sco_sock_sendmsg_62542 sco_sock_sendmsg 4 62542 NULL
114157 +qib_refresh_qsfp_cache_62547 qib_refresh_qsfp_cache 0 62547 NULL
114158 +link_send_sections_long_62557 link_send_sections_long 3 62557 NULL
114159 +xfrm_user_policy_62573 xfrm_user_policy 4 62573 NULL
114160 +compat_SyS_rt_sigpending_62580 compat_SyS_rt_sigpending 2 62580 NULL
114161 +get_subdir_62581 get_subdir 3 62581 NULL
114162 +nfsd_vfs_read_62605 nfsd_vfs_read 6 62605 NULL
114163 +tipc_port_recv_sections_62609 tipc_port_recv_sections 3 62609 NULL
114164 +dut_mode_write_62630 dut_mode_write 3 62630 NULL
114165 +vfs_fsync_range_62635 vfs_fsync_range 0 62635 NULL
114166 +lpfc_sli4_queue_alloc_62646 lpfc_sli4_queue_alloc 3 62646 NULL
114167 +ocfs2_wait_for_mask_interruptible_62675 ocfs2_wait_for_mask_interruptible 0 62675 NULL
114168 +printer_req_alloc_62687 printer_req_alloc 2 62687 NULL
114169 +bioset_integrity_create_62708 bioset_integrity_create 2 62708 NULL
114170 +gfs2_log_write_62717 gfs2_log_write 3 62717 NULL
114171 +rdm_62719 rdm 0 62719 NULL
114172 +obd_ioctl_popdata_62741 obd_ioctl_popdata 3 62741 NULL
114173 +key_replays_read_62746 key_replays_read 3 62746 NULL
114174 +lov_verify_lmm_62747 lov_verify_lmm 2 62747 NULL
114175 +mwifiex_rdeeprom_write_62754 mwifiex_rdeeprom_write 3 62754 NULL
114176 +ax25_sendmsg_62770 ax25_sendmsg 4 62770 NULL
114177 +C_SYSC_ipc_62776 C_SYSC_ipc 3 62776 NULL
114178 +SyS_sched_getaffinity_62786 SyS_sched_getaffinity 2 62786 NULL
114179 +dm_stats_account_io_62787 dm_stats_account_io 3 62787 NULL
114180 +tracing_total_entries_read_62817 tracing_total_entries_read 3 62817 NULL
114181 +__rounddown_pow_of_two_62836 __rounddown_pow_of_two 0 62836 NULL
114182 +bio_get_nr_vecs_62838 bio_get_nr_vecs 0 62838 NULL
114183 +xlog_recover_add_to_trans_62839 xlog_recover_add_to_trans 4 62839 NULL
114184 +rx_fcs_err_read_62844 rx_fcs_err_read 3 62844 NULL
114185 +read_nic_io_dword_62859 read_nic_io_dword 0 62859 NULL
114186 +l2tp_ip6_recvmsg_62874 l2tp_ip6_recvmsg 4 62874 NULL
114187 +aoechr_write_62883 aoechr_write 3 62883 NULL
114188 +if_spi_host_to_card_62890 if_spi_host_to_card 4 62890 NULL
114189 +ocfs2_validate_gd_parent_62905 ocfs2_validate_gd_parent 0 62905 NULL
114190 +mempool_create_slab_pool_62907 mempool_create_slab_pool 1 62907 NULL
114191 +getdqbuf_62908 getdqbuf 1 62908 NULL
114192 +ll_statahead_agl_seq_write_62928 ll_statahead_agl_seq_write 3 62928 NULL
114193 +agp_create_user_memory_62955 agp_create_user_memory 1 62955 NULL
114194 +kstrtoull_from_user_63026 kstrtoull_from_user 2 63026 NULL
114195 +__vb2_perform_fileio_63033 __vb2_perform_fileio 3 63033 NULL
114196 +pipeline_defrag_to_csum_swi_read_63037 pipeline_defrag_to_csum_swi_read 3 63037 NULL
114197 +scsi_host_alloc_63041 scsi_host_alloc 2 63041 NULL
114198 +unlink1_63059 unlink1 3 63059 NULL
114199 +xen_set_nslabs_63066 xen_set_nslabs 0 63066 NULL
114200 +iwl_dbgfs_fw_rx_stats_read_63070 iwl_dbgfs_fw_rx_stats_read 3 63070 NULL
114201 +sep_prepare_input_output_dma_table_in_dcb_63087 sep_prepare_input_output_dma_table_in_dcb 4-5 63087 NULL
114202 +iwl_dbgfs_sensitivity_read_63116 iwl_dbgfs_sensitivity_read 3 63116 NULL
114203 +ext4_chunk_trans_blocks_63123 ext4_chunk_trans_blocks 0-2 63123 NULL
114204 +smk_write_revoke_subj_63173 smk_write_revoke_subj 3 63173 NULL
114205 +SyS_syslog_63178 SyS_syslog 3 63178 NULL
114206 +vme_master_read_63221 vme_master_read 0 63221 NULL
114207 +SyS_gethostname_63227 SyS_gethostname 2 63227 NULL
114208 +ptp_read_63251 ptp_read 4 63251 NULL
114209 +xfs_dir2_leaf_getdents_63262 xfs_dir2_leaf_getdents 3 63262 NULL
114210 +raid5_resize_63306 raid5_resize 2 63306 NULL
114211 +proc_info_read_63344 proc_info_read 3 63344 NULL
114212 +ps_upsd_max_sptime_read_63362 ps_upsd_max_sptime_read 3 63362 NULL
114213 +idmouse_read_63374 idmouse_read 3 63374 NULL
114214 +usbnet_read_cmd_nopm_63388 usbnet_read_cmd_nopm 7 63388 NULL nohasharray
114215 +edac_pci_alloc_ctl_info_63388 edac_pci_alloc_ctl_info 1 63388 &usbnet_read_cmd_nopm_63388
114216 +rxpipe_missed_beacon_host_int_trig_rx_data_read_63405 rxpipe_missed_beacon_host_int_trig_rx_data_read 3 63405 NULL
114217 +nouveau_event_create_63411 nouveau_event_create 1 63411 NULL
114218 +l2cap_sock_sendmsg_63427 l2cap_sock_sendmsg 4 63427 NULL
114219 +nfsd_symlink_63442 nfsd_symlink 6 63442 NULL
114220 +si5351_bulk_write_63468 si5351_bulk_write 2-3 63468 NULL
114221 +snd_info_entry_write_63474 snd_info_entry_write 3 63474 NULL
114222 +reada_find_extent_63486 reada_find_extent 2 63486 NULL
114223 +read_kcore_63488 read_kcore 3 63488 NULL
114224 +snd_pcm_plug_write_transfer_63503 snd_pcm_plug_write_transfer 0-3 63503 NULL
114225 +efx_mcdi_rpc_async_63529 efx_mcdi_rpc_async 4-5 63529 NULL
114226 +ubi_more_leb_change_data_63534 ubi_more_leb_change_data 4 63534 NULL
114227 +write_file_spectral_period_63536 write_file_spectral_period 3 63536 NULL
114228 +if_sdio_read_scratch_63540 if_sdio_read_scratch 0 63540 NULL
114229 +append_to_buffer_63550 append_to_buffer 3 63550 NULL
114230 +kvm_write_guest_page_63555 kvm_write_guest_page 5 63555 NULL
114231 +rproc_alloc_63577 rproc_alloc 5 63577 NULL
114232 +write_debug_level_63613 write_debug_level 3 63613 NULL
114233 +symbol_build_supp_rates_63634 symbol_build_supp_rates 0 63634 NULL
114234 +proc_loginuid_write_63648 proc_loginuid_write 3 63648 NULL
114235 +ValidateDSDParamsChecksum_63654 ValidateDSDParamsChecksum 3 63654 NULL
114236 +ldlm_cli_enqueue_63657 ldlm_cli_enqueue 8 63657 NULL
114237 +hidraw_ioctl_63658 hidraw_ioctl 2 63658 NULL
114238 +vbi_read_63673 vbi_read 3 63673 NULL
114239 +write_file_spectral_fft_period_63696 write_file_spectral_fft_period 3 63696 NULL
114240 +nouveau_object_create__63715 nouveau_object_create_ 5 63715 NULL
114241 +btrfs_insert_delayed_dir_index_63720 btrfs_insert_delayed_dir_index 4 63720 NULL
114242 +selinux_secctx_to_secid_63744 selinux_secctx_to_secid 2 63744 NULL
114243 +snd_pcm_oss_read1_63771 snd_pcm_oss_read1 3 63771 NULL
114244 +snd_opl4_mem_proc_read_63774 snd_opl4_mem_proc_read 5 63774 NULL
114245 +spidev_compat_ioctl_63778 spidev_compat_ioctl 2 63778 NULL
114246 +mwifiex_11n_create_rx_reorder_tbl_63806 mwifiex_11n_create_rx_reorder_tbl 4 63806 NULL
114247 +copy_nodes_to_user_63807 copy_nodes_to_user 2 63807 NULL
114248 +prepare_copy_63826 prepare_copy 2 63826 NULL
114249 +sel_write_load_63830 sel_write_load 3 63830 NULL
114250 +ll_readlink_63836 ll_readlink 3 63836 NULL
114251 +proc_pid_attr_write_63845 proc_pid_attr_write 3 63845 NULL
114252 +xhci_alloc_stream_info_63902 xhci_alloc_stream_info 3 63902 NULL
114253 +uvc_alloc_urb_buffers_63922 uvc_alloc_urb_buffers 0-2-3 63922 NULL
114254 +snd_compr_write_63923 snd_compr_write 3 63923 NULL
114255 +afs_send_simple_reply_63940 afs_send_simple_reply 3 63940 NULL
114256 +__team_options_register_63941 __team_options_register 3 63941 NULL
114257 +macvtap_recvmsg_63949 macvtap_recvmsg 4 63949 NULL
114258 +sysfs_add_one_63969 sysfs_add_one 0 63969 NULL
114259 +set_bredr_63975 set_bredr 4 63975 NULL
114260 +construct_key_and_link_63985 construct_key_and_link 3 63985 NULL
114261 +rs_extent_to_bm_page_63996 rs_extent_to_bm_page 0-1 63996 NULL
114262 +read_file_frameerrors_64001 read_file_frameerrors 3 64001 NULL
114263 +hfsplus_security_setxattr_64009 hfsplus_security_setxattr 4 64009 NULL
114264 +SyS_rt_sigpending_64018 SyS_rt_sigpending 2 64018 NULL
114265 +dbAllocDmapLev_64030 dbAllocDmapLev 0 64030 NULL
114266 +SyS_fsetxattr_64039 SyS_fsetxattr 4 64039 NULL
114267 +get_u8_64076 get_u8 0 64076 NULL
114268 +xilly_malloc_64077 xilly_malloc 2 64077 NULL
114269 +sl_realloc_bufs_64086 sl_realloc_bufs 2 64086 NULL
114270 +vmci_handle_arr_get_size_64088 vmci_handle_arr_get_size 0 64088 NULL
114271 +lbs_highrssi_read_64089 lbs_highrssi_read 3 64089 NULL
114272 +SyS_set_mempolicy_64096 SyS_set_mempolicy 3 64096 NULL
114273 +SyS_mq_timedsend_64107 SyS_mq_timedsend 3 64107 NULL
114274 +rdma_addr_size_64116 rdma_addr_size 0 64116 NULL
114275 +do_load_xattr_datum_64118 do_load_xattr_datum 0 64118 NULL
114276 +bypass_wd_write_64120 bypass_wd_write 3 64120 NULL
114277 +ext4_prepare_inline_data_64124 ext4_prepare_inline_data 3 64124 NULL
114278 +init_bch_64130 init_bch 1-2 64130 NULL
114279 +ablkcipher_copy_iv_64140 ablkcipher_copy_iv 3 64140 NULL
114280 +read_div_64147 read_div 0 64147 NULL
114281 +dlfb_ops_write_64150 dlfb_ops_write 3 64150 NULL
114282 +cpumask_scnprintf_64170 cpumask_scnprintf 0-2 64170 NULL
114283 +xfs_vm_direct_IO_64223 xfs_vm_direct_IO 4 64223 NULL
114284 +read_pulse_64227 read_pulse 0-3 64227 NULL
114285 +ea_len_64229 ea_len 0 64229 NULL
114286 +io_capture_transfer_64276 io_capture_transfer 4 64276 NULL
114287 +btrfs_file_extent_offset_64278 btrfs_file_extent_offset 0 64278 NULL
114288 +sta_current_tx_rate_read_64286 sta_current_tx_rate_read 3 64286 NULL
114289 +xfs_dir_cilookup_result_64288 xfs_dir_cilookup_result 3 64288 NULL nohasharray
114290 +event_id_read_64288 event_id_read 3 64288 &xfs_dir_cilookup_result_64288
114291 +ocfs2_block_check_validate_bhs_64302 ocfs2_block_check_validate_bhs 0 64302 NULL
114292 +snd_hda_get_sub_nodes_64304 snd_hda_get_sub_nodes 0 64304 NULL
114293 +error_error_bar_retry_read_64305 error_error_bar_retry_read 3 64305 NULL
114294 +sisusbcon_clear_64329 sisusbcon_clear 4-3-5 64329 NULL
114295 +ts_write_64336 ts_write 3 64336 NULL
114296 +usbtmc_write_64340 usbtmc_write 3 64340 NULL
114297 +bnx2x_vfop_mcast_cmd_64354 bnx2x_vfop_mcast_cmd 5 64354 NULL
114298 +user_regset_copyin_64360 user_regset_copyin 7 64360 NULL
114299 +wlc_phy_loadsampletable_nphy_64367 wlc_phy_loadsampletable_nphy 3 64367 NULL
114300 +reg_create_64372 reg_create 5 64372 NULL
114301 +ilo_write_64378 ilo_write 3 64378 NULL
114302 +btrfs_map_block_64379 btrfs_map_block 3 64379 NULL
114303 +vmcs_readl_64381 vmcs_readl 0 64381 NULL
114304 +nilfs_alloc_seg_bio_64383 nilfs_alloc_seg_bio 3 64383 NULL
114305 +ir_lirc_transmit_ir_64403 ir_lirc_transmit_ir 3 64403 NULL
114306 +pidlist_allocate_64404 pidlist_allocate 1 64404 NULL
114307 +rx_hdr_overflow_read_64407 rx_hdr_overflow_read 3 64407 NULL
114308 +snd_card_create_64418 snd_card_create 4 64418 NULL nohasharray
114309 +keyctl_get_security_64418 keyctl_get_security 3 64418 &snd_card_create_64418
114310 +oom_adj_write_64428 oom_adj_write 3 64428 NULL
114311 +read_file_spectral_short_repeat_64431 read_file_spectral_short_repeat 3 64431 NULL
114312 +ax25_recvmsg_64441 ax25_recvmsg 4 64441 NULL
114313 +single_open_size_64483 single_open_size 4 64483 NULL
114314 +p54_parse_rssical_64493 p54_parse_rssical 3 64493 NULL
114315 +msg_data_sz_64503 msg_data_sz 0 64503 NULL
114316 +remove_uuid_64505 remove_uuid 4 64505 NULL
114317 +crypto_blkcipher_alignmask_64520 crypto_blkcipher_alignmask 0 64520 NULL
114318 +opera1_usb_i2c_msgxfer_64521 opera1_usb_i2c_msgxfer 4 64521 NULL
114319 +iwl_dbgfs_ucode_tracing_write_64524 iwl_dbgfs_ucode_tracing_write 3 64524 NULL
114320 +ses_send_diag_64527 ses_send_diag 4 64527 NULL
114321 +prctl_set_mm_64538 prctl_set_mm 3 64538 NULL
114322 +SyS_bind_64544 SyS_bind 3 64544 NULL
114323 +rbd_obj_read_sync_64554 rbd_obj_read_sync 4-3 64554 NULL
114324 +__btrfs_prealloc_file_range_64557 __btrfs_prealloc_file_range 3 64557 NULL
114325 +__spi_sync_64561 __spi_sync 0 64561 NULL nohasharray
114326 +ll_max_rw_chunk_seq_write_64561 ll_max_rw_chunk_seq_write 3 64561 &__spi_sync_64561
114327 +__apei_exec_run_64563 __apei_exec_run 0 64563 NULL
114328 +kstrtoul_from_user_64569 kstrtoul_from_user 2 64569 NULL
114329 +do_erase_64574 do_erase 4 64574 NULL
114330 +fanotify_write_64623 fanotify_write 3 64623 NULL
114331 +regmap_read_debugfs_64658 regmap_read_debugfs 5 64658 NULL
114332 +ocfs2_read_xattr_block_64661 ocfs2_read_xattr_block 0 64661 NULL nohasharray
114333 +tlbflush_read_file_64661 tlbflush_read_file 3 64661 &ocfs2_read_xattr_block_64661
114334 +efx_tsoh_get_buffer_64664 efx_tsoh_get_buffer 3 64664 NULL
114335 +rx_rx_out_of_mpdu_nodes_read_64668 rx_rx_out_of_mpdu_nodes_read 3 64668 NULL
114336 +nr_free_zone_pages_64680 nr_free_zone_pages 0 64680 NULL
114337 +sec_bulk_write_64691 sec_bulk_write 2-3 64691 NULL
114338 +snd_pcm_oss_capture_position_fixup_64713 snd_pcm_oss_capture_position_fixup 0 64713 NULL
114339 +dapm_bias_read_file_64715 dapm_bias_read_file 3 64715 NULL
114340 +atomic_add_return_64720 atomic_add_return 0-1 64720 NULL
114341 +i2400m_msg_to_dev_64722 i2400m_msg_to_dev 3 64722 NULL
114342 +AscGetChipVersion_64737 AscGetChipVersion 0 64737 NULL
114343 +squashfs_read_inode_lookup_table_64739 squashfs_read_inode_lookup_table 4 64739 NULL
114344 +bio_map_kern_64751 bio_map_kern 3 64751 NULL
114345 +rt2x00debug_write_csr_64753 rt2x00debug_write_csr 3 64753 NULL
114346 +message_for_md_64777 message_for_md 5 64777 NULL
114347 +isr_low_rssi_read_64789 isr_low_rssi_read 3 64789 NULL
114348 +regmap_reg_ranges_read_file_64798 regmap_reg_ranges_read_file 3 64798 NULL
114349 +nfsctl_transaction_write_64800 nfsctl_transaction_write 3 64800 NULL
114350 +rfkill_fop_write_64808 rfkill_fop_write 3 64808 NULL
114351 +proc_projid_map_write_64810 proc_projid_map_write 3 64810 NULL
114352 +megaraid_change_queue_depth_64815 megaraid_change_queue_depth 2 64815 NULL
114353 +ecryptfs_send_miscdev_64816 ecryptfs_send_miscdev 2 64816 NULL
114354 +do_kimage_alloc_64827 do_kimage_alloc 3 64827 NULL
114355 +altera_set_dr_pre_64862 altera_set_dr_pre 2 64862 NULL
114356 +lprocfs_write_u64_helper_64880 lprocfs_write_u64_helper 2 64880 NULL
114357 +ffs_epfile_io_64886 ffs_epfile_io 3 64886 NULL
114358 +ieee80211_if_read_ave_beacon_64924 ieee80211_if_read_ave_beacon 3 64924 NULL
114359 +ip_options_get_from_user_64958 ip_options_get_from_user 4 64958 NULL
114360 +traceprobe_probes_write_64969 traceprobe_probes_write 3 64969 NULL
114361 +suspend_dtim_interval_read_64971 suspend_dtim_interval_read 3 64971 NULL
114362 +crypto_ahash_digestsize_65014 crypto_ahash_digestsize 0 65014 NULL
114363 +insert_dent_65034 insert_dent 7 65034 NULL
114364 +snd_hda_get_pin_label_65035 snd_hda_get_pin_label 5 65035 NULL
114365 +ext4_ind_trans_blocks_65053 ext4_ind_trans_blocks 0-2 65053 NULL
114366 +pcibios_enable_device_65059 pcibios_enable_device 0 65059 NULL
114367 +__alloc_bootmem_node_high_65076 __alloc_bootmem_node_high 2 65076 NULL
114368 +batadv_socket_write_65083 batadv_socket_write 3 65083 NULL
114369 +ocfs2_truncate_cluster_pages_65086 ocfs2_truncate_cluster_pages 2 65086 NULL
114370 +ath9k_dump_mci_btcoex_65090 ath9k_dump_mci_btcoex 3-0 65090 NULL
114371 +uasp_alloc_cmd_65097 uasp_alloc_cmd 0 65097 NULL
114372 +generic_ocp_write_65107 generic_ocp_write 4 65107 NULL
114373 +rx_rx_done_read_65217 rx_rx_done_read 3 65217 NULL
114374 +print_endpoint_stat_65232 print_endpoint_stat 3-4-0 65232 NULL
114375 +whci_n_caps_65247 whci_n_caps 0 65247 NULL
114376 +kmalloc_parameter_65279 kmalloc_parameter 1 65279 NULL
114377 +compat_core_sys_select_65285 compat_core_sys_select 1 65285 NULL
114378 +mpi_set_buffer_65294 mpi_set_buffer 3 65294 NULL
114379 +redirected_tty_write_65297 redirected_tty_write 3 65297 NULL
114380 +get_var_len_65304 get_var_len 0 65304 NULL
114381 +unpack_array_65318 unpack_array 0 65318 NULL
114382 +pci_vpd_find_tag_65325 pci_vpd_find_tag 0-2 65325 NULL
114383 +dccp_setsockopt_service_65336 dccp_setsockopt_service 4 65336 NULL
114384 +dma_rx_requested_read_65354 dma_rx_requested_read 3 65354 NULL
114385 +alloc_cpu_rmap_65363 alloc_cpu_rmap 1 65363 NULL
114386 +SyS_writev_65372 SyS_writev 3 65372 NULL
114387 +__alloc_bootmem_nopanic_65397 __alloc_bootmem_nopanic 1 65397 NULL
114388 +trace_seq_to_user_65398 trace_seq_to_user 3 65398 NULL
114389 +__read_vmcore_65402 __read_vmcore 2 65402 NULL
114390 +usb_ep_enable_65405 usb_ep_enable 0 65405 NULL
114391 +ocfs2_write_begin_nolock_65410 ocfs2_write_begin_nolock 3-4 65410 NULL
114392 +device_add_groups_65423 device_add_groups 0 65423 NULL
114393 +xpc_kzalloc_cacheline_aligned_65433 xpc_kzalloc_cacheline_aligned 1 65433 NULL
114394 +usb_alloc_coherent_65444 usb_alloc_coherent 2 65444 NULL
114395 +il_dbgfs_wd_timeout_write_65464 il_dbgfs_wd_timeout_write 3 65464 NULL
114396 +clear_user_65470 clear_user 2 65470 NULL
114397 +dpcm_state_read_file_65489 dpcm_state_read_file 3 65489 NULL
114398 +lookup_inline_extent_backref_65493 lookup_inline_extent_backref 9 65493 NULL
114399 +nvme_trans_standard_inquiry_page_65526 nvme_trans_standard_inquiry_page 4 65526 NULL
114400 +tree_mod_log_eb_copy_65535 tree_mod_log_eb_copy 6 65535 NULL
114401 diff --git a/tools/gcc/size_overflow_hash_aux.data b/tools/gcc/size_overflow_hash_aux.data
114402 new file mode 100644
114403 index 0000000..560cd7b
114404 --- /dev/null
114405 +++ b/tools/gcc/size_overflow_hash_aux.data
114406 @@ -0,0 +1,92 @@
114407 +spa_set_aux_vdevs_746 spa_set_aux_vdevs 3 746 NULL
114408 +zfs_lookup_2144 zfs_lookup 0 2144 NULL
114409 +mappedread_2627 mappedread 2 2627 NULL
114410 +vdev_disk_dio_alloc_2957 vdev_disk_dio_alloc 1 2957 NULL
114411 +nv_alloc_pushpage_spl_4286 nv_alloc_pushpage_spl 2 4286 NULL
114412 +zpl_xattr_get_4574 zpl_xattr_get 0 4574 NULL
114413 +sa_replace_all_by_template_5699 sa_replace_all_by_template 3 5699 NULL
114414 +dmu_write_6048 dmu_write 4-3 6048 NULL
114415 +dmu_buf_hold_array_6095 dmu_buf_hold_array 4-3 6095 NULL
114416 +update_pages_6225 update_pages 2-3 6225 NULL
114417 +bio_nr_pages_7117 bio_nr_pages 0-2 7117 NULL
114418 +dmu_buf_hold_array_by_bonus_8562 dmu_buf_hold_array_by_bonus 3-2 8562 NULL
114419 +zpios_dmu_write_8858 zpios_dmu_write 4-5 8858 NULL
114420 +ddi_copyout_9401 ddi_copyout 3 9401 NULL
114421 +avl_numnodes_12384 avl_numnodes 0 12384 NULL
114422 +dmu_write_uio_dnode_12473 dmu_write_uio_dnode 3 12473 NULL
114423 +dmu_xuio_init_12866 dmu_xuio_init 2 12866 NULL
114424 +zpl_read_common_14389 zpl_read_common 0 14389 NULL
114425 +dmu_snapshot_realname_14632 dmu_snapshot_realname 4 14632 NULL
114426 +kmem_alloc_debug_14852 kmem_alloc_debug 1 14852 NULL
114427 +kmalloc_node_nofail_15151 kmalloc_node_nofail 1 15151 NULL
114428 +dmu_write_uio_16351 dmu_write_uio 4 16351 NULL
114429 +zfs_log_write_16524 zfs_log_write 6-5 16524 NULL
114430 +sa_build_layouts_16910 sa_build_layouts 3 16910 NULL
114431 +dsl_dir_namelen_17053 dsl_dir_namelen 0 17053 NULL
114432 +kcopy_copy_to_user_17336 kcopy_copy_to_user 5 17336 NULL
114433 +sa_add_layout_entry_17507 sa_add_layout_entry 3 17507 NULL
114434 +sa_attr_table_setup_18029 sa_attr_table_setup 3 18029 NULL
114435 +uiocopy_18680 uiocopy 2 18680 NULL
114436 +dmu_buf_hold_array_by_dnode_19125 dmu_buf_hold_array_by_dnode 2-3 19125 NULL
114437 +zpl_acl_from_xattr_21141 zpl_acl_from_xattr 2 21141 NULL
114438 +dsl_pool_tx_assign_init_22518 dsl_pool_tx_assign_init 2 22518 NULL
114439 +nvlist_lookup_byte_array_22527 nvlist_lookup_byte_array 0 22527 NULL
114440 +sa_replace_all_by_template_locked_22533 sa_replace_all_by_template_locked 3 22533 NULL
114441 +tsd_hash_table_init_22559 tsd_hash_table_init 1 22559 NULL
114442 +spa_vdev_remove_aux_23966 spa_vdev_remove_aux 4 23966 NULL
114443 +zpl_xattr_acl_set_access_24129 zpl_xattr_acl_set_access 4 24129 NULL
114444 +dmu_assign_arcbuf_24622 dmu_assign_arcbuf 2 24622 NULL
114445 +zap_lookup_norm_25166 zap_lookup_norm 9 25166 NULL
114446 +dmu_prealloc_25456 dmu_prealloc 4-3 25456 NULL
114447 +kmalloc_nofail_26347 kmalloc_nofail 1 26347 NULL
114448 +zfsctl_snapshot_zpath_27578 zfsctl_snapshot_zpath 2 27578 NULL
114449 +zpios_dmu_read_30015 zpios_dmu_read 4-5 30015 NULL
114450 +splat_write_30943 splat_write 3 30943 NULL
114451 +zpl_xattr_get_sa_31183 zpl_xattr_get_sa 0 31183 NULL
114452 +dmu_read_uio_31467 dmu_read_uio 4 31467 NULL
114453 +zfs_replay_fuids_31479 zfs_replay_fuids 4 31479 NULL
114454 +spa_history_log_to_phys_31632 spa_history_log_to_phys 0-1 31632 NULL
114455 +__zpl_xattr_get_32601 __zpl_xattr_get 0 32601 NULL
114456 +proc_copyout_string_34049 proc_copyout_string 2 34049 NULL
114457 +nv_alloc_sleep_spl_34544 nv_alloc_sleep_spl 2 34544 NULL
114458 +nv_alloc_nosleep_spl_34761 nv_alloc_nosleep_spl 2 34761 NULL
114459 +zap_leaf_array_match_36922 zap_leaf_array_match 4 36922 NULL
114460 +copyinstr_36980 copyinstr 3 36980 NULL
114461 +zpl_xattr_acl_set_default_37864 zpl_xattr_acl_set_default 4 37864 NULL
114462 +splat_read_38116 splat_read 3 38116 NULL
114463 +sa_setup_38756 sa_setup 4 38756 NULL
114464 +vdev_disk_physio_39898 vdev_disk_physio 3 39898 NULL
114465 +arc_buf_size_39982 arc_buf_size 0 39982 NULL
114466 +kzalloc_nofail_40719 kzalloc_nofail 1 40719 NULL
114467 +fuidstr_to_sid_40777 fuidstr_to_sid 4 40777 NULL
114468 +vdev_raidz_matrix_reconstruct_40852 vdev_raidz_matrix_reconstruct 2-3 40852 NULL
114469 +sa_find_layout_40892 sa_find_layout 4 40892 NULL
114470 +zpl_xattr_get_dir_41918 zpl_xattr_get_dir 0 41918 NULL
114471 +zfs_sa_get_xattr_42600 zfs_sa_get_xattr 0 42600 NULL
114472 +zpl_xattr_acl_set_42808 zpl_xattr_acl_set 4 42808 NULL
114473 +xdr_dec_array_43091 xdr_dec_array 5 43091 NULL
114474 +dsl_dataset_namelen_43136 dsl_dataset_namelen 0 43136 NULL
114475 +kcopy_write_43683 kcopy_write 3 43683 NULL
114476 +uiomove_44355 uiomove 2 44355 NULL
114477 +dmu_read_44418 dmu_read 4-3 44418 NULL
114478 +ddi_copyin_44846 ddi_copyin 3 44846 NULL
114479 +kcopy_do_get_45061 kcopy_do_get 5 45061 NULL
114480 +copyin_45945 copyin 3 45945 NULL
114481 +zil_itx_create_46555 zil_itx_create 2 46555 NULL
114482 +dmu_write_uio_dbuf_48064 dmu_write_uio_dbuf 3 48064 NULL
114483 +blk_rq_pos_48233 blk_rq_pos 0 48233 NULL
114484 +spa_history_write_49650 spa_history_write 3 49650 NULL
114485 +kcopy_copy_pages_to_user_49823 kcopy_copy_pages_to_user 3-4 49823 NULL
114486 +zfs_log_write_50162 zfs_log_write 6-5 50162 NULL
114487 +i_fm_alloc_51038 i_fm_alloc 2 51038 NULL
114488 +copyout_51409 copyout 3 51409 NULL
114489 +zvol_log_write_54898 zvol_log_write 4-3 54898 NULL
114490 +zfs_acl_node_alloc_55641 zfs_acl_node_alloc 1 55641 NULL
114491 +get_nvlist_56685 get_nvlist 2 56685 NULL
114492 +zprop_get_numprops_56820 zprop_get_numprops 0 56820 NULL
114493 +splat_taskq_test4_common_59829 splat_taskq_test4_common 5 59829 NULL
114494 +zfs_replay_domain_cnt_61399 zfs_replay_domain_cnt 0 61399 NULL
114495 +zpios_write_61823 zpios_write 3 61823 NULL
114496 +proc_copyin_string_62019 proc_copyin_string 4 62019 NULL
114497 +random_get_pseudo_bytes_64611 random_get_pseudo_bytes 2 64611 NULL
114498 +zpios_read_64734 zpios_read 3 64734 NULL
114499 diff --git a/tools/gcc/size_overflow_plugin.c b/tools/gcc/size_overflow_plugin.c
114500 new file mode 100644
114501 index 0000000..ed21b21
114502 --- /dev/null
114503 +++ b/tools/gcc/size_overflow_plugin.c
114504 @@ -0,0 +1,4166 @@
114505 +/*
114506 + * Copyright 2011-2014 by Emese Revfy <re.emese@gmail.com>
114507 + * Licensed under the GPL v2, or (at your option) v3
114508 + *
114509 + * Homepage:
114510 + * http://www.grsecurity.net/~ephox/overflow_plugin/
114511 + *
114512 + * Documentation:
114513 + * http://forums.grsecurity.net/viewtopic.php?f=7&t=3043
114514 + *
114515 + * This plugin recomputes expressions of function arguments marked by a size_overflow attribute
114516 + * with double integer precision (DImode/TImode for 32/64 bit integer types).
114517 + * The recomputed argument is checked against TYPE_MAX and an event is logged on overflow and the triggering process is killed.
114518 + *
114519 + * Usage:
114520 + * $ # for 4.5/4.6/C based 4.7
114521 + * $ 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
114522 + * $ # for C++ based 4.7/4.8+
114523 + * $ 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
114524 + *
114525 + * $ gcc -fplugin=./size_overflow_plugin.so test.c -O2
114526 + */
114527 +
114528 +#include "gcc-common.h"
114529 +
114530 +int plugin_is_GPL_compatible;
114531 +
114532 +static struct plugin_info size_overflow_plugin_info = {
114533 + .version = "20140407",
114534 + .help = "no-size-overflow\tturn off size overflow checking\n",
114535 +};
114536 +
114537 +#define BEFORE_STMT true
114538 +#define AFTER_STMT false
114539 +#define CREATE_NEW_VAR NULL_TREE
114540 +#define CODES_LIMIT 32
114541 +#define MAX_PARAM 31
114542 +#define VEC_LEN 128
114543 +#define RET_CHECK NULL_TREE
114544 +#define CANNOT_FIND_ARG 32
114545 +#define WRONG_NODE 32
114546 +#define NOT_INTENTIONAL_ASM NULL
114547 +#define MIN_CHECK true
114548 +#define MAX_CHECK false
114549 +
114550 +#define TURN_OFF_ASM_STR "# size_overflow MARK_TURN_OFF "
114551 +#define YES_ASM_STR "# size_overflow MARK_YES "
114552 +#define OK_ASM_STR "# size_overflow "
114553 +
114554 +struct size_overflow_hash {
114555 + const struct size_overflow_hash * const next;
114556 + const char * const name;
114557 + const unsigned int param;
114558 +};
114559 +
114560 +#include "size_overflow_hash.h"
114561 +#include "size_overflow_hash_aux.h"
114562 +
114563 +enum mark {
114564 + MARK_NO, MARK_YES, MARK_NOT_INTENTIONAL, MARK_TURN_OFF
114565 +};
114566 +
114567 +static unsigned int call_count;
114568 +
114569 +enum stmt_flags {
114570 + MY_STMT, NO_CAST_CHECK, VISITED_STMT, NO_FLAGS
114571 +};
114572 +
114573 +struct visited {
114574 + struct visited *next;
114575 + const_tree fndecl;
114576 + unsigned int num;
114577 +};
114578 +
114579 +struct next_cgraph_node {
114580 + struct next_cgraph_node *next;
114581 + struct cgraph_node *current_function;
114582 + tree callee_fndecl;
114583 + unsigned int num;
114584 +};
114585 +
114586 +struct interesting_node {
114587 + struct interesting_node *next;
114588 + gimple first_stmt;
114589 + const_tree fndecl;
114590 + tree node;
114591 +#if BUILDING_GCC_VERSION <= 4007
114592 + VEC(tree, gc) *last_nodes;
114593 +#else
114594 + vec<tree, va_gc> *last_nodes;
114595 +#endif
114596 + unsigned int num;
114597 + enum mark intentional_attr_decl;
114598 + enum mark intentional_attr_cur_fndecl;
114599 + gimple intentional_mark_from_gimple;
114600 +};
114601 +
114602 +static tree report_size_overflow_decl;
114603 +
114604 +static tree expand(struct pointer_set_t *visited, struct cgraph_node *caller_node, tree lhs);
114605 +static void set_conditions(struct pointer_set_t *visited, bool *interesting_conditions, const_tree lhs);
114606 +static void walk_use_def(struct pointer_set_t *visited, struct interesting_node *cur_node, tree lhs);
114607 +static enum mark search_intentional(struct pointer_set_t *visited, const_tree lhs);
114608 +static void search_size_overflow_attribute(struct pointer_set_t *visited, tree lhs);
114609 +
114610 +static void check_size_overflow(struct cgraph_node *caller_node, gimple stmt, tree size_overflow_type, tree cast_rhs, tree rhs, bool before);
114611 +static tree get_size_overflow_type(gimple stmt, const_tree node);
114612 +static tree dup_assign(struct pointer_set_t *visited, gimple oldstmt, const_tree node, tree rhs1, tree rhs2, tree __unused rhs3);
114613 +
114614 +static tree handle_size_overflow_attribute(tree *node, tree __unused name, tree args, int __unused flags, bool *no_add_attrs)
114615 +{
114616 + unsigned int arg_count;
114617 + enum tree_code code = TREE_CODE(*node);
114618 +
114619 + switch (code) {
114620 + case FUNCTION_DECL:
114621 + arg_count = type_num_arguments(TREE_TYPE(*node));
114622 + break;
114623 + case FUNCTION_TYPE:
114624 + case METHOD_TYPE:
114625 + arg_count = type_num_arguments(*node);
114626 + break;
114627 + default:
114628 + *no_add_attrs = true;
114629 + error("%s: %qE attribute only applies to functions", __func__, name);
114630 + return NULL_TREE;
114631 + }
114632 +
114633 + for (; args; args = TREE_CHAIN(args)) {
114634 + tree position = TREE_VALUE(args);
114635 + if (TREE_CODE(position) != INTEGER_CST || TREE_INT_CST_LOW(position) > arg_count ) {
114636 + error("%s: parameter %u is outside range.", __func__, (unsigned int)TREE_INT_CST_LOW(position));
114637 + *no_add_attrs = true;
114638 + }
114639 + }
114640 + return NULL_TREE;
114641 +}
114642 +
114643 +static tree handle_intentional_overflow_attribute(tree *node, tree __unused name, tree args, int __unused flags, bool *no_add_attrs)
114644 +{
114645 + unsigned int arg_count;
114646 + enum tree_code code = TREE_CODE(*node);
114647 +
114648 + switch (code) {
114649 + case FUNCTION_DECL:
114650 + arg_count = type_num_arguments(TREE_TYPE(*node));
114651 + break;
114652 + case FUNCTION_TYPE:
114653 + case METHOD_TYPE:
114654 + arg_count = type_num_arguments(*node);
114655 + break;
114656 + case FIELD_DECL:
114657 + return NULL_TREE;
114658 + default:
114659 + *no_add_attrs = true;
114660 + error("%qE attribute only applies to functions", name);
114661 + return NULL_TREE;
114662 + }
114663 +
114664 + if (TREE_INT_CST_HIGH(TREE_VALUE(args)) != 0)
114665 + return NULL_TREE;
114666 +
114667 + for (; args; args = TREE_CHAIN(args)) {
114668 + tree position = TREE_VALUE(args);
114669 + if (TREE_CODE(position) != INTEGER_CST || TREE_INT_CST_LOW(position) > arg_count ) {
114670 + error("%s: parameter %u is outside range.", __func__, (unsigned int)TREE_INT_CST_LOW(position));
114671 + *no_add_attrs = true;
114672 + }
114673 + }
114674 + return NULL_TREE;
114675 +}
114676 +
114677 +static struct attribute_spec size_overflow_attr = {
114678 + .name = "size_overflow",
114679 + .min_length = 1,
114680 + .max_length = -1,
114681 + .decl_required = true,
114682 + .type_required = false,
114683 + .function_type_required = false,
114684 + .handler = handle_size_overflow_attribute,
114685 +#if BUILDING_GCC_VERSION >= 4007
114686 + .affects_type_identity = false
114687 +#endif
114688 +};
114689 +
114690 +static struct attribute_spec intentional_overflow_attr = {
114691 + .name = "intentional_overflow",
114692 + .min_length = 1,
114693 + .max_length = -1,
114694 + .decl_required = true,
114695 + .type_required = false,
114696 + .function_type_required = false,
114697 + .handler = handle_intentional_overflow_attribute,
114698 +#if BUILDING_GCC_VERSION >= 4007
114699 + .affects_type_identity = false
114700 +#endif
114701 +};
114702 +
114703 +static void register_attributes(void __unused *event_data, void __unused *data)
114704 +{
114705 + register_attribute(&size_overflow_attr);
114706 + register_attribute(&intentional_overflow_attr);
114707 +}
114708 +
114709 +static enum stmt_flags get_stmt_flag(gimple stmt)
114710 +{
114711 + bool bit_1, bit_2;
114712 +
114713 + bit_1 = gimple_plf(stmt, GF_PLF_1);
114714 + bit_2 = gimple_plf(stmt, GF_PLF_2);
114715 +
114716 + if (!bit_1 && !bit_2)
114717 + return NO_FLAGS;
114718 + if (bit_1 && bit_2)
114719 + return MY_STMT;
114720 + if (!bit_1 && bit_2)
114721 + return VISITED_STMT;
114722 + return NO_CAST_CHECK;
114723 +}
114724 +
114725 +static void set_stmt_flag(gimple stmt, enum stmt_flags new_flag)
114726 +{
114727 + bool bit_1, bit_2;
114728 +
114729 + switch (new_flag) {
114730 + case NO_FLAGS:
114731 + bit_1 = bit_2 = false;
114732 + break;
114733 + case MY_STMT:
114734 + bit_1 = bit_2 = true;
114735 + break;
114736 + case VISITED_STMT:
114737 + bit_1 = false;
114738 + bit_2 = true;
114739 + break;
114740 + case NO_CAST_CHECK:
114741 + bit_1 = true;
114742 + bit_2 = false;
114743 + break;
114744 + default:
114745 + gcc_unreachable();
114746 + }
114747 +
114748 + gimple_set_plf(stmt, GF_PLF_1, bit_1);
114749 + gimple_set_plf(stmt, GF_PLF_2, bit_2);
114750 +}
114751 +
114752 +static bool is_bool(const_tree node)
114753 +{
114754 + const_tree type;
114755 +
114756 + if (node == NULL_TREE)
114757 + return false;
114758 +
114759 + type = TREE_TYPE(node);
114760 + if (!INTEGRAL_TYPE_P(type))
114761 + return false;
114762 + if (TREE_CODE(type) == BOOLEAN_TYPE)
114763 + return true;
114764 + if (TYPE_PRECISION(type) == 1)
114765 + return true;
114766 + return false;
114767 +}
114768 +
114769 +static bool skip_types(const_tree var)
114770 +{
114771 + tree type;
114772 + enum tree_code code;
114773 +
114774 + if (is_gimple_constant(var))
114775 + return true;
114776 +
114777 + switch (TREE_CODE(var)) {
114778 + case ADDR_EXPR:
114779 +#if BUILDING_GCC_VERSION >= 4006
114780 + case MEM_REF:
114781 +#endif
114782 + case ARRAY_REF:
114783 + case BIT_FIELD_REF:
114784 + case INDIRECT_REF:
114785 + case TARGET_MEM_REF:
114786 + case COMPONENT_REF:
114787 + case VAR_DECL:
114788 + case VIEW_CONVERT_EXPR:
114789 + return true;
114790 + default:
114791 + break;
114792 + }
114793 +
114794 + code = TREE_CODE(var);
114795 + gcc_assert(code == SSA_NAME || code == PARM_DECL);
114796 +
114797 + type = TREE_TYPE(var);
114798 + switch (TREE_CODE(type)) {
114799 + case INTEGER_TYPE:
114800 + case ENUMERAL_TYPE:
114801 + return false;
114802 + case BOOLEAN_TYPE:
114803 + return is_bool(var);
114804 + default:
114805 + return true;
114806 + }
114807 +}
114808 +
114809 +static inline gimple get_def_stmt(const_tree node)
114810 +{
114811 + gcc_assert(node != NULL_TREE);
114812 +
114813 + if (skip_types(node))
114814 + return NULL;
114815 +
114816 + if (TREE_CODE(node) != SSA_NAME)
114817 + return NULL;
114818 + return SSA_NAME_DEF_STMT(node);
114819 +}
114820 +
114821 +static unsigned char get_tree_code(const_tree type)
114822 +{
114823 + switch (TREE_CODE(type)) {
114824 + case ARRAY_TYPE:
114825 + return 0;
114826 + case BOOLEAN_TYPE:
114827 + return 1;
114828 + case ENUMERAL_TYPE:
114829 + return 2;
114830 + case FUNCTION_TYPE:
114831 + return 3;
114832 + case INTEGER_TYPE:
114833 + return 4;
114834 + case POINTER_TYPE:
114835 + return 5;
114836 + case RECORD_TYPE:
114837 + return 6;
114838 + case UNION_TYPE:
114839 + return 7;
114840 + case VOID_TYPE:
114841 + return 8;
114842 + case REAL_TYPE:
114843 + return 9;
114844 + case VECTOR_TYPE:
114845 + return 10;
114846 + case REFERENCE_TYPE:
114847 + return 11;
114848 + case OFFSET_TYPE:
114849 + return 12;
114850 + case COMPLEX_TYPE:
114851 + return 13;
114852 + default:
114853 + debug_tree((tree)type);
114854 + gcc_unreachable();
114855 + }
114856 +}
114857 +
114858 +struct function_hash {
114859 + size_t tree_codes_len;
114860 + unsigned char tree_codes[CODES_LIMIT];
114861 + const_tree fndecl;
114862 + unsigned int hash;
114863 +};
114864 +
114865 +// http://www.team5150.com/~andrew/noncryptohashzoo2~/CrapWow.html
114866 +static unsigned int CrapWow(const char *key, unsigned int len, unsigned int seed)
114867 +{
114868 +#define cwfold( a, b, lo, hi ) { p = (unsigned int)(a) * (unsigned long long)(b); lo ^= (unsigned int)p; hi ^= (unsigned int)(p >> 32); }
114869 +#define cwmixa( in ) { cwfold( in, m, k, h ); }
114870 +#define cwmixb( in ) { cwfold( in, n, h, k ); }
114871 +
114872 + unsigned int m = 0x57559429;
114873 + unsigned int n = 0x5052acdb;
114874 + const unsigned int *key4 = (const unsigned int *)key;
114875 + unsigned int h = len;
114876 + unsigned int k = len + seed + n;
114877 + unsigned long long p;
114878 +
114879 + while (len >= 8) {
114880 + cwmixb(key4[0]) cwmixa(key4[1]) key4 += 2;
114881 + len -= 8;
114882 + }
114883 + if (len >= 4) {
114884 + cwmixb(key4[0]) key4 += 1;
114885 + len -= 4;
114886 + }
114887 + if (len)
114888 + cwmixa(key4[0] & ((1 << (len * 8)) - 1 ));
114889 + cwmixb(h ^ (k + n));
114890 + return k ^ h;
114891 +
114892 +#undef cwfold
114893 +#undef cwmixa
114894 +#undef cwmixb
114895 +}
114896 +
114897 +static void set_hash(const char *fn_name, struct function_hash *fn_hash_data)
114898 +{
114899 + unsigned int fn, codes, seed = 0;
114900 +
114901 + fn = CrapWow(fn_name, strlen(fn_name), seed) & 0xffff;
114902 + codes = CrapWow((const char*)fn_hash_data->tree_codes, fn_hash_data->tree_codes_len, seed) & 0xffff;
114903 +
114904 + fn_hash_data->hash = fn ^ codes;
114905 +}
114906 +
114907 +static void set_node_codes(const_tree type, struct function_hash *fn_hash_data)
114908 +{
114909 + gcc_assert(type != NULL_TREE);
114910 + gcc_assert(TREE_CODE_CLASS(TREE_CODE(type)) == tcc_type);
114911 +
114912 + while (type && fn_hash_data->tree_codes_len < CODES_LIMIT) {
114913 + fn_hash_data->tree_codes[fn_hash_data->tree_codes_len] = get_tree_code(type);
114914 + fn_hash_data->tree_codes_len++;
114915 + type = TREE_TYPE(type);
114916 + }
114917 +}
114918 +
114919 +static void set_result_codes(const_tree node, struct function_hash *fn_hash_data)
114920 +{
114921 + const_tree result;
114922 +
114923 + gcc_assert(node != NULL_TREE);
114924 +
114925 + if (DECL_P(node)) {
114926 + result = DECL_RESULT(node);
114927 + if (result != NULL_TREE)
114928 + return set_node_codes(TREE_TYPE(result), fn_hash_data);
114929 + return set_result_codes(TREE_TYPE(node), fn_hash_data);
114930 + }
114931 +
114932 + gcc_assert(TYPE_P(node));
114933 +
114934 + if (TREE_CODE(node) == FUNCTION_TYPE)
114935 + return set_result_codes(TREE_TYPE(node), fn_hash_data);
114936 +
114937 + return set_node_codes(node, fn_hash_data);
114938 +}
114939 +
114940 +static void set_function_codes(struct function_hash *fn_hash_data)
114941 +{
114942 + const_tree arg, type = TREE_TYPE(fn_hash_data->fndecl);
114943 + enum tree_code code = TREE_CODE(type);
114944 +
114945 + gcc_assert(code == FUNCTION_TYPE || code == METHOD_TYPE);
114946 +
114947 + set_result_codes(fn_hash_data->fndecl, fn_hash_data);
114948 +
114949 + for (arg = TYPE_ARG_TYPES(type); arg != NULL_TREE && fn_hash_data->tree_codes_len < CODES_LIMIT; arg = TREE_CHAIN(arg))
114950 + set_node_codes(TREE_VALUE(arg), fn_hash_data);
114951 +}
114952 +
114953 +static const struct size_overflow_hash *get_proper_hash_chain(const struct size_overflow_hash *entry, const char *func_name)
114954 +{
114955 + while (entry) {
114956 + if (!strcmp(entry->name, func_name))
114957 + return entry;
114958 + entry = entry->next;
114959 + }
114960 + return NULL;
114961 +}
114962 +
114963 +static const struct size_overflow_hash *get_function_hash(const_tree fndecl)
114964 +{
114965 + const struct size_overflow_hash *entry;
114966 + struct function_hash fn_hash_data;
114967 + const char *func_name;
114968 +
114969 + // skip builtins __builtin_constant_p
114970 + if (DECL_BUILT_IN(fndecl))
114971 + return NULL;
114972 +
114973 + fn_hash_data.fndecl = fndecl;
114974 + fn_hash_data.tree_codes_len = 0;
114975 +
114976 + set_function_codes(&fn_hash_data);
114977 + gcc_assert(fn_hash_data.tree_codes_len != 0);
114978 +
114979 + func_name = DECL_NAME_POINTER(fn_hash_data.fndecl);
114980 + set_hash(func_name, &fn_hash_data);
114981 +
114982 + entry = size_overflow_hash[fn_hash_data.hash];
114983 + entry = get_proper_hash_chain(entry, func_name);
114984 + if (entry)
114985 + return entry;
114986 + entry = size_overflow_hash_aux[fn_hash_data.hash];
114987 + return get_proper_hash_chain(entry, func_name);
114988 +}
114989 +
114990 +static void print_missing_msg(const_tree func, unsigned int argnum)
114991 +{
114992 + location_t loc;
114993 + const char *curfunc;
114994 + struct function_hash fn_hash_data;
114995 +
114996 + fn_hash_data.fndecl = DECL_ORIGIN(func);
114997 + fn_hash_data.tree_codes_len = 0;
114998 +
114999 + loc = DECL_SOURCE_LOCATION(fn_hash_data.fndecl);
115000 + curfunc = DECL_NAME_POINTER(fn_hash_data.fndecl);
115001 +
115002 + set_function_codes(&fn_hash_data);
115003 + set_hash(curfunc, &fn_hash_data);
115004 +
115005 + inform(loc, "Function %s is missing from the size_overflow hash table +%s+%u+%u+", curfunc, curfunc, argnum, fn_hash_data.hash);
115006 +}
115007 +
115008 +static unsigned int find_arg_number_tree(const_tree arg, const_tree func)
115009 +{
115010 + tree var;
115011 + unsigned int argnum = 1;
115012 +
115013 + if (TREE_CODE(arg) == SSA_NAME)
115014 + arg = SSA_NAME_VAR(arg);
115015 +
115016 + for (var = DECL_ARGUMENTS(func); var; var = TREE_CHAIN(var), argnum++) {
115017 + if (!operand_equal_p(arg, var, 0) && strcmp(DECL_NAME_POINTER(var), DECL_NAME_POINTER(arg)))
115018 + continue;
115019 + if (!skip_types(var))
115020 + return argnum;
115021 + }
115022 +
115023 + return CANNOT_FIND_ARG;
115024 +}
115025 +
115026 +static tree create_new_var(tree type)
115027 +{
115028 + tree new_var = create_tmp_var(type, "cicus");
115029 +
115030 + add_referenced_var(new_var);
115031 + return new_var;
115032 +}
115033 +
115034 +static gimple create_binary_assign(enum tree_code code, gimple stmt, tree rhs1, tree rhs2)
115035 +{
115036 + gimple assign;
115037 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
115038 + tree type = TREE_TYPE(rhs1);
115039 + tree lhs = create_new_var(type);
115040 +
115041 + gcc_assert(types_compatible_p(type, TREE_TYPE(rhs2)));
115042 + assign = gimple_build_assign_with_ops(code, lhs, rhs1, rhs2);
115043 + gimple_assign_set_lhs(assign, make_ssa_name(lhs, assign));
115044 +
115045 + gsi_insert_before(&gsi, assign, GSI_NEW_STMT);
115046 + update_stmt(assign);
115047 + set_stmt_flag(assign, MY_STMT);
115048 + return assign;
115049 +}
115050 +
115051 +static tree cast_a_tree(tree type, tree var)
115052 +{
115053 + gcc_assert(type != NULL_TREE);
115054 + gcc_assert(var != NULL_TREE);
115055 + gcc_assert(fold_convertible_p(type, var));
115056 +
115057 + return fold_convert(type, var);
115058 +}
115059 +
115060 +static tree get_lhs(const_gimple stmt)
115061 +{
115062 + switch (gimple_code(stmt)) {
115063 + case GIMPLE_ASSIGN:
115064 + case GIMPLE_CALL:
115065 + return gimple_get_lhs(stmt);
115066 + case GIMPLE_PHI:
115067 + return gimple_phi_result(stmt);
115068 + default:
115069 + return NULL_TREE;
115070 + }
115071 +}
115072 +
115073 +static bool skip_cast(tree dst_type, const_tree rhs, bool force)
115074 +{
115075 + const_gimple def_stmt = get_def_stmt(rhs);
115076 +
115077 + if (force)
115078 + return false;
115079 +
115080 + if (is_gimple_constant(rhs))
115081 + return false;
115082 +
115083 + if (!def_stmt || gimple_code(def_stmt) == GIMPLE_NOP)
115084 + return false;
115085 +
115086 + if (!types_compatible_p(dst_type, TREE_TYPE(rhs)))
115087 + return false;
115088 +
115089 + // DI type can be on 32 bit (from create_assign) but overflow type stays DI
115090 + if (LONG_TYPE_SIZE == GET_MODE_BITSIZE(SImode))
115091 + return false;
115092 +
115093 + return true;
115094 +}
115095 +
115096 +static gimple build_cast_stmt(tree dst_type, tree rhs, tree lhs, gimple_stmt_iterator *gsi, bool before, bool force)
115097 +{
115098 + gimple assign, def_stmt;
115099 +
115100 + gcc_assert(dst_type != NULL_TREE && rhs != NULL_TREE);
115101 + if (gsi_end_p(*gsi) && before == AFTER_STMT)
115102 + gcc_unreachable();
115103 +
115104 + def_stmt = get_def_stmt(rhs);
115105 + if (def_stmt && gimple_code(def_stmt) != GIMPLE_NOP && skip_cast(dst_type, rhs, force) && get_stmt_flag(def_stmt) == MY_STMT)
115106 + return def_stmt;
115107 +
115108 + if (lhs == CREATE_NEW_VAR)
115109 + lhs = create_new_var(dst_type);
115110 +
115111 + assign = gimple_build_assign(lhs, cast_a_tree(dst_type, rhs));
115112 +
115113 + if (!gsi_end_p(*gsi)) {
115114 + location_t loc = gimple_location(gsi_stmt(*gsi));
115115 + gimple_set_location(assign, loc);
115116 + }
115117 +
115118 + gimple_assign_set_lhs(assign, make_ssa_name(lhs, assign));
115119 +
115120 + if (before)
115121 + gsi_insert_before(gsi, assign, GSI_NEW_STMT);
115122 + else
115123 + gsi_insert_after(gsi, assign, GSI_NEW_STMT);
115124 + update_stmt(assign);
115125 + return assign;
115126 +}
115127 +
115128 +static tree cast_to_new_size_overflow_type(gimple stmt, tree rhs, tree size_overflow_type, bool before)
115129 +{
115130 + gimple_stmt_iterator gsi;
115131 + tree lhs;
115132 + gimple new_stmt;
115133 +
115134 + if (rhs == NULL_TREE)
115135 + return NULL_TREE;
115136 +
115137 + gsi = gsi_for_stmt(stmt);
115138 + new_stmt = build_cast_stmt(size_overflow_type, rhs, CREATE_NEW_VAR, &gsi, before, false);
115139 + set_stmt_flag(new_stmt, MY_STMT);
115140 +
115141 + lhs = get_lhs(new_stmt);
115142 + gcc_assert(lhs != NULL_TREE);
115143 + return lhs;
115144 +}
115145 +
115146 +static tree cast_to_TI_type(gimple stmt, tree node)
115147 +{
115148 + gimple_stmt_iterator gsi;
115149 + gimple cast_stmt;
115150 + tree type = TREE_TYPE(node);
115151 +
115152 + if (types_compatible_p(type, intTI_type_node))
115153 + return node;
115154 +
115155 + gsi = gsi_for_stmt(stmt);
115156 + cast_stmt = build_cast_stmt(intTI_type_node, node, CREATE_NEW_VAR, &gsi, BEFORE_STMT, false);
115157 + set_stmt_flag(cast_stmt, MY_STMT);
115158 + return gimple_assign_lhs(cast_stmt);
115159 +}
115160 +
115161 +static tree create_assign(struct pointer_set_t *visited, gimple oldstmt, tree rhs1, bool before)
115162 +{
115163 + tree lhs, new_lhs;
115164 + gimple_stmt_iterator gsi;
115165 +
115166 + if (rhs1 == NULL_TREE) {
115167 + debug_gimple_stmt(oldstmt);
115168 + error("%s: rhs1 is NULL_TREE", __func__);
115169 + gcc_unreachable();
115170 + }
115171 +
115172 + switch (gimple_code(oldstmt)) {
115173 + case GIMPLE_ASM:
115174 + lhs = rhs1;
115175 + break;
115176 + case GIMPLE_CALL:
115177 + case GIMPLE_ASSIGN:
115178 + lhs = gimple_get_lhs(oldstmt);
115179 + break;
115180 + default:
115181 + debug_gimple_stmt(oldstmt);
115182 + gcc_unreachable();
115183 + }
115184 +
115185 + gsi = gsi_for_stmt(oldstmt);
115186 + pointer_set_insert(visited, oldstmt);
115187 + if (lookup_stmt_eh_lp(oldstmt) != 0) {
115188 + basic_block next_bb, cur_bb;
115189 + const_edge e;
115190 +
115191 + gcc_assert(before == false);
115192 + gcc_assert(stmt_can_throw_internal(oldstmt));
115193 + gcc_assert(gimple_code(oldstmt) == GIMPLE_CALL);
115194 + gcc_assert(!gsi_end_p(gsi));
115195 +
115196 + cur_bb = gimple_bb(oldstmt);
115197 + next_bb = cur_bb->next_bb;
115198 + e = find_edge(cur_bb, next_bb);
115199 + gcc_assert(e != NULL);
115200 + gcc_assert(e->flags & EDGE_FALLTHRU);
115201 +
115202 + gsi = gsi_after_labels(next_bb);
115203 + gcc_assert(!gsi_end_p(gsi));
115204 +
115205 + before = true;
115206 + oldstmt = gsi_stmt(gsi);
115207 + }
115208 +
115209 + new_lhs = cast_to_new_size_overflow_type(oldstmt, rhs1, get_size_overflow_type(oldstmt, lhs), before);
115210 + return new_lhs;
115211 +}
115212 +
115213 +static tree dup_assign(struct pointer_set_t *visited, gimple oldstmt, const_tree node, tree rhs1, tree rhs2, tree __unused rhs3)
115214 +{
115215 + gimple stmt;
115216 + gimple_stmt_iterator gsi;
115217 + tree size_overflow_type, new_var, lhs = gimple_assign_lhs(oldstmt);
115218 +
115219 + if (get_stmt_flag(oldstmt) == MY_STMT)
115220 + return lhs;
115221 +
115222 + if (gimple_num_ops(oldstmt) != 4 && rhs1 == NULL_TREE) {
115223 + rhs1 = gimple_assign_rhs1(oldstmt);
115224 + rhs1 = create_assign(visited, oldstmt, rhs1, BEFORE_STMT);
115225 + }
115226 + if (gimple_num_ops(oldstmt) == 3 && rhs2 == NULL_TREE) {
115227 + rhs2 = gimple_assign_rhs2(oldstmt);
115228 + rhs2 = create_assign(visited, oldstmt, rhs2, BEFORE_STMT);
115229 + }
115230 +
115231 + stmt = gimple_copy(oldstmt);
115232 + gimple_set_location(stmt, gimple_location(oldstmt));
115233 + set_stmt_flag(stmt, MY_STMT);
115234 +
115235 + if (gimple_assign_rhs_code(oldstmt) == WIDEN_MULT_EXPR)
115236 + gimple_assign_set_rhs_code(stmt, MULT_EXPR);
115237 +
115238 + size_overflow_type = get_size_overflow_type(oldstmt, node);
115239 +
115240 + new_var = create_new_var(size_overflow_type);
115241 + new_var = make_ssa_name(new_var, stmt);
115242 + gimple_assign_set_lhs(stmt, new_var);
115243 +
115244 + if (rhs1 != NULL_TREE)
115245 + gimple_assign_set_rhs1(stmt, rhs1);
115246 +
115247 + if (rhs2 != NULL_TREE)
115248 + gimple_assign_set_rhs2(stmt, rhs2);
115249 +#if BUILDING_GCC_VERSION >= 4006
115250 + if (rhs3 != NULL_TREE)
115251 + gimple_assign_set_rhs3(stmt, rhs3);
115252 +#endif
115253 + gimple_set_vuse(stmt, gimple_vuse(oldstmt));
115254 + gimple_set_vdef(stmt, gimple_vdef(oldstmt));
115255 +
115256 + gsi = gsi_for_stmt(oldstmt);
115257 + gsi_insert_after(&gsi, stmt, GSI_SAME_STMT);
115258 + update_stmt(stmt);
115259 + pointer_set_insert(visited, oldstmt);
115260 + return gimple_assign_lhs(stmt);
115261 +}
115262 +
115263 +static tree cast_parm_decl(tree phi_ssa_name, tree arg, tree size_overflow_type, basic_block bb)
115264 +{
115265 + gimple assign;
115266 + gimple_stmt_iterator gsi;
115267 + basic_block first_bb;
115268 +
115269 + gcc_assert(SSA_NAME_IS_DEFAULT_DEF(arg));
115270 +
115271 + if (bb->index == 0) {
115272 + first_bb = split_block_after_labels(ENTRY_BLOCK_PTR_FOR_FN(cfun))->dest;
115273 + gcc_assert(dom_info_available_p(CDI_DOMINATORS));
115274 + set_immediate_dominator(CDI_DOMINATORS, first_bb, ENTRY_BLOCK_PTR_FOR_FN(cfun));
115275 + bb = first_bb;
115276 + }
115277 +
115278 + gsi = gsi_after_labels(bb);
115279 + assign = build_cast_stmt(size_overflow_type, arg, phi_ssa_name, &gsi, BEFORE_STMT, false);
115280 + set_stmt_flag(assign, MY_STMT);
115281 +
115282 + return gimple_assign_lhs(assign);
115283 +}
115284 +
115285 +static tree use_phi_ssa_name(tree ssa_name_var, tree new_arg)
115286 +{
115287 + gimple_stmt_iterator gsi;
115288 + gimple assign, def_stmt = get_def_stmt(new_arg);
115289 +
115290 + if (gimple_code(def_stmt) == GIMPLE_PHI) {
115291 + gsi = gsi_after_labels(gimple_bb(def_stmt));
115292 + assign = build_cast_stmt(TREE_TYPE(new_arg), new_arg, ssa_name_var, &gsi, BEFORE_STMT, true);
115293 + } else {
115294 + gsi = gsi_for_stmt(def_stmt);
115295 + assign = build_cast_stmt(TREE_TYPE(new_arg), new_arg, ssa_name_var, &gsi, AFTER_STMT, true);
115296 + }
115297 +
115298 + set_stmt_flag(assign, MY_STMT);
115299 + return gimple_assign_lhs(assign);
115300 +}
115301 +
115302 +static tree cast_visited_phi_arg(tree ssa_name_var, tree arg, tree size_overflow_type)
115303 +{
115304 + basic_block bb;
115305 + gimple_stmt_iterator gsi;
115306 + const_gimple def_stmt;
115307 + gimple assign;
115308 +
115309 + def_stmt = get_def_stmt(arg);
115310 + bb = gimple_bb(def_stmt);
115311 + gcc_assert(bb->index != 0);
115312 + gsi = gsi_after_labels(bb);
115313 +
115314 + assign = build_cast_stmt(size_overflow_type, arg, ssa_name_var, &gsi, BEFORE_STMT, false);
115315 + set_stmt_flag(assign, MY_STMT);
115316 + return gimple_assign_lhs(assign);
115317 +}
115318 +
115319 +static tree create_new_phi_arg(tree ssa_name_var, tree new_arg, gimple oldstmt, unsigned int i)
115320 +{
115321 + tree size_overflow_type;
115322 + tree arg;
115323 + const_gimple def_stmt;
115324 +
115325 + if (new_arg != NULL_TREE && is_gimple_constant(new_arg))
115326 + return new_arg;
115327 +
115328 + arg = gimple_phi_arg_def(oldstmt, i);
115329 + def_stmt = get_def_stmt(arg);
115330 + gcc_assert(def_stmt != NULL);
115331 + size_overflow_type = get_size_overflow_type(oldstmt, arg);
115332 +
115333 + switch (gimple_code(def_stmt)) {
115334 + case GIMPLE_PHI:
115335 + return cast_visited_phi_arg(ssa_name_var, arg, size_overflow_type);
115336 + case GIMPLE_NOP: {
115337 + basic_block bb;
115338 +
115339 + bb = gimple_phi_arg_edge(oldstmt, i)->src;
115340 + return cast_parm_decl(ssa_name_var, arg, size_overflow_type, bb);
115341 + }
115342 + case GIMPLE_ASM: {
115343 + gimple_stmt_iterator gsi;
115344 + gimple assign, stmt = get_def_stmt(arg);
115345 +
115346 + gsi = gsi_for_stmt(stmt);
115347 + assign = build_cast_stmt(size_overflow_type, arg, ssa_name_var, &gsi, AFTER_STMT, false);
115348 + set_stmt_flag(assign, MY_STMT);
115349 + return gimple_assign_lhs(assign);
115350 + }
115351 + default:
115352 + gcc_assert(new_arg != NULL_TREE);
115353 + gcc_assert(types_compatible_p(TREE_TYPE(new_arg), size_overflow_type));
115354 + return use_phi_ssa_name(ssa_name_var, new_arg);
115355 + }
115356 +}
115357 +
115358 +static gimple overflow_create_phi_node(gimple oldstmt, tree result)
115359 +{
115360 + basic_block bb;
115361 + gimple phi;
115362 + gimple_seq seq;
115363 + gimple_stmt_iterator gsi = gsi_for_stmt(oldstmt);
115364 +
115365 + bb = gsi_bb(gsi);
115366 +
115367 + if (result == NULL_TREE) {
115368 + tree old_result = gimple_phi_result(oldstmt);
115369 + tree size_overflow_type = get_size_overflow_type(oldstmt, old_result);
115370 +
115371 + result = create_new_var(size_overflow_type);
115372 + }
115373 +
115374 + phi = create_phi_node(result, bb);
115375 + gimple_phi_set_result(phi, make_ssa_name(result, phi));
115376 + seq = phi_nodes(bb);
115377 + gsi = gsi_last(seq);
115378 + gsi_remove(&gsi, false);
115379 +
115380 + gsi = gsi_for_stmt(oldstmt);
115381 + gsi_insert_after(&gsi, phi, GSI_NEW_STMT);
115382 + gimple_set_bb(phi, bb);
115383 + set_stmt_flag(phi, MY_STMT);
115384 + return phi;
115385 +}
115386 +
115387 +#if BUILDING_GCC_VERSION <= 4007
115388 +static tree create_new_phi_node(VEC(tree, heap) **args, tree ssa_name_var, gimple oldstmt)
115389 +#else
115390 +static tree create_new_phi_node(vec<tree, va_heap, vl_embed> *&args, tree ssa_name_var, gimple oldstmt)
115391 +#endif
115392 +{
115393 + gimple new_phi;
115394 + unsigned int i;
115395 + tree arg, result;
115396 + location_t loc = gimple_location(oldstmt);
115397 +
115398 +#if BUILDING_GCC_VERSION <= 4007
115399 + gcc_assert(!VEC_empty(tree, *args));
115400 +#else
115401 + gcc_assert(!args->is_empty());
115402 +#endif
115403 +
115404 + new_phi = overflow_create_phi_node(oldstmt, ssa_name_var);
115405 + result = gimple_phi_result(new_phi);
115406 + ssa_name_var = SSA_NAME_VAR(result);
115407 +
115408 +#if BUILDING_GCC_VERSION <= 4007
115409 + FOR_EACH_VEC_ELT(tree, *args, i, arg) {
115410 +#else
115411 + FOR_EACH_VEC_SAFE_ELT(args, i, arg) {
115412 +#endif
115413 + arg = create_new_phi_arg(ssa_name_var, arg, oldstmt, i);
115414 + add_phi_arg(new_phi, arg, gimple_phi_arg_edge(oldstmt, i), loc);
115415 + }
115416 +
115417 +#if BUILDING_GCC_VERSION <= 4007
115418 + VEC_free(tree, heap, *args);
115419 +#else
115420 + vec_free(args);
115421 +#endif
115422 + update_stmt(new_phi);
115423 + return result;
115424 +}
115425 +
115426 +static tree handle_phi(struct pointer_set_t *visited, struct cgraph_node *caller_node, tree orig_result)
115427 +{
115428 + tree ssa_name_var = NULL_TREE;
115429 +#if BUILDING_GCC_VERSION <= 4007
115430 + VEC(tree, heap) *args = NULL;
115431 +#else
115432 + vec<tree, va_heap, vl_embed> *args = NULL;
115433 +#endif
115434 + gimple oldstmt = get_def_stmt(orig_result);
115435 + unsigned int i, len = gimple_phi_num_args(oldstmt);
115436 +
115437 + pointer_set_insert(visited, oldstmt);
115438 + for (i = 0; i < len; i++) {
115439 + tree arg, new_arg;
115440 +
115441 + arg = gimple_phi_arg_def(oldstmt, i);
115442 + new_arg = expand(visited, caller_node, arg);
115443 +
115444 + if (ssa_name_var == NULL_TREE && new_arg != NULL_TREE)
115445 + ssa_name_var = SSA_NAME_VAR(new_arg);
115446 +
115447 + if (is_gimple_constant(arg)) {
115448 + tree size_overflow_type = get_size_overflow_type(oldstmt, arg);
115449 +
115450 + new_arg = cast_a_tree(size_overflow_type, arg);
115451 + }
115452 +
115453 +#if BUILDING_GCC_VERSION <= 4007
115454 + VEC_safe_push(tree, heap, args, new_arg);
115455 +#else
115456 + vec_safe_push(args, new_arg);
115457 +#endif
115458 + }
115459 +
115460 +#if BUILDING_GCC_VERSION <= 4007
115461 + return create_new_phi_node(&args, ssa_name_var, oldstmt);
115462 +#else
115463 + return create_new_phi_node(args, ssa_name_var, oldstmt);
115464 +#endif
115465 +}
115466 +
115467 +static tree change_assign_rhs(gimple stmt, const_tree orig_rhs, tree new_rhs)
115468 +{
115469 + gimple assign;
115470 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
115471 + tree origtype = TREE_TYPE(orig_rhs);
115472 +
115473 + gcc_assert(is_gimple_assign(stmt));
115474 +
115475 + assign = build_cast_stmt(origtype, new_rhs, CREATE_NEW_VAR, &gsi, BEFORE_STMT, false);
115476 + set_stmt_flag(assign, MY_STMT);
115477 + return gimple_assign_lhs(assign);
115478 +}
115479 +
115480 +static bool is_a_cast_and_const_overflow(const_tree no_const_rhs)
115481 +{
115482 + const_tree rhs1, lhs, rhs1_type, lhs_type;
115483 + enum machine_mode lhs_mode, rhs_mode;
115484 + gimple def_stmt = get_def_stmt(no_const_rhs);
115485 +
115486 + if (!def_stmt || !gimple_assign_cast_p(def_stmt))
115487 + return false;
115488 +
115489 + rhs1 = gimple_assign_rhs1(def_stmt);
115490 + lhs = gimple_assign_lhs(def_stmt);
115491 + rhs1_type = TREE_TYPE(rhs1);
115492 + lhs_type = TREE_TYPE(lhs);
115493 + rhs_mode = TYPE_MODE(rhs1_type);
115494 + lhs_mode = TYPE_MODE(lhs_type);
115495 + if (TYPE_UNSIGNED(lhs_type) == TYPE_UNSIGNED(rhs1_type) || lhs_mode != rhs_mode)
115496 + return false;
115497 +
115498 + return true;
115499 +}
115500 +
115501 +static tree create_cast_assign(struct pointer_set_t *visited, gimple stmt)
115502 +{
115503 + tree rhs1 = gimple_assign_rhs1(stmt);
115504 + tree lhs = gimple_assign_lhs(stmt);
115505 + const_tree rhs1_type = TREE_TYPE(rhs1);
115506 + const_tree lhs_type = TREE_TYPE(lhs);
115507 +
115508 + if (TYPE_UNSIGNED(rhs1_type) == TYPE_UNSIGNED(lhs_type))
115509 + return create_assign(visited, stmt, lhs, AFTER_STMT);
115510 +
115511 + return create_assign(visited, stmt, rhs1, AFTER_STMT);
115512 +}
115513 +
115514 +static bool no_uses(tree node)
115515 +{
115516 + imm_use_iterator imm_iter;
115517 + use_operand_p use_p;
115518 +
115519 + FOR_EACH_IMM_USE_FAST(use_p, imm_iter, node) {
115520 + const_gimple use_stmt = USE_STMT(use_p);
115521 +
115522 + if (use_stmt == NULL)
115523 + return true;
115524 + if (is_gimple_debug(use_stmt))
115525 + continue;
115526 + return false;
115527 + }
115528 + return true;
115529 +}
115530 +
115531 +// 3.8.5 mm/page-writeback.c __ilog2_u64(): ret, uint + uintmax; uint -> int; int max
115532 +static bool is_const_plus_unsigned_signed_truncation(const_tree lhs)
115533 +{
115534 + tree rhs1, lhs_type, rhs_type, rhs2, not_const_rhs;
115535 + gimple def_stmt = get_def_stmt(lhs);
115536 +
115537 + if (!def_stmt || !gimple_assign_cast_p(def_stmt))
115538 + return false;
115539 +
115540 + rhs1 = gimple_assign_rhs1(def_stmt);
115541 + rhs_type = TREE_TYPE(rhs1);
115542 + lhs_type = TREE_TYPE(lhs);
115543 + if (TYPE_UNSIGNED(lhs_type) || !TYPE_UNSIGNED(rhs_type))
115544 + return false;
115545 + if (TYPE_MODE(lhs_type) != TYPE_MODE(rhs_type))
115546 + return false;
115547 +
115548 + def_stmt = get_def_stmt(rhs1);
115549 + if (!def_stmt || !is_gimple_assign(def_stmt) || gimple_num_ops(def_stmt) != 3)
115550 + return false;
115551 +
115552 + if (gimple_assign_rhs_code(def_stmt) != PLUS_EXPR)
115553 + return false;
115554 +
115555 + rhs1 = gimple_assign_rhs1(def_stmt);
115556 + rhs2 = gimple_assign_rhs2(def_stmt);
115557 + if (!is_gimple_constant(rhs1) && !is_gimple_constant(rhs2))
115558 + return false;
115559 +
115560 + if (is_gimple_constant(rhs2))
115561 + not_const_rhs = rhs1;
115562 + else
115563 + not_const_rhs = rhs2;
115564 +
115565 + return no_uses(not_const_rhs);
115566 +}
115567 +
115568 +static bool skip_lhs_cast_check(const_gimple stmt)
115569 +{
115570 + const_tree rhs = gimple_assign_rhs1(stmt);
115571 + const_gimple def_stmt = get_def_stmt(rhs);
115572 +
115573 + // 3.8.2 kernel/futex_compat.c compat_exit_robust_list(): get_user() 64 ulong -> int (compat_long_t), int max
115574 + if (gimple_code(def_stmt) == GIMPLE_ASM)
115575 + return true;
115576 +
115577 + if (is_const_plus_unsigned_signed_truncation(rhs))
115578 + return true;
115579 +
115580 + return false;
115581 +}
115582 +
115583 +static tree create_cast_overflow_check(struct pointer_set_t *visited, struct cgraph_node *caller_node, tree new_rhs1, gimple stmt)
115584 +{
115585 + bool cast_lhs, cast_rhs;
115586 + tree lhs = gimple_assign_lhs(stmt);
115587 + tree rhs = gimple_assign_rhs1(stmt);
115588 + const_tree lhs_type = TREE_TYPE(lhs);
115589 + const_tree rhs_type = TREE_TYPE(rhs);
115590 + enum machine_mode lhs_mode = TYPE_MODE(lhs_type);
115591 + enum machine_mode rhs_mode = TYPE_MODE(rhs_type);
115592 + unsigned int lhs_size = GET_MODE_BITSIZE(lhs_mode);
115593 + unsigned int rhs_size = GET_MODE_BITSIZE(rhs_mode);
115594 +
115595 + static bool check_lhs[3][4] = {
115596 + // ss su us uu
115597 + { false, true, true, false }, // lhs > rhs
115598 + { false, false, false, false }, // lhs = rhs
115599 + { true, true, true, true }, // lhs < rhs
115600 + };
115601 +
115602 + static bool check_rhs[3][4] = {
115603 + // ss su us uu
115604 + { true, false, true, true }, // lhs > rhs
115605 + { true, false, true, true }, // lhs = rhs
115606 + { true, false, true, true }, // lhs < rhs
115607 + };
115608 +
115609 + // skip lhs check on signed SI -> HI cast or signed SI -> QI cast !!!!
115610 + if (rhs_mode == SImode && !TYPE_UNSIGNED(rhs_type) && (lhs_mode == HImode || lhs_mode == QImode))
115611 + return create_assign(visited, stmt, lhs, AFTER_STMT);
115612 +
115613 + if (lhs_size > rhs_size) {
115614 + cast_lhs = check_lhs[0][TYPE_UNSIGNED(rhs_type) + 2 * TYPE_UNSIGNED(lhs_type)];
115615 + cast_rhs = check_rhs[0][TYPE_UNSIGNED(rhs_type) + 2 * TYPE_UNSIGNED(lhs_type)];
115616 + } else if (lhs_size == rhs_size) {
115617 + cast_lhs = check_lhs[1][TYPE_UNSIGNED(rhs_type) + 2 * TYPE_UNSIGNED(lhs_type)];
115618 + cast_rhs = check_rhs[1][TYPE_UNSIGNED(rhs_type) + 2 * TYPE_UNSIGNED(lhs_type)];
115619 + } else {
115620 + cast_lhs = check_lhs[2][TYPE_UNSIGNED(rhs_type) + 2 * TYPE_UNSIGNED(lhs_type)];
115621 + cast_rhs = check_rhs[2][TYPE_UNSIGNED(rhs_type) + 2 * TYPE_UNSIGNED(lhs_type)];
115622 + }
115623 +
115624 + if (!cast_lhs && !cast_rhs)
115625 + return dup_assign(visited, stmt, lhs, new_rhs1, NULL_TREE, NULL_TREE);
115626 +
115627 + if (cast_lhs && !skip_lhs_cast_check(stmt))
115628 + check_size_overflow(caller_node, stmt, TREE_TYPE(new_rhs1), new_rhs1, lhs, BEFORE_STMT);
115629 +
115630 + if (cast_rhs)
115631 + check_size_overflow(caller_node, stmt, TREE_TYPE(new_rhs1), new_rhs1, rhs, BEFORE_STMT);
115632 +
115633 + return dup_assign(visited, stmt, lhs, new_rhs1, NULL_TREE, NULL_TREE);
115634 +}
115635 +
115636 +static tree handle_unary_rhs(struct pointer_set_t *visited, struct cgraph_node *caller_node, gimple stmt)
115637 +{
115638 + tree rhs1, new_rhs1, lhs = gimple_assign_lhs(stmt);
115639 +
115640 + if (get_stmt_flag(stmt) == MY_STMT)
115641 + return lhs;
115642 +
115643 + rhs1 = gimple_assign_rhs1(stmt);
115644 + if (TREE_CODE(TREE_TYPE(rhs1)) == POINTER_TYPE)
115645 + return create_assign(visited, stmt, lhs, AFTER_STMT);
115646 +
115647 + new_rhs1 = expand(visited, caller_node, rhs1);
115648 +
115649 + if (new_rhs1 == NULL_TREE)
115650 + return create_cast_assign(visited, stmt);
115651 +
115652 + if (get_stmt_flag(stmt) == NO_CAST_CHECK)
115653 + return dup_assign(visited, stmt, lhs, new_rhs1, NULL_TREE, NULL_TREE);
115654 +
115655 + if (gimple_assign_rhs_code(stmt) == BIT_NOT_EXPR) {
115656 + tree size_overflow_type = get_size_overflow_type(stmt, rhs1);
115657 +
115658 + new_rhs1 = cast_to_new_size_overflow_type(stmt, new_rhs1, size_overflow_type, BEFORE_STMT);
115659 + check_size_overflow(caller_node, stmt, size_overflow_type, new_rhs1, rhs1, BEFORE_STMT);
115660 + return create_assign(visited, stmt, lhs, AFTER_STMT);
115661 + }
115662 +
115663 + if (!gimple_assign_cast_p(stmt))
115664 + return dup_assign(visited, stmt, lhs, new_rhs1, NULL_TREE, NULL_TREE);
115665 +
115666 + return create_cast_overflow_check(visited, caller_node, new_rhs1, stmt);
115667 +}
115668 +
115669 +static tree handle_unary_ops(struct pointer_set_t *visited, struct cgraph_node *caller_node, gimple stmt)
115670 +{
115671 + tree rhs1, lhs = gimple_assign_lhs(stmt);
115672 + gimple def_stmt = get_def_stmt(lhs);
115673 +
115674 + gcc_assert(gimple_code(def_stmt) != GIMPLE_NOP);
115675 + rhs1 = gimple_assign_rhs1(def_stmt);
115676 +
115677 + if (is_gimple_constant(rhs1))
115678 + return create_assign(visited, def_stmt, lhs, AFTER_STMT);
115679 +
115680 + switch (TREE_CODE(rhs1)) {
115681 + case SSA_NAME:
115682 + return handle_unary_rhs(visited, caller_node, def_stmt);
115683 + case ARRAY_REF:
115684 + case BIT_FIELD_REF:
115685 + case ADDR_EXPR:
115686 + case COMPONENT_REF:
115687 + case INDIRECT_REF:
115688 +#if BUILDING_GCC_VERSION >= 4006
115689 + case MEM_REF:
115690 +#endif
115691 + case TARGET_MEM_REF:
115692 + case VIEW_CONVERT_EXPR:
115693 + return create_assign(visited, def_stmt, lhs, AFTER_STMT);
115694 + case PARM_DECL:
115695 + case VAR_DECL:
115696 + return create_assign(visited, stmt, lhs, AFTER_STMT);
115697 +
115698 + default:
115699 + debug_gimple_stmt(def_stmt);
115700 + debug_tree(rhs1);
115701 + gcc_unreachable();
115702 + }
115703 +}
115704 +
115705 +static void insert_cond(basic_block cond_bb, tree arg, enum tree_code cond_code, tree type_value)
115706 +{
115707 + gimple cond_stmt;
115708 + gimple_stmt_iterator gsi = gsi_last_bb(cond_bb);
115709 +
115710 + cond_stmt = gimple_build_cond(cond_code, arg, type_value, NULL_TREE, NULL_TREE);
115711 + gsi_insert_after(&gsi, cond_stmt, GSI_CONTINUE_LINKING);
115712 + update_stmt(cond_stmt);
115713 +}
115714 +
115715 +static tree create_string_param(tree string)
115716 +{
115717 + tree i_type, a_type;
115718 + const int length = TREE_STRING_LENGTH(string);
115719 +
115720 + gcc_assert(length > 0);
115721 +
115722 + i_type = build_index_type(build_int_cst(NULL_TREE, length - 1));
115723 + a_type = build_array_type(char_type_node, i_type);
115724 +
115725 + TREE_TYPE(string) = a_type;
115726 + TREE_CONSTANT(string) = 1;
115727 + TREE_READONLY(string) = 1;
115728 +
115729 + return build1(ADDR_EXPR, ptr_type_node, string);
115730 +}
115731 +
115732 +static void insert_cond_result(struct cgraph_node *caller_node, basic_block bb_true, const_gimple stmt, const_tree arg, bool min)
115733 +{
115734 + gimple func_stmt;
115735 + const_gimple def_stmt;
115736 + const_tree loc_line;
115737 + tree loc_file, ssa_name, current_func;
115738 + expanded_location xloc;
115739 + char *ssa_name_buf;
115740 + int len;
115741 + struct cgraph_edge *edge;
115742 + struct cgraph_node *callee_node;
115743 + int frequency;
115744 + gimple_stmt_iterator gsi = gsi_start_bb(bb_true);
115745 +
115746 + def_stmt = get_def_stmt(arg);
115747 + xloc = expand_location(gimple_location(def_stmt));
115748 +
115749 + if (!gimple_has_location(def_stmt)) {
115750 + xloc = expand_location(gimple_location(stmt));
115751 + if (!gimple_has_location(stmt))
115752 + xloc = expand_location(DECL_SOURCE_LOCATION(current_function_decl));
115753 + }
115754 +
115755 + loc_line = build_int_cstu(unsigned_type_node, xloc.line);
115756 +
115757 + loc_file = build_string(strlen(xloc.file) + 1, xloc.file);
115758 + loc_file = create_string_param(loc_file);
115759 +
115760 + current_func = build_string(DECL_NAME_LENGTH(current_function_decl) + 1, DECL_NAME_POINTER(current_function_decl));
115761 + current_func = create_string_param(current_func);
115762 +
115763 + gcc_assert(DECL_NAME(SSA_NAME_VAR(arg)) != NULL);
115764 + call_count++;
115765 + 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);
115766 + gcc_assert(len > 0);
115767 + ssa_name = build_string(len + 1, ssa_name_buf);
115768 + free(ssa_name_buf);
115769 + ssa_name = create_string_param(ssa_name);
115770 +
115771 + // void report_size_overflow(const char *file, unsigned int line, const char *func, const char *ssa_name)
115772 + func_stmt = gimple_build_call(report_size_overflow_decl, 4, loc_file, loc_line, current_func, ssa_name);
115773 + gsi_insert_after(&gsi, func_stmt, GSI_CONTINUE_LINKING);
115774 +
115775 + callee_node = cgraph_get_create_node(report_size_overflow_decl);
115776 + frequency = compute_call_stmt_bb_frequency(current_function_decl, bb_true);
115777 +
115778 + edge = cgraph_create_edge(caller_node, callee_node, func_stmt, bb_true->count, frequency, bb_true->loop_depth);
115779 + gcc_assert(edge != NULL);
115780 +}
115781 +
115782 +static void __unused print_the_code_insertions(const_gimple stmt)
115783 +{
115784 + location_t loc = gimple_location(stmt);
115785 +
115786 + inform(loc, "Integer size_overflow check applied here.");
115787 +}
115788 +
115789 +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)
115790 +{
115791 + basic_block cond_bb, join_bb, bb_true;
115792 + edge e;
115793 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
115794 +
115795 + cond_bb = gimple_bb(stmt);
115796 + if (before)
115797 + gsi_prev(&gsi);
115798 + if (gsi_end_p(gsi))
115799 + e = split_block_after_labels(cond_bb);
115800 + else
115801 + e = split_block(cond_bb, gsi_stmt(gsi));
115802 + cond_bb = e->src;
115803 + join_bb = e->dest;
115804 + e->flags = EDGE_FALSE_VALUE;
115805 + e->probability = REG_BR_PROB_BASE;
115806 +
115807 + bb_true = create_empty_bb(cond_bb);
115808 + make_edge(cond_bb, bb_true, EDGE_TRUE_VALUE);
115809 + make_edge(cond_bb, join_bb, EDGE_FALSE_VALUE);
115810 + make_edge(bb_true, join_bb, EDGE_FALLTHRU);
115811 +
115812 + gcc_assert(dom_info_available_p(CDI_DOMINATORS));
115813 + set_immediate_dominator(CDI_DOMINATORS, bb_true, cond_bb);
115814 + set_immediate_dominator(CDI_DOMINATORS, join_bb, cond_bb);
115815 +
115816 + if (current_loops != NULL) {
115817 + gcc_assert(cond_bb->loop_father == join_bb->loop_father);
115818 + add_bb_to_loop(bb_true, cond_bb->loop_father);
115819 + }
115820 +
115821 + insert_cond(cond_bb, arg, cond_code, type_value);
115822 + insert_cond_result(caller_node, bb_true, stmt, arg, min);
115823 +
115824 +// print_the_code_insertions(stmt);
115825 +}
115826 +
115827 +static void check_size_overflow(struct cgraph_node *caller_node, gimple stmt, tree size_overflow_type, tree cast_rhs, tree rhs, bool before)
115828 +{
115829 + const_tree rhs_type = TREE_TYPE(rhs);
115830 + tree cast_rhs_type, type_max_type, type_min_type, type_max, type_min;
115831 +
115832 + gcc_assert(rhs_type != NULL_TREE);
115833 + if (TREE_CODE(rhs_type) == POINTER_TYPE)
115834 + return;
115835 +
115836 + gcc_assert(TREE_CODE(rhs_type) == INTEGER_TYPE || TREE_CODE(rhs_type) == ENUMERAL_TYPE);
115837 +
115838 + if (is_const_plus_unsigned_signed_truncation(rhs))
115839 + return;
115840 +
115841 + type_max = cast_a_tree(size_overflow_type, TYPE_MAX_VALUE(rhs_type));
115842 + // typemax (-1) < typemin (0)
115843 + if (TREE_OVERFLOW(type_max))
115844 + return;
115845 +
115846 + type_min = cast_a_tree(size_overflow_type, TYPE_MIN_VALUE(rhs_type));
115847 +
115848 + cast_rhs_type = TREE_TYPE(cast_rhs);
115849 + type_max_type = TREE_TYPE(type_max);
115850 + gcc_assert(types_compatible_p(cast_rhs_type, type_max_type));
115851 +
115852 + insert_check_size_overflow(caller_node, stmt, GT_EXPR, cast_rhs, type_max, before, MAX_CHECK);
115853 +
115854 + // special case: get_size_overflow_type(), 32, u64->s
115855 + if (LONG_TYPE_SIZE == GET_MODE_BITSIZE(SImode) && TYPE_UNSIGNED(size_overflow_type) && !TYPE_UNSIGNED(rhs_type))
115856 + return;
115857 +
115858 + type_min_type = TREE_TYPE(type_min);
115859 + gcc_assert(types_compatible_p(type_max_type, type_min_type));
115860 + insert_check_size_overflow(caller_node, stmt, LT_EXPR, cast_rhs, type_min, before, MIN_CHECK);
115861 +}
115862 +
115863 +static bool is_lt_signed_type_max(const_tree rhs)
115864 +{
115865 + const_tree new_type, type_max, type = TREE_TYPE(rhs);
115866 +
115867 + if (!TYPE_UNSIGNED(type))
115868 + return true;
115869 +
115870 + switch (TYPE_MODE(type)) {
115871 + case QImode:
115872 + new_type = intQI_type_node;
115873 + break;
115874 + case HImode:
115875 + new_type = intHI_type_node;
115876 + break;
115877 + case SImode:
115878 + new_type = intSI_type_node;
115879 + break;
115880 + case DImode:
115881 + new_type = intDI_type_node;
115882 + break;
115883 + default:
115884 + debug_tree((tree)type);
115885 + gcc_unreachable();
115886 + }
115887 +
115888 + type_max = TYPE_MAX_VALUE(new_type);
115889 + if (!tree_int_cst_lt(type_max, rhs))
115890 + return true;
115891 +
115892 + return false;
115893 +}
115894 +
115895 +static bool is_gt_zero(const_tree rhs)
115896 +{
115897 + const_tree type = TREE_TYPE(rhs);
115898 +
115899 + if (TYPE_UNSIGNED(type))
115900 + return true;
115901 +
115902 + if (!tree_int_cst_lt(rhs, integer_zero_node))
115903 + return true;
115904 +
115905 + return false;
115906 +}
115907 +
115908 +static bool is_a_constant_overflow(const_gimple stmt, const_tree rhs)
115909 +{
115910 + if (gimple_assign_rhs_code(stmt) == MIN_EXPR)
115911 + return false;
115912 + if (!is_gimple_constant(rhs))
115913 + return false;
115914 +
115915 + // If the const is between 0 and the max value of the signed type of the same bitsize then there is no intentional overflow
115916 +// if (is_lt_signed_type_max(rhs) && is_gt_zero(rhs))
115917 +// return false;
115918 +
115919 + return true;
115920 +}
115921 +
115922 +static tree get_def_stmt_rhs(const_tree var)
115923 +{
115924 + tree rhs1, def_stmt_rhs1;
115925 + gimple rhs1_def_stmt, def_stmt_rhs1_def_stmt, def_stmt;
115926 +
115927 + def_stmt = get_def_stmt(var);
115928 + if (!gimple_assign_cast_p(def_stmt))
115929 + return NULL_TREE;
115930 + gcc_assert(gimple_code(def_stmt) != GIMPLE_NOP && get_stmt_flag(def_stmt) == MY_STMT && gimple_assign_cast_p(def_stmt));
115931 +
115932 + rhs1 = gimple_assign_rhs1(def_stmt);
115933 + rhs1_def_stmt = get_def_stmt(rhs1);
115934 + if (!gimple_assign_cast_p(rhs1_def_stmt))
115935 + return rhs1;
115936 +
115937 + def_stmt_rhs1 = gimple_assign_rhs1(rhs1_def_stmt);
115938 + def_stmt_rhs1_def_stmt = get_def_stmt(def_stmt_rhs1);
115939 +
115940 + switch (gimple_code(def_stmt_rhs1_def_stmt)) {
115941 + case GIMPLE_CALL:
115942 + case GIMPLE_NOP:
115943 + case GIMPLE_ASM:
115944 + case GIMPLE_PHI:
115945 + return def_stmt_rhs1;
115946 + case GIMPLE_ASSIGN:
115947 + return rhs1;
115948 + default:
115949 + debug_gimple_stmt(def_stmt_rhs1_def_stmt);
115950 + gcc_unreachable();
115951 + }
115952 +}
115953 +
115954 +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)
115955 +{
115956 + tree new_rhs, orig_rhs;
115957 + void (*gimple_assign_set_rhs)(gimple, tree);
115958 + tree rhs1 = gimple_assign_rhs1(stmt);
115959 + tree rhs2 = gimple_assign_rhs2(stmt);
115960 + tree lhs = gimple_assign_lhs(stmt);
115961 +
115962 + if (!check_overflow)
115963 + return create_assign(visited, stmt, lhs, AFTER_STMT);
115964 +
115965 + if (change_rhs == NULL_TREE)
115966 + return create_assign(visited, stmt, lhs, AFTER_STMT);
115967 +
115968 + if (new_rhs2 == NULL_TREE) {
115969 + orig_rhs = rhs1;
115970 + gimple_assign_set_rhs = &gimple_assign_set_rhs1;
115971 + } else {
115972 + orig_rhs = rhs2;
115973 + gimple_assign_set_rhs = &gimple_assign_set_rhs2;
115974 + }
115975 +
115976 + check_size_overflow(caller_node, stmt, TREE_TYPE(change_rhs), change_rhs, orig_rhs, BEFORE_STMT);
115977 +
115978 + new_rhs = change_assign_rhs(stmt, orig_rhs, change_rhs);
115979 + gimple_assign_set_rhs(stmt, new_rhs);
115980 + update_stmt(stmt);
115981 +
115982 + return create_assign(visited, stmt, lhs, AFTER_STMT);
115983 +}
115984 +
115985 +static bool is_subtraction_special(const_gimple stmt)
115986 +{
115987 + gimple rhs1_def_stmt, rhs2_def_stmt;
115988 + const_tree rhs1_def_stmt_rhs1, rhs2_def_stmt_rhs1, rhs1_def_stmt_lhs, rhs2_def_stmt_lhs;
115989 + enum machine_mode rhs1_def_stmt_rhs1_mode, rhs2_def_stmt_rhs1_mode, rhs1_def_stmt_lhs_mode, rhs2_def_stmt_lhs_mode;
115990 + const_tree rhs1 = gimple_assign_rhs1(stmt);
115991 + const_tree rhs2 = gimple_assign_rhs2(stmt);
115992 +
115993 + if (is_gimple_constant(rhs1) || is_gimple_constant(rhs2))
115994 + return false;
115995 +
115996 + gcc_assert(TREE_CODE(rhs1) == SSA_NAME && TREE_CODE(rhs2) == SSA_NAME);
115997 +
115998 + if (gimple_assign_rhs_code(stmt) != MINUS_EXPR)
115999 + return false;
116000 +
116001 + rhs1_def_stmt = get_def_stmt(rhs1);
116002 + rhs2_def_stmt = get_def_stmt(rhs2);
116003 + if (!gimple_assign_cast_p(rhs1_def_stmt) || !gimple_assign_cast_p(rhs2_def_stmt))
116004 + return false;
116005 +
116006 + rhs1_def_stmt_rhs1 = gimple_assign_rhs1(rhs1_def_stmt);
116007 + rhs2_def_stmt_rhs1 = gimple_assign_rhs1(rhs2_def_stmt);
116008 + rhs1_def_stmt_lhs = gimple_assign_lhs(rhs1_def_stmt);
116009 + rhs2_def_stmt_lhs = gimple_assign_lhs(rhs2_def_stmt);
116010 + rhs1_def_stmt_rhs1_mode = TYPE_MODE(TREE_TYPE(rhs1_def_stmt_rhs1));
116011 + rhs2_def_stmt_rhs1_mode = TYPE_MODE(TREE_TYPE(rhs2_def_stmt_rhs1));
116012 + rhs1_def_stmt_lhs_mode = TYPE_MODE(TREE_TYPE(rhs1_def_stmt_lhs));
116013 + rhs2_def_stmt_lhs_mode = TYPE_MODE(TREE_TYPE(rhs2_def_stmt_lhs));
116014 + if (GET_MODE_BITSIZE(rhs1_def_stmt_rhs1_mode) <= GET_MODE_BITSIZE(rhs1_def_stmt_lhs_mode))
116015 + return false;
116016 + if (GET_MODE_BITSIZE(rhs2_def_stmt_rhs1_mode) <= GET_MODE_BITSIZE(rhs2_def_stmt_lhs_mode))
116017 + return false;
116018 +
116019 + set_stmt_flag(rhs1_def_stmt, NO_CAST_CHECK);
116020 + set_stmt_flag(rhs2_def_stmt, NO_CAST_CHECK);
116021 + return true;
116022 +}
116023 +
116024 +static tree handle_integer_truncation(struct pointer_set_t *visited, struct cgraph_node *caller_node, const_tree lhs)
116025 +{
116026 + tree new_rhs1, new_rhs2;
116027 + tree new_rhs1_def_stmt_rhs1, new_rhs2_def_stmt_rhs1, new_lhs;
116028 + gimple assign, stmt = get_def_stmt(lhs);
116029 + tree rhs1 = gimple_assign_rhs1(stmt);
116030 + tree rhs2 = gimple_assign_rhs2(stmt);
116031 +
116032 + if (!is_subtraction_special(stmt))
116033 + return NULL_TREE;
116034 +
116035 + new_rhs1 = expand(visited, caller_node, rhs1);
116036 + new_rhs2 = expand(visited, caller_node, rhs2);
116037 +
116038 + new_rhs1_def_stmt_rhs1 = get_def_stmt_rhs(new_rhs1);
116039 + new_rhs2_def_stmt_rhs1 = get_def_stmt_rhs(new_rhs2);
116040 +
116041 + if (new_rhs1_def_stmt_rhs1 == NULL_TREE || new_rhs2_def_stmt_rhs1 == NULL_TREE)
116042 + return NULL_TREE;
116043 +
116044 + if (!types_compatible_p(TREE_TYPE(new_rhs1_def_stmt_rhs1), TREE_TYPE(new_rhs2_def_stmt_rhs1))) {
116045 + new_rhs1_def_stmt_rhs1 = cast_to_TI_type(stmt, new_rhs1_def_stmt_rhs1);
116046 + new_rhs2_def_stmt_rhs1 = cast_to_TI_type(stmt, new_rhs2_def_stmt_rhs1);
116047 + }
116048 +
116049 + assign = create_binary_assign(MINUS_EXPR, stmt, new_rhs1_def_stmt_rhs1, new_rhs2_def_stmt_rhs1);
116050 + new_lhs = gimple_assign_lhs(assign);
116051 + check_size_overflow(caller_node, assign, TREE_TYPE(new_lhs), new_lhs, rhs1, AFTER_STMT);
116052 +
116053 + return dup_assign(visited, stmt, lhs, new_rhs1, new_rhs2, NULL_TREE);
116054 +}
116055 +
116056 +static bool is_a_neg_overflow(const_gimple stmt, const_tree rhs)
116057 +{
116058 + const_gimple def_stmt;
116059 +
116060 + if (TREE_CODE(rhs) != SSA_NAME)
116061 + return false;
116062 +
116063 + if (gimple_assign_rhs_code(stmt) != PLUS_EXPR)
116064 + return false;
116065 +
116066 + def_stmt = get_def_stmt(rhs);
116067 + if (!is_gimple_assign(def_stmt) || gimple_assign_rhs_code(def_stmt) != BIT_NOT_EXPR)
116068 + return false;
116069 +
116070 + return true;
116071 +}
116072 +
116073 +static tree handle_binary_ops(struct pointer_set_t *visited, struct cgraph_node *caller_node, tree lhs)
116074 +{
116075 + tree rhs1, rhs2, new_lhs;
116076 + gimple def_stmt = get_def_stmt(lhs);
116077 + tree new_rhs1 = NULL_TREE;
116078 + tree new_rhs2 = NULL_TREE;
116079 +
116080 + rhs1 = gimple_assign_rhs1(def_stmt);
116081 + rhs2 = gimple_assign_rhs2(def_stmt);
116082 +
116083 + /* no DImode/TImode division in the 32/64 bit kernel */
116084 + switch (gimple_assign_rhs_code(def_stmt)) {
116085 + case RDIV_EXPR:
116086 + case TRUNC_DIV_EXPR:
116087 + case CEIL_DIV_EXPR:
116088 + case FLOOR_DIV_EXPR:
116089 + case ROUND_DIV_EXPR:
116090 + case TRUNC_MOD_EXPR:
116091 + case CEIL_MOD_EXPR:
116092 + case FLOOR_MOD_EXPR:
116093 + case ROUND_MOD_EXPR:
116094 + case EXACT_DIV_EXPR:
116095 + case POINTER_PLUS_EXPR:
116096 + case BIT_AND_EXPR:
116097 + return create_assign(visited, def_stmt, lhs, AFTER_STMT);
116098 + default:
116099 + break;
116100 + }
116101 +
116102 + new_lhs = handle_integer_truncation(visited, caller_node, lhs);
116103 + if (new_lhs != NULL_TREE)
116104 + return new_lhs;
116105 +
116106 + if (TREE_CODE(rhs1) == SSA_NAME)
116107 + new_rhs1 = expand(visited, caller_node, rhs1);
116108 + if (TREE_CODE(rhs2) == SSA_NAME)
116109 + new_rhs2 = expand(visited, caller_node, rhs2);
116110 +
116111 + if (is_a_neg_overflow(def_stmt, rhs2))
116112 + return handle_intentional_overflow(visited, caller_node, true, def_stmt, new_rhs1, NULL_TREE);
116113 + if (is_a_neg_overflow(def_stmt, rhs1))
116114 + return handle_intentional_overflow(visited, caller_node, true, def_stmt, new_rhs2, new_rhs2);
116115 +
116116 +
116117 + if (is_a_constant_overflow(def_stmt, rhs2))
116118 + return handle_intentional_overflow(visited, caller_node, !is_a_cast_and_const_overflow(rhs1), def_stmt, new_rhs1, NULL_TREE);
116119 + if (is_a_constant_overflow(def_stmt, rhs1))
116120 + return handle_intentional_overflow(visited, caller_node, !is_a_cast_and_const_overflow(rhs2), def_stmt, new_rhs2, new_rhs2);
116121 +
116122 + // the const is between 0 and (signed) MAX
116123 + if (is_gimple_constant(rhs1))
116124 + new_rhs1 = create_assign(visited, def_stmt, rhs1, BEFORE_STMT);
116125 + if (is_gimple_constant(rhs2))
116126 + new_rhs2 = create_assign(visited, def_stmt, rhs2, BEFORE_STMT);
116127 +
116128 + return dup_assign(visited, def_stmt, lhs, new_rhs1, new_rhs2, NULL_TREE);
116129 +}
116130 +
116131 +#if BUILDING_GCC_VERSION >= 4006
116132 +static tree get_new_rhs(struct pointer_set_t *visited, struct cgraph_node *caller_node, tree size_overflow_type, tree rhs)
116133 +{
116134 + if (is_gimple_constant(rhs))
116135 + return cast_a_tree(size_overflow_type, rhs);
116136 + if (TREE_CODE(rhs) != SSA_NAME)
116137 + return NULL_TREE;
116138 + return expand(visited, caller_node, rhs);
116139 +}
116140 +
116141 +static tree handle_ternary_ops(struct pointer_set_t *visited, struct cgraph_node *caller_node, tree lhs)
116142 +{
116143 + tree rhs1, rhs2, rhs3, new_rhs1, new_rhs2, new_rhs3, size_overflow_type;
116144 + gimple def_stmt = get_def_stmt(lhs);
116145 +
116146 + size_overflow_type = get_size_overflow_type(def_stmt, lhs);
116147 +
116148 + rhs1 = gimple_assign_rhs1(def_stmt);
116149 + rhs2 = gimple_assign_rhs2(def_stmt);
116150 + rhs3 = gimple_assign_rhs3(def_stmt);
116151 + new_rhs1 = get_new_rhs(visited, caller_node, size_overflow_type, rhs1);
116152 + new_rhs2 = get_new_rhs(visited, caller_node, size_overflow_type, rhs2);
116153 + new_rhs3 = get_new_rhs(visited, caller_node, size_overflow_type, rhs3);
116154 +
116155 + return dup_assign(visited, def_stmt, lhs, new_rhs1, new_rhs2, new_rhs3);
116156 +}
116157 +#endif
116158 +
116159 +static tree get_size_overflow_type(gimple stmt, const_tree node)
116160 +{
116161 + const_tree type;
116162 + tree new_type;
116163 +
116164 + gcc_assert(node != NULL_TREE);
116165 +
116166 + type = TREE_TYPE(node);
116167 +
116168 + if (get_stmt_flag(stmt) == MY_STMT)
116169 + return TREE_TYPE(node);
116170 +
116171 + switch (TYPE_MODE(type)) {
116172 + case QImode:
116173 + new_type = intHI_type_node;
116174 + break;
116175 + case HImode:
116176 + new_type = intSI_type_node;
116177 + break;
116178 + case SImode:
116179 + new_type = intDI_type_node;
116180 + break;
116181 + case DImode:
116182 + if (LONG_TYPE_SIZE == GET_MODE_BITSIZE(SImode))
116183 + new_type = TYPE_UNSIGNED(type) ? unsigned_intDI_type_node : intDI_type_node;
116184 + else
116185 + new_type = intTI_type_node;
116186 + break;
116187 + case TImode:
116188 + gcc_assert(!TYPE_UNSIGNED(type));
116189 + new_type = intTI_type_node;
116190 + break;
116191 + default:
116192 + debug_tree((tree)node);
116193 + error("%s: unsupported gcc configuration (%qE).", __func__, current_function_decl);
116194 + gcc_unreachable();
116195 + }
116196 +
116197 + if (TYPE_QUALS(type) != 0)
116198 + return build_qualified_type(new_type, TYPE_QUALS(type));
116199 + return new_type;
116200 +}
116201 +
116202 +static tree expand_visited(gimple def_stmt)
116203 +{
116204 + const_gimple next_stmt;
116205 + gimple_stmt_iterator gsi;
116206 + enum gimple_code code = gimple_code(def_stmt);
116207 +
116208 + if (code == GIMPLE_ASM)
116209 + return NULL_TREE;
116210 +
116211 + gsi = gsi_for_stmt(def_stmt);
116212 + gsi_next(&gsi);
116213 +
116214 + if (gimple_code(def_stmt) == GIMPLE_PHI && gsi_end_p(gsi))
116215 + return NULL_TREE;
116216 + gcc_assert(!gsi_end_p(gsi));
116217 + next_stmt = gsi_stmt(gsi);
116218 +
116219 + if (gimple_code(def_stmt) == GIMPLE_PHI && get_stmt_flag((gimple)next_stmt) != MY_STMT)
116220 + return NULL_TREE;
116221 + gcc_assert(get_stmt_flag((gimple)next_stmt) == MY_STMT);
116222 +
116223 + return get_lhs(next_stmt);
116224 +}
116225 +
116226 +static tree expand(struct pointer_set_t *visited, struct cgraph_node *caller_node, tree lhs)
116227 +{
116228 + gimple def_stmt;
116229 +
116230 + def_stmt = get_def_stmt(lhs);
116231 +
116232 + if (!def_stmt || gimple_code(def_stmt) == GIMPLE_NOP)
116233 + return NULL_TREE;
116234 +
116235 + if (get_stmt_flag(def_stmt) == MY_STMT)
116236 + return lhs;
116237 +
116238 + if (pointer_set_contains(visited, def_stmt))
116239 + return expand_visited(def_stmt);
116240 +
116241 + switch (gimple_code(def_stmt)) {
116242 + case GIMPLE_PHI:
116243 + return handle_phi(visited, caller_node, lhs);
116244 + case GIMPLE_CALL:
116245 + case GIMPLE_ASM:
116246 + return create_assign(visited, def_stmt, lhs, AFTER_STMT);
116247 + case GIMPLE_ASSIGN:
116248 + switch (gimple_num_ops(def_stmt)) {
116249 + case 2:
116250 + return handle_unary_ops(visited, caller_node, def_stmt);
116251 + case 3:
116252 + return handle_binary_ops(visited, caller_node, lhs);
116253 +#if BUILDING_GCC_VERSION >= 4006
116254 + case 4:
116255 + return handle_ternary_ops(visited, caller_node, lhs);
116256 +#endif
116257 + }
116258 + default:
116259 + debug_gimple_stmt(def_stmt);
116260 + error("%s: unknown gimple code", __func__);
116261 + gcc_unreachable();
116262 + }
116263 +}
116264 +
116265 +static tree cast_to_orig_type(gimple stmt, const_tree orig_node, tree new_node)
116266 +{
116267 + const_gimple assign;
116268 + tree orig_type = TREE_TYPE(orig_node);
116269 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
116270 +
116271 + assign = build_cast_stmt(orig_type, new_node, CREATE_NEW_VAR, &gsi, BEFORE_STMT, false);
116272 + return gimple_assign_lhs(assign);
116273 +}
116274 +
116275 +static void change_orig_node(struct interesting_node *cur_node, tree new_node)
116276 +{
116277 + void (*set_rhs)(gimple, tree);
116278 + gimple stmt = cur_node->first_stmt;
116279 + const_tree orig_node = cur_node->node;
116280 +
116281 + switch (gimple_code(stmt)) {
116282 + case GIMPLE_RETURN:
116283 + gimple_return_set_retval(stmt, cast_to_orig_type(stmt, orig_node, new_node));
116284 + break;
116285 + case GIMPLE_CALL:
116286 + gimple_call_set_arg(stmt, cur_node->num - 1, cast_to_orig_type(stmt, orig_node, new_node));
116287 + break;
116288 + case GIMPLE_ASSIGN:
116289 + switch (cur_node->num) {
116290 + case 1:
116291 + set_rhs = &gimple_assign_set_rhs1;
116292 + break;
116293 + case 2:
116294 + set_rhs = &gimple_assign_set_rhs2;
116295 + break;
116296 +#if BUILDING_GCC_VERSION >= 4006
116297 + case 3:
116298 + set_rhs = &gimple_assign_set_rhs3;
116299 + break;
116300 +#endif
116301 + default:
116302 + gcc_unreachable();
116303 + }
116304 +
116305 + set_rhs(stmt, cast_to_orig_type(stmt, orig_node, new_node));
116306 + break;
116307 + default:
116308 + debug_gimple_stmt(stmt);
116309 + gcc_unreachable();
116310 + }
116311 +
116312 + update_stmt(stmt);
116313 +}
116314 +
116315 +static unsigned int get_correct_arg_count(unsigned int argnum, const_tree fndecl)
116316 +{
116317 + const struct size_overflow_hash *hash;
116318 + unsigned int new_argnum;
116319 + tree arg;
116320 + const_tree origarg;
116321 +
116322 + if (argnum == 0)
116323 + return argnum;
116324 +
116325 + hash = get_function_hash(fndecl);
116326 + if (hash && hash->param & (1U << argnum))
116327 + return argnum;
116328 +
116329 + if (DECL_EXTERNAL(fndecl))
116330 + return argnum;
116331 +
116332 + origarg = DECL_ARGUMENTS(DECL_ORIGIN(fndecl));
116333 + argnum--;
116334 + while (origarg && argnum) {
116335 + origarg = TREE_CHAIN(origarg);
116336 + argnum--;
116337 + }
116338 + gcc_assert(argnum == 0);
116339 + gcc_assert(origarg != NULL_TREE);
116340 +
116341 + for (arg = DECL_ARGUMENTS(fndecl), new_argnum = 1; arg; arg = TREE_CHAIN(arg), new_argnum++)
116342 + if (operand_equal_p(origarg, arg, 0) || !strcmp(DECL_NAME_POINTER(origarg), DECL_NAME_POINTER(arg)))
116343 + return new_argnum;
116344 +
116345 + return CANNOT_FIND_ARG;
116346 +}
116347 +
116348 +// Don't want to duplicate entries in next_cgraph_node
116349 +static bool is_in_next_cgraph_node(struct next_cgraph_node *head, struct cgraph_node *node, const_tree fndecl, unsigned int num)
116350 +{
116351 + const_tree new_callee_fndecl;
116352 + struct next_cgraph_node *cur_node;
116353 +
116354 + if (fndecl == RET_CHECK)
116355 + new_callee_fndecl = NODE_DECL(node);
116356 + else
116357 + new_callee_fndecl = fndecl;
116358 +
116359 + for (cur_node = head; cur_node; cur_node = cur_node->next) {
116360 + if (!operand_equal_p(NODE_DECL(cur_node->current_function), NODE_DECL(node), 0))
116361 + continue;
116362 + if (!operand_equal_p(cur_node->callee_fndecl, new_callee_fndecl, 0))
116363 + continue;
116364 + if (num == cur_node->num)
116365 + return true;
116366 + }
116367 + return false;
116368 +}
116369 +
116370 +/* Add a next_cgraph_node into the list for handle_function().
116371 + * handle_function() iterates over all the next cgraph nodes and
116372 + * starts the overflow check insertion process.
116373 + */
116374 +static struct next_cgraph_node *create_new_next_cgraph_node(struct next_cgraph_node *head, struct cgraph_node *node, tree fndecl, unsigned int num)
116375 +{
116376 + struct next_cgraph_node *new_node;
116377 +
116378 + if (is_in_next_cgraph_node(head, node, fndecl, num))
116379 + return head;
116380 +
116381 + new_node = (struct next_cgraph_node *)xmalloc(sizeof(*new_node));
116382 + new_node->current_function = node;
116383 + new_node->next = NULL;
116384 + new_node->num = num;
116385 + if (fndecl == RET_CHECK)
116386 + new_node->callee_fndecl = NODE_DECL(node);
116387 + else
116388 + new_node->callee_fndecl = fndecl;
116389 +
116390 + if (!head)
116391 + return new_node;
116392 +
116393 + new_node->next = head;
116394 + return new_node;
116395 +}
116396 +
116397 +static struct next_cgraph_node *create_new_next_cgraph_nodes(struct next_cgraph_node *head, struct cgraph_node *node, unsigned int num)
116398 +{
116399 + struct cgraph_edge *e;
116400 +
116401 + if (num == 0)
116402 + return create_new_next_cgraph_node(head, node, RET_CHECK, num);
116403 +
116404 + for (e = node->callers; e; e = e->next_caller) {
116405 + tree fndecl = gimple_call_fndecl(e->call_stmt);
116406 +
116407 + gcc_assert(fndecl != NULL_TREE);
116408 + head = create_new_next_cgraph_node(head, e->caller, fndecl, num);
116409 + }
116410 +
116411 + return head;
116412 +}
116413 +
116414 +static bool is_a_return_check(const_tree node)
116415 +{
116416 + if (TREE_CODE(node) == FUNCTION_DECL)
116417 + return true;
116418 +
116419 + gcc_assert(TREE_CODE(node) == PARM_DECL);
116420 + return false;
116421 +}
116422 +
116423 +static bool is_in_hash_table(const_tree fndecl, unsigned int num)
116424 +{
116425 + const struct size_overflow_hash *hash;
116426 +
116427 + hash = get_function_hash(fndecl);
116428 + if (hash && (hash->param & (1U << num)))
116429 + return true;
116430 + return false;
116431 +}
116432 +
116433 +struct missing_functions {
116434 + struct missing_functions *next;
116435 + const_tree node;
116436 + tree fndecl;
116437 +};
116438 +
116439 +static struct missing_functions *create_new_missing_function(struct missing_functions *missing_fn_head, tree node)
116440 +{
116441 + struct missing_functions *new_function;
116442 +
116443 + new_function = (struct missing_functions *)xmalloc(sizeof(*new_function));
116444 + new_function->node = node;
116445 + new_function->next = NULL;
116446 +
116447 + if (TREE_CODE(node) == FUNCTION_DECL)
116448 + new_function->fndecl = node;
116449 + else
116450 + new_function->fndecl = current_function_decl;
116451 + gcc_assert(new_function->fndecl);
116452 +
116453 + if (!missing_fn_head)
116454 + return new_function;
116455 +
116456 + new_function->next = missing_fn_head;
116457 + return new_function;
116458 +}
116459 +
116460 +/* Check if the function has a size_overflow attribute or it is in the size_overflow hash table.
116461 + * If the function is missing everywhere then print the missing message into stderr.
116462 + */
116463 +static bool is_missing_function(const_tree orig_fndecl, unsigned int num)
116464 +{
116465 + switch (DECL_FUNCTION_CODE(orig_fndecl)) {
116466 +#if BUILDING_GCC_VERSION >= 4008
116467 + case BUILT_IN_BSWAP16:
116468 +#endif
116469 + case BUILT_IN_BSWAP32:
116470 + case BUILT_IN_BSWAP64:
116471 + case BUILT_IN_EXPECT:
116472 + case BUILT_IN_MEMCMP:
116473 + return false;
116474 + default:
116475 + break;
116476 + }
116477 +
116478 + // skip test.c
116479 + if (strcmp(DECL_NAME_POINTER(current_function_decl), "coolmalloc")) {
116480 + if (lookup_attribute("size_overflow", DECL_ATTRIBUTES(orig_fndecl)))
116481 + warning(0, "unnecessary size_overflow attribute on: %s\n", DECL_NAME_POINTER(orig_fndecl));
116482 + }
116483 +
116484 + if (is_in_hash_table(orig_fndecl, num))
116485 + return false;
116486 +
116487 + print_missing_msg(orig_fndecl, num);
116488 + return true;
116489 +}
116490 +
116491 +// Get the argnum of a function decl, if node is a return then the argnum is 0
116492 +static unsigned int get_function_num(const_tree node, const_tree orig_fndecl)
116493 +{
116494 + if (is_a_return_check(node))
116495 + return 0;
116496 + else
116497 + return find_arg_number_tree(node, orig_fndecl);
116498 +}
116499 +
116500 +/* If the function is missing from the hash table and it is a static function
116501 + * then create a next_cgraph_node from it for handle_function()
116502 + */
116503 +static struct next_cgraph_node *check_missing_overflow_attribute_and_create_next_node(struct next_cgraph_node *cnodes, struct missing_functions *missing_fn_head)
116504 +{
116505 + unsigned int num;
116506 + const_tree orig_fndecl;
116507 + struct cgraph_node *next_node = NULL;
116508 +
116509 + orig_fndecl = DECL_ORIGIN(missing_fn_head->fndecl);
116510 +
116511 + num = get_function_num(missing_fn_head->node, orig_fndecl);
116512 + if (num == CANNOT_FIND_ARG)
116513 + return cnodes;
116514 +
116515 + if (!is_missing_function(orig_fndecl, num))
116516 + return cnodes;
116517 +
116518 + next_node = cgraph_get_node(missing_fn_head->fndecl);
116519 + if (next_node && next_node->local.local)
116520 + cnodes = create_new_next_cgraph_nodes(cnodes, next_node, num);
116521 + return cnodes;
116522 +}
116523 +
116524 +/* Search for missing size_overflow attributes on the last nodes in ipa and collect them
116525 + * into the next_cgraph_node list. They will be the next interesting returns or callees.
116526 + */
116527 +static struct next_cgraph_node *search_overflow_attribute(struct next_cgraph_node *cnodes, struct interesting_node *cur_node)
116528 +{
116529 + unsigned int i;
116530 + tree node;
116531 + struct missing_functions *cur, *missing_fn_head = NULL;
116532 +
116533 +#if BUILDING_GCC_VERSION <= 4007
116534 + FOR_EACH_VEC_ELT(tree, cur_node->last_nodes, i, node) {
116535 +#else
116536 + FOR_EACH_VEC_ELT(*cur_node->last_nodes, i, node) {
116537 +#endif
116538 + switch (TREE_CODE(node)) {
116539 + case PARM_DECL:
116540 + if (TREE_CODE(TREE_TYPE(node)) != INTEGER_TYPE)
116541 + break;
116542 + case FUNCTION_DECL:
116543 + missing_fn_head = create_new_missing_function(missing_fn_head, node);
116544 + break;
116545 + default:
116546 + break;
116547 + }
116548 + }
116549 +
116550 + while (missing_fn_head) {
116551 + cnodes = check_missing_overflow_attribute_and_create_next_node(cnodes, missing_fn_head);
116552 +
116553 + cur = missing_fn_head->next;
116554 + free(missing_fn_head);
116555 + missing_fn_head = cur;
116556 + }
116557 +
116558 + return cnodes;
116559 +}
116560 +
116561 +static void walk_phi_set_conditions(struct pointer_set_t *visited, bool *interesting_conditions, const_tree result)
116562 +{
116563 + gimple phi = get_def_stmt(result);
116564 + unsigned int i, n = gimple_phi_num_args(phi);
116565 +
116566 + pointer_set_insert(visited, phi);
116567 + for (i = 0; i < n; i++) {
116568 + const_tree arg = gimple_phi_arg_def(phi, i);
116569 +
116570 + set_conditions(visited, interesting_conditions, arg);
116571 + }
116572 +}
116573 +
116574 +enum conditions {
116575 + FROM_CONST, NOT_UNARY, CAST
116576 +};
116577 +
116578 +// Search for constants, cast assignments and binary/ternary assignments
116579 +static void set_conditions(struct pointer_set_t *visited, bool *interesting_conditions, const_tree lhs)
116580 +{
116581 + gimple def_stmt = get_def_stmt(lhs);
116582 +
116583 + if (is_gimple_constant(lhs)) {
116584 + interesting_conditions[FROM_CONST] = true;
116585 + return;
116586 + }
116587 +
116588 + if (!def_stmt)
116589 + return;
116590 +
116591 + if (pointer_set_contains(visited, def_stmt))
116592 + return;
116593 +
116594 + switch (gimple_code(def_stmt)) {
116595 + case GIMPLE_NOP:
116596 + case GIMPLE_CALL:
116597 + case GIMPLE_ASM:
116598 + return;
116599 + case GIMPLE_PHI:
116600 + return walk_phi_set_conditions(visited, interesting_conditions, lhs);
116601 + case GIMPLE_ASSIGN:
116602 + if (gimple_num_ops(def_stmt) == 2) {
116603 + const_tree rhs = gimple_assign_rhs1(def_stmt);
116604 +
116605 + if (gimple_assign_cast_p(def_stmt))
116606 + interesting_conditions[CAST] = true;
116607 +
116608 + return set_conditions(visited, interesting_conditions, rhs);
116609 + } else {
116610 + interesting_conditions[NOT_UNARY] = true;
116611 + return;
116612 + }
116613 + default:
116614 + debug_gimple_stmt(def_stmt);
116615 + gcc_unreachable();
116616 + }
116617 +}
116618 +
116619 +// determine whether duplication will be necessary or not.
116620 +static void search_interesting_conditions(struct interesting_node *cur_node, bool *interesting_conditions)
116621 +{
116622 + struct pointer_set_t *visited;
116623 +
116624 + if (gimple_assign_cast_p(cur_node->first_stmt))
116625 + interesting_conditions[CAST] = true;
116626 + else if (is_gimple_assign(cur_node->first_stmt) && gimple_num_ops(cur_node->first_stmt) > 2)
116627 + interesting_conditions[NOT_UNARY] = true;
116628 +
116629 + visited = pointer_set_create();
116630 + set_conditions(visited, interesting_conditions, cur_node->node);
116631 + pointer_set_destroy(visited);
116632 +}
116633 +
116634 +// Remove the size_overflow asm stmt and create an assignment from the input and output of the asm
116635 +static void replace_size_overflow_asm_with_assign(gimple asm_stmt, tree lhs, tree rhs)
116636 +{
116637 + gimple assign;
116638 + gimple_stmt_iterator gsi;
116639 +
116640 + // already removed
116641 + if (gimple_bb(asm_stmt) == NULL)
116642 + return;
116643 + gsi = gsi_for_stmt(asm_stmt);
116644 +
116645 + assign = gimple_build_assign(lhs, rhs);
116646 + gsi_insert_before(&gsi, assign, GSI_SAME_STMT);
116647 + SSA_NAME_DEF_STMT(lhs) = assign;
116648 +
116649 + gsi_remove(&gsi, true);
116650 +}
116651 +
116652 +// Get the field decl of a component ref for intentional_overflow checking
116653 +static const_tree search_field_decl(const_tree comp_ref)
116654 +{
116655 + const_tree field = NULL_TREE;
116656 + unsigned int i, len = TREE_OPERAND_LENGTH(comp_ref);
116657 +
116658 + for (i = 0; i < len; i++) {
116659 + field = TREE_OPERAND(comp_ref, i);
116660 + if (TREE_CODE(field) == FIELD_DECL)
116661 + break;
116662 + }
116663 + gcc_assert(TREE_CODE(field) == FIELD_DECL);
116664 + return field;
116665 +}
116666 +
116667 +/* Get the fndecl of an interesting stmt, the fndecl is the caller function if the interesting
116668 + * stmt is a return otherwise it is the callee function.
116669 + */
116670 +static const_tree get_interesting_orig_fndecl(const_gimple stmt, unsigned int argnum)
116671 +{
116672 + const_tree fndecl;
116673 +
116674 + if (argnum == 0)
116675 + fndecl = current_function_decl;
116676 + else
116677 + fndecl = gimple_call_fndecl(stmt);
116678 +
116679 + if (fndecl == NULL_TREE)
116680 + return NULL_TREE;
116681 +
116682 + return DECL_ORIGIN(fndecl);
116683 +}
116684 +
116685 +/* Get the param of the intentional_overflow attribute.
116686 + * * 0: MARK_NOT_INTENTIONAL
116687 + * * 1..MAX_PARAM: MARK_YES
116688 + * * -1: MARK_TURN_OFF
116689 + */
116690 +static tree get_attribute_param(const_tree decl)
116691 +{
116692 + const_tree attr;
116693 +
116694 + if (decl == NULL_TREE)
116695 + return NULL_TREE;
116696 +
116697 + attr = lookup_attribute("intentional_overflow", DECL_ATTRIBUTES(decl));
116698 + if (!attr || !TREE_VALUE(attr))
116699 + return NULL_TREE;
116700 +
116701 + return TREE_VALUE(attr);
116702 +}
116703 +
116704 +// MARK_TURN_OFF
116705 +static bool is_turn_off_intentional_attr(const_tree decl)
116706 +{
116707 + const_tree param_head;
116708 +
116709 + param_head = get_attribute_param(decl);
116710 + if (param_head == NULL_TREE)
116711 + return false;
116712 +
116713 + if (TREE_INT_CST_HIGH(TREE_VALUE(param_head)) == -1)
116714 + return true;
116715 + return false;
116716 +}
116717 +
116718 +// MARK_NOT_INTENTIONAL
116719 +static bool is_end_intentional_intentional_attr(const_tree decl, unsigned int argnum)
116720 +{
116721 + const_tree param_head;
116722 +
116723 + if (argnum == 0)
116724 + return false;
116725 +
116726 + param_head = get_attribute_param(decl);
116727 + if (param_head == NULL_TREE)
116728 + return false;
116729 +
116730 + if (!TREE_INT_CST_LOW(TREE_VALUE(param_head)))
116731 + return true;
116732 + return false;
116733 +}
116734 +
116735 +// MARK_YES
116736 +static bool is_yes_intentional_attr(const_tree decl, unsigned int argnum)
116737 +{
116738 + tree param, param_head;
116739 +
116740 + if (argnum == 0)
116741 + return false;
116742 +
116743 + param_head = get_attribute_param(decl);
116744 + for (param = param_head; param; param = TREE_CHAIN(param))
116745 + if (argnum == TREE_INT_CST_LOW(TREE_VALUE(param)))
116746 + return true;
116747 + return false;
116748 +}
116749 +
116750 +static const char *get_asm_string(const_gimple stmt)
116751 +{
116752 + if (!stmt)
116753 + return NULL;
116754 + if (gimple_code(stmt) != GIMPLE_ASM)
116755 + return NULL;
116756 +
116757 + return gimple_asm_string(stmt);
116758 +}
116759 +
116760 +static bool is_size_overflow_intentional_asm_turn_off(const_gimple stmt)
116761 +{
116762 + const char *str;
116763 +
116764 + str = get_asm_string(stmt);
116765 + if (!str)
116766 + return false;
116767 + return !strncmp(str, TURN_OFF_ASM_STR, sizeof(TURN_OFF_ASM_STR) - 1);
116768 +}
116769 +
116770 +static bool is_size_overflow_intentional_asm_yes(const_gimple stmt)
116771 +{
116772 + const char *str;
116773 +
116774 + str = get_asm_string(stmt);
116775 + if (!str)
116776 + return false;
116777 + return !strncmp(str, YES_ASM_STR, sizeof(YES_ASM_STR) - 1);
116778 +}
116779 +
116780 +static bool is_size_overflow_asm(const_gimple stmt)
116781 +{
116782 + const char *str;
116783 +
116784 + str = get_asm_string(stmt);
116785 + if (!str)
116786 + return false;
116787 + return !strncmp(str, OK_ASM_STR, sizeof(OK_ASM_STR) - 1);
116788 +}
116789 +
116790 +static void print_missing_intentional(enum mark callee_attr, enum mark caller_attr, const_tree decl, unsigned int argnum)
116791 +{
116792 + location_t loc;
116793 +
116794 + if (caller_attr == MARK_NO || caller_attr == MARK_NOT_INTENTIONAL || caller_attr == MARK_TURN_OFF)
116795 + return;
116796 +
116797 + if (callee_attr == MARK_NOT_INTENTIONAL || callee_attr == MARK_YES)
116798 + return;
116799 +
116800 + loc = DECL_SOURCE_LOCATION(decl);
116801 + inform(loc, "The intentional_overflow attribute is missing from +%s+%u+", DECL_NAME_POINTER(decl), argnum);
116802 +}
116803 +
116804 +/* Get the type of the intentional_overflow attribute of a node
116805 + * * MARK_TURN_OFF
116806 + * * MARK_YES
116807 + * * MARK_NO
116808 + * * MARK_NOT_INTENTIONAL
116809 + */
116810 +static enum mark get_intentional_attr_type(const_tree node)
116811 +{
116812 + const_tree cur_decl;
116813 +
116814 + if (node == NULL_TREE)
116815 + return MARK_NO;
116816 +
116817 + switch (TREE_CODE(node)) {
116818 + case COMPONENT_REF:
116819 + cur_decl = search_field_decl(node);
116820 + if (is_turn_off_intentional_attr(cur_decl))
116821 + return MARK_TURN_OFF;
116822 + if (is_end_intentional_intentional_attr(cur_decl, 1))
116823 + return MARK_YES;
116824 + break;
116825 + case PARM_DECL: {
116826 + unsigned int argnum;
116827 +
116828 + cur_decl = DECL_ORIGIN(current_function_decl);
116829 + argnum = find_arg_number_tree(node, cur_decl);
116830 + if (argnum == CANNOT_FIND_ARG)
116831 + return MARK_NO;
116832 + if (is_yes_intentional_attr(cur_decl, argnum))
116833 + return MARK_YES;
116834 + if (is_end_intentional_intentional_attr(cur_decl, argnum))
116835 + return MARK_NOT_INTENTIONAL;
116836 + break;
116837 + }
116838 + case FUNCTION_DECL:
116839 + if (is_turn_off_intentional_attr(DECL_ORIGIN(node)))
116840 + return MARK_TURN_OFF;
116841 + break;
116842 + default:
116843 + break;
116844 + }
116845 + return MARK_NO;
116846 +}
116847 +
116848 +// Search for the intentional_overflow attribute on the last nodes
116849 +static enum mark search_last_nodes_intentional(struct interesting_node *cur_node)
116850 +{
116851 + unsigned int i;
116852 + tree last_node;
116853 + enum mark mark = MARK_NO;
116854 +
116855 +#if BUILDING_GCC_VERSION <= 4007
116856 + FOR_EACH_VEC_ELT(tree, cur_node->last_nodes, i, last_node) {
116857 +#else
116858 + FOR_EACH_VEC_ELT(*cur_node->last_nodes, i, last_node) {
116859 +#endif
116860 + mark = get_intentional_attr_type(last_node);
116861 + if (mark != MARK_NO)
116862 + break;
116863 + }
116864 + return mark;
116865 +}
116866 +
116867 +/* Check the intentional kind of size_overflow asm stmt (created by the gimple pass) and
116868 + * set the appropriate intentional_overflow type. Delete the asm stmt in the end.
116869 + */
116870 +static bool is_intentional_attribute_from_gimple(struct interesting_node *cur_node)
116871 +{
116872 + if (!cur_node->intentional_mark_from_gimple)
116873 + return false;
116874 +
116875 + if (is_size_overflow_intentional_asm_yes(cur_node->intentional_mark_from_gimple))
116876 + cur_node->intentional_attr_cur_fndecl = MARK_YES;
116877 + else
116878 + cur_node->intentional_attr_cur_fndecl = MARK_TURN_OFF;
116879 +
116880 + // skip param decls
116881 + if (gimple_asm_noutputs(cur_node->intentional_mark_from_gimple) == 0)
116882 + return true;
116883 + return true;
116884 +}
116885 +
116886 +/* Search intentional_overflow attribute on caller and on callee too.
116887 + * 0</MARK_YES: no dup, search size_overflow and intentional_overflow attributes
116888 + * 0/MARK_NOT_INTENTIONAL: no dup, search size_overflow attribute (int)
116889 + * -1/MARK_TURN_OFF: no dup, no search, current_function_decl -> no dup
116890 +*/
116891 +static void check_intentional_attribute_ipa(struct interesting_node *cur_node)
116892 +{
116893 + const_tree fndecl;
116894 +
116895 + if (is_intentional_attribute_from_gimple(cur_node))
116896 + return;
116897 +
116898 + if (is_turn_off_intentional_attr(DECL_ORIGIN(current_function_decl))) {
116899 + cur_node->intentional_attr_cur_fndecl = MARK_TURN_OFF;
116900 + return;
116901 + }
116902 +
116903 + if (gimple_code(cur_node->first_stmt) == GIMPLE_ASM) {
116904 + cur_node->intentional_attr_cur_fndecl = MARK_NOT_INTENTIONAL;
116905 + return;
116906 + }
116907 +
116908 + if (gimple_code(cur_node->first_stmt) == GIMPLE_ASSIGN)
116909 + return;
116910 +
116911 + fndecl = get_interesting_orig_fndecl(cur_node->first_stmt, cur_node->num);
116912 + if (is_turn_off_intentional_attr(fndecl)) {
116913 + cur_node->intentional_attr_decl = MARK_TURN_OFF;
116914 + return;
116915 + }
116916 +
116917 + if (is_end_intentional_intentional_attr(fndecl, cur_node->num))
116918 + cur_node->intentional_attr_decl = MARK_NOT_INTENTIONAL;
116919 + else if (is_yes_intentional_attr(fndecl, cur_node->num))
116920 + cur_node->intentional_attr_decl = MARK_YES;
116921 +
116922 + cur_node->intentional_attr_cur_fndecl = search_last_nodes_intentional(cur_node);
116923 + print_missing_intentional(cur_node->intentional_attr_decl, cur_node->intentional_attr_cur_fndecl, cur_node->fndecl, cur_node->num);
116924 +}
116925 +
116926 +// e.g., 3.8.2, 64, arch/x86/ia32/ia32_signal.c copy_siginfo_from_user32(): compat_ptr() u32 max
116927 +static bool skip_asm(const_tree arg)
116928 +{
116929 + gimple def_stmt = get_def_stmt(arg);
116930 +
116931 + if (!def_stmt || !gimple_assign_cast_p(def_stmt))
116932 + return false;
116933 +
116934 + def_stmt = get_def_stmt(gimple_assign_rhs1(def_stmt));
116935 + return def_stmt && gimple_code(def_stmt) == GIMPLE_ASM;
116936 +}
116937 +
116938 +static void walk_use_def_phi(struct pointer_set_t *visited, struct interesting_node *cur_node, tree result)
116939 +{
116940 + gimple phi = get_def_stmt(result);
116941 + unsigned int i, n = gimple_phi_num_args(phi);
116942 +
116943 + pointer_set_insert(visited, phi);
116944 + for (i = 0; i < n; i++) {
116945 + tree arg = gimple_phi_arg_def(phi, i);
116946 +
116947 + walk_use_def(visited, cur_node, arg);
116948 + }
116949 +}
116950 +
116951 +static void walk_use_def_binary(struct pointer_set_t *visited, struct interesting_node *cur_node, tree lhs)
116952 +{
116953 + gimple def_stmt = get_def_stmt(lhs);
116954 + tree rhs1, rhs2;
116955 +
116956 + rhs1 = gimple_assign_rhs1(def_stmt);
116957 + rhs2 = gimple_assign_rhs2(def_stmt);
116958 +
116959 + walk_use_def(visited, cur_node, rhs1);
116960 + walk_use_def(visited, cur_node, rhs2);
116961 +}
116962 +
116963 +static void insert_last_node(struct interesting_node *cur_node, tree node)
116964 +{
116965 + unsigned int i;
116966 + tree element;
116967 + enum tree_code code;
116968 +
116969 + gcc_assert(node != NULL_TREE);
116970 +
116971 + if (is_gimple_constant(node))
116972 + return;
116973 +
116974 + code = TREE_CODE(node);
116975 + if (code == VAR_DECL) {
116976 + node = DECL_ORIGIN(node);
116977 + code = TREE_CODE(node);
116978 + }
116979 +
116980 + if (code != PARM_DECL && code != FUNCTION_DECL && code != COMPONENT_REF)
116981 + return;
116982 +
116983 +#if BUILDING_GCC_VERSION <= 4007
116984 + FOR_EACH_VEC_ELT(tree, cur_node->last_nodes, i, element) {
116985 +#else
116986 + FOR_EACH_VEC_ELT(*cur_node->last_nodes, i, element) {
116987 +#endif
116988 + if (operand_equal_p(node, element, 0))
116989 + return;
116990 + }
116991 +
116992 +#if BUILDING_GCC_VERSION <= 4007
116993 + gcc_assert(VEC_length(tree, cur_node->last_nodes) < VEC_LEN);
116994 + VEC_safe_push(tree, gc, cur_node->last_nodes, node);
116995 +#else
116996 + gcc_assert(cur_node->last_nodes->length() < VEC_LEN);
116997 + vec_safe_push(cur_node->last_nodes, node);
116998 +#endif
116999 +}
117000 +
117001 +// a size_overflow asm stmt in the control flow doesn't stop the recursion
117002 +static void handle_asm_stmt(struct pointer_set_t *visited, struct interesting_node *cur_node, tree lhs, const_gimple stmt)
117003 +{
117004 + if (!is_size_overflow_asm(stmt))
117005 + walk_use_def(visited, cur_node, SSA_NAME_VAR(lhs));
117006 +}
117007 +
117008 +/* collect the parm_decls and fndecls (for checking a missing size_overflow attribute (ret or arg) or intentional_overflow)
117009 + * and component refs (for checking the intentional_overflow attribute).
117010 + */
117011 +static void walk_use_def(struct pointer_set_t *visited, struct interesting_node *cur_node, tree lhs)
117012 +{
117013 + const_gimple def_stmt;
117014 +
117015 + if (TREE_CODE(lhs) != SSA_NAME) {
117016 + insert_last_node(cur_node, lhs);
117017 + return;
117018 + }
117019 +
117020 + def_stmt = get_def_stmt(lhs);
117021 + if (!def_stmt)
117022 + return;
117023 +
117024 + if (pointer_set_insert(visited, def_stmt))
117025 + return;
117026 +
117027 + switch (gimple_code(def_stmt)) {
117028 + case GIMPLE_NOP:
117029 + return walk_use_def(visited, cur_node, SSA_NAME_VAR(lhs));
117030 + case GIMPLE_ASM:
117031 + return handle_asm_stmt(visited, cur_node, lhs, def_stmt);
117032 + case GIMPLE_CALL: {
117033 + tree fndecl = gimple_call_fndecl(def_stmt);
117034 +
117035 + if (fndecl == NULL_TREE)
117036 + return;
117037 + insert_last_node(cur_node, fndecl);
117038 + return;
117039 + }
117040 + case GIMPLE_PHI:
117041 + return walk_use_def_phi(visited, cur_node, lhs);
117042 + case GIMPLE_ASSIGN:
117043 + switch (gimple_num_ops(def_stmt)) {
117044 + case 2:
117045 + return walk_use_def(visited, cur_node, gimple_assign_rhs1(def_stmt));
117046 + case 3:
117047 + return walk_use_def_binary(visited, cur_node, lhs);
117048 + }
117049 + default:
117050 + debug_gimple_stmt((gimple)def_stmt);
117051 + error("%s: unknown gimple code", __func__);
117052 + gcc_unreachable();
117053 + }
117054 +}
117055 +
117056 +// Collect all the last nodes for checking the intentional_overflow and size_overflow attributes
117057 +static void set_last_nodes(struct interesting_node *cur_node)
117058 +{
117059 + struct pointer_set_t *visited;
117060 +
117061 + visited = pointer_set_create();
117062 + walk_use_def(visited, cur_node, cur_node->node);
117063 + pointer_set_destroy(visited);
117064 +}
117065 +
117066 +enum precond {
117067 + NO_ATTRIBUTE_SEARCH, NO_CHECK_INSERT, NONE
117068 +};
117069 +
117070 +/* 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.
117071 + * There is only missing size_overflow attribute checking if the intentional_overflow attribute is the mark_no type.
117072 + * Stmt duplication is unnecessary if there are no binary/ternary assignements or if the unary assignment isn't a cast.
117073 + * 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.
117074 + */
117075 +static enum precond check_preconditions(struct interesting_node *cur_node)
117076 +{
117077 + bool interesting_conditions[3] = {false, false, false};
117078 +
117079 + set_last_nodes(cur_node);
117080 +
117081 + check_intentional_attribute_ipa(cur_node);
117082 + if (cur_node->intentional_attr_decl == MARK_TURN_OFF || cur_node->intentional_attr_cur_fndecl == MARK_TURN_OFF)
117083 + return NO_ATTRIBUTE_SEARCH;
117084 +
117085 + search_interesting_conditions(cur_node, interesting_conditions);
117086 +
117087 + // error code
117088 + if (interesting_conditions[CAST] && interesting_conditions[FROM_CONST] && !interesting_conditions[NOT_UNARY])
117089 + return NO_ATTRIBUTE_SEARCH;
117090 +
117091 + // unnecessary overflow check
117092 + if (!interesting_conditions[CAST] && !interesting_conditions[NOT_UNARY])
117093 + return NO_CHECK_INSERT;
117094 +
117095 + if (cur_node->intentional_attr_cur_fndecl != MARK_NO)
117096 + return NO_CHECK_INSERT;
117097 +
117098 + return NONE;
117099 +}
117100 +
117101 +/* This function calls the main recursion function (expand) that duplicates the stmts. Before that it checks the intentional_overflow attribute and asm stmts,
117102 + * 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
117103 + * in the original stmt (first stmt) and it inserts the overflow check for the arg of the callee or for the return value.
117104 + */
117105 +static struct next_cgraph_node *handle_interesting_stmt(struct next_cgraph_node *cnodes, struct interesting_node *cur_node, struct cgraph_node *caller_node)
117106 +{
117107 + enum precond ret;
117108 + struct pointer_set_t *visited;
117109 + tree new_node, orig_node = cur_node->node;
117110 +
117111 + ret = check_preconditions(cur_node);
117112 + if (ret == NO_ATTRIBUTE_SEARCH)
117113 + return cnodes;
117114 +
117115 + cnodes = search_overflow_attribute(cnodes, cur_node);
117116 +
117117 + if (ret == NO_CHECK_INSERT)
117118 + return cnodes;
117119 +
117120 + visited = pointer_set_create();
117121 + new_node = expand(visited, caller_node, orig_node);
117122 + pointer_set_destroy(visited);
117123 +
117124 + if (new_node == NULL_TREE)
117125 + return cnodes;
117126 +
117127 + change_orig_node(cur_node, new_node);
117128 + check_size_overflow(caller_node, cur_node->first_stmt, TREE_TYPE(new_node), new_node, orig_node, BEFORE_STMT);
117129 +
117130 + return cnodes;
117131 +}
117132 +
117133 +// Check visited interesting nodes.
117134 +static bool is_in_interesting_node(struct interesting_node *head, const_gimple first_stmt, const_tree node, unsigned int num)
117135 +{
117136 + struct interesting_node *cur;
117137 +
117138 + for (cur = head; cur; cur = cur->next) {
117139 + if (!operand_equal_p(node, cur->node, 0))
117140 + continue;
117141 + if (num != cur->num)
117142 + continue;
117143 + if (first_stmt == cur->first_stmt)
117144 + return true;
117145 + }
117146 + return false;
117147 +}
117148 +
117149 +/* Create an interesting node. The ipa pass starts to duplicate from these stmts.
117150 + 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
117151 + 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
117152 + the intentional_overflow attribute check. They are collected by set_last_nodes().
117153 + num: arg count of a call stmt or 0 when it is a ret
117154 + node: the recursion starts from here, it is a call arg or a return value
117155 + 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.
117156 + intentional_attr_decl: intentional_overflow attribute of the callee function
117157 + intentional_attr_cur_fndecl: intentional_overflow attribute of the caller function
117158 + intentional_mark_from_gimple: the intentional overflow type of size_overflow asm stmt from gimple if it exists
117159 + */
117160 +static struct interesting_node *create_new_interesting_node(struct interesting_node *head, gimple first_stmt, tree node, unsigned int num, gimple asm_stmt)
117161 +{
117162 + struct interesting_node *new_node;
117163 + tree fndecl;
117164 + enum gimple_code code;
117165 +
117166 + gcc_assert(node != NULL_TREE);
117167 + code = gimple_code(first_stmt);
117168 + gcc_assert(code == GIMPLE_CALL || code == GIMPLE_ASM || code == GIMPLE_ASSIGN || code == GIMPLE_RETURN);
117169 +
117170 + if (num == CANNOT_FIND_ARG)
117171 + return head;
117172 +
117173 + if (skip_types(node))
117174 + return head;
117175 +
117176 + if (skip_asm(node))
117177 + return head;
117178 +
117179 + if (is_gimple_call(first_stmt))
117180 + fndecl = gimple_call_fndecl(first_stmt);
117181 + else
117182 + fndecl = current_function_decl;
117183 +
117184 + if (fndecl == NULL_TREE)
117185 + return head;
117186 +
117187 + if (is_in_interesting_node(head, first_stmt, node, num))
117188 + return head;
117189 +
117190 + new_node = (struct interesting_node *)xmalloc(sizeof(*new_node));
117191 +
117192 + new_node->next = NULL;
117193 + new_node->first_stmt = first_stmt;
117194 +#if BUILDING_GCC_VERSION <= 4007
117195 + new_node->last_nodes = VEC_alloc(tree, gc, VEC_LEN);
117196 +#else
117197 + vec_alloc(new_node->last_nodes, VEC_LEN);
117198 +#endif
117199 + new_node->num = num;
117200 + new_node->node = node;
117201 + new_node->fndecl = fndecl;
117202 + new_node->intentional_attr_decl = MARK_NO;
117203 + new_node->intentional_attr_cur_fndecl = MARK_NO;
117204 + new_node->intentional_mark_from_gimple = asm_stmt;
117205 +
117206 + if (!head)
117207 + return new_node;
117208 +
117209 + new_node->next = head;
117210 + return new_node;
117211 +}
117212 +
117213 +/* 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).
117214 + * If the ret stmt is in the next cgraph node list then it's an interesting ret.
117215 + */
117216 +static struct interesting_node *handle_stmt_by_cgraph_nodes_ret(struct interesting_node *head, gimple stmt, struct next_cgraph_node *next_node)
117217 +{
117218 + struct next_cgraph_node *cur_node;
117219 + tree ret = gimple_return_retval(stmt);
117220 +
117221 + if (ret == NULL_TREE)
117222 + return head;
117223 +
117224 + for (cur_node = next_node; cur_node; cur_node = cur_node->next) {
117225 + if (!operand_equal_p(cur_node->callee_fndecl, DECL_ORIGIN(current_function_decl), 0))
117226 + continue;
117227 + if (cur_node->num == 0)
117228 + head = create_new_interesting_node(head, stmt, ret, 0, NOT_INTENTIONAL_ASM);
117229 + }
117230 +
117231 + return head;
117232 +}
117233 +
117234 +/* 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).
117235 + * If the call stmt is in the next cgraph node list then it's an interesting call.
117236 + */
117237 +static struct interesting_node *handle_stmt_by_cgraph_nodes_call(struct interesting_node *head, gimple stmt, struct next_cgraph_node *next_node)
117238 +{
117239 + unsigned int argnum;
117240 + tree arg;
117241 + const_tree fndecl;
117242 + struct next_cgraph_node *cur_node;
117243 +
117244 + fndecl = gimple_call_fndecl(stmt);
117245 + if (fndecl == NULL_TREE)
117246 + return head;
117247 +
117248 + for (cur_node = next_node; cur_node; cur_node = cur_node->next) {
117249 + if (!operand_equal_p(cur_node->callee_fndecl, fndecl, 0))
117250 + continue;
117251 + argnum = get_correct_arg_count(cur_node->num, fndecl);
117252 + gcc_assert(argnum != CANNOT_FIND_ARG);
117253 + if (argnum == 0)
117254 + continue;
117255 +
117256 + arg = gimple_call_arg(stmt, argnum - 1);
117257 + head = create_new_interesting_node(head, stmt, arg, argnum, NOT_INTENTIONAL_ASM);
117258 + }
117259 +
117260 + return head;
117261 +}
117262 +
117263 +static unsigned int check_ops(const_tree orig_node, const_tree node, unsigned int ret_count)
117264 +{
117265 + if (!operand_equal_p(orig_node, node, 0))
117266 + return WRONG_NODE;
117267 + if (skip_types(node))
117268 + return WRONG_NODE;
117269 + return ret_count;
117270 +}
117271 +
117272 +// Get the index of the rhs node in an assignment
117273 +static unsigned int get_assign_ops_count(const_gimple stmt, tree node)
117274 +{
117275 + const_tree rhs1, rhs2;
117276 + unsigned int ret;
117277 +
117278 + gcc_assert(stmt);
117279 + gcc_assert(is_gimple_assign(stmt));
117280 +
117281 + rhs1 = gimple_assign_rhs1(stmt);
117282 + gcc_assert(rhs1 != NULL_TREE);
117283 +
117284 + switch (gimple_num_ops(stmt)) {
117285 + case 2:
117286 + return check_ops(node, rhs1, 1);
117287 + case 3:
117288 + ret = check_ops(node, rhs1, 1);
117289 + if (ret != WRONG_NODE)
117290 + return ret;
117291 +
117292 + rhs2 = gimple_assign_rhs2(stmt);
117293 + gcc_assert(rhs2 != NULL_TREE);
117294 + return check_ops(node, rhs2, 2);
117295 + default:
117296 + gcc_unreachable();
117297 + }
117298 +}
117299 +
117300 +// Find the correct arg number of a call stmt. It is needed when the interesting function is a cloned function.
117301 +static unsigned int find_arg_number_gimple(const_tree arg, const_gimple stmt)
117302 +{
117303 + unsigned int i;
117304 +
117305 + if (gimple_call_fndecl(stmt) == NULL_TREE)
117306 + return CANNOT_FIND_ARG;
117307 +
117308 + for (i = 0; i < gimple_call_num_args(stmt); i++) {
117309 + tree node;
117310 +
117311 + node = gimple_call_arg(stmt, i);
117312 + if (!operand_equal_p(arg, node, 0))
117313 + continue;
117314 + if (!skip_types(node))
117315 + return i + 1;
117316 + }
117317 +
117318 + return CANNOT_FIND_ARG;
117319 +}
117320 +
117321 +/* starting from the size_overflow asm stmt collect interesting stmts. They can be
117322 + * any of return, call or assignment stmts (because of inlining).
117323 + */
117324 +static struct interesting_node *get_interesting_ret_or_call(struct pointer_set_t *visited, struct interesting_node *head, tree node, gimple intentional_asm)
117325 +{
117326 + use_operand_p use_p;
117327 + imm_use_iterator imm_iter;
117328 + unsigned int argnum;
117329 +
117330 + gcc_assert(TREE_CODE(node) == SSA_NAME);
117331 +
117332 + if (pointer_set_insert(visited, node))
117333 + return head;
117334 +
117335 + FOR_EACH_IMM_USE_FAST(use_p, imm_iter, node) {
117336 + gimple stmt = USE_STMT(use_p);
117337 +
117338 + if (stmt == NULL)
117339 + return head;
117340 + if (is_gimple_debug(stmt))
117341 + continue;
117342 +
117343 + switch (gimple_code(stmt)) {
117344 + case GIMPLE_CALL:
117345 + argnum = find_arg_number_gimple(node, stmt);
117346 + head = create_new_interesting_node(head, stmt, node, argnum, intentional_asm);
117347 + break;
117348 + case GIMPLE_RETURN:
117349 + head = create_new_interesting_node(head, stmt, node, 0, intentional_asm);
117350 + break;
117351 + case GIMPLE_ASSIGN:
117352 + argnum = get_assign_ops_count(stmt, node);
117353 + head = create_new_interesting_node(head, stmt, node, argnum, intentional_asm);
117354 + break;
117355 + case GIMPLE_PHI: {
117356 + tree result = gimple_phi_result(stmt);
117357 + head = get_interesting_ret_or_call(visited, head, result, intentional_asm);
117358 + break;
117359 + }
117360 + case GIMPLE_ASM:
117361 + if (gimple_asm_noutputs(stmt) != 0)
117362 + break;
117363 + if (!is_size_overflow_asm(stmt))
117364 + break;
117365 + head = create_new_interesting_node(head, stmt, node, 1, intentional_asm);
117366 + break;
117367 + case GIMPLE_COND:
117368 + case GIMPLE_SWITCH:
117369 + break;
117370 + default:
117371 + debug_gimple_stmt(stmt);
117372 + gcc_unreachable();
117373 + break;
117374 + }
117375 + }
117376 + return head;
117377 +}
117378 +
117379 +static void remove_size_overflow_asm(gimple stmt)
117380 +{
117381 + gimple_stmt_iterator gsi;
117382 + tree input, output;
117383 +
117384 + if (!is_size_overflow_asm(stmt))
117385 + return;
117386 +
117387 + if (gimple_asm_noutputs(stmt) == 0) {
117388 + gsi = gsi_for_stmt(stmt);
117389 + ipa_remove_stmt_references(cgraph_get_create_node(current_function_decl), stmt);
117390 + gsi_remove(&gsi, true);
117391 + return;
117392 + }
117393 +
117394 + input = gimple_asm_input_op(stmt, 0);
117395 + output = gimple_asm_output_op(stmt, 0);
117396 + replace_size_overflow_asm_with_assign(stmt, TREE_VALUE(output), TREE_VALUE(input));
117397 +}
117398 +
117399 +/* handle the size_overflow asm stmts from the gimple pass and collect the interesting stmts.
117400 + * If the asm stmt is a parm_decl kind (noutputs == 0) then remove it.
117401 + * If it is a simple asm stmt then replace it with an assignment from the asm input to the asm output.
117402 + */
117403 +static struct interesting_node *handle_stmt_by_size_overflow_asm(gimple stmt, struct interesting_node *head)
117404 +{
117405 + const_tree output;
117406 + struct pointer_set_t *visited;
117407 + gimple intentional_asm = NOT_INTENTIONAL_ASM;
117408 +
117409 + if (!is_size_overflow_asm(stmt))
117410 + return head;
117411 +
117412 + if (is_size_overflow_intentional_asm_yes(stmt) || is_size_overflow_intentional_asm_turn_off(stmt))
117413 + intentional_asm = stmt;
117414 +
117415 + gcc_assert(gimple_asm_ninputs(stmt) == 1);
117416 +
117417 + if (gimple_asm_noutputs(stmt) == 0 && is_size_overflow_intentional_asm_turn_off(stmt))
117418 + return head;
117419 +
117420 + if (gimple_asm_noutputs(stmt) == 0) {
117421 + const_tree input;
117422 +
117423 + if (!is_size_overflow_intentional_asm_turn_off(stmt))
117424 + return head;
117425 +
117426 + input = gimple_asm_input_op(stmt, 0);
117427 + remove_size_overflow_asm(stmt);
117428 + if (is_gimple_constant(TREE_VALUE(input)))
117429 + return head;
117430 + visited = pointer_set_create();
117431 + head = get_interesting_ret_or_call(visited, head, TREE_VALUE(input), intentional_asm);
117432 + pointer_set_destroy(visited);
117433 + return head;
117434 + }
117435 +
117436 + if (!is_size_overflow_intentional_asm_yes(stmt) && !is_size_overflow_intentional_asm_turn_off(stmt))
117437 + remove_size_overflow_asm(stmt);
117438 +
117439 + visited = pointer_set_create();
117440 + output = gimple_asm_output_op(stmt, 0);
117441 + head = get_interesting_ret_or_call(visited, head, TREE_VALUE(output), intentional_asm);
117442 + pointer_set_destroy(visited);
117443 + return head;
117444 +}
117445 +
117446 +/* Iterate over all the stmts of a function and look for the size_overflow asm stmts (they were created in the gimple pass)
117447 + * or a call stmt or a return stmt and store them in the interesting_node list
117448 + */
117449 +static struct interesting_node *collect_interesting_stmts(struct next_cgraph_node *next_node)
117450 +{
117451 + basic_block bb;
117452 + struct interesting_node *head = NULL;
117453 +
117454 + FOR_ALL_BB_FN(bb, cfun) {
117455 + gimple_stmt_iterator gsi;
117456 +
117457 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
117458 + enum gimple_code code;
117459 + gimple stmt = gsi_stmt(gsi);
117460 +
117461 + code = gimple_code(stmt);
117462 +
117463 + if (code == GIMPLE_ASM)
117464 + head = handle_stmt_by_size_overflow_asm(stmt, head);
117465 +
117466 + if (!next_node)
117467 + continue;
117468 + if (code == GIMPLE_CALL)
117469 + head = handle_stmt_by_cgraph_nodes_call(head, stmt, next_node);
117470 + if (code == GIMPLE_RETURN)
117471 + head = handle_stmt_by_cgraph_nodes_ret(head, stmt, next_node);
117472 + }
117473 + }
117474 + return head;
117475 +}
117476 +
117477 +static void set_current_function_decl(tree fndecl)
117478 +{
117479 + gcc_assert(fndecl != NULL_TREE);
117480 +
117481 + push_cfun(DECL_STRUCT_FUNCTION(fndecl));
117482 + calculate_dominance_info(CDI_DOMINATORS);
117483 + current_function_decl = fndecl;
117484 +}
117485 +
117486 +static void unset_current_function_decl(void)
117487 +{
117488 + free_dominance_info(CDI_DOMINATORS);
117489 + pop_cfun();
117490 + current_function_decl = NULL_TREE;
117491 +}
117492 +
117493 +static void free_interesting_node(struct interesting_node *head)
117494 +{
117495 + struct interesting_node *cur;
117496 +
117497 + while (head) {
117498 + cur = head->next;
117499 +#if BUILDING_GCC_VERSION <= 4007
117500 + VEC_free(tree, gc, head->last_nodes);
117501 +#else
117502 + vec_free(head->last_nodes);
117503 +#endif
117504 + free(head);
117505 + head = cur;
117506 + }
117507 +}
117508 +
117509 +static struct visited *insert_visited_function(struct visited *head, struct interesting_node *cur_node)
117510 +{
117511 + struct visited *new_visited;
117512 +
117513 + new_visited = (struct visited *)xmalloc(sizeof(*new_visited));
117514 + new_visited->fndecl = cur_node->fndecl;
117515 + new_visited->num = cur_node->num;
117516 + new_visited->next = NULL;
117517 +
117518 + if (!head)
117519 + return new_visited;
117520 +
117521 + new_visited->next = head;
117522 + return new_visited;
117523 +}
117524 +
117525 +/* 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
117526 + * it is a visited function.
117527 + */
117528 +static bool is_visited_function(struct visited *head, struct interesting_node *cur_node)
117529 +{
117530 + struct visited *cur;
117531 +
117532 + if (!head)
117533 + return false;
117534 +
117535 + if (get_stmt_flag(cur_node->first_stmt) != VISITED_STMT)
117536 + return false;
117537 +
117538 + for (cur = head; cur; cur = cur->next) {
117539 + if (!operand_equal_p(cur_node->fndecl, cur->fndecl, 0))
117540 + continue;
117541 + if (cur_node->num == cur->num)
117542 + return true;
117543 + }
117544 + return false;
117545 +}
117546 +
117547 +static void free_next_cgraph_node(struct next_cgraph_node *head)
117548 +{
117549 + struct next_cgraph_node *cur;
117550 +
117551 + while (head) {
117552 + cur = head->next;
117553 + free(head);
117554 + head = cur;
117555 + }
117556 +}
117557 +
117558 +static void remove_all_size_overflow_asm(void)
117559 +{
117560 + basic_block bb;
117561 +
117562 + FOR_ALL_BB_FN(bb, cfun) {
117563 + gimple_stmt_iterator si;
117564 +
117565 + for (si = gsi_start_bb(bb); !gsi_end_p(si); gsi_next(&si))
117566 + remove_size_overflow_asm(gsi_stmt(si));
117567 + }
117568 +}
117569 +
117570 +/* Main recursive walk of the ipa pass: iterate over the collected interesting stmts in a function
117571 + * (they are interesting if they have an associated size_overflow asm stmt) and recursively walk
117572 + * the newly collected interesting functions (they are interesting if there is control flow between
117573 + * the interesting stmts and them).
117574 + */
117575 +static struct visited *handle_function(struct cgraph_node *node, struct next_cgraph_node *next_node, struct visited *visited)
117576 +{
117577 + struct interesting_node *head, *cur_node;
117578 + struct next_cgraph_node *cur_cnodes, *cnodes_head = NULL;
117579 +
117580 + set_current_function_decl(NODE_DECL(node));
117581 + call_count = 0;
117582 +
117583 + head = collect_interesting_stmts(next_node);
117584 +
117585 + for (cur_node = head; cur_node; cur_node = cur_node->next) {
117586 + if (is_visited_function(visited, cur_node))
117587 + continue;
117588 + cnodes_head = handle_interesting_stmt(cnodes_head, cur_node, node);
117589 + set_stmt_flag(cur_node->first_stmt, VISITED_STMT);
117590 + visited = insert_visited_function(visited, cur_node);
117591 + }
117592 +
117593 + free_interesting_node(head);
117594 + remove_all_size_overflow_asm();
117595 + unset_current_function_decl();
117596 +
117597 + for (cur_cnodes = cnodes_head; cur_cnodes; cur_cnodes = cur_cnodes->next)
117598 + visited = handle_function(cur_cnodes->current_function, cur_cnodes, visited);
117599 +
117600 + free_next_cgraph_node(cnodes_head);
117601 + return visited;
117602 +}
117603 +
117604 +static void free_visited(struct visited *head)
117605 +{
117606 + struct visited *cur;
117607 +
117608 + while (head) {
117609 + cur = head->next;
117610 + free(head);
117611 + head = cur;
117612 + }
117613 +}
117614 +
117615 +// erase the local flag
117616 +static void set_plf_false(void)
117617 +{
117618 + basic_block bb;
117619 +
117620 + FOR_ALL_BB_FN(bb, cfun) {
117621 + gimple_stmt_iterator si;
117622 +
117623 + for (si = gsi_start_bb(bb); !gsi_end_p(si); gsi_next(&si))
117624 + set_stmt_flag(gsi_stmt(si), NO_FLAGS);
117625 + for (si = gsi_start_phis(bb); !gsi_end_p(si); gsi_next(&si))
117626 + set_stmt_flag(gsi_stmt(si), NO_FLAGS);
117627 + }
117628 +}
117629 +
117630 +// Main entry point of the ipa pass: erases the plf flag of all stmts and iterates over all the functions
117631 +static unsigned int search_function(void)
117632 +{
117633 + struct cgraph_node *node;
117634 + struct visited *visited = NULL;
117635 +
117636 + FOR_EACH_FUNCTION_WITH_GIMPLE_BODY(node) {
117637 + set_current_function_decl(NODE_DECL(node));
117638 + set_plf_false();
117639 + unset_current_function_decl();
117640 + }
117641 +
117642 + FOR_EACH_FUNCTION_WITH_GIMPLE_BODY(node) {
117643 + gcc_assert(cgraph_function_flags_ready);
117644 +#if BUILDING_GCC_VERSION <= 4007
117645 + gcc_assert(node->reachable);
117646 +#endif
117647 +
117648 + visited = handle_function(node, NULL, visited);
117649 + }
117650 +
117651 + free_visited(visited);
117652 + return 0;
117653 +}
117654 +
117655 +#if BUILDING_GCC_VERSION >= 4009
117656 +static const struct pass_data ipa_pass_data = {
117657 +#else
117658 +static struct ipa_opt_pass_d ipa_pass = {
117659 + .pass = {
117660 +#endif
117661 + .type = SIMPLE_IPA_PASS,
117662 + .name = "size_overflow",
117663 +#if BUILDING_GCC_VERSION >= 4008
117664 + .optinfo_flags = OPTGROUP_NONE,
117665 +#endif
117666 +#if BUILDING_GCC_VERSION >= 4009
117667 + .has_gate = false,
117668 + .has_execute = true,
117669 +#else
117670 + .gate = NULL,
117671 + .execute = search_function,
117672 + .sub = NULL,
117673 + .next = NULL,
117674 + .static_pass_number = 0,
117675 +#endif
117676 + .tv_id = TV_NONE,
117677 + .properties_required = 0,
117678 + .properties_provided = 0,
117679 + .properties_destroyed = 0,
117680 + .todo_flags_start = 0,
117681 + .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,
117682 +#if BUILDING_GCC_VERSION < 4009
117683 + },
117684 + .generate_summary = NULL,
117685 + .write_summary = NULL,
117686 + .read_summary = NULL,
117687 +#if BUILDING_GCC_VERSION >= 4006
117688 + .write_optimization_summary = NULL,
117689 + .read_optimization_summary = NULL,
117690 +#endif
117691 + .stmt_fixup = NULL,
117692 + .function_transform_todo_flags_start = 0,
117693 + .function_transform = NULL,
117694 + .variable_transform = NULL,
117695 +#endif
117696 +};
117697 +
117698 +#if BUILDING_GCC_VERSION >= 4009
117699 +namespace {
117700 +class ipa_pass : public ipa_opt_pass_d {
117701 +public:
117702 + ipa_pass() : ipa_opt_pass_d(ipa_pass_data, g, NULL, NULL, NULL, NULL, NULL, NULL, 0, NULL, NULL) {}
117703 + unsigned int execute() { return search_function(); }
117704 +};
117705 +}
117706 +#endif
117707 +
117708 +static struct opt_pass *make_ipa_pass(void)
117709 +{
117710 +#if BUILDING_GCC_VERSION >= 4009
117711 + return new ipa_pass();
117712 +#else
117713 + return &ipa_pass.pass;
117714 +#endif
117715 +}
117716 +
117717 +// data for the size_overflow asm stmt
117718 +struct asm_data {
117719 + gimple def_stmt;
117720 + tree input;
117721 + tree output;
117722 +};
117723 +
117724 +#if BUILDING_GCC_VERSION <= 4007
117725 +static VEC(tree, gc) *create_asm_io_list(tree string, tree io)
117726 +#else
117727 +static vec<tree, va_gc> *create_asm_io_list(tree string, tree io)
117728 +#endif
117729 +{
117730 + tree list;
117731 +#if BUILDING_GCC_VERSION <= 4007
117732 + VEC(tree, gc) *vec_list = NULL;
117733 +#else
117734 + vec<tree, va_gc> *vec_list = NULL;
117735 +#endif
117736 +
117737 + list = build_tree_list(NULL_TREE, string);
117738 + list = chainon(NULL_TREE, build_tree_list(list, io));
117739 +#if BUILDING_GCC_VERSION <= 4007
117740 + VEC_safe_push(tree, gc, vec_list, list);
117741 +#else
117742 + vec_safe_push(vec_list, list);
117743 +#endif
117744 + return vec_list;
117745 +}
117746 +
117747 +static void create_asm_stmt(const char *str, tree str_input, tree str_output, struct asm_data *asm_data)
117748 +{
117749 + gimple asm_stmt;
117750 + gimple_stmt_iterator gsi;
117751 +#if BUILDING_GCC_VERSION <= 4007
117752 + VEC(tree, gc) *input, *output = NULL;
117753 +#else
117754 + vec<tree, va_gc> *input, *output = NULL;
117755 +#endif
117756 +
117757 + input = create_asm_io_list(str_input, asm_data->input);
117758 +
117759 + if (asm_data->output)
117760 + output = create_asm_io_list(str_output, asm_data->output);
117761 +
117762 + asm_stmt = gimple_build_asm_vec(str, input, output, NULL, NULL);
117763 + gsi = gsi_for_stmt(asm_data->def_stmt);
117764 + gsi_insert_after(&gsi, asm_stmt, GSI_NEW_STMT);
117765 +
117766 + if (asm_data->output)
117767 + SSA_NAME_DEF_STMT(asm_data->output) = asm_stmt;
117768 +}
117769 +
117770 +static void replace_call_lhs(const struct asm_data *asm_data)
117771 +{
117772 + gimple_set_lhs(asm_data->def_stmt, asm_data->input);
117773 + update_stmt(asm_data->def_stmt);
117774 + SSA_NAME_DEF_STMT(asm_data->input) = asm_data->def_stmt;
117775 +}
117776 +
117777 +static enum mark search_intentional_phi(struct pointer_set_t *visited, const_tree result)
117778 +{
117779 + enum mark cur_fndecl_attr;
117780 + gimple phi = get_def_stmt(result);
117781 + unsigned int i, n = gimple_phi_num_args(phi);
117782 +
117783 + pointer_set_insert(visited, phi);
117784 + for (i = 0; i < n; i++) {
117785 + tree arg = gimple_phi_arg_def(phi, i);
117786 +
117787 + cur_fndecl_attr = search_intentional(visited, arg);
117788 + if (cur_fndecl_attr != MARK_NO)
117789 + return cur_fndecl_attr;
117790 + }
117791 + return MARK_NO;
117792 +}
117793 +
117794 +static enum mark search_intentional_binary(struct pointer_set_t *visited, const_tree lhs)
117795 +{
117796 + enum mark cur_fndecl_attr;
117797 + const_tree rhs1, rhs2;
117798 + gimple def_stmt = get_def_stmt(lhs);
117799 +
117800 + rhs1 = gimple_assign_rhs1(def_stmt);
117801 + rhs2 = gimple_assign_rhs2(def_stmt);
117802 +
117803 + cur_fndecl_attr = search_intentional(visited, rhs1);
117804 + if (cur_fndecl_attr != MARK_NO)
117805 + return cur_fndecl_attr;
117806 + return search_intentional(visited, rhs2);
117807 +}
117808 +
117809 +// Look up the intentional_overflow attribute on the caller and the callee functions.
117810 +static enum mark search_intentional(struct pointer_set_t *visited, const_tree lhs)
117811 +{
117812 + const_gimple def_stmt;
117813 +
117814 + if (TREE_CODE(lhs) != SSA_NAME)
117815 + return get_intentional_attr_type(lhs);
117816 +
117817 + def_stmt = get_def_stmt(lhs);
117818 + if (!def_stmt)
117819 + return MARK_NO;
117820 +
117821 + if (pointer_set_contains(visited, def_stmt))
117822 + return MARK_NO;
117823 +
117824 + switch (gimple_code(def_stmt)) {
117825 + case GIMPLE_NOP:
117826 + return search_intentional(visited, SSA_NAME_VAR(lhs));
117827 + case GIMPLE_ASM:
117828 + if (is_size_overflow_intentional_asm_turn_off(def_stmt))
117829 + return MARK_TURN_OFF;
117830 + return MARK_NO;
117831 + case GIMPLE_CALL:
117832 + return MARK_NO;
117833 + case GIMPLE_PHI:
117834 + return search_intentional_phi(visited, lhs);
117835 + case GIMPLE_ASSIGN:
117836 + switch (gimple_num_ops(def_stmt)) {
117837 + case 2:
117838 + return search_intentional(visited, gimple_assign_rhs1(def_stmt));
117839 + case 3:
117840 + return search_intentional_binary(visited, lhs);
117841 + }
117842 + case GIMPLE_RETURN:
117843 + return MARK_NO;
117844 + default:
117845 + debug_gimple_stmt((gimple)def_stmt);
117846 + error("%s: unknown gimple code", __func__);
117847 + gcc_unreachable();
117848 + }
117849 +}
117850 +
117851 +// Check the intentional_overflow attribute and create the asm comment string for the size_overflow asm stmt.
117852 +static enum mark check_intentional_attribute_gimple(const_tree arg, const_gimple stmt, unsigned int argnum)
117853 +{
117854 + const_tree fndecl;
117855 + struct pointer_set_t *visited;
117856 + enum mark cur_fndecl_attr, decl_attr = MARK_NO;
117857 +
117858 + fndecl = get_interesting_orig_fndecl(stmt, argnum);
117859 + if (is_end_intentional_intentional_attr(fndecl, argnum))
117860 + decl_attr = MARK_NOT_INTENTIONAL;
117861 + else if (is_yes_intentional_attr(fndecl, argnum))
117862 + decl_attr = MARK_YES;
117863 + else if (is_turn_off_intentional_attr(fndecl) || is_turn_off_intentional_attr(DECL_ORIGIN(current_function_decl))) {
117864 + return MARK_TURN_OFF;
117865 + }
117866 +
117867 + visited = pointer_set_create();
117868 + cur_fndecl_attr = search_intentional(visited, arg);
117869 + pointer_set_destroy(visited);
117870 +
117871 + switch (cur_fndecl_attr) {
117872 + case MARK_NO:
117873 + case MARK_TURN_OFF:
117874 + return cur_fndecl_attr;
117875 + default:
117876 + print_missing_intentional(decl_attr, cur_fndecl_attr, fndecl, argnum);
117877 + return MARK_YES;
117878 + }
117879 +}
117880 +
117881 +static void check_missing_size_overflow_attribute(tree var)
117882 +{
117883 + tree orig_fndecl;
117884 + unsigned int num;
117885 +
117886 + if (is_a_return_check(var))
117887 + orig_fndecl = DECL_ORIGIN(var);
117888 + else
117889 + orig_fndecl = DECL_ORIGIN(current_function_decl);
117890 +
117891 + num = get_function_num(var, orig_fndecl);
117892 + if (num == CANNOT_FIND_ARG)
117893 + return;
117894 +
117895 + is_missing_function(orig_fndecl, num);
117896 +}
117897 +
117898 +static void search_size_overflow_attribute_phi(struct pointer_set_t *visited, const_tree result)
117899 +{
117900 + gimple phi = get_def_stmt(result);
117901 + unsigned int i, n = gimple_phi_num_args(phi);
117902 +
117903 + pointer_set_insert(visited, phi);
117904 + for (i = 0; i < n; i++) {
117905 + tree arg = gimple_phi_arg_def(phi, i);
117906 +
117907 + search_size_overflow_attribute(visited, arg);
117908 + }
117909 +}
117910 +
117911 +static void search_size_overflow_attribute_binary(struct pointer_set_t *visited, const_tree lhs)
117912 +{
117913 + const_gimple def_stmt = get_def_stmt(lhs);
117914 + tree rhs1, rhs2;
117915 +
117916 + rhs1 = gimple_assign_rhs1(def_stmt);
117917 + rhs2 = gimple_assign_rhs2(def_stmt);
117918 +
117919 + search_size_overflow_attribute(visited, rhs1);
117920 + search_size_overflow_attribute(visited, rhs2);
117921 +}
117922 +
117923 +static void search_size_overflow_attribute(struct pointer_set_t *visited, tree lhs)
117924 +{
117925 + const_gimple def_stmt;
117926 +
117927 + if (TREE_CODE(lhs) == PARM_DECL) {
117928 + check_missing_size_overflow_attribute(lhs);
117929 + return;
117930 + }
117931 +
117932 + def_stmt = get_def_stmt(lhs);
117933 + if (!def_stmt)
117934 + return;
117935 +
117936 + if (pointer_set_insert(visited, def_stmt))
117937 + return;
117938 +
117939 + switch (gimple_code(def_stmt)) {
117940 + case GIMPLE_NOP:
117941 + return search_size_overflow_attribute(visited, SSA_NAME_VAR(lhs));
117942 + case GIMPLE_ASM:
117943 + return;
117944 + case GIMPLE_CALL: {
117945 + tree fndecl = gimple_call_fndecl(def_stmt);
117946 +
117947 + if (fndecl == NULL_TREE)
117948 + return;
117949 + check_missing_size_overflow_attribute(fndecl);
117950 + return;
117951 + }
117952 + case GIMPLE_PHI:
117953 + return search_size_overflow_attribute_phi(visited, lhs);
117954 + case GIMPLE_ASSIGN:
117955 + switch (gimple_num_ops(def_stmt)) {
117956 + case 2:
117957 + return search_size_overflow_attribute(visited, gimple_assign_rhs1(def_stmt));
117958 + case 3:
117959 + return search_size_overflow_attribute_binary(visited, lhs);
117960 + }
117961 + default:
117962 + debug_gimple_stmt((gimple)def_stmt);
117963 + error("%s: unknown gimple code", __func__);
117964 + gcc_unreachable();
117965 + }
117966 +}
117967 +
117968 +// Search missing entries in the hash table (invoked from the gimple pass)
117969 +static void search_missing_size_overflow_attribute_gimple(const_gimple stmt, unsigned int num)
117970 +{
117971 + tree fndecl = NULL_TREE;
117972 + tree lhs;
117973 + struct pointer_set_t *visited;
117974 +
117975 + if (is_turn_off_intentional_attr(DECL_ORIGIN(current_function_decl)))
117976 + return;
117977 +
117978 + if (num == 0) {
117979 + gcc_assert(gimple_code(stmt) == GIMPLE_RETURN);
117980 + lhs = gimple_return_retval(stmt);
117981 + } else {
117982 + gcc_assert(is_gimple_call(stmt));
117983 + lhs = gimple_call_arg(stmt, num - 1);
117984 + fndecl = gimple_call_fndecl(stmt);
117985 + }
117986 +
117987 + if (fndecl != NULL_TREE && is_turn_off_intentional_attr(DECL_ORIGIN(fndecl)))
117988 + return;
117989 +
117990 + visited = pointer_set_create();
117991 + search_size_overflow_attribute(visited, lhs);
117992 + pointer_set_destroy(visited);
117993 +}
117994 +
117995 +static void create_output_from_phi(gimple stmt, unsigned int argnum, struct asm_data *asm_data)
117996 +{
117997 + gimple_stmt_iterator gsi;
117998 + gimple assign;
117999 +
118000 + assign = gimple_build_assign(asm_data->input, asm_data->output);
118001 + gsi = gsi_for_stmt(stmt);
118002 + gsi_insert_before(&gsi, assign, GSI_NEW_STMT);
118003 + asm_data->def_stmt = assign;
118004 +
118005 + asm_data->output = create_new_var(TREE_TYPE(asm_data->output));
118006 + asm_data->output = make_ssa_name(asm_data->output, stmt);
118007 + if (gimple_code(stmt) == GIMPLE_RETURN)
118008 + gimple_return_set_retval(stmt, asm_data->output);
118009 + else
118010 + gimple_call_set_arg(stmt, argnum - 1, asm_data->output);
118011 + update_stmt(stmt);
118012 +}
118013 +
118014 +static char *create_asm_comment(unsigned int argnum, const_gimple stmt , const char *mark_str)
118015 +{
118016 + const char *fn_name;
118017 + char *asm_comment;
118018 + unsigned int len;
118019 +
118020 + if (argnum == 0)
118021 + fn_name = DECL_NAME_POINTER(current_function_decl);
118022 + else
118023 + fn_name = DECL_NAME_POINTER(gimple_call_fndecl(stmt));
118024 +
118025 + len = asprintf(&asm_comment, "%s %s %u", mark_str, fn_name, argnum);
118026 + gcc_assert(len > 0);
118027 +
118028 + return asm_comment;
118029 +}
118030 +
118031 +static const char *convert_mark_to_str(enum mark mark)
118032 +{
118033 + switch (mark) {
118034 + case MARK_NO:
118035 + return OK_ASM_STR;
118036 + case MARK_YES:
118037 + case MARK_NOT_INTENTIONAL:
118038 + return YES_ASM_STR;
118039 + case MARK_TURN_OFF:
118040 + return TURN_OFF_ASM_STR;
118041 + }
118042 +
118043 + gcc_unreachable();
118044 +}
118045 +
118046 +/* Create the input of the size_overflow asm stmt.
118047 + * When the arg of the callee function is a parm_decl it creates this kind of size_overflow asm stmt:
118048 + * __asm__("# size_overflow MARK_YES" : : "rm" size_1(D));
118049 + * The input field in asm_data will be empty if there is no need for further size_overflow asm stmt insertion.
118050 + * otherwise create the input (for a phi stmt the output too) of the asm stmt.
118051 + */
118052 +static void create_asm_input(gimple stmt, unsigned int argnum, struct asm_data *asm_data)
118053 +{
118054 + if (!asm_data->def_stmt) {
118055 + asm_data->input = NULL_TREE;
118056 + return;
118057 + }
118058 +
118059 + asm_data->input = create_new_var(TREE_TYPE(asm_data->output));
118060 + asm_data->input = make_ssa_name(asm_data->input, asm_data->def_stmt);
118061 +
118062 + switch (gimple_code(asm_data->def_stmt)) {
118063 + case GIMPLE_ASSIGN:
118064 + case GIMPLE_CALL:
118065 + replace_call_lhs(asm_data);
118066 + break;
118067 + case GIMPLE_PHI:
118068 + create_output_from_phi(stmt, argnum, asm_data);
118069 + break;
118070 + case GIMPLE_NOP: {
118071 + enum mark mark;
118072 + const char *mark_str;
118073 + char *asm_comment;
118074 +
118075 + mark = check_intentional_attribute_gimple(asm_data->output, stmt, argnum);
118076 +
118077 + asm_data->input = asm_data->output;
118078 + asm_data->output = NULL;
118079 + asm_data->def_stmt = stmt;
118080 +
118081 + mark_str = convert_mark_to_str(mark);
118082 + asm_comment = create_asm_comment(argnum, stmt, mark_str);
118083 +
118084 + create_asm_stmt(asm_comment, build_string(2, "rm"), NULL, asm_data);
118085 + free(asm_comment);
118086 + asm_data->input = NULL_TREE;
118087 + break;
118088 + }
118089 + case GIMPLE_ASM:
118090 + if (is_size_overflow_asm(asm_data->def_stmt)) {
118091 + asm_data->input = NULL_TREE;
118092 + break;
118093 + }
118094 + default:
118095 + debug_gimple_stmt(asm_data->def_stmt);
118096 + gcc_unreachable();
118097 + }
118098 +}
118099 +
118100 +/* This is the gimple part of searching for a missing size_overflow attribute. If the intentional_overflow attribute type
118101 + * is of the right kind create the appropriate size_overflow asm stmts:
118102 + * __asm__("# size_overflow" : =rm" D.3344_8 : "0" cicus.4_16);
118103 + * __asm__("# size_overflow MARK_YES" : : "rm" size_1(D));
118104 + */
118105 +static void create_size_overflow_asm(gimple stmt, tree output_node, unsigned int argnum)
118106 +{
118107 + struct asm_data asm_data;
118108 + const char *mark_str;
118109 + char *asm_comment;
118110 + enum mark mark;
118111 +
118112 + if (is_gimple_constant(output_node))
118113 + return;
118114 +
118115 + asm_data.output = output_node;
118116 + mark = check_intentional_attribute_gimple(asm_data.output, stmt, argnum);
118117 + if (mark != MARK_TURN_OFF)
118118 + search_missing_size_overflow_attribute_gimple(stmt, argnum);
118119 +
118120 + asm_data.def_stmt = get_def_stmt(asm_data.output);
118121 + if (is_size_overflow_intentional_asm_turn_off(asm_data.def_stmt))
118122 + return;
118123 +
118124 + create_asm_input(stmt, argnum, &asm_data);
118125 + if (asm_data.input == NULL_TREE)
118126 + return;
118127 +
118128 + mark_str = convert_mark_to_str(mark);
118129 + asm_comment = create_asm_comment(argnum, stmt, mark_str);
118130 + create_asm_stmt(asm_comment, build_string(1, "0"), build_string(3, "=rm"), &asm_data);
118131 + free(asm_comment);
118132 +}
118133 +
118134 +// Insert an asm stmt with "MARK_TURN_OFF", "MARK_YES" or "MARK_NOT_INTENTIONAL".
118135 +static bool create_mark_asm(gimple stmt, enum mark mark)
118136 +{
118137 + struct asm_data asm_data;
118138 + const char *asm_str;
118139 +
118140 + switch (mark) {
118141 + case MARK_TURN_OFF:
118142 + asm_str = TURN_OFF_ASM_STR;
118143 + break;
118144 + case MARK_NOT_INTENTIONAL:
118145 + case MARK_YES:
118146 + asm_str = YES_ASM_STR;
118147 + break;
118148 + default:
118149 + gcc_unreachable();
118150 + }
118151 +
118152 + asm_data.def_stmt = stmt;
118153 + asm_data.output = gimple_call_lhs(stmt);
118154 +
118155 + if (asm_data.output == NULL_TREE) {
118156 + asm_data.input = gimple_call_arg(stmt, 0);
118157 + if (is_gimple_constant(asm_data.input))
118158 + return false;
118159 + asm_data.output = NULL;
118160 + create_asm_stmt(asm_str, build_string(2, "rm"), NULL, &asm_data);
118161 + return true;
118162 + }
118163 +
118164 + create_asm_input(stmt, 0, &asm_data);
118165 + gcc_assert(asm_data.input != NULL_TREE);
118166 +
118167 + create_asm_stmt(asm_str, build_string(1, "0"), build_string(3, "=rm"), &asm_data);
118168 + return true;
118169 +}
118170 +
118171 +static bool is_from_cast(const_tree node)
118172 +{
118173 + gimple def_stmt = get_def_stmt(node);
118174 +
118175 + if (!def_stmt)
118176 + return false;
118177 +
118178 + if (gimple_assign_cast_p(def_stmt))
118179 + return true;
118180 +
118181 + return false;
118182 +}
118183 +
118184 +// Skip duplication when there is a minus expr and the type of rhs1 or rhs2 is a pointer_type.
118185 +static bool skip_ptr_minus(gimple stmt)
118186 +{
118187 + const_tree rhs1, rhs2, ptr1_rhs, ptr2_rhs;
118188 +
118189 + if (gimple_assign_rhs_code(stmt) != MINUS_EXPR)
118190 + return false;
118191 +
118192 + rhs1 = gimple_assign_rhs1(stmt);
118193 + if (!is_from_cast(rhs1))
118194 + return false;
118195 +
118196 + rhs2 = gimple_assign_rhs2(stmt);
118197 + if (!is_from_cast(rhs2))
118198 + return false;
118199 +
118200 + ptr1_rhs = gimple_assign_rhs1(get_def_stmt(rhs1));
118201 + ptr2_rhs = gimple_assign_rhs1(get_def_stmt(rhs2));
118202 +
118203 + if (TREE_CODE(TREE_TYPE(ptr1_rhs)) != POINTER_TYPE && TREE_CODE(TREE_TYPE(ptr2_rhs)) != POINTER_TYPE)
118204 + return false;
118205 +
118206 + create_mark_asm(stmt, MARK_YES);
118207 + return true;
118208 +}
118209 +
118210 +static void walk_use_def_ptr(struct pointer_set_t *visited, const_tree lhs)
118211 +{
118212 + gimple def_stmt;
118213 +
118214 + def_stmt = get_def_stmt(lhs);
118215 + if (!def_stmt)
118216 + return;
118217 +
118218 + if (pointer_set_insert(visited, def_stmt))
118219 + return;
118220 +
118221 + switch (gimple_code(def_stmt)) {
118222 + case GIMPLE_NOP:
118223 + case GIMPLE_ASM:
118224 + case GIMPLE_CALL:
118225 + break;
118226 + case GIMPLE_PHI: {
118227 + unsigned int i, n = gimple_phi_num_args(def_stmt);
118228 +
118229 + pointer_set_insert(visited, def_stmt);
118230 +
118231 + for (i = 0; i < n; i++) {
118232 + tree arg = gimple_phi_arg_def(def_stmt, i);
118233 +
118234 + walk_use_def_ptr(visited, arg);
118235 + }
118236 + }
118237 + case GIMPLE_ASSIGN:
118238 + switch (gimple_num_ops(def_stmt)) {
118239 + case 2:
118240 + walk_use_def_ptr(visited, gimple_assign_rhs1(def_stmt));
118241 + return;
118242 + case 3:
118243 + if (skip_ptr_minus(def_stmt))
118244 + return;
118245 +
118246 + walk_use_def_ptr(visited, gimple_assign_rhs1(def_stmt));
118247 + walk_use_def_ptr(visited, gimple_assign_rhs2(def_stmt));
118248 + return;
118249 + default:
118250 + return;
118251 + }
118252 + default:
118253 + debug_gimple_stmt((gimple)def_stmt);
118254 + error("%s: unknown gimple code", __func__);
118255 + gcc_unreachable();
118256 + }
118257 +}
118258 +
118259 +// Look for a ptr - ptr expression (e.g., cpuset_common_file_read() s - page)
118260 +static void insert_mark_not_intentional_asm_at_ptr(const_tree arg)
118261 +{
118262 + struct pointer_set_t *visited;
118263 +
118264 + visited = pointer_set_create();
118265 + walk_use_def_ptr(visited, arg);
118266 + pointer_set_destroy(visited);
118267 +}
118268 +
118269 +// Determine the return value and insert the asm stmt to mark the return stmt.
118270 +static void insert_asm_ret(gimple stmt)
118271 +{
118272 + tree ret;
118273 +
118274 + ret = gimple_return_retval(stmt);
118275 + create_size_overflow_asm(stmt, ret, 0);
118276 +}
118277 +
118278 +// Determine the correct arg index and arg and insert the asm stmt to mark the stmt.
118279 +static void insert_asm_arg(gimple stmt, unsigned int orig_argnum)
118280 +{
118281 + tree arg;
118282 + unsigned int argnum;
118283 +
118284 + argnum = get_correct_arg_count(orig_argnum, gimple_call_fndecl(stmt));
118285 + gcc_assert(argnum != 0);
118286 + if (argnum == CANNOT_FIND_ARG)
118287 + return;
118288 +
118289 + arg = gimple_call_arg(stmt, argnum - 1);
118290 + gcc_assert(arg != NULL_TREE);
118291 +
118292 + // skip all ptr - ptr expressions
118293 + insert_mark_not_intentional_asm_at_ptr(arg);
118294 +
118295 + create_size_overflow_asm(stmt, arg, argnum);
118296 +}
118297 +
118298 +// If a function arg or the return value is marked by the size_overflow attribute then set its index in the array.
118299 +static void set_argnum_attribute(const_tree attr, bool *argnums)
118300 +{
118301 + unsigned int argnum;
118302 + tree attr_value;
118303 +
118304 + for (attr_value = TREE_VALUE(attr); attr_value; attr_value = TREE_CHAIN(attr_value)) {
118305 + argnum = TREE_INT_CST_LOW(TREE_VALUE(attr_value));
118306 + argnums[argnum] = true;
118307 + }
118308 +}
118309 +
118310 +// If a function arg or the return value is in the hash table then set its index in the array.
118311 +static void set_argnum_hash(tree fndecl, bool *argnums)
118312 +{
118313 + unsigned int num;
118314 + const struct size_overflow_hash *hash;
118315 +
118316 + hash = get_function_hash(DECL_ORIGIN(fndecl));
118317 + if (!hash)
118318 + return;
118319 +
118320 + for (num = 0; num <= MAX_PARAM; num++) {
118321 + if (!(hash->param & (1U << num)))
118322 + continue;
118323 +
118324 + argnums[num] = true;
118325 + }
118326 +}
118327 +
118328 +static bool is_all_the_argnums_empty(bool *argnums)
118329 +{
118330 + unsigned int i;
118331 +
118332 + for (i = 0; i <= MAX_PARAM; i++)
118333 + if (argnums[i])
118334 + return false;
118335 + return true;
118336 +}
118337 +
118338 +// Check whether the arguments or the return value of the function are in the hash table or are marked by the size_overflow attribute.
118339 +static void search_interesting_args(tree fndecl, bool *argnums)
118340 +{
118341 + const_tree attr;
118342 +
118343 + set_argnum_hash(fndecl, argnums);
118344 + if (!is_all_the_argnums_empty(argnums))
118345 + return;
118346 +
118347 + attr = lookup_attribute("size_overflow", DECL_ATTRIBUTES(fndecl));
118348 + if (attr && TREE_VALUE(attr))
118349 + set_argnum_attribute(attr, argnums);
118350 +}
118351 +
118352 +/*
118353 + * Look up the intentional_overflow attribute that turns off ipa based duplication
118354 + * on the callee function.
118355 + */
118356 +static bool is_mark_turn_off_attribute(gimple stmt)
118357 +{
118358 + enum mark mark;
118359 + const_tree fndecl = gimple_call_fndecl(stmt);
118360 +
118361 + mark = get_intentional_attr_type(DECL_ORIGIN(fndecl));
118362 + if (mark == MARK_TURN_OFF)
118363 + return true;
118364 + return false;
118365 +}
118366 +
118367 +// 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
118368 +static void handle_interesting_function(gimple stmt)
118369 +{
118370 + unsigned int argnum;
118371 + tree fndecl;
118372 + bool orig_argnums[MAX_PARAM + 1] = {false};
118373 +
118374 + if (gimple_call_num_args(stmt) == 0)
118375 + return;
118376 + fndecl = gimple_call_fndecl(stmt);
118377 + if (fndecl == NULL_TREE)
118378 + return;
118379 + fndecl = DECL_ORIGIN(fndecl);
118380 +
118381 + if (is_mark_turn_off_attribute(stmt)) {
118382 + create_mark_asm(stmt, MARK_TURN_OFF);
118383 + return;
118384 + }
118385 +
118386 + search_interesting_args(fndecl, orig_argnums);
118387 +
118388 + for (argnum = 1; argnum < MAX_PARAM; argnum++)
118389 + if (orig_argnums[argnum])
118390 + insert_asm_arg(stmt, argnum);
118391 +}
118392 +
118393 +// 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
118394 +static void handle_interesting_ret(gimple stmt)
118395 +{
118396 + bool orig_argnums[MAX_PARAM + 1] = {false};
118397 +
118398 + search_interesting_args(current_function_decl, orig_argnums);
118399 +
118400 + if (orig_argnums[0])
118401 + insert_asm_ret(stmt);
118402 +}
118403 +
118404 +// Iterate over all the stmts and search for call and return stmts and mark them if they're in the hash table
118405 +static unsigned int search_interesting_functions(void)
118406 +{
118407 + basic_block bb;
118408 +
118409 + FOR_ALL_BB_FN(bb, cfun) {
118410 + gimple_stmt_iterator gsi;
118411 +
118412 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
118413 + gimple stmt = gsi_stmt(gsi);
118414 +
118415 + if (is_size_overflow_asm(stmt))
118416 + continue;
118417 +
118418 + if (is_gimple_call(stmt))
118419 + handle_interesting_function(stmt);
118420 + else if (gimple_code(stmt) == GIMPLE_RETURN)
118421 + handle_interesting_ret(stmt);
118422 + }
118423 + }
118424 + return 0;
118425 +}
118426 +
118427 +/*
118428 + * A lot of functions get inlined before the ipa passes so after the build_ssa gimple pass
118429 + * this pass inserts asm stmts to mark the interesting args
118430 + * that the ipa pass will detect and insert the size overflow checks for.
118431 + */
118432 +#if BUILDING_GCC_VERSION >= 4009
118433 +static const struct pass_data insert_size_overflow_asm_pass_data = {
118434 +#else
118435 +static struct gimple_opt_pass insert_size_overflow_asm_pass = {
118436 + .pass = {
118437 +#endif
118438 + .type = GIMPLE_PASS,
118439 + .name = "insert_size_overflow_asm",
118440 +#if BUILDING_GCC_VERSION >= 4008
118441 + .optinfo_flags = OPTGROUP_NONE,
118442 +#endif
118443 +#if BUILDING_GCC_VERSION >= 4009
118444 + .has_gate = false,
118445 + .has_execute = true,
118446 +#else
118447 + .gate = NULL,
118448 + .execute = search_interesting_functions,
118449 + .sub = NULL,
118450 + .next = NULL,
118451 + .static_pass_number = 0,
118452 +#endif
118453 + .tv_id = TV_NONE,
118454 + .properties_required = PROP_cfg,
118455 + .properties_provided = 0,
118456 + .properties_destroyed = 0,
118457 + .todo_flags_start = 0,
118458 + .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
118459 +#if BUILDING_GCC_VERSION < 4009
118460 + }
118461 +#endif
118462 +};
118463 +
118464 +#if BUILDING_GCC_VERSION >= 4009
118465 +namespace {
118466 +class insert_size_overflow_asm_pass : public gimple_opt_pass {
118467 +public:
118468 + insert_size_overflow_asm_pass() : gimple_opt_pass(insert_size_overflow_asm_pass_data, g) {}
118469 + unsigned int execute() { return search_interesting_functions(); }
118470 +};
118471 +}
118472 +#endif
118473 +
118474 +static struct opt_pass *make_insert_size_overflow_asm_pass(void)
118475 +{
118476 +#if BUILDING_GCC_VERSION >= 4009
118477 + return new insert_size_overflow_asm_pass();
118478 +#else
118479 + return &insert_size_overflow_asm_pass.pass;
118480 +#endif
118481 +}
118482 +
118483 +// Create the noreturn report_size_overflow() function decl.
118484 +static void size_overflow_start_unit(void __unused *gcc_data, void __unused *user_data)
118485 +{
118486 + tree const_char_ptr_type_node;
118487 + tree fntype;
118488 +
118489 + const_char_ptr_type_node = build_pointer_type(build_type_variant(char_type_node, 1, 0));
118490 +
118491 + // void report_size_overflow(const char *loc_file, unsigned int loc_line, const char *current_func, const char *ssa_var)
118492 + fntype = build_function_type_list(void_type_node,
118493 + const_char_ptr_type_node,
118494 + unsigned_type_node,
118495 + const_char_ptr_type_node,
118496 + const_char_ptr_type_node,
118497 + NULL_TREE);
118498 + report_size_overflow_decl = build_fn_decl("report_size_overflow", fntype);
118499 +
118500 + DECL_ASSEMBLER_NAME(report_size_overflow_decl);
118501 + TREE_PUBLIC(report_size_overflow_decl) = 1;
118502 + DECL_EXTERNAL(report_size_overflow_decl) = 1;
118503 + DECL_ARTIFICIAL(report_size_overflow_decl) = 1;
118504 + TREE_THIS_VOLATILE(report_size_overflow_decl) = 1;
118505 +}
118506 +
118507 +static unsigned int dump_functions(void)
118508 +{
118509 + struct cgraph_node *node;
118510 +
118511 + FOR_EACH_FUNCTION_WITH_GIMPLE_BODY(node) {
118512 + basic_block bb;
118513 +
118514 + push_cfun(DECL_STRUCT_FUNCTION(NODE_DECL(node)));
118515 + current_function_decl = NODE_DECL(node);
118516 +
118517 + fprintf(stderr, "-----------------------------------------\n%s\n-----------------------------------------\n", DECL_NAME_POINTER(current_function_decl));
118518 +
118519 + FOR_ALL_BB_FN(bb, cfun) {
118520 + gimple_stmt_iterator si;
118521 +
118522 + fprintf(stderr, "<bb %u>:\n", bb->index);
118523 + for (si = gsi_start_phis(bb); !gsi_end_p(si); gsi_next(&si))
118524 + debug_gimple_stmt(gsi_stmt(si));
118525 + for (si = gsi_start_bb(bb); !gsi_end_p(si); gsi_next(&si))
118526 + debug_gimple_stmt(gsi_stmt(si));
118527 + fprintf(stderr, "\n");
118528 + }
118529 +
118530 + fprintf(stderr, "-------------------------------------------------------------------------\n");
118531 +
118532 + pop_cfun();
118533 + current_function_decl = NULL_TREE;
118534 + }
118535 +
118536 + fprintf(stderr, "###############################################################################\n");
118537 +
118538 + return 0;
118539 +}
118540 +
118541 +#if BUILDING_GCC_VERSION >= 4009
118542 +static const struct pass_data dump_pass_data = {
118543 +#else
118544 +static struct ipa_opt_pass_d dump_pass = {
118545 + .pass = {
118546 +#endif
118547 + .type = SIMPLE_IPA_PASS,
118548 + .name = "dump",
118549 +#if BUILDING_GCC_VERSION >= 4008
118550 + .optinfo_flags = OPTGROUP_NONE,
118551 +#endif
118552 +#if BUILDING_GCC_VERSION >= 4009
118553 + .has_gate = false,
118554 + .has_execute = true,
118555 +#else
118556 + .gate = NULL,
118557 + .execute = dump_functions,
118558 + .sub = NULL,
118559 + .next = NULL,
118560 + .static_pass_number = 0,
118561 +#endif
118562 + .tv_id = TV_NONE,
118563 + .properties_required = 0,
118564 + .properties_provided = 0,
118565 + .properties_destroyed = 0,
118566 + .todo_flags_start = 0,
118567 + .todo_flags_finish = 0,
118568 +#if BUILDING_GCC_VERSION < 4009
118569 + },
118570 + .generate_summary = NULL,
118571 + .write_summary = NULL,
118572 + .read_summary = NULL,
118573 +#if BUILDING_GCC_VERSION >= 4006
118574 + .write_optimization_summary = NULL,
118575 + .read_optimization_summary = NULL,
118576 +#endif
118577 + .stmt_fixup = NULL,
118578 + .function_transform_todo_flags_start = 0,
118579 + .function_transform = NULL,
118580 + .variable_transform = NULL,
118581 +#endif
118582 +};
118583 +
118584 +#if BUILDING_GCC_VERSION >= 4009
118585 +namespace {
118586 +class dump_pass : public ipa_opt_pass_d {
118587 +public:
118588 + dump_pass() : ipa_opt_pass_d(dump_pass_data, g, NULL, NULL, NULL, NULL, NULL, NULL, 0, NULL, NULL) {}
118589 + unsigned int execute() { return dump_functions(); }
118590 +};
118591 +}
118592 +#endif
118593 +
118594 +static struct opt_pass *make_dump_pass(void)
118595 +{
118596 +#if BUILDING_GCC_VERSION >= 4009
118597 + return new dump_pass();
118598 +#else
118599 + return &dump_pass.pass;
118600 +#endif
118601 +}
118602 +
118603 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
118604 +{
118605 + int i;
118606 + const char * const plugin_name = plugin_info->base_name;
118607 + const int argc = plugin_info->argc;
118608 + const struct plugin_argument * const argv = plugin_info->argv;
118609 + bool enable = true;
118610 + struct register_pass_info insert_size_overflow_asm_pass_info;
118611 + struct register_pass_info __unused dump_before_pass_info;
118612 + struct register_pass_info __unused dump_after_pass_info;
118613 + struct register_pass_info ipa_pass_info;
118614 + static const struct ggc_root_tab gt_ggc_r_gt_size_overflow[] = {
118615 + {
118616 + .base = &report_size_overflow_decl,
118617 + .nelt = 1,
118618 + .stride = sizeof(report_size_overflow_decl),
118619 + .cb = &gt_ggc_mx_tree_node,
118620 + .pchw = &gt_pch_nx_tree_node
118621 + },
118622 + LAST_GGC_ROOT_TAB
118623 + };
118624 +
118625 + insert_size_overflow_asm_pass_info.pass = make_insert_size_overflow_asm_pass();
118626 + insert_size_overflow_asm_pass_info.reference_pass_name = "ssa";
118627 + insert_size_overflow_asm_pass_info.ref_pass_instance_number = 1;
118628 + insert_size_overflow_asm_pass_info.pos_op = PASS_POS_INSERT_AFTER;
118629 +
118630 + dump_before_pass_info.pass = make_dump_pass();
118631 + dump_before_pass_info.reference_pass_name = "increase_alignment";
118632 + dump_before_pass_info.ref_pass_instance_number = 1;
118633 + dump_before_pass_info.pos_op = PASS_POS_INSERT_BEFORE;
118634 +
118635 + ipa_pass_info.pass = make_ipa_pass();
118636 + ipa_pass_info.reference_pass_name = "increase_alignment";
118637 + ipa_pass_info.ref_pass_instance_number = 1;
118638 + ipa_pass_info.pos_op = PASS_POS_INSERT_BEFORE;
118639 +
118640 + dump_after_pass_info.pass = make_dump_pass();
118641 + dump_after_pass_info.reference_pass_name = "increase_alignment";
118642 + dump_after_pass_info.ref_pass_instance_number = 1;
118643 + dump_after_pass_info.pos_op = PASS_POS_INSERT_BEFORE;
118644 +
118645 + if (!plugin_default_version_check(version, &gcc_version)) {
118646 + error(G_("incompatible gcc/plugin versions"));
118647 + return 1;
118648 + }
118649 +
118650 + for (i = 0; i < argc; ++i) {
118651 + if (!strcmp(argv[i].key, "no-size-overflow")) {
118652 + enable = false;
118653 + continue;
118654 + }
118655 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
118656 + }
118657 +
118658 + register_callback(plugin_name, PLUGIN_INFO, NULL, &size_overflow_plugin_info);
118659 + if (enable) {
118660 + register_callback(plugin_name, PLUGIN_START_UNIT, &size_overflow_start_unit, NULL);
118661 + register_callback(plugin_name, PLUGIN_REGISTER_GGC_ROOTS, NULL, (void *)&gt_ggc_r_gt_size_overflow);
118662 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &insert_size_overflow_asm_pass_info);
118663 +// register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &dump_before_pass_info);
118664 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &ipa_pass_info);
118665 +// register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &dump_after_pass_info);
118666 + }
118667 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
118668 +
118669 + return 0;
118670 +}
118671 diff --git a/tools/gcc/stackleak_plugin.c b/tools/gcc/stackleak_plugin.c
118672 new file mode 100644
118673 index 0000000..5c0b937
118674 --- /dev/null
118675 +++ b/tools/gcc/stackleak_plugin.c
118676 @@ -0,0 +1,374 @@
118677 +/*
118678 + * Copyright 2011-2014 by the PaX Team <pageexec@freemail.hu>
118679 + * Licensed under the GPL v2
118680 + *
118681 + * Note: the choice of the license means that the compilation process is
118682 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
118683 + * but for the kernel it doesn't matter since it doesn't link against
118684 + * any of the gcc libraries
118685 + *
118686 + * gcc plugin to help implement various PaX features
118687 + *
118688 + * - track lowest stack pointer
118689 + *
118690 + * TODO:
118691 + * - initialize all local variables
118692 + *
118693 + * BUGS:
118694 + * - none known
118695 + */
118696 +
118697 +#include "gcc-common.h"
118698 +
118699 +int plugin_is_GPL_compatible;
118700 +
118701 +static int track_frame_size = -1;
118702 +static const char track_function[] = "pax_track_stack";
118703 +static const char check_function[] = "pax_check_alloca";
118704 +static tree track_function_decl, check_function_decl;
118705 +static bool init_locals;
118706 +
118707 +static struct plugin_info stackleak_plugin_info = {
118708 + .version = "201402131920",
118709 + .help = "track-lowest-sp=nn\ttrack sp in functions whose frame size is at least nn bytes\n"
118710 +// "initialize-locals\t\tforcibly initialize all stack frames\n"
118711 +};
118712 +
118713 +static void stackleak_check_alloca(gimple_stmt_iterator *gsi)
118714 +{
118715 + gimple check_alloca;
118716 + tree alloca_size;
118717 +
118718 + // insert call to void pax_check_alloca(unsigned long size)
118719 + alloca_size = gimple_call_arg(gsi_stmt(*gsi), 0);
118720 + check_alloca = gimple_build_call(check_function_decl, 1, alloca_size);
118721 + gsi_insert_before(gsi, check_alloca, GSI_SAME_STMT);
118722 +}
118723 +
118724 +static void stackleak_add_instrumentation(gimple_stmt_iterator *gsi)
118725 +{
118726 + gimple track_stack;
118727 +
118728 + // insert call to void pax_track_stack(void)
118729 + track_stack = gimple_build_call(track_function_decl, 0);
118730 + gsi_insert_after(gsi, track_stack, GSI_CONTINUE_LINKING);
118731 +}
118732 +
118733 +static bool is_alloca(gimple stmt)
118734 +{
118735 + if (gimple_call_builtin_p(stmt, BUILT_IN_ALLOCA))
118736 + return true;
118737 +
118738 +#if BUILDING_GCC_VERSION >= 4007
118739 + if (gimple_call_builtin_p(stmt, BUILT_IN_ALLOCA_WITH_ALIGN))
118740 + return true;
118741 +#endif
118742 +
118743 + return false;
118744 +}
118745 +
118746 +static unsigned int execute_stackleak_tree_instrument(void)
118747 +{
118748 + basic_block bb, entry_bb;
118749 + bool prologue_instrumented = false, is_leaf = true;
118750 +
118751 + entry_bb = ENTRY_BLOCK_PTR_FOR_FN(cfun)->next_bb;
118752 +
118753 + // 1. loop through BBs and GIMPLE statements
118754 + FOR_EACH_BB_FN(bb, cfun) {
118755 + gimple_stmt_iterator gsi;
118756 +
118757 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
118758 + gimple stmt;
118759 +
118760 + stmt = gsi_stmt(gsi);
118761 +
118762 + if (is_gimple_call(stmt))
118763 + is_leaf = false;
118764 +
118765 + // gimple match: align 8 built-in BUILT_IN_NORMAL:BUILT_IN_ALLOCA attributes <tree_list 0xb7576450>
118766 + if (!is_alloca(stmt))
118767 + continue;
118768 +
118769 + // 2. insert stack overflow check before each __builtin_alloca call
118770 + stackleak_check_alloca(&gsi);
118771 +
118772 + // 3. insert track call after each __builtin_alloca call
118773 + stackleak_add_instrumentation(&gsi);
118774 + if (bb == entry_bb)
118775 + prologue_instrumented = true;
118776 + }
118777 + }
118778 +
118779 + // special cases for some bad linux code: taking the address of static inline functions will materialize them
118780 + // but we mustn't instrument some of them as the resulting stack alignment required by the function call ABI
118781 + // will break other assumptions regarding the expected (but not otherwise enforced) register clobbering ABI.
118782 + // case in point: native_save_fl on amd64 when optimized for size clobbers rdx if it were instrumented here.
118783 + if (is_leaf && !TREE_PUBLIC(current_function_decl) && DECL_DECLARED_INLINE_P(current_function_decl))
118784 + return 0;
118785 + if (is_leaf && !strncmp(IDENTIFIER_POINTER(DECL_NAME(current_function_decl)), "_paravirt_", 10))
118786 + return 0;
118787 +
118788 + // 4. insert track call at the beginning
118789 + if (!prologue_instrumented) {
118790 + gimple_stmt_iterator gsi;
118791 +
118792 + bb = split_block_after_labels(ENTRY_BLOCK_PTR_FOR_FN(cfun))->dest;
118793 + if (dom_info_available_p(CDI_DOMINATORS))
118794 + set_immediate_dominator(CDI_DOMINATORS, bb, ENTRY_BLOCK_PTR_FOR_FN(cfun));
118795 + gsi = gsi_start_bb(bb);
118796 + stackleak_add_instrumentation(&gsi);
118797 + }
118798 +
118799 + return 0;
118800 +}
118801 +
118802 +static unsigned int execute_stackleak_final(void)
118803 +{
118804 + rtx insn, next;
118805 +
118806 + if (cfun->calls_alloca)
118807 + return 0;
118808 +
118809 + // keep calls only if function frame is big enough
118810 + if (get_frame_size() >= track_frame_size)
118811 + return 0;
118812 +
118813 + // 1. find pax_track_stack calls
118814 + for (insn = get_insns(); insn; insn = next) {
118815 + // 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))
118816 + rtx body;
118817 +
118818 + next = NEXT_INSN(insn);
118819 + if (!CALL_P(insn))
118820 + continue;
118821 + body = PATTERN(insn);
118822 + if (GET_CODE(body) != CALL)
118823 + continue;
118824 + body = XEXP(body, 0);
118825 + if (GET_CODE(body) != MEM)
118826 + continue;
118827 + body = XEXP(body, 0);
118828 + if (GET_CODE(body) != SYMBOL_REF)
118829 + continue;
118830 +// if (strcmp(XSTR(body, 0), track_function))
118831 + if (SYMBOL_REF_DECL(body) != track_function_decl)
118832 + continue;
118833 +// warning(0, "track_frame_size: %d %ld %d", cfun->calls_alloca, get_frame_size(), track_frame_size);
118834 + // 2. delete call
118835 + delete_insn_and_edges(insn);
118836 +#if BUILDING_GCC_VERSION >= 4007
118837 + if (GET_CODE(next) == NOTE && NOTE_KIND(next) == NOTE_INSN_CALL_ARG_LOCATION) {
118838 + insn = next;
118839 + next = NEXT_INSN(insn);
118840 + delete_insn_and_edges(insn);
118841 + }
118842 +#endif
118843 + }
118844 +
118845 +// print_simple_rtl(stderr, get_insns());
118846 +// print_rtl(stderr, get_insns());
118847 +// warning(0, "track_frame_size: %d %ld %d", cfun->calls_alloca, get_frame_size(), track_frame_size);
118848 +
118849 + return 0;
118850 +}
118851 +
118852 +static bool gate_stackleak_track_stack(void)
118853 +{
118854 + return track_frame_size >= 0;
118855 +}
118856 +
118857 +static void stackleak_start_unit(void *gcc_data, void *user_data)
118858 +{
118859 + tree fntype;
118860 +
118861 + // void pax_track_stack(void)
118862 + fntype = build_function_type_list(void_type_node, NULL_TREE);
118863 + track_function_decl = build_fn_decl(track_function, fntype);
118864 + DECL_ASSEMBLER_NAME(track_function_decl); // for LTO
118865 + TREE_PUBLIC(track_function_decl) = 1;
118866 + DECL_EXTERNAL(track_function_decl) = 1;
118867 + DECL_ARTIFICIAL(track_function_decl) = 1;
118868 +
118869 + // void pax_check_alloca(unsigned long)
118870 + fntype = build_function_type_list(void_type_node, long_unsigned_type_node, NULL_TREE);
118871 + check_function_decl = build_fn_decl(check_function, fntype);
118872 + DECL_ASSEMBLER_NAME(check_function_decl); // for LTO
118873 + TREE_PUBLIC(check_function_decl) = 1;
118874 + DECL_EXTERNAL(check_function_decl) = 1;
118875 + DECL_ARTIFICIAL(check_function_decl) = 1;
118876 +}
118877 +
118878 +#if BUILDING_GCC_VERSION >= 4009
118879 +static const struct pass_data stackleak_tree_instrument_pass_data = {
118880 +#else
118881 +static struct gimple_opt_pass stackleak_tree_instrument_pass = {
118882 + .pass = {
118883 +#endif
118884 + .type = GIMPLE_PASS,
118885 + .name = "stackleak_tree_instrument",
118886 +#if BUILDING_GCC_VERSION >= 4008
118887 + .optinfo_flags = OPTGROUP_NONE,
118888 +#endif
118889 +#if BUILDING_GCC_VERSION >= 4009
118890 + .has_gate = true,
118891 + .has_execute = true,
118892 +#else
118893 + .gate = gate_stackleak_track_stack,
118894 + .execute = execute_stackleak_tree_instrument,
118895 + .sub = NULL,
118896 + .next = NULL,
118897 + .static_pass_number = 0,
118898 +#endif
118899 + .tv_id = TV_NONE,
118900 + .properties_required = PROP_gimple_leh | PROP_cfg,
118901 + .properties_provided = 0,
118902 + .properties_destroyed = 0,
118903 + .todo_flags_start = 0, //TODO_verify_ssa | TODO_verify_flow | TODO_verify_stmts,
118904 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_update_ssa | TODO_rebuild_cgraph_edges
118905 +#if BUILDING_GCC_VERSION < 4009
118906 + }
118907 +#endif
118908 +};
118909 +
118910 +#if BUILDING_GCC_VERSION >= 4009
118911 +static const struct pass_data stackleak_final_rtl_opt_pass_data = {
118912 +#else
118913 +static struct rtl_opt_pass stackleak_final_rtl_opt_pass = {
118914 + .pass = {
118915 +#endif
118916 + .type = RTL_PASS,
118917 + .name = "stackleak_final",
118918 +#if BUILDING_GCC_VERSION >= 4008
118919 + .optinfo_flags = OPTGROUP_NONE,
118920 +#endif
118921 +#if BUILDING_GCC_VERSION >= 4009
118922 + .has_gate = true,
118923 + .has_execute = true,
118924 +#else
118925 + .gate = gate_stackleak_track_stack,
118926 + .execute = execute_stackleak_final,
118927 + .sub = NULL,
118928 + .next = NULL,
118929 + .static_pass_number = 0,
118930 +#endif
118931 + .tv_id = TV_NONE,
118932 + .properties_required = 0,
118933 + .properties_provided = 0,
118934 + .properties_destroyed = 0,
118935 + .todo_flags_start = 0,
118936 + .todo_flags_finish = TODO_dump_func
118937 +#if BUILDING_GCC_VERSION < 4009
118938 + }
118939 +#endif
118940 +};
118941 +
118942 +#if BUILDING_GCC_VERSION >= 4009
118943 +namespace {
118944 +class stackleak_tree_instrument_pass : public gimple_opt_pass {
118945 +public:
118946 + stackleak_tree_instrument_pass() : gimple_opt_pass(stackleak_tree_instrument_pass_data, g) {}
118947 + bool gate() { return gate_stackleak_track_stack(); }
118948 + unsigned int execute() { return execute_stackleak_tree_instrument(); }
118949 +};
118950 +
118951 +class stackleak_final_rtl_opt_pass : public rtl_opt_pass {
118952 +public:
118953 + stackleak_final_rtl_opt_pass() : rtl_opt_pass(stackleak_final_rtl_opt_pass_data, g) {}
118954 + bool gate() { return gate_stackleak_track_stack(); }
118955 + unsigned int execute() { return execute_stackleak_final(); }
118956 +};
118957 +}
118958 +#endif
118959 +
118960 +static struct opt_pass *make_stackleak_tree_instrument_pass(void)
118961 +{
118962 +#if BUILDING_GCC_VERSION >= 4009
118963 + return new stackleak_tree_instrument_pass();
118964 +#else
118965 + return &stackleak_tree_instrument_pass.pass;
118966 +#endif
118967 +}
118968 +
118969 +static struct opt_pass *make_stackleak_final_rtl_opt_pass(void)
118970 +{
118971 +#if BUILDING_GCC_VERSION >= 4009
118972 + return new stackleak_final_rtl_opt_pass();
118973 +#else
118974 + return &stackleak_final_rtl_opt_pass.pass;
118975 +#endif
118976 +}
118977 +
118978 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
118979 +{
118980 + const char * const plugin_name = plugin_info->base_name;
118981 + const int argc = plugin_info->argc;
118982 + const struct plugin_argument * const argv = plugin_info->argv;
118983 + int i;
118984 + struct register_pass_info stackleak_tree_instrument_pass_info;
118985 + struct register_pass_info stackleak_final_pass_info;
118986 + static const struct ggc_root_tab gt_ggc_r_gt_stackleak[] = {
118987 + {
118988 + .base = &track_function_decl,
118989 + .nelt = 1,
118990 + .stride = sizeof(track_function_decl),
118991 + .cb = &gt_ggc_mx_tree_node,
118992 + .pchw = &gt_pch_nx_tree_node
118993 + },
118994 + {
118995 + .base = &check_function_decl,
118996 + .nelt = 1,
118997 + .stride = sizeof(check_function_decl),
118998 + .cb = &gt_ggc_mx_tree_node,
118999 + .pchw = &gt_pch_nx_tree_node
119000 + },
119001 + LAST_GGC_ROOT_TAB
119002 + };
119003 +
119004 + stackleak_tree_instrument_pass_info.pass = make_stackleak_tree_instrument_pass();
119005 +// stackleak_tree_instrument_pass_info.reference_pass_name = "tree_profile";
119006 + stackleak_tree_instrument_pass_info.reference_pass_name = "optimized";
119007 + stackleak_tree_instrument_pass_info.ref_pass_instance_number = 1;
119008 + stackleak_tree_instrument_pass_info.pos_op = PASS_POS_INSERT_BEFORE;
119009 +
119010 + stackleak_final_pass_info.pass = make_stackleak_final_rtl_opt_pass();
119011 + stackleak_final_pass_info.reference_pass_name = "final";
119012 + stackleak_final_pass_info.ref_pass_instance_number = 1;
119013 + stackleak_final_pass_info.pos_op = PASS_POS_INSERT_BEFORE;
119014 +
119015 + if (!plugin_default_version_check(version, &gcc_version)) {
119016 + error(G_("incompatible gcc/plugin versions"));
119017 + return 1;
119018 + }
119019 +
119020 + register_callback(plugin_name, PLUGIN_INFO, NULL, &stackleak_plugin_info);
119021 +
119022 + for (i = 0; i < argc; ++i) {
119023 + if (!strcmp(argv[i].key, "track-lowest-sp")) {
119024 + if (!argv[i].value) {
119025 + error(G_("no value supplied for option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
119026 + continue;
119027 + }
119028 + track_frame_size = atoi(argv[i].value);
119029 + if (argv[i].value[0] < '0' || argv[i].value[0] > '9' || track_frame_size < 0)
119030 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
119031 + continue;
119032 + }
119033 + if (!strcmp(argv[i].key, "initialize-locals")) {
119034 + if (argv[i].value) {
119035 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
119036 + continue;
119037 + }
119038 + init_locals = true;
119039 + continue;
119040 + }
119041 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
119042 + }
119043 +
119044 + register_callback(plugin_name, PLUGIN_START_UNIT, &stackleak_start_unit, NULL);
119045 + register_callback(plugin_name, PLUGIN_REGISTER_GGC_ROOTS, NULL, (void *)&gt_ggc_r_gt_stackleak);
119046 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &stackleak_tree_instrument_pass_info);
119047 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &stackleak_final_pass_info);
119048 +
119049 + return 0;
119050 +}
119051 diff --git a/tools/gcc/structleak_plugin.c b/tools/gcc/structleak_plugin.c
119052 new file mode 100644
119053 index 0000000..796569a
119054 --- /dev/null
119055 +++ b/tools/gcc/structleak_plugin.c
119056 @@ -0,0 +1,273 @@
119057 +/*
119058 + * Copyright 2013-2014 by PaX Team <pageexec@freemail.hu>
119059 + * Licensed under the GPL v2
119060 + *
119061 + * Note: the choice of the license means that the compilation process is
119062 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
119063 + * but for the kernel it doesn't matter since it doesn't link against
119064 + * any of the gcc libraries
119065 + *
119066 + * gcc plugin to forcibly initialize certain local variables that could
119067 + * otherwise leak kernel stack to userland if they aren't properly initialized
119068 + * by later code
119069 + *
119070 + * Homepage: http://pax.grsecurity.net/
119071 + *
119072 + * Usage:
119073 + * $ # for 4.5/4.6/C based 4.7
119074 + * $ 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
119075 + * $ # for C++ based 4.7/4.8+
119076 + * $ 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
119077 + * $ gcc -fplugin=./structleak_plugin.so test.c -O2
119078 + *
119079 + * TODO: eliminate redundant initializers
119080 + * increase type coverage
119081 + */
119082 +
119083 +#include "gcc-common.h"
119084 +
119085 +// unused C type flag in all versions 4.5-4.9
119086 +#define TYPE_USERSPACE(TYPE) TYPE_LANG_FLAG_3(TYPE)
119087 +
119088 +int plugin_is_GPL_compatible;
119089 +
119090 +static struct plugin_info structleak_plugin_info = {
119091 + .version = "201401260140",
119092 + .help = "disable\tdo not activate plugin\n",
119093 +};
119094 +
119095 +static tree handle_user_attribute(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
119096 +{
119097 + *no_add_attrs = true;
119098 +
119099 + // check for types? for now accept everything linux has to offer
119100 + if (TREE_CODE(*node) != FIELD_DECL)
119101 + return NULL_TREE;
119102 +
119103 + *no_add_attrs = false;
119104 + return NULL_TREE;
119105 +}
119106 +
119107 +static struct attribute_spec user_attr = {
119108 + .name = "user",
119109 + .min_length = 0,
119110 + .max_length = 0,
119111 + .decl_required = false,
119112 + .type_required = false,
119113 + .function_type_required = false,
119114 + .handler = handle_user_attribute,
119115 +#if BUILDING_GCC_VERSION >= 4007
119116 + .affects_type_identity = true
119117 +#endif
119118 +};
119119 +
119120 +static void register_attributes(void *event_data, void *data)
119121 +{
119122 + register_attribute(&user_attr);
119123 +// register_attribute(&force_attr);
119124 +}
119125 +
119126 +static tree get_field_type(tree field)
119127 +{
119128 + return strip_array_types(TREE_TYPE(field));
119129 +}
119130 +
119131 +static bool is_userspace_type(tree type)
119132 +{
119133 + tree field;
119134 +
119135 + for (field = TYPE_FIELDS(type); field; field = TREE_CHAIN(field)) {
119136 + tree fieldtype = get_field_type(field);
119137 + enum tree_code code = TREE_CODE(fieldtype);
119138 +
119139 + if (code == RECORD_TYPE || code == UNION_TYPE)
119140 + if (is_userspace_type(fieldtype))
119141 + return true;
119142 +
119143 + if (lookup_attribute("user", DECL_ATTRIBUTES(field)))
119144 + return true;
119145 + }
119146 + return false;
119147 +}
119148 +
119149 +static void finish_type(void *event_data, void *data)
119150 +{
119151 + tree type = (tree)event_data;
119152 +
119153 + if (TYPE_USERSPACE(type))
119154 + return;
119155 +
119156 + if (is_userspace_type(type))
119157 + TYPE_USERSPACE(type) = 1;
119158 +}
119159 +
119160 +static void initialize(tree var)
119161 +{
119162 + basic_block bb;
119163 + gimple_stmt_iterator gsi;
119164 + tree initializer;
119165 + gimple init_stmt;
119166 +
119167 + // this is the original entry bb before the forced split
119168 + // TODO: check further BBs in case more splits occured before us
119169 + bb = ENTRY_BLOCK_PTR_FOR_FN(cfun)->next_bb->next_bb;
119170 +
119171 + // first check if the variable is already initialized, warn otherwise
119172 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
119173 + gimple stmt = gsi_stmt(gsi);
119174 + tree rhs1;
119175 +
119176 + // we're looking for an assignment of a single rhs...
119177 + if (!gimple_assign_single_p(stmt))
119178 + continue;
119179 + rhs1 = gimple_assign_rhs1(stmt);
119180 +#if BUILDING_GCC_VERSION >= 4007
119181 + // ... of a non-clobbering expression...
119182 + if (TREE_CLOBBER_P(rhs1))
119183 + continue;
119184 +#endif
119185 + // ... to our variable...
119186 + if (gimple_get_lhs(stmt) != var)
119187 + continue;
119188 + // if it's an initializer then we're good
119189 + if (TREE_CODE(rhs1) == CONSTRUCTOR)
119190 + return;
119191 + }
119192 +
119193 + // these aren't the 0days you're looking for
119194 +// inform(DECL_SOURCE_LOCATION(var), "userspace variable will be forcibly initialized");
119195 +
119196 + // build the initializer expression
119197 + initializer = build_constructor(TREE_TYPE(var), NULL);
119198 +
119199 + // build the initializer stmt
119200 + init_stmt = gimple_build_assign(var, initializer);
119201 + gsi = gsi_start_bb(ENTRY_BLOCK_PTR_FOR_FN(cfun)->next_bb);
119202 + gsi_insert_before(&gsi, init_stmt, GSI_NEW_STMT);
119203 + update_stmt(init_stmt);
119204 +}
119205 +
119206 +static unsigned int handle_function(void)
119207 +{
119208 + basic_block bb;
119209 + unsigned int ret = 0;
119210 + tree var;
119211 + unsigned int i;
119212 +
119213 + // split the first bb where we can put the forced initializers
119214 + bb = split_block_after_labels(ENTRY_BLOCK_PTR_FOR_FN(cfun))->dest;
119215 + if (dom_info_available_p(CDI_DOMINATORS))
119216 + set_immediate_dominator(CDI_DOMINATORS, bb, ENTRY_BLOCK_PTR_FOR_FN(cfun));
119217 +
119218 + // enumarate all local variables and forcibly initialize our targets
119219 + FOR_EACH_LOCAL_DECL(cfun, i, var) {
119220 + tree type = TREE_TYPE(var);
119221 +
119222 + gcc_assert(DECL_P(var));
119223 + if (!auto_var_in_fn_p(var, current_function_decl))
119224 + continue;
119225 +
119226 + // only care about structure types
119227 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE)
119228 + continue;
119229 +
119230 + // if the type is of interest, examine the variable
119231 + if (TYPE_USERSPACE(type))
119232 + initialize(var);
119233 + }
119234 +
119235 + return ret;
119236 +}
119237 +
119238 +#if BUILDING_GCC_VERSION >= 4009
119239 +static const struct pass_data structleak_pass_data = {
119240 +#else
119241 +static struct gimple_opt_pass structleak_pass = {
119242 + .pass = {
119243 +#endif
119244 + .type = GIMPLE_PASS,
119245 + .name = "structleak",
119246 +#if BUILDING_GCC_VERSION >= 4008
119247 + .optinfo_flags = OPTGROUP_NONE,
119248 +#endif
119249 +#if BUILDING_GCC_VERSION >= 4009
119250 + .has_gate = false,
119251 + .has_execute = true,
119252 +#else
119253 + .gate = NULL,
119254 + .execute = handle_function,
119255 + .sub = NULL,
119256 + .next = NULL,
119257 + .static_pass_number = 0,
119258 +#endif
119259 + .tv_id = TV_NONE,
119260 + .properties_required = PROP_cfg,
119261 + .properties_provided = 0,
119262 + .properties_destroyed = 0,
119263 + .todo_flags_start = 0,
119264 + .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
119265 +#if BUILDING_GCC_VERSION < 4009
119266 + }
119267 +#endif
119268 +};
119269 +
119270 +#if BUILDING_GCC_VERSION >= 4009
119271 +namespace {
119272 +class structleak_pass : public gimple_opt_pass {
119273 +public:
119274 + structleak_pass() : gimple_opt_pass(structleak_pass_data, g) {}
119275 + unsigned int execute() { return handle_function(); }
119276 +};
119277 +}
119278 +#endif
119279 +
119280 +static struct opt_pass *make_structleak_pass(void)
119281 +{
119282 +#if BUILDING_GCC_VERSION >= 4009
119283 + return new structleak_pass();
119284 +#else
119285 + return &structleak_pass.pass;
119286 +#endif
119287 +}
119288 +
119289 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
119290 +{
119291 + int i;
119292 + const char * const plugin_name = plugin_info->base_name;
119293 + const int argc = plugin_info->argc;
119294 + const struct plugin_argument * const argv = plugin_info->argv;
119295 + bool enable = true;
119296 + struct register_pass_info structleak_pass_info;
119297 +
119298 + structleak_pass_info.pass = make_structleak_pass();
119299 + structleak_pass_info.reference_pass_name = "ssa";
119300 + structleak_pass_info.ref_pass_instance_number = 1;
119301 + structleak_pass_info.pos_op = PASS_POS_INSERT_AFTER;
119302 +
119303 + if (!plugin_default_version_check(version, &gcc_version)) {
119304 + error(G_("incompatible gcc/plugin versions"));
119305 + return 1;
119306 + }
119307 +
119308 + if (strcmp(lang_hooks.name, "GNU C")) {
119309 + inform(UNKNOWN_LOCATION, G_("%s supports C only"), plugin_name);
119310 + enable = false;
119311 + }
119312 +
119313 + for (i = 0; i < argc; ++i) {
119314 + if (!strcmp(argv[i].key, "disable")) {
119315 + enable = false;
119316 + continue;
119317 + }
119318 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
119319 + }
119320 +
119321 + register_callback(plugin_name, PLUGIN_INFO, NULL, &structleak_plugin_info);
119322 + if (enable) {
119323 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &structleak_pass_info);
119324 + register_callback(plugin_name, PLUGIN_FINISH_TYPE, finish_type, NULL);
119325 + }
119326 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
119327 +
119328 + return 0;
119329 +}
119330 diff --git a/tools/lib/lk/Makefile b/tools/lib/lk/Makefile
119331 index 3dba0a4..97175dc 100644
119332 --- a/tools/lib/lk/Makefile
119333 +++ b/tools/lib/lk/Makefile
119334 @@ -13,7 +13,7 @@ LIB_OBJS += $(OUTPUT)debugfs.o
119335
119336 LIBFILE = liblk.a
119337
119338 -CFLAGS = -ggdb3 -Wall -Wextra -std=gnu99 -Werror -O6 -D_FORTIFY_SOURCE=2 $(EXTRA_WARNINGS) $(EXTRA_CFLAGS) -fPIC
119339 +CFLAGS = -ggdb3 -Wall -Wextra -std=gnu99 -Werror -O6 -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 $(EXTRA_WARNINGS) $(EXTRA_CFLAGS) -fPIC
119340 EXTLIBS = -lelf -lpthread -lrt -lm
119341 ALL_CFLAGS = $(CFLAGS) $(BASIC_CFLAGS) -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64
119342 ALL_LDFLAGS = $(LDFLAGS)
119343 diff --git a/tools/perf/util/include/asm/alternative-asm.h b/tools/perf/util/include/asm/alternative-asm.h
119344 index 6789d78..4afd019e 100644
119345 --- a/tools/perf/util/include/asm/alternative-asm.h
119346 +++ b/tools/perf/util/include/asm/alternative-asm.h
119347 @@ -5,4 +5,7 @@
119348
119349 #define altinstruction_entry #
119350
119351 + .macro pax_force_retaddr rip=0, reload=0
119352 + .endm
119353 +
119354 #endif
119355 diff --git a/tools/perf/util/include/linux/compiler.h b/tools/perf/util/include/linux/compiler.h
119356 index b003ad7..c0a02f8 100644
119357 --- a/tools/perf/util/include/linux/compiler.h
119358 +++ b/tools/perf/util/include/linux/compiler.h
119359 @@ -27,4 +27,12 @@
119360 # define __weak __attribute__((weak))
119361 #endif
119362
119363 +#ifndef __size_overflow
119364 +# define __size_overflow(...)
119365 +#endif
119366 +
119367 +#ifndef __intentional_overflow
119368 +# define __intentional_overflow(...)
119369 +#endif
119370 +
119371 #endif
119372 diff --git a/virt/kvm/ioapic.c b/virt/kvm/ioapic.c
119373 index 2d68297..39dc5bc 100644
119374 --- a/virt/kvm/ioapic.c
119375 +++ b/virt/kvm/ioapic.c
119376 @@ -306,7 +306,7 @@ static int ioapic_deliver(struct kvm_ioapic *ioapic, int irq, bool line_status)
119377 BUG_ON(ioapic->rtc_status.pending_eoi != 0);
119378 ret = kvm_irq_delivery_to_apic(ioapic->kvm, NULL, &irqe,
119379 ioapic->rtc_status.dest_map);
119380 - ioapic->rtc_status.pending_eoi = ret;
119381 + ioapic->rtc_status.pending_eoi = (ret < 0 ? 0 : ret);
119382 } else
119383 ret = kvm_irq_delivery_to_apic(ioapic->kvm, NULL, &irqe, NULL);
119384
119385 diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
119386 index 4f588bc..a543c97 100644
119387 --- a/virt/kvm/kvm_main.c
119388 +++ b/virt/kvm/kvm_main.c
119389 @@ -76,12 +76,17 @@ LIST_HEAD(vm_list);
119390
119391 static cpumask_var_t cpus_hardware_enabled;
119392 static int kvm_usage_count = 0;
119393 -static atomic_t hardware_enable_failed;
119394 +static atomic_unchecked_t hardware_enable_failed;
119395
119396 struct kmem_cache *kvm_vcpu_cache;
119397 EXPORT_SYMBOL_GPL(kvm_vcpu_cache);
119398
119399 -static __read_mostly struct preempt_ops kvm_preempt_ops;
119400 +static void kvm_sched_in(struct preempt_notifier *pn, int cpu);
119401 +static void kvm_sched_out(struct preempt_notifier *pn, struct task_struct *next);
119402 +static struct preempt_ops kvm_preempt_ops = {
119403 + .sched_in = kvm_sched_in,
119404 + .sched_out = kvm_sched_out,
119405 +};
119406
119407 struct dentry *kvm_debugfs_dir;
119408
119409 @@ -751,7 +756,7 @@ int __kvm_set_memory_region(struct kvm *kvm,
119410 /* We can read the guest memory with __xxx_user() later on. */
119411 if ((mem->slot < KVM_USER_MEM_SLOTS) &&
119412 ((mem->userspace_addr & (PAGE_SIZE - 1)) ||
119413 - !access_ok(VERIFY_WRITE,
119414 + !access_ok_noprefault(VERIFY_WRITE,
119415 (void __user *)(unsigned long)mem->userspace_addr,
119416 mem->memory_size)))
119417 goto out;
119418 @@ -1615,9 +1620,17 @@ EXPORT_SYMBOL_GPL(kvm_read_guest_cached);
119419
119420 int kvm_clear_guest_page(struct kvm *kvm, gfn_t gfn, int offset, int len)
119421 {
119422 - const void *zero_page = (const void *) __va(page_to_phys(ZERO_PAGE(0)));
119423 + int r;
119424 + unsigned long addr;
119425
119426 - return kvm_write_guest_page(kvm, gfn, zero_page, offset, len);
119427 + addr = gfn_to_hva(kvm, gfn);
119428 + if (kvm_is_error_hva(addr))
119429 + return -EFAULT;
119430 + r = __clear_user((void __user *)addr + offset, len);
119431 + if (r)
119432 + return -EFAULT;
119433 + mark_page_dirty(kvm, gfn);
119434 + return 0;
119435 }
119436 EXPORT_SYMBOL_GPL(kvm_clear_guest_page);
119437
119438 @@ -1872,7 +1885,7 @@ static int kvm_vcpu_release(struct inode *inode, struct file *filp)
119439 return 0;
119440 }
119441
119442 -static struct file_operations kvm_vcpu_fops = {
119443 +static file_operations_no_const kvm_vcpu_fops __read_only = {
119444 .release = kvm_vcpu_release,
119445 .unlocked_ioctl = kvm_vcpu_ioctl,
119446 #ifdef CONFIG_COMPAT
119447 @@ -2532,7 +2545,7 @@ out:
119448 }
119449 #endif
119450
119451 -static struct file_operations kvm_vm_fops = {
119452 +static file_operations_no_const kvm_vm_fops __read_only = {
119453 .release = kvm_vm_release,
119454 .unlocked_ioctl = kvm_vm_ioctl,
119455 #ifdef CONFIG_COMPAT
119456 @@ -2632,7 +2645,7 @@ out:
119457 return r;
119458 }
119459
119460 -static struct file_operations kvm_chardev_ops = {
119461 +static file_operations_no_const kvm_chardev_ops __read_only = {
119462 .unlocked_ioctl = kvm_dev_ioctl,
119463 .compat_ioctl = kvm_dev_ioctl,
119464 .llseek = noop_llseek,
119465 @@ -2658,7 +2671,7 @@ static void hardware_enable_nolock(void *junk)
119466
119467 if (r) {
119468 cpumask_clear_cpu(cpu, cpus_hardware_enabled);
119469 - atomic_inc(&hardware_enable_failed);
119470 + atomic_inc_unchecked(&hardware_enable_failed);
119471 printk(KERN_INFO "kvm: enabling virtualization on "
119472 "CPU%d failed\n", cpu);
119473 }
119474 @@ -2714,10 +2727,10 @@ static int hardware_enable_all(void)
119475
119476 kvm_usage_count++;
119477 if (kvm_usage_count == 1) {
119478 - atomic_set(&hardware_enable_failed, 0);
119479 + atomic_set_unchecked(&hardware_enable_failed, 0);
119480 on_each_cpu(hardware_enable_nolock, NULL, 1);
119481
119482 - if (atomic_read(&hardware_enable_failed)) {
119483 + if (atomic_read_unchecked(&hardware_enable_failed)) {
119484 hardware_disable_all_nolock();
119485 r = -EBUSY;
119486 }
119487 @@ -3148,7 +3161,7 @@ static void kvm_sched_out(struct preempt_notifier *pn,
119488 kvm_arch_vcpu_put(vcpu);
119489 }
119490
119491 -int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
119492 +int kvm_init(const void *opaque, unsigned vcpu_size, unsigned vcpu_align,
119493 struct module *module)
119494 {
119495 int r;
119496 @@ -3195,7 +3208,7 @@ int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
119497 if (!vcpu_align)
119498 vcpu_align = __alignof__(struct kvm_vcpu);
119499 kvm_vcpu_cache = kmem_cache_create("kvm_vcpu", vcpu_size, vcpu_align,
119500 - 0, NULL);
119501 + SLAB_USERCOPY, NULL);
119502 if (!kvm_vcpu_cache) {
119503 r = -ENOMEM;
119504 goto out_free_3;
119505 @@ -3205,9 +3218,11 @@ int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
119506 if (r)
119507 goto out_free;
119508
119509 + pax_open_kernel();
119510 kvm_chardev_ops.owner = module;
119511 kvm_vm_fops.owner = module;
119512 kvm_vcpu_fops.owner = module;
119513 + pax_close_kernel();
119514
119515 r = misc_register(&kvm_dev);
119516 if (r) {
119517 @@ -3217,9 +3232,6 @@ int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
119518
119519 register_syscore_ops(&kvm_syscore_ops);
119520
119521 - kvm_preempt_ops.sched_in = kvm_sched_in;
119522 - kvm_preempt_ops.sched_out = kvm_sched_out;
119523 -
119524 r = kvm_init_debug();
119525 if (r) {
119526 printk(KERN_ERR "kvm: create debugfs files failed\n");